mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
The auxiliary device registration was using a hardcoded ID of 0, which caused probe() to fail on multi-GPU systems with: sysfs: cannot create duplicate filename '/bus/auxiliary/devices/NovaCore.nova-drm.0' Fix this by using an atomic counter to generate unique IDs for each GPU's aux device registration. The TODO item to eventually use XArray for recycling aux device IDs is retained, but for now, this works very nicely. This has the side effect of making debugfs[1] work on multi-GPU systems. [1] https://lore.kernel.org/20260203224757.871729-1-ttabi@nvidia.com Reviewed-by: Gary Guo <gary@garyguo.net> Signed-off-by: John Hubbard <jhubbard@nvidia.com> Link: https://patch.msgid.link/20260221020952.412352-2-jhubbard@nvidia.com [ Use LKMM atomics; inline and slightly reword TODO comment. - Danilo ] Signed-off-by: Danilo Krummrich <dakr@kernel.org>
115 lines
3.2 KiB
Rust
115 lines
3.2 KiB
Rust
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
use kernel::{
|
|
auxiliary,
|
|
device::Core,
|
|
devres::Devres,
|
|
dma::Device,
|
|
dma::DmaMask,
|
|
pci,
|
|
pci::{
|
|
Class,
|
|
ClassMask,
|
|
Vendor, //
|
|
},
|
|
prelude::*,
|
|
sizes::SZ_16M,
|
|
sync::{
|
|
atomic::{
|
|
Atomic,
|
|
Relaxed, //
|
|
},
|
|
Arc,
|
|
},
|
|
};
|
|
|
|
use crate::gpu::Gpu;
|
|
|
|
/// Counter for generating unique auxiliary device IDs.
|
|
static AUXILIARY_ID_COUNTER: Atomic<u32> = Atomic::new(0);
|
|
|
|
#[pin_data]
|
|
pub(crate) struct NovaCore {
|
|
#[pin]
|
|
pub(crate) gpu: Gpu,
|
|
#[pin]
|
|
_reg: Devres<auxiliary::Registration>,
|
|
}
|
|
|
|
const BAR0_SIZE: usize = SZ_16M;
|
|
|
|
// For now we only support Ampere which can use up to 47-bit DMA addresses.
|
|
//
|
|
// TODO: Add an abstraction for this to support newer GPUs which may support
|
|
// larger DMA addresses. Limiting these GPUs to smaller address widths won't
|
|
// have any adverse affects, unless installed on systems which require larger
|
|
// DMA addresses. These systems should be quite rare.
|
|
const GPU_DMA_BITS: u32 = 47;
|
|
|
|
pub(crate) type Bar0 = pci::Bar<BAR0_SIZE>;
|
|
|
|
kernel::pci_device_table!(
|
|
PCI_TABLE,
|
|
MODULE_PCI_TABLE,
|
|
<NovaCore as pci::Driver>::IdInfo,
|
|
[
|
|
// Modern NVIDIA GPUs will show up as either VGA or 3D controllers.
|
|
(
|
|
pci::DeviceId::from_class_and_vendor(
|
|
Class::DISPLAY_VGA,
|
|
ClassMask::ClassSubclass,
|
|
Vendor::NVIDIA
|
|
),
|
|
()
|
|
),
|
|
(
|
|
pci::DeviceId::from_class_and_vendor(
|
|
Class::DISPLAY_3D,
|
|
ClassMask::ClassSubclass,
|
|
Vendor::NVIDIA
|
|
),
|
|
()
|
|
),
|
|
]
|
|
);
|
|
|
|
impl pci::Driver for NovaCore {
|
|
type IdInfo = ();
|
|
const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE;
|
|
|
|
fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> impl PinInit<Self, Error> {
|
|
pin_init::pin_init_scope(move || {
|
|
dev_dbg!(pdev, "Probe Nova Core GPU driver.\n");
|
|
|
|
pdev.enable_device_mem()?;
|
|
pdev.set_master();
|
|
|
|
// SAFETY: No concurrent DMA allocations or mappings can be made because
|
|
// the device is still being probed and therefore isn't being used by
|
|
// other threads of execution.
|
|
unsafe { pdev.dma_set_mask_and_coherent(DmaMask::new::<GPU_DMA_BITS>())? };
|
|
|
|
let bar = Arc::pin_init(
|
|
pdev.iomap_region_sized::<BAR0_SIZE>(0, c"nova-core/bar0"),
|
|
GFP_KERNEL,
|
|
)?;
|
|
|
|
Ok(try_pin_init!(Self {
|
|
gpu <- Gpu::new(pdev, bar.clone(), bar.access(pdev.as_ref())?),
|
|
_reg <- auxiliary::Registration::new(
|
|
pdev.as_ref(),
|
|
c"nova-drm",
|
|
// TODO[XARR]: Use XArray or perhaps IDA for proper ID allocation/recycling. For
|
|
// now, use a simple atomic counter that never recycles IDs.
|
|
AUXILIARY_ID_COUNTER.fetch_add(1, Relaxed),
|
|
crate::MODULE_NAME
|
|
),
|
|
}))
|
|
})
|
|
}
|
|
|
|
fn unbind(pdev: &pci::Device<Core>, this: Pin<&Self>) {
|
|
this.gpu.unbind(pdev.as_ref());
|
|
}
|
|
}
|