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 <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; 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 data = try_pin_init!(NovaData { adev: adev.into() }); 63 64 let drm = drm::UnregisteredDevice::<Self>::new(adev.as_ref(), data)?; 65 let drm = drm::Registration::new_foreign_owned(drm, adev.as_ref(), 0)?; 66 67 Ok(Nova { drm: drm.into() }) 68 } 69 } 70 71 #[vtable] 72 impl drm::Driver for NovaDriver { 73 type Data = NovaData; 74 type File = File; 75 type Object<Ctx: drm::DeviceContext> = gem::Object<NovaObject, Ctx>; 76 77 const INFO: drm::DriverInfo = INFO; 78 79 kernel::declare_drm_ioctls! { 80 (NOVA_GETPARAM, drm_nova_getparam, ioctl::RENDER_ALLOW, File::get_param), 81 (NOVA_GEM_CREATE, drm_nova_gem_create, ioctl::AUTH | ioctl::RENDER_ALLOW, File::gem_create), 82 (NOVA_GEM_INFO, drm_nova_gem_info, ioctl::AUTH | ioctl::RENDER_ALLOW, File::gem_info), 83 } 84 } 85