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