drm/tyr: use pin-init self-referential support
Subsystems (4)
Danilo Krummrich
maintainerv2 cover drm/tyr: use pin-init self-referential support
This series uses pin-init's self-referential support to replace Arcs for resources whose lifetimes are bounded by their owners.
It also cleans up lifetime names and simplifies firmware loading cleanup with ScopeGuard.
Changes in v2:
- Use generic names for covariant lifetime parameters and resource names for invariant ones.
- Include VmAsData, GpuVmData, the VM operation types and PtUpdateContext in the lifetime cleanup.
- Drop the pin-init lint suppression patch and temporarily allow clippy::multiple_bound_locations in Tyr instead.
Danilo Krummrich (3):
drm/tyr: clarify resource lifetime names drm/tyr: use pin-init self-referential support drm/tyr: use ScopeGuard for firmware loading cleanup
drivers/gpu/drm/tyr/driver.rs | 38 +++-- drivers/gpu/drm/tyr/fw.rs | 151 +++++++++---------- drivers/gpu/drm/tyr/gem.rs | 15 +- drivers/gpu/drm/tyr/mmu.rs | 56 ++++---- drivers/gpu/drm/tyr/mmu/address_space.rs | 54 +++---- drivers/gpu/drm/tyr/tyr.rs | 5 + drivers/gpu/drm/tyr/vm.rs | 175 +++++++++++------------ 7 files changed, 247 insertions(+), 247 deletions(-)
base-commit: abfb640b2374e26de8ff81d488c39d8254db538e
Signature · 1 line
2.56.1
Danilo Krummrich
maintainerPATCH v2 1/3 drm/tyr: clarify resource lifetime names
Use generic names for covariant lifetime parameters and 'res for invariant device resource lifetimes throughout Tyr's firmware, buffer, VM and MMU code.
Apply this convention consistently in preparation for introducing additional borrow lifetimes with self-referential pin-init.
--- drivers/gpu/drm/tyr/fw.rs | 26 +++---- drivers/gpu/drm/tyr/gem.rs | 8 +- drivers/gpu/drm/tyr/mmu.rs | 24 +++--- drivers/gpu/drm/tyr/mmu/address_space.rs | 44 +++++------ drivers/gpu/drm/tyr/vm.rs | 96 ++++++++++++------------ 5 files changed, 99 insertions(+), 99 deletions(-)
drivers/gpu/drm/tyr/fw.rs +13 -13
@@ -131,7 +131,7 @@ fn try_from_fw(value: u32) -> Result<Self> { }/// A parsed section of the firmware binary. -struct Section <'drm> { +struct Section <'res> {// Raw firmware section data for reset purposes #[expect(dead_code)] data:KVec <u8 >,
@@ -139,23 +139,23 @@ struct Section<'drm> {// Keep the BO backing this firmware section so that both the // GPU mapping and CPU mapping remain valid until the Section is dropped. #[expect(dead_code)] - mem: gem::KernelBo<'drm>, + mem: gem::KernelBo<'res>, }/// Loaded firmware with sections mapped into MCU VM. -pub (crate )struct Firmware <'drm> { +pub (crate )struct Firmware <'res> {/// Iomem need to access registers. - iomem:Arc <IoMem <'drm>>, + iomem:Arc <IoMem <'res>>,/// MCU VM. - vm:Arc <Vm <'drm>>, + vm:Arc <Vm <'res>>,/// List of firmware sections. #[expect(dead_code)] - sections:KVec <Section <'drm>>, + sections:KVec <Section <'res>>, } -impl <'drm>Drop for Firmware <'drm> { +impl <'res>Drop for Firmware <'res> {fn drop (&mut self) {// Stop the MCU before releasing its firmware mappings and memory. let _ = self.stop ();
@@ -165,8 +165,8 @@ fn drop(&mut self) { } } -impl <'drm>Firmware <'drm> { -fn init_section_mem (dev: &Device , mem: &mut KernelBo <'drm>, data: &KVec <u8 >) ->Result { +impl <'res>Firmware <'res> { +fn init_section_mem (dev: &Device , mem: &mut KernelBo <'res>, data: &KVec <u8 >) ->Result {if data.is_empty () {return Ok (()); }
@@ -213,12 +213,12 @@ fn load(/// Load firmware and map sections into MCU VM. pub (crate )fn new ( - dev: &'drmDevice <Bound >, - iomem:Arc <IoMem <'drm>>, + dev: &'resDevice <Bound >, + iomem:Arc <IoMem <'res>>, ddev: &TyrDrmDevice , - mmu:ArcBorrow <'_,Mmu <'drm>>, + mmu:ArcBorrow <'_,Mmu <'res>>, gpu_info: &GpuInfo , - ) ->Result <Firmware <'drm>> { + ) ->Result <Firmware <'res>> {let vm =Vm ::new (dev, ddev, mmu, gpu_info)?; vm.activate ()?;
drivers/gpu/drm/tyr/gem.rs +4 -4
@@ -82,16 +82,16 @@ pub(crate) enum KernelBoVaAlloc {/// a GEM object with automatic GPU virtual address (VA) space mapping and cleanup. /// /// When dropped, the buffer is automatically unmapped from the GPU VA space. -pub (crate )struct KernelBo <'drm> { +pub (crate )struct KernelBo <'res> {/// The underlying GEM buffer object. bo:ARef <Bo >,/// The GPU VM this buffer is mapped into. - vm:Arc <Vm <'drm>>, + vm:Arc <Vm <'res>>,/// The GPU VA range occupied by this buffer. va_range:Range <u64 >, } -impl <'drm>KernelBo <'drm> { +impl <'res>KernelBo <'res> {/// Creates a new kernel-owned buffer object and maps it into GPU VA space. /// /// This function allocates a new shmem-backed GEM object and immediately maps
@@ -99,7 +99,7 @@ impl<'drm> KernelBo<'drm> {/// cleaned up when the [`KernelBo`] is dropped. pub (crate )fn new ( ddev: &TyrDrmDevice , - vm:Arc <Vm <'drm>>, + vm:Arc <Vm <'res>>, size:u64 , va_alloc:KernelBoVaAlloc , flags: VmMapFlags,
drivers/gpu/drm/tyr/mmu.rs +12 -12
@@ -43,23 +43,23 @@pub (crate )mod address_space; -pub (crate )type AsSlotManager <'drm> =SlotManager <AddressSpaceManager <'drm>,MAX_AS >; +pub (crate )type AsSlotManager <'res> =SlotManager <AddressSpaceManager <'res>,MAX_AS >;/// Locked wrapper for carrying out virtual memory (VM) operations on the MMU. #[pin_data] -pub (crate )struct Mmu <'drm> { +pub (crate )struct Mmu <'res> {/// Slot Manager instance used to allocate hardware slots and write to MMU registers. #[pin] -pub (crate ) as_manager:Mutex <AsSlotManager <'drm>>, +pub (crate ) as_manager:Mutex <AsSlotManager <'res>>, } -impl <'drm>Mmu <'drm> { +impl <'res>Mmu <'res> {/// Create an MMU component for this device. pub (crate )fn new ( - dev: &'drmDevice <Bound >, - iomem:ArcBorrow <'_,IoMem <'drm>>, + dev: &'resDevice <Bound >, + iomem:ArcBorrow <'_,IoMem <'res>>, gpu_info: &GpuInfo , - ) ->Result <Arc <Mmu <'drm>>> { + ) ->Result <Arc <Mmu <'res>>> {let present =AS_PRESENT ::from_raw (gpu_info.as_present).present ().get ();let slot_count = present.count_ones ().try_into ()?;
@@ -81,17 +81,17 @@ pub(crate) fn new(/// Assign a VM to an AS slot, provide a translation table, /// and update the MMU to make the VM resident. -pub (crate )fn activate_vm (&self, vm_as_data:ArcBorrow <'_,VmAsData <'drm>>) ->Result { +pub (crate )fn activate_vm (&self, vm_as_data:ArcBorrow <'_,VmAsData <'res>>) ->Result { self.as_manager.lock ().activate_vm (vm_as_data) }/// Evict a VM from its AS slot and flush the MMU. -pub (crate )fn deactivate_vm (&self, vm_as_data: &VmAsData <'drm>) ->Result { +pub (crate )fn deactivate_vm (&self, vm_as_data: &VmAsData <'res>) ->Result { self.as_manager.lock ().deactivate_vm (vm_as_data) }/// Flush MMU translation caches after a VM update. -pub (crate )fn flush_vm (&self, vm_as_data: &VmAsData <'drm>) ->Result { +pub (crate )fn flush_vm (&self, vm_as_data: &VmAsData <'res>) ->Result { self.as_manager.lock ().flush_vm (vm_as_data) }
@@ -103,7 +103,7 @@ pub(crate) fn flush_vm(&self, vm_as_data: &VmAsData<'drm>) -> Result {/// If the VM is not resident, this is a NOP. pub (crate )fn start_vm_update ( &self, - vm_as_data: &VmAsData <'drm>, + vm_as_data: &VmAsData <'res>, region: &Range <u64 >, ) ->Result { self.as_manager.lock ().start_vm_update (vm_as_data, region)
@@ -114,7 +114,7 @@ pub(crate) fn start_vm_update(/// If the VM is resident, this will let GPU accesses on the updated /// range go through, in case any of them were blocked. /// If the VM is not resident, this is a NOP. -pub (crate )fn end_vm_update (&self, vm_as_data: &VmAsData <'drm>) ->Result { +pub (crate )fn end_vm_update (&self, vm_as_data: &VmAsData <'res>) ->Result { self.as_manager.lock ().end_vm_update (vm_as_data) } }
drivers/gpu/drm/tyr/mmu/address_space.rs +22 -22
122 lines not on this page · raw message
drivers/gpu/drm/tyr/vm.rs +48 -48
239 lines not on this page · raw message
Signature · 1 line
2.56.1
Re: [PATCH v2 1/3] drm/tyr: clarify resource lifetime names
Quoted 9 lines · Danilo Krummrich
Use generic names for covariant lifetime parameters and 'res for invariant device resource lifetimes throughout Tyr's firmware, buffer, VM and MMU code.
Apply this convention consistently in preparation for introducing additional borrow lifetimes with self-referential pin-init.
Signed-off-by Danilo Krummrich <[email protected]>
Re: [PATCH v2 1/3] drm/tyr: clarify resource lifetime names
In reply to Danilo KrummrichQuoted 8 lines · Danilo Krummrich
Use generic names for covariant lifetime parameters and 'res for invariant device resource lifetimes throughout Tyr's firmware, buffer, VM and MMU code.
Apply this convention consistently in preparation for introducing additional borrow lifetimes with self-referential pin-init.
Signed-off-by Danilo Krummrich <[email protected]>
Quoted 7 lines
--- drivers/gpu/drm/tyr/fw.rs | 26 +++---- drivers/gpu/drm/tyr/gem.rs | 8 +- drivers/gpu/drm/tyr/mmu.rs | 24 +++--- drivers/gpu/drm/tyr/mmu/address_space.rs | 44 +++++------ drivers/gpu/drm/tyr/vm.rs | 96 ++++++++++++------------ 5 files changed, 99 insertions(+), 99 deletions(-)
Danilo Krummrich
maintainerPATCH v2 2/3 drm/tyr: use pin-init self-referential support
In reply to Danilo KrummrichNow that pin-init supports self-referential structs, Arc is no longer needed just to share resources whose lifetimes are bounded by their owners.
Use pin-init's self-referential support to share the MMIO mapping, MMU and firmware VM through borrows instead of Arc, avoiding their separate allocations and reference counts.
Hide the invariant resource lifetime shared by the VM and its sections behind an existential lifetime that outlives 'mmu, so Firmware only needs a single lifetime parameter.
--- drivers/gpu/drm/tyr/driver.rs | 38 +++--- drivers/gpu/drm/tyr/fw.rs | 152 ++++++++++++----------- drivers/gpu/drm/tyr/gem.rs | 15 +-- drivers/gpu/drm/tyr/mmu.rs | 36 +++--- drivers/gpu/drm/tyr/mmu/address_space.rs | 14 +-- drivers/gpu/drm/tyr/tyr.rs | 5 + drivers/gpu/drm/tyr/vm.rs | 93 +++++++------- 7 files changed, 179 insertions(+), 174 deletions(-)
drivers/gpu/drm/tyr/driver.rs +18 -20
@@ -29,7 +29,7 @@ regulator::Regulator, sizes::SZ_2M, sync::{ - Arc, + aref::ARef, Mutex, // }, time, //
@@ -71,7 +71,14 @@ pub(crate) struct TyrDrmRegistrationData<'drm> { pub(crate) pdev: &'drm platform::Device<Bound>,/// Firmware sections. - pub(crate) fw: Firmware<'drm>, +#[pin] +#[uses('mmu: invariant)] + pub(crate) fw: Firmware<'mmu>, + +/// MMU shared by the firmware and its buffer objects. +#[pin] +#[uses('iomem: invariant)] + mmu: Mmu<'iomem>,#[pin] clks: Mutex<Clocks>,
@@ -80,7 +87,7 @@ pub(crate) struct TyrDrmRegistrationData<'drm> { regulators: Mutex<Regulators>,/// GPU MMIO register mapping. - pub(crate) iomem: Arc<IoMem<'drm>>, + pub(crate) iomem: IoMem<'drm>,/// GPU information read from hardware during probe. pub(crate) gpu_info: GpuInfo,
@@ -135,7 +142,7 @@ fn probe<'bound>(let request = pdev.io_request_by_index (0 ).ok_or (ENODEV )?; -let iomem =Arc ::new (request.iomap_sized ::<SZ_2M >()?,GFP_KERNEL )?; +let iomem = request.iomap_sized ::<SZ_2M >()?;issue_soft_reset (pdev.as_ref (), &iomem)?; gpu::l2_power_on (pdev.as_ref (), &iomem)?;
@@ -152,18 +159,7 @@ fn probe<'bound>(unsafe { pdev.dma_set_mask_and_coherent (DmaMask ::try_new (pa_bits)?)? };let unreg_dev = drm::UnregisteredDevice ::<TyrDrmDriver >::new (pdev)?; - -let mmu =Mmu ::new (pdev.as_ref (), iomem.as_arc_borrow (), &gpu_info)?; - -let firmware =Firmware ::new ( - pdev.as_ref (), - iomem.clone (), - &unreg_dev, - mmu.as_arc_borrow (), - &gpu_info, - )?; - - firmware.boot ()?; +let ddev =ARef ::from (&*unreg_dev); Ok(try_pin_init!(TyrPlatformDriverData { // SAFETY: `_reg` is stored in `TyrPlatformDriverData` and dropped when the
@@ -171,9 +167,13 @@ fn probe<'bound>( _reg <- unsafe { drm::Registration::new( pdev.as_ref(), unreg_dev, - pin_init!(TyrDrmRegistrationData { + try_pin_init!(TyrDrmRegistrationData { + iomem, + gpu_info, + mmu <- Mmu::new(pdev.as_ref(), iomem, gpu_info), + fw <- Firmware::new(pdev.as_ref(), iomem, &ddev, mmu.get_ref(), gpu_info), + _: { fw.boot()?; }, pdev, - fw: firmware, clks <- new_mutex!(Clocks { core: core_clk, stacks: stacks_clk,
@@ -183,8 +183,6 @@ fn probe<'bound>( _mali: mali_regulator, _sram: sram_regulator, }), - iomem, - gpu_info, }), )}, _: { dev_dbg!(pdev, "Tyr initialized correctly.") },
drivers/gpu/drm/tyr/fw.rs +79 -73
213 lines not on this page · raw message
drivers/gpu/drm/tyr/gem.rs +6 -9
@@ -12,10 +12,7 @@ shmem, // }, prelude::*, - sync::{ - aref::ARef, - Arc, // - }, // + sync::aref::ARef, // };use crate ::{
@@ -82,16 +79,16 @@ pub(crate) enum KernelBoVaAlloc {/// a GEM object with automatic GPU virtual address (VA) space mapping and cleanup. /// /// When dropped, the buffer is automatically unmapped from the GPU VA space. -pub (crate )struct KernelBo <'res> { +pub (crate )struct KernelBo <'a, 'res> {/// The underlying GEM buffer object. bo:ARef <Bo >,/// The GPU VM this buffer is mapped into. - vm:Arc <Vm <'res>>, + vm: &'aVm <'a, 'res>,/// The GPU VA range occupied by this buffer. va_range:Range <u64 >, } -impl <'res>KernelBo <'res> { +impl <'a, 'res>KernelBo <'a, 'res> {/// Creates a new kernel-owned buffer object and maps it into GPU VA space. /// /// This function allocates a new shmem-backed GEM object and immediately maps
@@ -99,7 +96,7 @@ impl<'res> KernelBo<'res> {/// cleaned up when the [`KernelBo`] is dropped. pub (crate )fn new ( ddev: &TyrDrmDevice , - vm:Arc <Vm <'res>>, + vm: &'aVm <'a, 'res>, size:u64 , va_alloc:KernelBoVaAlloc , flags: VmMapFlags,
@@ -138,7 +135,7 @@ pub(crate) fn bo(&self) -> &Bo { } } -impl Drop for KernelBo <'_> { +impl Drop for KernelBo <'_, '_> {fn drop (&mut self) {let va = self.va_range.start;let size = self.va_range.end - self.va_range.start;
drivers/gpu/drm/tyr/mmu.rs +18 -18
@@ -21,7 +21,6 @@ new_mutex, prelude::*, sync::{ -Arc ,ArcBorrow ,Mutex ,// }, //
@@ -57,26 +56,27 @@ impl<'res> Mmu<'res> {/// Create an MMU component for this device. pub (crate )fn new ( dev: &'resDevice <Bound >, - iomem:ArcBorrow <'_,IoMem <'res>>, + iomem: &'resIoMem <'res>, gpu_info: &GpuInfo , - ) ->Result <Arc <Mmu <'res>>> { + ) ->impl PinInit <Self ,Error > + 'res {let present =AS_PRESENT ::from_raw (gpu_info.as_present).present ().get (); -let slot_count = present.count_ones ().try_into ()?; +try_pin_init! (Self { + as_manager <- { +let slot_count = present.count_ones ().try_into ()?; -let address_space_manager =AddressSpaceManager ::new (dev, iomem.into (), present)?; -let as_slot_manager = -SlotManager ::new (address_space_manager, slot_count).inspect_err (|e| { -dev_err! ( - dev, -"Failed to initialize MMU slot manager with {} slots: {:?}" , - slot_count, - e - ); - })?; -let mmu_init =try_pin_init! (Self { - as_manager <-new_mutex! (as_slot_manager), - }); -Arc ::pin_init (mmu_init,GFP_KERNEL ) +let address_space_manager =AddressSpaceManager ::new (dev, iomem, present)?; +let as_slot_manager = +SlotManager ::new (address_space_manager, slot_count).inspect_err (|e| { +dev_err! ( + dev, +"Failed to initialize MMU slot manager with {} slots: {:?}" , + slot_count, + e + ); + })?; +new_mutex! (as_slot_manager) + }, + }) }/// Assign a VM to an AS slot, provide a translation table,
drivers/gpu/drm/tyr/mmu/address_space.rs +7 -7
@@ -152,7 +152,7 @@ pub(crate) struct AddressSpaceManager<'a> { dev: &'a Device<Bound>,/// Memory-mapped I/O region for GPU register access. - iomem: Arc<IoMem<'a>>, + iomem: &'a IoMem<'a>, /// Bitmask of present address space slots from GPU_AS_PRESENT register. as_present: u32,
@@ -165,7 +165,7 @@ impl<'a> AddressSpaceManager<'a> {/// I/O memory region, along with the bitmask of available AS slots. pub (super )fn new ( dev: &'aDevice <Bound >, - iomem:Arc <IoMem <'a>>, + iomem: &'aIoMem <'a>, as_present:u32 , ) ->Result <AddressSpaceManager <'a>> {if as_present.trailing_ones () != as_present.count_ones () {
@@ -216,7 +216,7 @@ fn validate_as_slot(&self, as_nr: usize) -> Result {/// /// Returns an error if polling times out after 10ms or if register access fails. fn as_wait_ready (&self, as_nr:usize ) ->Result { -let io = &*self.iomem; +let io = self.iomem;let op = || {let status_reg =STATUS ::try_at (as_nr).ok_or (EINVAL )?;Ok (io.read (status_reg))
@@ -232,7 +232,7 @@ fn as_wait_ready(&self, as_nr: usize) -> Result {/// Returns an error if waiting for ready times out or if register write fails. fn as_send_cmd (&mut self, as_nr:usize , cmd:MmuCommand ) ->Result { self.as_wait_ready (as_nr)?; -let io = &*self.iomem; +let io = self.iomem;let command_reg =COMMAND ::try_at (as_nr).ok_or (EINVAL )?; io.write (command_reg,COMMAND ::zeroed ().with_command (cmd));Ok (())
@@ -253,7 +253,7 @@ fn as_send_cmd_and_wait(&mut self, as_nr: usize, cmd: MmuCommand) -> Result {fn as_enable (&mut self, as_nr:usize , as_config: &AddressSpaceConfig ) ->Result { self.validate_as_slot (as_nr)?; -let io = &*self.iomem; +let io = self.iomem;let transtab = as_config.transtab; io.write(
@@ -299,7 +299,7 @@ fn as_disable(&mut self, as_nr: usize) -> Result {// Flush AS before disabling self.as_send_cmd_and_wait (as_nr,MmuCommand ::FlushMem )?; -let io = &*self.iomem; +let io = self.iomem; io.write ( TRANSTAB_LO::try_at(as_nr).ok_or(EINVAL)?,
@@ -394,7 +394,7 @@ fn as_start_update(&mut self, as_nr: usize, region: &Range<u64>) -> Result {// because log2(32 KiB) = 15. let lockaddr_size = lock_region_log2 -1 ; -let io = &*self.iomem; +let io = self.iomem;// The LOCKADDR base field stores address bits 63:12, so remove the low 12 bits // before passing this value to the register macro helper.
drivers/gpu/drm/tyr/tyr.rs +5 -0
@@ -5,6 +5,11 @@//! The name "Tyr" is inspired by Norse mythology, reflecting Arm's tradition of //! naming their GPUs after Nordic mythological figures and places. +#![allow( +clippy::multiple_bound_locations, +reason = "pin_data generates additional outlives bounds for borrowed fields" +)] +use crate ::driver::TyrPlatformDriver ;mod driver;
drivers/gpu/drm/tyr/vm.rs +46 -47
148 lines not on this page · raw message
Signature · 1 line
2.56.1
Quoted 9 lines · Danilo Krummrich
Now that pin-init supports self-referential structs, Arc is no longer needed just to share resources whose lifetimes are bounded by their owners.
Use pin-init's self-referential support to share the MMIO mapping, MMU and firmware VM through borrows instead of Arc, avoiding their separate allocations and reference counts.
Quoted 6 lines
Hide the invariant resource lifetime shared by the VM and its sections behind an existential lifetime that outlives 'mmu, so Firmware only needs a single lifetime parameter.
Cc Gary Guo <[email protected]>Signed-off-by Danilo Krummrich <[email protected]>
Quoted 8 lines · Danilo Krummrich
Now that pin-init supports self-referential structs, Arc is no longer needed just to share resources whose lifetimes are bounded by their owners.
Use pin-init's self-referential support to share the MMIO mapping, MMU and firmware VM through borrows instead of Arc, avoiding their separate allocations and reference counts.
Quoted 6 lines
Hide the invariant resource lifetime shared by the VM and its sections behind an existential lifetime that outlives 'mmu, so Firmware only needs a single lifetime parameter.
Cc Gary Guo <[email protected]>Signed-off-by Danilo Krummrich <[email protected]>
drivers/gpu/drm/tyr/driver.rs pub(crate) struct TyrDrmRegistrationData<'drm> {
Quoted 40 lines
--- drivers/gpu/drm/tyr/driver.rs | 38 +++--- drivers/gpu/drm/tyr/fw.rs | 152 ++++++++++++----------- drivers/gpu/drm/tyr/gem.rs | 15 +-- drivers/gpu/drm/tyr/mmu.rs | 36 +++--- drivers/gpu/drm/tyr/mmu/address_space.rs | 14 +-- drivers/gpu/drm/tyr/tyr.rs | 5 + drivers/gpu/drm/tyr/vm.rs | 93 +++++++------- 7 files changed, 179 insertions(+), 174 deletions(-)drivers/gpu/drm/tyr/driver.rs +9
-2@@ -29,7 +29,7 @@ regulator::Regulator, sizes::SZ_2M, sync::{ - Arc, + aref::ARef, Mutex, // }, time, //@@ -71,7 +71,14 @@ pub(crate) struct TyrDrmRegistrationData<'drm> { pub(crate) pdev: &'drm platform::Device<Bound>,/// Firmware sections. - pub(crate) fw: Firmware<'drm>, +#[pin] +#[uses('mmu: invariant)] + pub(crate) fw: Firmware<'mmu>, + +/// MMU shared by the firmware and its buffer objects. +#[pin] +#[uses('iomem: invariant)] + mmu: Mmu<'iomem>,#[pin] clks: Mutex<Clocks>,@@ -80,7 +87,7 @@ pub(crate) struct TyrDrmRegistrationData<'drm> {
This isn't renamed because it's top-level I suppose?
Best,
Gary
Quoted 8 lines
drivers/gpu/drm/tyr/driver.rs +1
-1regulators: Mutex<Regulators>,/// GPU MMIO register mapping. - pub(crate) iomem: Arc<IoMem<'drm>>, + pub(crate) iomem: IoMem<'drm>,/// GPU information read from hardware during probe. pub(crate) gpu_info: GpuInfo,
Danilo Krummrich
maintainerPATCH v2 3/3 drm/tyr: use ScopeGuard for firmware loading cleanup
In reply to Danilo KrummrichUse ScopeGuard to call vm.kill() when firmware section loading fails. Dismiss it on success, replacing the nested closure and explicit error check.
--- drivers/gpu/drm/tyr/fw.rs | 59 ++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 32 deletions(-)
drivers/gpu/drm/tyr/fw.rs +27 -32
@@ -29,7 +29,8 @@ num::Bounded, prelude::*, str::CString, - time, // + time, + types::ScopeGuard, // };use crate ::{
@@ -228,46 +229,40 @@ pub(crate) fn new<'a, 'res>( sections: { let vm = vm.get_ref(); vm.activate ()?; +let guard =ScopeGuard ::new (|| vm.kill ()); -let result:Result <_ > = (|| { -let (fw, parsed_sections) =Self ::load (dev, ddev, gpu_info)?; -let mut sections =KVec ::new (); -for parsedin parsed_sections { -let size = - u64::from (parsed.va.end.checked_sub (parsed.va.start).ok_or (EINVAL )?); +let (fw, parsed_sections) =Self ::load (dev, ddev, gpu_info)?; +let mut sections =KVec ::new (); +for parsedin parsed_sections { +let size = + u64::from (parsed.va.end.checked_sub (parsed.va.start).ok_or (EINVAL )?); -let va = u64::from (parsed.va.start); +let va = u64::from (parsed.va.start); -let mut mem =KernelBo ::new ( - ddev, - vm, - size, -KernelBoVaAlloc ::Explicit (va), - parsed.vm_map_flags, - )?; +let mut mem =KernelBo ::new ( + ddev, + vm, + size, +KernelBoVaAlloc ::Explicit (va), + parsed.vm_map_flags, + )?; -let section_start = parsed.data_range.startas usize ; -let section_end = parsed.data_range.endas usize ; -let mut data =KVec ::new (); +let section_start = parsed.data_range.startas usize ; +let section_end = parsed.data_range.endas usize ; +let mut data =KVec ::new (); -// Ensure that the firmware slice is not out of bounds. -let fw_data = fw.data (); -let bytes = fw_data.get (section_start..section_end).ok_or (EINVAL )?; - data.extend_from_slice (bytes,GFP_KERNEL )?; +// Ensure that the firmware slice is not out of bounds. +let fw_data = fw.data (); +let bytes = fw_data.get (section_start..section_end).ok_or (EINVAL )?; + data.extend_from_slice (bytes,GFP_KERNEL )?; -Self ::init_section_mem (dev, &mut mem, &data)?; +Self ::init_section_mem (dev, &mut mem, &data)?; - sections.push (Section { data, mem },GFP_KERNEL )?; - } - -Ok (sections) - })(); - -if result.is_err () { - vm.kill (); + sections.push (Section { data, mem },GFP_KERNEL )?; } - result? + guard.dismiss (); + sections }, }) }
Signature · 1 line
2.56.1
Re: [PATCH v2 3/3] drm/tyr: use ScopeGuard for firmware loading cleanup
Quoted 5 lines · Danilo Krummrich
Use ScopeGuard to call
vm.kill()when firmware section loading fails. Dismiss it on success, replacing the nested closure and explicit error check.Signed-off-by Danilo Krummrich <[email protected]>
Re: [PATCH v2 3/3] drm/tyr: use ScopeGuard for firmware loading cleanup
In reply to Danilo KrummrichQuoted 5 lines · Danilo Krummrich
Use ScopeGuard to call
vm.kill()when firmware section loading fails. Dismiss it on success, replacing the nested closure and explicit error check.Signed-off-by Danilo Krummrich <[email protected]>
Looks much cleaner!
Quoted 3 lines
--- drivers/gpu/drm/tyr/fw.rs | 59 ++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 32 deletions(-)
Daniel Almeida
maintainerHi folks,
Quoted 31 lines · Danilo Krummrich
This series uses pin-init's self-referential support to replace Arcs for resources whose lifetimes are bounded by their owners.
It also cleans up lifetime names and simplifies firmware loading cleanup with ScopeGuard.
Changes in v2:
- Use generic names for covariant lifetime parameters and resource names for invariant ones.
- Include VmAsData, GpuVmData, the VM operation types and PtUpdateContext in the lifetime cleanup.
- Drop the pin-init lint suppression patch and temporarily allowclippy::multiple_bound_locationsin Tyr instead.Danilo Krummrich (3):
drm/tyr: clarify resource lifetime names drm/tyr: use pin-init self-referential support drm/tyr: use ScopeGuard for firmware loading cleanupdrivers/gpu/drm/tyr/driver.rs | 38 +++-- drivers/gpu/drm/tyr/fw.rs | 151 +++++++++---------- drivers/gpu/drm/tyr/gem.rs | 15 +- drivers/gpu/drm/tyr/mmu.rs | 56 ++++---- drivers/gpu/drm/tyr/mmu/address_space.rs | 54 +++---- drivers/gpu/drm/tyr/tyr.rs | 5 + drivers/gpu/drm/tyr/vm.rs | 175 +++++++++++------------ 7 files changed, 247 insertions(+), 247 deletions(-)
Quoted 4 lines
base-commit:
abfb640b2374e26de8ff81d488c39d8254db538eSignature · 1 line
2.56.1
I am actively trying to rebase our downstream work on this.
Please wait for a tested-by tag, it may or may not reveal something relevant.
— Daniel