drm: tyr: use lifetime-bound IoMem
Subsystems (4)
Danilo Krummrich
maintainercover drm: tyr: use lifetime-bound IoMem
Adopt the driver core lifetime infrastructure for tyr.
Separate the driver type from the driver data and use lifetime-bound IoMem directly in probe instead of wrapping it in Devres and Arc, simplifying register access.
This patch series is based on [1] and drm-rust-next.
[1] https://lore.kernel.org/driver-core/[email protected]/
Danilo Krummrich (2):
gpu: drm: tyr: separate driver type from driver data
gpu: drm: tyr: use IoMem directly instead of Devres
drivers/gpu/drm/tyr/driver.rs | 29 ++++++++++++----------------- drivers/gpu/drm/tyr/gpu.rs | 13 +++---------- drivers/gpu/drm/tyr/tyr.rs | 4 ++-- 3 files changed, 17 insertions(+), 29 deletions(-)
Signature · 1 line
2.54.0
Danilo Krummrich
maintainerPATCH 1/2 gpu: drm: tyr: separate driver type from driver data
Introduce TyrPlatformDriver as a unit struct for the platform::Driver trait implementation and keep TyrPlatformDriverData for the private driver data.
--- drivers/gpu/drm/tyr/driver.rs | 10 ++++++---- drivers/gpu/drm/tyr/tyr.rs | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-)
drivers/gpu/drm/tyr/driver.rs +6 -4
@@ -51,6 +51,8 @@/// Convenience type alias for the DRM device type for this driver. pub (crate )type TyrDrmDevice = drm::Device <TyrDrmDriver >; +pub (crate )struct TyrPlatformDriver ; +#[pin_data( PinnedDrop )] pub (crate )struct TyrPlatformDriverData { _device:ARef <TyrDrmDevice >,
@@ -93,22 +95,22 @@ fn issue_soft_reset(dev: &Device<Bound>, iomem: &Devres<IoMem>) -> Result { kernel::of_device_table!(OF_TABLE ,MODULE_OF_TABLE , - <TyrPlatformDriverData as platform::Driver >::IdInfo , + <TyrPlatformDriver as platform::Driver >::IdInfo , [ (of::DeviceId ::new (c"rockchip,rk3588-mali" ), ()), (of::DeviceId ::new (c"arm,mali-valhall-csf" ), ()) ] ); -impl platform::Driver for TyrPlatformDriverData { +impl platform::Driver for TyrPlatformDriver {type IdInfo = (); -type Data <'bound> =Self ; +type Data <'bound> =TyrPlatformDriverData ;const OF_ID_TABLE :Option <of::IdTable <Self ::IdInfo >> =Some (&OF_TABLE );fn probe <'bound>( pdev: &'bound platform::Device <Core <'_>>, _info:Option <&'boundSelf ::IdInfo >, - ) ->impl PinInit <Self ,Error > + 'bound { + ) ->impl PinInit <Self ::Data <'bound>,Error > + 'bound {let core_clk =Clk ::get (pdev.as_ref (),Some (c"core" ))?;let stacks_clk =OptionalClk ::get (pdev.as_ref (),Some (c"stacks" ))?;let coregroup_clk =OptionalClk ::get (pdev.as_ref (),Some (c"coregroup" ))?;
drivers/gpu/drm/tyr/tyr.rs +2 -2
@@ -5,7 +5,7 @@//! The name "Tyr" is inspired by Norse mythology, reflecting Arm's tradition of //! naming their GPUs after Nordic mythological figures and places. -use crate ::driver::TyrPlatformDriverData ; +use crate ::driver::TyrPlatformDriver ;mod driver;mod file;
@@ -14,7 +14,7 @@mod regs; kernel::module_platform_driver! { -type :TyrPlatformDriverData , +type :TyrPlatformDriver , name:"tyr" , authors: ["The Tyr driver authors" ], description:"Arm Mali Tyr DRM driver" ,
Signature · 1 line
2.54.0
Re: [PATCH 1/2] gpu: drm: tyr: separate driver type from driver data
Quoted 6 lines · Danilo Krummrich
Introduce TyrPlatformDriver as a unit struct for the
platform::Drivertrait implementation and keep TyrPlatformDriverData for the private driver data.Signed-off-by Danilo Krummrich <[email protected]>---
Re: [PATCH 1/2] gpu: drm: tyr: separate driver type from driver data
In reply to Danilo KrummrichQuoted 5 lines · On Tue, 26 May 2026 01:01:43 +0200 Danilo Krummrich <[email protected]> wrote:
Introduce TyrPlatformDriver as a unit struct for the
platform::Drivertrait implementation and keep TyrPlatformDriverData for the private driver data.Signed-off-by Danilo Krummrich <[email protected]>
Quoted 67 lines
--- drivers/gpu/drm/tyr/driver.rs | 10 ++++++---- drivers/gpu/drm/tyr/tyr.rs | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-)drivers/gpu/drm/tyr/driver.rs +6
-4@@ -51,6 +51,8 @@/// Convenience type alias for the DRM device type for this driver. pub (crate )type TyrDrmDevice = drm::Device <TyrDrmDriver >; +pub (crate )struct TyrPlatformDriver ; +#[pin_data( PinnedDrop )] pub (crate )struct TyrPlatformDriverData { _device:ARef <TyrDrmDevice >,@@ -93,22 +95,22 @@ fn issue_soft_reset(dev: &Device<Bound>, iomem: &Devres<IoMem>) -> Result { kernel::of_device_table!(OF_TABLE ,MODULE_OF_TABLE , - <TyrPlatformDriverData as platform::Driver >::IdInfo , + <TyrPlatformDriver as platform::Driver >::IdInfo , [ (of::DeviceId ::new (c"rockchip,rk3588-mali" ), ()), (of::DeviceId ::new (c"arm,mali-valhall-csf" ), ()) ] ); -impl platform::Driver for TyrPlatformDriverData { +impl platform::Driver for TyrPlatformDriver {type IdInfo = (); -type Data <'bound> =Self ; +type Data <'bound> =TyrPlatformDriverData ;const OF_ID_TABLE :Option <of::IdTable <Self ::IdInfo >> =Some (&OF_TABLE );fn probe <'bound>( pdev: &'bound platform::Device <Core <'_>>, _info:Option <&'boundSelf ::IdInfo >, - ) ->impl PinInit <Self ,Error > + 'bound { + ) ->impl PinInit <Self ::Data <'bound>,Error > + 'bound {let core_clk =Clk ::get (pdev.as_ref (),Some (c"core" ))?;let stacks_clk =OptionalClk ::get (pdev.as_ref (),Some (c"stacks" ))?;let coregroup_clk =OptionalClk ::get (pdev.as_ref (),Some (c"coregroup" ))?;drivers/gpu/drm/tyr/tyr.rs +2
-2@@ -5,7 +5,7 @@//! The name "Tyr" is inspired by Norse mythology, reflecting Arm's tradition of //! naming their GPUs after Nordic mythological figures and places. -use crate ::driver::TyrPlatformDriverData ; +use crate ::driver::TyrPlatformDriver ;mod driver;mod file;@@ -14,7 +14,7 @@mod regs; kernel::module_platform_driver! { -type :TyrPlatformDriverData , +type :TyrPlatformDriver , name:"tyr" , authors: ["The Tyr driver authors" ], description:"Arm Mali Tyr DRM driver" ,
Re: [PATCH 1/2] gpu: drm: tyr: separate driver type from driver data
In reply to Danilo KrummrichQuoted 75 lines · Danilo Krummrich
Introduce TyrPlatformDriver as a unit struct for the
platform::Drivertrait implementation and keep TyrPlatformDriverData for the private driver data.Signed-off-by Danilo Krummrich <[email protected]>--- drivers/gpu/drm/tyr/driver.rs | 10 ++++++---- drivers/gpu/drm/tyr/tyr.rs | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-)drivers/gpu/drm/tyr/driver.rs +6
-4@@ -51,6 +51,8 @@/// Convenience type alias for the DRM device type for this driver. pub (crate )type TyrDrmDevice = drm::Device <TyrDrmDriver >; +pub (crate )struct TyrPlatformDriver ; +#[pin_data( PinnedDrop )] pub (crate )struct TyrPlatformDriverData { _device:ARef <TyrDrmDevice >,@@ -93,22 +95,22 @@ fn issue_soft_reset(dev: &Device<Bound>, iomem: &Devres<IoMem>) -> Result { kernel::of_device_table!(OF_TABLE ,MODULE_OF_TABLE , - <TyrPlatformDriverData as platform::Driver >::IdInfo , + <TyrPlatformDriver as platform::Driver >::IdInfo , [ (of::DeviceId ::new (c"rockchip,rk3588-mali" ), ()), (of::DeviceId ::new (c"arm,mali-valhall-csf" ), ()) ] ); -impl platform::Driver for TyrPlatformDriverData { +impl platform::Driver for TyrPlatformDriver {type IdInfo = (); -type Data <'bound> =Self ; +type Data <'bound> =TyrPlatformDriverData ;const OF_ID_TABLE :Option <of::IdTable <Self ::IdInfo >> =Some (&OF_TABLE );fn probe <'bound>( pdev: &'bound platform::Device <Core <'_>>, _info:Option <&'boundSelf ::IdInfo >, - ) ->impl PinInit <Self ,Error > + 'bound { + ) ->impl PinInit <Self ::Data <'bound>,Error > + 'bound {let core_clk =Clk ::get (pdev.as_ref (),Some (c"core" ))?;let stacks_clk =OptionalClk ::get (pdev.as_ref (),Some (c"stacks" ))?;let coregroup_clk =OptionalClk ::get (pdev.as_ref (),Some (c"coregroup" ))?;drivers/gpu/drm/tyr/tyr.rs +2
-2@@ -5,7 +5,7 @@//! The name "Tyr" is inspired by Norse mythology, reflecting Arm's tradition of //! naming their GPUs after Nordic mythological figures and places. -use crate ::driver::TyrPlatformDriverData ; +use crate ::driver::TyrPlatformDriver ;mod driver;mod file;@@ -14,7 +14,7 @@mod regs; kernel::module_platform_driver! { -type :TyrPlatformDriverData , +type :TyrPlatformDriver , name:"tyr" , authors: ["The Tyr driver authors" ], description:"Arm Mali Tyr DRM driver" ,Signature · 1 line
2.54.0
Re: [PATCH 1/2] gpu: drm: tyr: separate driver type from driver data
In reply to Danilo KrummrichQuoted 5 lines · Danilo Krummrich
Introduce TyrPlatformDriver as a unit struct for the
platform::Drivertrait implementation and keep TyrPlatformDriverData for the private driver data.Signed-off-by Danilo Krummrich <[email protected]>
Quoted 4 lines
--- drivers/gpu/drm/tyr/driver.rs | 10 ++++++---- drivers/gpu/drm/tyr/tyr.rs | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-)
Danilo Krummrich
maintainerPATCH 2/2 gpu: drm: tyr: use IoMem directly instead of Devres
In reply to Danilo KrummrichNow that IoMem is lifetime-parameterized, use it directly in probe rather than wrapping it in Devres and Arc. The I/O memory mapping is only used during probe and not stored in driver data, so device-managed revocation is unnecessary.
This removes the Devres access(dev) pattern from issue_soft_reset(), GpuInfo::new(), and l2_power_on(), simplifying register access.
--- drivers/gpu/drm/tyr/driver.rs | 19 ++++++------------- drivers/gpu/drm/tyr/gpu.rs | 13 +++---------- 2 files changed, 9 insertions(+), 23 deletions(-)
drivers/gpu/drm/tyr/driver.rs +6 -13
@@ -6,11 +6,9 @@ OptionalClk, // }, device::{ - Bound, Core, Device, // }, - devres::Devres, dma::{ Device as DmaDevice, DmaMask, //
@@ -30,7 +28,6 @@ sizes::SZ_2M, sync::{ aref::ARef, - Arc, Mutex, // }, time, //
@@ -44,7 +41,7 @@ regs::gpu_control::*, // }; -pub (crate )type IoMem = kernel::io::mem::IoMem <'static,SZ_2M >; +pub (crate )type IoMem <'a> = kernel::io::mem::IoMem <'a,SZ_2M >;pub (crate )struct TyrDrmDriver ;
@@ -74,15 +71,11 @@ pub(crate) struct TyrDrmDeviceData { pub(crate) gpu_info: GpuInfo, } -fn issue_soft_reset (dev: &Device <Bound >, iomem: &Devres <IoMem >) ->Result { -let io = (*iomem).access (dev)?; - io.write_reg (GPU_COMMAND ::reset (ResetMode ::SoftReset )); +fn issue_soft_reset (dev: &Device , iomem: &IoMem <'_>) ->Result { + iomem.write_reg (GPU_COMMAND ::reset (ResetMode ::SoftReset )); poll::read_poll_timeout ( - || { -let io = (*iomem).access (dev)?; -Ok (io.read (GPU_IRQ_RAWSTAT )) - }, + ||Ok (iomem.read (GPU_IRQ_RAWSTAT )), |status| status.reset_completed (), time::Delta ::from_millis (1 ), time::Delta::from_millis(100),
@@ -123,12 +116,12 @@ fn probe<'bound>(let sram_regulator =Regulator ::<regulator::Enabled >::get (pdev.as_ref (),c"sram" )?;let request = pdev.io_request_by_index (0 ).ok_or (ENODEV )?; -let iomem =Arc ::new (request.iomap_sized ::<SZ_2M >()?.into_devres ()?,GFP_KERNEL )?; +let iomem = request.iomap_sized ::<SZ_2M >()?;issue_soft_reset (pdev.as_ref (), &iomem)?; gpu::l2_power_on (pdev.as_ref (), &iomem)?; -let gpu_info =GpuInfo ::new (pdev.as_ref (), &iomem)?; +let gpu_info =GpuInfo ::new (&iomem)?; gpu_info.log (pdev.as_ref ());let pa_bits =MMU_FEATURES ::from_raw (gpu_info.mmu_features)
drivers/gpu/drm/tyr/gpu.rs +3 -10
@@ -9,7 +9,6 @@ Bound, Device, // }, - devres::Devres, io::{ poll, register::Array,
@@ -40,9 +39,7 @@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 io = (*iomem).access(dev)?; - + pub(crate) fn new(io: &IoMem<'_>) -> Result<Self> { Ok(Self(uapi::drm_panthor_gpu_info { gpu_id: io.read(GPU_ID).into_raw(), gpu_rev: io.read(REVIDR).into_raw(),
@@ -163,15 +160,11 @@ struct GpuModels { }];/// Powers on the l2 block. -pub (crate )fn l2_power_on (dev: &Device <Bound >, iomem: &Devres <IoMem >) ->Result { -let io = (*iomem).access (dev)?; +pub (crate )fn l2_power_on (dev: &Device , io: &IoMem <'_>) ->Result { io.write_reg (L2_PWRON_LO ::zeroed ().with_const_request ::<1 >()); poll::read_poll_timeout ( - || { -let io = (*iomem).access (dev)?; -Ok (io.read (L2_READY_LO )) - }, + ||Ok (io.read (L2_READY_LO )), |status| status.ready () ==1 ,Delta ::from_millis (1 ), Delta::from_millis(100),
Signature · 1 line
2.54.0
Re: [PATCH 2/2] gpu: drm: tyr: use IoMem directly instead of Devres
Quoted 5 lines · Danilo Krummrich
Now that IoMem is lifetime-parameterized, use it directly in probe rather than wrapping it in Devres and Arc. The I/O memory mapping is only used during probe and not stored in driver data, so device-managed revocation is unnecessary.
Quoted 8 lines
This removes the Devres access(dev) pattern from
issue_soft_reset(),GpuInfo::new(), andl2_power_on(), simplifying register access.Signed-off-by Danilo Krummrich <[email protected]>--- drivers/gpu/drm/tyr/driver.rs | 19 ++++++------------- drivers/gpu/drm/tyr/gpu.rs | 13 +++---------- 2 files changed, 9 insertions(+), 23 deletions(-)
Re: [PATCH 2/2] gpu: drm: tyr: use IoMem directly instead of Devres
In reply to Danilo KrummrichQuoted 94 lines · Danilo Krummrich
Now that IoMem is lifetime-parameterized, use it directly in probe rather than wrapping it in Devres and Arc. The I/O memory mapping is only used during probe and not stored in driver data, so device-managed revocation is unnecessary.
This removes the Devres access(dev) pattern from
issue_soft_reset(),GpuInfo::new(), andl2_power_on(), simplifying register access.Signed-off-by Danilo Krummrich <[email protected]>--- drivers/gpu/drm/tyr/driver.rs | 19 ++++++------------- drivers/gpu/drm/tyr/gpu.rs | 13 +++---------- 2 files changed, 9 insertions(+), 23 deletions(-)drivers/gpu/drm/tyr/driver.rs +6
-13@@ -6,11 +6,9 @@ OptionalClk, // }, device::{ - Bound, Core, Device, // }, - devres::Devres, dma::{ Device as DmaDevice, DmaMask, //@@ -30,7 +28,6 @@ sizes::SZ_2M, sync::{ aref::ARef, - Arc, Mutex, // }, time, //@@ -44,7 +41,7 @@ regs::gpu_control::*, // }; -pub (crate )type IoMem = kernel::io::mem::IoMem <'static,SZ_2M >; +pub (crate )type IoMem <'a> = kernel::io::mem::IoMem <'a,SZ_2M >;pub (crate )struct TyrDrmDriver ;@@ -74,15 +71,11 @@ pub(crate) struct TyrDrmDeviceData { pub(crate) gpu_info: GpuInfo, } -fn issue_soft_reset (dev: &Device <Bound >, iomem: &Devres <IoMem >) ->Result { -let io = (*iomem).access (dev)?; - io.write_reg (GPU_COMMAND ::reset (ResetMode ::SoftReset )); +fn issue_soft_reset (dev: &Device , iomem: &IoMem <'_>) ->Result { + iomem.write_reg (GPU_COMMAND ::reset (ResetMode ::SoftReset )); poll::read_poll_timeout ( - || { -let io = (*iomem).access (dev)?; -Ok (io.read (GPU_IRQ_RAWSTAT )) - }, + ||Ok (iomem.read (GPU_IRQ_RAWSTAT )), |status| status.reset_completed (), time::Delta ::from_millis (1 ), time::Delta::from_millis(100),@@ -123,12 +116,12 @@ fn probe<'bound>(let sram_regulator =Regulator ::<regulator::Enabled >::get (pdev.as_ref (),c"sram" )?;let request = pdev.io_request_by_index (0 ).ok_or (ENODEV )?; -let iomem =Arc ::new (request.iomap_sized ::<SZ_2M >()?.into_devres ()?,GFP_KERNEL )?; +let iomem = request.iomap_sized ::<SZ_2M >()?;issue_soft_reset (pdev.as_ref (), &iomem)?; gpu::l2_power_on (pdev.as_ref (), &iomem)?; -let gpu_info =GpuInfo ::new (pdev.as_ref (), &iomem)?; +let gpu_info =GpuInfo ::new (&iomem)?; gpu_info.log (pdev.as_ref ());let pa_bits =MMU_FEATURES ::from_raw (gpu_info.mmu_features)drivers/gpu/drm/tyr/gpu.rs +0
-1@@ -9,7 +9,6 @@ Bound, Device, // }, - devres::Devres, io::{ poll, register::Array,
drivers/gpu/drm/tyr/gpu.rs line 42
Quoted 7 lines
drivers/gpu/drm/tyr/gpu.rs +1
-3@@ -40,9 +39,7 @@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 io = (*iomem).access (dev)?; - +pub (crate )fn new (io: &IoMem <'_>) ->Result <Self > {
Perhaps a future patch can remove this now unnecessary looking Result in the return type.
Re: [PATCH 2/2] gpu: drm: tyr: use IoMem directly instead of Devres
Quoted 97 lines · Eliot Courtney
Quoted 96 lines · Danilo Krummrich
Now that IoMem is lifetime-parameterized, use it directly in probe rather than wrapping it in Devres and Arc. The I/O memory mapping is only used during probe and not stored in driver data, so device-managed revocation is unnecessary.
This removes the Devres access(dev) pattern from
issue_soft_reset(),GpuInfo::new(), andl2_power_on(), simplifying register access.Signed-off-by Danilo Krummrich <[email protected]>--- drivers/gpu/drm/tyr/driver.rs | 19 ++++++------------- drivers/gpu/drm/tyr/gpu.rs | 13 +++---------- 2 files changed, 9 insertions(+), 23 deletions(-)drivers/gpu/drm/tyr/driver.rs +6
-13@@ -6,11 +6,9 @@ OptionalClk, // }, device::{ - Bound, Core, Device, // }, - devres::Devres, dma::{ Device as DmaDevice, DmaMask, //@@ -30,7 +28,6 @@ sizes::SZ_2M, sync::{ aref::ARef, - Arc, Mutex, // }, time, //@@ -44,7 +41,7 @@ regs::gpu_control::*, // }; -pub (crate )type IoMem = kernel::io::mem::IoMem <'static,SZ_2M >; +pub (crate )type IoMem <'a> = kernel::io::mem::IoMem <'a,SZ_2M >;pub (crate )struct TyrDrmDriver ;@@ -74,15 +71,11 @@ pub(crate) struct TyrDrmDeviceData { pub(crate) gpu_info: GpuInfo, } -fn issue_soft_reset (dev: &Device <Bound >, iomem: &Devres <IoMem >) ->Result { -let io = (*iomem).access (dev)?; - io.write_reg (GPU_COMMAND ::reset (ResetMode ::SoftReset )); +fn issue_soft_reset (dev: &Device , iomem: &IoMem <'_>) ->Result { + iomem.write_reg (GPU_COMMAND ::reset (ResetMode ::SoftReset )); poll::read_poll_timeout ( - || { -let io = (*iomem).access (dev)?; -Ok (io.read (GPU_IRQ_RAWSTAT )) - }, + ||Ok (iomem.read (GPU_IRQ_RAWSTAT )), |status| status.reset_completed (), time::Delta ::from_millis (1 ), time::Delta::from_millis(100),@@ -123,12 +116,12 @@ fn probe<'bound>(let sram_regulator =Regulator ::<regulator::Enabled >::get (pdev.as_ref (),c"sram" )?;let request = pdev.io_request_by_index (0 ).ok_or (ENODEV )?; -let iomem =Arc ::new (request.iomap_sized ::<SZ_2M >()?.into_devres ()?,GFP_KERNEL )?; +let iomem = request.iomap_sized ::<SZ_2M >()?;issue_soft_reset (pdev.as_ref (), &iomem)?; gpu::l2_power_on (pdev.as_ref (), &iomem)?; -let gpu_info =GpuInfo ::new (pdev.as_ref (), &iomem)?; +let gpu_info =GpuInfo ::new (&iomem)?; gpu_info.log (pdev.as_ref ());let pa_bits =MMU_FEATURES ::from_raw (gpu_info.mmu_features)drivers/gpu/drm/tyr/gpu.rs +0
-1@@ -9,7 +9,6 @@ Bound, Device, // }, - devres::Devres, io::{ poll, register::Array,@@ -40,9 +39,7 @@pub (crate )struct GpuInfo (pub (crate ) uapi::drm_panthor_gpu_info );
Quoted 8 lines
drivers/gpu/drm/tyr/gpu.rs line 42
Quoted 5 lines
drivers/gpu/drm/tyr/gpu.rs +1
-3impl GpuInfo { -pub (crate )fn new (dev: &Device <Bound >, iomem: &Devres <IoMem >) ->Result <Self > { -let io = (*iomem).access (dev)?; - +pub (crate )fn new (io: &IoMem <'_>) ->Result <Self > {Perhaps a future patch can remove this now unnecessary looking Result in the return type.
Oh that's right now that we don't have: let io = (*iomem).access(dev)? we don't need the Result anymore.
Danilo, I can add this fix to our fw-boot series which I'm preparing to sit on top of these changes.
Quoted 3 lines
Reviewed-by Eliot Courtney <[email protected]>
Danilo Krummrich
maintainerRe: [PATCH 2/2] gpu: drm: tyr: use IoMem directly instead of Devres
Quoted 14 lines · Deborah Brouwer
Quoted 4 lines · Eliot Courtney
Quoted 3 lines · Danilo Krummrich
drivers/gpu/drm/tyr/gpu.rs +0
-0@@ -40,9 +39,7 @@pub (crate )struct GpuInfo (pub (crate ) uapi::drm_panthor_gpu_info );Quoted 8 lines
drivers/gpu/drm/tyr/gpu.rs line 42
Quoted 5 lines
drivers/gpu/drm/tyr/gpu.rs +1
-3impl GpuInfo { -pub (crate )fn new (dev: &Device <Bound >, iomem: &Devres <IoMem >) ->Result <Self > { -let io = (*iomem).access (dev)?; - +pub (crate )fn new (io: &IoMem <'_>) ->Result <Self > {Perhaps a future patch can remove this now unnecessary looking Result in the return type.
Quoted 5 lines
Oh that's right now that we don't have: let io = (*iomem).access(dev)? we don't need the Result anymore.
Danilo, I can add this fix to our fw-boot series which I'm preparing to sit on top of these changes.
I can send a v2, fix it up on apply when I get an ACK, have Alice fix it up on apply, or have it done in a follow-up as you offer -- just let me know. :)
Quoted 3 lines
Quoted 3 lines
Reviewed-by Eliot Courtney <[email protected]>
Gary Guo
reviewerRe: [PATCH 2/2] gpu: drm: tyr: use IoMem directly instead of Devres
Quoted 15 lines · Danilo Krummrich
Quoted 14 lines · Deborah Brouwer
Quoted 12 lines · Eliot Courtney
drivers/gpu/drm/tyr/gpu.rs line 42
Quoted 8 lines · Danilo Krummrich
drivers/gpu/drm/tyr/gpu.rs +1
-3@@ -40,9 +39,7 @@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 io = (*iomem).access (dev)?; - +pub (crate )fn new (io: &IoMem <'_>) ->Result <Self > {Perhaps a future patch can remove this now unnecessary looking Result in the return type.
Quoted 9 lines
Quoted 5 lines
Oh that's right now that we don't have: let io = (*iomem).access(dev)? we don't need the Result anymore.
Danilo, I can add this fix to our fw-boot series which I'm preparing to sit on top of these changes.
I can send a v2, fix it up on apply when I get an ACK, have Alice fix it up on apply, or have it done in a follow-up as you offer -- just let me know. :)
I think it makes sense to have a v2 with this, as getting rid of impossible failure paths is the reason we go for lifetime in the first place, so this is a good demonstration of that benefit.
Best,
Gary
Re: [PATCH 2/2] gpu: drm: tyr: use IoMem directly instead of Devres
Quoted 22 lines · Gary Guo
Quoted 21 lines · Danilo Krummrich
Quoted 19 lines · Deborah Brouwer
Quoted 4 lines · Eliot Courtney
Quoted 3 lines · Danilo Krummrich
drivers/gpu/drm/tyr/gpu.rs +0
-0@@ -40,9 +39,7 @@pub (crate )struct GpuInfo (pub (crate ) uapi::drm_panthor_gpu_info );Quoted 8 lines
drivers/gpu/drm/tyr/gpu.rs line 42
Quoted 5 lines
drivers/gpu/drm/tyr/gpu.rs +1
-3impl GpuInfo { -pub (crate )fn new (dev: &Device <Bound >, iomem: &Devres <IoMem >) ->Result <Self > { -let io = (*iomem).access (dev)?; - +pub (crate )fn new (io: &IoMem <'_>) ->Result <Self > {Perhaps a future patch can remove this now unnecessary looking Result in the return type.
Oh that's right now that we don't have: let io = (*iomem).access(dev)? we don't need the Result anymore.
Danilo, I can add this fix to our fw-boot series which I'm preparing to sit on top of these changes.
Quoted 7 lines
Quoted 3 lines
I can send a v2, fix it up on apply when I get an ACK, have Alice fix it up on apply, or have it done in a follow-up as you offer -- just let me know. :)
I think it makes sense to have a v2 with this, as getting rid of impossible failure paths is the reason we go for lifetime in the first place, so this is a good demonstration of that benefit.
yeah v2 is probably the cleanest/easiest way to fix.
And while here it would be nice to keep the subject prefix consistent, we've been using "drm/tyr:"
Quoted 3 lines
Best,
Gary
Re: [PATCH 2/2] gpu: drm: tyr: use IoMem directly instead of Devres
In reply to Danilo KrummrichQuoted 125 lines · Danilo Krummrich
Now that IoMem is lifetime-parameterized, use it directly in probe rather than wrapping it in Devres and Arc. The I/O memory mapping is only used during probe and not stored in driver data, so device-managed revocation is unnecessary.
This removes the Devres access(dev) pattern from
issue_soft_reset(),GpuInfo::new(), andl2_power_on(), simplifying register access.Signed-off-by Danilo Krummrich <[email protected]>--- drivers/gpu/drm/tyr/driver.rs | 19 ++++++------------- drivers/gpu/drm/tyr/gpu.rs | 13 +++---------- 2 files changed, 9 insertions(+), 23 deletions(-)drivers/gpu/drm/tyr/driver.rs +6
-13@@ -6,11 +6,9 @@ OptionalClk, // }, device::{ - Bound, Core, Device, // }, - devres::Devres, dma::{ Device as DmaDevice, DmaMask, //@@ -30,7 +28,6 @@ sizes::SZ_2M, sync::{ aref::ARef, - Arc, Mutex, // }, time, //@@ -44,7 +41,7 @@ regs::gpu_control::*, // }; -pub (crate )type IoMem = kernel::io::mem::IoMem <'static,SZ_2M >; +pub (crate )type IoMem <'a> = kernel::io::mem::IoMem <'a,SZ_2M >;pub (crate )struct TyrDrmDriver ;@@ -74,15 +71,11 @@ pub(crate) struct TyrDrmDeviceData { pub(crate) gpu_info: GpuInfo, } -fn issue_soft_reset (dev: &Device <Bound >, iomem: &Devres <IoMem >) ->Result { -let io = (*iomem).access (dev)?; - io.write_reg (GPU_COMMAND ::reset (ResetMode ::SoftReset )); +fn issue_soft_reset (dev: &Device , iomem: &IoMem <'_>) ->Result { + iomem.write_reg (GPU_COMMAND ::reset (ResetMode ::SoftReset )); poll::read_poll_timeout ( - || { -let io = (*iomem).access (dev)?; -Ok (io.read (GPU_IRQ_RAWSTAT )) - }, + ||Ok (iomem.read (GPU_IRQ_RAWSTAT )), |status| status.reset_completed (), time::Delta ::from_millis (1 ), time::Delta::from_millis(100),@@ -123,12 +116,12 @@ fn probe<'bound>(let sram_regulator =Regulator ::<regulator::Enabled >::get (pdev.as_ref (),c"sram" )?;let request = pdev.io_request_by_index (0 ).ok_or (ENODEV )?; -let iomem =Arc ::new (request.iomap_sized ::<SZ_2M >()?.into_devres ()?,GFP_KERNEL )?; +let iomem = request.iomap_sized ::<SZ_2M >()?;issue_soft_reset (pdev.as_ref (), &iomem)?; gpu::l2_power_on (pdev.as_ref (), &iomem)?; -let gpu_info =GpuInfo ::new (pdev.as_ref (), &iomem)?; +let gpu_info =GpuInfo ::new (&iomem)?; gpu_info.log (pdev.as_ref ());let pa_bits =MMU_FEATURES ::from_raw (gpu_info.mmu_features)drivers/gpu/drm/tyr/gpu.rs +3
-10@@ -9,7 +9,6 @@ Bound, Device, // }, - devres::Devres, io::{ poll, register::Array,@@ -40,9 +39,7 @@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 io = (*iomem).access(dev)?; - + pub(crate) fn new(io: &IoMem<'_>) -> Result<Self> { Ok(Self(uapi::drm_panthor_gpu_info { gpu_id: io.read(GPU_ID).into_raw(), gpu_rev: io.read(REVIDR).into_raw(),@@ -163,15 +160,11 @@ struct GpuModels { }];/// Powers on the l2 block. -pub (crate )fn l2_power_on (dev: &Device <Bound >, iomem: &Devres <IoMem >) ->Result { -let io = (*iomem).access (dev)?; +pub (crate )fn l2_power_on (dev: &Device , io: &IoMem <'_>) ->Result { io.write_reg (L2_PWRON_LO ::zeroed ().with_const_request ::<1 >()); poll::read_poll_timeout ( - || { -let io = (*iomem).access (dev)?; -Ok (io.read (L2_READY_LO )) - }, + ||Ok (io.read (L2_READY_LO )), |status| status.ready () ==1 ,Delta ::from_millis (1 ), Delta::from_millis(100),Signature · 1 line
2.54.0