gpu(gv11b): add sysmem GR aperture bind/save, FECS/GPCCS handshake, deltas, and ECC helpers (#469)

* feat(gr): GV11B GR deltas and aperture-aware FECS bind/save

gr_golden: add inst_block_word(phys, aperture) (target in bits 29:28);
inst_block_word_vidmem, fecs_bind and fecs_save delegate to the new
*_with_aperture variants with Aperture::Video, so GV100 behaviour is
unchanged (covered by a write-for-write equivalence test).

gv11b_gr (new, no_std, no unsafe), per nouveau-gv11b analysis 02 (nvgpu
L4T R36.5 citations):
- 1 GPC / 4 TPC / 2 PES / 8 SM topology and FECS/GPCCS register constants
- start_fecs_gpccs_and_handshake: GPCCS/FECS STARTCPU via cpuctl alias,
  mailbox 0/1/6 init, ctxsw-ready poll (1 pass / 2 fail), GR_CUR_CTX
  invalidate, watchdog method 0x21 (must pass), size queries
  0x10/0x16/0x1a/0x25
- apply_gv11b_gr_deltas: GPC MMU sync from FB MMU (0xfb00087f),
  texio OOR arm_63_48_match, re_suppress, scg_force_slow_drain_tpc,
  cta_subpartition_skew, fecs_host_int_enable 0x007f0003
- set_sm_hww_esr_report_masks (masks supplied by the caller)
- scrub_gv11b_ecc_if_enabled: fuse 0x21228 gate, SM LRF/L1D/L1T/CBU/ICACHE
  scrub polled per active GPC0 TPC; read_gv11b_ecc_status readback for
  FECS/GPCCS/GCC/L1TLB

Offline only; nothing has run on GV11B silicon.

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

* fix(gv11b_gr): align MMU debug reg names and require explicit ECC scrub masks

* gpu(gv11b): clear CTA skew bit 13 and check PRI errors in ECC reads

* gpu(gv11b): expose FECS ECC error counters separately from status readback

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
BlivionIaG
2026-12-05 02:03:32 +01:00
committed by GitHub
parent c83a56c7ae
commit 5a8ebbeebf
3 changed files with 790 additions and 12 deletions

View File

@ -646,3 +646,4 @@ pub mod gv11b_bringup;
pub mod gv11b_dvfs;
pub mod gv11b_fb;
pub mod gv11b_fw;
pub mod gv11b_gr;

View File

@ -8,6 +8,7 @@
//! `_nv033352rm`), and method class filter (`_nv041172rm`) is verified against
//! `nv-kernel.o_binary` (580.178.04) and physical GV100 transcript lines
//! 169469-177468.
use crate::mmu::ramin::Aperture;
use nv_rs_abi::NvStatus;
pub const GR_STATUS: u32 = 0x40_0700;
@ -79,7 +80,7 @@ pub struct GlobalCtxBuffers {
pub const TIMEOUT: NvStatus = NvStatus(0x65);
pub const GENERIC: NvStatus = NvStatus(0xffff);
const MAX_POLLS: u32 = 200_000;
pub(crate) const MAX_POLLS: u32 = 200_000;
/// Netlist regions and floorsweep geometry replayed by `_nv033275rm` + `_nv033195rm`.
#[derive(Clone, Copy, Debug, Default)]
@ -107,11 +108,27 @@ pub trait Io {
fn delay_us(&mut self, microseconds: u32);
}
/// `_nv033352rm(gpu, gr, phys_addr, 1)` for `ADDR_FBMEM` (VID_MEM, target = 0):
/// `0x8000_0000 | ((phys_addr >> 12) & 0x0fff_ffff)`.
/// Instance-block target field (bits 29:28) of the FECS operand; same
/// encoding as the RAMIN PDB aperture (`VID_MEM` 0, `SYS_MEM_COH` 2, `SYS_MEM_NCOH` 3).
const fn aperture_target(aperture: Aperture) -> u32 {
match aperture {
Aperture::Video => 0,
Aperture::SystemCoherent => 2,
Aperture::SystemNoncoherent => 3,
}
}
/// `_nv033352rm(gpu, gr, phys_addr, 1)`: FECS instance operand
/// `0x8000_0000 | (target << 28) | ((phys_addr >> 12) & 0x0fff_ffff)`.
#[inline]
pub const fn inst_block_word(phys_addr: u64, aperture: Aperture) -> u32 {
0x8000_0000 | (aperture_target(aperture) << 28) | (((phys_addr >> 12) as u32) & 0x0fff_ffff)
}
/// `inst_block_word` for `ADDR_FBMEM` (VID_MEM, target = 0).
#[inline]
pub const fn inst_block_word_vidmem(phys_addr: u64) -> u32 {
0x8000_0000 | (((phys_addr >> 12) as u32) & 0x0fff_ffff)
inst_block_word(phys_addr, Aperture::Video)
}
/// `_nv041172rm(class_id)`: maps a method-init class ID to its GR class kind:
@ -130,7 +147,7 @@ pub const fn method_class_kind(class_id: u16) -> u32 {
/// Returns true for PCIe bus-loss (`0xffff_ffff`) or PRI error (`0xbad0_xxxx`) readbacks.
#[inline]
const fn is_pri_error(v: u32) -> bool {
pub(crate) const fn is_pri_error(v: u32) -> bool {
v == u32::MAX || (v & 0xfff0_0000) == 0xbad0_0000
}
@ -255,10 +272,19 @@ pub fn ctxsw_reset<I: Io>(io: &mut I) -> NvStatus {
TIMEOUT
}
/// `_nv031605rm`: clears `0x409840 = 0x30`, submits FECS method `0x03` with
/// `inst_block_word_vidmem(inst_block_phys)`, polls `0x409800` for `0x10` (ok) or `0x21` (fail).
/// `_nv031605rm` for a video-memory instance block.
pub fn fecs_bind<I: Io>(io: &mut I, inst_block_phys: u64) -> NvStatus {
let inst_word = inst_block_word_vidmem(inst_block_phys);
fecs_bind_with_aperture(io, inst_block_phys, Aperture::Video)
}
/// `_nv031605rm`: clears `0x409840 = 0x30`, submits FECS method `0x03` with
/// `inst_block_word(inst_block_phys, aperture)`, polls `0x409800` for `0x10` (ok) or `0x21` (fail).
pub fn fecs_bind_with_aperture<I: Io>(
io: &mut I,
inst_block_phys: u64,
aperture: Aperture,
) -> NvStatus {
let inst_word = inst_block_word(inst_block_phys, aperture);
io.write32(FECS_MAILBOX0_CLEAR, 0x30);
io.write32(FECS_METHOD_DATA, inst_word);
io.write32(FECS_METHOD_PUSH, FECS_METHOD_BIND);
@ -278,11 +304,21 @@ pub fn fecs_bind<I: Io>(io: &mut I, inst_block_phys: u64) -> NvStatus {
TIMEOUT
}
/// `_nv013582rm` mode 0 (method `0x01`) or mode 2 (method `0x09`):
/// clears `0x409840 = 0x03`, submits FECS method with `inst_block_word_vidmem(inst_block_phys)`,
/// polls `0x409800` for `0x01` (ok) or `0x02` (fail).
/// `_nv013582rm` for a video-memory instance block.
pub fn fecs_save<I: Io>(io: &mut I, inst_block_phys: u64, method: u32) -> NvStatus {
let inst_word = inst_block_word_vidmem(inst_block_phys);
fecs_save_with_aperture(io, inst_block_phys, Aperture::Video, method)
}
/// `_nv013582rm` mode 0 (method `0x01`) or mode 2 (method `0x09`):
/// clears `0x409840 = 0x03`, submits FECS method with `inst_block_word(inst_block_phys, aperture)`,
/// polls `0x409800` for `0x01` (ok) or `0x02` (fail).
pub fn fecs_save_with_aperture<I: Io>(
io: &mut I,
inst_block_phys: u64,
aperture: Aperture,
method: u32,
) -> NvStatus {
let inst_word = inst_block_word(inst_block_phys, aperture);
io.write32(FECS_MAILBOX0_CLEAR, 0x03);
io.write32(FECS_METHOD_DATA, inst_word);
io.write32(FECS_METHOD_PUSH, method);
@ -765,6 +801,107 @@ mod tests {
assert_eq!(inst_block_word_vidmem(0x7_fdb9_0000), 0x807f_db90);
}
#[test]
fn inst_block_word_encodes_aperture_target() {
let phys = 0x7_fdb9_0000;
assert_eq!(inst_block_word(phys, Aperture::Video), 0x807f_db90);
assert_eq!(inst_block_word(phys, Aperture::SystemCoherent), 0xa07f_db90);
assert_eq!(
inst_block_word(phys, Aperture::SystemNoncoherent),
0xb07f_db90
);
// 40-bit sysmem address: bits above 39 are outside the 28-bit page field.
assert_eq!(
inst_block_word(0xff_ffff_f000, Aperture::SystemNoncoherent),
0xbfff_ffff
);
assert_eq!(
inst_block_word(0x100_0000_0000, Aperture::Video),
0x8000_0000
);
}
struct MailboxGr {
writes: Vec<(u32, u32)>,
reply: u32,
}
impl Io for MailboxGr {
fn read32(&mut self, offset: u32) -> u32 {
if offset == FECS_MAILBOX0 {
self.reply
} else {
0
}
}
fn write32(&mut self, offset: u32, value: u32) {
self.writes.push((offset, value));
}
fn delay_us(&mut self, _us: u32) {}
}
fn mailbox_gr(reply: u32) -> MailboxGr {
MailboxGr {
writes: Vec::new(),
reply,
}
}
#[test]
fn fecs_bind_and_save_with_aperture_emit_target_bits() {
let mut gr = mailbox_gr(0x10);
let st = fecs_bind_with_aperture(&mut gr, 0x8000_0000, Aperture::SystemNoncoherent);
assert_eq!(st, NvStatus::OK);
assert_eq!(
gr.writes,
[
(FECS_MAILBOX0_CLEAR, 0x30),
(FECS_METHOD_DATA, 0xb008_0000),
(FECS_METHOD_PUSH, FECS_METHOD_BIND),
]
);
let mut gr = mailbox_gr(0x01);
let st = fecs_save_with_aperture(
&mut gr,
0x8000_0000,
Aperture::SystemCoherent,
FECS_METHOD_GOLDEN_SAVE,
);
assert_eq!(st, NvStatus::OK);
assert_eq!(
gr.writes,
[
(FECS_MAILBOX0_CLEAR, 0x03),
(FECS_METHOD_DATA, 0xa008_0000),
(FECS_METHOD_PUSH, FECS_METHOD_GOLDEN_SAVE),
]
);
}
#[test]
fn fecs_bind_and_save_video_delegates_are_unchanged() {
let phys = 0x7_fdb9_0000;
let mut a = mailbox_gr(0x10);
let mut b = mailbox_gr(0x10);
assert_eq!(fecs_bind(&mut a, phys), NvStatus::OK);
assert_eq!(
fecs_bind_with_aperture(&mut b, phys, Aperture::Video),
NvStatus::OK
);
assert_eq!(a.writes, b.writes);
assert!(a.writes.contains(&(FECS_METHOD_DATA, 0x807f_db90)));
let mut a = mailbox_gr(0x02);
let mut b = mailbox_gr(0x02);
assert_eq!(fecs_save(&mut a, phys, FECS_METHOD_SAVE), GENERIC);
assert_eq!(
fecs_save_with_aperture(&mut b, phys, Aperture::Video, FECS_METHOD_SAVE),
GENERIC
);
assert_eq!(a.writes, b.writes);
assert_eq!(fecs_bind(&mut mailbox_gr(0x21), phys), GENERIC);
}
#[test]
fn method_class_kind_matches_nv041172rm() {
assert_eq!(method_class_kind(0xc397), 0); // Volta 3D

View File

@ -0,0 +1,640 @@
//! GV11B (Tegra194 Volta) GR deltas on top of the GV100 golden-context path.
//!
//! Source: `analysis/02-gr-netlist-topology.md` (nouveau-gv11b), which cites
//! nvgpu L4T R36.5: `hal_gv11b_litter.c`, `hw_proj_gv11b.h:84-98` (topology),
//! `gr_falcon_gm20b_fusa.c:83-110,484` (FECS/GPCCS start and ctxsw-ready
//! handshake), `gr_falcon_gv11b_fusa.c` (`fecs_host_int_enable`),
//! `gr_init_gv11b_fusa.c:367,531-610` (register deltas, ECC scrub),
//! `gr_intr_gv11b_fusa.c:~900-926` (SM ESR report masks), `ecc_gp10b.c`
//! (`fuse_opt_ecc_en`). Nothing here has run on GV11B silicon.
use super::gr_golden::{is_pri_error, Io, GENERIC, GR_CUR_CTX, MAX_POLLS, TIMEOUT};
use super::gr_golden::{FECS_MAILBOX0, FECS_MAILBOX0_CLEAR, FECS_METHOD_DATA, FECS_METHOD_PUSH};
use super::gr_golden::{GPC_UNICAST_BASE, TPC_IN_GPC_BASE, TPC_STRIDE};
use nv_rs_abi::NvStatus;
pub const GV11B_GPC_COUNT: u32 = 1;
pub const GV11B_TPC_PER_GPC: u32 = 4;
pub const GV11B_PES_PER_GPC: u32 = 2;
pub const GV11B_SM_PER_TPC: u32 = 2;
pub const GV11B_SM_COUNT: u32 = GV11B_GPC_COUNT * GV11B_TPC_PER_GPC * GV11B_SM_PER_TPC;
pub const FECS_HOST_INT_ENABLE: u32 = 0x40_9c24;
pub const FECS_HOST_INT_ENABLE_VALUE: u32 = 0x007f_0003;
pub const FECS_CPUCTL_ALIAS: u32 = 0x40_9130;
pub const GPCCS_CPUCTL_ALIAS: u32 = 0x41_a130;
pub const CPUCTL_STARTCPU: u32 = 0x2;
pub const FECS_MAILBOX1: u32 = 0x40_9804;
pub const FECS_MAILBOX6: u32 = 0x40_9818;
pub const FUSE_OPT_ECC_EN: u32 = 0x02_1228;
pub const MAILBOX_PASS: u32 = 1;
pub const MAILBOX_FAIL: u32 = 2;
pub const FECS_METHOD_IMAGE_SIZE: u32 = 0x10;
pub const FECS_METHOD_ZCULL_SIZE: u32 = 0x16;
pub const FECS_METHOD_PREEMPT_SIZE: u32 = 0x1a;
pub const FECS_METHOD_WATCHDOG: u32 = 0x21;
pub const FECS_METHOD_PM_SIZE: u32 = 0x25;
pub const FECS_WATCHDOG_TIMEOUT: u32 = 0x7fff_ffff;
pub const FB_MMU_CTRL: u32 = 0x10_0c80;
pub const FB_MMU_DEBUG_CTRL: u32 = 0x10_0cc4;
pub const FB_MMU_DEBUG_WR: u32 = 0x10_0cc8;
pub const FB_MMU_DEBUG_RD: u32 = 0x10_0ccc;
pub const GPCS_MMU_CTRL: u32 = 0x41_8880;
pub const GPCS_MMU_CTRL_MASK: u32 = 0xfb00_087f;
pub const GPCS_MMU_PM_UNIT_MASK: u32 = 0x41_8890;
pub const GPCS_MMU_PM_REQ_MASK: u32 = 0x41_8894;
pub const GPCS_MMU_DEBUG_CTRL: u32 = 0x41_88b0;
pub const GPCS_MMU_DEBUG_WR: u32 = 0x41_88b4;
pub const GPCS_MMU_DEBUG_RD: u32 = 0x41_88b8;
pub const GPCS_TPCS_SM_TEXIO_CONTROL: u32 = 0x41_9bd8;
pub const TEXIO_OOR_ADDR_CHECK_MASK: u32 = 0x700;
pub const TEXIO_OOR_ARM_63_48_MATCH: u32 = 0x100;
pub const GPCS_TPCS_RE_SUPPRESS_REG: u32 = 0x41_9ba4;
pub const RE_SUPPRESS_MASK: u32 = 0x3 << 11;
pub const RE_SUPPRESS_VALUE: u32 = 0x1000;
pub const GR_DEBUG_0: u32 = 0x40_0080;
pub const SCG_FORCE_SLOW_DRAIN_TPC: u32 = 1 << 11;
pub const GPCS_TPCS_CTA_SKEW_REG: u32 = 0x41_9c04;
pub const CTA_SUBPARTITION_SKEW_MASK: u32 = 1 << 13;
pub const CTA_SUBPARTITION_SKEW_DISABLE: u32 = 0;
pub const GPCS_TPCS_SMS_HWW_WARP_ESR_REPORT_MASK: u32 = 0x41_9ea8;
pub const GPCS_TPCS_SMS_HWW_GLOBAL_ESR_REPORT_MASK: u32 = 0x41_9eac;
/// `gpcs_tpcs` broadcast base; unicast `gpc0_tpcN` = `0x504000 + N * 0x800` + same offset.
const GPCS_TPCS_BASE: u32 = 0x41_9800;
/// One SM ECC unit: broadcast control register and caller-supplied scrub-task bits.
/// Scrub completes when every task bit reads back 0 on each active TPC.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct EccScrubUnit {
pub control: u32,
pub tasks: u32,
}
/// Verified SM ECC broadcast control registers (`gv11b_gr_init_ecc_scrub_reg`):
/// LRF (`0x419b54`), L1 data (`0x419b68`), L1 tag (`0x419e20`),
/// CBU (`0x419e34`), ICACHE (`0x419e48`).
pub const GV11B_SM_ECC_CONTROL_REGS: [u32; 5] =
[0x41_9b54, 0x41_9b68, 0x41_9e20, 0x41_9e34, 0x41_9e48];
/// ECC control/status registers of units with no SW scrub (FECS, GPCCS, GCC L1.5,
/// GPC MMU L1TLB); read back separately from the error-count registers.
pub const GV11B_ECC_STATUS: [u32; 8] = [
0x40_968c, 0x40_9678, 0x50_268c, 0x50_2678, 0x50_1044, 0x50_1048, 0x50_0310, 0x50_0314,
];
/// FECS Falcon IMEM/DMEM corrected and uncorrected ECC error-count registers (`hw_gr_gv11b.h`).
pub const FECS_ECC_CORRECTED_ERR_COUNT: u32 = 0x40_967c;
pub const FECS_ECC_UNCORRECTED_ERR_COUNT: u32 = 0x40_9680;
/// FECS corrected and uncorrected ECC error counts.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct FecsEccCounts {
pub corrected: u32,
pub uncorrected: u32,
}
/// FECS context buffer sizes from the discover methods.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct CtxBufferSizes {
pub image: u32,
pub zcull: u32,
pub preempt: u32,
pub pm: u32,
}
/// SM HWW ESR report masks (`set_hww_esr_report_mask`), written after `sw_ctx_load`.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct EsrReportMasks {
pub warp: u32,
pub global: u32,
}
fn read<I: Io>(io: &mut I, reg: u32) -> Result<u32, NvStatus> {
let v = io.read32(reg);
if is_pri_error(v) {
return Err(TIMEOUT);
}
Ok(v)
}
fn rmw<I: Io>(io: &mut I, reg: u32, clear: u32, set: u32) -> Result<(), NvStatus> {
let v = read(io, reg)?;
io.write32(reg, (v & !clear) | set);
Ok(())
}
fn copy<I: Io>(io: &mut I, from: u32, to: u32, mask: u32) -> Result<(), NvStatus> {
let v = read(io, from)?;
io.write32(to, v & mask);
Ok(())
}
fn status(r: Result<(), NvStatus>) -> NvStatus {
match r {
Ok(()) => NvStatus::OK,
Err(st) => st,
}
}
/// Polls `reg` until `done(value)`; PRI errors and exhausted polls are `TIMEOUT`.
fn poll<I: Io>(io: &mut I, reg: u32, done: impl Fn(u32) -> bool) -> Result<u32, NvStatus> {
for _ in 0..MAX_POLLS {
let v = read(io, reg)?;
if done(v) {
return Ok(v);
}
io.delay_us(1);
}
Err(TIMEOUT)
}
/// Waits for ctxsw mailbox 0 to report pass (1) or fail (2).
fn wait_mailbox_pass<I: Io>(io: &mut I) -> Result<(), NvStatus> {
match poll(io, FECS_MAILBOX0, |v| {
v == MAILBOX_PASS || v == MAILBOX_FAIL
})? {
MAILBOX_PASS => Ok(()),
_ => Err(GENERIC),
}
}
/// `submit_fecs_method_op`: clear mailbox 0 (`0x409840 = ~0`), data, push.
fn fecs_method<I: Io>(io: &mut I, method: u32, data: u32) {
io.write32(FECS_MAILBOX0_CLEAR, u32::MAX);
io.write32(FECS_METHOD_DATA, data);
io.write32(FECS_METHOD_PUSH, method);
}
/// Discover method: result is the first non-zero mailbox 0 value.
fn fecs_query<I: Io>(io: &mut I, method: u32) -> Result<u32, NvStatus> {
fecs_method(io, method, 0);
poll(io, FECS_MAILBOX0, |v| v != 0)
}
/// `start_gpccs` + `start_fecs`: GPCCS STARTCPU via its cpuctl alias, FECS
/// mailbox init (0 = 0, 1 = 1, 6 = 0), then FECS STARTCPU via its alias.
pub fn start_fecs_gpccs<I: Io>(io: &mut I) {
io.write32(GPCCS_CPUCTL_ALIAS, CPUCTL_STARTCPU);
io.write32(FECS_MAILBOX0, 0);
io.write32(FECS_MAILBOX1, 1);
io.write32(FECS_MAILBOX6, 0);
io.write32(FECS_CPUCTL_ALIAS, CPUCTL_STARTCPU);
}
/// `wait_ctxsw_ready` + `init_ctx_state`: mailbox 0 pass, invalidate
/// `GR_CUR_CTX`, watchdog method (must pass on GV11B), buffer-size queries.
pub fn ctxsw_handshake<I: Io>(io: &mut I) -> Result<CtxBufferSizes, NvStatus> {
wait_mailbox_pass(io)?;
io.write32(GR_CUR_CTX, 0);
fecs_method(io, FECS_METHOD_WATCHDOG, FECS_WATCHDOG_TIMEOUT);
wait_mailbox_pass(io)?;
Ok(CtxBufferSizes {
image: fecs_query(io, FECS_METHOD_IMAGE_SIZE)?,
zcull: fecs_query(io, FECS_METHOD_ZCULL_SIZE)?,
preempt: fecs_query(io, FECS_METHOD_PREEMPT_SIZE)?,
pm: fecs_query(io, FECS_METHOD_PM_SIZE)?,
})
}
/// Starts the ACR-loaded FECS/GPCCS and completes the ctxsw-ready handshake.
pub fn start_fecs_gpccs_and_handshake<I: Io>(io: &mut I) -> Result<CtxBufferSizes, NvStatus> {
start_fecs_gpccs(io);
ctxsw_handshake(io)
}
/// `gv11b_gr_init_gpc_mmu`: mirror FB MMU control/debug into the GPC MMUs.
fn sync_gpc_mmu<I: Io>(io: &mut I) -> Result<(), NvStatus> {
copy(io, FB_MMU_CTRL, GPCS_MMU_CTRL, GPCS_MMU_CTRL_MASK)?;
io.write32(GPCS_MMU_PM_UNIT_MASK, 0);
io.write32(GPCS_MMU_PM_REQ_MASK, 0);
copy(io, FB_MMU_DEBUG_CTRL, GPCS_MMU_DEBUG_CTRL, u32::MAX)?;
copy(io, FB_MMU_DEBUG_WR, GPCS_MMU_DEBUG_WR, u32::MAX)?;
copy(io, FB_MMU_DEBUG_RD, GPCS_MMU_DEBUG_RD, u32::MAX)
}
fn apply_deltas<I: Io>(io: &mut I) -> Result<(), NvStatus> {
sync_gpc_mmu(io)?;
rmw(
io,
GPCS_TPCS_SM_TEXIO_CONTROL,
TEXIO_OOR_ADDR_CHECK_MASK,
TEXIO_OOR_ARM_63_48_MATCH,
)?;
rmw(
io,
GPCS_TPCS_RE_SUPPRESS_REG,
RE_SUPPRESS_MASK,
RE_SUPPRESS_VALUE,
)?;
rmw(io, GR_DEBUG_0, 0, SCG_FORCE_SLOW_DRAIN_TPC)?;
rmw(
io,
GPCS_TPCS_CTA_SKEW_REG,
CTA_SUBPARTITION_SKEW_MASK,
CTA_SUBPARTITION_SKEW_DISABLE,
)?;
io.write32(FECS_HOST_INT_ENABLE, FECS_HOST_INT_ENABLE_VALUE);
Ok(())
}
/// GV11B `setup_hw` register deltas versus the GV100 path.
pub fn apply_gv11b_gr_deltas<I: Io>(io: &mut I) -> NvStatus {
status(apply_deltas(io))
}
/// `set_hww_esr_report_mask`: broadcast SM warp/global ESR report masks.
pub fn set_sm_hww_esr_report_masks<I: Io>(io: &mut I, masks: EsrReportMasks) {
io.write32(GPCS_TPCS_SMS_HWW_WARP_ESR_REPORT_MASK, masks.warp);
io.write32(GPCS_TPCS_SMS_HWW_GLOBAL_ESR_REPORT_MASK, masks.global);
}
/// Unicast GPC0 address of a `gpcs_tpcs` broadcast register for `tpc`.
pub const fn gpc0_tpc_reg(broadcast: u32, tpc: u32) -> u32 {
GPC_UNICAST_BASE + TPC_IN_GPC_BASE + tpc * TPC_STRIDE + (broadcast - GPCS_TPCS_BASE)
}
fn scrub_unit<I: Io>(io: &mut I, unit: EccScrubUnit, tpc_mask: u8) -> Result<(), NvStatus> {
io.write32(unit.control, unit.tasks);
for tpc in (0..GV11B_TPC_PER_GPC).filter(|t| tpc_mask & (1 << t) != 0) {
poll(io, gpc0_tpc_reg(unit.control, tpc), |v| v & unit.tasks == 0)?;
}
Ok(())
}
/// `fuse_opt_ecc_en` (`gp10b_fuse_is_opt_ecc_enable`): non-zero = ECC on.
pub fn gv11b_ecc_enabled<I: Io>(io: &mut I) -> Result<bool, NvStatus> {
Ok(read(io, FUSE_OPT_ECC_EN)? != 0)
}
/// Scrubs caller-supplied SM ECC units (`GV11B_SM_ECC_CONTROL_REGS`) across
/// the active GPC0 TPCs in `tpc_mask` when the ECC fuse is set.
pub fn scrub_gv11b_ecc_if_enabled<I: Io>(
io: &mut I,
tpc_mask: u8,
units: &[EccScrubUnit],
) -> Result<bool, NvStatus> {
if !gv11b_ecc_enabled(io)? {
return Ok(false);
}
for &unit in units {
scrub_unit(io, unit, tpc_mask)?;
}
Ok(true)
}
/// Reads the non-SM ECC control/status registers (`GV11B_ECC_STATUS` order).
pub fn read_gv11b_ecc_status<I: Io>(io: &mut I) -> Result<[u32; 8], NvStatus> {
let mut out = [0u32; 8];
for (slot, &reg) in out.iter_mut().zip(GV11B_ECC_STATUS.iter()) {
*slot = read(io, reg)?;
}
Ok(out)
}
/// Reads the FECS corrected and uncorrected ECC error-count registers separately from control/status.
pub fn read_gv11b_fecs_ecc_counts<I: Io>(io: &mut I) -> Result<FecsEccCounts, NvStatus> {
Ok(FecsEccCounts {
corrected: read(io, FECS_ECC_CORRECTED_ERR_COUNT)?,
uncorrected: read(io, FECS_ECC_UNCORRECTED_ERR_COUNT)?,
})
}
#[cfg(test)]
mod tests {
use super::*;
extern crate std;
use std::vec::Vec;
/// Register file with scripted FECS mailbox replies and scrub completion.
struct FakeGv11b {
regs: Vec<(u32, u32)>,
writes: Vec<(u32, u32)>,
fecs_running: bool,
watchdog_reply: u32,
ready_reply: u32,
scrub_sticks: bool,
}
impl FakeGv11b {
fn new() -> Self {
Self {
regs: Vec::new(),
writes: Vec::new(),
fecs_running: false,
watchdog_reply: MAILBOX_PASS,
ready_reply: MAILBOX_PASS,
scrub_sticks: false,
}
}
fn with(mut self, reg: u32, value: u32) -> Self {
self.set(reg, value);
self
}
fn get(&self, reg: u32) -> u32 {
self.regs
.iter()
.rev()
.find(|&&(r, _)| r == reg)
.map_or(0, |&(_, v)| v)
}
fn set(&mut self, reg: u32, value: u32) {
self.regs.push((reg, value));
}
fn query_reply(method: u32) -> u32 {
match method {
FECS_METHOD_IMAGE_SIZE => 0x4_8000,
FECS_METHOD_ZCULL_SIZE => 0x2000,
FECS_METHOD_PREEMPT_SIZE => 0x1_0000,
FECS_METHOD_PM_SIZE => 0x3000,
_ => 0,
}
}
fn written(&self, reg: u32) -> Vec<u32> {
self.writes
.iter()
.filter(|&&(r, _)| r == reg)
.map(|&(_, v)| v)
.collect()
}
}
impl Io for FakeGv11b {
fn read32(&mut self, offset: u32) -> u32 {
self.get(offset)
}
fn write32(&mut self, offset: u32, value: u32) {
self.writes.push((offset, value));
match offset {
FECS_MAILBOX0_CLEAR => self.set(FECS_MAILBOX0, self.get(FECS_MAILBOX0) & !value),
FECS_CPUCTL_ALIAS => {
self.fecs_running = true;
self.set(FECS_MAILBOX0, self.ready_reply);
}
FECS_METHOD_PUSH if self.fecs_running => {
let reply = if value == FECS_METHOD_WATCHDOG {
self.watchdog_reply
} else {
Self::query_reply(value)
};
self.set(FECS_MAILBOX0, reply);
}
_ => self.set(offset, value),
}
if GV11B_SM_ECC_CONTROL_REGS.contains(&offset) {
let left = if self.scrub_sticks { value } else { 0 };
for tpc in 0..GV11B_TPC_PER_GPC {
self.set(gpc0_tpc_reg(offset, tpc), left);
}
}
}
fn delay_us(&mut self, _us: u32) {}
}
#[test]
fn topology_matches_gv11b_litter() {
assert_eq!(GV11B_GPC_COUNT, 1);
assert_eq!(GV11B_TPC_PER_GPC, 4);
assert_eq!(GV11B_PES_PER_GPC, 2);
assert_eq!(GV11B_SM_COUNT, 8);
assert_eq!(FECS_HOST_INT_ENABLE_VALUE, 0x007f_0003);
// GPCCS alias = FECS alias + (gpcs_gpccs_hwcfg 0x41a108 - fecs_hwcfg 0x409108).
assert_eq!(
GPCCS_CPUCTL_ALIAS - FECS_CPUCTL_ALIAS,
0x41_a108 - 0x40_9108
);
}
#[test]
fn gpc0_tpc_reg_matches_documented_unicast_controls() {
assert_eq!(gpc0_tpc_reg(0x41_9b54, 0), 0x50_4354);
assert_eq!(gpc0_tpc_reg(0x41_9b68, 0), 0x50_4368);
assert_eq!(gpc0_tpc_reg(0x41_9e20, 0), 0x50_4620);
assert_eq!(gpc0_tpc_reg(0x41_9e34, 0), 0x50_4634);
assert_eq!(gpc0_tpc_reg(0x41_9e48, 3), 0x50_5e48);
}
#[test]
fn handshake_emits_exact_sequence_and_sizes() {
let mut gr = FakeGv11b::new();
let sizes = start_fecs_gpccs_and_handshake(&mut gr).unwrap();
assert_eq!(
sizes,
CtxBufferSizes {
image: 0x4_8000,
zcull: 0x2000,
preempt: 0x1_0000,
pm: 0x3000,
}
);
let q = |m: u32| {
[
(FECS_MAILBOX0_CLEAR, u32::MAX),
(FECS_METHOD_DATA, 0),
(FECS_METHOD_PUSH, m),
]
};
let mut expect = std::vec![
(GPCCS_CPUCTL_ALIAS, CPUCTL_STARTCPU),
(FECS_MAILBOX0, 0),
(FECS_MAILBOX1, 1),
(FECS_MAILBOX6, 0),
(FECS_CPUCTL_ALIAS, CPUCTL_STARTCPU),
(GR_CUR_CTX, 0),
(FECS_MAILBOX0_CLEAR, u32::MAX),
(FECS_METHOD_DATA, FECS_WATCHDOG_TIMEOUT),
(FECS_METHOD_PUSH, FECS_METHOD_WATCHDOG),
];
for m in [
FECS_METHOD_IMAGE_SIZE,
FECS_METHOD_ZCULL_SIZE,
FECS_METHOD_PREEMPT_SIZE,
FECS_METHOD_PM_SIZE,
] {
expect.extend_from_slice(&q(m));
}
assert_eq!(gr.writes, expect);
}
#[test]
fn handshake_fails_on_ready_fail() {
let mut gr = FakeGv11b::new();
gr.ready_reply = MAILBOX_FAIL;
assert_eq!(start_fecs_gpccs_and_handshake(&mut gr), Err(GENERIC));
assert!(gr.written(GR_CUR_CTX).is_empty());
}
#[test]
fn handshake_fails_on_watchdog_fail() {
let mut gr = FakeGv11b::new();
gr.watchdog_reply = MAILBOX_FAIL;
assert_eq!(start_fecs_gpccs_and_handshake(&mut gr), Err(GENERIC));
assert!(gr.written(FECS_METHOD_PUSH) == [FECS_METHOD_WATCHDOG]);
}
#[test]
fn handshake_times_out_when_fecs_never_answers() {
let mut gr = FakeGv11b::new();
assert_eq!(ctxsw_handshake(&mut gr), Err(TIMEOUT));
}
#[test]
fn handshake_bails_on_pri_error() {
let mut gr = FakeGv11b::new();
gr.ready_reply = 0xbad0_0100;
assert_eq!(start_fecs_gpccs_and_handshake(&mut gr), Err(TIMEOUT));
}
#[test]
fn deltas_program_each_register() {
let mut gr = FakeGv11b::new()
.with(FB_MMU_CTRL, 0x7fff_ffff)
.with(FB_MMU_DEBUG_CTRL, 0x33)
.with(FB_MMU_DEBUG_WR, 0x11)
.with(FB_MMU_DEBUG_RD, 0x22)
.with(GPCS_TPCS_SM_TEXIO_CONTROL, 0x7fff_ffff)
.with(GPCS_TPCS_RE_SUPPRESS_REG, 0x1800)
.with(GR_DEBUG_0, 0x0030_03d2)
.with(GPCS_TPCS_CTA_SKEW_REG, CTA_SUBPARTITION_SKEW_MASK | 0x1);
assert_eq!(apply_gv11b_gr_deltas(&mut gr), NvStatus::OK);
assert_eq!(gr.written(GPCS_MMU_CTRL), [0x7b00_087f]);
assert_eq!(gr.written(GPCS_MMU_PM_UNIT_MASK), [0]);
assert_eq!(gr.written(GPCS_MMU_PM_REQ_MASK), [0]);
assert_eq!(gr.written(GPCS_MMU_DEBUG_CTRL), [0x33]);
assert_eq!(gr.written(GPCS_MMU_DEBUG_WR), [0x11]);
assert_eq!(gr.written(GPCS_MMU_DEBUG_RD), [0x22]);
assert_eq!(gr.written(GPCS_TPCS_SM_TEXIO_CONTROL), [0x7fff_f9ff]);
assert_eq!(gr.written(GPCS_TPCS_RE_SUPPRESS_REG), [0x1000]);
assert_eq!(gr.written(GR_DEBUG_0), [0x0030_0bd2]);
assert_eq!(gr.written(GPCS_TPCS_CTA_SKEW_REG), [0x1]);
assert_eq!(gr.written(FECS_HOST_INT_ENABLE), [0x007f_0003]);
}
#[test]
fn deltas_stop_on_pri_error() {
let mut gr = FakeGv11b::new().with(FB_MMU_CTRL, 0xbad0_0000);
assert_eq!(apply_gv11b_gr_deltas(&mut gr), TIMEOUT);
assert!(gr.writes.is_empty());
}
#[test]
fn esr_masks_go_to_broadcast_registers() {
let mut gr = FakeGv11b::new();
set_sm_hww_esr_report_masks(
&mut gr,
EsrReportMasks {
warp: 0x1234,
global: 0x5678,
},
);
assert_eq!(
gr.writes,
[
(GPCS_TPCS_SMS_HWW_WARP_ESR_REPORT_MASK, 0x1234),
(GPCS_TPCS_SMS_HWW_GLOBAL_ESR_REPORT_MASK, 0x5678),
]
);
}
fn test_ecc_units() -> [EccScrubUnit; 5] {
GV11B_SM_ECC_CONTROL_REGS.map(|control| EccScrubUnit {
control,
tasks: 0x3,
})
}
#[test]
fn ecc_scrub_skipped_when_fuse_clear() {
let mut gr = FakeGv11b::new();
assert_eq!(
scrub_gv11b_ecc_if_enabled(&mut gr, 0xf, &test_ecc_units()),
Ok(false)
);
assert!(gr.writes.is_empty());
}
#[test]
fn ecc_scrub_writes_every_sm_unit_when_fused_on() {
let mut gr = FakeGv11b::new().with(FUSE_OPT_ECC_EN, 1);
let units = test_ecc_units();
assert_eq!(scrub_gv11b_ecc_if_enabled(&mut gr, 0xf, &units), Ok(true));
let expect: Vec<(u32, u32)> = units.iter().map(|u| (u.control, u.tasks)).collect();
assert_eq!(gr.writes, expect);
}
#[test]
fn ecc_scrub_polls_only_active_tpcs() {
let mut gr = FakeGv11b::new().with(FUSE_OPT_ECC_EN, 1);
let units = test_ecc_units();
gr.scrub_sticks = true;
// Every TPC stuck: TPC 0 (the only active one) times out after the first unit.
assert_eq!(
scrub_gv11b_ecc_if_enabled(&mut gr, 0x1, &units),
Err(TIMEOUT)
);
assert_eq!(gr.writes.len(), 1);
// Empty TPC mask: nothing to poll, all five controls written.
let mut gr = FakeGv11b::new().with(FUSE_OPT_ECC_EN, 1);
gr.scrub_sticks = true;
assert_eq!(scrub_gv11b_ecc_if_enabled(&mut gr, 0, &units), Ok(true));
assert_eq!(gr.writes.len(), units.len());
}
#[test]
fn ecc_fuse_pri_error_is_reported() {
let mut gr = FakeGv11b::new().with(FUSE_OPT_ECC_EN, u32::MAX);
assert_eq!(
scrub_gv11b_ecc_if_enabled(&mut gr, 0xf, &test_ecc_units()),
Err(TIMEOUT)
);
}
#[test]
fn ecc_status_readback_follows_table_order() {
let mut gr = FakeGv11b::new().with(0x40_968c, 7).with(0x50_0314, 9);
let st = read_gv11b_ecc_status(&mut gr).unwrap();
assert_eq!(st[0], 7);
assert_eq!(st[7], 9);
assert!(gr.writes.is_empty());
}
#[test]
fn ecc_status_readback_propagates_pri_errors() {
let mut gr = FakeGv11b::new().with(0x50_268c, u32::MAX);
assert_eq!(read_gv11b_ecc_status(&mut gr), Err(TIMEOUT));
let mut gr = FakeGv11b::new().with(0x50_1044, 0xbad0_0001);
assert_eq!(read_gv11b_ecc_status(&mut gr), Err(TIMEOUT));
}
#[test]
fn fecs_ecc_error_counters_read_separately_from_status() {
let mut gr = FakeGv11b::new()
.with(0x40_9678, 0x11)
.with(0x40_968c, 0x22)
.with(FECS_ECC_CORRECTED_ERR_COUNT, 3)
.with(FECS_ECC_UNCORRECTED_ERR_COUNT, 1);
let counts = read_gv11b_fecs_ecc_counts(&mut gr).unwrap();
assert_eq!(
counts,
FecsEccCounts {
corrected: 3,
uncorrected: 1,
}
);
let st = read_gv11b_ecc_status(&mut gr).unwrap();
assert_eq!(st[0], 0x22);
assert_eq!(st[1], 0x11);
assert!(gr.writes.is_empty());
}
#[test]
fn fecs_ecc_error_counters_propagate_pri_errors() {
let mut gr = FakeGv11b::new().with(FECS_ECC_CORRECTED_ERR_COUNT, u32::MAX);
assert_eq!(read_gv11b_fecs_ecc_counts(&mut gr), Err(TIMEOUT));
let mut gr = FakeGv11b::new().with(FECS_ECC_UNCORRECTED_ERR_COUNT, 0xbad0_0001);
assert_eq!(read_gv11b_fecs_ecc_counts(&mut gr), Err(TIMEOUT));
}
}