5
5
//! C header: [`include/drm/gpu_scheduler.h`](../../../../include/drm/gpu_scheduler.h)
6
6
7
7
use crate :: {
8
- alloc:: { box_ext:: BoxExt , flags:: * } ,
9
8
bindings, device,
10
9
dma_fence:: * ,
11
10
error:: { to_result, Result } ,
12
11
prelude:: * ,
13
12
sync:: { Arc , UniqueArc } ,
14
13
} ;
15
- use alloc:: boxed:: Box ;
16
14
use core:: marker:: PhantomData ;
17
15
use core:: mem:: MaybeUninit ;
18
16
use core:: ops:: { Deref , DerefMut } ;
@@ -103,7 +101,7 @@ unsafe extern "C" fn free_job_cb<T: JobImpl>(sched_job: *mut bindings::drm_sched
103
101
104
102
// Convert the job back to a Box and drop it
105
103
// 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) ) } ;
107
105
}
108
106
109
107
/// A DRM scheduler job.
@@ -135,7 +133,7 @@ impl<T: JobImpl> Drop for Job<T> {
135
133
}
136
134
137
135
/// 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 > ) ;
139
137
140
138
impl < ' a , T : JobImpl > PendingJob < ' a , T > {
141
139
/// Add a fence as a dependency to the job
@@ -169,7 +167,7 @@ impl<'a, T: JobImpl> DerefMut for PendingJob<'a, T> {
169
167
}
170
168
171
169
/// 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 > ) ;
173
171
174
172
impl < ' a , T : JobImpl > ArmedJob < ' a , T > {
175
173
/// Returns the job fences
@@ -182,7 +180,7 @@ impl<'a, T: JobImpl> ArmedJob<'a, T> {
182
180
pub fn push ( self ) {
183
181
// After this point, the job is submitted and owned by the scheduler
184
182
let ptr = match self {
185
- ArmedJob ( job, _) => Box :: < Job < T > > :: into_raw ( job) ,
183
+ ArmedJob ( job, _) => KBox :: < Job < T > > :: into_raw ( job) ,
186
184
} ;
187
185
188
186
// SAFETY: We are passing in ownership of a valid Box raw pointer.
@@ -241,13 +239,13 @@ unsafe impl<T: JobImpl> Sync for EntityInner<T> {}
241
239
unsafe impl < T : JobImpl > Send for EntityInner < T > { }
242
240
243
241
/// A DRM scheduler entity.
244
- pub struct Entity < T : JobImpl > ( Pin < Box < EntityInner < T > > > ) ;
242
+ pub struct Entity < T : JobImpl > ( Pin < KBox < EntityInner < T > > > ) ;
245
243
246
244
impl < T : JobImpl > Entity < T > {
247
245
/// Create a new scheduler entity.
248
246
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) ?;
251
249
252
250
let mut sched_ptr = & sched. 0 . sched as * const _ as * mut _ ;
253
251
@@ -276,7 +274,7 @@ impl<T: JobImpl> Entity<T> {
276
274
/// this requires a mutable reference to the entity, ensuring that only one new job can be
277
275
/// in flight at once.
278
276
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) ?;
280
278
281
279
// SAFETY: We hold a reference to the entity (which is a valid pointer),
282
280
// and the job object was just allocated above.
@@ -330,7 +328,7 @@ impl<T: JobImpl> Scheduler<T> {
330
328
/// Creates a new DRM Scheduler object
331
329
// TODO: Shared timeout workqueues & scores
332
330
pub fn new (
333
- device : & impl device:: RawDevice ,
331
+ device : & device:: Device ,
334
332
num_rqs : u32 ,
335
333
credit_limit : u32 ,
336
334
hang_limit : u32 ,
@@ -347,6 +345,7 @@ impl<T: JobImpl> Scheduler<T> {
347
345
} ;
348
346
349
347
// SAFETY: The drm_sched pointer is valid and pinned as it was just allocated above.
348
+ // `device` is valid by its type invarants
350
349
to_result ( unsafe {
351
350
bindings:: drm_sched_init (
352
351
addr_of_mut ! ( ( * sched. as_mut_ptr( ) ) . sched) ,
@@ -359,7 +358,7 @@ impl<T: JobImpl> Scheduler<T> {
359
358
core:: ptr:: null_mut ( ) ,
360
359
core:: ptr:: null_mut ( ) ,
361
360
name. as_char_ptr ( ) ,
362
- device. raw_device ( ) ,
361
+ device. as_raw ( ) ,
363
362
)
364
363
} ) ?;
365
364
0 commit comments