* [PATCH v2 1/3] drm/tyr: clarify resource lifetime names
2026-11-30 23:19 [PATCH v2 0/3] drm/tyr: use pin-init self-referential support Danilo Krummrich
@ 2026-11-30 23:19 ` Danilo Krummrich
2026-11-30 23:19 ` [PATCH v2 2/3] drm/tyr: use pin-init self-referential support Danilo Krummrich
2026-11-30 23:19 ` [PATCH v2 3/3] drm/tyr: use ScopeGuard for firmware loading cleanup Danilo Krummrich
2 siblings, 0 replies; 4+ messages in thread
From: Danilo Krummrich @ 2026-11-30 23:19 UTC (permalink / raw)
To: dakr, aliceryhl, daniel.almeida, airlied, simona, lossin, gary,
ojeda, boqun, bjorn3_gh, a.hindborg, tmgross, tamird, acourbot,
work
Cc: dri-devel, rust-for-linux, linux-kernel
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 <dakr@kernel.org>
---
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(-)
diff --git a/drivers/gpu/drm/tyr/fw.rs b/drivers/gpu/drm/tyr/fw.rs
index aea151ff1f93..6521c5c1b63a 100644
--- a/drivers/gpu/drm/tyr/fw.rs
+++ b/drivers/gpu/drm/tyr/fw.rs
@@ -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: &'drm Device<Bound>,
- iomem: Arc<IoMem<'drm>>,
+ dev: &'res Device<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()?;
diff --git a/drivers/gpu/drm/tyr/gem.rs b/drivers/gpu/drm/tyr/gem.rs
index 3bf3787f5c3f..c9f9e5592e41 100644
--- a/drivers/gpu/drm/tyr/gem.rs
+++ b/drivers/gpu/drm/tyr/gem.rs
@@ -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,
diff --git a/drivers/gpu/drm/tyr/mmu.rs b/drivers/gpu/drm/tyr/mmu.rs
index 5e88c9e6a4cd..e708a181aedb 100644
--- a/drivers/gpu/drm/tyr/mmu.rs
+++ b/drivers/gpu/drm/tyr/mmu.rs
@@ -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: &'drm Device<Bound>,
- iomem: ArcBorrow<'_, IoMem<'drm>>,
+ dev: &'res Device<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)
}
}
diff --git a/drivers/gpu/drm/tyr/mmu/address_space.rs b/drivers/gpu/drm/tyr/mmu/address_space.rs
index 76e3d2df6afd..49899d395249 100644
--- a/drivers/gpu/drm/tyr/mmu/address_space.rs
+++ b/drivers/gpu/drm/tyr/mmu/address_space.rs
@@ -72,27 +72,27 @@ struct AddressSpaceConfig {
/// Virtual memory (VM) address space data for use in MMU operations.
#[pin_data]
-pub(crate) struct VmAsData<'drm> {
+pub(crate) struct VmAsData<'res> {
/// This address-space seat tracks this VM's binding to a hardware address space slot.
/// It can only be accessed when holding the `Mmu::as_manager` lock.
- as_seat: LockedSeat<AddressSpaceManager<'drm>, MAX_AS>,
+ as_seat: LockedSeat<AddressSpaceManager<'res>, MAX_AS>,
/// Virtual address bits for this address space.
va_bits: u8,
/// The page table which maps GPU virtual addresses to physical addresses for this VM.
#[pin]
- pub(crate) page_table: IoPageTable<'drm, ARM64LPAES1>,
+ pub(crate) page_table: IoPageTable<'res, ARM64LPAES1>,
}
-impl<'drm> VmAsData<'drm> {
+impl<'res> VmAsData<'res> {
/// Creates VM address space data by initializing all of its fields.
pub(crate) fn new<'a>(
- mmu: &'a Mmu<'drm>,
- dev: &'drm Device<Bound>,
+ mmu: &'a Mmu<'res>,
+ dev: &'res Device<Bound>,
va_bits: u32,
pa_bits: u32,
- ) -> impl pin_init::PinInit<VmAsData<'drm>, Error> + 'a {
+ ) -> impl pin_init::PinInit<VmAsData<'res>, Error> + 'a {
let pt_config = Config {
quirks: 0,
pgsize_bitmap: SZ_4K | SZ_2M,
@@ -147,27 +147,27 @@ fn as_config(&self) -> Result<AddressSpaceConfig> {
/// Coordinates all hardware-level address space operations through MMIO register
/// operations including enabling, disabling, flushing, and updating address spaces.
-pub(crate) struct AddressSpaceManager<'drm> {
+pub(crate) struct AddressSpaceManager<'a> {
/// Parent device used for logging.
- dev: &'drm Device<Bound>,
+ dev: &'a Device<Bound>,
/// Memory-mapped I/O region for GPU register access.
- iomem: Arc<IoMem<'drm>>,
+ iomem: Arc<IoMem<'a>>,
/// Bitmask of present address space slots from GPU_AS_PRESENT register.
as_present: u32,
}
-impl<'drm> AddressSpaceManager<'drm> {
+impl<'a> AddressSpaceManager<'a> {
/// Creates a new address space manager.
///
/// Initializes the manager with references to the platform device and
/// I/O memory region, along with the bitmask of available AS slots.
pub(super) fn new(
- dev: &'drm Device<Bound>,
- iomem: Arc<IoMem<'drm>>,
+ dev: &'a Device<Bound>,
+ iomem: Arc<IoMem<'a>>,
as_present: u32,
- ) -> Result<AddressSpaceManager<'drm>> {
+ ) -> Result<AddressSpaceManager<'a>> {
if as_present.trailing_ones() != as_present.count_ones() {
dev_err!(
dev,
@@ -436,9 +436,9 @@ fn as_flush(&mut self, as_nr: usize) -> Result {
}
}
-impl<'drm> SlotOperations<MAX_AS> for AddressSpaceManager<'drm> {
+impl<'a> SlotOperations<MAX_AS> for AddressSpaceManager<'a> {
/// VM address space data associated with a hardware slot.
- type SlotData = Arc<VmAsData<'drm>>;
+ type SlotData = Arc<VmAsData<'a>>;
fn seat(slot_data: &Self::SlotData) -> &LockedSeat<Self, MAX_AS> {
&slot_data.as_seat
@@ -458,11 +458,11 @@ fn evict(&mut self, slot_idx: usize, _slot_data: &Self::SlotData) -> Result {
}
}
-impl<'drm> AsSlotManager<'drm> {
+impl<'res> AsSlotManager<'res> {
/// Locks a region for translation table updates if the VM has an active slot.
pub(super) fn start_vm_update(
&mut self,
- vm_as_data: &VmAsData<'drm>,
+ vm_as_data: &VmAsData<'res>,
region: &Range<u64>,
) -> Result {
let seat = vm_as_data.as_seat.access(self);
@@ -476,7 +476,7 @@ pub(super) fn start_vm_update(
}
/// Completes translation table updates and unlocks the region.
- pub(super) fn end_vm_update(&mut self, vm_as_data: &VmAsData<'drm>) -> Result {
+ pub(super) fn end_vm_update(&mut self, vm_as_data: &VmAsData<'res>) -> Result {
let seat = vm_as_data.as_seat.access(self);
match seat.slot() {
Some(slot) => {
@@ -488,7 +488,7 @@ pub(super) fn end_vm_update(&mut self, vm_as_data: &VmAsData<'drm>) -> Result {
}
/// Flushes the translation table cache if the VM has an active slot.
- pub(super) fn flush_vm(&mut self, vm_as_data: &VmAsData<'drm>) -> Result {
+ pub(super) fn flush_vm(&mut self, vm_as_data: &VmAsData<'res>) -> Result {
let seat = vm_as_data.as_seat.access(self);
match seat.slot() {
Some(slot) => {
@@ -500,12 +500,12 @@ pub(super) fn flush_vm(&mut self, vm_as_data: &VmAsData<'drm>) -> Result {
}
/// Activates a VM by assigning it to a hardware slot.
- pub(super) fn activate_vm(&mut self, vm_as_data: ArcBorrow<'_, VmAsData<'drm>>) -> Result {
+ pub(super) fn activate_vm(&mut self, vm_as_data: ArcBorrow<'_, VmAsData<'res>>) -> Result {
self.activate(vm_as_data.into())
}
/// Deactivates a VM by evicting it from its hardware slot.
- pub(super) fn deactivate_vm(&mut self, vm_as_data: &VmAsData<'drm>) -> Result {
+ pub(super) fn deactivate_vm(&mut self, vm_as_data: &VmAsData<'res>) -> Result {
self.evict(&vm_as_data.as_seat)
}
}
diff --git a/drivers/gpu/drm/tyr/vm.rs b/drivers/gpu/drm/tyr/vm.rs
index 1dd11b2b1253..e15f314b9c2e 100644
--- a/drivers/gpu/drm/tyr/vm.rs
+++ b/drivers/gpu/drm/tyr/vm.rs
@@ -155,19 +155,19 @@ fn try_from(value: u32) -> Result<Self, Self::Error> {
}
/// Arguments for a virtual memory map operation.
-struct VmMapArgs<'drm> {
+struct VmMapArgs<'res> {
/// Access permissions and caching behavior for the mapping.
flags: VmMapFlags,
/// GEM buffer object registered with the GPUVM framework.
- vm_bo: ARef<GpuVmBo<GpuVmData<'drm>>>,
+ vm_bo: ARef<GpuVmBo<GpuVmData<'res>>>,
/// Offset in bytes from the start of the buffer object.
bo_offset: u64,
}
/// Type of virtual memory operation.
-enum VmOpType<'drm> {
+enum VmOpType<'res> {
/// Map a GEM buffer object into the virtual address space.
- Map(VmMapArgs<'drm>),
+ Map(VmMapArgs<'res>),
/// Unmap a region from the virtual address space.
Unmap,
}
@@ -177,20 +177,20 @@ enum VmOpType<'drm> {
/// VM operations may require allocating new GPUVA objects to track mappings.
/// To avoid allocation failures during the operation, preallocate the
/// maximum number of GPUVAs that might be needed.
-struct VmOpResources<'drm> {
+struct VmOpResources<'res> {
/// Preallocated GPUVA objects for remap operations.
///
/// Partial unmap requests or map requests overlapping existing mappings
/// will trigger a remap call, which needs to register up to three VA
/// objects (one for the new mapping, and two for the previous and next
/// mappings).
- preallocated_gpuvas: [Option<GpuVaAlloc<GpuVmData<'drm>>>; 3],
+ preallocated_gpuvas: [Option<GpuVaAlloc<GpuVmData<'res>>>; 3],
}
/// Request to execute a virtual memory operation.
-struct VmOpRequest<'drm> {
+struct VmOpRequest<'res> {
/// Request type.
- op_type: VmOpType<'drm>,
+ op_type: VmOpType<'res>,
/// Region of the virtual address space covered by this request.
region: Range<u64>,
@@ -218,18 +218,18 @@ enum PtOpType {
/// automatically flushes changes when dropped. It ensures that the
/// Memory Management Unit (MMU) state is properly managed and Translation
/// Lookaside Buffer (TLB) entries are flushed.
-pub(crate) struct PtUpdateContext<'ctx, 'drm> {
+pub(crate) struct PtUpdateContext<'a, 'res> {
/// Device used for DMA-mapping GEM shmem SG tables.
- dev: &'ctx Device<Bound>,
+ dev: &'a Device<Bound>,
/// Page table.
- pt: &'ctx IoPageTable<'drm, ARM64LPAES1>,
+ pt: &'a IoPageTable<'res, ARM64LPAES1>,
/// MMU manager.
- mmu: &'ctx Mmu<'drm>,
+ mmu: &'a Mmu<'res>,
/// Reference to the address space data to pass to the MMU functions.
- as_data: &'ctx VmAsData<'drm>,
+ as_data: &'a VmAsData<'res>,
/// Region of the virtual address space covered by this request.
region: Range<u64>,
@@ -238,24 +238,24 @@ pub(crate) struct PtUpdateContext<'ctx, 'drm> {
op_type: PtOpType,
/// Preallocated resources that can be used when executing the request.
- resources: &'ctx mut VmOpResources<'drm>,
+ resources: &'a mut VmOpResources<'res>,
}
-impl<'ctx, 'drm> PtUpdateContext<'ctx, 'drm> {
+impl<'a, 'res> PtUpdateContext<'a, 'res> {
/// Creates a new page table update context.
///
/// This prepares the MMU for a page table update.
/// The context will automatically flush the TLB and
/// complete the update when dropped.
fn new(
- dev: &'ctx Device<Bound>,
- pt: &'ctx IoPageTable<'drm, ARM64LPAES1>,
- mmu: &'ctx Mmu<'drm>,
- as_data: &'ctx VmAsData<'drm>,
+ dev: &'a Device<Bound>,
+ pt: &'a IoPageTable<'res, ARM64LPAES1>,
+ mmu: &'a Mmu<'res>,
+ as_data: &'a VmAsData<'res>,
region: Range<u64>,
op_type: PtOpType,
- resources: &'ctx mut VmOpResources<'drm>,
- ) -> Result<PtUpdateContext<'ctx, 'drm>> {
+ resources: &'a mut VmOpResources<'res>,
+ ) -> Result<PtUpdateContext<'a, 'res>> {
mmu.start_vm_update(as_data, ®ion)?;
Ok(Self {
@@ -270,7 +270,7 @@ fn new(
}
/// Finds one of our pre-allocated VAs.
- fn preallocated_gpuva(&mut self) -> Result<GpuVaAlloc<GpuVmData<'drm>>> {
+ fn preallocated_gpuva(&mut self) -> Result<GpuVaAlloc<GpuVmData<'res>>> {
self.resources
.preallocated_gpuvas
.iter_mut()
@@ -280,7 +280,7 @@ fn preallocated_gpuva(&mut self) -> Result<GpuVaAlloc<GpuVmData<'drm>>> {
/// Returns an unused GPUVA object to the preallocated pool.
/// If the pool is already full, the unused allocation is simply dropped.
- fn return_preallocated_gpuva(&mut self, gpuva: GpuVaAlloc<GpuVmData<'drm>>) {
+ fn return_preallocated_gpuva(&mut self, gpuva: GpuVaAlloc<GpuVmData<'res>>) {
if let Some(slot) = self
.resources
.preallocated_gpuvas
@@ -308,42 +308,42 @@ fn drop(&mut self) {
///
/// Implements [`DriverGpuVm`] to provide VM operation callbacks (map, unmap, remap)
/// and associated types for buffer objects, virtual addresses, and contexts.
-pub(crate) struct GpuVmData<'drm> {
- _phantom: PhantomData<&'drm ()>,
+pub(crate) struct GpuVmData<'a> {
+ _phantom: PhantomData<&'a ()>,
}
/// GPU virtual address space.
///
/// Each VM can be mapped into a hardware address space slot.
#[pin_data]
-pub(crate) struct Vm<'drm> {
+pub(crate) struct Vm<'res> {
/// Data referenced by an AS when the VM is active
- as_data: Arc<VmAsData<'drm>>,
+ as_data: Arc<VmAsData<'res>>,
/// MMU manager.
- mmu: Arc<Mmu<'drm>>,
+ mmu: Arc<Mmu<'res>>,
/// Parent device used for DMA mapping and page-table operations.
- dev: &'drm Device<Bound>,
+ dev: &'res Device<Bound>,
/// DRM GPUVM core for managing virtual address space.
#[pin]
- gpuvm_unique: Mutex<UniqueRefGpuVm<GpuVmData<'drm>>>,
+ gpuvm_unique: Mutex<UniqueRefGpuVm<GpuVmData<'res>>>,
/// Non-core part of the GPUVM. Can be used for stuff that doesn't modify the
/// internal mapping tree, like GpuVm::obtain()
- gpuvm: ARef<GpuVm<GpuVmData<'drm>>>,
+ gpuvm: ARef<GpuVm<GpuVmData<'res>>>,
/// VA range for this VM.
va_range: Range<u64>,
}
-impl<'drm> Vm<'drm> {
+impl<'res> Vm<'res> {
/// Creates a new GPU virtual address space.
///
/// The VM is initialized with a page table configured according to the GPU's
/// address translation capabilities and registered with the GPUVM framework.
pub(crate) fn new(
- dev: &'drm Device<Bound>,
+ dev: &'res Device<Bound>,
ddev: &TyrDrmDevice,
- mmu: ArcBorrow<'_, Mmu<'drm>>,
+ mmu: ArcBorrow<'_, Mmu<'res>>,
gpu_info: &GpuInfo,
- ) -> Result<Arc<Vm<'drm>>> {
+ ) -> Result<Arc<Vm<'res>>> {
let mmu_features = MMU_FEATURES::from_raw(gpu_info.mmu_features);
let va_bits = mmu_features.va_bits().get();
let pa_bits = mmu_features.pa_bits().get();
@@ -362,7 +362,7 @@ pub(crate) fn new(
&*dummy_obj,
range.clone(),
reserve_range,
- GpuVmData::<'drm> {
+ GpuVmData::<'res> {
_phantom: PhantomData::<&()>,
},
)
@@ -389,7 +389,7 @@ pub(crate) fn new(
}
/// Returns the parent device used by this VM for DMA mapping and page-table operations.
- pub(crate) fn dev(&self) -> &'drm Device<Bound> {
+ pub(crate) fn dev(&self) -> &'res Device<Bound> {
self.dev
}
@@ -426,9 +426,9 @@ pub(crate) fn kill(&self) {
/// GPUVM framework and the hardware page table.
fn exec_op<'a>(
&self,
- gpuvm_unique: &mut UniqueRefGpuVm<GpuVmData<'drm>>,
- req: VmOpRequest<'drm>,
- resources: &'a mut VmOpResources<'drm>,
+ gpuvm_unique: &mut UniqueRefGpuVm<GpuVmData<'res>>,
+ req: VmOpRequest<'res>,
+ resources: &'a mut VmOpResources<'res>,
) -> Result {
let pt = &self.as_data.page_table;
@@ -524,9 +524,9 @@ pub(crate) fn map_bo_range(
};
let mut resources = VmOpResources {
preallocated_gpuvas: [
- Some(GpuVaAlloc::<GpuVmData<'drm>>::new(GFP_KERNEL)?),
- Some(GpuVaAlloc::<GpuVmData<'drm>>::new(GFP_KERNEL)?),
- Some(GpuVaAlloc::<GpuVmData<'drm>>::new(GFP_KERNEL)?),
+ Some(GpuVaAlloc::<GpuVmData<'res>>::new(GFP_KERNEL)?),
+ Some(GpuVaAlloc::<GpuVmData<'res>>::new(GFP_KERNEL)?),
+ Some(GpuVaAlloc::<GpuVmData<'res>>::new(GFP_KERNEL)?),
],
};
let result = {
@@ -577,9 +577,9 @@ pub(crate) fn unmap_range(&self, va: u64, size: u64) -> Result {
[None, None, None]
} else {
[
- Some(GpuVaAlloc::<GpuVmData<'drm>>::new(GFP_KERNEL)?),
- Some(GpuVaAlloc::<GpuVmData<'drm>>::new(GFP_KERNEL)?),
- Some(GpuVaAlloc::<GpuVmData<'drm>>::new(GFP_KERNEL)?),
+ Some(GpuVaAlloc::<GpuVmData<'res>>::new(GFP_KERNEL)?),
+ Some(GpuVaAlloc::<GpuVmData<'res>>::new(GFP_KERNEL)?),
+ Some(GpuVaAlloc::<GpuVmData<'res>>::new(GFP_KERNEL)?),
]
},
};
@@ -595,13 +595,13 @@ pub(crate) fn unmap_range(&self, va: u64, size: u64) -> Result {
}
}
-impl<'drm> DriverGpuVm for GpuVmData<'drm> {
+impl<'a> DriverGpuVm for GpuVmData<'a> {
type Driver = TyrDrmDriver;
type Object = Bo;
type VmBoData = ();
type VaData = ();
type SmContext<'ctx>
- = PtUpdateContext<'ctx, 'drm>
+ = PtUpdateContext<'ctx, 'a>
where
Self: 'ctx;
--
2.56.1
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 2/3] drm/tyr: use pin-init self-referential support
2026-11-30 23:19 [PATCH v2 0/3] drm/tyr: use pin-init self-referential support Danilo Krummrich
2026-11-30 23:19 ` [PATCH v2 1/3] drm/tyr: clarify resource lifetime names Danilo Krummrich
@ 2026-11-30 23:19 ` Danilo Krummrich
2026-11-30 23:19 ` [PATCH v2 3/3] drm/tyr: use ScopeGuard for firmware loading cleanup Danilo Krummrich
2 siblings, 0 replies; 4+ messages in thread
From: Danilo Krummrich @ 2026-11-30 23:19 UTC (permalink / raw)
To: dakr, aliceryhl, daniel.almeida, airlied, simona, lossin, gary,
ojeda, boqun, bjorn3_gh, a.hindborg, tmgross, tamird, acourbot,
work
Cc: dri-devel, rust-for-linux, linux-kernel
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.
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 <gary@garyguo.net>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
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(-)
diff --git a/drivers/gpu/drm/tyr/driver.rs b/drivers/gpu/drm/tyr/driver.rs
index 557f2ec0a767..a2fa7350f144 100644
--- a/drivers/gpu/drm/tyr/driver.rs
+++ b/drivers/gpu/drm/tyr/driver.rs
@@ -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.") },
diff --git a/drivers/gpu/drm/tyr/fw.rs b/drivers/gpu/drm/tyr/fw.rs
index 6521c5c1b63a..698c3e9b6845 100644
--- a/drivers/gpu/drm/tyr/fw.rs
+++ b/drivers/gpu/drm/tyr/fw.rs
@@ -29,10 +29,6 @@
num::Bounded,
prelude::*,
str::CString,
- sync::{
- Arc,
- ArcBorrow, //
- },
time, //
};
@@ -131,7 +127,7 @@ fn try_from_fw(value: u32) -> Result<Self> {
}
/// A parsed section of the firmware binary.
-struct Section<'res> {
+struct Section<'a, 'res> {
// Raw firmware section data for reset purposes
#[expect(dead_code)]
data: KVec<u8>,
@@ -139,34 +135,41 @@ struct Section<'res> {
// 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<'res>,
+ mem: gem::KernelBo<'a, 'res>,
}
/// Loaded firmware with sections mapped into MCU VM.
-pub(crate) struct Firmware<'res> {
+#[pin_data(PinnedDrop)]
+pub(crate) struct Firmware<'mmu>
+where
+ exists<'res>: 'mmu,
+{
/// Iomem need to access registers.
- iomem: Arc<IoMem<'res>>,
-
- /// MCU VM.
- vm: Arc<Vm<'res>>,
+ iomem: &'mmu IoMem<'mmu>,
/// List of firmware sections.
- #[expect(dead_code)]
- sections: KVec<Section<'res>>,
+ #[uses('res: invariant)]
+ sections: KVec<Section<'vm, 'res>>,
+
+ /// MCU VM.
+ #[pin]
+ #[uses('res: invariant)]
+ vm: Vm<'mmu, 'res>,
}
-impl<'res> Drop for Firmware<'res> {
- fn drop(&mut self) {
+#[pinned_drop]
+impl PinnedDrop for Firmware<'_> {
+ fn drop(self: Pin<&mut Self>) {
// Stop the MCU before releasing its firmware mappings and memory.
let _ = self.stop();
// AS slots retain a VM ref, we need to kill the circular ref manually.
- self.vm.kill();
+ self.with_vm(|vm| vm.kill());
}
}
-impl<'res> Firmware<'res> {
- fn init_section_mem(dev: &Device, mem: &mut KernelBo<'res>, data: &KVec<u8>) -> Result {
+impl<'mmu> Firmware<'mmu> {
+ fn init_section_mem(dev: &Device, mem: &mut KernelBo<'_, '_>, data: &KVec<u8>) -> Result {
if data.is_empty() {
return Ok(());
}
@@ -212,62 +215,65 @@ fn load(
}
/// Load firmware and map sections into MCU VM.
- pub(crate) fn new(
+ pub(crate) fn new<'a, 'res>(
dev: &'res Device<Bound>,
- iomem: Arc<IoMem<'res>>,
- ddev: &TyrDrmDevice,
- mmu: ArcBorrow<'_, Mmu<'res>>,
- gpu_info: &GpuInfo,
- ) -> Result<Firmware<'res>> {
- let vm = Vm::new(dev, ddev, mmu, gpu_info)?;
- vm.activate()?;
-
- let result = (|| {
- let (fw, parsed_sections) = Self::load(dev, ddev, gpu_info)?;
- let mut sections = KVec::new();
- for parsed in 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 mut mem = KernelBo::new(
- ddev,
- vm.clone(),
- size,
- KernelBoVaAlloc::Explicit(va),
- parsed.vm_map_flags,
- )?;
-
- let section_start = parsed.data_range.start as usize;
- let section_end = parsed.data_range.end as 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)?;
-
- Self::init_section_mem(dev, &mut mem, &data)?;
-
- sections.push(Section { data, mem }, GFP_KERNEL)?;
- }
-
- Ok(Firmware {
- iomem,
- vm: vm.clone(),
- sections,
- })
- })();
-
- if result.is_err() {
- vm.kill();
- }
-
- result
+ iomem: &'mmu IoMem<'mmu>,
+ ddev: &'a TyrDrmDevice,
+ mmu: &'mmu Mmu<'res>,
+ gpu_info: &'a GpuInfo,
+ ) -> impl PinInit<Self, Error> + use<'a, 'mmu, 'res> {
+ try_pin_init!(Self {
+ iomem,
+ vm <- Vm::new(dev, ddev, mmu, gpu_info),
+ sections: {
+ let vm = vm.get_ref();
+ vm.activate()?;
+
+ let result: Result<_> = (|| {
+ let (fw, parsed_sections) = Self::load(dev, ddev, gpu_info)?;
+ let mut sections = KVec::new();
+ for parsed in 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 mut mem = KernelBo::new(
+ ddev,
+ vm,
+ size,
+ KernelBoVaAlloc::Explicit(va),
+ parsed.vm_map_flags,
+ )?;
+
+ let section_start = parsed.data_range.start as usize;
+ let section_end = parsed.data_range.end as 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)?;
+
+ Self::init_section_mem(dev, &mut mem, &data)?;
+
+ sections.push(Section { data, mem }, GFP_KERNEL)?;
+ }
+
+ Ok(sections)
+ })();
+
+ if result.is_err() {
+ vm.kill();
+ }
+
+ result?
+ },
+ })
}
pub(crate) fn boot(&self) -> Result {
- let io = &self.iomem;
+ let io = self.iomem;
// Discard any stale global interrupt.
io.write_reg(JOB_IRQ_CLEAR::zeroed().with_glb(true));
@@ -284,7 +290,7 @@ pub(crate) fn boot(&self) -> Result {
) {
let status = io.read(MCU_STATUS);
dev_err!(
- self.vm.dev(),
+ self.with_vm(|vm| vm.dev()),
"MCU failed to boot, status: {:?}",
status.value()
);
@@ -297,7 +303,7 @@ pub(crate) fn boot(&self) -> Result {
}
fn stop(&self) -> Result {
- let io = &self.iomem;
+ let io = self.iomem;
io.write_reg(MCU_CONTROL::zeroed().with_req(McuControlMode::Disable));
if let Err(e) = poll::read_poll_timeout(
@@ -308,7 +314,7 @@ fn stop(&self) -> Result {
) {
let status = io.read(MCU_STATUS);
dev_err!(
- self.vm.dev(),
+ self.with_vm(|vm| vm.dev()),
"MCU failed to stop, status: {:?}",
status.value()
);
diff --git a/drivers/gpu/drm/tyr/gem.rs b/drivers/gpu/drm/tyr/gem.rs
index c9f9e5592e41..ecf22a277fc0 100644
--- a/drivers/gpu/drm/tyr/gem.rs
+++ b/drivers/gpu/drm/tyr/gem.rs
@@ -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: &'a Vm<'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: &'a Vm<'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;
diff --git a/drivers/gpu/drm/tyr/mmu.rs b/drivers/gpu/drm/tyr/mmu.rs
index e708a181aedb..23daa7ad81d6 100644
--- a/drivers/gpu/drm/tyr/mmu.rs
+++ b/drivers/gpu/drm/tyr/mmu.rs
@@ -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: &'res Device<Bound>,
- iomem: ArcBorrow<'_, IoMem<'res>>,
+ iomem: &'res IoMem<'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,
diff --git a/drivers/gpu/drm/tyr/mmu/address_space.rs b/drivers/gpu/drm/tyr/mmu/address_space.rs
index 49899d395249..f6fdc70a7c58 100644
--- a/drivers/gpu/drm/tyr/mmu/address_space.rs
+++ b/drivers/gpu/drm/tyr/mmu/address_space.rs
@@ -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: &'a Device<Bound>,
- iomem: Arc<IoMem<'a>>,
+ iomem: &'a IoMem<'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.
diff --git a/drivers/gpu/drm/tyr/tyr.rs b/drivers/gpu/drm/tyr/tyr.rs
index e7ec450bdc9c..7575a5365353 100644
--- a/drivers/gpu/drm/tyr/tyr.rs
+++ b/drivers/gpu/drm/tyr/tyr.rs
@@ -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;
diff --git a/drivers/gpu/drm/tyr/vm.rs b/drivers/gpu/drm/tyr/vm.rs
index e15f314b9c2e..c3551b531989 100644
--- a/drivers/gpu/drm/tyr/vm.rs
+++ b/drivers/gpu/drm/tyr/vm.rs
@@ -50,7 +50,6 @@
sync::{
aref::ARef,
Arc,
- ArcBorrow,
Mutex, //
},
uapi, //
@@ -316,11 +315,11 @@ pub(crate) struct GpuVmData<'a> {
///
/// Each VM can be mapped into a hardware address space slot.
#[pin_data]
-pub(crate) struct Vm<'res> {
+pub(crate) struct Vm<'a, 'res> {
/// Data referenced by an AS when the VM is active
as_data: Arc<VmAsData<'res>>,
/// MMU manager.
- mmu: Arc<Mmu<'res>>,
+ mmu: &'a Mmu<'res>,
/// Parent device used for DMA mapping and page-table operations.
dev: &'res Device<Bound>,
/// DRM GPUVM core for managing virtual address space.
@@ -333,59 +332,59 @@ pub(crate) struct Vm<'res> {
va_range: Range<u64>,
}
-impl<'res> Vm<'res> {
+impl<'a, 'res> Vm<'a, 'res> {
/// Creates a new GPU virtual address space.
///
/// The VM is initialized with a page table configured according to the GPU's
/// address translation capabilities and registered with the GPUVM framework.
- pub(crate) fn new(
+ pub(crate) fn new<'b>(
dev: &'res Device<Bound>,
- ddev: &TyrDrmDevice,
- mmu: ArcBorrow<'_, Mmu<'res>>,
- gpu_info: &GpuInfo,
- ) -> Result<Arc<Vm<'res>>> {
- let mmu_features = MMU_FEATURES::from_raw(gpu_info.mmu_features);
- let va_bits = mmu_features.va_bits().get();
- let pa_bits = mmu_features.pa_bits().get();
-
- let range = 0..(1u64 << va_bits);
- let reserve_range = 0..0u64;
-
- // dummy_obj is used to initialize the GPUVM tree.
- let dummy_obj = gem::new_dummy_object(ddev).inspect_err(|e| {
- dev_err!(dev, "Failed to create dummy GEM object: {:?}", e);
- })?;
+ ddev: &'b TyrDrmDevice,
+ mmu: &'a Mmu<'res>,
+ gpu_info: &'b GpuInfo,
+ ) -> impl PinInit<Self, Error> + 'b
+ where
+ 'a: 'b,
+ {
+ pin_init::pin_init_scope(move || {
+ let mmu_features = MMU_FEATURES::from_raw(gpu_info.mmu_features);
+ let va_bits = mmu_features.va_bits().get();
+ let pa_bits = mmu_features.pa_bits().get();
+
+ let range = 0..(1u64 << va_bits);
+ let reserve_range = 0..0u64;
+
+ // dummy_obj is used to initialize the GPUVM tree.
+ let dummy_obj = gem::new_dummy_object(ddev).inspect_err(|e| {
+ dev_err!(dev, "Failed to create dummy GEM object: {:?}", e);
+ })?;
- let gpuvm_unique = GpuVm::new::<Error, _>(
- c"Tyr::GpuVm",
- ddev,
- &*dummy_obj,
- range.clone(),
- reserve_range,
- GpuVmData::<'res> {
- _phantom: PhantomData::<&()>,
- },
- )
- .inspect_err(|e| {
- dev_err!(dev, "Failed to create GpuVm: {:?}", e);
- })?;
- let gpuvm = ARef::from(&*gpuvm_unique);
+ let gpuvm_unique = GpuVm::new::<Error, _>(
+ c"Tyr::GpuVm",
+ ddev,
+ &*dummy_obj,
+ range.clone(),
+ reserve_range,
+ GpuVmData::<'res> {
+ _phantom: PhantomData::<&()>,
+ },
+ )
+ .inspect_err(|e| {
+ dev_err!(dev, "Failed to create GpuVm: {:?}", e);
+ })?;
+ let gpuvm = ARef::from(&*gpuvm_unique);
- let as_data = Arc::pin_init(VmAsData::new(&mmu, dev, va_bits, pa_bits), GFP_KERNEL)?;
+ let as_data = Arc::pin_init(VmAsData::new(mmu, dev, va_bits, pa_bits), GFP_KERNEL)?;
- let vm = Arc::pin_init(
- pin_init!(Self{
+ Ok(try_pin_init!(Self {
as_data,
dev,
- mmu: mmu.into(),
+ mmu,
gpuvm,
gpuvm_unique <- new_mutex!(gpuvm_unique),
va_range: range,
- }),
- GFP_KERNEL,
- )?;
-
- Ok(vm)
+ }))
+ })
}
/// Returns the parent device used by this VM for DMA mapping and page-table operations.
@@ -424,11 +423,11 @@ pub(crate) fn kill(&self) {
///
/// This handles both map and unmap operations by coordinating between the
/// GPUVM framework and the hardware page table.
- fn exec_op<'a>(
+ fn exec_op<'b>(
&self,
gpuvm_unique: &mut UniqueRefGpuVm<GpuVmData<'res>>,
req: VmOpRequest<'res>,
- resources: &'a mut VmOpResources<'res>,
+ resources: &'b mut VmOpResources<'res>,
) -> Result {
let pt = &self.as_data.page_table;
@@ -437,7 +436,7 @@ fn exec_op<'a>(
let mut pt_upd = PtUpdateContext::new(
self.dev,
pt,
- &self.mmu,
+ self.mmu,
&self.as_data,
req.region,
PtOpType::Map(PtMapArgs {
@@ -459,7 +458,7 @@ fn exec_op<'a>(
let mut pt_upd = PtUpdateContext::new(
self.dev,
pt,
- &self.mmu,
+ self.mmu,
&self.as_data,
req.region,
PtOpType::Unmap,
--
2.56.1
^ permalink raw reply [flat|nested] 4+ messages in thread