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 20 pub(crate) struct Nova { 21 #[expect(unused)] 22 drm: ARef<drm::Device<NovaDriver>>, 23 } 24 25 /// Convienence type alias for the DRM device type for this driver 26 pub(crate) type NovaDevice<Ctx = drm::Registered> = drm::Device<NovaDriver, Ctx>; 27 28 #[pin_data] 29 pub(crate) struct NovaData { 30 pub(crate) adev: ARef<auxiliary::Device>, 31 } 32 33 const INFO: drm::DriverInfo = drm::DriverInfo { 34 major: 0, 35 minor: 0, 36 patchlevel: 0, 37 name: c"nova-drm", 38 desc: c"NVIDIA Graphics and Compute", 39 }; 40 41 const NOVA_CORE_MODULE_NAME: &CStr = c"nova-core"; 42 const AUXILIARY_NAME: &CStr = c"nova-drm"; 43 44 kernel::auxiliary_device_table!( 45 AUX_TABLE, 46 MODULE_AUX_TABLE, 47 <NovaDriver as auxiliary::Driver>::IdInfo, 48 [( 49 auxiliary::DeviceId::new(NOVA_CORE_MODULE_NAME, AUXILIARY_NAME), 50 () 51 )] 52 ); 53 54 impl auxiliary::Driver for NovaDriver { 55 type IdInfo = (); 56 type Data<'bound> = Nova; 57 const ID_TABLE: auxiliary::IdTable<Self::IdInfo> = &AUX_TABLE; 58 59 fn probe<'bound>( 60 adev: &'bound auxiliary::Device<Core<'_>>, 61 _info: &'bound Self::IdInfo, 62 ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound { 63 let data = try_pin_init!(NovaData { adev: adev.into() }); 64 65 let drm = drm::UnregisteredDevice::<Self>::new(adev.as_ref(), data)?; 66 let drm = drm::Registration::new_foreign_owned(drm, adev.as_ref(), 0)?; 67 68 Ok(Nova { drm: drm.into() }) 69 } 70 } 71 72 #[vtable] 73 impl drm::Driver for NovaDriver { 74 type Data = NovaData; 75 type File = File; 76 type Object<Ctx: drm::DeviceContext> = gem::Object<NovaObject, Ctx>; 77 78 const INFO: drm::DriverInfo = INFO; 79 80 kernel::declare_drm_ioctls! { 81 (NOVA_GETPARAM, drm_nova_getparam, ioctl::RENDER_ALLOW, File::get_param), 82 (NOVA_GEM_CREATE, drm_nova_gem_create, ioctl::AUTH | ioctl::RENDER_ALLOW, File::gem_create), 83 (NOVA_GEM_INFO, drm_nova_gem_info, ioctl::AUTH | ioctl::RENDER_ALLOW, File::gem_info), 84 } 85 } 86