xref: /linux/drivers/gpu/drm/nova/driver.rs (revision fdc290ff4ab19c7e0dde36c4cd1e2771b61f6bf5)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 use kernel::{
4     auxiliary,
5     device::{
6         Core,
7         DeviceContext, //
8     },
9     drm::{
10         self,
11         gem,
12         ioctl, //
13     },
14     prelude::*,
15     sync::aref::ARef, //
16 };
17 
18 use crate::file::File;
19 use crate::gem::NovaObject;
20 
21 pub(crate) struct NovaDriver;
22 
23 pub(crate) struct Nova<'bound> {
24     #[expect(unused)]
25     drm: ARef<drm::Device<NovaDriver>>,
26     _reg: drm::Registration<'bound, NovaDriver>,
27 }
28 
29 /// Convienence type alias for the DRM device type for this driver
30 pub(crate) type NovaDevice<Ctx = drm::Normal> = drm::Device<NovaDriver, Ctx>;
31 
32 const INFO: drm::DriverInfo = drm::DriverInfo {
33     major: 0,
34     minor: 0,
35     patchlevel: 0,
36     name: c"nova-drm",
37     desc: c"NVIDIA Graphics and Compute",
38 };
39 
40 const NOVA_CORE_MODULE_NAME: &CStr = c"nova-core";
41 const AUXILIARY_NAME: &CStr = c"nova-drm";
42 
43 kernel::auxiliary_device_table!(
44     AUX_TABLE,
45     MODULE_AUX_TABLE,
46     <NovaDriver as auxiliary::Driver>::IdInfo,
47     [(
48         auxiliary::DeviceId::new(NOVA_CORE_MODULE_NAME, AUXILIARY_NAME),
49         ()
50     )]
51 );
52 
53 impl auxiliary::Driver for NovaDriver {
54     type IdInfo = ();
55     type Data<'bound> = Nova<'bound>;
56     const ID_TABLE: auxiliary::IdTable<Self::IdInfo> = &AUX_TABLE;
57 
58     fn probe<'bound>(
59         adev: &'bound auxiliary::Device<Core<'_>>,
60         _info: &'bound Self::IdInfo,
61     ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
62         let drm = drm::UnregisteredDevice::<Self>::new(adev, Ok(()))?;
63         // SAFETY: `reg` is stored in `Nova` and dropped when the driver is unbound; it is
64         // never forgotten.
65         let reg = unsafe { drm::Registration::new(adev.as_ref(), drm, (), 0)? };
66 
67         Ok(Nova {
68             drm: reg.device().into(),
69             _reg: reg,
70         })
71     }
72 }
73 
74 #[vtable]
75 impl drm::Driver for NovaDriver {
76     type Data = ();
77     type RegistrationData<'a> = ();
78     type File = File;
79     type Object = gem::Object<NovaObject>;
80     type ParentDevice<Ctx: DeviceContext> = auxiliary::Device<Ctx>;
81 
82     const INFO: drm::DriverInfo = INFO;
83 
84     kernel::declare_drm_ioctls! {
85         (NOVA_GETPARAM, drm_nova_getparam, ioctl::RENDER_ALLOW, File::get_param),
86         (NOVA_GEM_CREATE, drm_nova_gem_create, ioctl::AUTH | ioctl::RENDER_ALLOW, File::gem_create),
87         (NOVA_GEM_INFO, drm_nova_gem_info, ioctl::AUTH | ioctl::RENDER_ALLOW, File::gem_info),
88     }
89 }
90