Skip to content

Commit

Permalink
fixup! drm/asahi: Add the Asahi driver for Apple AGX GPUs
Browse files Browse the repository at this point in the history
  • Loading branch information
jannau committed Dec 21, 2024
1 parent 8514c7e commit 5f27855
Show file tree
Hide file tree
Showing 22 changed files with 227 additions and 213 deletions.
2 changes: 1 addition & 1 deletion drivers/gpu/drm/asahi/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ config DRM_ASAHI
depends on DRM
depends on (ARM64 && ARCH_APPLE) || (COMPILE_TEST && !GENERIC_ATOMIC64)
depends on MMU
depends on IOMMU_SUPPORT
select RUST_DRM_SCHED
select IOMMU_SUPPORT
select IOMMU_IO_PGTABLE_LPAE
select RUST_DRM_GEM_SHMEM_HELPER
select RUST_APPLE_RTKIT
Expand Down
22 changes: 11 additions & 11 deletions drivers/gpu/drm/asahi/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ pub(crate) trait Allocator {
#[inline(never)]
fn new_boxed<T: GpuStruct>(
&mut self,
inner: Box<T>,
inner: KBox<T>,
callback: impl for<'a> FnOnce(
&'a T,
&'a mut MaybeUninit<T::Raw<'a>>,
Expand Down Expand Up @@ -600,7 +600,7 @@ impl Drop for HeapAllocation {
if let Some(garbage) = a.garbage.as_mut() {
if garbage.push(node, GFP_KERNEL).is_err() {
dev_err!(
&a.dev,
&a.dev.as_ref(),
"HeapAllocation[{}]::drop: Failed to keep garbage\n",
&*a.name,
);
Expand Down Expand Up @@ -687,7 +687,7 @@ pub(crate) struct HeapAllocator {
min_align: usize,
block_size: usize,
cpu_maps: bool,
guard_nodes: Vec<mm::Node<HeapAllocatorInner, HeapAllocationInner>>,
guard_nodes: KVec<mm::Node<HeapAllocatorInner, HeapAllocationInner>>,
mm: mm::Allocator<HeapAllocatorInner, HeapAllocationInner>,
name: CString,
}
Expand Down Expand Up @@ -720,7 +720,7 @@ impl HeapAllocator {
let inner = HeapAllocatorInner {
dev: dev.into(),
allocated: 0,
backing_objects: Vec::new(),
backing_objects: KVec::new(),
// TODO: This clearly needs a try_clone() or similar
name: CString::try_from_fmt(fmt!("{}", &*name))?,
vm_id: vm.id(),
Expand All @@ -740,7 +740,7 @@ impl HeapAllocator {
min_align,
block_size: block_size.max(min_align),
cpu_maps,
guard_nodes: Vec::new(),
guard_nodes: KVec::new(),
mm,
name,
})
Expand All @@ -765,7 +765,7 @@ impl HeapAllocator {

if self.top.saturating_add(size_aligned as u64) >= self.end {
dev_err!(
&self.dev,
self.dev.as_ref(),
"HeapAllocator[{}]::add_block: Exhausted VA space\n",
&*self.name,
);
Expand Down Expand Up @@ -795,7 +795,7 @@ impl HeapAllocator {
if self.cpu_maps {
let guard = self.min_align.max(mmu::UAT_PGSZ);
mod_dev_dbg!(
&self.dev,
self.dev,
"HeapAllocator[{}]::add_block: Adding guard node {:#x}:{:#x}\n",
&*self.name,
new_top,
Expand All @@ -812,7 +812,7 @@ impl HeapAllocator {
Ok(a) => a,
Err(a) => {
dev_err!(
&self.dev,
self.dev.as_ref(),
"HeapAllocator[{}]::add_block: Failed to reserve guard node {:#x}:{:#x}: {:?}\n",
&*self.name,
guard,
Expand Down Expand Up @@ -917,7 +917,7 @@ impl Allocator for HeapAllocator {
Ok(a) => a,
Err(a) => {
dev_err!(
&self.dev,
&self.dev.as_ref(),
"HeapAllocator[{}]::new: Failed to insert node of size {:#x} / align {:#x}: {:?}\n",
&*self.name, size_aligned, align, a
);
Expand All @@ -933,7 +933,7 @@ impl Allocator for HeapAllocator {
if end > self.top {
if start > self.top {
dev_warn!(
self.dev,
self.dev.as_ref(),
"HeapAllocator[{}]::alloc: top={:#x}, start={:#x}\n",
&*self.name,
self.top,
Expand All @@ -960,7 +960,7 @@ impl Allocator for HeapAllocator {
Ok(a) => a,
Err(_) => {
dev_warn!(
self.dev,
self.dev.as_ref(),
"HeapAllocator[{}]::alloc: Failed to find object at {:#x}\n",
&*self.name,
start
Expand Down
4 changes: 1 addition & 3 deletions drivers/gpu/drm/asahi/asahi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ mod slotalloc;
mod util;
mod workqueue;

use kernel::module_platform_driver;

module_platform_driver! {
kernel::module_platform_driver! {
type: driver::AsahiDriver,
name: "asahi",
license: "Dual MIT/GPL",
Expand Down
10 changes: 5 additions & 5 deletions drivers/gpu/drm/asahi/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ struct BufferInner {
info: GpuObject<buffer::Info::ver>,
ualloc: Arc<Mutex<alloc::DefaultAllocator>>,
ualloc_priv: Arc<Mutex<alloc::DefaultAllocator>>,
blocks: Vec<GpuOnlyArray<u8>>,
blocks: KVec<GpuOnlyArray<u8>>,
max_blocks: usize,
max_blocks_nomemless: usize,
mgr: BufferManager::ver,
Expand Down Expand Up @@ -394,7 +394,7 @@ impl Buffer::ver {
info,
ualloc,
ualloc_priv,
blocks: Vec::new(),
blocks: KVec::new(),
max_blocks,
max_blocks_nomemless,
mgr: mgr.clone(),
Expand Down Expand Up @@ -476,7 +476,7 @@ impl Buffer::ver {
let add_blocks = min_blocks - cur_count;
let new_count = min_blocks;

let mut new_blocks: Vec<GpuOnlyArray<u8>> = Vec::new();
let mut new_blocks: KVec<GpuOnlyArray<u8>> = KVec::new();

// Allocate the new blocks first, so if it fails they will be dropped
let mut ualloc = inner.ualloc.lock();
Expand Down Expand Up @@ -720,7 +720,7 @@ impl slotalloc::SlotItem for BufferSlotInner::ver {
/// Inner data for the event manager, to be protected by the SlotAllocator lock.
#[versions(AGX)]
pub(crate) struct BufferManagerInner {
owners: Vec<Option<Buffer::ver>>,
owners: KVec<Option<Buffer::ver>>,
}

/// The GPU-global buffer manager, used to allocate and release buffer slots from the pool.
Expand All @@ -730,7 +730,7 @@ pub(crate) struct BufferManager(slotalloc::SlotAllocator<BufferSlotInner::ver>);
#[versions(AGX)]
impl BufferManager::ver {
pub(crate) fn new() -> Result<BufferManager::ver> {
let mut owners = Vec::new();
let mut owners = KVec::new();
for _i in 0..(NUM_BUFFERS as usize) {
owners.push(None, GFP_KERNEL)?;
}
Expand Down
44 changes: 29 additions & 15 deletions drivers/gpu/drm/asahi/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,10 @@ impl EventChannel::ver {
EventMsg::Fault => match self.gpu.as_ref() {
Some(gpu) => gpu.handle_fault(),
None => {
dev_crit!(self.dev, "EventChannel: No GPU manager available!\n")
dev_crit!(
self.dev.as_ref(),
"EventChannel: No GPU manager available!\n"
)
}
},
EventMsg::Timeout {
Expand All @@ -358,7 +361,10 @@ impl EventChannel::ver {
} => match self.gpu.as_ref() {
Some(gpu) => gpu.handle_timeout(counter, event_slot),
None => {
dev_crit!(self.dev, "EventChannel: No GPU manager available!\n")
dev_crit!(
self.dev.as_ref(),
"EventChannel: No GPU manager available!\n"
)
}
},
EventMsg::Flag { firing, .. } => {
Expand All @@ -381,16 +387,19 @@ impl EventChannel::ver {
gpu.ack_grow(buffer_slot, vm_slot, counter);
}
None => {
dev_crit!(self.dev, "EventChannel: No GPU manager available!\n")
dev_crit!(
self.dev.as_ref(),
"EventChannel: No GPU manager available!\n"
)
}
},
msg => {
dev_crit!(self.dev, "Unknown event message: {:?}\n", msg);
dev_crit!(self.dev.as_ref(), "Unknown event message: {:?}\n", msg);
}
}
}
_ => {
dev_warn!(self.dev, "Unknown event message: {:?}\n", unsafe {
dev_warn!(self.dev.as_ref(), "Unknown event message: {:?}\n", unsafe {
msg.raw
});
}
Expand Down Expand Up @@ -442,13 +451,13 @@ impl FwLogChannel {
while let Some(msg) = self.ch.peek(i) {
cls_dev_dbg!(FwLogCh, self.dev, "FwLog{}: {:?}\n", i, msg);
if msg.msg_type != 2 {
dev_warn!(self.dev, "Unknown FWLog{} message: {:?}\n", i, msg);
dev_warn!(self.dev.as_ref(), "Unknown FWLog{} message: {:?}\n", i, msg);
self.ch.get(i);
continue;
}
if msg.msg_index.0 as usize >= Self::BUF_SIZE {
dev_warn!(
self.dev,
self.dev.as_ref(),
"FWLog{} message index out of bounds: {:?}\n",
i,
msg
Expand All @@ -459,7 +468,12 @@ impl FwLogChannel {
let index = Self::BUF_SIZE * i + msg.msg_index.0 as usize;
let payload = &self.payload_buf.as_slice()[index];
if payload.msg_type != 3 {
dev_warn!(self.dev, "Unknown FWLog{} payload: {:?}\n", i, payload);
dev_warn!(
self.dev.as_ref(),
"Unknown FWLog{} payload: {:?}\n",
i,
payload
);
self.ch.get(i);
continue;
}
Expand All @@ -468,7 +482,7 @@ impl FwLogChannel {
.unwrap_or(c_str!("cstr_err"))
} else {
dev_warn!(
self.dev,
self.dev.as_ref(),
"FWLog{} payload not NUL-terminated: {:?}\n",
i,
payload
Expand All @@ -477,12 +491,12 @@ impl FwLogChannel {
continue;
};
match i {
0 => dev_dbg!(self.dev, "FWLog: {}\n", msg),
1 => dev_info!(self.dev, "FWLog: {}\n", msg),
2 => dev_notice!(self.dev, "FWLog: {}\n", msg),
3 => dev_warn!(self.dev, "FWLog: {}\n", msg),
4 => dev_err!(self.dev, "FWLog: {}\n", msg),
5 => dev_crit!(self.dev, "FWLog: {}\n", msg),
0 => dev_dbg!(self.dev.as_ref(), "FWLog: {}\n", msg),
1 => dev_info!(self.dev.as_ref(), "FWLog: {}\n", msg),
2 => dev_notice!(self.dev.as_ref(), "FWLog: {}\n", msg),
3 => dev_warn!(self.dev.as_ref(), "FWLog: {}\n", msg),
4 => dev_err!(self.dev.as_ref(), "FWLog: {}\n", msg),
5 => dev_crit!(self.dev.as_ref(), "FWLog: {}\n", msg),
_ => (),
};
self.ch.get(i);
Expand Down
3 changes: 1 addition & 2 deletions drivers/gpu/drm/asahi/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use kernel::{

use crate::{debug, file, gem, gpu, hw, regs};

use kernel::device::RawDevice;
use kernel::macros::vtable;
use kernel::types::ARef;

Expand Down Expand Up @@ -143,7 +142,7 @@ impl platform::Driver for AsahiDriver {
}
_ => {
dev_info!(
dev,
pdev.as_ref(),
"Unsupported GPU/firmware combination ({:?}, {:?}, {:?})\n",
cfg.gpu_gen,
cfg.gpu_variant,
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpu/drm/asahi/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub(crate) struct EventManagerInner {
stamps: GpuArray<Stamp>,
fw_stamps: GpuArray<FwStamp>,
// Note: Use dyn to avoid having to version this entire module.
owners: Vec<Option<Arc<dyn workqueue::WorkQueue + Send + Sync>>>,
owners: KVec<Option<Arc<dyn workqueue::WorkQueue + Send + Sync>>>,
}

/// Top-level EventManager object.
Expand All @@ -140,7 +140,7 @@ impl EventManager {
/// Create a new EventManager.
#[inline(never)]
pub(crate) fn new(alloc: &mut gpu::KernelAllocators) -> Result<EventManager> {
let mut owners = Vec::new();
let mut owners = KVec::new();
for _i in 0..(NUM_EVENTS as usize) {
owners.push(None, GFP_KERNEL)?;
}
Expand Down Expand Up @@ -216,7 +216,7 @@ impl EventManager {

/// Fail all commands, used when the GPU crashes.
pub(crate) fn fail_all(&self, error: workqueue::WorkError) {
let mut owners: Vec<Arc<dyn workqueue::WorkQueue + Send + Sync>> = Vec::new();
let mut owners: KVec<Arc<dyn workqueue::WorkQueue + Send + Sync>> = KVec::new();

self.alloc.with_inner(|inner| {
for wq in inner.owners.iter().filter_map(|o| o.as_ref()).cloned() {
Expand Down
Loading

0 comments on commit 5f27855

Please sign in to comment.