Skip to content

Commit 750079d

Browse files
committed
fixup! rust: drm: sched: Add GPU scheduler abstraction
1 parent d1bae00 commit 750079d

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

rust/kernel/drm/sched.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55
//! C header: [`include/drm/gpu_scheduler.h`](../../../../include/drm/gpu_scheduler.h)
66
77
use crate::{
8-
alloc::{box_ext::BoxExt, flags::*},
98
bindings, device,
109
dma_fence::*,
1110
error::{to_result, Result},
1211
prelude::*,
1312
sync::{Arc, UniqueArc},
1413
};
15-
use alloc::boxed::Box;
1614
use core::marker::PhantomData;
1715
use core::mem::MaybeUninit;
1816
use core::ops::{Deref, DerefMut};
@@ -103,7 +101,7 @@ unsafe extern "C" fn free_job_cb<T: JobImpl>(sched_job: *mut bindings::drm_sched
103101

104102
// Convert the job back to a Box and drop it
105103
// SAFETY: All of our Job<T>s are created inside a box.
106-
unsafe { drop(Box::from_raw(p)) };
104+
unsafe { drop(KBox::from_raw(p)) };
107105
}
108106

109107
/// A DRM scheduler job.
@@ -135,7 +133,7 @@ impl<T: JobImpl> Drop for Job<T> {
135133
}
136134

137135
/// A pending DRM scheduler job (not yet armed)
138-
pub struct PendingJob<'a, T: JobImpl>(Box<Job<T>>, PhantomData<&'a T>);
136+
pub struct PendingJob<'a, T: JobImpl>(KBox<Job<T>>, PhantomData<&'a T>);
139137

140138
impl<'a, T: JobImpl> PendingJob<'a, T> {
141139
/// Add a fence as a dependency to the job
@@ -169,7 +167,7 @@ impl<'a, T: JobImpl> DerefMut for PendingJob<'a, T> {
169167
}
170168

171169
/// An armed DRM scheduler job (not yet submitted)
172-
pub struct ArmedJob<'a, T: JobImpl>(Box<Job<T>>, PhantomData<&'a T>);
170+
pub struct ArmedJob<'a, T: JobImpl>(KBox<Job<T>>, PhantomData<&'a T>);
173171

174172
impl<'a, T: JobImpl> ArmedJob<'a, T> {
175173
/// Returns the job fences
@@ -182,7 +180,7 @@ impl<'a, T: JobImpl> ArmedJob<'a, T> {
182180
pub fn push(self) {
183181
// After this point, the job is submitted and owned by the scheduler
184182
let ptr = match self {
185-
ArmedJob(job, _) => Box::<Job<T>>::into_raw(job),
183+
ArmedJob(job, _) => KBox::<Job<T>>::into_raw(job),
186184
};
187185

188186
// SAFETY: We are passing in ownership of a valid Box raw pointer.
@@ -241,13 +239,13 @@ unsafe impl<T: JobImpl> Sync for EntityInner<T> {}
241239
unsafe impl<T: JobImpl> Send for EntityInner<T> {}
242240

243241
/// A DRM scheduler entity.
244-
pub struct Entity<T: JobImpl>(Pin<Box<EntityInner<T>>>);
242+
pub struct Entity<T: JobImpl>(Pin<KBox<EntityInner<T>>>);
245243

246244
impl<T: JobImpl> Entity<T> {
247245
/// Create a new scheduler entity.
248246
pub fn new(sched: &Scheduler<T>, priority: Priority) -> Result<Self> {
249-
let mut entity: Box<MaybeUninit<EntityInner<T>>> =
250-
Box::new_uninit(GFP_KERNEL | __GFP_ZERO)?;
247+
let mut entity: KBox<MaybeUninit<EntityInner<T>>> =
248+
KBox::new_uninit(GFP_KERNEL | __GFP_ZERO)?;
251249

252250
let mut sched_ptr = &sched.0.sched as *const _ as *mut _;
253251

@@ -276,7 +274,7 @@ impl<T: JobImpl> Entity<T> {
276274
/// this requires a mutable reference to the entity, ensuring that only one new job can be
277275
/// in flight at once.
278276
pub fn new_job(&mut self, credits: u32, inner: T) -> Result<PendingJob<'_, T>> {
279-
let mut job: Box<MaybeUninit<Job<T>>> = Box::new_uninit(GFP_KERNEL | __GFP_ZERO)?;
277+
let mut job: KBox<MaybeUninit<Job<T>>> = Box::new_uninit(GFP_KERNEL | __GFP_ZERO)?;
280278

281279
// SAFETY: We hold a reference to the entity (which is a valid pointer),
282280
// and the job object was just allocated above.
@@ -330,7 +328,7 @@ impl<T: JobImpl> Scheduler<T> {
330328
/// Creates a new DRM Scheduler object
331329
// TODO: Shared timeout workqueues & scores
332330
pub fn new(
333-
device: &impl device::RawDevice,
331+
device: &device::Device,
334332
num_rqs: u32,
335333
credit_limit: u32,
336334
hang_limit: u32,
@@ -347,6 +345,7 @@ impl<T: JobImpl> Scheduler<T> {
347345
};
348346

349347
// SAFETY: The drm_sched pointer is valid and pinned as it was just allocated above.
348+
// `device` is valid by its type invarants
350349
to_result(unsafe {
351350
bindings::drm_sched_init(
352351
addr_of_mut!((*sched.as_mut_ptr()).sched),
@@ -359,7 +358,7 @@ impl<T: JobImpl> Scheduler<T> {
359358
core::ptr::null_mut(),
360359
core::ptr::null_mut(),
361360
name.as_char_ptr(),
362-
device.raw_device(),
361+
device.as_raw(),
363362
)
364363
})?;
365364

0 commit comments

Comments
 (0)