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/omega-gpu-driver/blob/main/gsp/sim.om # omega-gpu-driver aien-dev/omega-gpu-driver 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 `omega-gpu-driver / gsp / sim.om` 332 lines ยท 7069 bytes Raw Blame History 1 note gsp/sim.om: a simulated GB10B SEC2 + GSP falcon for host tests of gsp/mmio.om. NOT the chip. 2 note Port of aien-dev/aienux PR #441 native/kernel/gpu/gsp_sim.{h,c}. Models only what the driver source 3 note says the host sees on BAR0 during GSP start-up: SEC2 EMEM channel 0 (1 KiB, EMEMC/EMEMD with write 4 note auto-increment), its queue HEAD/TAIL and MAILBOX0/1, and the GSP falcon's MAILBOX0/1, HWCFG2 5 note (target-mask pattern, lockdown bit 13), FALCON_OS, RISC-V CPUCTL and QUEUE_HEAD(0). Time is counted 6 note in reads of the polled register. Every access is logged in order (first 1024 kept, all counted); 7 note accesses the driver never makes, and orders it never uses, are violations. SIM-CHOICE marks what 8 note the source does not settle. The offsets are this file's own copies (not the driver's), so a wrong 9 note driver constant shows up as a wrong access instead of moving the simulator with it. 10 note Library unit: no main. simrd / simwr are the mode 0 device of gsprd / gspwr. 11 const XS2MB0 ulong `8650816` 12 const XS2MB1 ulong `8650820` 13 const XS2EMC ulong `8653504` 14 const XS2EMD ulong `8653508` 15 const XS2QH ulong `8653824` 16 const XS2QT ulong `8653828` 17 const XGMB0 ulong `1114176` 18 const XGMB1 ulong `1114180` 19 const XGOS ulong `1114240` 20 const XGHWCF2 ulong `1114356` 21 const XGQH ulong `1117184` 22 const XGCPUCT ulong `1119112` 23 note AINCW 1<<24, busy 0xc001cafe, lockdown 1<<13, active 1<<7, a wait that never ends 0xFFFFFFFF 24 const XAINCW ulong `16777216` 25 const XBUSY ulong `3221342974` 26 const XLOCK ulong 8192 27 const XACT ulong 128 28 const XM32 ulong `4294967295` 29 const NOEND ulong `4294967295` 30 const LOGMAX ulong 1024 31 note config (struct ck_gspsim_cfg), set by the caller before siminit: scfg 32 note 0 busy_reads, 1 cmd_reads, 2 mask_reads, 3 args_reads, 4 lockdown_reads, 5 fmc_error, 6 riscv_dead, 33 note 7 emem_no_inc, 8 fmc_args_pa, 9 hwcfg2_zero_reads 34 global scfg ulong 10 35 global semem ulong 256 36 note runtime PM state of the simulated device, set by the caller: 0 active, 1 suspended (D3). 37 note siminit leaves it alone. Any access while suspended counts as a violation. 38 global spm ulong 1 39 note Test-only selected packet family; zero preserves GB10B independent oracle cases. 40 global sprof ulong 1 41 fn simpmok to bool 42 ret eq get spm 0 0 43 end 44 note state words: ss[i] 45 const SEMEMC ulong 0 46 const SQHEAD ulong 1 47 const SQTAIL ulong 2 48 const SS2MB0 ulong 3 49 const SS2MB1 ulong 4 50 const SGMB0 ulong 5 51 const SGMB1 ulong 6 52 const SHWCFG2 ulong 7 53 const SOS ulong 8 54 const SCPUCTL ulong 9 55 const SGQHW ulong 10 56 note phase: 0 idle, 1 command posted, 2 handled (mask), 3 FMC running (lockdown), 4 released, 9 rejected 57 const SPHASE ulong 11 58 const SLEFT ulong 12 59 const SZLEFT ulong 13 60 const SPKTOK ulong 14 61 const SOSPH ulong 15 62 const SNLOG ulong 16 63 const SVIOL ulong 17 64 global ss ulong 18 65 global slogo ulong 1024 66 global slogv ulong 1024 67 global slogw uchar 1024 68 fn sg i ulong to ulong 69 ret get ss i 70 end 71 fn sp i ulong v ulong to void 72 put ss i v 73 end 74 fn sviol to void 75 sp SVIOL add sg SVIOL 1 76 end 77 note a countdown word: 0 stays (the caller acts on 0), NOEND stays, anything else drops by one 78 fn sdec i ulong to void 79 l = sg i 80 if and ne l 0 ne l NOEND 81 sp i sub l 1 82 end 83 end 84 fn slog off ulong v ulong w uchar to void 85 n = sg SNLOG 86 if lt n LOGMAX 87 put slogo n off 88 put slogv n v 89 put slogw n w 90 end 91 sp SNLOG add n 1 92 end 93 fn siminit to void 94 for i ulong 18 95 sp i 0 96 end 97 for j ulong 256 98 put semem j 0 99 end 100 note an old message in the channel: HEAD != TAIL until busy_reads HEAD reads have passed 101 if ne get scfg 0 0 102 sp SQHEAD 0 103 sp SQTAIL 16 104 end 105 note SIM-CHOICE: target locked to SEC2, low byte 0xA7 (0xBADF41A7); idle SEC2 MAILBOX0 0 106 sp SHWCFG2 `3135193511` 107 sp SS2MB0 0 108 sp SLEFT get scfg 0 109 end 110 note SEC2 checks the GB10B HAL constant MCTP dword 1, NVDM 0x1410DE7E, payload version 1, size 860, 111 note TAIL 864. Anything else (SIM-CHOICE): consumed, the target mask is never released. 112 fn simpkt to bool 113 if eq get sprof 0 2 114 a = and eq sg SQTAIL 864 eq get semem 0 `3221225472` 115 b = and eq get semem 1 `336649854` eq and get semem 2 65535 2 116 ret and and a b eq shr get semem 2 16 860 117 end 118 a = and eq sg SQTAIL 864 eq get semem 0 1 119 b = and eq get semem 1 `336649854` eq and get semem 2 65535 1 120 ret and and a b eq shr get semem 2 16 860 121 end 122 fn srqh to ulong 123 if and eq sg SPHASE 0 ne sg SQHEAD sg SQTAIL 124 if eq sg SLEFT 0 125 sp SQHEAD sg SQTAIL 126 else 127 sdec SLEFT 128 end 129 end 130 ret sg SQHEAD 131 end 132 fn srmb0 to ulong 133 if eq sg SPHASE 1 134 if eq sg SLEFT 0 135 sp SS2MB0 0 136 sp SQHEAD sg SQTAIL 137 if ne sg SPKTOK 0 138 sp SPHASE 2 139 sp SLEFT get scfg 2 140 sp SZLEFT get scfg 9 141 else 142 sp SPHASE 9 143 end 144 else 145 sdec SLEFT 146 end 147 end 148 ret sg SS2MB0 149 end 150 fn srfmc to void 151 if eq sg SLEFT 0 152 if ne get scfg 5 0 153 sp SGMB0 get scfg 5 154 else 155 sp SHWCFG2 and sg SHWCFG2 not XLOCK 156 sp SPHASE 4 157 if eq get scfg 6 0 158 sp SCPUCTL XACT 159 end 160 end 161 else 162 sdec SLEFT 163 end 164 end 165 fn srhw to ulong 166 ph = sg SPHASE 167 if and eq ph 2 ne sg SZLEFT 0 168 sdec SZLEFT 169 ret 0 170 end 171 if eq ph 2 172 if eq sg SLEFT 0 173 sp SPHASE 3 174 note SIM-CHOICE: other HWCFG2 bits 0x5, so HWCFG2 = 0x2005 175 sp SHWCFG2 or XLOCK 5 176 pa = get scfg 8 177 sp SGMB0 and pa XM32 178 sp SGMB1 shr pa 32 179 sp SLEFT get scfg 4 180 else 181 sdec SLEFT 182 end 183 else 184 if and eq ph 3 ne sg SGMB0 and get scfg 8 XM32 185 srfmc 186 end 187 end 188 ret sg SHWCFG2 189 end 190 fn srgmb0 to ulong 191 if and eq sg SPHASE 3 eq sg SGMB0 and get scfg 8 XM32 192 a = get scfg 3 193 if ne a NOEND 194 if eq a 0 195 sp SGMB0 0 196 sp SGMB1 0 197 else 198 put scfg 3 sub a 1 199 end 200 end 201 end 202 ret sg SGMB0 203 end 204 fn simrd off ulong to ulong 205 if ne get spm 0 0 206 sviol 207 end 208 v = ulong 0 209 if eq off XS2QH 210 v = srqh 211 else 212 if eq off XS2QT 213 v = sg SQTAIL 214 else 215 if eq off XS2EMC 216 v = sg SEMEMC 217 else 218 if eq off XS2EMD 219 e = sg SEMEMC 220 v = get semem and add mul and shr e 8 255 64 and shr e 2 63 255 221 else 222 if eq off XS2MB0 223 v = srmb0 224 else 225 if eq off XS2MB1 226 v = sg SS2MB1 227 else 228 if eq off XGHWCF2 229 v = srhw 230 else 231 if eq off XGMB0 232 v = srgmb0 233 else 234 if eq off XGMB1 235 v = sg SGMB1 236 else 237 if eq off XGOS 238 v = sg SOS 239 else 240 if eq off XGCPUCT 241 v = sg SCPUCTL 242 else 243 sviol 244 end 245 end 246 end 247 end 248 end 249 end 250 end 251 end 252 end 253 end 254 end 255 slog off v 0 256 ret v 257 end 258 fn swememd val ulong to void 259 e = sg SEMEMC 260 dw = add mul and shr e 8 255 64 and shr e 2 63 261 if or or eq and e XAINCW 0 ge dw 256 ne sg SPHASE 0 262 sviol 263 ret 264 end 265 put semem dw val 266 if eq get scfg 7 0 267 dw = add dw 1 268 note EMEMC keeps all but bits 2..15 (mask ~0xFFFC = 0xFFFF0003), then block << 8 | offset << 2 269 sp SEMEMC or or and e `4294901763` shl and div dw 64 255 8 shl rem dw 64 2 270 end 271 end 272 fn swqh val ulong to void 273 ph = sg SPHASE 274 note the doorbell: TAIL must already point at the last dword of a message starting at 0 275 if or or ne ph 0 ne val 0 eq sg SQTAIL sg SQHEAD 276 sviol 277 end 278 sp SQHEAD val 279 if eq ph 0 280 if simpkt 281 sp SPKTOK 1 282 else 283 sp SPKTOK 0 284 end 285 sp SPHASE 1 286 sp SS2MB0 XBUSY 287 sp SLEFT get scfg 1 288 end 289 end 290 fn simwr off ulong val ulong to void 291 if ne get spm 0 0 292 sviol 293 end 294 slog off val 1 295 if eq off XS2EMC 296 sp SEMEMC val 297 ret 298 end 299 if eq off XS2EMD 300 swememd val 301 ret 302 end 303 if eq off XS2QT 304 note the driver writes only into an empty channel 305 if or ne sg SPHASE 0 ne sg SQHEAD sg SQTAIL 306 sviol 307 end 308 sp SQTAIL val 309 ret 310 end 311 if eq off XS2QH 312 swqh val 313 ret 314 end 315 if eq off XGOS 316 sp SOS val 317 sp SOSPH sg SPHASE 318 note FALCON_OS before lockdown release 319 if ne sg SPHASE 4 320 sviol 321 end 322 ret 323 end 324 if eq off XGQH 325 sp SGQHW add sg SGQHW 1 326 if ne val 0 327 sviol 328 end 329 ret 330 end 331 sviol 332 end