// SPDX-License-Identifier: GPL-2.0 or MIT
+use core::ops::Deref;
+use core::ops::DerefMut;
use kernel::bits::genmask_u32;
use kernel::device::Bound;
use kernel::device::Device;
use kernel::prelude::*;
use kernel::time;
use kernel::transmute::AsBytes;
+use kernel::uapi;
use crate::driver::IoMem;
use crate::regs;
/// # Invariants
///
/// - The layout of this struct identical to the C `struct drm_panthor_gpu_info`.
-#[repr(C)]
-pub(crate) struct GpuInfo {
- pub(crate) gpu_id: u32,
- pub(crate) gpu_rev: u32,
- pub(crate) csf_id: u32,
- pub(crate) l2_features: u32,
- pub(crate) tiler_features: u32,
- pub(crate) mem_features: u32,
- pub(crate) mmu_features: u32,
- pub(crate) thread_features: u32,
- pub(crate) max_threads: u32,
- pub(crate) thread_max_workgroup_size: u32,
- pub(crate) thread_max_barrier_size: u32,
- pub(crate) coherency_features: u32,
- pub(crate) texture_features: [u32; 4],
- pub(crate) as_present: u32,
- pub(crate) pad0: u32,
- pub(crate) shader_present: u64,
- pub(crate) l2_present: u64,
- pub(crate) tiler_present: u64,
- pub(crate) core_features: u32,
- pub(crate) pad: u32,
-}
+#[repr(transparent)]
+#[derive(Clone, Copy)]
+pub(crate) struct GpuInfo(pub(crate) uapi::drm_panthor_gpu_info);
impl GpuInfo {
pub(crate) fn new(dev: &Device<Bound>, iomem: &Devres<IoMem>) -> Result<Self> {
let l2_present = u64::from(regs::GPU_L2_PRESENT_LO.read(dev, iomem)?);
let l2_present = l2_present | u64::from(regs::GPU_L2_PRESENT_HI.read(dev, iomem)?) << 32;
- Ok(Self {
+ Ok(Self(uapi::drm_panthor_gpu_info {
gpu_id,
gpu_rev,
csf_id,
tiler_present,
core_features,
pad: 0,
- })
+ gpu_features: 0,
+ }))
}
pub(crate) fn log(&self, pdev: &platform::Device) {
}
}
+impl Deref for GpuInfo {
+ type Target = uapi::drm_panthor_gpu_info;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+impl DerefMut for GpuInfo {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut self.0
+ }
+}
+
// SAFETY: `GpuInfo`'s invariant guarantees that it is the same type that is
// already exposed to userspace by the C driver. This implies that it fulfills
// the requirements for `AsBytes`.