Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0
2
3use kernel::{auxiliary, bindings, c_str, device::Core, pci, prelude::*, sizes::SZ_16M, sync::Arc};
4
5use crate::gpu::Gpu;
6
7#[pin_data]
8pub(crate) struct NovaCore {
9 #[pin]
10 pub(crate) gpu: Gpu,
11 _reg: auxiliary::Registration,
12}
13
14const BAR0_SIZE: usize = SZ_16M;
15pub(crate) type Bar0 = pci::Bar<BAR0_SIZE>;
16
17kernel::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
27impl 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 = Arc::pin_init(
38 pdev.iomap_region_sized::<BAR0_SIZE>(0, c_str!("nova-core/bar0")),
39 GFP_KERNEL,
40 )?;
41
42 let this = KBox::pin_init(
43 try_pin_init!(Self {
44 gpu <- Gpu::new(pdev, bar)?,
45 _reg: auxiliary::Registration::new(
46 pdev.as_ref(),
47 c_str!("nova-drm"),
48 0, // TODO[XARR]: Once it lands, use XArray; for now we don't use the ID.
49 crate::MODULE_NAME
50 )?,
51 }),
52 GFP_KERNEL,
53 )?;
54
55 Ok(this)
56 }
57}