Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/crates/aienos-accel/src/lib.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / crates / aienos-accel / src / lib.rs` 198 lines ยท 6934 bytes Raw Blame History 1 #![no_std] 2 // SPDX-License-Identifier: Apache-2.0 3 // Copyright 2026 Drake Stapleton (AIEN / aien-dev) 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 use core::fmt::Write; 18 19 pub mod pci; 20 pub mod profile; 21 pub mod registers; 22 23 /// PCI identity observed for the GB10 GPU in the DGX Spark. 24 pub const NVIDIA_VENDOR_ID: u16 = 0x10de; 25 pub const GB10_DEVICE_ID: u16 = 0x2e12; 26 /// Read-only PMC registers used by the Linux Nova driver for identification. 27 pub const PMC_BOOT_0: u64 = 0; 28 pub const PMC_BOOT_42: u64 = 0x0a00; 29 30 /// PCI location and BAR0 discovered before firmware boot services are exited. 31 #[derive(Clone, Copy, Debug, PartialEq, Eq)] 32 pub struct PciLocation { 33 pub segment: u32, 34 pub bus: u8, 35 pub device: u8, 36 pub function: u8, 37 } 38 39 /// PCI location and BAR0 discovered before firmware boot services are exited. 40 #[derive(Clone, Copy, Debug, PartialEq, Eq)] 41 pub struct Gb10Bar { 42 pub location: PciLocation, 43 pub physical_base: u64, 44 } 45 46 impl Gb10Bar { 47 /// Accept only a matching GB10 function with a programmed 64-bit memory BAR. 48 pub fn from_config( 49 location: PciLocation, 50 vendor_device: u32, 51 command_status: u32, 52 bar0_low: u32, 53 bar0_high: u32, 54 ) -> Option { 55 if vendor_device != (u32::from(GB10_DEVICE_ID) << 16 | u32::from(NVIDIA_VENDOR_ID)) 56 || command_status & 0x2 == 0 57 || bar0_low & 0x7 != 0x4 58 { 59 return None; 60 } 61 let physical_base = (u64::from(bar0_high) << 32) | u64::from(bar0_low & !0xf); 62 if physical_base == 0 || physical_base.checked_add(PMC_BOOT_42 + 4).is_none() { 63 return None; 64 } 65 Some(Self { 66 location, 67 physical_base, 68 }) 69 } 70 } 71 72 /// Two GPU register values read through the PCI root bridge before handoff. 73 /// Their presence proves a register transaction was attempted, not GPU compute. 74 #[derive(Clone, Copy, Debug, PartialEq, Eq)] 75 pub struct Gb10Identity { 76 pub bar: Gb10Bar, 77 pub pmc_boot_0: u32, 78 pub pmc_boot_42: u32, 79 } 80 81 /// Outcome for one PCI root bridge during GB10 discovery, carried into the 82 /// boot reports so a missed discovery says why. 83 #[derive(Clone, Copy, Debug, PartialEq, Eq)] 84 pub enum RootBridgeOutcome { 85 /// The firmware refused the open of `PciRootBridgeIo` (status name). 86 OpenRefused(&'static str), 87 Scanned(RootBridgeScan), 88 } 89 90 /// What the scan of one PCI root bridge observed. 91 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] 92 pub struct RootBridgeScan { 93 pub segment: u32, 94 pub devices: u16, 95 pub bridges: u16, 96 /// Bridges with a valid secondary..subordinate bus window. 97 pub windows: u16, 98 /// A GB10 vendor/device match that failed the BAR check: raw 99 /// command/status and BAR0 low/high, so the report shows the BAR state. 100 pub rejected_candidate: Option<(u32, u32, u32)>, 101 } 102 103 /// Report lines explaining why discovery produced no GB10 identity: 104 /// bridges seen, opens refused, segments, bridge windows, and BAR state. 105 /// `handles` is the number of `PciRootBridgeIo` handles, if known. 106 pub fn write_discovery_diagnostics( 107 out: &mut impl Write, 108 handles: Option, 109 roots: &[Option], 110 ) { 111 match handles { 112 Some(n) => { 113 let _ = writeln!(out, "gb10_pci_root_bridges: {n}"); 114 } 115 None => { 116 let _ = writeln!(out, "gb10_pci_root_bridges: lookup failed"); 117 return; 118 } 119 } 120 for (index, outcome) in roots.iter().flatten().enumerate() { 121 match outcome { 122 RootBridgeOutcome::OpenRefused(status) => { 123 let _ = writeln!(out, "gb10_pci_root_open[{index}]: refused ({status})"); 124 } 125 RootBridgeOutcome::Scanned(scan) => { 126 let _ = writeln!( 127 out, 128 "gb10_pci_root[{index}]: segment {} devices {} bridges {} windows {}", 129 scan.segment, scan.devices, scan.bridges, scan.windows 130 ); 131 if let Some((command_status, bar0_low, bar0_high)) = scan.rejected_candidate { 132 let _ = writeln!( 133 out, 134 "gb10_pci_candidate[{index}]: command_status {command_status:#010x} bar0 {bar0_high:#010x}:{bar0_low:#010x}" 135 ); 136 } 137 } 138 } 139 } 140 } 141 142 #[cfg(test)] 143 mod tests { 144 use super::*; 145 extern crate std; 146 use std::string::String; 147 148 #[test] 149 fn validates_gb10_memory_bar() { 150 let location = PciLocation { 151 segment: 15, 152 bus: 1, 153 device: 0, 154 function: 0, 155 }; 156 let bar = Gb10Bar::from_config(location, 0x2e12_10de, 0x6, 0x2400_0004, 0).unwrap(); 157 assert_eq!(bar.physical_base, 0x2400_0000); 158 assert!(Gb10Bar::from_config(location, 0x2e12_10df, 0x6, 0x2400_0004, 0).is_none()); 159 assert!(Gb10Bar::from_config(location, 0x2e12_10de, 0x4, 0x2400_0004, 0).is_none()); 160 assert!(Gb10Bar::from_config(location, 0x2e12_10de, 0x6, 0x2400_0000, 0).is_none()); 161 } 162 163 #[test] 164 fn diagnostics_report_refused_opens_segments_and_bar_state() { 165 let roots = [ 166 Some(RootBridgeOutcome::OpenRefused("ACCESS_DENIED")), 167 Some(RootBridgeOutcome::Scanned(RootBridgeScan { 168 segment: 15, 169 devices: 4, 170 bridges: 1, 171 windows: 1, 172 rejected_candidate: Some((0x10_0004, 0, 0)), 173 })), 174 None, 175 ]; 176 let mut text = String::new(); 177 write_discovery_diagnostics(&mut text, Some(2), &roots); 178 for line in [ 179 "gb10_pci_root_bridges: 2", 180 "gb10_pci_root_open[0]: refused (ACCESS_DENIED)", 181 "gb10_pci_root[1]: segment 15 devices 4 bridges 1 windows 1", 182 "gb10_pci_candidate[1]: command_status 0x00100004 bar0 0x00000000:0x00000000", 183 ] { 184 assert!( 185 text.lines().any(|l| l == line), 186 "missing {line:?} in:\n{text}" 187 ); 188 } 189 190 let mut text = String::new(); 191 write_discovery_diagnostics(&mut text, None, &[None]); 192 assert_eq!(text, "gb10_pci_root_bridges: lookup failed\n"); 193 194 let mut text = String::new(); 195 write_discovery_diagnostics(&mut text, Some(0), &[None]); 196 assert_eq!(text, "gb10_pci_root_bridges: 0\n"); 197 } 198 }