Skip to content

Commit 43586cf

Browse files
committed
drm/asahi: Convert to ARef<Device<T>> DRM device API
Signed-off-by: Asahi Lina <[email protected]>
1 parent a5ddd9d commit 43586cf

7 files changed

Lines changed: 46 additions & 51 deletions

File tree

drivers/gpu/drm/asahi/alloc.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use kernel::{c_str, drm::mm, error::Result, prelude::*, str::CString, sync::LockClassKey};
1616

1717
use crate::debug::*;
18-
use crate::driver::AsahiDevice;
18+
use crate::driver::{AsahiDevRef, AsahiDevice};
1919
use crate::fw::types::Zeroable;
2020
use crate::mmu;
2121
use crate::object::{GpuArray, GpuObject, GpuOnlyArray, GpuStruct, GpuWeakPointer};
@@ -410,7 +410,7 @@ pub(crate) trait Allocator {
410410
/// `ptr` is either None or a valid, non-null pointer to the CPU view of the object.
411411
/// `gpu_ptr` is the GPU-side VA of the object.
412412
pub(crate) struct SimpleAllocation {
413-
dev: AsahiDevice,
413+
dev: AsahiDevRef,
414414
ptr: Option<NonNull<u8>>,
415415
gpu_ptr: u64,
416416
size: usize,
@@ -461,7 +461,7 @@ impl RawAllocation for SimpleAllocation {
461461
/// the guard page after the allocation, which can be useful to validate that the firmware's or
462462
/// GPU's idea of object size what we expect.
463463
pub(crate) struct SimpleAllocator {
464-
dev: AsahiDevice,
464+
dev: AsahiDevRef,
465465
start: u64,
466466
end: u64,
467467
prot: u32,
@@ -490,7 +490,7 @@ impl SimpleAllocator {
490490
cpu_maps = true;
491491
}
492492
Ok(SimpleAllocator {
493-
dev: dev.clone(),
493+
dev: dev.into(),
494494
vm: vm.clone(),
495495
start,
496496
end,
@@ -572,7 +572,7 @@ impl Allocator for SimpleAllocator {
572572
///
573573
/// This is wrapped in an `mm::Node`.
574574
pub(crate) struct HeapAllocationInner {
575-
dev: AsahiDevice,
575+
dev: AsahiDevRef,
576576
ptr: Option<NonNull<u8>>,
577577
real_size: usize,
578578
}
@@ -664,7 +664,7 @@ impl RawAllocation for HeapAllocation {
664664
///
665665
/// This is wrapped by an `mm::Allocator`.
666666
struct HeapAllocatorInner {
667-
dev: AsahiDevice,
667+
dev: AsahiDevRef,
668668
allocated: usize,
669669
backing_objects: Vec<(crate::gem::ObjectRef, u64)>,
670670
garbage: Option<Vec<mm::Node<HeapAllocatorInner, HeapAllocationInner>>>,
@@ -678,7 +678,7 @@ struct HeapAllocatorInner {
678678
/// The heap is composed of a series of GEM objects. This implementation only ever grows the heap,
679679
/// never shrinks it.
680680
pub(crate) struct HeapAllocator {
681-
dev: AsahiDevice,
681+
dev: AsahiDevRef,
682682
start: u64,
683683
end: u64,
684684
top: u64,
@@ -720,7 +720,7 @@ impl HeapAllocator {
720720
let name = CString::try_from_fmt(name)?;
721721

722722
let inner = HeapAllocatorInner {
723-
dev: dev.clone(),
723+
dev: dev.into(),
724724
allocated: 0,
725725
backing_objects: Vec::new(),
726726
// TODO: This clearly needs a try_clone() or similar
@@ -739,7 +739,7 @@ impl HeapAllocator {
739739
)?;
740740

741741
Ok(HeapAllocator {
742-
dev: dev.clone(),
742+
dev: dev.into(),
743743
vm: vm.clone(),
744744
start,
745745
end,

drivers/gpu/drm/asahi/channel.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! implementation.
1010
1111
use crate::debug::*;
12-
use crate::driver::AsahiDevice;
12+
use crate::driver::{AsahiDevRef, AsahiDevice};
1313
use crate::fw::channels::*;
1414
use crate::fw::initdata::{raw, ChannelRing};
1515
use crate::fw::types::*;
@@ -185,7 +185,7 @@ where
185185
/// Device Control channel for global device management commands.
186186
#[versions(AGX)]
187187
pub(crate) struct DeviceControlChannel {
188-
dev: AsahiDevice,
188+
dev: AsahiDevRef,
189189
ch: TxChannel<ChannelState, DeviceControlMsg::ver>,
190190
}
191191

@@ -199,7 +199,7 @@ impl DeviceControlChannel::ver {
199199
alloc: &mut gpu::KernelAllocators,
200200
) -> Result<DeviceControlChannel::ver> {
201201
Ok(DeviceControlChannel::ver {
202-
dev: dev.clone(),
202+
dev: dev.into(),
203203
ch: TxChannel::<ChannelState, DeviceControlMsg::ver>::new(alloc, 0x100)?,
204204
})
205205
}
@@ -224,7 +224,7 @@ impl DeviceControlChannel::ver {
224224
/// Pipe channel to submit WorkQueue execution requests.
225225
#[versions(AGX)]
226226
pub(crate) struct PipeChannel {
227-
dev: AsahiDevice,
227+
dev: AsahiDevRef,
228228
ch: TxChannel<ChannelState, PipeMsg::ver>,
229229
}
230230

@@ -236,7 +236,7 @@ impl PipeChannel::ver {
236236
alloc: &mut gpu::KernelAllocators,
237237
) -> Result<PipeChannel::ver> {
238238
Ok(PipeChannel::ver {
239-
dev: dev.clone(),
239+
dev: dev.into(),
240240
ch: TxChannel::<ChannelState, PipeMsg::ver>::new(alloc, 0x100)?,
241241
})
242242
}
@@ -255,7 +255,7 @@ impl PipeChannel::ver {
255255

256256
/// Firmware Control channel, used for secure cache flush requests.
257257
pub(crate) struct FwCtlChannel {
258-
dev: AsahiDevice,
258+
dev: AsahiDevRef,
259259
ch: TxChannel<FwCtlChannelState, FwCtlMsg>,
260260
}
261261

@@ -268,7 +268,7 @@ impl FwCtlChannel {
268268
alloc: &mut gpu::KernelAllocators,
269269
) -> Result<FwCtlChannel> {
270270
Ok(FwCtlChannel {
271-
dev: dev.clone(),
271+
dev: dev.into(),
272272
ch: TxChannel::<FwCtlChannelState, FwCtlMsg>::new_uncached(alloc, 0x100)?,
273273
})
274274
}
@@ -293,7 +293,7 @@ impl FwCtlChannel {
293293
/// Event channel, used to notify the driver of command completions, GPU faults and errors, and
294294
/// other events.
295295
pub(crate) struct EventChannel {
296-
dev: AsahiDevice,
296+
dev: AsahiDevRef,
297297
ch: RxChannel<ChannelState, RawEventMsg>,
298298
mgr: Arc<event::EventManager>,
299299
gpu: Option<Arc<dyn gpu::GpuManager>>,
@@ -307,7 +307,7 @@ impl EventChannel {
307307
mgr: Arc<event::EventManager>,
308308
) -> Result<EventChannel> {
309309
Ok(EventChannel {
310-
dev: dev.clone(),
310+
dev: dev.into(),
311311
ch: RxChannel::<ChannelState, RawEventMsg>::new(alloc, 0x100)?,
312312
mgr,
313313
gpu: None,
@@ -378,7 +378,7 @@ impl EventChannel {
378378
/// levels), and it also uses a side buffer to actually hold the log messages, only passing around
379379
/// pointers in the main buffer.
380380
pub(crate) struct FwLogChannel {
381-
dev: AsahiDevice,
381+
dev: AsahiDevRef,
382382
ch: RxChannel<FwLogChannelState, RawFwLogMsg>,
383383
payload_buf: GpuArray<RawFwLogPayloadMsg>,
384384
}
@@ -393,7 +393,7 @@ impl FwLogChannel {
393393
alloc: &mut gpu::KernelAllocators,
394394
) -> Result<FwLogChannel> {
395395
Ok(FwLogChannel {
396-
dev: dev.clone(),
396+
dev: dev.into(),
397397
ch: RxChannel::<FwLogChannelState, RawFwLogMsg>::new(alloc, Self::RING_SIZE)?,
398398
payload_buf: alloc
399399
.shared
@@ -467,7 +467,7 @@ impl FwLogChannel {
467467
}
468468

469469
pub(crate) struct KTraceChannel {
470-
dev: AsahiDevice,
470+
dev: AsahiDevRef,
471471
ch: RxChannel<ChannelState, RawKTraceMsg>,
472472
}
473473

@@ -480,7 +480,7 @@ impl KTraceChannel {
480480
alloc: &mut gpu::KernelAllocators,
481481
) -> Result<KTraceChannel> {
482482
Ok(KTraceChannel {
483-
dev: dev.clone(),
483+
dev: dev.into(),
484484
ch: RxChannel::<ChannelState, RawKTraceMsg>::new(alloc, 0x200)?,
485485
})
486486
}
@@ -502,7 +502,7 @@ impl KTraceChannel {
502502
/// Not really implemented other than debug logs yet...
503503
#[versions(AGX)]
504504
pub(crate) struct StatsChannel {
505-
dev: AsahiDevice,
505+
dev: AsahiDevRef,
506506
ch: RxChannel<ChannelState, RawStatsMsg::ver>,
507507
}
508508

@@ -514,7 +514,7 @@ impl StatsChannel::ver {
514514
alloc: &mut gpu::KernelAllocators,
515515
) -> Result<StatsChannel::ver> {
516516
Ok(StatsChannel::ver {
517-
dev: dev.clone(),
517+
dev: dev.into(),
518518
ch: RxChannel::<ChannelState, RawStatsMsg::ver>::new(alloc, 0x100)?,
519519
})
520520
}

drivers/gpu/drm/asahi/driver.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::{debug, file, gem, gpu, hw, regs};
1010

1111
use kernel::device::RawDevice;
1212
use kernel::macros::vtable;
13+
use kernel::types::ARef;
1314

1415
/// Driver metadata
1516
const INFO: drv::DriverInfo = drv::DriverInfo {
@@ -37,6 +38,7 @@ pub(crate) struct AsahiDriver;
3738

3839
/// Convenience type alias for the DRM device type for this driver.
3940
pub(crate) type AsahiDevice = kernel::drm::device::Device<AsahiDriver>;
41+
pub(crate) type AsahiDevRef = ARef<AsahiDevice>;
4042

4143
/// DRM Driver implementation for `AsahiDriver`.
4244
#[vtable]

drivers/gpu/drm/asahi/gpu.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use kernel::{
3232

3333
use crate::alloc::Allocator;
3434
use crate::debug::*;
35-
use crate::driver::AsahiDevice;
35+
use crate::driver::{AsahiDevRef, AsahiDevice};
3636
use crate::fw::channels::PipeType;
3737
use crate::fw::types::{U32, U64};
3838
use crate::{
@@ -190,7 +190,7 @@ pub(crate) struct SequenceIDs {
190190
#[versions(AGX)]
191191
#[pin_data]
192192
pub(crate) struct GpuManager {
193-
dev: AsahiDevice,
193+
dev: AsahiDevRef,
194194
cfg: &'static hw::HwConfig,
195195
dyncfg: hw::DynConfig,
196196
pub(crate) initdata: fw::types::GpuObject<fw::initdata::InitData::ver>,
@@ -620,7 +620,7 @@ impl GpuManager::ver {
620620
}))?;
621621

622622
let x = UniqueArc::pin_init(try_pin_init!(GpuManager::ver {
623-
dev: dev.clone(),
623+
dev: dev.into(),
624624
cfg,
625625
dyncfg: *dyncfg,
626626
initdata: *initdata,

drivers/gpu/drm/asahi/mmu.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ const PAGETABLES_SIZE: usize = UAT_PGSZ;
181181

182182
/// Inner data for a Vm instance. This is reference-counted by the outer Vm object.
183183
struct VmInner {
184-
dev: driver::AsahiDevice,
184+
dev: driver::AsahiDevRef,
185185
is_kernel: bool,
186186
min_va: usize,
187187
max_va: usize,
@@ -618,7 +618,7 @@ impl UatInner {
618618

619619
/// Top-level UAT manager object
620620
pub(crate) struct Uat {
621-
dev: driver::AsahiDevice,
621+
dev: driver::AsahiDevRef,
622622
cfg: &'static hw::HwConfig,
623623
pagetables_rgn: UatRegion,
624624

@@ -765,15 +765,15 @@ impl io_pgtable::FlushOps for Uat {
765765
impl Vm {
766766
/// Create a new virtual memory address space
767767
fn new(
768-
dev: driver::AsahiDevice,
768+
dev: &driver::AsahiDevice,
769769
uat_inner: Arc<UatInner>,
770770
cfg: &'static hw::HwConfig,
771771
is_kernel: bool,
772772
id: u64,
773773
file_id: u64,
774774
) -> Result<Vm> {
775775
let page_table = AppleUAT::new(
776-
&dev,
776+
dev,
777777
io_pgtable::Config {
778778
pgsize_bitmap: UAT_PGSZ,
779779
ias: if is_kernel { UAT_IAS_KERN } else { UAT_IAS },
@@ -807,7 +807,7 @@ impl Vm {
807807
file_id,
808808
inner: Arc::pin_init(new_mutex!(
809809
VmInner {
810-
dev,
810+
dev: dev.into(),
811811
min_va,
812812
max_va,
813813
is_kernel,
@@ -1168,14 +1168,7 @@ impl Uat {
11681168

11691169
/// Creates a new `Vm` linked to this UAT.
11701170
pub(crate) fn new_vm(&self, id: u64, file_id: u64) -> Result<Vm> {
1171-
Vm::new(
1172-
self.dev.clone(),
1173-
self.inner.clone(),
1174-
self.cfg,
1175-
false,
1176-
id,
1177-
file_id,
1178-
)
1171+
Vm::new(&self.dev, self.inner.clone(), self.cfg, false, id, file_id)
11791172
}
11801173

11811174
/// Creates the reference-counted inner data for a new `Uat` instance.
@@ -1218,16 +1211,16 @@ impl Uat {
12181211
let pagetables_rgn = Self::map_region(dev, c_str!("pagetables"), PAGETABLES_SIZE, true)?;
12191212

12201213
dev_info!(dev, "MMU: Creating kernel page tables\n");
1221-
let kernel_lower_vm = Vm::new(dev.clone(), inner.clone(), cfg, false, 1, 0)?;
1222-
let kernel_vm = Vm::new(dev.clone(), inner.clone(), cfg, true, 0, 0)?;
1214+
let kernel_lower_vm = Vm::new(dev, inner.clone(), cfg, false, 1, 0)?;
1215+
let kernel_vm = Vm::new(dev, inner.clone(), cfg, true, 0, 0)?;
12231216

12241217
dev_info!(dev, "MMU: Kernel page tables created\n");
12251218

12261219
let ttb0 = kernel_lower_vm.ttb();
12271220
let ttb1 = kernel_vm.ttb();
12281221

12291222
let uat = Self {
1230-
dev: dev.clone(),
1223+
dev: dev.into(),
12311224
cfg,
12321225
pagetables_rgn,
12331226
kernel_vm,

drivers/gpu/drm/asahi/queue/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use kernel::{
1818

1919
use crate::alloc::Allocator;
2020
use crate::debug::*;
21-
use crate::driver::AsahiDevice;
21+
use crate::driver::{AsahiDevRef, AsahiDevice};
2222
use crate::fw::types::*;
2323
use crate::gpu::GpuManager;
2424
use crate::inner_weak_ptr;
@@ -94,7 +94,7 @@ impl SubQueueJob::ver {
9494

9595
#[versions(AGX)]
9696
pub(crate) struct Queue {
97-
dev: AsahiDevice,
97+
dev: AsahiDevRef,
9898
_sched: sched::Scheduler<QueueJob::ver>,
9999
entity: sched::Entity<QueueJob::ver>,
100100
vm: mmu::Vm,
@@ -156,7 +156,7 @@ impl dma_fence::FenceOps for JobFence::ver {
156156

157157
#[versions(AGX)]
158158
pub(crate) struct QueueJob {
159-
dev: AsahiDevice,
159+
dev: AsahiDevRef,
160160
vm_bind: mmu::VmBind,
161161
op_guard: Option<gpu::OpGuard>,
162162
sj_vtx: Option<SubQueueJob::ver>,
@@ -407,7 +407,7 @@ impl Queue::ver {
407407
};
408408

409409
let mut ret = Queue::ver {
410-
dev: dev.clone(),
410+
dev: dev.into(),
411411
_sched: sched,
412412
entity,
413413
vm,

0 commit comments

Comments
 (0)