From 5f27855628bec73f8d5f9ed2832cb63f302b1344 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Sat, 9 Nov 2024 23:10:46 +0100 Subject: [PATCH] fixup! drm/asahi: Add the Asahi driver for Apple AGX GPUs --- drivers/gpu/drm/asahi/Kconfig | 2 +- drivers/gpu/drm/asahi/alloc.rs | 22 ++-- drivers/gpu/drm/asahi/asahi.rs | 4 +- drivers/gpu/drm/asahi/buffer.rs | 10 +- drivers/gpu/drm/asahi/channel.rs | 44 +++++--- drivers/gpu/drm/asahi/driver.rs | 3 +- drivers/gpu/drm/asahi/event.rs | 6 +- drivers/gpu/drm/asahi/file.rs | 24 ++--- drivers/gpu/drm/asahi/fw/types.rs | 1 - drivers/gpu/drm/asahi/gem.rs | 4 +- drivers/gpu/drm/asahi/gpu.rs | 138 ++++++++++++++----------- drivers/gpu/drm/asahi/hw/mod.rs | 54 +++++----- drivers/gpu/drm/asahi/initdata.rs | 9 +- drivers/gpu/drm/asahi/microseq.rs | 4 +- drivers/gpu/drm/asahi/mmu.rs | 39 ++++--- drivers/gpu/drm/asahi/object.rs | 15 ++- drivers/gpu/drm/asahi/queue/compute.rs | 2 +- drivers/gpu/drm/asahi/queue/mod.rs | 26 ++--- drivers/gpu/drm/asahi/queue/render.rs | 2 +- drivers/gpu/drm/asahi/regs.rs | 15 +-- drivers/gpu/drm/asahi/slotalloc.rs | 5 +- drivers/gpu/drm/asahi/workqueue.rs | 11 +- 22 files changed, 227 insertions(+), 213 deletions(-) diff --git a/drivers/gpu/drm/asahi/Kconfig b/drivers/gpu/drm/asahi/Kconfig index 0436f6a93e2a14..dcf19f96a60ecb 100644 --- a/drivers/gpu/drm/asahi/Kconfig +++ b/drivers/gpu/drm/asahi/Kconfig @@ -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 diff --git a/drivers/gpu/drm/asahi/alloc.rs b/drivers/gpu/drm/asahi/alloc.rs index f042cd7ebcbee0..58bf7706686380 100644 --- a/drivers/gpu/drm/asahi/alloc.rs +++ b/drivers/gpu/drm/asahi/alloc.rs @@ -212,7 +212,7 @@ pub(crate) trait Allocator { #[inline(never)] fn new_boxed( &mut self, - inner: Box, + inner: KBox, callback: impl for<'a> FnOnce( &'a T, &'a mut MaybeUninit>, @@ -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, ); @@ -687,7 +687,7 @@ pub(crate) struct HeapAllocator { min_align: usize, block_size: usize, cpu_maps: bool, - guard_nodes: Vec>, + guard_nodes: KVec>, mm: mm::Allocator, name: CString, } @@ -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(), @@ -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, }) @@ -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, ); @@ -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, @@ -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, @@ -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 ); @@ -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, @@ -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 diff --git a/drivers/gpu/drm/asahi/asahi.rs b/drivers/gpu/drm/asahi/asahi.rs index 5423c856abcea7..93fca9f14b5d41 100644 --- a/drivers/gpu/drm/asahi/asahi.rs +++ b/drivers/gpu/drm/asahi/asahi.rs @@ -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", diff --git a/drivers/gpu/drm/asahi/buffer.rs b/drivers/gpu/drm/asahi/buffer.rs index 01c65cc9ba9223..9893c0f3949c6e 100644 --- a/drivers/gpu/drm/asahi/buffer.rs +++ b/drivers/gpu/drm/asahi/buffer.rs @@ -275,7 +275,7 @@ struct BufferInner { info: GpuObject, ualloc: Arc>, ualloc_priv: Arc>, - blocks: Vec>, + blocks: KVec>, max_blocks: usize, max_blocks_nomemless: usize, mgr: BufferManager::ver, @@ -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(), @@ -476,7 +476,7 @@ impl Buffer::ver { let add_blocks = min_blocks - cur_count; let new_count = min_blocks; - let mut new_blocks: Vec> = Vec::new(); + let mut new_blocks: KVec> = KVec::new(); // Allocate the new blocks first, so if it fails they will be dropped let mut ualloc = inner.ualloc.lock(); @@ -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>, + owners: KVec>, } /// The GPU-global buffer manager, used to allocate and release buffer slots from the pool. @@ -730,7 +730,7 @@ pub(crate) struct BufferManager(slotalloc::SlotAllocator); #[versions(AGX)] impl BufferManager::ver { pub(crate) fn new() -> Result { - let mut owners = Vec::new(); + let mut owners = KVec::new(); for _i in 0..(NUM_BUFFERS as usize) { owners.push(None, GFP_KERNEL)?; } diff --git a/drivers/gpu/drm/asahi/channel.rs b/drivers/gpu/drm/asahi/channel.rs index e46c17f98a146f..6f25759b967f84 100644 --- a/drivers/gpu/drm/asahi/channel.rs +++ b/drivers/gpu/drm/asahi/channel.rs @@ -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 { @@ -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, .. } => { @@ -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 }); } @@ -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 @@ -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; } @@ -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 @@ -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); diff --git a/drivers/gpu/drm/asahi/driver.rs b/drivers/gpu/drm/asahi/driver.rs index 0fa8b533651069..4198c491d549f8 100644 --- a/drivers/gpu/drm/asahi/driver.rs +++ b/drivers/gpu/drm/asahi/driver.rs @@ -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; @@ -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, diff --git a/drivers/gpu/drm/asahi/event.rs b/drivers/gpu/drm/asahi/event.rs index cb4387c483b401..b9a50938f54ae1 100644 --- a/drivers/gpu/drm/asahi/event.rs +++ b/drivers/gpu/drm/asahi/event.rs @@ -128,7 +128,7 @@ pub(crate) struct EventManagerInner { stamps: GpuArray, fw_stamps: GpuArray, // Note: Use dyn to avoid having to version this entire module. - owners: Vec>>, + owners: KVec>>, } /// Top-level EventManager object. @@ -140,7 +140,7 @@ impl EventManager { /// Create a new EventManager. #[inline(never)] pub(crate) fn new(alloc: &mut gpu::KernelAllocators) -> Result { - let mut owners = Vec::new(); + let mut owners = KVec::new(); for _i in 0..(NUM_EVENTS as usize) { owners.push(None, GFP_KERNEL)?; } @@ -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> = Vec::new(); + let mut owners: KVec> = KVec::new(); self.alloc.with_inner(|inner| { for wq in inner.owners.iter().filter_map(|o| o.as_ref()).cloned() { diff --git a/drivers/gpu/drm/asahi/file.rs b/drivers/gpu/drm/asahi/file.rs index fbe24b2e646152..94f1186e76e06c 100644 --- a/drivers/gpu/drm/asahi/file.rs +++ b/drivers/gpu/drm/asahi/file.rs @@ -99,8 +99,8 @@ impl SyncItem { } } - fn parse_array(file: &DrmFile, ptr: u64, count: u32, out: bool) -> Result> { - let mut vec = Vec::with_capacity(count as usize, GFP_KERNEL)?; + fn parse_array(file: &DrmFile, ptr: u64, count: u32, out: bool) -> Result> { + let mut vec = KVec::with_capacity(count as usize, GFP_KERNEL)?; const STRIDE: usize = core::mem::size_of::(); let size = STRIDE * count as usize; @@ -127,8 +127,8 @@ impl SyncItem { /// State associated with a client. pub(crate) struct File { id: u64, - vms: xarray::XArray>, - queues: xarray::XArray>>>, + vms: xarray::XArray>, + queues: xarray::XArray>>>, } /// Convenience type alias for our DRM `File` type. @@ -158,33 +158,33 @@ impl drm::file::DriverFile for File { type Driver = driver::AsahiDriver; /// Create a new `File` instance for a fresh client. - fn open(device: &AsahiDevice) -> Result>> { + fn open(device: &AsahiDevice) -> Result>> { debug::update_debug_flags(); let gpu = &device.data().gpu; let id = gpu.ids().file.next(); mod_dev_dbg!(device, "[File {}]: DRM device opened\n", id); - Ok(Box::into_pin(Box::new( + Ok(KBox::pin( Self { id, vms: xarray::XArray::new(xarray::flags::ALLOC1), queues: xarray::XArray::new(xarray::flags::ALLOC1), }, GFP_KERNEL, - )?)) + )?) } } impl File { - fn vms(self: Pin<&Self>) -> Pin<&xarray::XArray>> { + fn vms(self: Pin<&Self>) -> Pin<&xarray::XArray>> { // SAFETY: Structural pinned projection for vms. // We never move out of this field. unsafe { self.map_unchecked(|s| &s.vms) } } #[allow(clippy::type_complexity)] - fn queues(self: Pin<&Self>) -> Pin<&xarray::XArray>>>> { + fn queues(self: Pin<&Self>) -> Pin<&xarray::XArray>>>> { // SAFETY: Structural pinned projection for queues. // We never move out of this field. unsafe { self.map_unchecked(|s| &s.queues) } @@ -655,7 +655,7 @@ impl File { gpu.update_globals(); // Upgrade to Arc to drop the XArray lock early - let queue: Arc>> = file + let queue: Arc>> = file .inner() .queues() .get(data.queue_id.try_into()?) @@ -710,7 +710,7 @@ impl File { data.queue_id, id ); - let mut commands = Vec::with_capacity(data.command_count as usize, GFP_KERNEL)?; + let mut commands = KVec::with_capacity(data.command_count as usize, GFP_KERNEL)?; const STRIDE: usize = core::mem::size_of::(); let size = STRIDE * data.command_count as usize; @@ -737,7 +737,7 @@ impl File { Err(ERESTARTSYS) => Err(ERESTARTSYS), Err(e) => { dev_info!( - device, + device.as_ref(), "[File {} Queue {}]: IOCTL: submit failed! (submission ID: {} err: {:?})\n", file.inner().id, data.queue_id, diff --git a/drivers/gpu/drm/asahi/fw/types.rs b/drivers/gpu/drm/asahi/fw/types.rs index fd6cdd29fc1a13..6ed628afd0b017 100644 --- a/drivers/gpu/drm/asahi/fw/types.rs +++ b/drivers/gpu/drm/asahi/fw/types.rs @@ -10,7 +10,6 @@ pub(crate) use crate::event::EventValue; pub(crate) use crate::object::{GpuPointer, GpuStruct, GpuWeakPointer}; pub(crate) use crate::{f32, float::F32}; -pub(crate) use ::alloc::boxed::Box; pub(crate) use core::fmt::Debug; pub(crate) use core::marker::PhantomData; pub(crate) use core::sync::atomic::{AtomicI32, AtomicU32, AtomicU64}; diff --git a/drivers/gpu/drm/asahi/gem.rs b/drivers/gpu/drm/asahi/gem.rs index b7b6640940e04b..39c7835ed94427 100644 --- a/drivers/gpu/drm/asahi/gem.rs +++ b/drivers/gpu/drm/asahi/gem.rs @@ -237,10 +237,8 @@ pub(crate) fn lookup_handle(file: &DrmFile, handle: u32) -> Result { } impl gem::BaseDriverObject for DriverObject { - type Initializer = impl PinInit; - /// Callback to create the inner data of a GEM object - fn new(_dev: &AsahiDevice, _size: usize) -> Self::Initializer { + fn new(_dev: &AsahiDevice, _size: usize) -> impl PinInit { let id = GEM_ID.fetch_add(1, Ordering::Relaxed); mod_pr_debug!("DriverObject::new id={}\n", id); try_pin_init!(DriverObject { diff --git a/drivers/gpu/drm/asahi/gpu.rs b/drivers/gpu/drm/asahi/gpu.rs index 9241fb7a795c62..6cecf9aa535bc0 100644 --- a/drivers/gpu/drm/asahi/gpu.rs +++ b/drivers/gpu/drm/asahi/gpu.rs @@ -128,9 +128,9 @@ struct RxChannels { /// GPU work submission pipe channels (driver->GPU). #[versions(AGX)] struct PipeChannels { - pub(crate) vtx: Vec>>>, - pub(crate) frag: Vec>>>, - pub(crate) comp: Vec>>>, + pub(crate) vtx: KVec>>>, + pub(crate) frag: KVec>>>, + pub(crate) comp: KVec>>>, } /// Misc command transmit (driver->GPU) channels. @@ -218,7 +218,7 @@ pub(crate) struct GpuManager { garbage_work: Mutex>>, #[allow(clippy::vec_box)] #[pin] - garbage_contexts: Mutex>>>, + garbage_contexts: Mutex>>>, } /// Trait used to abstract the firmware/GPU-dependent variants of the GpuManager. @@ -247,7 +247,7 @@ pub(crate) trait GpuManager: Send + Sync { ualloc_priv: Arc>, priority: u32, caps: u32, - ) -> Result>; + ) -> Result>; /// Return a reference to the global `SequenceIDs` instance. fn ids(&self) -> &SequenceIDs; /// Kick the firmware (wake it up if asleep). @@ -295,10 +295,10 @@ impl rtkit::Operations for GpuManager::ver { fn recv_message(data: ::Borrowed<'_>, ep: u8, msg: u64) { let dev = &data.dev; - //dev_info!(dev, "RtKit message: {:#x}:{:#x}\n", ep, msg); + //dev_info!(dev.as_ref(), "RtKit message: {:#x}:{:#x}\n", ep, msg); if ep != EP_FIRMWARE || msg != MSG_RX_DOORBELL { - dev_err!(dev, "Unknown message: {:#x}:{:#x}\n", ep, msg); + dev_err!(dev.as_ref(), "Unknown message: {:#x}:{:#x}\n", ep, msg); return; } @@ -318,7 +318,7 @@ impl rtkit::Operations for GpuManager::ver { if debug_enabled(DebugFlags::OopsOnGpuCrash) { panic!("GPU firmware crashed"); } else { - dev_err!(dev, "GPU firmware crashed, failing all jobs\n"); + dev_err!(dev.as_ref(), "GPU firmware crashed, failing all jobs\n"); data.event_manager.fail_all(workqueue::WorkError::NoDevice); } } @@ -477,7 +477,7 @@ impl GpuManager::ver { }); } - let mut p_pipes: Vec = Vec::new(); + let mut p_pipes: KVec = KVec::new(); for ((v, f), c) in mgr .pipes @@ -535,7 +535,7 @@ impl GpuManager::ver { let mgr = Arc::from(mgr); - let rtkit = rtkit::RtKit::::new(dev, None, 0, mgr.clone())?; + let rtkit = rtkit::RtKit::::new(dev.as_ref(), None, 0, mgr.clone())?; *mgr.rtkit.lock() = Some(rtkit); @@ -567,7 +567,7 @@ impl GpuManager::ver { cfg: &'static hw::HwConfig, dyncfg: &hw::DynConfig, alloc: &mut KernelAllocators, - ) -> Result>> { + ) -> Result>> { let mut builder = initdata::InitDataBuilder::ver::new(dev, alloc, cfg, dyncfg); builder.build() } @@ -576,7 +576,7 @@ impl GpuManager::ver { /// /// Force disable inlining to avoid blowing up the stack. #[inline(never)] - fn make_uat(dev: &AsahiDevice, cfg: &'static hw::HwConfig) -> Result> { + fn make_uat(dev: &AsahiDevice, cfg: &'static hw::HwConfig) -> Result> { // G14X has a new thing in the Scene structure that unfortunately requires // write access from user contexts. Hopefully it's not security-sensitive. #[ver(G >= G14X)] @@ -584,7 +584,7 @@ impl GpuManager::ver { #[ver(G < G14X)] let map_kernel_to_user = false; - Ok(Box::new( + Ok(KBox::new( mmu::Uat::new(dev, cfg, map_kernel_to_user)?, GFP_KERNEL, )?) @@ -597,21 +597,21 @@ impl GpuManager::ver { fn make_mgr( dev: &AsahiDevice, cfg: &'static hw::HwConfig, - dyncfg: Box, - uat: Box, + dyncfg: KBox, + uat: KBox, mut alloc: KernelAllocators, event_manager: Arc, - initdata: Box>, + initdata: KBox>, ) -> Result>> { let mut pipes = PipeChannels::ver { - vtx: Vec::new(), - frag: Vec::new(), - comp: Vec::new(), + vtx: KVec::new(), + frag: KVec::new(), + comp: KVec::new(), }; for _i in 0..=NUM_PIPES - 1 { pipes.vtx.push( - Box::pin_init( + KBox::pin_init( Mutex::new_named( channel::PipeChannel::ver::new(dev, &mut alloc)?, c_str!("pipe_vtx"), @@ -621,7 +621,7 @@ impl GpuManager::ver { GFP_KERNEL, )?; pipes.frag.push( - Box::pin_init( + KBox::pin_init( Mutex::new_named( channel::PipeChannel::ver::new(dev, &mut alloc)?, c_str!("pipe_frag"), @@ -631,7 +631,7 @@ impl GpuManager::ver { GFP_KERNEL, )?; pipes.comp.push( - Box::pin_init( + KBox::pin_init( Mutex::new_named( channel::PipeChannel::ver::new(dev, &mut alloc)?, c_str!("pipe_comp"), @@ -648,7 +648,7 @@ impl GpuManager::ver { let event_manager_clone = event_manager.clone(); let buffer_mgr_clone = buffer_mgr.clone(); let alloc_ref = &mut alloc; - let rx_channels = Box::init( + let rx_channels = KBox::init( try_init!(RxChannels::ver { event: channel::EventChannel::ver::new( dev, @@ -701,12 +701,12 @@ impl GpuManager::ver { res: ®s::Resources, cfg: &'static hw::HwConfig, uat: &mmu::Uat, - ) -> Result> { + ) -> Result> { let gpu_id = res.get_gpu_id()?; - dev_info!(dev, "GPU Information:\n"); + dev_info!(dev.as_ref(), "GPU Information:\n"); dev_info!( - dev, + dev.as_ref(), " Type: {:?}{:?}\n", gpu_id.gpu_gen, gpu_id.gpu_variant @@ -714,33 +714,37 @@ impl GpuManager::ver { dev_info!(dev, " Max dies: {}\n", gpu_id.max_dies); dev_info!(dev, " Clusters: {}\n", gpu_id.num_clusters); dev_info!( - dev, + dev.as_ref(), " Cores: {} ({})\n", gpu_id.num_cores, gpu_id.num_cores * gpu_id.num_clusters ); dev_info!( - dev, + dev.as_ref(), " Frags: {} ({})\n", gpu_id.num_frags, gpu_id.num_frags * gpu_id.num_clusters ); dev_info!( - dev, + dev.as_ref(), " GPs: {} ({})\n", gpu_id.num_gps, gpu_id.num_gps * gpu_id.num_clusters ); - dev_info!(dev, " Core masks: {:#x?}\n", gpu_id.core_masks); - dev_info!(dev, " Active cores: {}\n", gpu_id.total_active_cores); + dev_info!(dev.as_ref(), " Core masks: {:#x?}\n", gpu_id.core_masks); + dev_info!( + dev.as_ref(), + " Active cores: {}\n", + gpu_id.total_active_cores + ); - dev_info!(dev, "Getting configuration from device tree...\n"); + dev_info!(dev.as_ref(), "Getting configuration from device tree...\n"); let pwr_cfg = hw::PwrConfig::load(dev, cfg)?; - dev_info!(dev, "Dynamic configuration fetched\n"); + dev_info!(dev.as_ref(), "Dynamic configuration fetched\n"); if gpu_id.gpu_gen != cfg.gpu_gen || gpu_id.gpu_variant != cfg.gpu_variant { dev_err!( - dev, + dev.as_ref(), "GPU type mismatch (expected {:?}{:?}, found {:?}{:?})\n", cfg.gpu_gen, cfg.gpu_variant, @@ -751,7 +755,7 @@ impl GpuManager::ver { } if gpu_id.num_clusters > cfg.max_num_clusters { dev_err!( - dev, + dev.as_ref(), "Too many clusters ({} > {})\n", gpu_id.num_clusters, cfg.max_num_clusters @@ -760,7 +764,7 @@ impl GpuManager::ver { } if gpu_id.num_cores > cfg.max_num_cores { dev_err!( - dev, + dev.as_ref(), "Too many cores ({} > {})\n", gpu_id.num_cores, cfg.max_num_cores @@ -769,7 +773,7 @@ impl GpuManager::ver { } if gpu_id.num_frags > cfg.max_num_frags { dev_err!( - dev, + dev.as_ref(), "Too many frags ({} > {})\n", gpu_id.num_frags, cfg.max_num_frags @@ -778,7 +782,7 @@ impl GpuManager::ver { } if gpu_id.num_gps > cfg.max_num_gps { dev_err!( - dev, + dev.as_ref(), "Too many GPs ({} > {})\n", gpu_id.num_gps, cfg.max_num_gps @@ -839,7 +843,7 @@ impl GpuManager::ver { /// Mark work associated with currently in-progress event slots as failed, after a fault or /// timeout. fn mark_pending_events(&self, culprit_slot: Option, error: workqueue::WorkError) { - dev_err!(self.dev, " Pending events:\n"); + dev_err!(self.dev.as_ref(), " Pending events:\n"); self.initdata.globals.with(|raw, _inner| { for (index, i) in raw.pending_stamps.iter().enumerate() { @@ -856,7 +860,7 @@ impl GpuManager::ver { #[ver(V < V13_5)] let flags = info & 0x7; dev_err!( - self.dev, + self.dev.as_ref(), " [{}:{}] flags={} value={:#x}\n", index, slot, @@ -890,7 +894,11 @@ impl GpuManager::ver { let info = res.get_fault_info(self.cfg); if info.is_some() { - dev_err!(self.dev, " Fault info: {:#x?}\n", info.as_ref().unwrap()); + dev_err!( + self.dev.as_ref(), + " Fault info: {:#x?}\n", + info.as_ref().unwrap() + ); } info } @@ -900,8 +908,8 @@ impl GpuManager::ver { self.initdata.fw_status.with(|raw, _inner| { let halt_count = raw.flags.halt_count.load(Ordering::Relaxed); let mut halted = raw.flags.halted.load(Ordering::Relaxed); - dev_err!(self.dev, " Halt count: {}\n", halt_count); - dev_err!(self.dev, " Halted: {}\n", halted); + dev_err!(self.dev.as_ref(), " Halt count: {}\n", halt_count); + dev_err!(self.dev.as_ref(), " Halted: {}\n", halted); if halted == 0 { let start = clock::KernelTime::now(); @@ -916,13 +924,16 @@ impl GpuManager::ver { } if debug_enabled(DebugFlags::NoGpuRecovery) { - dev_crit!(self.dev, " GPU recovery is disabled, wedging forever!\n"); + dev_crit!( + self.dev.as_ref(), + " GPU recovery is disabled, wedging forever!\n" + ); } else if halted != 0 { - dev_err!(self.dev, " Attempting recovery...\n"); + dev_err!(self.dev.as_ref(), " Attempting recovery...\n"); raw.flags.halted.store(0, Ordering::SeqCst); raw.flags.resume.store(1, Ordering::SeqCst); } else { - dev_err!(self.dev, " Cannot recover.\n"); + dev_err!(self.dev.as_ref(), " Cannot recover.\n"); } }); } @@ -1097,12 +1108,15 @@ impl GpuManager for GpuManager::ver { self.garbage_work.lock().clear(); /* Clean up idle contexts */ - let mut garbage_ctx = Vec::new(); + let mut garbage_ctx = KVec::new(); core::mem::swap(&mut *self.garbage_contexts.lock(), &mut garbage_ctx); for ctx in garbage_ctx { if self.invalidate_context(&ctx).is_err() { - dev_err!(self.dev, "GpuContext: Failed to invalidate GPU context!\n"); + dev_err!( + self.dev.as_ref(), + "GpuContext: Failed to invalidate GPU context!\n" + ); if debug_enabled(DebugFlags::OopsOnGpuCrash) { panic!("GPU firmware timed out"); } @@ -1119,7 +1133,7 @@ impl GpuManager for GpuManager::ver { garbage_bytes ); if self.flush_fw_cache().is_err() { - dev_err!(self.dev, "Failed to flush FW cache\n"); + dev_err!(self.dev.as_ref(), "Failed to flush FW cache\n"); } else { guard.private.collect_garbage(garbage_count); } @@ -1134,7 +1148,7 @@ impl GpuManager for GpuManager::ver { garbage_bytes ); if self.flush_fw_cache().is_err() { - dev_err!(self.dev, "Failed to flush FW cache\n"); + dev_err!(self.dev.as_ref(), "Failed to flush FW cache\n"); } else { guard.gpu_ro.collect_garbage(garbage_count); } @@ -1158,10 +1172,10 @@ impl GpuManager for GpuManager::ver { ualloc_priv: Arc>, priority: u32, caps: u32, - ) -> Result> { + ) -> Result> { let mut kalloc = self.alloc(); let id = self.ids.queue.next(); - Ok(Box::new( + Ok(KBox::new( queue::Queue::ver::new( &self.dev, vm, @@ -1258,13 +1272,13 @@ impl GpuManager for GpuManager::ver { } fn handle_fault(&self) { - dev_err!(self.dev, " (\\________/) \n"); - dev_err!(self.dev, " | | \n"); - dev_err!(self.dev, "'.| \\ , / |.'\n"); - dev_err!(self.dev, "--| / (( \\ |--\n"); - dev_err!(self.dev, ".'| _-_- |'.\n"); - dev_err!(self.dev, " |________| \n"); - dev_err!(self.dev, "GPU fault nya~!!!!!\n"); + dev_err!(self.dev.as_ref(), " (\\________/) \n"); + dev_err!(self.dev.as_ref(), " | | \n"); + dev_err!(self.dev.as_ref(), "'.| \\ , / |.'\n"); + dev_err!(self.dev.as_ref(), "--| / (( \\ |--\n"); + dev_err!(self.dev.as_ref(), ".'| _-_- |'.\n"); + dev_err!(self.dev.as_ref(), " |________| \n"); + dev_err!(self.dev.as_ref(), "GPU fault nya~!!!!!\n"); let error = match self.get_fault_info() { Some(info) => workqueue::WorkError::Fault(info), None => workqueue::WorkError::Unknown, @@ -1294,7 +1308,7 @@ impl GpuManager for GpuManager::ver { .send_message(EP_DOORBELL, MSG_TX_DOORBELL | DOORBELL_DEVCTRL) .is_err() { - dev_err!(self.dev, "Failed to send TVB Grow Ack command\n"); + dev_err!(self.dev.as_ref(), "Failed to send TVB Grow Ack command\n"); } } } @@ -1353,12 +1367,12 @@ impl GpuManager for GpuManager::ver { } } - fn free_context(&self, ctx: Box>) { + fn free_context(&self, ctx: KBox>) { let mut garbage = self.garbage_contexts.lock(); if garbage.push(ctx, GFP_KERNEL).is_err() { dev_err!( - self.dev, + self.dev.as_ref(), "Failed to reserve space for freed context, deadlock possible.\n" ); } diff --git a/drivers/gpu/drm/asahi/hw/mod.rs b/drivers/gpu/drm/asahi/hw/mod.rs index 0685f833b41a1d..519ca1382ddb11 100644 --- a/drivers/gpu/drm/asahi/hw/mod.rs +++ b/drivers/gpu/drm/asahi/hw/mod.rs @@ -6,9 +6,7 @@ use crate::driver::AsahiDevice; use crate::fw::types::*; -use alloc::vec::Vec; use kernel::c_str; -use kernel::device::RawDevice; use kernel::prelude::*; const MAX_POWERZONES: usize = 5; @@ -108,7 +106,7 @@ pub(crate) mod feat { #[derive(Debug)] pub(crate) struct PState { /// Voltage in millivolts, per GPU cluster. - pub(crate) volt_mv: Vec, + pub(crate) volt_mv: KVec, /// Frequency in hertz. pub(crate) freq_hz: u32, /// Maximum power consumption of the GPU at this pstate, in milliwatts. @@ -340,23 +338,23 @@ pub(crate) struct GpuIdConfig { /// Total number of active cores for the whole GPU. pub(crate) total_active_cores: u32, /// Mask of active cores per cluster. - pub(crate) core_masks: Vec, + pub(crate) core_masks: KVec, /// Packed mask of all active cores. - pub(crate) core_masks_packed: Vec, + pub(crate) core_masks_packed: KVec, } /// Configurable CS/AFR GPU power settings from the device tree. #[derive(Debug)] pub(crate) struct CsAfrPwrConfig { /// GPU CS performance state list. - pub(crate) perf_states_cs: Vec, + pub(crate) perf_states_cs: KVec, /// GPU AFR performance state list. - pub(crate) perf_states_afr: Vec, + pub(crate) perf_states_afr: KVec, /// CS leakage coefficient per die. - pub(crate) leak_coef_cs: Vec, + pub(crate) leak_coef_cs: KVec, /// AFR leakage coefficient per die. - pub(crate) leak_coef_afr: Vec, + pub(crate) leak_coef_afr: KVec, /// Minimum voltage for the CS/AFR SRAM power domain in microvolts. pub(crate) min_sram_microvolt: u32, @@ -366,14 +364,14 @@ pub(crate) struct CsAfrPwrConfig { #[derive(Debug)] pub(crate) struct PwrConfig { /// GPU performance state list. - pub(crate) perf_states: Vec, + pub(crate) perf_states: KVec, /// GPU power zone list. - pub(crate) power_zones: Vec, + pub(crate) power_zones: KVec, /// Core leakage coefficient per cluster. - pub(crate) core_leak_coef: Vec, + pub(crate) core_leak_coef: KVec, /// SRAM leakage coefficient per cluster. - pub(crate) sram_leak_coef: Vec, + pub(crate) sram_leak_coef: KVec, pub(crate) csafr: Option, @@ -469,15 +467,15 @@ impl PwrConfig { name: &CStr, cfg: &HwConfig, is_main: bool, - ) -> Result> { - let mut perf_states = Vec::new(); + ) -> Result> { + let mut perf_states = KVec::new(); - let node = dev.of_node().ok_or(EIO)?; + let node = dev.as_ref().of_node().ok_or(EIO)?; let opps = node.parse_phandle(name, 0).ok_or(EIO)?; for opp in opps.children() { let freq_hz: u64 = opp.get_property(c_str!("opp-hz"))?; - let mut volt_uv: Vec = opp.get_property(c_str!("opp-microvolt"))?; + let mut volt_uv: KVec = opp.get_property(c_str!("opp-microvolt"))?; let pwr_uw: u32 = if is_main { opp.get_property(c_str!("opp-microwatt"))? } else { @@ -492,7 +490,7 @@ impl PwrConfig { if volt_uv.len() != voltage_count as usize { dev_err!( - dev, + dev.as_ref(), "Invalid opp-microvolt length (expected {}, got {})\n", voltage_count, volt_uv.len() @@ -525,34 +523,34 @@ impl PwrConfig { /// Load the GPU power configuration from the device tree. pub(crate) fn load(dev: &AsahiDevice, cfg: &HwConfig) -> Result { let perf_states = Self::load_opp(dev, c_str!("operating-points-v2"), cfg, true)?; - let node = dev.of_node().ok_or(EIO)?; + let node = dev.as_ref().of_node().ok_or(EIO)?; macro_rules! prop { ($prop:expr, $default:expr) => {{ node.get_opt_property(c_str!($prop)) .map_err(|e| { - dev_err!(dev, "Error reading property {}: {:?}\n", $prop, e); + dev_err!(dev.as_ref(), "Error reading property {}: {:?}\n", $prop, e); e })? .unwrap_or($default) }}; ($prop:expr) => {{ node.get_property(c_str!($prop)).map_err(|e| { - dev_err!(dev, "Error reading property {}: {:?}\n", $prop, e); + dev_err!(dev.as_ref(), "Error reading property {}: {:?}\n", $prop, e); e })? }}; } - let pz_data = prop!("apple,power-zones", Vec::new()); + let pz_data = prop!("apple,power-zones", KVec::new()); if pz_data.len() > 3 * MAX_POWERZONES || pz_data.len() % 3 != 0 { - dev_err!(dev, "Invalid apple,power-zones value\n"); + dev_err!(dev.as_ref(), "Invalid apple,power-zones value\n"); return Err(EINVAL); } let pz_count = pz_data.len() / 3; - let mut power_zones = Vec::new(); + let mut power_zones = KVec::new(); for i in (0..pz_count).step_by(3) { power_zones.push( PowerZone { @@ -564,15 +562,15 @@ impl PwrConfig { )?; } - let core_leak_coef: Vec = prop!("apple,core-leak-coef"); - let sram_leak_coef: Vec = prop!("apple,sram-leak-coef"); + let core_leak_coef: KVec = prop!("apple,core-leak-coef"); + let sram_leak_coef: KVec = prop!("apple,sram-leak-coef"); if core_leak_coef.len() != cfg.max_num_clusters as usize { - dev_err!(dev, "Invalid apple,core-leak-coef\n"); + dev_err!(dev.as_ref(), "Invalid apple,core-leak-coef\n"); return Err(EINVAL); } if sram_leak_coef.len() != cfg.max_num_clusters as usize { - dev_err!(dev, "Invalid apple,sram_leak_coef\n"); + dev_err!(dev.as_ref(), "Invalid apple,sram_leak_coef\n"); return Err(EINVAL); } diff --git a/drivers/gpu/drm/asahi/initdata.rs b/drivers/gpu/drm/asahi/initdata.rs index 0d23208fdbe3ea..6228dff08163ac 100644 --- a/drivers/gpu/drm/asahi/initdata.rs +++ b/drivers/gpu/drm/asahi/initdata.rs @@ -15,10 +15,9 @@ use crate::f32; use crate::fw::initdata::*; use crate::fw::types::*; use crate::{driver::AsahiDevice, gem, gpu, hw, mmu}; -use alloc::vec::Vec; -use kernel::alloc::{box_ext::BoxExt, flags::*, vec_ext::VecExt}; use kernel::error::{Error, Result}; use kernel::macros::versions; +use kernel::prelude::*; use kernel::{init, init::Init, try_init}; /// Builder helper for the global GPU InitData. @@ -69,7 +68,7 @@ impl<'a> InitDataBuilder::ver<'a> { unk_4: u32, t1: &[u16], t2: &[i16], - t3: &[Vec], + t3: &[KVec], ) { curve.unk_0 = unk_0; curve.unk_4 = unk_4; @@ -851,7 +850,7 @@ impl<'a> InitDataBuilder::ver<'a> { /// Build the top-level InitData object. #[inline(never)] - pub(crate) fn build(&mut self) -> Result>> { + pub(crate) fn build(&mut self) -> Result>> { let runtime_pointers = self.runtime_pointers()?; let globals = self.globals()?; let fw_status = self.fw_status()?; @@ -896,6 +895,6 @@ impl<'a> InitDataBuilder::ver<'a> { }) }, )?; - Ok(Box::new(obj, GFP_KERNEL)?) + Ok(KBox::new(obj, GFP_KERNEL)?) } } diff --git a/drivers/gpu/drm/asahi/microseq.rs b/drivers/gpu/drm/asahi/microseq.rs index 34074fa912f02f..b973c7318899bf 100644 --- a/drivers/gpu/drm/asahi/microseq.rs +++ b/drivers/gpu/drm/asahi/microseq.rs @@ -25,13 +25,13 @@ pub(crate) type MicroSequence = GpuArray; /// MicroSequence builder. pub(crate) struct Builder { - ops: Vec, + ops: KVec, } impl Builder { /// Create a new Builder object pub(crate) fn new() -> Builder { - Builder { ops: Vec::new() } + Builder { ops: KVec::new() } } /// Get the relative offset from the current pointer to a given target offset. diff --git a/drivers/gpu/drm/asahi/mmu.rs b/drivers/gpu/drm/asahi/mmu.rs index e859bb78b01275..6391c9520be3f8 100644 --- a/drivers/gpu/drm/asahi/mmu.rs +++ b/drivers/gpu/drm/asahi/mmu.rs @@ -399,7 +399,7 @@ impl Mapping { .is_err() { dev_err!( - owner.dev, + owner.dev.as_ref(), "MMU: unmap for remap {:#x}:{:#x} failed\n", self.iova(), self.size() @@ -409,7 +409,7 @@ impl Mapping { let prot = self.0.prot | prot::CACHE; if owner.map_node(&self.0, prot).is_err() { dev_err!( - owner.dev, + owner.dev.as_ref(), "MMU: remap {:#x}:{:#x} failed\n", self.iova(), self.size() @@ -479,7 +479,11 @@ impl Mapping { let pages = self.size() >> UAT_PGBIT; flush.begin_flush(self.iova() as u64, self.size() as u64); if pages >= 0x10000 { - dev_err!(owner.dev, "MMU: Flush too big ({:#x} pages))\n", pages); + dev_err!( + owner.dev.as_ref(), + "MMU: Flush too big ({:#x} pages))\n", + pages + ); } let cmd = fw::channels::FwCtlMsg { @@ -493,7 +497,7 @@ impl Mapping { // Tell the firmware to do a cache flush if let Err(e) = owner.dev.data().gpu.fwctl(cmd) { dev_err!( - owner.dev, + owner.dev.as_ref(), "MMU: ASC cache flush {:#x}:{:#x} failed (err: {:?})\n", self.iova(), self.size(), @@ -548,7 +552,7 @@ impl Drop for Mapping { .is_err() { dev_err!( - owner.dev, + owner.dev.as_ref(), "MMU: unmap {:#x}:{:#x} failed\n", self.iova(), self.size() @@ -773,7 +777,7 @@ impl Vm { file_id: u64, ) -> Result { let page_table = AppleUAT::new( - dev, + dev.as_ref(), io_pgtable::Config { pgsize_bitmap: UAT_PGSZ, ias: if is_kernel { UAT_IAS_KERN } else { UAT_IAS }, @@ -913,7 +917,7 @@ impl Vm { if (phys | size | iova) & UAT_PGMSK != 0 { dev_err!( - inner.dev, + inner.dev.as_ref(), "MMU: Mapping {:#x}:{:#x} -> {:#x} is not page-aligned\n", phys, size, @@ -923,7 +927,7 @@ impl Vm { } dev_info!( - inner.dev, + inner.dev.as_ref(), "MMU: IO map: {:#x}:{:#x} -> {:#x}\n", phys, size, @@ -997,7 +1001,7 @@ impl Drop for VmInner { impl Uat { /// Map a bootloader-preallocated memory region fn map_region( - dev: &dyn device::RawDevice, + dev: &device::Device, name: &CStr, size: usize, cached: bool, @@ -1149,12 +1153,12 @@ impl Uat { /// Creates the reference-counted inner data for a new `Uat` instance. #[inline(never)] fn make_inner(dev: &driver::AsahiDevice) -> Result> { - let handoff_rgn = Self::map_region(dev, c_str!("handoff"), HANDOFF_SIZE, false)?; - let ttbs_rgn = Self::map_region(dev, c_str!("ttbs"), SLOTS_SIZE, false)?; + let handoff_rgn = Self::map_region(dev.as_ref(), c_str!("handoff"), HANDOFF_SIZE, false)?; + let ttbs_rgn = Self::map_region(dev.as_ref(), c_str!("ttbs"), SLOTS_SIZE, false)?; let handoff = unsafe { &(handoff_rgn.map.as_ptr() as *mut Handoff).as_ref().unwrap() }; - dev_info!(dev, "MMU: Initializing kernel page table\n"); + dev_info!(dev.as_ref(), "MMU: Initializing kernel page table\n"); Arc::pin_init( try_pin_init!(UatInner { @@ -1182,17 +1186,18 @@ impl Uat { cfg: &'static hw::HwConfig, map_kernel_to_user: bool, ) -> Result { - dev_info!(dev, "MMU: Initializing...\n"); + dev_info!(dev.as_ref(), "MMU: Initializing...\n"); let inner = Self::make_inner(dev)?; - let pagetables_rgn = Self::map_region(dev, c_str!("pagetables"), PAGETABLES_SIZE, true)?; + let pagetables_rgn = + Self::map_region(dev.as_ref(), c_str!("pagetables"), PAGETABLES_SIZE, true)?; dev_info!(dev, "MMU: Creating kernel page tables\n"); let kernel_lower_vm = Vm::new(dev, inner.clone(), cfg, false, 1, 0)?; let kernel_vm = Vm::new(dev, inner.clone(), cfg, true, 0, 0)?; - dev_info!(dev, "MMU: Kernel page tables created\n"); + dev_info!(dev.as_ref(), "MMU: Kernel page tables created\n"); let ttb0 = kernel_lower_vm.ttb(); let ttb1 = kernel_vm.ttb(); @@ -1221,7 +1226,7 @@ impl Uat { inner.handoff().init()?; - dev_info!(dev, "MMU: Initializing TTBs\n"); + dev_info!(dev.as_ref(), "MMU: Initializing TTBs\n"); inner.handoff().lock(); @@ -1243,7 +1248,7 @@ impl Uat { uat.kpt0()[2].store(ttb1 | PTE_TABLE, Ordering::Relaxed); - dev_info!(dev, "MMU: initialized\n"); + dev_info!(dev.as_ref(), "MMU: initialized\n"); Ok(uat) } diff --git a/drivers/gpu/drm/asahi/object.rs b/drivers/gpu/drm/asahi/object.rs index 3e099f42b4c89a..b190df6322c6d4 100644 --- a/drivers/gpu/drm/asahi/object.rs +++ b/drivers/gpu/drm/asahi/object.rs @@ -45,7 +45,6 @@ use kernel::{error::code::*, prelude::*}; -use alloc::boxed::Box; use core::fmt; use core::fmt::Debug; use core::fmt::Formatter; @@ -225,7 +224,7 @@ pub(crate) struct GpuObject> { raw: *mut T::Raw<'static>, alloc: U, gpu_ptr: GpuWeakPointer, - inner: Box, + inner: KBox, } impl> GpuObject { @@ -242,7 +241,7 @@ impl> GpuObject { let size = mem::size_of::>(); if size > 0x1000 { dev_crit!( - alloc.device(), + alloc.device().as_ref(), "Allocating {} of size {:#x}, with new, please use new_boxed!\n", core::any::type_name::(), size @@ -269,7 +268,7 @@ impl> GpuObject { raw: p, gpu_ptr, alloc, - inner: Box::new(inner, GFP_KERNEL)?, + inner: KBox::new(inner, GFP_KERNEL)?, }) } @@ -281,7 +280,7 @@ impl> GpuObject { /// macro to avoid constructing the whole `T::Raw` object on the stack. pub(crate) fn new_boxed( alloc: U, - inner: Box, + inner: KBox, callback: impl for<'a> FnOnce( &'a T, &'a mut MaybeUninit>, @@ -303,7 +302,7 @@ impl> GpuObject { let raw = callback(&inner, unsafe { &mut *p })?; if p as *mut T::Raw<'_> != raw as *mut _ { dev_err!( - alloc.device(), + alloc.device().as_ref(), "Allocation callback returned a mismatched reference ({})\n", core::any::type_name::(), ); @@ -331,7 +330,7 @@ impl> GpuObject { &'a mut MaybeUninit>, ) -> Result<&'a mut T::Raw<'a>>, ) -> Result { - GpuObject::::new_boxed(alloc, Box::new(inner, GFP_KERNEL)?, callback) + GpuObject::::new_boxed(alloc, KBox::new(inner, GFP_KERNEL)?, callback) } /// Create a new GpuObject given an allocator and the boxed inner data (a type implementing @@ -366,7 +365,7 @@ impl> GpuObject { raw: p as *mut u8 as *mut T::Raw<'static>, gpu_ptr, alloc, - inner: Box::init(inner, GFP_KERNEL)?, + inner: KBox::init(inner, GFP_KERNEL)?, }; let q = &*ret.inner as *const T; // SAFETY: `p` is guaranteed to be valid per the Allocation invariant. diff --git a/drivers/gpu/drm/asahi/queue/compute.rs b/drivers/gpu/drm/asahi/queue/compute.rs index f53e64efd4f4e5..a167fd3925fb5f 100644 --- a/drivers/gpu/drm/asahi/queue/compute.rs +++ b/drivers/gpu/drm/asahi/queue/compute.rs @@ -45,7 +45,7 @@ impl super::Queue::ver { let gpu = match dev.gpu.as_any().downcast_ref::() { Some(gpu) => gpu, None => { - dev_crit!(self.dev, "GpuManager mismatched with Queue!\n"); + dev_crit!(self.dev.as_ref(), "GpuManager mismatched with Queue!\n"); return Err(EIO); } }; diff --git a/drivers/gpu/drm/asahi/queue/mod.rs b/drivers/gpu/drm/asahi/queue/mod.rs index 1793b20b08f7f4..f3e5418296946b 100644 --- a/drivers/gpu/drm/asahi/queue/mod.rs +++ b/drivers/gpu/drm/asahi/queue/mod.rs @@ -8,7 +8,6 @@ use kernel::dma_fence::*; use kernel::prelude::*; use kernel::{ - alloc::vec_ext::VecExt, c_str, dma_fence, drm::gem::shmem::VMap, drm::sched, @@ -40,10 +39,10 @@ pub(crate) trait Queue: Send + Sync { fn submit( &mut self, id: u64, - in_syncs: Vec, - out_syncs: Vec, + in_syncs: KVec, + out_syncs: KVec, result_buf: Option, - commands: Vec, + commands: KVec, ) -> Result; } @@ -243,7 +242,7 @@ impl sched::JobImpl for QueueJob::ver { { Ok(gpu) => gpu, Err(_) => { - dev_crit!(job.dev, "GpuManager mismatched with QueueJob!\n"); + dev_crit!(job.dev.as_ref(), "GpuManager mismatched with QueueJob!\n"); return Err(EIO); } }; @@ -309,7 +308,7 @@ impl sched::JobImpl for QueueJob::ver { fn timed_out(job: &mut sched::Job) -> sched::Status { // FIXME: Handle timeouts properly dev_err!( - job.dev, + job.dev.as_ref(), "QueueJob {}: Job timed out on the DRM scheduler, things will probably break (ran: {})\n", job.id, job.did_run ); @@ -389,7 +388,8 @@ impl Queue::ver { GFP_KERNEL, )?; - let sched = sched::Scheduler::new(dev, 3, WQ_SIZE, 0, 100000, c_str!("asahi_sched"))?; + let sched = + sched::Scheduler::new(dev.as_ref(), 3, WQ_SIZE, 0, 100000, c_str!("asahi_sched"))?; // Priorities are handled by the AGX scheduler, there is no meaning within a // per-queue scheduler. let entity = sched::Entity::new(&sched, sched::Priority::Normal)?; @@ -505,10 +505,10 @@ impl Queue for Queue::ver { fn submit( &mut self, id: u64, - in_syncs: Vec, - out_syncs: Vec, + in_syncs: KVec, + out_syncs: KVec, result_buf: Option, - commands: Vec, + commands: KVec, ) -> Result { let dev = self.dev.data(); let gpu = match dev @@ -519,7 +519,7 @@ impl Queue for Queue::ver { { Ok(gpu) => gpu, Err(_) => { - dev_crit!(self.dev, "GpuManager mismatched with JobImpl!\n"); + dev_crit!(self.dev.as_ref(), "GpuManager mismatched with JobImpl!\n"); return Err(EIO); } }; @@ -528,7 +528,7 @@ impl Queue for Queue::ver { if gpu.is_crashed() { dev_err!( - self.dev, + self.dev.as_ref(), "[Submission {}] GPU is crashed, cannot submit\n", id ); @@ -546,7 +546,7 @@ impl Queue for Queue::ver { None }; - let mut events: [Vec>; SQ_COUNT] = + let mut events: [KVec>; SQ_COUNT] = Default::default(); events[SQ_RENDER].push( diff --git a/drivers/gpu/drm/asahi/queue/render.rs b/drivers/gpu/drm/asahi/queue/render.rs index a2cc8f848f5445..7e6730c2c58555 100644 --- a/drivers/gpu/drm/asahi/queue/render.rs +++ b/drivers/gpu/drm/asahi/queue/render.rs @@ -254,7 +254,7 @@ impl super::Queue::ver { let gpu = match dev.gpu.as_any().downcast_ref::() { Some(gpu) => gpu, None => { - dev_crit!(self.dev, "GpuManager mismatched with Queue!\n"); + dev_crit!(self.dev.as_ref(), "GpuManager mismatched with Queue!\n"); return Err(EIO); } }; diff --git a/drivers/gpu/drm/asahi/regs.rs b/drivers/gpu/drm/asahi/regs.rs index 5a92e026c2a53e..fe62d10bb57319 100644 --- a/drivers/gpu/drm/asahi/regs.rs +++ b/drivers/gpu/drm/asahi/regs.rs @@ -8,14 +8,7 @@ //! information, and starting the GPU firmware coprocessor. use crate::hw; -use kernel::{ - alloc::{flags::*, vec_ext::VecExt}, - device, - io_mem::IoMem, - platform, - prelude::*, - types::ARef, -}; +use kernel::{device, io_mem::IoMem, platform, prelude::*, types::ARef}; /// Size of the ASC control MMIO region. pub(crate) const ASC_CTL_SIZE: usize = 0x4000; @@ -229,7 +222,7 @@ impl Resources { let gpu_gen = (id_version >> 24) & 0xff; - let mut core_mask_regs = Vec::new(); + let mut core_mask_regs = KVec::new(); let num_clusters = match gpu_gen { 4 | 5 => { @@ -251,7 +244,7 @@ impl Resources { } }; - let mut core_masks_packed = Vec::new(); + let mut core_masks_packed = KVec::new(); core_masks_packed.extend_from_slice(&core_mask_regs, GFP_KERNEL)?; dev_info!(self.dev, "Core masks: {:#x?}\n", core_masks_packed); @@ -278,7 +271,7 @@ impl Resources { return Err(ENODEV); } - let mut core_masks = Vec::new(); + let mut core_masks = KVec::new(); let mut total_active_cores: u32 = 0; let max_core_mask = ((1u64 << num_cores) - 1) as u32; diff --git a/drivers/gpu/drm/asahi/slotalloc.rs b/drivers/gpu/drm/asahi/slotalloc.rs index 4cbbda073584a7..5f3bbe5ae7f4d3 100644 --- a/drivers/gpu/drm/asahi/slotalloc.rs +++ b/drivers/gpu/drm/asahi/slotalloc.rs @@ -17,7 +17,6 @@ use core::ops::{Deref, DerefMut}; use kernel::{ - alloc::{flags::*, vec_ext::VecExt}, error::{code::*, Result}, prelude::*, str::CStr, @@ -105,7 +104,7 @@ struct Entry { /// Inner data for the `SlotAllocator`, protected by a `Mutex`. struct SlotAllocatorInner { data: T::Data, - slots: Vec>>, + slots: KVec>>, get_count: u64, drop_count: u64, } @@ -136,7 +135,7 @@ impl SlotAllocator { lock_key1: LockClassKey, lock_key2: LockClassKey, ) -> Result> { - let mut slots = Vec::with_capacity(num_slots as usize, GFP_KERNEL)?; + let mut slots = KVec::with_capacity(num_slots as usize, GFP_KERNEL)?; for i in 0..num_slots { slots diff --git a/drivers/gpu/drm/asahi/workqueue.rs b/drivers/gpu/drm/asahi/workqueue.rs index 453350cc958665..cfa26007801acb 100644 --- a/drivers/gpu/drm/asahi/workqueue.rs +++ b/drivers/gpu/drm/asahi/workqueue.rs @@ -24,7 +24,6 @@ use crate::{channel, driver, event, fw, gpu, object, regs}; use core::num::NonZeroU64; use core::sync::atomic::Ordering; use kernel::{ - alloc::{box_ext::BoxExt, flags::*, vec_ext::VecExt}, c_str, dma_fence, error::code::*, prelude::*, @@ -104,7 +103,7 @@ impl From for kernel::error::Error { /// A GPU context tracking structure, which must be explicitly invalidated when dropped. pub(crate) struct GpuContext { dev: driver::AsahiDevRef, - data: Option>>, + data: Option>>, } no_debug!(GpuContext); @@ -117,7 +116,7 @@ impl GpuContext { ) -> Result { Ok(GpuContext { dev: dev.into(), - data: Some(Box::new( + data: Some(KBox::new( alloc.shared.new_object( fw::workqueue::GpuContextData { _buffer: buffer }, |_inner| Default::default(), @@ -644,7 +643,7 @@ impl WorkQueue::ver { pipe_type, size, wptr: 0, - pending: Vec::new(), + pending: KVec::new(), last_token: None, event: None, priority, @@ -720,7 +719,7 @@ impl WorkQueue::ver { info_ptr: self.info_pointer, }, start_value: ev.1, - pending: Vec::new(), + pending: KVec::new(), event_count: 0, committed: false, submitted: false, @@ -887,7 +886,7 @@ impl WorkQueue for WorkQueue::ver { error ); - let mut cmds = Vec::new(); + let mut cmds = KVec::new(); core::mem::swap(&mut inner.pending, &mut cmds);