mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
This is an associated type that may be used in order to specify a data-type to pass to gem objects when constructing 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> Reviewed-by: Janne Grunau <j@jananu.net> Tested-by: Deborah Brouwer <deborah.brouwer@collabora.com> Link: https://patch.msgid.link/20260316211646.650074-5-lyude@redhat.com [ Resolve merge conflicts in Tyr. - Danilo ] Signed-off-by: Danilo Krummrich <dakr@kernel.org>
49 lines
1.1 KiB
Rust
49 lines
1.1 KiB
Rust
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
use kernel::{
|
|
drm,
|
|
drm::{gem, gem::BaseObject},
|
|
page,
|
|
prelude::*,
|
|
sync::aref::ARef,
|
|
};
|
|
|
|
use crate::{
|
|
driver::{NovaDevice, NovaDriver},
|
|
file::File,
|
|
};
|
|
|
|
/// GEM Object inner driver data
|
|
#[pin_data]
|
|
pub(crate) struct NovaObject {}
|
|
|
|
impl gem::DriverObject for NovaObject {
|
|
type Driver = NovaDriver;
|
|
type Args = ();
|
|
|
|
fn new(_dev: &NovaDevice, _size: usize, _args: Self::Args) -> impl PinInit<Self, Error> {
|
|
try_pin_init!(NovaObject {})
|
|
}
|
|
}
|
|
|
|
impl NovaObject {
|
|
/// Create a new DRM GEM object.
|
|
pub(crate) fn new(dev: &NovaDevice, size: usize) -> Result<ARef<gem::Object<Self>>> {
|
|
if size == 0 {
|
|
return Err(EINVAL);
|
|
}
|
|
let aligned_size = page::page_align(size).ok_or(EINVAL)?;
|
|
|
|
gem::Object::new(dev, aligned_size, ())
|
|
}
|
|
|
|
/// Look up a GEM object handle for a `File` and return an `ObjectRef` for it.
|
|
#[inline]
|
|
pub(crate) fn lookup_handle(
|
|
file: &drm::File<File>,
|
|
handle: u32,
|
|
) -> Result<ARef<gem::Object<Self>>> {
|
|
gem::Object::lookup_handle(file, handle)
|
|
}
|
|
}
|