Files
nvdriver/kernel-open/nvidia/platform_driver.h
BlivionIaG ddc733f814 kernel-open(gv11b): add opt-in firmware bundle loader, sysmem BAR2 bind, and platform IRQ handlers (#435)
* kernel-open(gv11b): add platform FW bundle loader, sysmem BAR2, IRQs, hwmon/BPMP and NETD netlist

- opt-in 10-blob GV11B firmware bundle load/validate/rollback through the
  nv_rs_gv11b_* validators, with each blob addressed by a named index
- sysmem BAR2 instance block (40-bit coherent DMA) and NV_PBUS_BAR2_BLOCK bind
- stall/nonstall platform IRQ handlers masking NV_PMC_INTR_EN_CLEAR_{0,1}
- hwmon telemetry, BPMP clock and the tegra_gv11b_bringup=0|1|2 level
- host fixture coverage for all of the above

The GR netlist is the silicon-signed gv11b/NETD_img.bin (NETA is the
simulation image). The firmware path list lives once in
NV_RS_GV11B_FW_FILES, feeding both MODULE_FIRMWARE and the
request_firmware table, with its count checked by _Static_assert. The Rust
Gv11bFwFile::NetlistA variant is renamed to Netlist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* nvidia: harden GV11B BAR2 bind/unbind and Volta PMC IRQ teardown

* nvidia: validate bringup level, filter shared IRQs, and retain unstopped BAR2 DMA

* nvidia: free retained BAR2 blocks only after a confirmed GPU stop

nv_rs_platform_quiesce() force-freed every retained BAR2 instance block
for the device whenever the current binding had not written BAR2. A
block retained by an earlier unbind that could not confirm suspension
may still be the GPU's BAR2 target, so a later probe failing before its
own BAR2 write freed memory the GPU could still DMA into.

Track whether reset_control_assert() succeeded or runtime PM reports
the device suspended, and reclaim retained blocks only when one of them
confirms the stop.

The platform host fixture now covers a reprobe failing at firmware
load after such a retained unbind: the block stays pinned without a
confirmed stop and is freed once runtime suspend or reset confirms it.

Verified: platform_driver.c C11 host compile with
-Werror=declaration-after-statement, platform host fixture PASS (the
new case fails against the previous quiesce logic), cargo fmt --check,
cargo clippy --workspace --all-targets -D warnings, cargo test -p
nv-rs-core --lib (1609 passed, 0 failed, 153 ignored).

* nvidia: confirm GV11B BAR2 left virtual mode before releasing DMA

nv_rs_platform_unbind_bar2() treated a clear BIND_STATUS as proof that BAR2
had left virtual mode and dropped DMA ownership without reading BAR2_BLOCK
back. NV_PBUS_BAR2_BLOCK_MODE (bit 31) is a read/write field, and the bind
path already checks its readback, so require the mode bit to read back
clear after the bind poll and return -EIO otherwise. bar2_hw_written then
stays set and the instance block stays pinned.

The discarded posting read after the mode write is dropped: the BIND_STATUS
poll and the new readback order the write.

Verified with the platform host fixture: a readback that keeps bit 31 set
makes unbind fail with -EIO and free_inst_block() keeps the page.

* nvidia: re-arm quarantined GV11B IRQ sources once they clear

The threaded PMC handler masks a source that is still asserted after the
top half (re-enabling a level source with no unit handler would storm),
but nothing ever re-armed it, so the source stayed masked for good even
after its status cleared.

Fold the quarantined bits into the next thread run on the same line:
sources whose NV_PMC_INTR status has cleared are re-enabled through
NV_PMC_INTR_EN_SET together with the newly handled ones; sources still
asserted stay quarantined. This matches nvgpu's GV11B pause/resume model
(EN_CLEAR in the top half, EN_SET after servicing) without claiming unit
servicing this driver does not have.

Verified with the platform host fixture: a quarantined nonstall source is
re-armed by the next event on its line once clear, while a source that
stays asserted is quarantined in turn.

* tests: require a runtime PM reference in the teardown MMIO guard

The platform fixture's teardown guard only checked pm_enabled, which stays
true after pm_runtime_put_sync() drops the usage count. Also require
pm_usage > 0 so a register read slipped in after the PM put fails the
fixture; the current unbind reads all run before the put.

Verified: platform host fixture passes.

* nvidia: keep retained GV11B BAR2 blocks owned until a confirmed stop

A BAR2 instance block whose unbind could not be confirmed is kept pinned
until runtime suspend or reset confirms the GPU stopped. Two paths still
lost the record needed to free it later:

- the fixed eight-entry retained table: once full, the block stayed in
  the platform object, which probe rollback or remove then freed;
- module unload: a block retained by an earlier unbind lived in a static
  table that went away with the module.

Allocate a retained record together with each instance block and link it
into a list on retention, so retention can no longer fail or overflow.
Each retained record holds a module reference (try_module_get), so the
module cannot be unloaded while a block awaits a confirmed stop; the
reference is dropped when the block is freed. Module exit cannot be
refused, so a block first retained during the final unregister without a
confirmed stop stays pinned with its device reference and only the record
is dropped; it is never freed while DMA may still target it.

Verified with the platform host fixture: ten failed unbinds without a
confirmed stop keep ten records, device and module references, and one
failing reprobe with a confirmed suspend frees all of them; a block
retained while the module exits stays pinned after unregister.

* nvidia: publish accepted RM power limits to hwmon

A successful NV2080_CTRL_CMD_PMGR_PWR_POLICY_IDX_LIMIT_ARB_INPUT_SET
updated the RM node's power cap but not hwmon's power1_cap. GPUs with a
live telemetry poll caught up on the next poll; the GV11B platform GPU has
none, so power1_cap kept reporting the 15 W probe default.

Publish the accepted limit through nv_rs_hwmon_set_limits() from the same
update path (temperature limits untouched). A reset request stores the
architecture default, so hwmon returns to 15 W on GV11B.

Verified: kernel crate builds with rustc -D warnings against nv-rs-core.

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-05 23:24:16 -08:00

99 lines
4.0 KiB
C

/* SPDX-License-Identifier: MIT */
#ifndef NV_RS_PLATFORM_DRIVER_H
#define NV_RS_PLATFORM_DRIVER_H
#ifndef NV_RS_PLATFORM_HOST_FIXTURE
#include <linux/types.h>
#else
#include <stdbool.h>
#include <stdint.h>
#endif
#define NV_RS_GV11B_BOOT42_CHIP_MASK 0x3ffU
#define NV_RS_GV11B_BOOT42_CHIP_ID 0x15bU
/* Synthetic BDF 0xffff:00:00.0 for a single integrated GV11B SoC platform GPU;
* SoCs using this path are not expected to host a real PCI domain 0xffff. */
#define NV_RS_PLAT_DOMAIN 0xffffU
#define NV_RS_PLAT_BUS 0U
#define NV_RS_PLAT_SLOT 0U
#define NV_RS_PLAT_FUNC 0U
#define NV_RS_PLAT_GPU_ID (((NV_RS_PLAT_DOMAIN) << 16) | ((NV_RS_PLAT_BUS) << 8) | (NV_RS_PLAT_SLOT))
#define NV_RS_GV11B_PCI_VENDOR 0x10deU
#define NV_RS_GV11B_PCI_DEVICE 0x015bU
#define NV_RS_PMC_INTR_0_OFF 0x100U
#define NV_RS_PMC_INTR_1_OFF 0x104U
#define NV_RS_PMC_INTR_EN_0_OFF 0x140U
#define NV_RS_PMC_INTR_EN_1_OFF 0x144U
#define NV_RS_PMC_INTR_EN_SET_0 0x160U
#define NV_RS_PMC_INTR_EN_SET_1 0x164U
#define NV_RS_PMC_INTR_EN_CLEAR_0 0x180U
#define NV_RS_PMC_INTR_EN_CLEAR_1 0x184U
#define NV_RS_PMC_INTR_EN_CLEAR_ALL 0xffffffffU
#define NV_RS_PBUS_BIND_STATUS_OFF 0x1710U
#define NV_RS_PBUS_BIND_STATUS_BAR2_MASK 0xcU
#define NV_RS_PBUS_BAR2_BLOCK_OFF 0x1714U
#define NV_RS_PBUS_BAR2_BLOCK_MODE_BIT 0x80000000U
#define NV_RS_GV11B_INST_BLOCK_BYTES 4096U
#define NV_RS_GV11B_FW_COUNT 10U
/*
* GV11B firmware bundle in load order; must match nv_rs_core::gpu::gv11b_fw::Gv11bFwFile.
* The GR netlist is the silicon-signed NETD image (NETA is the simulation netlist).
*/
#define NV_RS_GV11B_FW_FILES(X) \
X("gv11b/acr_ucode_prod.bin") \
X("gv11b/pmu_bl.bin") \
X("gv11b/pmu_sig.bin") \
X("gv11b/gpmu_ucode_desc.bin") \
X("gv11b/gpmu_ucode_image.bin") \
X("gv11b/fecs.bin") \
X("gv11b/fecs_sig.bin") \
X("gv11b/gpccs.bin") \
X("gv11b/gpccs_sig.bin") \
X("gv11b/NETD_img.bin")
/* Index of each NV_RS_GV11B_FW_FILES entry. */
enum nv_rs_gv11b_fw_idx {
NV_RS_GV11B_FW_ACR,
NV_RS_GV11B_FW_PMU_BL,
NV_RS_GV11B_FW_PMU_SIG,
NV_RS_GV11B_FW_PMU_DESC,
NV_RS_GV11B_FW_PMU_IMAGE,
NV_RS_GV11B_FW_FECS,
NV_RS_GV11B_FW_FECS_SIG,
NV_RS_GV11B_FW_GPCCS,
NV_RS_GV11B_FW_GPCCS_SIG,
NV_RS_GV11B_FW_NETLIST,
};
_Static_assert(NV_RS_GV11B_FW_NETLIST + 1 == NV_RS_GV11B_FW_COUNT,
"nv_rs_gv11b_fw_idx must cover NV_RS_GV11B_FW_FILES");
struct nv_rs_platform_gpu;
int nv_rs_platform_driver_register(void);
void nv_rs_platform_driver_unregister(void);
static inline bool nv_rs_platform_is_gv11b(u32 boot42)
{
return ((boot42 >> 20) & NV_RS_GV11B_BOOT42_CHIP_MASK) == NV_RS_GV11B_BOOT42_CHIP_ID;
}
bool nv_rs_platform_is_removed(struct nv_rs_platform_gpu *g);
int nv_rs_platform_read32(struct nv_rs_platform_gpu *g, u64 offset, u32 *value);
int nv_rs_platform_write32(struct nv_rs_platform_gpu *g, u64 offset, u32 value);
int nv_rs_platform_bar0_info(struct nv_rs_platform_gpu *g, u64 *physical, u64 *bytes);
u32 nv_rs_platform_boot0(const struct nv_rs_platform_gpu *g);
u32 nv_rs_platform_boot42(const struct nv_rs_platform_gpu *g);
int nv_rs_platform_irq_stall(const struct nv_rs_platform_gpu *g);
int nv_rs_platform_irq_nonstall(const struct nv_rs_platform_gpu *g);
unsigned int nv_rs_platform_dma_bits(const struct nv_rs_platform_gpu *g);
int nv_rs_platform_load_gv11b_fw(struct nv_rs_platform_gpu *g);
void nv_rs_platform_release_gv11b_fw(struct nv_rs_platform_gpu *g);
int nv_rs_platform_alloc_inst_block(struct nv_rs_platform_gpu *g, u64 *dma_out, u32 *bar2_reg_out);
void nv_rs_platform_free_inst_block(struct nv_rs_platform_gpu *g);
int nv_rs_platform_bind_bar2(struct nv_rs_platform_gpu *g);
int nv_rs_platform_irq_register(struct nv_rs_platform_gpu *g);
void nv_rs_platform_irq_unregister(struct nv_rs_platform_gpu *g);
unsigned long nv_rs_platform_irq_count(const struct nv_rs_platform_gpu *g);
#endif