2025-03-06 23:23:30 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
2025-07-31 21:41:37 +02:00
|
|
|
use kernel::{auxiliary, bindings, c_str, device::Core, pci, prelude::*, sizes::SZ_16M, sync::Arc};
|
2025-03-06 23:23:30 +01:00
|
|
|
|
|
|
|
use crate::gpu::Gpu;
|
|
|
|
|
|
|
|
#[pin_data]
|
|
|
|
pub(crate) struct NovaCore {
|
|
|
|
#[pin]
|
|
|
|
pub(crate) gpu: Gpu,
|
2025-04-24 18:02:49 +02:00
|
|
|
_reg: auxiliary::Registration,
|
2025-03-06 23:23:30 +01:00
|
|
|
}
|
|
|
|
|
2025-06-19 22:23:54 +09:00
|
|
|
const BAR0_SIZE: usize = SZ_16M;
|
2025-03-06 23:23:30 +01:00
|
|
|
pub(crate) type Bar0 = pci::Bar<BAR0_SIZE>;
|
|
|
|
|
|
|
|
kernel::pci_device_table!(
|
|
|
|
PCI_TABLE,
|
|
|
|
MODULE_PCI_TABLE,
|
|
|
|
<NovaCore as pci::Driver>::IdInfo,
|
|
|
|
[(
|
2025-06-15 16:55:08 -04:00
|
|
|
pci::DeviceId::from_id(bindings::PCI_VENDOR_ID_NVIDIA, bindings::PCI_ANY_ID as u32),
|
2025-03-06 23:23:30 +01:00
|
|
|
()
|
|
|
|
)]
|
|
|
|
);
|
|
|
|
|
|
|
|
impl pci::Driver for NovaCore {
|
|
|
|
type IdInfo = ();
|
|
|
|
const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE;
|
|
|
|
|
Driver core updates for 6.15-rc1
Here is the big set of driver core updates for 6.15-rc1. Lots of stuff
happened this development cycle, including:
- kernfs scaling changes to make it even faster thanks to rcu
- bin_attribute constify work in many subsystems
- faux bus minor tweaks for the rust bindings
- rust binding updates for driver core, pci, and platform busses,
making more functionaliy available to rust drivers. These are all
due to people actually trying to use the bindings that were in 6.14.
- make Rafael and Danilo full co-maintainers of the driver core
codebase
- other minor fixes and updates.
This has been in linux-next for a while now, with the only reported
issue being some merge conflicts with the rust tree. Depending on which
tree you pull first, you will have conflicts in one of them. The merge
resolution has been in linux-next as an example of what to do, or can be
found here:
https://lore.kernel.org/r/CANiq72n3Xe8JcnEjirDhCwQgvWoE65dddWecXnfdnbrmuah-RQ@mail.gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-----BEGIN PGP SIGNATURE-----
iG0EABECAC0WIQT0tgzFv3jCIUoxPcsxR9QN2y37KQUCZ+mMrg8cZ3JlZ0Brcm9h
aC5jb20ACgkQMUfUDdst+ylRgwCdH58OE3BgL0uoFY5vFImStpmPtqUAoL5HpVWI
jtbJ+UuXGsnmO+JVNBEv
=gy6W
-----END PGP SIGNATURE-----
Merge tag 'driver-core-6.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core
Pull driver core updatesk from Greg KH:
"Here is the big set of driver core updates for 6.15-rc1. Lots of stuff
happened this development cycle, including:
- kernfs scaling changes to make it even faster thanks to rcu
- bin_attribute constify work in many subsystems
- faux bus minor tweaks for the rust bindings
- rust binding updates for driver core, pci, and platform busses,
making more functionaliy available to rust drivers. These are all
due to people actually trying to use the bindings that were in
6.14.
- make Rafael and Danilo full co-maintainers of the driver core
codebase
- other minor fixes and updates"
* tag 'driver-core-6.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (52 commits)
rust: platform: require Send for Driver trait implementers
rust: pci: require Send for Driver trait implementers
rust: platform: impl Send + Sync for platform::Device
rust: pci: impl Send + Sync for pci::Device
rust: platform: fix unrestricted &mut platform::Device
rust: pci: fix unrestricted &mut pci::Device
rust: device: implement device context marker
rust: pci: use to_result() in enable_device_mem()
MAINTAINERS: driver core: mark Rafael and Danilo as co-maintainers
rust/kernel/faux: mark Registration methods inline
driver core: faux: only create the device if probe() succeeds
rust/faux: Add missing parent argument to Registration::new()
rust/faux: Drop #[repr(transparent)] from faux::Registration
rust: io: fix devres test with new io accessor functions
rust: io: rename `io::Io` accessors
kernfs: Move dput() outside of the RCU section.
efi: rci2: mark bin_attribute as __ro_after_init
rapidio: constify 'struct bin_attribute'
firmware: qemu_fw_cfg: constify 'struct bin_attribute'
powerpc/perf/hv-24x7: Constify 'struct bin_attribute'
...
2025-04-01 11:02:03 -07:00
|
|
|
fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> Result<Pin<KBox<Self>>> {
|
2025-03-06 23:23:30 +01:00
|
|
|
dev_dbg!(pdev.as_ref(), "Probe Nova Core GPU driver.\n");
|
|
|
|
|
|
|
|
pdev.enable_device_mem()?;
|
|
|
|
pdev.set_master();
|
|
|
|
|
rust: devres: get rid of Devres' inner Arc
So far Devres uses an inner memory allocation and reference count, i.e.
an inner Arc, in order to ensure that the devres callback can't run into
a use-after-free in case where the Devres object is dropped while the
devres callback runs concurrently.
Instead, use a completion in order to avoid a potential UAF: In
Devres::drop(), if we detect that we can't remove the devres action
anymore, we wait for the completion that is completed from the devres
callback. If, in turn, we were able to successfully remove the devres
action, we can just go ahead.
This, again, allows us to get rid of the internal Arc, and instead let
Devres consume an `impl PinInit<T, E>` in order to return an
`impl PinInit<Devres<T>, E>`, which enables us to get away with less
memory allocations.
Additionally, having the resulting explicit synchronization in
Devres::drop() prevents potential subtle undesired side effects of the
devres callback dropping the final Arc reference asynchronously within
the devres callback.
Reviewed-by: Benno Lossin <lossin@kernel.org>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250626200054.243480-4-dakr@kernel.org
[ Move '# Invariants' below '# Examples'. - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
2025-06-26 22:00:41 +02:00
|
|
|
let bar = Arc::pin_init(
|
|
|
|
pdev.iomap_region_sized::<BAR0_SIZE>(0, c_str!("nova-core/bar0")),
|
|
|
|
GFP_KERNEL,
|
|
|
|
)?;
|
2025-03-06 23:23:30 +01:00
|
|
|
|
|
|
|
let this = KBox::pin_init(
|
|
|
|
try_pin_init!(Self {
|
|
|
|
gpu <- Gpu::new(pdev, bar)?,
|
2025-04-24 18:02:49 +02:00
|
|
|
_reg: auxiliary::Registration::new(
|
|
|
|
pdev.as_ref(),
|
|
|
|
c_str!("nova-drm"),
|
2025-06-19 22:24:08 +09:00
|
|
|
0, // TODO[XARR]: Once it lands, use XArray; for now we don't use the ID.
|
2025-04-24 18:02:49 +02:00
|
|
|
crate::MODULE_NAME
|
|
|
|
)?,
|
2025-03-06 23:23:30 +01:00
|
|
|
}),
|
|
|
|
GFP_KERNEL,
|
|
|
|
)?;
|
|
|
|
|
|
|
|
Ok(this)
|
|
|
|
}
|
|
|
|
}
|