mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
gpu,mmu(gv11b): add 10-blob firmware bundle validator, sysmem BAR2 bind encoder, and kernel FFI (#434)
* gpu,mmu(gv11b): add 10-blob firmware bundle validator, sysmem BAR2 bind encoder, and stack-safe FFI * gpu,kernel(gv11b): validate PMU image segment bounds and output pointer alignment * test(gv11b): ensure deterministic unaligned u32 pointer in FFI alignment test * kernel(gv11b): reject oversized len > isize::MAX in gv11b_platform::byte_slice
This commit is contained in:
File diff suppressed because one or more lines are too long
236
src/nvidia/kernel/gv11b_platform.rs
Normal file
236
src/nvidia/kernel/gv11b_platform.rs
Normal file
@ -0,0 +1,236 @@
|
||||
//! Stack-bounded `#![no_std]` kernel FFI helpers for Tegra194 `GV11B` firmware
|
||||
//! validation and unified-sysmem BAR2 setup.
|
||||
use core::slice;
|
||||
use nv_rs_core::{gpu::gv11b_fw, mmu::bar2};
|
||||
|
||||
const EINVAL: i32 = -22;
|
||||
|
||||
fn valid_opt_out<T>(out: *mut T) -> bool {
|
||||
out.is_null() || out.is_aligned()
|
||||
}
|
||||
|
||||
unsafe fn byte_slice<'a>(bytes: *const u8, len: usize) -> Option<&'a [u8]> {
|
||||
if bytes.is_null() || len == 0 || len > isize::MAX as usize {
|
||||
return None;
|
||||
}
|
||||
Some(unsafe { slice::from_raw_parts(bytes, len) })
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn nv_rs_gv11b_validate_acr(
|
||||
bytes: *const u8,
|
||||
len: usize,
|
||||
out_data_offset: *mut u32,
|
||||
out_data_size: *mut u32,
|
||||
) -> i32 {
|
||||
if !valid_opt_out(out_data_offset) || !valid_opt_out(out_data_size) {
|
||||
return EINVAL;
|
||||
}
|
||||
let Some(data) = (unsafe { byte_slice(bytes, len) }) else {
|
||||
return EINVAL;
|
||||
};
|
||||
let Ok(hdr) = gv11b_fw::parse_acr_header(data) else {
|
||||
return EINVAL;
|
||||
};
|
||||
if !out_data_offset.is_null() {
|
||||
unsafe { out_data_offset.write(hdr.data_offset) };
|
||||
}
|
||||
if !out_data_size.is_null() {
|
||||
unsafe { out_data_size.write(hdr.data_size) };
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn nv_rs_gv11b_validate_falcon_desc(
|
||||
bytes: *const u8,
|
||||
len: usize,
|
||||
out_imem_offset: *mut u32,
|
||||
out_entry: *mut u32,
|
||||
) -> i32 {
|
||||
if !valid_opt_out(out_imem_offset) || !valid_opt_out(out_entry) {
|
||||
return EINVAL;
|
||||
}
|
||||
let Some(data) = (unsafe { byte_slice(bytes, len) }) else {
|
||||
return EINVAL;
|
||||
};
|
||||
let Ok(desc) = gv11b_fw::parse_falcon_desc(data) else {
|
||||
return EINVAL;
|
||||
};
|
||||
if !out_imem_offset.is_null() {
|
||||
unsafe { out_imem_offset.write(desc.imem_offset) };
|
||||
}
|
||||
if !out_entry.is_null() {
|
||||
unsafe { out_entry.write(desc.entry_point) };
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn nv_rs_gv11b_validate_pmu_desc(
|
||||
bytes: *const u8,
|
||||
len: usize,
|
||||
image_len: usize,
|
||||
out_image_size: *mut u32,
|
||||
) -> i32 {
|
||||
if !valid_opt_out(out_image_size) {
|
||||
return EINVAL;
|
||||
}
|
||||
let Some(data) = (unsafe { byte_slice(bytes, len) }) else {
|
||||
return EINVAL;
|
||||
};
|
||||
let Ok(desc) = gv11b_fw::parse_pmu_desc(data) else {
|
||||
return EINVAL;
|
||||
};
|
||||
let Some(min_img) = desc.required_image_bytes() else {
|
||||
return EINVAL;
|
||||
};
|
||||
if image_len < min_img || (image_len & 3) != 0 {
|
||||
return EINVAL;
|
||||
}
|
||||
if !out_image_size.is_null() {
|
||||
unsafe { out_image_size.write(desc.image_size) };
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn nv_rs_gv11b_validate_netlist(
|
||||
bytes: *const u8,
|
||||
len: usize,
|
||||
out_regions: *mut u32,
|
||||
) -> i32 {
|
||||
if !valid_opt_out(out_regions) {
|
||||
return EINVAL;
|
||||
}
|
||||
let Some(data) = (unsafe { byte_slice(bytes, len) }) else {
|
||||
return EINVAL;
|
||||
};
|
||||
let Ok(net) = gv11b_fw::parse_netlist(data) else {
|
||||
return EINVAL;
|
||||
};
|
||||
if !out_regions.is_null() {
|
||||
unsafe { out_regions.write(net.region_count()) };
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn nv_rs_gv11b_encode_bar2_bind(inst_dma: u64, out_reg: *mut u32) -> i32 {
|
||||
if out_reg.is_null() || !out_reg.is_aligned() {
|
||||
return EINVAL;
|
||||
}
|
||||
let Ok(reg) = bar2::encode_gv11b_sysmem_bind(inst_dma) else {
|
||||
return EINVAL;
|
||||
};
|
||||
unsafe { out_reg.write(reg) };
|
||||
0
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use core::ptr;
|
||||
|
||||
fn put_u32(buf: &mut [u8], offset: usize, value: u32) {
|
||||
buf[offset..offset + 4].copy_from_slice(&value.to_le_bytes());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ffi_validates_acr_falcon_pmu_netlist_and_bar2() {
|
||||
let mut acr = [0u8; 24832];
|
||||
for (i, w) in [0x10de, 1, 0x6100, 0x100, 0x200, 0x5f00]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
put_u32(&mut acr, i * 4, w);
|
||||
}
|
||||
let mut off = 0u32;
|
||||
let mut sz = 0u32;
|
||||
unsafe {
|
||||
assert_eq!(
|
||||
nv_rs_gv11b_validate_acr(acr.as_ptr(), acr.len(), &mut off, &mut sz),
|
||||
0
|
||||
);
|
||||
assert_eq!(off, 0x200);
|
||||
assert_eq!(sz, 0x5f00);
|
||||
assert_eq!(
|
||||
nv_rs_gv11b_validate_acr(ptr::null(), 24832, &mut off, &mut sz),
|
||||
EINVAL
|
||||
);
|
||||
}
|
||||
|
||||
let mut fecs = [0u8; gv11b_fw::FALCON_CTXSW_DESC_FILE_BYTES];
|
||||
put_u32(&mut fecs, 0x04, 0x100);
|
||||
put_u32(&mut fecs, 0x08, 0x7e00);
|
||||
put_u32(&mut fecs, 0x0c, 0x7e00);
|
||||
let mut imem = 0u32;
|
||||
let mut entry = 0u32;
|
||||
unsafe {
|
||||
assert_eq!(
|
||||
nv_rs_gv11b_validate_falcon_desc(fecs.as_ptr(), fecs.len(), &mut imem, &mut entry),
|
||||
0
|
||||
);
|
||||
assert_eq!(imem, 0x7e00);
|
||||
assert_eq!(entry, 0x7e00);
|
||||
assert_eq!(
|
||||
nv_rs_gv11b_validate_falcon_desc(fecs.as_ptr(), 16, &mut imem, &mut entry),
|
||||
EINVAL
|
||||
);
|
||||
}
|
||||
|
||||
let mut desc = [0u8; gv11b_fw::PMU_UCODE_DESC_BYTES];
|
||||
put_u32(&mut desc, 0x00, 0x290);
|
||||
put_u32(&mut desc, 0x04, 0x400);
|
||||
put_u32(&mut desc, 0x54, 0x100);
|
||||
put_u32(&mut desc, 0x58, 0x5e00);
|
||||
put_u32(&mut desc, 0x5c, 0x5e00);
|
||||
put_u32(&mut desc, 0x64, 0x400);
|
||||
let mut img_sz = 0u32;
|
||||
unsafe {
|
||||
assert_eq!(
|
||||
nv_rs_gv11b_validate_pmu_desc(desc.as_ptr(), desc.len(), 0x400, &mut img_sz),
|
||||
0
|
||||
);
|
||||
assert_eq!(img_sz, 0x400);
|
||||
assert_eq!(
|
||||
nv_rs_gv11b_validate_pmu_desc(desc.as_ptr(), desc.len(), 0x3fc, &mut img_sz),
|
||||
EINVAL
|
||||
);
|
||||
}
|
||||
|
||||
let mut net = [0u8; 24];
|
||||
put_u32(&mut net, 4, 1);
|
||||
put_u32(&mut net, 8, 1);
|
||||
put_u32(&mut net, 12, 4);
|
||||
put_u32(&mut net, 16, 20);
|
||||
let mut regions = 0u32;
|
||||
unsafe {
|
||||
assert_eq!(
|
||||
nv_rs_gv11b_validate_netlist(net.as_ptr(), net.len(), &mut regions),
|
||||
0
|
||||
);
|
||||
assert_eq!(regions, 1);
|
||||
}
|
||||
|
||||
let mut reg = 0u32;
|
||||
let mut aligned = [0u32; 2];
|
||||
unsafe {
|
||||
let bad = aligned.as_mut_ptr().cast::<u8>().add(1).cast::<u32>();
|
||||
assert_eq!(nv_rs_gv11b_encode_bar2_bind(0x8000_0000, &mut reg), 0);
|
||||
assert_eq!(reg, 0xe008_0000);
|
||||
assert_eq!(nv_rs_gv11b_encode_bar2_bind(0, &mut reg), EINVAL);
|
||||
assert_eq!(nv_rs_gv11b_encode_bar2_bind(1u64 << 40, &mut reg), EINVAL);
|
||||
assert_eq!(nv_rs_gv11b_encode_bar2_bind(0x8000_0000, ptr::null_mut()), EINVAL);
|
||||
assert_eq!(nv_rs_gv11b_encode_bar2_bind(0x8000_0000, bad), EINVAL);
|
||||
assert_eq!(nv_rs_gv11b_validate_acr(acr.as_ptr(), acr.len(), &mut off, bad), EINVAL);
|
||||
assert_eq!(
|
||||
nv_rs_gv11b_validate_acr(acr.as_ptr(), (isize::MAX as usize) + 1, &mut off, &mut img_sz),
|
||||
EINVAL
|
||||
);
|
||||
assert_eq!(nv_rs_gv11b_validate_falcon_desc(fecs.as_ptr(), fecs.len(), bad, &mut entry), EINVAL);
|
||||
assert_eq!(nv_rs_gv11b_validate_pmu_desc(desc.as_ptr(), desc.len(), 0x400, bad), EINVAL);
|
||||
assert_eq!(nv_rs_gv11b_validate_netlist(net.as_ptr(), net.len(), bad), EINVAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -62,6 +62,8 @@ mod gsp_bringup;
|
||||
#[cfg(not(nv_rs_edu_guest))]
|
||||
mod gsp_route;
|
||||
#[allow(dead_code)]
|
||||
mod gv11b_platform;
|
||||
#[allow(dead_code)]
|
||||
mod hypervisor;
|
||||
#[allow(dead_code)]
|
||||
mod instance;
|
||||
|
||||
@ -24,6 +24,137 @@ pub const GV11B_NETLIST_LIMITS: Limits = Limits {
|
||||
max_regions: 64,
|
||||
};
|
||||
|
||||
/// Expected byte length of Xavier Falcon RSA signature files (`pmu_sig.bin`, `fecs_sig.bin`, `gpccs_sig.bin`).
|
||||
pub const FALCON_SIG_BYTES: usize = 108;
|
||||
|
||||
/// Maximum bounded size for `pmu_bl.bin` container validation.
|
||||
pub const PMU_BL_MAX_BYTES: usize = 64 * 1024;
|
||||
|
||||
/// Canonical Linux `/lib/firmware/` relative paths required for Tegra194 `GV11B` bring-up.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Gv11bFwFile {
|
||||
AcrUcodeProd = 0,
|
||||
PmuBl = 1,
|
||||
PmuSig = 2,
|
||||
PmuUcodeDesc = 3,
|
||||
PmuUcodeImage = 4,
|
||||
Fecs = 5,
|
||||
FecsSig = 6,
|
||||
Gpccs = 7,
|
||||
GpccsSig = 8,
|
||||
NetlistA = 9,
|
||||
}
|
||||
|
||||
impl Gv11bFwFile {
|
||||
/// Ordered set of all 10 required `GV11B` firmware assets.
|
||||
pub const ALL_REQUIRED: [Self; 10] = [
|
||||
Self::AcrUcodeProd,
|
||||
Self::PmuBl,
|
||||
Self::PmuSig,
|
||||
Self::PmuUcodeDesc,
|
||||
Self::PmuUcodeImage,
|
||||
Self::Fecs,
|
||||
Self::FecsSig,
|
||||
Self::Gpccs,
|
||||
Self::GpccsSig,
|
||||
Self::NetlistA,
|
||||
];
|
||||
|
||||
/// Relative firmware path passed to Linux `request_firmware()`.
|
||||
pub const fn path(self) -> &'static str {
|
||||
match self {
|
||||
Self::AcrUcodeProd => "gv11b/acr_ucode_prod.bin",
|
||||
Self::PmuBl => "gv11b/pmu_bl.bin",
|
||||
Self::PmuSig => "gv11b/pmu_sig.bin",
|
||||
Self::PmuUcodeDesc => "gv11b/gpmu_ucode_desc.bin",
|
||||
Self::PmuUcodeImage => "gv11b/gpmu_ucode_image.bin",
|
||||
Self::Fecs => "gv11b/fecs.bin",
|
||||
Self::FecsSig => "gv11b/fecs_sig.bin",
|
||||
Self::Gpccs => "gv11b/gpccs.bin",
|
||||
Self::GpccsSig => "gv11b/gpccs_sig.bin",
|
||||
Self::NetlistA => "gv11b/NETA_img.bin",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Errors returned by [`validate_fw_bundle`].
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum BundleError {
|
||||
Acr(Error),
|
||||
PmuBl(Error),
|
||||
SigInvalidLen(Gv11bFwFile),
|
||||
PmuDesc(Error),
|
||||
PmuImageSize,
|
||||
Fecs(Error),
|
||||
Gpccs(Error),
|
||||
Netlist(gr_netlist::Error),
|
||||
}
|
||||
|
||||
/// Validated metadata extracted from a complete 10-blob `GV11B` firmware set.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Gv11bFwBundleSummary {
|
||||
pub acr_data_size: u32,
|
||||
pub pmu_bl_data_size: u32,
|
||||
pub pmu_app_version: u32,
|
||||
pub pmu_image_size: u32,
|
||||
pub fecs_entry_point: u32,
|
||||
pub gpccs_entry_point: u32,
|
||||
pub netlist_regions: u32,
|
||||
}
|
||||
|
||||
/// Validates a complete 10-blob `GV11B` firmware bundle without allocating or copying payloads.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn validate_fw_bundle(
|
||||
acr_ucode_prod: &[u8],
|
||||
pmu_bl: &[u8],
|
||||
pmu_sig: &[u8],
|
||||
pmu_desc: &[u8],
|
||||
pmu_image: &[u8],
|
||||
fecs: &[u8],
|
||||
fecs_sig: &[u8],
|
||||
gpccs: &[u8],
|
||||
gpccs_sig: &[u8],
|
||||
netlist_a: &[u8],
|
||||
) -> Result<Gv11bFwBundleSummary, BundleError> {
|
||||
let acr = parse_acr_header(acr_ucode_prod).map_err(BundleError::Acr)?;
|
||||
if pmu_bl.len() > PMU_BL_MAX_BYTES {
|
||||
return Err(BundleError::PmuBl(Error::InvalidSize));
|
||||
}
|
||||
let bl = parse_acr_header(pmu_bl).map_err(BundleError::PmuBl)?;
|
||||
if (bl.data_size & 3) != 0 {
|
||||
return Err(BundleError::PmuBl(Error::InvalidSize));
|
||||
}
|
||||
if pmu_sig.len() != FALCON_SIG_BYTES {
|
||||
return Err(BundleError::SigInvalidLen(Gv11bFwFile::PmuSig));
|
||||
}
|
||||
if fecs_sig.len() != FALCON_SIG_BYTES {
|
||||
return Err(BundleError::SigInvalidLen(Gv11bFwFile::FecsSig));
|
||||
}
|
||||
if gpccs_sig.len() != FALCON_SIG_BYTES {
|
||||
return Err(BundleError::SigInvalidLen(Gv11bFwFile::GpccsSig));
|
||||
}
|
||||
let pmu = parse_pmu_desc(pmu_desc).map_err(BundleError::PmuDesc)?;
|
||||
let Some(min_img) = pmu.required_image_bytes() else {
|
||||
return Err(BundleError::PmuDesc(Error::InvalidBounds));
|
||||
};
|
||||
if pmu_image.len() < min_img || (pmu_image.len() & 3) != 0 {
|
||||
return Err(BundleError::PmuImageSize);
|
||||
}
|
||||
let fecs_hdr = parse_falcon_desc(fecs).map_err(BundleError::Fecs)?;
|
||||
let gpccs_hdr = parse_falcon_desc(gpccs).map_err(BundleError::Gpccs)?;
|
||||
let net = parse_netlist(netlist_a).map_err(BundleError::Netlist)?;
|
||||
|
||||
Ok(Gv11bFwBundleSummary {
|
||||
acr_data_size: acr.data_size,
|
||||
pmu_bl_data_size: bl.data_size,
|
||||
pmu_app_version: pmu.app_version,
|
||||
pmu_image_size: pmu.image_size,
|
||||
fecs_entry_point: fecs_hdr.entry_point,
|
||||
gpccs_entry_point: gpccs_hdr.entry_point,
|
||||
netlist_regions: net.region_count(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Hardware/platform bring-up capabilities for Tegra194 internal `GV11B`.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Gv11bBringupPolicy {
|
||||
@ -125,6 +256,17 @@ pub struct PmuUcodeDesc {
|
||||
pub compressed: u32,
|
||||
}
|
||||
|
||||
impl PmuUcodeDesc {
|
||||
/// Minimum required byte length of `gpmu_ucode_image.bin` covering `image_size`,
|
||||
/// the bootloader segment, and the app segment.
|
||||
pub fn required_image_bytes(&self) -> Option<usize> {
|
||||
let bl_end =
|
||||
(self.bootloader_start_offset as usize).checked_add(self.bootloader_size as usize)?;
|
||||
let app_end = (self.app_start_offset as usize).checked_add(self.app_size as usize)?;
|
||||
Some((self.image_size as usize).max(bl_end).max(app_end))
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn read_u32_le(bytes: &[u8], offset: usize) -> Option<u32> {
|
||||
let slice = bytes.get(offset..offset.checked_add(4)?)?;
|
||||
Some(u32::from_le_bytes([slice[0], slice[1], slice[2], slice[3]]))
|
||||
@ -489,4 +631,131 @@ mod tests {
|
||||
put_u32(&mut bad, 4, 65);
|
||||
assert_eq!(parse_netlist(&bad).err(), Some(gr_netlist::Error::Budget));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fw_bundle_validates_all_ten_assets_and_rejects_bad_inputs() {
|
||||
assert_eq!(Gv11bFwFile::ALL_REQUIRED.len(), 10);
|
||||
assert_eq!(Gv11bFwFile::AcrUcodeProd.path(), "gv11b/acr_ucode_prod.bin");
|
||||
assert_eq!(Gv11bFwFile::NetlistA.path(), "gv11b/NETA_img.bin");
|
||||
|
||||
let mut acr = [0u8; 24832];
|
||||
for (i, w) in [0x10de, 1, 0x6100, 0x100, 0x200, 0x5f00]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
put_u32(&mut acr, i * 4, w);
|
||||
}
|
||||
let mut bl = [0u8; 1280];
|
||||
for (i, w) in [0x10de, 1, 0x500, 0x100, 0x200, 0x300]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
put_u32(&mut bl, i * 4, w);
|
||||
}
|
||||
let sig = [0xa5u8; FALCON_SIG_BYTES];
|
||||
let mut pmu_desc = [0u8; PMU_UCODE_DESC_BYTES];
|
||||
put_u32(&mut pmu_desc, 0x00, 0x290);
|
||||
put_u32(&mut pmu_desc, 0x04, 0x400);
|
||||
put_u32(&mut pmu_desc, 0x08, 2);
|
||||
put_u32(&mut pmu_desc, 0x0c, 0x17d_8e8f);
|
||||
put_u32(&mut pmu_desc, 0x50, 0);
|
||||
put_u32(&mut pmu_desc, 0x54, 0x100);
|
||||
put_u32(&mut pmu_desc, 0x58, 0x5e00);
|
||||
put_u32(&mut pmu_desc, 0x5c, 0x5e00);
|
||||
put_u32(&mut pmu_desc, 0x60, 0x200);
|
||||
put_u32(&mut pmu_desc, 0x64, 0x400);
|
||||
let pmu_img = [0u8; 0x600];
|
||||
|
||||
let mut fecs = [0u8; FALCON_CTXSW_DESC_FILE_BYTES];
|
||||
put_u32(&mut fecs, 0x04, 0x100);
|
||||
put_u32(&mut fecs, 0x08, 0x7e00);
|
||||
put_u32(&mut fecs, 0x0c, 0x7e00);
|
||||
|
||||
let mut gpccs = [0u8; FALCON_CTXSW_DESC_FILE_BYTES];
|
||||
put_u32(&mut gpccs, 0x04, 0x100);
|
||||
put_u32(&mut gpccs, 0x08, 0x3400);
|
||||
put_u32(&mut gpccs, 0x0c, 0x3400);
|
||||
|
||||
let mut net = [0u8; 24];
|
||||
put_u32(&mut net, 4, 1);
|
||||
put_u32(&mut net, 8, 1);
|
||||
put_u32(&mut net, 12, 4);
|
||||
put_u32(&mut net, 16, 20);
|
||||
|
||||
let summary = validate_fw_bundle(
|
||||
&acr, &bl, &sig, &pmu_desc, &pmu_img, &fecs, &sig, &gpccs, &sig, &net,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(summary.acr_data_size, 0x5f00);
|
||||
assert_eq!(summary.pmu_bl_data_size, 0x300);
|
||||
assert_eq!(summary.pmu_app_version, 0x17d_8e8f);
|
||||
assert_eq!(summary.pmu_image_size, 0x400);
|
||||
assert_eq!(summary.fecs_entry_point, 0x7e00);
|
||||
assert_eq!(summary.gpccs_entry_point, 0x3400);
|
||||
assert_eq!(summary.netlist_regions, 1);
|
||||
|
||||
assert_eq!(
|
||||
validate_fw_bundle(
|
||||
&acr,
|
||||
&bl,
|
||||
&sig[..100],
|
||||
&pmu_desc,
|
||||
&pmu_img,
|
||||
&fecs,
|
||||
&sig,
|
||||
&gpccs,
|
||||
&sig,
|
||||
&net,
|
||||
),
|
||||
Err(BundleError::SigInvalidLen(Gv11bFwFile::PmuSig))
|
||||
);
|
||||
assert_eq!(
|
||||
validate_fw_bundle(
|
||||
&acr,
|
||||
&bl,
|
||||
&sig,
|
||||
&pmu_desc,
|
||||
&pmu_img[..0x3fc],
|
||||
&fecs,
|
||||
&sig,
|
||||
&gpccs,
|
||||
&sig,
|
||||
&net,
|
||||
),
|
||||
Err(BundleError::PmuImageSize)
|
||||
);
|
||||
assert_eq!(
|
||||
validate_fw_bundle(
|
||||
&acr,
|
||||
&bl,
|
||||
&sig,
|
||||
&pmu_desc,
|
||||
&pmu_img[..0x5fc],
|
||||
&fecs,
|
||||
&sig,
|
||||
&gpccs,
|
||||
&sig,
|
||||
&net,
|
||||
),
|
||||
Err(BundleError::PmuImageSize)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pmu_desc_rejects_segment_offset_overflow() {
|
||||
let mut pmu_desc = [0u8; PMU_UCODE_DESC_BYTES];
|
||||
put_u32(&mut pmu_desc, 0x00, 0x290);
|
||||
put_u32(&mut pmu_desc, 0x04, 0x400);
|
||||
put_u32(&mut pmu_desc, 0x50, u32::MAX - 0x10);
|
||||
put_u32(&mut pmu_desc, 0x54, 0x100);
|
||||
put_u32(&mut pmu_desc, 0x58, 0x5e00);
|
||||
put_u32(&mut pmu_desc, 0x5c, 0x5e00);
|
||||
put_u32(&mut pmu_desc, 0x60, 0);
|
||||
put_u32(&mut pmu_desc, 0x64, 0x200);
|
||||
assert_eq!(parse_pmu_desc(&pmu_desc), Err(Error::InvalidBounds));
|
||||
|
||||
put_u32(&mut pmu_desc, 0x50, 0);
|
||||
put_u32(&mut pmu_desc, 0x60, u32::MAX - 0x10);
|
||||
assert_eq!(parse_pmu_desc(&pmu_desc), Err(Error::InvalidBounds));
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,6 +38,25 @@ pub fn encode_bind(mode: BindMode, instance: Option<InstanceLocation>) -> Result
|
||||
};
|
||||
Ok(0xc0000000 | (target << 28) | ((instance.address >> 12) as u32))
|
||||
}
|
||||
|
||||
/// Encodes `NV_PBUS_BAR2_BLOCK` (`0x1714`) for Tegra194 unified-sysmem `GV11B`.
|
||||
///
|
||||
/// `GV11B` has no dedicated VRAM (`GV11B_POLICY.has_vram == false`), so the BAR2
|
||||
/// instance block lives in coherent system memory (`Aperture::SystemCoherent`)
|
||||
/// within the 40-bit Tegra194 DMA address space. Rejects zero, misaligned, and
|
||||
/// `>= 1 << 40` DMA addresses.
|
||||
pub fn encode_gv11b_sysmem_bind(inst_dma: u64) -> Result<u32, Error> {
|
||||
if inst_dma == 0 {
|
||||
return Err(Error::InstanceAddress);
|
||||
}
|
||||
encode_bind(
|
||||
BindMode::Virtual,
|
||||
Some(InstanceLocation {
|
||||
address: inst_dma,
|
||||
aperture: super::ramin::Aperture::SystemCoherent,
|
||||
}),
|
||||
)
|
||||
}
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Level {
|
||||
pub low: u8,
|
||||
|
||||
@ -182,3 +182,18 @@ fn complete_original_bind_register_words_match_and_unsafe_truncation_is_rejected
|
||||
}
|
||||
assert_eq!(encode_bind(BindMode::Physical, None), Ok(0x40000000));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gv11b_sysmem_bar2_bind_enforces_coherent_40bit_dma_and_alignment() {
|
||||
assert_eq!(encode_gv11b_sysmem_bind(0x1_2345_0000), Ok(0xe012_3450));
|
||||
assert_eq!(
|
||||
encode_gv11b_sysmem_bind((1u64 << 40) - 4096),
|
||||
Ok(0xefff_ffff)
|
||||
);
|
||||
for invalid in [0u64, 1, 2048, 0x1_0000_0001, 1u64 << 40, u64::MAX - 4095] {
|
||||
assert_eq!(
|
||||
encode_gv11b_sysmem_bind(invalid),
|
||||
Err(Error::InstanceAddress)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user