mirror of
https://github.com/torvalds/linux.git
synced 2026-10-07 19:16:02 +02:00
Restrict AlwaysRefCounted for gem::Object and gem::shmem::Object to the Normal context, since only Normal objects should be independently reference-counted. To avoid cascading through IntoGEMObject (which had AlwaysRefCounted as a supertrait), remove AlwaysRefCounted from IntoGEMObject's supertraits and instead add it as an explicit bound on lookup_handle(), which is the only BaseObject method that returns an ARef. Since Object::new() and shmem::Object::new() return ARef<Self>, move them to Normal-only impl blocks. Similarly, simplify ObjectConfig and shmem's parent_resv_obj field to the Normal context. Remove the DeviceContext generic from DriverObject::new() and Driver::Object, since GEM objects can only be constructed in the Normal context. Simplify DriverAllocImpl accordingly. Reviewed-by: Lyude Paul <lyude@redhat.com> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Tested-by: Deborah Brouwer <deborah.brouwer@collabora.com> Link: https://patch.msgid.link/20260628145406.2107056-8-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org>
52 lines
1.1 KiB
Rust
52 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::<Self>::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)
|
|
}
|
|
}
|