1 // SPDX-License-Identifier: GPL-2.0 2 3 use kernel::{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 } 12 13 const BAR0_SIZE: usize = 8; 14 pub(crate) type Bar0 = pci::Bar<BAR0_SIZE>; 15 16 kernel::pci_device_table!( 17 PCI_TABLE, 18 MODULE_PCI_TABLE, 19 <NovaCore as pci::Driver>::IdInfo, 20 [( 21 pci::DeviceId::from_id(bindings::PCI_VENDOR_ID_NVIDIA, bindings::PCI_ANY_ID as _), 22 () 23 )] 24 ); 25 26 impl pci::Driver for NovaCore { 27 type IdInfo = (); 28 const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE; 29 probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> Result<Pin<KBox<Self>>>30 fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> Result<Pin<KBox<Self>>> { 31 dev_dbg!(pdev.as_ref(), "Probe Nova Core GPU driver.\n"); 32 33 pdev.enable_device_mem()?; 34 pdev.set_master(); 35 36 let bar = pdev.iomap_region_sized::<BAR0_SIZE>(0, c_str!("nova-core/bar0"))?; 37 38 let this = KBox::pin_init( 39 try_pin_init!(Self { 40 gpu <- Gpu::new(pdev, bar)?, 41 }), 42 GFP_KERNEL, 43 )?; 44 45 Ok(this) 46 } 47 } 48