1 // SPDX-License-Identifier: GPL-2.0 2 3 use kernel::{auxiliary, bindings, c_str, device::Core, pci, prelude::*, sizes::SZ_16M, sync::Arc}; 4 5 use crate::gpu::Gpu; 6 7 #[pin_data] 8 pub(crate) struct NovaCore { 9 #[pin] 10 pub(crate) gpu: Gpu, 11 _reg: auxiliary::Registration, 12 } 13 14 const BAR0_SIZE: usize = SZ_16M; 15 pub(crate) type Bar0 = pci::Bar<BAR0_SIZE>; 16 17 kernel::pci_device_table!( 18 PCI_TABLE, 19 MODULE_PCI_TABLE, 20 <NovaCore as pci::Driver>::IdInfo, 21 [( 22 pci::DeviceId::from_id(bindings::PCI_VENDOR_ID_NVIDIA, bindings::PCI_ANY_ID as u32), 23 () 24 )] 25 ); 26 27 impl pci::Driver for NovaCore { 28 type IdInfo = (); 29 const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE; 30 31 fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> Result<Pin<KBox<Self>>> { 32 dev_dbg!(pdev.as_ref(), "Probe Nova Core GPU driver.\n"); 33 34 pdev.enable_device_mem()?; 35 pdev.set_master(); 36 37 let devres_bar = Arc::pin_init( 38 pdev.iomap_region_sized::<BAR0_SIZE>(0, c_str!("nova-core/bar0")), 39 GFP_KERNEL, 40 )?; 41 42 // Used to provided a `&Bar0` to `Gpu::new` without tying it to the lifetime of 43 // `devres_bar`. 44 let bar_clone = Arc::clone(&devres_bar); 45 let bar = bar_clone.access(pdev.as_ref())?; 46 47 let this = KBox::pin_init( 48 try_pin_init!(Self { 49 gpu <- Gpu::new(pdev, devres_bar, bar), 50 _reg: auxiliary::Registration::new( 51 pdev.as_ref(), 52 c_str!("nova-drm"), 53 0, // TODO[XARR]: Once it lands, use XArray; for now we don't use the ID. 54 crate::MODULE_NAME 55 )?, 56 }), 57 GFP_KERNEL, 58 )?; 59 60 Ok(this) 61 } 62 63 fn unbind(pdev: &pci::Device<Core>, this: Pin<&Self>) { 64 this.gpu.unbind(pdev.as_ref()); 65 } 66 } 67