Skip to content

Commit 45092df

Browse files
Lyudejannau
authored andcommitted
rust: gem: Introduce DriverObject::Args
This is an associated type that may be used in order to specify a data-type to pass to gem objects when construction them, allowing for drivers to more easily initialize their private-data for gem objects. Signed-off-by: Lyude Paul <lyude@redhat.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
1 parent 342b6ff commit 45092df

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

drivers/gpu/drm/nova/gem.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ pub(crate) struct NovaObject {}
1818

1919
impl gem::DriverObject for NovaObject {
2020
type Driver = NovaDriver;
21+
type Args = ();
2122

22-
fn new(_dev: &NovaDevice, _size: usize) -> impl PinInit<Self, Error> {
23+
fn new(_dev: &NovaDevice, _size: usize, _args: Self::Args) -> impl PinInit<Self, Error> {
2324
try_pin_init!(NovaObject {})
2425
}
2526
}
@@ -33,7 +34,7 @@ impl NovaObject {
3334
return Err(EINVAL);
3435
}
3536

36-
gem::Object::new(dev, aligned_size)
37+
gem::Object::new(dev, aligned_size, ())
3738
}
3839

3940
/// Look up a GEM object handle for a `File` and return an `ObjectRef` for it.

drivers/gpu/drm/tyr/gem.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ pub(crate) struct TyrObject {}
1111

1212
impl gem::DriverObject for TyrObject {
1313
type Driver = TyrDriver;
14+
type Args = ();
1415

15-
fn new(_dev: &TyrDevice, _size: usize) -> impl PinInit<Self, Error> {
16+
fn new(_dev: &TyrDevice, _size: usize, _args: ()) -> impl PinInit<Self, Error> {
1617
try_pin_init!(TyrObject {})
1718
}
1819
}

rust/kernel/drm/gem/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,15 @@ pub trait DriverObject: Sync + Send + Sized {
6464
/// Parent `Driver` for this object.
6565
type Driver: drm::Driver;
6666

67+
/// The data type to use for passing arguments to [`DriverObject::new`].
68+
type Args;
69+
6770
/// Create a new driver data object for a GEM object of a given size.
68-
fn new(dev: &drm::Device<Self::Driver>, size: usize) -> impl PinInit<Self, Error>;
71+
fn new(
72+
dev: &drm::Device<Self::Driver>,
73+
size: usize,
74+
args: Self::Args,
75+
) -> impl PinInit<Self, Error>;
6976

7077
/// Open a new handle to an existing object, associated with a File.
7178
fn open(_obj: &<Self::Driver as drm::Driver>::Object, _file: &DriverFile<Self>) -> Result {
@@ -244,11 +251,11 @@ impl<T: DriverObject> Object<T> {
244251
};
245252

246253
/// Create a new GEM object.
247-
pub fn new(dev: &drm::Device<T::Driver>, size: usize) -> Result<ARef<Self>> {
254+
pub fn new(dev: &drm::Device<T::Driver>, size: usize, args: T::Args) -> Result<ARef<Self>> {
248255
let obj: Pin<KBox<Self>> = KBox::pin_init(
249256
try_pin_init!(Self {
250257
obj: Opaque::new(bindings::drm_gem_object::default()),
251-
data <- T::new(dev, size),
258+
data <- T::new(dev, size, args),
252259
}),
253260
GFP_KERNEL,
254261
)?;

0 commit comments

Comments
 (0)