1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
// SPDX-License-Identifier: GPL-2.0
use crate::driver::{NovaDevice, NovaDriver};
use crate::gem::NovaObject;
use crate::uapi::{GemCreate, GemInfo, Getparam};
use kernel::{
alloc::flags::*,
drm::{self, gem::BaseObject},
pci,
prelude::*,
types::Opaque,
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: &Opaque<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 getparam: &Getparam = getparam.into();
let value = match getparam.param() as u32 {
uapi::NOVA_GETPARAM_VRAM_BAR_SIZE => pdev.resource_len(1)?,
_ => return Err(EINVAL),
};
getparam.set_value(value);
Ok(0)
}
/// IOCTL: gem_create: Create a new DRM GEM object.
pub(crate) fn gem_create(
dev: &NovaDevice,
req: &Opaque<uapi::drm_nova_gem_create>,
file: &drm::File<File>,
) -> Result<u32> {
let req: &GemCreate = req.into();
let obj = NovaObject::new(dev, req.size().try_into()?)?;
req.set_handle(obj.create_handle(file)?);
Ok(0)
}
/// IOCTL: gem_info: Query GEM metadata.
pub(crate) fn gem_info(
_dev: &NovaDevice,
req: &Opaque<uapi::drm_nova_gem_info>,
file: &drm::File<File>,
) -> Result<u32> {
let req: &GemInfo = req.into();
let bo = NovaObject::lookup_handle(file, req.handle())?;
req.set_size(bo.size().try_into()?);
Ok(0)
}
}
|