summaryrefslogtreecommitdiff
path: root/drivers/gpu/nova-core/irq
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2026-11-21 17:22:21 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2026-11-21 17:22:21 -0800
commit4843f6873f7c4835e62f2c73ba0fd538e57a2f22 (patch)
treeee620501a1ffbad9a83141e3a70154e1fe641040 /drivers/gpu/nova-core/irq
downloadlinux-master.tar.gz
linux-master.zip
Merge tag 'sysctl-7.04-fixes-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/sysctl/sysctlgraftedHEADmaster
Pull sysctl fix from Joel Granados: "Fix sysctl jiffy / milliseconds conversion: - Writing a previously read value "X" shall keep the same "X" value - Remove truncation that was causing incorrect saturation of valid timeouts" * tag 'sysctl-7.04-fixes-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/sysctl/sysctl: sysctl: Do jiffy / ms conversion in ulong space
Diffstat (limited to 'drivers/gpu/nova-core/irq')
-rw-r--r--drivers/gpu/nova-core/irq/doorbell_test.rs251
-rw-r--r--drivers/gpu/nova-core/irq/gsp.rs195
-rw-r--r--drivers/gpu/nova-core/irq/hal.rs67
-rw-r--r--drivers/gpu/nova-core/irq/hal/gh100.rs40
-rw-r--r--drivers/gpu/nova-core/irq/hal/tu102.rs43
-rw-r--r--drivers/gpu/nova-core/irq/interrupt_tree.rs682
-rw-r--r--drivers/gpu/nova-core/irq/regs.rs88
7 files changed, 1366 insertions, 0 deletions
diff --git a/drivers/gpu/nova-core/irq/doorbell_test.rs b/drivers/gpu/nova-core/irq/doorbell_test.rs
new file mode 100644
index 000000000..db6338e4d
--- /dev/null
+++ b/drivers/gpu/nova-core/irq/doorbell_test.rs
@@ -0,0 +1,251 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+//! Interrupt delivery self-test.
+//!
+//! The test triggers the CPU doorbell vector from software, twice, and checks that each trigger
+//! reaches a registered handler. It runs during probe under `CONFIG_NOVA_CORE_SELFTESTS`.
+
+use core::pin::Pin;
+
+use kernel::{
+ device::Bound,
+ io::poll::read_poll_timeout,
+ irq,
+ pci,
+ prelude::*,
+ sync::atomic::{
+ Acquire,
+ Atomic,
+ Relaxed,
+ Release, //
+ },
+ time::Delta, //
+};
+
+use super::interrupt_tree::{
+ GinVector,
+ LeafEnableGuard,
+ LeafMask,
+ Subtree,
+ TopEnableGuard,
+ Tree, //
+};
+
+use crate::{
+ driver::Bar0,
+ gpu::Chipset,
+ selftest_assert,
+ selftest_assert_eq, //
+};
+
+/// The CPU doorbell vector. Every supported GPU uses this number, so the test needs nothing from
+/// GSP-RM, which is not running yet.
+const DOORBELL_VECTOR: GinVector = GinVector::new::<129>();
+
+/// The only subtree that this test services.
+const DOORBELL_SUBTREE: Subtree = DOORBELL_VECTOR.subtree();
+
+/// Time allowed for each delivery to arrive.
+const DELIVERY_TIMEOUT: Delta = Delta::from_millis(1000);
+
+/// The self-test's interrupt handler.
+///
+/// It clears only the doorbell's bit, rearms delivery, and never walks the tree. A missing rearm
+/// shows up as a timeout on the second delivery.
+#[pin_data]
+struct DoorbellTestHandler<'a> {
+ tree: &'a Tree<'a>,
+ /// Deliveries that found the doorbell bit set.
+ irq_count: Atomic<u32>,
+ /// The doorbell leaf's pending bits, as read by the first delivery.
+ first_pending: Atomic<u32>,
+ /// The doorbell leaf's pending bits, as read by the second delivery.
+ second_pending: Atomic<u32>,
+}
+
+impl irq::Handler for DoorbellTestHandler<'_> {
+ fn handle(&self) -> irq::IrqReturn {
+ let leaf = self.tree.read_pending(DOORBELL_VECTOR.leaf_index());
+ let pending = leaf.vectors();
+ if !pending.contains(DOORBELL_VECTOR.leaf_mask()) {
+ self.tree.rearm_pci_irq(DOORBELL_SUBTREE);
+ return irq::IrqReturn::None;
+ }
+ leaf.clear_vectors(DOORBELL_VECTOR.leaf_mask());
+ // Rearm before counting the delivery, since the waiting thread triggers the next doorbell
+ // as soon as it observes the count.
+ self.tree.rearm_pci_irq(DOORBELL_SUBTREE);
+
+ match self.irq_count.load(Relaxed) {
+ 0 => self.first_pending.store(pending.into_raw(), Relaxed),
+ 1 => self.second_pending.store(pending.into_raw(), Relaxed),
+ _ => (),
+ }
+ self.irq_count.fetch_add(1, Release);
+
+ irq::IrqReturn::Handled
+ }
+}
+
+/// The self-test's handler registration and the enables that deliver to it.
+///
+/// Drops in the order that "Enabling the GSP event" in
+/// `Documentation/gpu/nova/core/interrupts.rst` requires: the vector is disabled, then the
+/// handler is freed, then the subtree is disabled.
+struct SelftestResources<'a, 'r> {
+ _leaf_guard: LeafEnableGuard<'a>,
+ reg: Pin<KBox<irq::Registration<'r, DoorbellTestHandler<'a>>>>,
+ _top_guard: TopEnableGuard<'a>,
+}
+
+impl<'a> SelftestResources<'a, '_> {
+ fn handler(&self) -> &DoorbellTestHandler<'a> {
+ self.reg.handler()
+ }
+
+ /// Disables the doorbell vector and waits for a handler in flight on another CPU to finish.
+ ///
+ /// The handler's counters and the leaf's pending bits are final on return.
+ fn quiesce_source(&self) {
+ self.handler()
+ .tree
+ .disable_leaf(DOORBELL_VECTOR.leaf_index(), DOORBELL_VECTOR.leaf_mask());
+ self.reg.synchronize();
+ }
+}
+
+/// Waits until `handler` has serviced `deliveries` interrupts, or [`DELIVERY_TIMEOUT`] elapses.
+///
+/// Returns `false` on timeout.
+fn wait_for_deliveries(handler: &DoorbellTestHandler<'_>, deliveries: u32) -> bool {
+ const DELIVERY_POLL_INTERVAL: Delta = Delta::from_micros(100);
+
+ read_poll_timeout(
+ || Ok(handler.irq_count.load(Acquire)),
+ |count| *count >= deliveries,
+ DELIVERY_POLL_INTERVAL,
+ DELIVERY_TIMEOUT,
+ )
+ .is_ok()
+}
+
+/// Runs the interrupt delivery self-test.
+///
+/// Call this only during probe, before GSP boot: it disables every vector in the tree and clears
+/// every pending bit. On return, the doorbell's subtree is disabled at `TOP`, and the test's PCI
+/// vectors and handler are released.
+///
+/// # Errors
+///
+/// `EINVAL` if `chipset` does not implement the doorbell's subtree. `ETIMEDOUT` if a delivery
+/// does not arrive within [`DELIVERY_TIMEOUT`]. `EIO` if a self-test assertion fails.
+/// Otherwise the error from allocating the PCI vectors or registering the handler.
+pub(crate) fn run_selftest(pdev: &pci::Device<Bound>, bar: Bar0<'_>, chipset: Chipset) -> Result {
+ let tree = Tree::new(pdev, bar, chipset, DOORBELL_SUBTREE.into())?;
+ let tree_ref = &tree;
+ let request = tree.request_for(DOORBELL_SUBTREE)?;
+ let doorbell = DOORBELL_VECTOR.leaf_index();
+ let doorbell_mask = DOORBELL_VECTOR.leaf_mask();
+
+ dev_info!(
+ pdev,
+ "interrupt self-test: starting on vector {}, subtree {}, with {:?}\n",
+ DOORBELL_VECTOR.into_raw(),
+ DOORBELL_SUBTREE.index(),
+ tree.msi_type,
+ );
+
+ // GFW boot can leave vectors enabled and pending. Registering a handler unmasks the PCI
+ // interrupt, and they would be delivered to a handler that services only the doorbell.
+ tree.reset();
+
+ // A delivery proves nothing unless the doorbell bit starts out clear.
+ let pre_pending = tree.read_pending(doorbell).vectors();
+ selftest_assert!(
+ pdev,
+ !pre_pending.contains(doorbell_mask),
+ "vector {} already pending, leaf[{}] is {:#x}",
+ DOORBELL_VECTOR.into_raw(),
+ doorbell.get(),
+ pre_pending.into_raw()
+ );
+
+ let handler_init = try_pin_init!(DoorbellTestHandler {
+ tree: tree_ref,
+ irq_count: Atomic::new(0),
+ first_pending: Atomic::new(0),
+ second_pending: Atomic::new(0),
+ }? Error);
+
+ // Registration must precede any enable, or a delivery reaches no handler.
+ let reg = KBox::pin_init(
+ // SAFETY: this registration is dropped before the enclosing function returns, so its
+ // `Drop`, which calls `free_irq()`, always runs.
+ unsafe {
+ irq::Registration::new(
+ request,
+ irq::Flags::TRIGGER_NONE,
+ c"nova-core-selftest",
+ handler_init,
+ )
+ },
+ GFP_KERNEL,
+ )?;
+
+ let resources = SelftestResources {
+ _leaf_guard: tree.enable_leaf_guarded(doorbell, doorbell_mask),
+ _top_guard: tree.enable_top_guarded(),
+ reg,
+ };
+ let handler = resources.handler();
+
+ tree.trigger(DOORBELL_VECTOR)?;
+ let mut completed = wait_for_deliveries(handler, 1);
+
+ // The second trigger waits for the first delivery, or the two could coalesce.
+ if completed {
+ tree.trigger(DOORBELL_VECTOR)?;
+ completed = wait_for_deliveries(handler, 2);
+ }
+
+ resources.quiesce_source();
+
+ let count = handler.irq_count.load(Relaxed);
+ let first_pending = LeafMask::from_raw(handler.first_pending.load(Relaxed));
+ let second_pending = LeafMask::from_raw(handler.second_pending.load(Relaxed));
+ let residual = tree.read_pending(doorbell).vectors();
+
+ if !completed {
+ dev_err!(
+ pdev,
+ "interrupt self-test: only {} of 2 deliveries arrived within {} ms\n",
+ count,
+ DELIVERY_TIMEOUT.as_millis(),
+ );
+ return Err(ETIMEDOUT);
+ }
+
+ selftest_assert_eq!(pdev, count, 2, "delivery count");
+
+ // Every other vector in the leaf is disabled and was drained, so require the exact mask.
+ selftest_assert_eq!(pdev, first_pending, doorbell_mask, "first delivery");
+ selftest_assert_eq!(pdev, second_pending, doorbell_mask, "second delivery");
+ selftest_assert!(
+ pdev,
+ !residual.contains(doorbell_mask),
+ "vector {} still pending, leaf[{}] is {:#x}",
+ DOORBELL_VECTOR.into_raw(),
+ doorbell.get(),
+ residual.into_raw()
+ );
+
+ dev_info!(
+ pdev,
+ "interrupt self-test: passed, subtree {}, {} deliveries\n",
+ DOORBELL_SUBTREE.index(),
+ count,
+ );
+
+ Ok(())
+}
diff --git a/drivers/gpu/nova-core/irq/gsp.rs b/drivers/gpu/nova-core/irq/gsp.rs
new file mode 100644
index 000000000..1abde8e0a
--- /dev/null
+++ b/drivers/gpu/nova-core/irq/gsp.rs
@@ -0,0 +1,195 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+//! The GSP event interrupt.
+//!
+//! The GSP posts messages to the GSP-to-CPU queue and raises SWGEN0, a software-generated cause
+//! of its falcon. A threaded handler services it: the top half clears the tree and falcon state,
+//! and the IRQ thread drains the queue.
+//!
+//! See "The GSP event" in `Documentation/gpu/nova/core/interrupts.rst`.
+
+use kernel::{
+ device,
+ irq,
+ pci,
+ prelude::*, //
+};
+
+use super::interrupt_tree::{
+ GinVector,
+ LeafEnableGuard,
+ Subtree,
+ Tree, //
+};
+use crate::{
+ falcon::{
+ gsp::Gsp as GspFalcon,
+ Falcon, //
+ },
+ gsp::cmdq::Cmdq,
+ regs, //
+};
+
+/// The GSP event vector, which has the same number on every supported GPU.
+const GSP_INTR_0_VECTOR: GinVector = GinVector::new::<155>();
+
+/// The GSP event's subtree, the only one that nova-core services.
+pub(crate) const GSP_SUBTREE: Subtree = GSP_INTR_0_VECTOR.subtree();
+
+/// Clears the tree and falcon interrupt state that GSP boot leaves behind, and rearms PCI
+/// interrupt delivery.
+///
+/// On return, no vector is enabled at its leaf, the serviced subtrees are disabled at `TOP`, and
+/// the SWGEN0 latch is clear, so the next message that the GSP posts signals the tree.
+pub(crate) fn quiesce(tree: &Tree<'_>, falcon: &Falcon<'_, GspFalcon>) {
+ tree.reset();
+ // The latch is cleared after the tree reset. The other order can leave the latch set with its
+ // leaf bit cleared. See "Enabling the GSP event" in interrupts.rst.
+ falcon.clear_swgen0_intr();
+}
+
+/// Threaded IRQ handler for the GSP event.
+pub(crate) struct GspInterrupt<'a> {
+ falcon: &'a Falcon<'a, GspFalcon>,
+ cmdq: &'a Cmdq<'a>,
+ tree: &'a Tree<'a>,
+ /// For logging.
+ dev: &'a device::Device,
+}
+
+impl GspInterrupt<'_> {
+ /// Clears the latch of every host-routed cause in `status` other than SWGEN0, and logs them.
+ ///
+ /// Returns the causes still set after the clear. A cause driven from outside the falcon stays
+ /// set, and only a device reset ends it.
+ fn clear_faults(
+ &self,
+ status: regs::NV_PFALCON_FALCON_IRQSTAT,
+ ) -> regs::NV_PFALCON_FALCON_IRQSTAT {
+ let faults = status.with_swgen0(false);
+ if faults.into_raw() == 0 {
+ return faults;
+ }
+
+ dev_err!(
+ &self.dev,
+ "unserviceable GSP falcon interrupt, IRQSTAT {:#x}\n",
+ status.into_raw()
+ );
+ self.falcon.clear_intr(faults);
+
+ self.falcon.read_host_intr().with_swgen0(false)
+ }
+}
+
+impl irq::ThreadedHandler for GspInterrupt<'_> {
+ /// Top half, in hard interrupt context. Services the GSP vector only, so another vector
+ /// pending in the same leaf stays pending.
+ fn handle(&self) -> irq::ThreadedIrqReturn {
+ let leaf = self.tree.read_pending(GSP_INTR_0_VECTOR.leaf_index());
+ if !leaf.vectors().contains(GSP_INTR_0_VECTOR.leaf_mask()) {
+ self.tree.rearm_pci_irq(GSP_SUBTREE);
+ return irq::ThreadedIrqReturn::None;
+ }
+ leaf.clear_vectors(GSP_INTR_0_VECTOR.leaf_mask());
+
+ let status = self.falcon.take_host_intr();
+
+ let remaining_faults = self.clear_faults(status);
+ if remaining_faults.into_raw() == 0 {
+ self.falcon.retrigger_intr();
+ } else {
+ // Disabling the vector loses no notification: the falcon signals nothing further
+ // while a cause stays set. See "Retriggering a falcon" in interrupts.rst.
+ self.tree.disable_leaf(
+ GSP_INTR_0_VECTOR.leaf_index(),
+ GSP_INTR_0_VECTOR.leaf_mask(),
+ );
+ dev_err!(
+ &self.dev,
+ "GSP falcon cause {:#x} needs a device reset, GSP events are no longer serviced\n",
+ remaining_faults.into_raw()
+ );
+ }
+
+ self.tree.rearm_pci_irq(GSP_SUBTREE);
+
+ if status.swgen0() {
+ irq::ThreadedIrqReturn::WakeThread
+ } else {
+ irq::ThreadedIrqReturn::Handled
+ }
+ }
+
+ /// IRQ thread. Drains the GSP-to-CPU queue, which may sleep.
+ fn handle_threaded(&self) -> irq::IrqReturn {
+ if let Err(e) = self.cmdq.drain() {
+ // The failed message stays at the queue head, so every later drain fails the same way.
+ self.tree.disable_leaf(
+ GSP_INTR_0_VECTOR.leaf_index(),
+ GSP_INTR_0_VECTOR.leaf_mask(),
+ );
+ dev_err!(
+ &self.dev,
+ "GSP event drain failed ({:?}), the message queue is no longer serviced\n",
+ e
+ );
+ }
+ irq::IrqReturn::Handled
+ }
+}
+
+/// The registered GSP event handler and the enable of its vector.
+///
+/// The declaration order is the drop order, and it is required: the vector is disabled before
+/// `free_irq` runs. See "Enabling the GSP event" in `Documentation/gpu/nova/core/interrupts.rst`.
+#[pin_data]
+pub(crate) struct GspIrq<'a> {
+ _leaf_guard: LeafEnableGuard<'a>,
+ #[pin]
+ reg: irq::ThreadedRegistration<'a, GspInterrupt<'a>>,
+}
+
+impl<'a> GspIrq<'a> {
+ /// Returns an initializer that registers the threaded handler and then enables the GSP
+ /// vector at its leaf.
+ ///
+ /// An event that latched while the vector was disabled is delivered as soon as the GSP
+ /// subtree is enabled at `TOP`.
+ ///
+ /// # Errors
+ ///
+ /// `EINVAL` if `tree` does not service the GSP subtree. Otherwise the error from
+ /// `request_threaded_irq`.
+ ///
+ /// # Safety
+ ///
+ /// Callers must not `mem::forget()` the initialized `GspIrq` or otherwise prevent its [`Drop`]
+ /// implementation, which runs `free_irq`, from running.
+ pub(crate) unsafe fn new(
+ pdev: &'a pci::Device<device::Bound>,
+ tree: &'a Tree<'a>,
+ falcon: &'a Falcon<'a, GspFalcon>,
+ cmdq: &'a Cmdq<'a>,
+ ) -> impl PinInit<Self, Error> + 'a {
+ let dev = pdev.as_ref();
+
+ try_pin_init!(Self {
+ // SAFETY: this function's caller must not leak the `GspIrq` that owns this
+ // registration, so the registration's `Drop` runs.
+ reg <- unsafe {
+ irq::ThreadedRegistration::new(
+ tree.request_for(GSP_SUBTREE)?,
+ irq::Flags::TRIGGER_NONE,
+ c"nova-core",
+ Ok(GspInterrupt { falcon, cmdq, tree, dev }),
+ )
+ },
+ _leaf_guard: tree.enable_leaf_guarded(
+ GSP_INTR_0_VECTOR.leaf_index(),
+ GSP_INTR_0_VECTOR.leaf_mask(),
+ ),
+ })
+ }
+}
diff --git a/drivers/gpu/nova-core/irq/hal.rs b/drivers/gpu/nova-core/irq/hal.rs
new file mode 100644
index 000000000..387695cca
--- /dev/null
+++ b/drivers/gpu/nova-core/irq/hal.rs
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+//! Per-architecture differences in the GIN CPU interrupt tree.
+//!
+//! See "Per-architecture differences" in `Documentation/gpu/nova/core/interrupts.rst`.
+
+mod gh100;
+mod tu102;
+
+use kernel::{
+ io::Io,
+ prelude::*, //
+};
+
+use crate::{
+ driver::Bar0,
+ gpu::{
+ Architecture,
+ Chipset, //
+ }, //
+};
+
+use super::{
+ interrupt_tree::{
+ LeafCount,
+ Subtree,
+ SubtreeSet, //
+ },
+ regs::*,
+ MsiType, //
+};
+
+/// Clears and then sets the `TOP` enables of `subtrees`, which produces a new delivery edge.
+fn cycle_top_enables(bar: Bar0<'_>, subtrees: SubtreeSet) {
+ bar.write_reg(NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_TOP_EN_CLEAR::zeroed().with_subtrees(subtrees));
+ bar.write_reg(NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_TOP_EN_SET::zeroed().with_subtrees(subtrees));
+}
+
+/// The leaf count and the rearm of the GIN CPU tree, which differ by GPU family.
+pub(super) trait CpuInterruptHal: Send + Sync {
+ /// Returns the number of leaves the tree implements.
+ fn leaf_count(&self) -> LeafCount;
+
+ /// Rearms PCI interrupt delivery after a handler serviced `subtree`.
+ ///
+ /// `serviced` is every subtree that nova-core services, for the Hopper-plus MSI form, which
+ /// cycles the `TOP` enables of them all. See "Rearming PCI interrupt delivery" in
+ /// `Documentation/gpu/nova/core/interrupts.rst`.
+ fn rearm_pci_irq(
+ &self,
+ bar: Bar0<'_>,
+ msi_type: MsiType,
+ serviced: SubtreeSet,
+ subtree: Subtree,
+ );
+}
+
+/// Returns the [`CpuInterruptHal`] for `chipset`'s architecture.
+pub(super) fn cpu_interrupt_hal(chipset: Chipset) -> &'static dyn CpuInterruptHal {
+ match chipset.arch() {
+ Architecture::Turing | Architecture::Ampere | Architecture::Ada => tu102::TU102_HAL,
+ Architecture::Hopper | Architecture::BlackwellGB10x | Architecture::BlackwellGB20x => {
+ gh100::GH100_HAL
+ }
+ }
+}
diff --git a/drivers/gpu/nova-core/irq/hal/gh100.rs b/drivers/gpu/nova-core/irq/hal/gh100.rs
new file mode 100644
index 000000000..6e307c8d1
--- /dev/null
+++ b/drivers/gpu/nova-core/irq/hal/gh100.rs
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+use crate::driver::Bar0;
+
+use super::{
+ cycle_top_enables,
+ CpuInterruptHal,
+ LeafCount,
+ MsiType,
+ Subtree,
+ SubtreeSet, //
+};
+
+/// The CPU interrupt tree properties of Hopper and Blackwell.
+struct Gh100;
+
+impl CpuInterruptHal for Gh100 {
+ fn leaf_count(&self) -> LeafCount {
+ LeafCount::Sixteen
+ }
+
+ fn rearm_pci_irq(
+ &self,
+ bar: Bar0<'_>,
+ msi_type: MsiType,
+ serviced: SubtreeSet,
+ subtree: Subtree,
+ ) {
+ let subtrees = match msi_type {
+ MsiType::Msi => serviced,
+ MsiType::MsiX => subtree.into(),
+ };
+
+ cycle_top_enables(bar, subtrees);
+ }
+}
+
+const GH100: Gh100 = Gh100;
+pub(super) const GH100_HAL: &dyn CpuInterruptHal = &GH100;
diff --git a/drivers/gpu/nova-core/irq/hal/tu102.rs b/drivers/gpu/nova-core/irq/hal/tu102.rs
new file mode 100644
index 000000000..7e3aea946
--- /dev/null
+++ b/drivers/gpu/nova-core/irq/hal/tu102.rs
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+use kernel::io::Io;
+
+use crate::{
+ driver::Bar0,
+ irq::regs::NV_XVE_CYA_2, //
+};
+
+use super::{
+ cycle_top_enables,
+ CpuInterruptHal,
+ LeafCount,
+ MsiType,
+ Subtree,
+ SubtreeSet, //
+};
+
+/// The CPU interrupt tree properties of Turing, Ampere, and Ada.
+struct Tu102;
+
+impl CpuInterruptHal for Tu102 {
+ fn leaf_count(&self) -> LeafCount {
+ LeafCount::Eight
+ }
+
+ fn rearm_pci_irq(
+ &self,
+ bar: Bar0<'_>,
+ msi_type: MsiType,
+ _serviced: SubtreeSet,
+ subtree: Subtree,
+ ) {
+ match msi_type {
+ MsiType::Msi => bar.write(NV_XVE_CYA_2, 0u32.into()),
+ MsiType::MsiX => cycle_top_enables(bar, subtree.into()),
+ }
+ }
+}
+
+const TU102: Tu102 = Tu102;
+pub(super) const TU102_HAL: &dyn CpuInterruptHal = &TU102;
diff --git a/drivers/gpu/nova-core/irq/interrupt_tree.rs b/drivers/gpu/nova-core/irq/interrupt_tree.rs
new file mode 100644
index 000000000..590f92189
--- /dev/null
+++ b/drivers/gpu/nova-core/irq/interrupt_tree.rs
@@ -0,0 +1,682 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+//! The GIN CPU interrupt tree for one PCIe function.
+//!
+//! A [`GinVector`] names an interrupt source, a [`LeafIndex`] the leaf register that latches it,
+//! a [`LeafMask`] a set of vectors within one leaf, and a [`Subtree`] one `TOP` bit. The types
+//! keep the four from being confused with one another.
+//!
+//! Servicing a leaf requires reading its pending bits before clearing them. Only
+//! [`Tree::read_pending`] produces a [`LeafPending`], and only a [`LeafPending`] clears a leaf,
+//! so that the wrong order does not compile. This module does not serialize access to the tree.
+//!
+//! See `Documentation/gpu/nova/core/interrupts.rst`.
+
+use kernel::{
+ device::Bound,
+ io::{
+ register::Array,
+ Io, //
+ },
+ irq,
+ num::Bounded,
+ pci::{
+ self,
+ IrqType, //
+ },
+ prelude::*, //
+};
+
+use crate::{
+ driver::Bar0,
+ gpu::Chipset,
+ num, //
+};
+
+use super::{
+ hal::{
+ cpu_interrupt_hal,
+ CpuInterruptHal, //
+ },
+ regs::*,
+ MsiType, //
+};
+
+/// Number of vectors one leaf register carries, one per bit.
+const VECTORS_PER_LEAF: u32 = u32::BITS;
+
+/// Number of leaves one subtree covers.
+const LEAVES_PER_SUBTREE: u32 = 2;
+
+/// Number of subtrees the widest supported tree implements.
+const MAX_NUM_SUBTREES: u32 = 8;
+
+/// Number of leaves the widest supported tree implements.
+const MAX_NUM_LEAVES: u32 = MAX_NUM_SUBTREES * LEAVES_PER_SUBTREE;
+
+/// Number of bits needed to address every vector in the widest supported tree.
+const VECTOR_BITS: u32 = (MAX_NUM_LEAVES * VECTORS_PER_LEAF).ilog2();
+
+/// Width of the vector field in the leaf trigger register.
+const TRIGGER_VECTOR_BITS: u32 = {
+ let range = NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_TRIGGER::VECTOR_RANGE;
+ num::u8_as_u32(*range.end() - *range.start() + 1)
+};
+
+/// Index of a leaf register within the widest supported tree. An 8-leaf tree implements only the
+/// lower half of the range.
+pub(super) type LeafIndex = Bounded<usize, { MAX_NUM_LEAVES.ilog2() }>;
+
+/// Number of leaves a tree implements.
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+#[repr(u32)]
+pub(super) enum LeafCount {
+ /// Turing through Ada.
+ Eight = 8,
+
+ /// Hopper and later.
+ Sixteen = 16,
+}
+
+impl LeafCount {
+ pub(super) const fn into_u32(self) -> u32 {
+ // CAST: `LeafCount` is `repr(u32)`, so the cast is lossless.
+ self as u32
+ }
+
+ pub(super) const fn into_raw(self) -> usize {
+ num::u32_as_usize(self.into_u32())
+ }
+
+ /// Returns the number of subtrees a tree of this size implements.
+ pub(super) const fn subtree_count(self) -> u32 {
+ self.into_u32() / LEAVES_PER_SUBTREE
+ }
+
+ /// Returns the set of every subtree a tree of this size implements.
+ pub(super) const fn subtree_set(self) -> SubtreeSet {
+ SubtreeSet((1u32 << self.subtree_count()) - 1)
+ }
+
+ /// Returns the number of vectors a tree of this size carries.
+ pub(super) const fn vector_count(self) -> u32 {
+ self.into_u32() * VECTORS_PER_LEAF
+ }
+
+ /// Returns every leaf a tree of this size implements.
+ pub(super) fn iter(self) -> impl Iterator<Item = LeafIndex> {
+ (0..self.into_raw()).filter_map(LeafIndex::try_new)
+ }
+}
+
+// `VECTOR_BITS` and `LeafCount::Sixteen` are written separately. This assert keeps them in
+// agreement about the widest supported tree.
+static_assert!(1 << VECTOR_BITS == LeafCount::Sixteen.vector_count());
+
+/// Set of vectors within one leaf, one bit per vector.
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+pub(super) struct LeafMask(u32);
+
+impl LeafMask {
+ /// Returns the mask with every vector set.
+ pub(super) const fn all() -> Self {
+ Self(u32::MAX)
+ }
+
+ #[cfg_attr(not(CONFIG_NOVA_CORE_SELFTESTS), expect(dead_code))]
+ pub(super) const fn from_raw(raw: u32) -> Self {
+ Self(raw)
+ }
+
+ #[cfg_attr(
+ not(any(CONFIG_NOVA_CORE_SELFTESTS, CONFIG_KUNIT = "y")),
+ expect(dead_code)
+ )]
+ pub(super) const fn into_raw(self) -> u32 {
+ self.0
+ }
+
+ pub(super) const fn is_empty(self) -> bool {
+ self.0 == 0
+ }
+
+ /// Returns whether every vector in `other` is also in this mask.
+ pub(super) const fn contains(self, other: Self) -> bool {
+ self.0 & other.0 == other.0
+ }
+}
+
+impl From<Bounded<u32, 32>> for LeafMask {
+ fn from(vectors: Bounded<u32, 32>) -> Self {
+ Self(vectors.get())
+ }
+}
+
+impl From<LeafMask> for Bounded<u32, 32> {
+ fn from(vectors: LeafMask) -> Self {
+ vectors.0.into()
+ }
+}
+
+/// One subtree, held as the `TOP` bit that covers it.
+///
+/// # Invariants
+///
+/// Exactly one bit is set.
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+pub(crate) struct Subtree(u32);
+
+impl Subtree {
+ /// Returns the subtree at index `idx`.
+ const fn new(idx: u32) -> Self {
+ // INVARIANT: shifting `1` left leaves exactly one bit set.
+ Self(1 << idx)
+ }
+
+ /// Returns this subtree's index within the tree.
+ pub(super) const fn index(self) -> u32 {
+ self.0.trailing_zeros()
+ }
+
+ pub(super) const fn into_raw(self) -> u32 {
+ self.0
+ }
+}
+
+/// Set of subtrees, one bit per subtree, in the layout of the `TOP` registers.
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+pub(crate) struct SubtreeSet(u32);
+
+impl SubtreeSet {
+ pub(super) const fn contains(self, subtree: Subtree) -> bool {
+ self.0 & subtree.into_raw() != 0
+ }
+
+ pub(super) const fn is_empty(self) -> bool {
+ self.0 == 0
+ }
+
+ pub(super) const fn intersection(self, other: Self) -> Self {
+ Self(self.0 & other.0)
+ }
+
+ /// Returns one more than the highest index in this set, or `0` for an empty set. An MSI-X
+ /// allocation that covers the set needs this many entries.
+ pub(super) const fn span(self) -> u32 {
+ u32::BITS - self.0.leading_zeros()
+ }
+
+ /// Returns the subtrees of this set, lowest index first.
+ pub(super) fn iter(self) -> impl Iterator<Item = Subtree> {
+ (0..u32::BITS)
+ .map(Subtree::new)
+ .filter(move |subtree| self.contains(*subtree))
+ }
+}
+
+impl From<Subtree> for SubtreeSet {
+ fn from(subtree: Subtree) -> Self {
+ Self(subtree.into_raw())
+ }
+}
+
+impl From<Bounded<u32, 32>> for SubtreeSet {
+ fn from(subtrees: Bounded<u32, 32>) -> Self {
+ Self(subtrees.get())
+ }
+}
+
+impl From<SubtreeSet> for Bounded<u32, 32> {
+ fn from(subtrees: SubtreeSet) -> Self {
+ subtrees.0.into()
+ }
+}
+
+/// A GIN interrupt vector, bounded to the widest tree that any supported chipset implements.
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+pub(super) struct GinVector(Bounded<u32, VECTOR_BITS>);
+
+impl GinVector {
+ /// Returns vector number `VECTOR`.
+ ///
+ /// Fails to compile if `VECTOR` is beyond the widest supported tree.
+ pub(super) const fn new<const VECTOR: u32>() -> Self {
+ Self(Bounded::<u32, VECTOR_BITS>::new::<VECTOR>())
+ }
+
+ #[cfg_attr(not(CONFIG_NOVA_CORE_SELFTESTS), expect(dead_code))]
+ pub(super) const fn into_raw(self) -> u32 {
+ self.0.get()
+ }
+
+ /// Returns this vector's leaf.
+ pub(super) fn leaf_index(self) -> LeafIndex {
+ // CALC: `self.0 / VECTORS_PER_LEAF`.
+ self.0.shr::<{ VECTORS_PER_LEAF.ilog2() }, _>().cast()
+ }
+
+ /// Returns this vector's bit within its leaf.
+ pub(super) const fn leaf_mask(self) -> LeafMask {
+ LeafMask(1 << (self.0.get() % VECTORS_PER_LEAF))
+ }
+
+ /// Returns this vector's subtree.
+ pub(super) const fn subtree(self) -> Subtree {
+ Subtree::new(self.0.get() / (VECTORS_PER_LEAF * LEAVES_PER_SUBTREE))
+ }
+
+ /// Checks that a tree with `leaves` leaves implements this vector.
+ ///
+ /// # Errors
+ ///
+ /// `EINVAL` if it does not.
+ pub(super) const fn validate(self, leaves: LeafCount) -> Result {
+ if self.0.get() >= leaves.vector_count() {
+ Err(EINVAL)
+ } else {
+ Ok(())
+ }
+ }
+}
+
+impl From<GinVector> for Bounded<u32, TRIGGER_VECTOR_BITS> {
+ fn from(vector: GinVector) -> Self {
+ vector.0.extend()
+ }
+}
+
+/// Disables `vectors` in `leaf`.
+fn clear_leaf_enables(bar: Bar0<'_>, leaf: LeafIndex, vectors: LeafMask) {
+ bar.write(
+ Array::at(*leaf),
+ NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_EN_CLEAR::zeroed().with_vectors(vectors),
+ );
+}
+
+/// Disables the subtrees in `serviced` at `TOP`.
+fn clear_top_enables(bar: Bar0<'_>, serviced: SubtreeSet) {
+ bar.write_reg(NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_TOP_EN_CLEAR::zeroed().with_subtrees(serviced));
+}
+
+/// The CPU tree of one PCIe function, the subtrees that nova-core services, and the PCI vectors
+/// that deliver them.
+///
+/// A subtree may be enabled at `TOP` only once a handler is registered on the PCI vector that
+/// delivers it. See "The serviced-subtree invariant" in
+/// `Documentation/gpu/nova/core/interrupts.rst`.
+pub(crate) struct Tree<'a> {
+ bar: Bar0<'a>,
+ hal: &'static dyn CpuInterruptHal,
+ serviced: SubtreeSet,
+ /// The interrupt type that Linux granted for `vectors`.
+ pub(super) msi_type: MsiType,
+ vectors: pci::IrqVectorRegistration<'a>,
+}
+
+impl<'a> Tree<'a> {
+ /// Creates the tree of `chipset` and allocates the PCI vectors for the subtrees in `serviced`.
+ ///
+ /// Requests MSI-X entries `0` through the highest subtree in `serviced`, since an allocation
+ /// cannot be sparse, and falls back to a single MSI message for the whole tree.
+ ///
+ /// # Errors
+ ///
+ /// `EINVAL` if `serviced` is empty or names a subtree that `chipset` does not implement.
+ /// Otherwise, when neither interrupt type could be allocated, the error from the MSI request.
+ pub(crate) fn new(
+ pdev: &'a pci::Device<Bound>,
+ bar: Bar0<'a>,
+ chipset: Chipset,
+ serviced: SubtreeSet,
+ ) -> Result<Self> {
+ let hal = cpu_interrupt_hal(chipset);
+ let num_leaves = hal.leaf_count();
+
+ if serviced.is_empty() || serviced.intersection(num_leaves.subtree_set()) != serviced {
+ return Err(EINVAL);
+ }
+
+ let entries = serviced.span();
+ let (vectors, msi_type) = pdev
+ .alloc_irq_vectors(entries, entries, IrqType::MsiX.into())
+ .map(|vectors| (vectors, MsiType::MsiX))
+ // Every subtree raises the one MSI message, so one MSI vector serves the whole tree.
+ // See "Delivery over PCI" in `Documentation/gpu/nova/core/interrupts.rst`.
+ .or_else(|_| {
+ pdev.alloc_irq_vectors(1, 1, IrqType::Msi.into())
+ .map(|vectors| (vectors, MsiType::Msi))
+ })?;
+
+ Ok(Self {
+ bar,
+ hal,
+ serviced,
+ msi_type,
+ vectors,
+ })
+ }
+
+ /// Returns the [`irq::IrqRequest`] for the PCI vector that delivers `subtree`.
+ ///
+ /// # Errors
+ ///
+ /// `EINVAL` if `subtree` is not one of the serviced subtrees.
+ pub(super) fn request_for(&self, subtree: Subtree) -> Result<irq::IrqRequest<'_>> {
+ if !self.serviced.contains(subtree) {
+ return Err(EINVAL);
+ }
+
+ let entry = match self.msi_type {
+ MsiType::MsiX => num::u32_as_usize(subtree.index()),
+ MsiType::Msi => 0,
+ };
+
+ self.vectors.index(entry).map(Into::into)
+ }
+
+ /// Rearms PCI interrupt delivery to the CPU after servicing `subtree`, the one subtree that
+ /// the calling handler serves.
+ ///
+ /// A handler must call this before returning, or it receives no further interrupts.
+ pub(super) fn rearm_pci_irq(&self, subtree: Subtree) {
+ self.hal
+ .rearm_pci_irq(self.bar, self.msi_type, self.serviced, subtree);
+ }
+
+ /// Enables the serviced subtrees at `TOP`.
+ ///
+ /// Each of them must have a handler registered on its PCI vector.
+ pub(super) fn enable_top(&self) {
+ self.bar.write_reg(
+ NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_TOP_EN_SET::zeroed().with_subtrees(self.serviced),
+ );
+ }
+
+ /// Disables the serviced subtrees at `TOP`.
+ pub(super) fn disable_top(&self) {
+ clear_top_enables(self.bar, self.serviced);
+ }
+
+ /// Enables the serviced subtrees at `TOP` until the returned guard drops.
+ pub(crate) fn enable_top_guarded(&self) -> TopEnableGuard<'a> {
+ self.enable_top();
+
+ TopEnableGuard {
+ bar: self.bar,
+ serviced: self.serviced,
+ }
+ }
+
+ /// Enables `vectors` in `leaf`.
+ pub(super) fn enable_leaf(&self, leaf: LeafIndex, vectors: LeafMask) {
+ self.bar.write(
+ Array::at(*leaf),
+ NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_EN_SET::zeroed().with_vectors(vectors),
+ );
+ }
+
+ /// Disables `vectors` in `leaf`.
+ pub(super) fn disable_leaf(&self, leaf: LeafIndex, vectors: LeafMask) {
+ clear_leaf_enables(self.bar, leaf, vectors);
+ }
+
+ /// Enables `vectors` in `leaf` until the returned guard drops.
+ pub(super) fn enable_leaf_guarded(
+ &self,
+ leaf: LeafIndex,
+ vectors: LeafMask,
+ ) -> LeafEnableGuard<'a> {
+ self.enable_leaf(leaf, vectors);
+
+ LeafEnableGuard {
+ bar: self.bar,
+ leaf,
+ vectors,
+ }
+ }
+
+ /// Reads the pending bits of `leaf`, and returns the handle that clears them.
+ pub(super) fn read_pending(&self, leaf: LeafIndex) -> LeafPending<'a> {
+ let pending = self
+ .bar
+ .read(NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF::at(*leaf))
+ .vectors();
+
+ LeafPending {
+ bar: self.bar,
+ leaf,
+ pending,
+ }
+ }
+
+ /// Sets the pending bit of `vector` in its leaf, as if the vector's source had raised it.
+ ///
+ /// # Errors
+ ///
+ /// `EINVAL` if this tree does not implement `vector`.
+ #[cfg_attr(not(CONFIG_NOVA_CORE_SELFTESTS), expect(dead_code))]
+ pub(super) fn trigger(&self, vector: GinVector) -> Result {
+ vector.validate(self.hal.leaf_count())?;
+ self.bar.write_reg(
+ NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_TRIGGER::zeroed().with_vector(vector),
+ );
+
+ Ok(())
+ }
+
+ /// Disables every vector in every implemented leaf, including the subtrees that nova-core does
+ /// not service. Call this only during probe.
+ pub(super) fn disable_all_leaves(&self) {
+ for leaf in self.hal.leaf_count().iter() {
+ self.disable_leaf(leaf, LeafMask::all());
+ }
+ }
+
+ /// Clears every pending bit in every implemented leaf, including the subtrees that nova-core
+ /// does not service.
+ ///
+ /// The serviced subtrees are disabled at `TOP` on return. Call this only during probe, with no
+ /// interrupt handler registered.
+ pub(super) fn drain(&self) {
+ self.disable_top();
+
+ // A vector that latched while disabled does not show in `TOP`, so read every leaf rather
+ // than descending from it.
+ for leaf in self.hal.leaf_count().iter() {
+ self.read_pending(leaf).clear();
+ }
+ }
+
+ /// Disables every vector, clears every pending bit, and rearms PCI interrupt delivery.
+ ///
+ /// The serviced subtrees are disabled at `TOP` on return. Call this only during probe, with
+ /// no interrupt handler registered.
+ pub(super) fn reset(&self) {
+ self.disable_all_leaves();
+ self.drain();
+ for subtree in self.serviced.iter() {
+ self.rearm_pci_irq(subtree);
+ }
+
+ // A `TOP`-enable rearm leaves the subtrees that it cycles enabled, and a subtree may be
+ // enabled only once a handler is registered on its vector.
+ self.disable_top();
+ }
+}
+
+/// The pending bits of one leaf as they were read, and the handle that clears them.
+pub(super) struct LeafPending<'a> {
+ bar: Bar0<'a>,
+ leaf: LeafIndex,
+ pending: LeafMask,
+}
+
+impl LeafPending<'_> {
+ pub(super) fn vectors(&self) -> LeafMask {
+ self.pending
+ }
+
+ /// Clears the vectors that were pending at the read. A vector that latched since stays pending.
+ pub(super) fn clear(&self) {
+ self.clear_vectors(self.pending);
+ }
+
+ /// Clears `vectors` and no other bit.
+ pub(super) fn clear_vectors(&self, vectors: LeafMask) {
+ if !vectors.is_empty() {
+ self.bar.write(
+ Array::at(*self.leaf),
+ NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF::zeroed().with_vectors(vectors),
+ );
+ }
+ }
+}
+
+/// Disables a set of vectors in one leaf when dropped.
+pub(super) struct LeafEnableGuard<'a> {
+ bar: Bar0<'a>,
+ leaf: LeafIndex,
+ vectors: LeafMask,
+}
+
+impl Drop for LeafEnableGuard<'_> {
+ fn drop(&mut self) {
+ clear_leaf_enables(self.bar, self.leaf, self.vectors);
+ }
+}
+
+/// Disables the serviced subtrees at `TOP` when dropped.
+pub(crate) struct TopEnableGuard<'a> {
+ bar: Bar0<'a>,
+ serviced: SubtreeSet,
+}
+
+impl Drop for TopEnableGuard<'_> {
+ fn drop(&mut self) {
+ clear_top_enables(self.bar, self.serviced);
+ }
+}
+
+#[kunit_tests(nova_core_gin_tree)]
+mod tests {
+ use super::*;
+
+ /// A leaf index cannot name a leaf beyond the widest supported tree.
+ #[test]
+ fn leaf_index_bounds() {
+ assert!(LeafIndex::try_new(0).is_some());
+ assert!(LeafIndex::try_new(15).is_some());
+ assert!(LeafIndex::try_new(16).is_none());
+ }
+
+ /// The subtree count, the implemented-subtree set, and the vector count follow the leaf count.
+ #[test]
+ fn leaf_count_derives_subtrees_and_vectors() {
+ assert_eq!(LeafCount::Eight.subtree_count(), 4);
+ assert_eq!(
+ Bounded::<u32, 32>::from(LeafCount::Eight.subtree_set()).get(),
+ 0x0f
+ );
+ assert_eq!(LeafCount::Eight.vector_count(), 256);
+
+ assert_eq!(LeafCount::Sixteen.subtree_count(), 8);
+ assert_eq!(
+ Bounded::<u32, 32>::from(LeafCount::Sixteen.subtree_set()).get(),
+ 0xff
+ );
+ assert_eq!(LeafCount::Sixteen.vector_count(), 512);
+ }
+
+ /// A tree enumerates every leaf that it implements, in order, and no more.
+ #[test]
+ fn leaf_count_iter_covers_the_tree() {
+ for (count, expected) in [(LeafCount::Eight, 8usize), (LeafCount::Sixteen, 16)] {
+ let mut seen = 0;
+
+ for (index, leaf) in count.iter().enumerate() {
+ assert_eq!(leaf.get(), index);
+ seen += 1;
+ }
+
+ assert_eq!(seen, expected);
+ }
+ }
+
+ /// A vector maps to its leaf, its bit within that leaf, and its subtree. The doorbell (129)
+ /// and the GSP event (155) share a subtree.
+ #[test]
+ fn vector_maps_to_leaf_bit_and_subtree() {
+ let doorbell = GinVector::new::<129>();
+ let gsp = GinVector::new::<155>();
+
+ assert_eq!(doorbell.leaf_index().get(), 4);
+ assert_eq!(doorbell.leaf_mask().into_raw(), 1 << 1);
+ assert_eq!(doorbell.subtree().index(), 2);
+
+ assert_eq!(gsp.leaf_index().get(), 4);
+ assert_eq!(gsp.leaf_mask().into_raw(), 1 << 27);
+ assert_eq!(gsp.subtree().index(), 2);
+
+ assert_eq!(doorbell.subtree(), gsp.subtree());
+ }
+
+ /// Both fixed vectors are within the 8-leaf tree, so every supported chipset implements them.
+ #[test]
+ fn fixed_vectors_fit_the_narrowest_tree() {
+ assert!(GinVector::new::<129>().validate(LeafCount::Eight).is_ok());
+ assert!(GinVector::new::<155>().validate(LeafCount::Eight).is_ok());
+
+ // The first vector beyond an 8-leaf tree.
+ assert!(GinVector::new::<256>().validate(LeafCount::Eight).is_err());
+ assert!(GinVector::new::<256>().validate(LeafCount::Sixteen).is_ok());
+ }
+
+ /// A subtree set reports membership, intersection, and its span from subtree 0.
+ #[test]
+ fn subtree_set_operations() {
+ let gsp = GinVector::new::<155>().subtree();
+
+ assert!(LeafCount::Eight.subtree_set().contains(gsp));
+ assert!(!LeafCount::Eight.subtree_set().is_empty());
+
+ // The GSP needs no subtree above 2, so an MSI-X request covers entries 0 through 2.
+ assert_eq!(SubtreeSet::from(gsp).span(), 3);
+
+ // A 16-leaf tree implements every subtree that an 8-leaf tree does.
+ assert_eq!(
+ LeafCount::Sixteen
+ .subtree_set()
+ .intersection(LeafCount::Eight.subtree_set()),
+ LeafCount::Eight.subtree_set()
+ );
+ }
+
+ /// Iterating a subtree set yields each subtree once, lowest index first, and nothing for an
+ /// empty set.
+ #[test]
+ fn subtree_set_iterates_its_members() {
+ assert!(LeafCount::Eight
+ .subtree_set()
+ .iter()
+ .map(Subtree::index)
+ .eq([0u32, 1, 2, 3]));
+
+ let gsp = SubtreeSet::from(GinVector::new::<155>().subtree());
+ assert!(gsp.iter().map(Subtree::index).eq([2u32]));
+
+ let empty = SubtreeSet::from(Bounded::<u32, 32>::new::<0>());
+ assert_eq!(empty.iter().count(), 0);
+ }
+
+ /// Every supported chipset implements the subtree that carries the GSP event.
+ #[test]
+ fn gsp_subtree_is_implemented_everywhere() {
+ for &chipset in Chipset::ALL {
+ assert!(cpu_interrupt_hal(chipset)
+ .leaf_count()
+ .subtree_set()
+ .contains(crate::irq::gsp::GSP_SUBTREE));
+ }
+ }
+}
diff --git a/drivers/gpu/nova-core/irq/regs.rs b/drivers/gpu/nova-core/irq/regs.rs
new file mode 100644
index 000000000..4ddd01bcb
--- /dev/null
+++ b/drivers/gpu/nova-core/irq/regs.rs
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+use kernel::io::register;
+
+use crate::driver::NovaRegisters;
+
+use super::interrupt_tree::{
+ LeafMask,
+ SubtreeSet, //
+};
+
+// The GIN CPU interrupt tree, reached through the `NV_VIRTUAL_FUNCTION_PRIV` aperture. See
+// "Register naming" in `Documentation/gpu/nova/core/interrupts.rst`. The leaf arrays are declared
+// with 16 entries, the widest tree that any supported chipset implements.
+
+register! {
+ base: NovaRegisters;
+
+ /// Pending bits of one leaf, one per vector.
+ ///
+ /// Vector `v` is bit `v % 32` of leaf `v / 32`. The bit is set when the vector's source
+ /// drives it, whether or not the vector is enabled. Writing a `1` clears the bit, and a `0`
+ /// leaves it as it was.
+ pub(super) NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF(u32)[16] @ 0x00b81000 {
+ /// The vectors pending in this leaf.
+ 31:0 vectors => LeafMask;
+ }
+
+ /// Enables vectors of one leaf.
+ ///
+ /// A `1` enables the matching vector, and a `0` leaves it as it was.
+ pub(super) NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_EN_SET(u32)[16] @ 0x00b81200 {
+ /// Vectors to enable.
+ 31:0 vectors => LeafMask;
+ }
+
+ /// Disables vectors of one leaf.
+ ///
+ /// A `1` disables the matching vector, and a `0` leaves it as it was. A disabled vector still
+ /// latches in `LEAF`, and `TOP` does not show it.
+ pub(super) NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_EN_CLEAR(u32)[16] @ 0x00b81400 {
+ /// Vectors to disable.
+ 31:0 vectors => LeafMask;
+ }
+
+ /// Enables subtrees.
+ ///
+ /// Bit `N` covers subtree `N`, which is leaves `2N` and `2N + 1`. A `1` enables the matching
+ /// subtree, and a `0` leaves it as it was.
+ ///
+ /// The hardware headers declare a one-element array, so nova-core declares a scalar.
+ pub(super) NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_TOP_EN_SET(u32) @ 0x00b81608 {
+ /// Subtrees to enable.
+ 31:0 subtrees => SubtreeSet;
+ }
+
+ /// Disables subtrees, with the bit layout of `TOP_EN_SET`.
+ ///
+ /// A `1` disables the matching subtree, and a `0` leaves it as it was. A disabled subtree
+ /// delivers nothing, and `TOP` still reports it.
+ pub(super) NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_TOP_EN_CLEAR(u32) @ 0x00b81610 {
+ /// Subtrees to disable.
+ 31:0 subtrees => SubtreeSet;
+ }
+
+ /// Latches a vector from software. Write-only.
+ ///
+ /// The write sets the pending bit of the vector in its `LEAF` register, as if the vector's
+ /// source had raised it, and the vector reaches the CPU under the same enables. Implemented on
+ /// every supported chipset.
+ pub(super) NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_TRIGGER(u32) @ 0x00b81640 {
+ /// Vector to latch.
+ 11:0 vector;
+ }
+}
+
+// PCI configuration-space mirror in BAR0.
+
+register! {
+ base: NovaRegisters;
+
+ /// MSI end-of-interrupt register. Writing any value rearms MSI delivery.
+ ///
+ /// Only pre-Hopper MSI rearms through this register. See "Rearming PCI interrupt delivery"
+ /// in `Documentation/gpu/nova/core/interrupts.rst`.
+ pub(super) NV_XVE_CYA_2(u32) @ 0x00088704 {}
+}