Skip to content

Commit 2979000

Browse files
committed
fixup! drm/asahi: Add the Asahi driver for Apple AGX GPUs
Signed-off-by: Janne Grunau <j@jannau.net>
1 parent c76057a commit 2979000

16 files changed

Lines changed: 248 additions & 164 deletions

File tree

drivers/gpu/drm/asahi/alloc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ impl Drop for HeapAllocation {
627627

628628
alloc.with(|a| {
629629
if let Some(garbage) = a.garbage.as_mut() {
630-
if garbage.try_push(node).is_err() {
630+
if garbage.push(node, GFP_KERNEL).is_err() {
631631
dev_err!(
632632
&a.dev,
633633
"HeapAllocation[{}]::drop: Failed to keep garbage\n",
@@ -825,7 +825,7 @@ impl HeapAllocator {
825825
})?;
826826

827827
self.mm
828-
.with_inner(|inner| inner.backing_objects.try_reserve(1))?;
828+
.with_inner(|inner| inner.backing_objects.reserve(1, GFP_KERNEL))?;
829829

830830
let mut new_top = self.top + size_aligned as u64;
831831
if self.cpu_maps {
@@ -859,7 +859,7 @@ impl HeapAllocator {
859859
}
860860
};
861861

862-
self.guard_nodes.try_push(node)?;
862+
self.guard_nodes.push(node, GFP_KERNEL)?;
863863

864864
new_top += guard as u64;
865865
}

drivers/gpu/drm/asahi/buffer.rs

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -411,26 +411,29 @@ impl Buffer::ver {
411411
})?;
412412

413413
Ok(Buffer::ver {
414-
inner: Arc::pin_init(Mutex::new(BufferInner::ver {
415-
info,
416-
ualloc,
417-
ualloc_priv,
418-
blocks: Vec::new(),
419-
max_blocks,
420-
max_blocks_nomemless,
421-
mgr: mgr.clone(),
422-
active_scenes: 0,
423-
active_slot: None,
424-
last_token: None,
425-
tpc: None,
426-
kernel_buffer,
427-
stats,
428-
cfg: gpu.get_cfg(),
429-
preempt1_size,
430-
preempt2_size,
431-
preempt3_size,
432-
num_clusters,
433-
}))?,
414+
inner: Arc::pin_init(
415+
Mutex::new(BufferInner::ver {
416+
info,
417+
ualloc,
418+
ualloc_priv,
419+
blocks: Vec::new(),
420+
max_blocks,
421+
max_blocks_nomemless,
422+
mgr: mgr.clone(),
423+
active_scenes: 0,
424+
active_slot: None,
425+
last_token: None,
426+
tpc: None,
427+
kernel_buffer,
428+
stats,
429+
cfg: gpu.get_cfg(),
430+
preempt1_size,
431+
preempt2_size,
432+
preempt3_size,
433+
num_clusters,
434+
}),
435+
GFP_KERNEL,
436+
)?,
434437
})
435438
}
436439

@@ -500,20 +503,20 @@ impl Buffer::ver {
500503
// Allocate the new blocks first, so if it fails they will be dropped
501504
let mut ualloc = inner.ualloc.lock();
502505
for _i in 0..add_blocks {
503-
new_blocks.try_push(ualloc.array_gpuonly(BLOCK_SIZE)?)?;
506+
new_blocks.push(ualloc.array_gpuonly(BLOCK_SIZE)?, GFP_KERNEL)?;
504507
}
505508
core::mem::drop(ualloc);
506509

507510
// Then actually commit them
508-
inner.blocks.try_reserve(add_blocks)?;
511+
inner.blocks.reserve(add_blocks, GFP_KERNEL)?;
509512

510513
for (i, block) in new_blocks.into_iter().enumerate() {
511514
let page_num = (block.gpu_va().get() >> PAGE_SHIFT) as u32;
512515

513516
inner
514517
.blocks
515-
.try_push(block)
516-
.expect("try_push() failed after try_reserve()");
518+
.push(block, GFP_KERNEL)
519+
.expect("push() failed after reserve()");
517520
inner.info.block_list[2 * (cur_count + i)] = page_num;
518521
for j in 0..PAGES_PER_BLOCK {
519522
inner.info.page_list[(cur_count + i) * PAGES_PER_BLOCK + j] = page_num + j as u32;
@@ -762,7 +765,7 @@ impl BufferManager::ver {
762765
pub(crate) fn new() -> Result<BufferManager::ver> {
763766
let mut owners = Vec::new();
764767
for _i in 0..(NUM_BUFFERS as usize) {
765-
owners.try_push(None)?;
768+
owners.push(None, GFP_KERNEL)?;
766769
}
767770
Ok(BufferManager::ver(slotalloc::SlotAllocator::new(
768771
NUM_BUFFERS,

drivers/gpu/drm/asahi/event.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl EventManager {
142142
pub(crate) fn new(alloc: &mut gpu::KernelAllocators) -> Result<EventManager> {
143143
let mut owners = Vec::new();
144144
for _i in 0..(NUM_EVENTS as usize) {
145-
owners.try_push(None)?;
145+
owners.push(None, GFP_KERNEL)?;
146146
}
147147
let inner = EventManagerInner {
148148
stamps: alloc.shared.array_empty(NUM_EVENTS as usize)?,
@@ -222,7 +222,7 @@ impl EventManager {
222222

223223
self.alloc.with_inner(|inner| {
224224
for wq in inner.owners.iter().filter_map(|o| o.as_ref()).cloned() {
225-
if owners.try_push(wq).is_err() {
225+
if owners.push(wq, GFP_KERNEL).is_err() {
226226
pr_err!("Failed to signal failure to WorkQueue\n");
227227
}
228228
}

drivers/gpu/drm/asahi/file.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl SyncItem {
119119
}
120120

121121
fn parse_array(file: &DrmFile, ptr: u64, count: u32, out: bool) -> Result<Vec<SyncItem>> {
122-
let mut vec = Vec::try_with_capacity(count as usize)?;
122+
let mut vec = Vec::with_capacity(count as usize, GFP_KERNEL)?;
123123

124124
const STRIDE: usize = core::mem::size_of::<uapi::drm_asahi_sync>();
125125
let size = STRIDE * count as usize;
@@ -136,7 +136,7 @@ impl SyncItem {
136136
// SAFETY: All bit patterns in the struct are valid
137137
let sync = unsafe { sync.assume_init() };
138138

139-
vec.try_push(SyncItem::parse_one(file, sync, out)?)?;
139+
vec.push(SyncItem::parse_one(file, sync, out)?, GFP_KERNEL)?;
140140
}
141141

142142
Ok(vec)
@@ -182,11 +182,14 @@ impl drm::file::DriverFile for File {
182182
let id = gpu.ids().file.next();
183183

184184
mod_dev_dbg!(device, "[File {}]: DRM device opened\n", id);
185-
Ok(Box::into_pin(Box::try_new(Self {
186-
id,
187-
vms: xarray::XArray::new(xarray::flags::ALLOC1),
188-
queues: xarray::XArray::new(xarray::flags::ALLOC1),
189-
})?))
185+
Ok(Box::into_pin(Box::new(
186+
Self {
187+
id,
188+
vms: xarray::XArray::new(xarray::flags::ALLOC1),
189+
queues: xarray::XArray::new(xarray::flags::ALLOC1),
190+
},
191+
GFP_KERNEL,
192+
)?))
190193
}
191194
}
192195

@@ -688,7 +691,7 @@ impl File {
688691
.new_queue(vm, ualloc, ualloc_priv, data.priority, data.queue_caps)?;
689692

690693
data.queue_id = resv.index().try_into()?;
691-
resv.store(Arc::pin_init(Mutex::new(queue))?)?;
694+
resv.store(Arc::pin_init(Mutex::new(queue), GFP_KERNEL)?)?;
692695

693696
Ok(0)
694697
}
@@ -802,7 +805,7 @@ impl File {
802805
data.queue_id,
803806
id
804807
);
805-
let mut commands = Vec::try_with_capacity(data.command_count as usize)?;
808+
let mut commands = Vec::with_capacity(data.command_count as usize, GFP_KERNEL)?;
806809

807810
const STRIDE: usize = core::mem::size_of::<uapi::drm_asahi_command>();
808811
let size = STRIDE * data.command_count as usize;
@@ -818,7 +821,7 @@ impl File {
818821
unsafe { reader.read_raw(cmd.as_mut_ptr() as *mut u8, STRIDE)? };
819822

820823
// SAFETY: All bit patterns in the struct are valid
821-
commands.try_push(unsafe { cmd.assume_init() })?;
824+
commands.push(unsafe { cmd.assume_init() }, GFP_KERNEL)?;
822825
}
823826

824827
let ret = queue

drivers/gpu/drm/asahi/gpu.rs

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,14 @@ impl GpuManager::ver {
490490
.zip(&mgr.pipes.frag)
491491
.zip(&mgr.pipes.comp)
492492
{
493-
p_pipes.try_push(fw::initdata::raw::PipeChannels::ver {
494-
vtx: v.lock().to_raw(),
495-
frag: f.lock().to_raw(),
496-
comp: c.lock().to_raw(),
497-
})?;
493+
p_pipes.push(
494+
fw::initdata::raw::PipeChannels::ver {
495+
vtx: v.lock().to_raw(),
496+
frag: f.lock().to_raw(),
497+
comp: c.lock().to_raw(),
498+
},
499+
GFP_KERNEL,
500+
)?;
498501
}
499502

500503
mgr.as_mut()
@@ -532,7 +535,7 @@ impl GpuManager::ver {
532535
raw.sgx_sram_ptr = U64(mapping.iova());
533536
});
534537

535-
mgr.as_mut().io_mappings_mut().try_push(mapping)?;
538+
mgr.as_mut().io_mappings_mut().push(mapping, GFP_KERNEL)?;
536539
}
537540

538541
let mgr = Arc::from(mgr);
@@ -601,7 +604,10 @@ impl GpuManager::ver {
601604
#[ver(G < G14X)]
602605
let map_kernel_to_user = false;
603606

604-
Ok(Box::try_new(mmu::Uat::new(dev, cfg, map_kernel_to_user)?)?)
607+
Ok(Box::new(
608+
mmu::Uat::new(dev, cfg, map_kernel_to_user)?,
609+
GFP_KERNEL,
610+
)?)
605611
}
606612

607613
/// Actually create the final GpuManager instance, as a UniqueArc.
@@ -624,18 +630,36 @@ impl GpuManager::ver {
624630
};
625631

626632
for _i in 0..=NUM_PIPES - 1 {
627-
pipes.vtx.try_push(Box::pin_init(Mutex::new_named(
628-
channel::PipeChannel::ver::new(dev, &mut alloc)?,
629-
c_str!("pipe_vtx"),
630-
))?)?;
631-
pipes.frag.try_push(Box::pin_init(Mutex::new_named(
632-
channel::PipeChannel::ver::new(dev, &mut alloc)?,
633-
c_str!("pipe_frag"),
634-
))?)?;
635-
pipes.comp.try_push(Box::pin_init(Mutex::new_named(
636-
channel::PipeChannel::ver::new(dev, &mut alloc)?,
637-
c_str!("pipe_comp"),
638-
))?)?;
633+
pipes.vtx.push(
634+
Box::pin_init(
635+
Mutex::new_named(
636+
channel::PipeChannel::ver::new(dev, &mut alloc)?,
637+
c_str!("pipe_vtx"),
638+
),
639+
GFP_KERNEL,
640+
)?,
641+
GFP_KERNEL,
642+
)?;
643+
pipes.frag.push(
644+
Box::pin_init(
645+
Mutex::new_named(
646+
channel::PipeChannel::ver::new(dev, &mut alloc)?,
647+
c_str!("pipe_frag"),
648+
),
649+
GFP_KERNEL,
650+
)?,
651+
GFP_KERNEL,
652+
)?;
653+
pipes.comp.push(
654+
Box::pin_init(
655+
Mutex::new_named(
656+
channel::PipeChannel::ver::new(dev, &mut alloc)?,
657+
c_str!("pipe_comp"),
658+
),
659+
GFP_KERNEL,
660+
)?,
661+
GFP_KERNEL,
662+
)?;
639663
}
640664

641665
let fwctl_channel = channel::FwCtlChannel::new(dev, &mut alloc)?;
@@ -1182,18 +1206,21 @@ impl GpuManager for GpuManager::ver {
11821206
) -> Result<Box<dyn queue::Queue>> {
11831207
let mut kalloc = self.alloc();
11841208
let id = self.ids.queue.next();
1185-
Ok(Box::try_new(queue::Queue::ver::new(
1186-
&self.dev,
1187-
vm,
1188-
&mut kalloc,
1189-
ualloc,
1190-
ualloc_priv,
1191-
self.event_manager.clone(),
1192-
&self.buffer_mgr,
1193-
id,
1194-
priority,
1195-
caps,
1196-
)?)?)
1209+
Ok(Box::new(
1210+
queue::Queue::ver::new(
1211+
&self.dev,
1212+
vm,
1213+
&mut kalloc,
1214+
ualloc,
1215+
ualloc_priv,
1216+
self.event_manager.clone(),
1217+
&self.buffer_mgr,
1218+
id,
1219+
priority,
1220+
caps,
1221+
)?,
1222+
GFP_KERNEL,
1223+
)?)
11971224
}
11981225

11991226
fn kick_firmware(&self) -> Result {
@@ -1357,7 +1384,7 @@ impl GpuManager for GpuManager::ver {
13571384
fn add_completed_work(&self, work: Vec<Box<dyn workqueue::GenSubmittedWork>>) {
13581385
let mut garbage = self.garbage_work.lock();
13591386

1360-
if garbage.try_reserve(work.len()).is_err() {
1387+
if garbage.reserve(work.len(), GFP_KERNEL).is_err() {
13611388
dev_err!(
13621389
self.dev,
13631390
"Failed to reserve space for completed work, deadlock possible.\n"
@@ -1367,15 +1394,15 @@ impl GpuManager for GpuManager::ver {
13671394

13681395
for i in work {
13691396
garbage
1370-
.try_push(i)
1371-
.expect("try_push() failed after try_reserve()");
1397+
.push(i, GFP_KERNEL)
1398+
.expect("push() failed after reserve()");
13721399
}
13731400
}
13741401

13751402
fn free_context(&self, ctx: Box<fw::types::GpuObject<fw::workqueue::GpuContextData>>) {
13761403
let mut garbage = self.garbage_contexts.lock();
13771404

1378-
if garbage.try_push(ctx).is_err() {
1405+
if garbage.push(ctx, GFP_KERNEL).is_err() {
13791406
dev_err!(
13801407
self.dev,
13811408
"Failed to reserve space for freed context, deadlock possible.\n"

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,14 @@ impl PwrConfig {
514514

515515
let pwr_mw = pwr_uw / 1000;
516516

517-
perf_states.try_push(PState {
518-
freq_hz: freq_hz.try_into()?,
519-
volt_mv,
520-
pwr_mw,
521-
})?;
517+
perf_states.push(
518+
PState {
519+
freq_hz: freq_hz.try_into()?,
520+
volt_mv,
521+
pwr_mw,
522+
},
523+
GFP_KERNEL,
524+
)?;
522525
}
523526

524527
if perf_states.is_empty() {
@@ -560,11 +563,14 @@ impl PwrConfig {
560563
let pz_count = pz_data.len() / 3;
561564
let mut power_zones = Vec::new();
562565
for i in (0..pz_count).step_by(3) {
563-
power_zones.try_push(PowerZone {
564-
target: pz_data[i],
565-
target_offset: pz_data[i + 1],
566-
filter_tc: pz_data[i + 2],
567-
})?;
566+
power_zones.push(
567+
PowerZone {
568+
target: pz_data[i],
569+
target_offset: pz_data[i + 1],
570+
filter_tc: pz_data[i + 2],
571+
},
572+
GFP_KERNEL,
573+
)?;
568574
}
569575

570576
let core_leak_coef: Vec<F32> = prop!("apple,core-leak-coef");

0 commit comments

Comments
 (0)