1 // SPDX-License-Identifier: GPL-2.0 2 3 use kernel::{auxiliary, bindings, c_str, device::Core, pci, prelude::*}; 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 = 8; 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 _), 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 bar = pdev.iomap_region_sized::<BAR0_SIZE>(0, c_str!("nova-core/bar0"))?; 38 39 let this = KBox::pin_init( 40 try_pin_init!(Self { 41 gpu <- Gpu::new(pdev, bar)?, 42 _reg: auxiliary::Registration::new( 43 pdev.as_ref(), 44 c_str!("nova-drm"), 45 0, // TODO: Once it lands, use XArray; for now we don't use the ID. 46 crate::MODULE_NAME 47 )?, 48 }), 49 GFP_KERNEL, 50 )?; 51 52 Ok(this) 53 } 54 } 55