mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 14:38:47 +00:00
Mechanical, behavior-neutral: edition/resolver keys, unsafe extern blocks, unsafe(no_mangle)/unsafe(export_name), unsafe blocks inside unsafe fn, r#gen renames, --edition flags in Makefiles/tools, rustfmt style_edition pinned to 2021 so formatting stays edition-independent, and clippy collapsible_if allowed workspace-wide (let-chain churn). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
114 lines
3.2 KiB
Rust
114 lines
3.2 KiB
Rust
use core::num::NonZeroU32;
|
|
use nv_rs_core::compute::gv100::*;
|
|
unsafe extern "C" {
|
|
fn native_qmd_oracle(
|
|
qmd: *mut u32,
|
|
constants: *mut u32,
|
|
code: u64,
|
|
cb: u64,
|
|
output: u64,
|
|
completion: u64,
|
|
seed: u32,
|
|
payload: u32,
|
|
);
|
|
}
|
|
fn binding(base: u64) -> Bindings {
|
|
Bindings {
|
|
code: base,
|
|
constants: base + 4096,
|
|
output: base + 8192,
|
|
qmd: 0x4000_0000,
|
|
completion: 0x4000_1000,
|
|
}
|
|
}
|
|
#[test]
|
|
fn payload_matches_independent_vendor_header_packing() {
|
|
for base in [
|
|
0x1000_0000,
|
|
0x1_ffff_f000,
|
|
0x1_0000_0000,
|
|
0xff_ffff_f000,
|
|
0x1_ffff_ffff_c000,
|
|
] {
|
|
for seed in [0, 1, 0x12f04321, u32::MAX] {
|
|
for payload in [1, 0xdeadbeef, u32::MAX] {
|
|
let b = binding(base);
|
|
let validated = b.validate().unwrap();
|
|
let (mut qmd, mut constants) =
|
|
([0xa5a5a5a5; QMD_WORDS], [0xa5a5a5a5; CONSTANT_WORDS]);
|
|
write_qmd(&mut qmd, validated, NonZeroU32::new(payload).unwrap());
|
|
write_constants(&mut constants, validated, seed);
|
|
let (mut reference, mut cb) = ([0u32; QMD_WORDS], [0u32; CONSTANT_WORDS]);
|
|
unsafe {
|
|
native_qmd_oracle(
|
|
reference.as_mut_ptr(),
|
|
cb.as_mut_ptr(),
|
|
b.code,
|
|
b.constants,
|
|
b.output,
|
|
b.completion,
|
|
seed,
|
|
payload,
|
|
);
|
|
}
|
|
assert_eq!(qmd, reference);
|
|
assert_eq!(constants, cb);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#[test]
|
|
fn validates_page_namespaces_and_does_not_truncate_addresses() {
|
|
let b = binding(0x1000_0000);
|
|
assert!(b.validate().is_ok());
|
|
for invalid in [
|
|
Bindings { code: 0, ..b },
|
|
Bindings {
|
|
code: b.code + 1,
|
|
..b
|
|
},
|
|
Bindings { code: 1 << 49, ..b },
|
|
Bindings { qmd: 1 << 40, ..b },
|
|
Bindings {
|
|
completion: 1 << 40,
|
|
..b
|
|
},
|
|
Bindings {
|
|
output: b.code,
|
|
..b
|
|
},
|
|
Bindings {
|
|
constants: 0xff00_0000,
|
|
..b
|
|
},
|
|
] {
|
|
assert!(invalid.validate().is_err(), "{invalid:?}");
|
|
}
|
|
}
|
|
#[test]
|
|
fn pushbuffer_targets_pcas_signaling_instead_of_legacy_delta_method() {
|
|
let b = binding(0x1000_0000).validate().unwrap();
|
|
let mut words = [0; PUSH_WORDS];
|
|
write_pushbuffer(&mut words, b, 0).unwrap();
|
|
assert_eq!(
|
|
words,
|
|
[
|
|
0x20010000, 0xc3c0, 0x200200a8, 0, 0xfe000000, 0x200201ec, 0, 0xff000000, 0x200100ad,
|
|
0x400000, 0x200100af, 3
|
|
]
|
|
);
|
|
for channel in 0..8 {
|
|
write_pushbuffer(&mut words, b, channel).unwrap();
|
|
}
|
|
words.fill(0xa5a5a5a5);
|
|
assert!(write_pushbuffer(&mut words, b, 8).is_err());
|
|
assert_eq!(words, [0xa5a5a5a5; PUSH_WORDS]);
|
|
assert_eq!(CODE.len(), 256);
|
|
for index in 0..64 {
|
|
assert_eq!(
|
|
expected_output(0x12f04321, index),
|
|
0x12f04321 ^ index.wrapping_mul(0x9e3779b9)
|
|
);
|
|
}
|
|
}
|