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