mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-08-09 06:14:34 +02:00
Now that we have the ability to represent the context in which a DRM device is in at compile-time, we can start carrying around this context with GEM object types in order to allow a driver to safely create GEM objects before a DRM device has registered with userspace. Signed-off-by: Lyude Paul <lyude@redhat.com> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com> Link: https://patch.msgid.link/20260507220044.3204919-4-lyude@redhat.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
56 lines
1.2 KiB
Rust
56 lines
1.2 KiB
Rust
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
use kernel::{
|
|
drm,
|
|
drm::{gem, gem::BaseObject, DeviceContext},
|
|
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<Ctx: DeviceContext>(
|
|
_dev: &NovaDevice<Ctx>,
|
|
_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<Ctx: DeviceContext>(
|
|
dev: &NovaDevice<Ctx>,
|
|
size: usize,
|
|
) -> Result<ARef<gem::Object<Self, Ctx>>> {
|
|
if size == 0 {
|
|
return Err(EINVAL);
|
|
}
|
|
let aligned_size = page::page_align(size).ok_or(EINVAL)?;
|
|
|
|
gem::Object::<Self, Ctx>::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)
|
|
}
|
|
}
|