gsp: proactive multi-gen Turing-Blackwell parity (Wave 7C)

This commit is contained in:
Eric Hartford
2026-12-02 01:55:50 +00:00
parent 0658135d16
commit cbaa0fe20f
6 changed files with 388 additions and 109 deletions

View File

@ -101,10 +101,14 @@ struct nv_rs_ga10x_pci_info {
u64 bar_len[6];
u32 io_bars;
u16 vendor, device, subsystem_vendor, subsystem_device;
u8 revision, pad[3];
u8 revision, flr_supported, bar0_64b, behind_bridge;
u32 dev_id;
u64 max_user_va;
u64 page_size;
u32 domain;
u32 link_cap;
u8 is_passthru;
u8 pad2[7];
};
int nv_rs_ga10x_pci_info(struct nv_rs_pci *pci, struct nv_rs_ga10x_pci_info *out);
@ -112,6 +116,7 @@ int nv_rs_ga10x_pci_info(struct nv_rs_pci *pci, struct nv_rs_ga10x_pci_info *out
{
struct pci_dev *pdev = pci ? nv_rs_pci_pdev(pci) : NULL;
u16 cmd = 0;
u32 devcap = 0;
int i;
if (!pdev || !out)
@ -129,9 +134,18 @@ int nv_rs_ga10x_pci_info(struct nv_rs_pci *pci, struct nv_rs_ga10x_pci_info *out
out->subsystem_vendor = pdev->subsystem_vendor;
out->subsystem_device = pdev->subsystem_device;
out->revision = pdev->revision;
if (pcie_capability_read_dword(pdev, PCI_EXP_DEVCAP, &devcap) == 0)
out->flr_supported = (devcap & PCI_EXP_DEVCAP_FLR) ? 1u : 0u;
out->bar0_64b = (pci_resource_flags(pdev, 0) & IORESOURCE_MEM_64) ? 1u : 0u;
out->behind_bridge = (pdev->bus && pdev->bus->self) ? 1u : 0u;
out->dev_id = pci_dev_id(pdev);
out->max_user_va = TASK_SIZE;
out->page_size = PAGE_SIZE;
out->domain = (u32)pci_domain_nr(pdev->bus);
pcie_capability_read_dword(pdev, PCI_EXP_LNKCAP, &out->link_cap);
#ifdef CONFIG_X86
out->is_passthru = boot_cpu_has(X86_FEATURE_HYPERVISOR) ? 1u : 0u;
#endif
return 0;
}

View File

@ -86,6 +86,54 @@ pub(crate) struct Ga10xGpu {
const SCRATCH_BYTES: usize = fw::MAX_ELEMENT_BYTES;
impl Ga10xGpu {
pub fn boot_id(&self) -> nv_rs_core::gpu::chip_arch::BootId {
if self.gsp.is_null() {
return nv_rs_core::gpu::chip_arch::BootId::from_pmc_boot(0, 0);
}
unsafe { (*self.gsp).boot_id }
}
/// Exact per-GPU `(main, pm, patch)` GR context buffer sizes queried from GSP-RM via
/// `NV2080_CTRL_CMD_INTERNAL_STATIC_KGR_GET_CONTEXT_BUFFERS_INFO` (`0x20800a32`), falling back
/// to architecture defaults only when a slot is 0.
pub fn ctx_sizes(&self) -> [u64; 3] {
let fallback = self
.boot_id()
.arch_family()
.map(crate::ga10x_objects::ctx_sizes_for_family)
.unwrap_or([0x19_6000, 0x1_1b00, 0x5000]);
let pick = |queried: u32, fb: u64| {
if queried != 0 {
u64::from(queried)
} else {
fb
}
};
[
pick(self.gr_size[0], fallback[0]),
pick(self.gr_size[9], fallback[1]),
pick(self.gr_size[0x10], fallback[2]),
]
}
/// Returns `(gpfifo_channel_class, gr_3d_class)` for golden context capture across all GSP-RM
/// generations (Turing through Blackwell/Rubin).
pub fn golden_classes(&self) -> (u32, u32) {
use nv_rs_core::gpu::chip_arch::ArchFamily;
let Some(profile) = self.boot_id().profile() else {
return (0xc56f, 0xc797);
};
match profile.family {
ArchFamily::Turing => (0xc46f, 0xc597),
ArchFamily::Ampere if profile.boot42_impl == 0x0 => (0xc56f, 0xc697),
ArchFamily::Ampere => (0xc56f, 0xc797),
ArchFamily::Ada => (0xc56f, 0xc997),
ArchFamily::Hopper => (0xc86f, 0xcb97),
ArchFamily::Blackwell1 | ArchFamily::Blackwell2 | ArchFamily::Rubin => (0xc96f, 0xcd97),
_ => (0xc56f, 0xc797),
}
}
fn scratch(&mut self, len: usize) -> Result<&mut [u8], i32> {
if len > SCRATCH_BYTES {
return Err(EINVAL);

View File

@ -88,7 +88,6 @@ const GSP: u32 = 0x11_0000;
const SEC2: u32 = 0x84_0000;
/// falcon2 / RISC-V registers: falcon base + 0x1000.
const RV: u32 = 0x1000;
const GSP_RM_FIRMWARE: &[u8] = b"nvidia/580.178.04/gsp_ga10x.bin\0";
const GSP_RM_VERSION: &str = "580.178.04";
const QUEUE_BYTES: u64 = 0x4_0000;
const IMAGE_RUN: u64 = 0x20_0000;
@ -117,10 +116,16 @@ pub(crate) struct PciInfo {
pub subsystem_vendor: u16,
pub subsystem_device: u16,
pub revision: u8,
pub pad: [u8; 3],
pub flr_supported: u8,
pub bar0_64b: u8,
pub behind_bridge: u8,
pub dev_id: u32,
pub max_user_va: u64,
pub page_size: u64,
pub domain: u32,
pub link_cap: u32,
pub is_passthru: u8,
pub pad2: [u8; 7],
}
// ---- logging: a static message and up to four values ----
@ -408,10 +413,11 @@ pub(crate) struct Ga10xGsp {
stale: [(u32, u32); 8],
stale_next: usize,
pub running: bool,
pub in_lockdown: bool,
pub last_os_error: u32,
seq_mismatch: u32,
boot_id: nv_rs_core::gpu::chip_arch::BootId,
fw_family: nv_rs_core::gpu::gsp_boot::GspFirmwareChipFamily,
pub boot_id: nv_rs_core::gpu::chip_arch::BootId,
pub fw_family: nv_rs_core::gpu::gsp_boot::GspFirmwareChipFamily,
}
impl Ga10xGsp {
@ -902,11 +908,13 @@ impl Ga10xGsp {
let (data, size, handle) = self.request_fw_path(path)?;
let bytes = unsafe { core::slice::from_raw_parts(data, size) };
let res = (|| {
self.boot.alloc_into(&mut self.dma, bytes.len() as u64)?;
self.boot.write(&mut self.dma, 0, bytes)?;
self.boot_code = 0;
self.boot_data = 0;
self.boot_manifest = 0;
let (img, code_off, data_off, manifest_off) =
fw::parse_riscv_bootloader(bytes).map_err(fw_errno)?;
self.boot.alloc_into(&mut self.dma, img.len() as u64)?;
self.boot.write(&mut self.dma, 0, img)?;
self.boot_code = code_off;
self.boot_data = data_off;
self.boot_manifest = manifest_off;
Ok(())
})();
unsafe { nv_rs_firmware_release(handle) };
@ -914,46 +922,28 @@ impl Ga10xGsp {
}
#[inline(never)]
fn gsprm_load(&mut self) -> Result<(), i32> {
use nv_rs_core::gpu::gsp_image;
let abi = crate::gsp_bringup::gsp_abi();
let mut last_rc = EOPNOTSUPP;
for release in gsp_image::releases_for_abi(abi) {
let Some(name) = gsp_image::firmware_filename_cstr_for_release(self.fw_family, *release)
else {
continue;
};
let (mut data, mut size, mut handle) = (ptr::null(), 0usize, ptr::null_mut());
let rc = unsafe {
nv_rs_firmware_request(self.pci, name.as_ptr(), &mut data, &mut size, &mut handle)
};
if rc != 0 || data.is_null() {
if !handle.is_null() {
unsafe { nv_rs_firmware_release(handle) };
}
last_rc = if rc != 0 { rc } else { EIO };
continue;
}
let r = self.gsprm_copy(unsafe { core::slice::from_raw_parts(data, size) });
unsafe { nv_rs_firmware_release(handle) };
return r;
}
// Fallback to default 580.178.04 filename if ABI-specific list missed.
use nv_rs_core::gpu::gsp_image::{self, GspFwRelease};
// `ga10x_gsp.rs` speaks the 580.178.04 XOR-framed RPC protocol (`GspSystemInfo` 0x3a8,
// `GspStaticConfigInfo` 0x700), so request the 580.178.04 firmware matching `self.fw_family`
// directly (never cross-loading `gsp_ga10x.bin` on Turing/GA100/Hopper/Blackwell or R620).
let Some(name) = gsp_image::firmware_filename_cstr_for_release(
self.fw_family,
GspFwRelease::V580_178_04,
) else {
self.error(b"gsp firmware: no 580.178.04 image for family\0", 0, 0, 0, 0);
return Err(EOPNOTSUPP);
};
let (mut data, mut size, mut handle) = (ptr::null(), 0usize, ptr::null_mut());
let rc = unsafe {
nv_rs_firmware_request(
self.pci,
GSP_RM_FIRMWARE.as_ptr(),
&mut data,
&mut size,
&mut handle,
)
nv_rs_firmware_request(self.pci, name.as_ptr(), &mut data, &mut size, &mut handle)
};
if rc != 0 || data.is_null() {
self.error(b"gsp firmware: request_firmware\0", last_rc as u64, 0, 0, 0);
let err = if rc != 0 { rc } else { EIO };
self.error(b"gsp firmware: request_firmware\0", err as u64, 0, 0, 0);
if !handle.is_null() {
unsafe { nv_rs_firmware_release(handle) };
}
return Err(last_rc);
return Err(err);
}
let r = self.gsprm_copy(unsafe { core::slice::from_raw_parts(data, size) });
unsafe { nv_rs_firmware_release(handle) };
@ -962,19 +952,13 @@ impl Ga10xGsp {
#[inline(never)]
fn gsprm_copy(&mut self, file: &[u8]) -> Result<(), i32> {
let elf = GspFirmware::parse(file).map_err(|_| EINVAL)?;
if !elf.validate_version(GSP_RM_VERSION)
&& !elf.validate_version("620.70.06")
&& !elf.validate_version("620.73.04")
{
self.error(b"gsp firmware: unsupported .fwversion\0", 0, 0, 0, 0);
if !elf.validate_version(GSP_RM_VERSION) {
self.error(b"gsp firmware: unsupported .fwversion (want 580.178.04)\0", 0, 0, 0, 0);
return Err(EINVAL);
}
let image = elf.fwimage().ok_or(EINVAL)?;
let profile = self.boot_id.profile();
let sig = profile
.and_then(|p| elf.signature_for(&p, false))
.or_else(|| elf.section(".fwsignature_ga10x"))
.ok_or(EINVAL)?;
let profile = self.boot_id.profile().ok_or(EOPNOTSUPP)?;
let sig = elf.signature_for(&profile, false).ok_or(EINVAL)?;
let r3 = fw::Radix3::new(image.len() as u64).map_err(fw_errno)?;
let runs = (image.len() as u64).div_ceil(IMAGE_RUN) as usize;
if runs > MAX_IMAGE_RUNS {
@ -1368,8 +1352,19 @@ impl Ga10xGsp {
function::EVENT_MMU_FAULT_QUEUED => {
self.error(b"GSP-RM: MMU fault queued\0", 0, 0, 0, 0)
}
function::EVENT_GSP_LOCKDOWN_NOTICE => {
if n >= 4 {
self.in_lockdown = fw::rd32(p, 0).unwrap_or(0) != 0;
self.note(
b"GSP-RM: lockdown notice (lockdown)\0",
u64::from(self.in_lockdown),
0,
0,
0,
);
}
}
function::EVENT_GSP_POST_NOCAT_RECORD
| function::EVENT_GSP_LOCKDOWN_NOTICE
| function::EVENT_UCODE_LIBOS_PRINT
| function::EVENT_PERF_BRIDGELESS_INFO_UPDATE
| function::EVENT_POST_EVENT
@ -1564,7 +1559,11 @@ impl Ga10xGsp {
// ---- boot ----
#[inline(never)]
fn fwsec_frts(&mut self) -> Result<(), i32> {
if self.rd(0x1f_a828) != 0 {
if self.fw_family == nv_rs_core::gpu::gsp_boot::GspFirmwareChipFamily::Ga100 {
// `_nv041327rm`: GA100 has no VBIOS FRTS carveout (`frts_size == 0`).
return Ok(());
}
if (self.rd(0x1f_a828) >> 4) != 0 {
self.error(
b"WPR2 already up: not running FWSEC-FRTS (lo, hi)\0",
u64::from(self.rd(0x1f_a824)),
@ -1661,7 +1660,9 @@ impl Ga10xGsp {
.map(|bytes| (bytes >> 20) as u32)
.unwrap_or(0)
};
self.layout = fw::fb_layout(fb_mb, self.rd(0x62_5f04)).map_err(|e| {
let has_frts =
!self.is_fmc_boot() && self.fw_family != GspFirmwareChipFamily::Ga100;
self.layout = fw::fb_layout_for_family(fb_mb, self.rd(0x62_5f04), has_frts).map_err(|e| {
self.error(
b"usable FB size register\0",
u64::from(fb_mb),
@ -1686,6 +1687,10 @@ impl Ga10xGsp {
if unsafe { nv_rs_ga10x_pci_info(self.pci, &mut info) } != 0 {
return Err(ENODEV);
}
let (mirror_base, mirror_size) = fw::pci_config_mirror_for_family(self.fw_family);
let bdf = (u64::from(info.domain) << 32)
| u64::from(info.dev_id & 0xff00)
| u64::from((info.dev_id >> 3) & 0x1f);
let s = fw::SystemInfo {
bar0: info.bar[0],
bar1: info.bar[1],
@ -1695,13 +1700,20 @@ impl Ga10xGsp {
} else {
0
},
bdf: u64::from(info.dev_id),
bdf,
max_user_va: info.max_user_va,
pci_config_mirror_base: mirror_base,
pci_config_mirror_size: mirror_size,
vendor: info.vendor,
device: info.device,
subsystem_vendor: info.subsystem_vendor,
subsystem_device: info.subsystem_device,
revision: info.revision,
behind_bridge: info.behind_bridge != 0,
flr_supported: info.flr_supported != 0,
bar0_64b: info.bar0_64b != 0,
is_passthru: info.is_passthru != 0,
link_cap: info.link_cap,
host_page_size: info.page_size,
};
let mut b = Bytes::zeroed(fw::SYSTEM_INFO_BYTES)?;
@ -1777,14 +1789,16 @@ impl Ga10xGsp {
let run_res = self.run(3, SEC2, 0, None);
self.frts.buf.free(&mut self.dma);
let (m0, m1) = run_res?;
let scratch15 = self.rd(0x11_80fc);
self.note(
b"ad10x scrubber done (mbox0, mbox1, scratch15)\0",
u64::from(m0),
u64::from(m1),
u64::from(self.rd(0x11_80fc)),
u64::from(scratch15),
0,
);
if m0 != 0 {
// Match `_nv041258rm` (`kgspExecuteScrubberIfNeeded_AD102`): verify post-scrub `scratch15 > 0x5fff_ffff`.
if m0 != 0 || scratch15 <= 0x5fff_ffff {
return Err(EIO);
}
Ok(())
@ -1815,19 +1829,61 @@ impl Ga10xGsp {
u64::from(self.boot_data),
u64::from(self.boot_manifest),
);
let layout = &self.layout;
layout.fill_wpr_meta(
&mut self.wpr,
radix3,
image_len,
boot,
boot_len,
code,
data,
manifest,
sig,
sig_len,
);
if self.is_fmc_boot() {
use nv_rs_core::gpu::gsp_boot::{
calculate_wpr_heap_size, init_wpr_meta_gb10b, init_wpr_meta_gh100,
wpr_params_for_profile, Gh100WprInputs,
};
let profile = self.boot_id.profile().ok_or(EOPNOTSUPP)?;
let wp = wpr_params_for_profile(&profile, false);
let heap_size = calculate_wpr_heap_size(
self.layout.fb_size,
0,
wp.heap_min_mb,
wp.heap_max_mb,
wp.heap_max_mb,
wp.heap_extra_bytes,
0,
);
let inp = Gh100WprInputs {
pmu_reserved_size: wp.pmu_reserved_size as u32,
sysmem_addr_of_radix3_elf: radix3,
size_of_radix3_elf: image_len,
sysmem_addr_of_bootloader: boot,
size_of_bootloader: boot_len,
bootloader_code_offset: code,
bootloader_data_offset: data,
bootloader_manifest_offset: manifest,
sysmem_addr_of_signature: sig,
size_of_signature: sig_len,
non_wpr_heap_size: wp.non_wpr_heap_size,
gsp_fw_heap_size: heap_size,
frts_size: wp.frts_size,
vf_partition_count: 0,
sysmem_addr_of_crash_report: 0,
size_of_crash_report: 0,
sriov_enabled: false,
};
self.wpr = if profile.boot42_impl == 0xb {
init_wpr_meta_gb10b(&inp)
} else {
init_wpr_meta_gh100(&inp)
};
} else {
let layout = &self.layout;
layout.fill_wpr_meta(
&mut self.wpr,
radix3,
image_len,
boot,
boot_len,
code,
data,
manifest,
sig,
sig_len,
);
}
let elem = unsafe { core::slice::from_raw_parts_mut(self.elem, fw::MAX_ELEMENT_BYTES) };
let bytes = &mut elem[..256];
fw::zero(bytes);
@ -1989,7 +2045,7 @@ impl Ga10xGsp {
}
self.running = false;
}
if !self.is_fmc_boot() && self.rd(0x1f_a828) != 0 && self.booter_unload.buf.live {
if !self.is_fmc_boot() && (self.rd(0x1f_a828) >> 4) != 0 && self.booter_unload.buf.live {
let _ = self.flcn_reset(GSP);
if self.fwsec_sb.buf.live {
let r = self.run(2, GSP, 0, None);
@ -2011,6 +2067,10 @@ impl Ga10xGsp {
);
}
if self.is_fmc_boot() {
// Wait for GSP RISC-V core to halt/idle after UNLOADING_GUEST_DRIVER before resetting falcon.
let _ = poll_sleep(500_000, || {
self.frd(GSP, RV + 0x388) & 0x80 == 0 || self.frd(GSP, 0x040) == 0x8000_0000
});
let mut io = PciRegIo(self.pci);
return nv_rs_core::gpu::gsp_boot::reset_gsp_falcon_gh100(&mut io).is_ok();
}

View File

@ -80,6 +80,7 @@ struct Tsg {
mthd: [u64; 2],
ctx_promoted: bool,
ctx: [u64; 3],
ctx_size: [u64; 3],
/// The 64 subcontext ids in use.
subctx: u64,
}
@ -366,13 +367,17 @@ fn tsg_release(g: &mut Ga10xGpu, i: usize) {
}
if t.ctx_promoted {
for k in 0..3 {
g.mem.free(t.ctx[k], CTX_SIZE[k]);
if t.ctx[k] != 0 && t.ctx_size[k] != 0 {
g.mem.free(t.ctx[k], t.ctx_size[k]);
}
}
}
let t = &mut g.objs.tsg[i];
t.handle = 0;
t.client = 0;
t.ctx_promoted = false;
t.ctx = [0; 3];
t.ctx_size = [0; 3];
t.subctx = 0;
t.mthd = [0; 2];
}
@ -548,6 +553,7 @@ pub(crate) fn channel_alloc(
client: u32,
parent: u32,
object: u32,
class: u32,
user: &mut [u8],
userd_pa: u64,
err_pa: u64,
@ -594,7 +600,7 @@ pub(crate) fn channel_alloc(
let notifier = if err_pa != 0 { 3u32 } else { 1 };
fw::wr32(p, 0xf4, u32::from(admin) | notifier << 2 | 1 << 4).map_err(e)?;
fw::wr32(p, 0x128, unsafe { nv_rs_os_tgid() }).map_err(e)?;
let st = match g.rm_alloc(client, parent, object, 0xc56f, p) {
let st = match g.rm_alloc(client, parent, object, class, p) {
Ok(st) => st,
Err(err) => {
g.mem.free(inst, 0x1000);
@ -644,6 +650,7 @@ const GOLD_GR: u32 = 0xbaba_0046;
pub(crate) struct GoldenTemps {
held: bool,
vid: [u64; 4],
vid_size: [u64; 4],
mthd: u64,
mthd_size: u64,
}
@ -683,8 +690,9 @@ fn golden(g: &mut Ga10xGpu) -> Result<(), i32> {
if g.golden_done {
return Ok(());
}
let main = g.mem.alloc(CTX_SIZE[0], 0x1000);
let patch = g.mem.alloc(CTX_SIZE[2], 0x1000);
let ctx = g.ctx_sizes();
let main = g.mem.alloc(ctx[0], 0x1000);
let patch = g.mem.alloc(ctx[2], 0x1000);
let inst = g.mem.alloc(0x1000, 0x1000);
let userd = g.mem.alloc(0x1000, 0x1000);
let chid = g.objs.free_chid(1).filter(|&c| c < CHID_MIN);
@ -705,6 +713,7 @@ fn golden(g: &mut Ga10xGpu) -> Result<(), i32> {
g,
main,
patch,
ctx,
inst,
userd,
chid as u32,
@ -733,6 +742,7 @@ fn golden(g: &mut Ga10xGpu) -> Result<(), i32> {
inst.unwrap_or(0),
userd.unwrap_or(0),
],
vid_size: [ctx[0], ctx[2], 0x1000, 0x1000],
mthd: mthd.unwrap_or(0),
mthd_size: size,
};
@ -770,12 +780,8 @@ fn golden_release(g: &mut Ga10xGpu, t: GoldenTemps) {
{
vas_release(g, i);
}
for (pa, sz) in t
.vid
.into_iter()
.zip([CTX_SIZE[0], CTX_SIZE[2], 0x1000, 0x1000])
{
if pa != 0 {
for (pa, sz) in t.vid.into_iter().zip(t.vid_size) {
if pa != 0 && sz != 0 {
g.mem.free(pa, sz);
}
}
@ -790,6 +796,7 @@ fn golden_run(
g: &mut Ga10xGpu,
main: u64,
patch: u64,
ctx: [u64; 3],
inst: u64,
userd: u64,
chid: u32,
@ -797,6 +804,7 @@ fn golden_run(
mthd_size: u64,
client: &mut bool,
) -> Result<(), i32> {
let (chan_class, gr_class) = g.golden_classes();
// VAs as NVIDIA's kernel side used: main, patch, bundle CB, pagepool, attribute CB, RTV, FECS event, priv access
// map (not mapped), unrestricted priv access map
const GID: [u16; 9] = [0, 2, 3, 4, 5, 6, 9, 10, 11];
@ -851,8 +859,8 @@ fn golden_run(
continue;
}
let (pa, sz, sys) = match GID[i] {
0 => (main, CTX_SIZE[0], false),
2 => (patch, CTX_SIZE[2], false),
0 => (main, ctx[0], false),
2 => (patch, ctx[2], false),
id => (
g.gr_global_pa[id as usize],
g.gr_global_size[id as usize],
@ -887,7 +895,7 @@ fn golden_run(
fw::wr32(p, 0xf0, GOLD_GROUP).map_err(e)?;
fw::wr32(p, 0xf4, 0x16).map_err(e)?; // PRIVILEGE KERNEL, notifiers NONE
fw::wr32(p, 0x128, unsafe { nv_rs_os_tgid() }).map_err(e)?;
let st = g.rm_alloc(GOLD_CLIENT, GOLD_DEVICE, GOLD_CHAN, 0xc56f, p)?;
let st = g.rm_alloc(GOLD_CLIENT, GOLD_DEVICE, GOLD_CHAN, chan_class, p)?;
ga10x_gsp::note(
g.pci,
b"golden: channel (chid, instance, root, status)\0",
@ -912,8 +920,8 @@ fn golden_run(
for i in 0..9 {
let id = GID[i];
let (pa, sz) = match id {
0 => (main, CTX_SIZE[0]),
2 => (patch, CTX_SIZE[2]),
0 => (main, ctx[0]),
2 => (patch, ctx[2]),
id => (g.gr_global_pa[id as usize], g.gr_global_size[id as usize]),
};
if pa == 0 {
@ -946,17 +954,17 @@ fn golden_run(
}
}
// the 3D object: GSP-RM captures the golden context
let st = g.rm_alloc(GOLD_CLIENT, GOLD_CHAN, GOLD_GR, 0xc797, &mut [])?;
let st = g.rm_alloc(GOLD_CLIENT, GOLD_CHAN, GOLD_GR, gr_class, &mut [])?;
ga10x_gsp::note(
g.pci,
b"golden: AMPERE_B (status)\0",
b"golden: 3D class (class, status)\0",
u64::from(gr_class),
u64::from(st),
0,
0,
0,
);
if st != 0 {
return fail(g, b"golden: AMPERE_B (status)\0", st);
return fail(g, b"golden: 3D class (status)\0", st);
}
g.golden_done = true;
g.gr_global_init = true;
@ -1018,10 +1026,11 @@ pub(crate) fn gr_object_alloc(
n += 1;
}
}
let ctx = g.ctx_sizes();
fw::wr32(p, 0x28, n as u32).map_err(e)?;
for k in 0..3 {
let o = 0x30 + 0x20 * k;
fw::wr64(p, o + 0x10, CTX_SIZE[k]).map_err(e)?;
fw::wr64(p, o + 0x10, ctx[k]).map_err(e)?;
fw::wr32(p, o + 0x18, 4).map_err(e)?; // physAttr as NVIDIA's kernel side sent it
fw::wr16(p, o + 0x1c, k as u16).map_err(e)?; // MAIN, PM, PATCH
fw::wr8(p, o + 0x1e, 1).map_err(e)?; // bInitialize
@ -1029,13 +1038,13 @@ pub(crate) fn gr_object_alloc(
}
let mut pa = [0u64; 3];
for k in 0..3 {
let a = g.mem.alloc(CTX_SIZE[k], 0x1000);
let a = g.mem.alloc(ctx[k], 0x1000);
let placed = a.is_some_and(|a| fw::wr64(p, 0x30 + 0x20 * k, a).is_ok());
if let Some(a) = a {
pa[k] = a;
}
if !placed {
for (a, sz) in pa.into_iter().zip(CTX_SIZE) {
for (a, sz) in pa.into_iter().zip(ctx) {
if a != 0 {
g.mem.free(a, sz);
}
@ -1046,13 +1055,14 @@ pub(crate) fn gr_object_alloc(
let st = g.rm_control(client, subdevice, 0x2080_012b, p);
if st != Ok(0) {
for k in 0..3 {
g.mem.free(pa[k], CTX_SIZE[k]);
g.mem.free(pa[k], ctx[k]);
}
return st;
}
g.gr_global_init = true;
g.objs.tsg[t].ctx_promoted = true;
g.objs.tsg[t].ctx = pa;
g.objs.tsg[t].ctx_size = ctx;
}
g.rm_alloc(client, parent, object, class, params)
}
@ -1193,9 +1203,9 @@ pub(crate) fn channel_info(
let mut k = 0usize;
if tsg.ctx_promoted {
for (id, sz) in [
(0u32, CTX_SIZE[0]),
(1, fw::align_up(CTX_SIZE[1], 0x1000)),
(2, CTX_SIZE[2]),
(0u32, tsg.ctx_size[0]),
(1, fw::align_up(tsg.ctx_size[1], 0x1000)),
(2, tsg.ctx_size[2]),
] {
ids[k] = id;
pa[k] = tsg.ctx[id as usize];

View File

@ -505,9 +505,15 @@ pub(crate) fn pre(
params.len() as u32,
err(r),
);
// a GSP-RM refusal: nvdriver's own answer
if r != Ok(0) {
return None;
// Only fall back to nvdriver's native server when GSP-RM explicitly reports NOT_SUPPORTED
// (or a transport error occurs); return real GSP-RM status codes (e.g. INVALID_ARGUMENT) directly.
match r {
Ok(0) => {}
Ok(ST_NOT_SUPPORTED) | Err(_) => return None,
Ok(st) => {
wr(top, 28, st);
return Some(0);
}
}
if cmd == 0x2080_0170 || cmd == 0x2080_2a0a {
// answers NVIDIA's kernel side shapes from GSP-RM's (the engines it exposes, CE roles)
@ -710,7 +716,7 @@ fn post_alloc(
} else if class == 0x9067 {
objs::ctxshare_alloc(g, client, parent, object, p)
} else if is_gsp_channel_class(class) {
channel(node, g, client, parent, object, p)
channel(node, g, client, parent, object, class, p)
} else if is_gsp_gr_class(class) {
match subdevice_of(client, par.gpu) {
Some(sub) => objs::gr_object_alloc(g, client, sub, parent, object, class, p),
@ -830,12 +836,14 @@ fn free_memory_users(client: u32, owner: u64, object: u32) -> Option<u32> {
/// `AMPERE_CHANNEL_GPFIFO_A`: USERD = hUserdMemory[0] (+0x20) + userdOffset[0] (+0x40), which must be video memory
/// with the 512-byte USERD inside it; the error notifier = hObjectError (+0), its first system-memory page.
#[inline(never)]
#[allow(clippy::too_many_arguments)]
fn channel(
node: &mut Node,
g: &mut Ga10xGpu,
client: u32,
parent: u32,
object: u32,
class: u32,
p: &mut [u8],
) -> Result<u32, i32> {
let userd_off = u64::from(rd(p, 0x40)) | u64::from(rd(p, 0x44)) << 32;
@ -869,7 +877,7 @@ fn channel(
err_pa as u32,
(err_pa >> 32) as u32,
);
objs::channel_alloc(g, client, parent, object, p, userd_pa, err_pa, err_token)
objs::channel_alloc(g, client, parent, object, class, p, userd_pa, err_pa, err_token)
}
fn subdevice_of(client: u32, gpu: u32) -> Option<u32> {

View File

@ -561,6 +561,16 @@ pub struct FbLayout {
/// `NV_USABLE_FB_SIZE_IN_MB` (0x1183a4) and `NV_PDISP_VGA_WORKSPACE_BASE` (0x625f04): the FB size, the VGA
/// workspace and the FRTS region below it.
pub fn fb_layout(usable_fb_mb: u32, vga_workspace: u32) -> Result<FbLayout> {
fb_layout_for_family(usable_fb_mb, vga_workspace, true)
}
/// Family-aware FB layout: GA100 (`has_frts = false`) has no FWSEC-FRTS region (`frts_size = 0`,
/// matching `_nv041327rm`), whereas TU10x/GA10x/AD10x reserve 1 MiB (`0x10_0000`) below the VGA workspace.
pub fn fb_layout_for_family(
usable_fb_mb: u32,
vga_workspace: u32,
has_frts: bool,
) -> Result<FbLayout> {
if usable_fb_mb == 0 || usable_fb_mb == u32::MAX || usable_fb_mb & 0xbad0_0000 == 0xbad0_0000 {
return Err(Error::BadLayout);
}
@ -579,7 +589,7 @@ pub fn fb_layout(usable_fb_mb: u32, vga_workspace: u32) -> Result<FbLayout> {
a
}
};
let frts_size = 0x10_0000;
let frts_size = if has_frts { 0x10_0000 } else { 0 };
Ok(FbLayout {
fb_size,
vga_addr,
@ -948,21 +958,75 @@ pub mod function {
/// `GspSystemInfo` (580.178.04: 0x3a8 bytes).
pub const SYSTEM_INFO_BYTES: usize = 0x3a8;
/// What `GSP_SET_SYSTEM_INFO` carries from the PCI device (nouveau `r535_gsp_rpc_set_system_info`).
/// Parses an external GSP RISC-V bootloader firmware blob: either an `nvfw_bin_hdr` + `RM_RISCV_UCODE_DESC`
/// container (as packaged in linux-firmware `bootloader-580.bin`) or a raw flat RISC-V binary.
///
/// Returns `(image_bytes, code_offset, data_offset, manifest_offset)`.
pub fn parse_riscv_bootloader(bytes: &[u8]) -> Result<(&[u8], u32, u32, u32)> {
// nvfw_bin_hdr: vendor_id (0x10de), version (1), total_size, header_offset, header_size, data_offset, data_size
if bytes.len() >= 28 && rd32(bytes, 0)? == 0x10de && rd32(bytes, 4)? == 1 {
let hdr_off = rd32(bytes, 12)? as usize;
let hdr_len = rd32(bytes, 16)? as usize;
let data_off = rd32(bytes, 20)? as usize;
let data_len = rd32(bytes, 24)? as usize;
let hdr = span(bytes, hdr_off, hdr_len)?;
let img = span(bytes, data_off, data_len)?;
if hdr.len() >= 0x38 {
let manifest_offset = rd32(hdr, 0x20)?;
let data_offset = rd32(hdr, 0x28)?;
let code_offset = rd32(hdr, 0x30)?;
return Ok((img, code_offset, data_offset, manifest_offset));
}
return Ok((img, 0, 0, 0));
}
Ok((bytes, 0, 0, 0))
}
/// Returns `(pciConfigMirrorBase, pciConfigMirrorSize)` for `GspSystemInfo` (`+0x50/+0x54`)
/// matching stock 580.178.04 (`NV_PBUS_PCI_NV_0` = `0x88000` on Turing/Ampere/Ada, `0x92000` on Hopper,
/// `0` on Blackwell where BAR0 PCI config mirroring is removed).
pub const fn pci_config_mirror_for_family(
family: crate::gpu::gsp_boot::GspFirmwareChipFamily,
) -> (u32, u32) {
use crate::gpu::gsp_boot::GspFirmwareChipFamily;
match family {
GspFirmwareChipFamily::Tu10x
| GspFirmwareChipFamily::Tu11x
| GspFirmwareChipFamily::Ga100
| GspFirmwareChipFamily::Ga10x
| GspFirmwareChipFamily::Ad10x => (0x08_8000, 0x1000),
GspFirmwareChipFamily::Gh100 => (0x09_2000, 0x1000),
GspFirmwareChipFamily::Gb10x
| GspFirmwareChipFamily::Gb10y
| GspFirmwareChipFamily::Gb20x
| GspFirmwareChipFamily::Gb20y
| GspFirmwareChipFamily::Null => (0, 0),
}
}
/// What `GSP_SET_SYSTEM_INFO` carries from the PCI device (nouveau `r535_gsp_rpc_set_system_info`
/// & stock 580.178.04 `kgspPopulateGspRmInitMessage` / `GspSystemInfo`).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct SystemInfo {
pub bar0: u64,
pub bar1: u64,
pub bar3: u64,
pub io: u64,
/// `pci_dev_id`: bus << 8 | devfn.
/// `gpuEncodeDomainBusDevice(domain, bus, PCI_SLOT(devfn))`: `(domain << 32) | (bus << 8) | slot`.
pub bdf: u64,
pub max_user_va: u64,
pub pci_config_mirror_base: u32,
pub pci_config_mirror_size: u32,
pub vendor: u16,
pub device: u16,
pub subsystem_vendor: u16,
pub subsystem_device: u16,
pub revision: u8,
pub behind_bridge: bool,
pub flr_supported: bool,
pub bar0_64b: bool,
pub is_passthru: bool,
pub link_cap: u32,
pub host_page_size: u64,
}
@ -974,8 +1038,8 @@ pub fn write_system_info(out: &mut [u8], s: &SystemInfo) -> Result<()> {
wr64(out, 0x18, s.io)?;
wr64(out, 0x20, s.bdf)?;
wr64(out, 0x48, s.max_user_va)?;
wr32(out, 0x50, 0x08_8000)?; // pciConfigMirrorBase
wr32(out, 0x54, 0x1000)?; // pciConfigMirrorSize
wr32(out, 0x50, s.pci_config_mirror_base)?; // pciConfigMirrorBase
wr32(out, 0x54, s.pci_config_mirror_size)?; // pciConfigMirrorSize
wr32(out, 0x58, u32::from(s.device) << 16 | u32::from(s.vendor))?;
wr32(
out,
@ -983,6 +1047,12 @@ pub fn write_system_info(out: &mut [u8], s: &SystemInfo) -> Result<()> {
u32::from(s.subsystem_device) << 16 | u32::from(s.subsystem_vendor),
)?;
wr32(out, 0x60, u32::from(s.revision))?;
wr64(out, 0x70, 1)?; // clPdbProperties bit 0 (PCIe root port / sysmem access)
wr8(out, 0x7c, u8::from(s.behind_bridge))?; // bGpuBehindBridge
wr8(out, 0x7d, u8::from(s.flr_supported))?; // bFlrSupported
wr8(out, 0x7e, u8::from(s.bar0_64b))?; // b64bBar0Supported
wr8(out, 0x34a, u8::from(s.is_passthru))?; // bIsPassthru
wr32(out, 0x384, s.link_cap)?; // PCI_EXP_LNKCAP
wr64(out, 0x398, s.host_page_size)
}
@ -1307,4 +1377,73 @@ mod tests {
assert_eq!(rd64(&t, 0).unwrap(), 0x10_1000);
assert_eq!(rd64(&t, 0x1000 + 35 * 8).unwrap(), 0x10_0000 + 37 * 0x1000);
}
#[test]
fn parse_riscv_bootloader_handles_nvfw_bin_hdr_and_raw() {
let mut blob = vec![0u8; 0x120];
wr32(&mut blob, 0, 0x10de).unwrap();
wr32(&mut blob, 4, 1).unwrap();
wr32(&mut blob, 8, 0x120).unwrap();
wr32(&mut blob, 12, 0x20).unwrap(); // hdr_off
wr32(&mut blob, 16, 0x40).unwrap(); // hdr_len
wr32(&mut blob, 20, 0x80).unwrap(); // data_off
wr32(&mut blob, 24, 0xa0).unwrap(); // data_len
wr32(&mut blob, 0x20 + 0x20, 0x100).unwrap(); // manifest_offset
wr32(&mut blob, 0x20 + 0x28, 0x800).unwrap(); // data_offset
wr32(&mut blob, 0x20 + 0x30, 0x1800).unwrap(); // code_offset
blob[0x80] = 0xab;
let (img, code, data, manifest) = parse_riscv_bootloader(&blob).unwrap();
assert_eq!(img.len(), 0xa0);
assert_eq!(img[0], 0xab);
assert_eq!((code, data, manifest), (0x1800, 0x800, 0x100));
let raw = [0x11u8, 0x22, 0x33, 0x44];
let (img2, c2, d2, m2) = parse_riscv_bootloader(&raw).unwrap();
assert_eq!(img2, &raw);
assert_eq!((c2, d2, m2), (0, 0, 0));
}
#[test]
fn system_info_and_ga100_fb_layout_match_multi_gen() {
use crate::gpu::gsp_boot::GspFirmwareChipFamily;
assert_eq!(
pci_config_mirror_for_family(GspFirmwareChipFamily::Tu10x),
(0x08_8000, 0x1000)
);
assert_eq!(
pci_config_mirror_for_family(GspFirmwareChipFamily::Gh100),
(0x09_2000, 0x1000)
);
assert_eq!(
pci_config_mirror_for_family(GspFirmwareChipFamily::Gb20x),
(0, 0)
);
let ga100 = fb_layout_for_family(40960, 1, false).unwrap();
assert_eq!(ga100.frts_size, 0);
let mut buf = vec![0u8; SYSTEM_INFO_BYTES];
let s = SystemInfo {
bdf: (1u64 << 32) | (0xb3 << 8) | 2,
pci_config_mirror_base: 0x09_2000,
pci_config_mirror_size: 0x1000,
behind_bridge: true,
flr_supported: true,
bar0_64b: true,
is_passthru: true,
link_cap: 0x0043_f104,
host_page_size: 4096,
..SystemInfo::default()
};
write_system_info(&mut buf, &s).unwrap();
assert_eq!(rd64(&buf, 0x20).unwrap(), s.bdf);
assert_eq!(rd32(&buf, 0x50).unwrap(), 0x09_2000);
assert_eq!(rd32(&buf, 0x54).unwrap(), 0x1000);
assert_eq!(rd64(&buf, 0x70).unwrap(), 1);
assert_eq!(buf[0x7c], 1);
assert_eq!(buf[0x7d], 1);
assert_eq!(buf[0x7e], 1);
assert_eq!(buf[0x34a], 1);
assert_eq!(rd32(&buf, 0x384).unwrap(), 0x0043_f104);
}
}