* [PATCH] rust: drm: tyr: use generated bindings for GpuInfo
@ 2025-11-27 21:18 Deborah Brouwer
2025-11-28 9:29 ` Alice Ryhl
2025-11-28 12:22 ` Daniel Almeida
0 siblings, 2 replies; 3+ messages in thread
From: Deborah Brouwer @ 2025-11-27 21:18 UTC (permalink / raw)
To: dri-devel, rust-for-linux
Cc: daniel.almeida, aliceryhl, boris.brezillon, Deborah Brouwer
Currently Tyr's struct GpuInfo is manually copied and updated from
include/uapi/drm/panthor_drm.h. But an auto generated struct is available,
so use that instead to avoid copy/paste errors and to stay up-to-date with
the panthor uapi.
Signed-off-by: Deborah Brouwer <deborah.brouwer@collabora.com>
---
drivers/gpu/drm/tyr/gpu.rs | 48 ++++++++++++++++++--------------------
1 file changed, 23 insertions(+), 25 deletions(-)
diff --git a/drivers/gpu/drm/tyr/gpu.rs b/drivers/gpu/drm/tyr/gpu.rs
index 6c582910dd5d..3072562e36e5 100644
--- a/drivers/gpu/drm/tyr/gpu.rs
+++ b/drivers/gpu/drm/tyr/gpu.rs
@@ -1,5 +1,7 @@
// 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;
@@ -8,6 +10,7 @@
use kernel::prelude::*;
use kernel::time;
use kernel::transmute::AsBytes;
+use kernel::uapi;
use crate::driver::IoMem;
use crate::regs;
@@ -18,29 +21,9 @@
/// # 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> {
@@ -73,7 +56,7 @@ 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,
@@ -95,7 +78,8 @@ pub(crate) fn new(dev: &Device<Bound>, iomem: &Devres<IoMem>) -> Result<Self> {
tiler_present,
core_features,
pad: 0,
- })
+ gpu_features: 0,
+ }))
}
pub(crate) fn log(&self, pdev: &platform::Device) {
@@ -154,6 +138,20 @@ pub(crate) fn pa_bits(&self) -> u32 {
}
}
+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`.
--
2.51.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] rust: drm: tyr: use generated bindings for GpuInfo
2025-11-27 21:18 [PATCH] rust: drm: tyr: use generated bindings for GpuInfo Deborah Brouwer
@ 2025-11-28 9:29 ` Alice Ryhl
2025-11-28 12:22 ` Daniel Almeida
1 sibling, 0 replies; 3+ messages in thread
From: Alice Ryhl @ 2025-11-28 9:29 UTC (permalink / raw)
To: Deborah Brouwer
Cc: dri-devel, rust-for-linux, daniel.almeida, boris.brezillon
On Thu, Nov 27, 2025 at 01:18:43PM -0800, Deborah Brouwer wrote:
> Currently Tyr's struct GpuInfo is manually copied and updated from
> include/uapi/drm/panthor_drm.h. But an auto generated struct is available,
> so use that instead to avoid copy/paste errors and to stay up-to-date with
> the panthor uapi.
>
> Signed-off-by: Deborah Brouwer <deborah.brouwer@collabora.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] rust: drm: tyr: use generated bindings for GpuInfo
2025-11-27 21:18 [PATCH] rust: drm: tyr: use generated bindings for GpuInfo Deborah Brouwer
2025-11-28 9:29 ` Alice Ryhl
@ 2025-11-28 12:22 ` Daniel Almeida
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Almeida @ 2025-11-28 12:22 UTC (permalink / raw)
To: Deborah Brouwer; +Cc: dri-devel, rust-for-linux, aliceryhl, boris.brezillon
> On 27 Nov 2025, at 18:18, Deborah Brouwer <deborah.brouwer@collabora.com> wrote:
>
> Currently Tyr's struct GpuInfo is manually copied and updated from
> include/uapi/drm/panthor_drm.h. But an auto generated struct is available,
> so use that instead to avoid copy/paste errors and to stay up-to-date with
> the panthor uapi.
>
> Signed-off-by: Deborah Brouwer <deborah.brouwer@collabora.com>
> ---
> drivers/gpu/drm/tyr/gpu.rs | 48 ++++++++++++++++++--------------------
> 1 file changed, 23 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/gpu/drm/tyr/gpu.rs b/drivers/gpu/drm/tyr/gpu.rs
> index 6c582910dd5d..3072562e36e5 100644
> --- a/drivers/gpu/drm/tyr/gpu.rs
> +++ b/drivers/gpu/drm/tyr/gpu.rs
> @@ -1,5 +1,7 @@
> // 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;
> @@ -8,6 +10,7 @@
> use kernel::prelude::*;
> use kernel::time;
> use kernel::transmute::AsBytes;
> +use kernel::uapi;
>
> use crate::driver::IoMem;
> use crate::regs;
> @@ -18,29 +21,9 @@
> /// # 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> {
> @@ -73,7 +56,7 @@ 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,
> @@ -95,7 +78,8 @@ pub(crate) fn new(dev: &Device<Bound>, iomem: &Devres<IoMem>) -> Result<Self> {
> tiler_present,
> core_features,
> pad: 0,
> - })
> + gpu_features: 0,
> + }))
> }
>
> pub(crate) fn log(&self, pdev: &platform::Device) {
> @@ -154,6 +138,20 @@ pub(crate) fn pa_bits(&self) -> u32 {
> }
> }
>
> +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`.
> --
> 2.51.1
>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-11-28 12:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-27 21:18 [PATCH] rust: drm: tyr: use generated bindings for GpuInfo Deborah Brouwer
2025-11-28 9:29 ` Alice Ryhl
2025-11-28 12:22 ` Daniel Almeida
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).