mirror of
https://github.com/torvalds/linux.git
synced 2026-04-28 19:42:31 -04:00
With the Opaque<T>, the expectations are that Rust should not make any assumptions on the layout or invariants of the wrapped C types. That runs rather counter to ioctl arguments, which must adhere to certain data-layout constraints. By using Opaque<T>, ioctl handlers are forced to use unsafe code where none is actually needed. This adds needless complexity and maintenance overhead, brining no safety benefits. Drop the use of Opaque for ioctl arguments as that is not the best fit here. Signed-off-by: Beata Michalska <beata.michalska@arm.com> Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20250626162313.2755584-1-beata.michalska@arm.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
70 lines
1.6 KiB
Rust
70 lines
1.6 KiB
Rust
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
use crate::driver::{NovaDevice, NovaDriver};
|
|
use crate::gem::NovaObject;
|
|
use kernel::{
|
|
alloc::flags::*,
|
|
drm::{self, gem::BaseObject},
|
|
pci,
|
|
prelude::*,
|
|
uapi,
|
|
};
|
|
|
|
pub(crate) struct File;
|
|
|
|
impl drm::file::DriverFile for File {
|
|
type Driver = NovaDriver;
|
|
|
|
fn open(_dev: &NovaDevice) -> Result<Pin<KBox<Self>>> {
|
|
Ok(KBox::new(Self, GFP_KERNEL)?.into())
|
|
}
|
|
}
|
|
|
|
impl File {
|
|
/// IOCTL: get_param: Query GPU / driver metadata.
|
|
pub(crate) fn get_param(
|
|
dev: &NovaDevice,
|
|
getparam: &mut uapi::drm_nova_getparam,
|
|
_file: &drm::File<File>,
|
|
) -> Result<u32> {
|
|
let adev = &dev.adev;
|
|
let parent = adev.parent().ok_or(ENOENT)?;
|
|
let pdev: &pci::Device = parent.try_into()?;
|
|
|
|
let value = match getparam.param as u32 {
|
|
uapi::NOVA_GETPARAM_VRAM_BAR_SIZE => pdev.resource_len(1)?,
|
|
_ => return Err(EINVAL),
|
|
};
|
|
|
|
getparam.value = value;
|
|
|
|
Ok(0)
|
|
}
|
|
|
|
/// IOCTL: gem_create: Create a new DRM GEM object.
|
|
pub(crate) fn gem_create(
|
|
dev: &NovaDevice,
|
|
req: &mut uapi::drm_nova_gem_create,
|
|
file: &drm::File<File>,
|
|
) -> Result<u32> {
|
|
let obj = NovaObject::new(dev, req.size.try_into()?)?;
|
|
|
|
req.handle = obj.create_handle(file)?;
|
|
|
|
Ok(0)
|
|
}
|
|
|
|
/// IOCTL: gem_info: Query GEM metadata.
|
|
pub(crate) fn gem_info(
|
|
_dev: &NovaDevice,
|
|
req: &mut uapi::drm_nova_gem_info,
|
|
file: &drm::File<File>,
|
|
) -> Result<u32> {
|
|
let bo = NovaObject::lookup_handle(file, req.handle)?;
|
|
|
|
req.size = bo.size().try_into()?;
|
|
|
|
Ok(0)
|
|
}
|
|
}
|