xref: /linux/drivers/gpu/drm/nova/driver.rs (revision 654826aa4a8f25cf825ad9254f37e6cb5092098f)
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     const ID_TABLE: auxiliary::IdTable<Self::IdInfo> = &AUX_TABLE;
55 
56     fn probe(adev: &auxiliary::Device<Core>, _info: &Self::IdInfo) -> impl PinInit<Self, Error> {
57         let data = try_pin_init!(NovaData { adev: adev.into() });
58 
59         let drm = drm::Device::<Self>::new(adev.as_ref(), data)?;
60         drm::Registration::new_foreign_owned(&drm, adev.as_ref(), 0)?;
61 
62         Ok(Self { drm })
63     }
64 }
65 
66 #[vtable]
67 impl drm::Driver for NovaDriver {
68     type Data = NovaData;
69     type File = File;
70     type Object = gem::Object<NovaObject>;
71 
72     const INFO: drm::DriverInfo = INFO;
73 
74     kernel::declare_drm_ioctls! {
75         (NOVA_GETPARAM, drm_nova_getparam, ioctl::RENDER_ALLOW, File::get_param),
76         (NOVA_GEM_CREATE, drm_nova_gem_create, ioctl::AUTH | ioctl::RENDER_ALLOW, File::gem_create),
77         (NOVA_GEM_INFO, drm_nova_gem_info, ioctl::AUTH | ioctl::RENDER_ALLOW, File::gem_info),
78     }
79 }
80