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-mv/blob/main/gpu/driver/gsp/mmio.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / gpu / driver / gsp / mmio.om` 304 lines ยท 8185 bytes Raw Blame History 1 note gsp/mmio.om: the register-level GSP start-up on GB10B in seeded Omega, a port of 2 note aien-dev/aienux PR #441 native/kernel/gpu/gsp_mmio.{h,c} (ck_gsp_mmio_boot, ck_gsp_mmio_notify). 3 note GB10B has no FSP: SEC2 boots the GSP-FMC (open-gpu-kernel-modules 580.173.02, kgspBootstrap_GH100, 4 note kernel_gsp_gh100.c:833-995, SEC2 branch :868-872). The eleven steps: 5 note 1 wait until SEC2 EMEM channel 0 is empty, QUEUE_HEAD(0) == QUEUE_TAIL(0), HEAD read first 6 note (ksec2CanSendPacket_GB10B kernel_sec2_gb10b.c:343-357, _ksec2GetQueueHeadTail_GB10B :103-104) 7 note 2 EMEMC(0) = offset 0 with auto-increment on write (AINCW bit 24) (:118-154, :723) 8 note 3 EMEMD(0) = the packet one dword at a time, a short tail zero-padded (:166-213) 9 note 4 EMEMC(0) read back: the write pointer moved by exactly the dwords written (:204-210) 10 note 5 QUEUE_TAIL(0) = padded size - 4, THEN QUEUE_HEAD(0) = 0, which interrupts SEC2 (:72-84, :730) 11 note 6 wait until SEC2 MAILBOX0 no longer reads 0xc001cafe (:285-311, :640) 12 note 7 wait until GSP HWCFG2 is non-zero and not 0xBADF41xx (target mask released) (:264-283, :367-379) 13 note 8 wait until HWCFG2 bit 13 (RISCV_BR_PRIV_LOCKDOWN) is clear or GSP MAILBOX0 is non-zero; MAILBOX0:1 14 note equal to the FMC boot-argument address means not read yet (kernel_gsp_gh100.c:492-533) 15 note 9 GSP MAILBOX0 non-zero after that is an FMC error code (:940-946) 16 note 10 GSP FALCON_OS = GspRmBoot appVersion (:954-956) 17 note 11 RISC-V CPUCTL bit 7 ACTIVE_STAT must read ACTIVE (kernel_falcon_ga102.c:47-55) 18 note Notify (kgspSetCmdQueueHead_TU102, kernel_gsp_tu102.c:343-355): GSP QUEUE_HEAD(0) = 0. 19 note Library unit: no main. Build after it gsp/sim.om (the mode 0 device) and a driver with main. 20 note Register seam: every device access is gsprd / gspwr. gspmode 0 = the in-.om simulator (simrd/simwr), 21 note gspmode 1 = BAR0 through a vfiomapw handle in gspbar (mapget/mapset, 4 bytes). Mode 1 runs only in a 22 note hardware window; host tests never set it. Nothing here has run on the chip. 23 note BAR0 offsets, GB10B (dev_sec_pri.h:27-56, dev_gsp.h:27, dev_falcon_v4.h, dev_riscv_pri.h:58,68), 24 note written in decimal because OM-1 has no hex literal: 0x840040 0x840044 0x840ac0 0x840ac4 0x840c00 25 note 0x840c04 0x110040 0x110044 0x110080 0x1100f4 0x110c00 0x111388. 26 const S2MB0 ulong `8650816` 27 const S2MB1 ulong `8650820` 28 const S2EMC ulong `8653504` 29 const S2EMD ulong `8653508` 30 const S2QH ulong `8653824` 31 const S2QT ulong `8653828` 32 const GMB0 ulong `1114176` 33 const GMB1 ulong `1114180` 34 const GOS ulong `1114240` 35 const GHWCFG2 ulong `1114356` 36 const GQH ulong `1117184` 37 const GCPUCTL ulong `1119112` 38 note EMEMC AINCW 1<<24; 64 dwords per EMEM block; channel 1024 bytes; SEC2 busy 0xc001cafe; 39 note target locked 0xBADF4100 under mask 0xFFFFFF00; HWCFG2 lockdown 1<<13; CPUCTL active 1<<7. 40 const AINCW ulong `16777216` 41 const DWBLK ulong 64 42 const CHBYTES ulong 1024 43 const CMDBUSY ulong `3221342974` 44 const PRIVLCK ulong `3135193344` 45 const PRIVMSK ulong `4294967040` 46 const LOCKDN ulong 8192 47 const CPUACT ulong 128 48 const M32 ulong `4294967295` 49 note stage codes (enum ck_gsp_mmio_err) 50 const EOK long 0 51 const EARG long -1 52 const EBUSY long -2 53 const EEMEM long -3 54 const ESEC2 long -4 55 const EMASK long -5 56 const ELOCK long -6 57 const EFMC long -7 58 const ERISCV long -8 59 note -9: the device is not runtime-active (arm64: a BAR read of a D3 device is an external abort); 60 note checked before the first register access, so a refused start makes no access at all 61 const EPM long -9 62 note runtime PM: mode 0 asks the simulator (spm 0 = active); mode 1 reads the sysfs file whose path 63 note the caller puts in gpmp[0..gpmn) (.../power/runtime_status) and requires exactly "active\n" 64 text pmact "active\n" 65 global gpmp uchar 128 66 global gpmn ulong 1 67 global gpmb uchar 16 68 note seam state: mode, BAR0 handle (mode 1), pause between polls in nanoseconds (mode 1) 69 global gspmode ulong 1 70 global gspbar long 1 71 global gsppns long 1 72 note input (struct ck_gsp_mmio_in): the packet bytes, then gin 0 len, 1 fmc_args_pa, 2 app_version, 73 note 3..6 poll budgets of steps 1, 6, 7, 8 (0 = check once) 74 global gpkt uchar 1024 75 global gin ulong 7 76 note output (struct ck_gsp_mmio_out): gstage, then gout 0..3 polls of steps 1, 6, 7, 8, 4 dwords, 77 note 5 ememc_after, 6 sec2_mb0, 7 sec2_mb1, 8 hwcfg2, 9 gsp_mb0, 10 gsp_mb1, 11 cpuctl 78 global gstage long 1 79 global gout ulong 12 80 fn gsprd off ulong to ulong 81 m = get gspmode 0 82 if eq m 0 83 ret simrd off 84 end 85 if ne m 1 86 trap 9 87 end 88 ret mapget get gspbar 0 off 4 89 end 90 fn gspwr off ulong v ulong to void 91 m = get gspmode 0 92 if eq m 0 93 simwr off v 94 ret 95 end 96 if ne m 1 97 trap 9 98 end 99 r = mapset get gspbar 0 off 4 v 100 if ne r 0 101 trap 9 102 end 103 end 104 fn gsppause to void 105 if eq get gspmode 0 1 106 r = sleepns get gsppns 0 107 end 108 end 109 fn gspdelay us ulong to long 110 if eq get gspmode 0 1 111 ret sleepns long mul us 1000 112 end 113 ret 0 114 end 115 fn ememdw c ulong to ulong 116 ret add mul and shr c 8 255 DWBLK and shr c 2 63 117 end 118 fn maskrel h ulong to bool 119 if eq h 0 120 ret false 121 end 122 ret ne and h PRIVMSK PRIVLCK 123 end 124 fn gsppm to bool 125 if eq get gspmode 0 0 126 ret simpmok 127 end 128 fd = fopen gpmp 0 get gpmn 0 524288 0 129 if lt fd 0 130 ret false 131 end 132 n = read int fd gpmb ulong 0 16 133 r = fclose int fd 134 if ne n long len pmact 135 ret false 136 end 137 for i ulong len pmact 138 if ne get gpmb i get pmact i 139 ret false 140 end 141 end 142 ret true 143 end 144 note step 8 condition: MAILBOX0, MAILBOX1 only when MAILBOX0 is the argument address, then HWCFG2 145 fn lockdone to bool 146 m0 = gsprd GMB0 147 put gout 9 m0 148 pa = get gin 1 149 if ne m0 0 150 if eq m0 and pa M32 151 m1 = gsprd GMB1 152 put gout 10 m1 153 if eq m1 shr pa 32 154 ret false 155 end 156 end 157 end 158 h = gsprd GHWCFG2 159 put gout 8 h 160 if not maskrel h 161 ret false 162 end 163 if eq and m0 PRIVMSK PRIVLCK 164 ret false 165 end 166 ret or eq and h LOCKDN 0 ne m0 0 167 end 168 note one check of wait k (0 step 1, 1 step 6, 2 step 7, 3 step 8): true when it is over 169 fn pollonce k ulong to bool 170 if eq k 0 171 hd = gsprd S2QH 172 ret eq hd gsprd S2QT 173 end 174 if eq k 1 175 mb = gsprd S2MB0 176 put gout 6 mb 177 ret ne mb CMDBUSY 178 end 179 if eq k 2 180 hw = gsprd GHWCFG2 181 put gout 8 hw 182 ret maskrel hw 183 end 184 ret lockdone 185 end 186 note wait k with budget gin 3+k (a uint32): checks, then budget, then pause, as the C loop; the polls 187 note used go to gout k. Inner loops stop themselves at 999998 passes, so no loop reaches its bound. 188 fn pollstep k ulong to bool 189 b = get gin add 3 k 190 n = ulong 0 191 ok = false 192 stop = false 193 while not stop bound 4400 194 c = ulong 0 195 while true bound 999999 196 if pollonce k 197 ok = true 198 stop = true 199 break 200 end 201 if ge n b 202 stop = true 203 break 204 end 205 gsppause 206 n = add n 1 207 c = add c 1 208 if eq c 999998 209 break 210 end 211 end 212 end 213 put gout k n 214 ret ok 215 end 216 note step 3: whole dwords little-endian, then a short tail zero-padded 217 fn ememput ln ulong to void 218 i = ulong 0 219 while le add i 4 ln bound 300 220 v = or ulong get gpkt i shl ulong get gpkt add i 1 8 221 v = or v or shl ulong get gpkt add i 2 16 shl ulong get gpkt add i 3 24 222 gspwr S2EMD v 223 i = add i 4 224 end 225 if lt i ln 226 t = ulong 0 227 k = ulong 0 228 while lt add i k ln bound 4 229 t = or t shl ulong get gpkt add i k mul 8 k 230 k = add k 1 231 end 232 gspwr S2EMD t 233 end 234 end 235 fn gspfail e long to long 236 put gstage 0 e 237 ret e 238 end 239 note steps 1-11; returns the stage (also in gstage). Budgets and app_version are uint32 in the C 240 note struct: a value above that range is refused as an argument error. 241 fn gspboot to long 242 for i ulong 12 243 put gout i 0 244 end 245 put gstage 0 EARG 246 ln = get gin 0 247 if or eq ln 0 gt ln CHBYTES 248 ret EARG 249 end 250 for j ulong 5 251 if gt get gin add 2 j M32 252 ret EARG 253 end 254 end 255 if not gsppm 256 ret gspfail EPM 257 end 258 if not pollstep 0 259 ret gspfail EBUSY 260 end 261 gspwr S2EMC AINCW 262 st = ememdw gsprd S2EMC 263 ememput ln 264 dw = div add ln 3 4 265 put gout 4 dw 266 ea = gsprd S2EMC 267 put gout 5 ea 268 if ne and sub ememdw ea st M32 dw 269 ret gspfail EEMEM 270 end 271 gspwr S2QT sub mul dw 4 4 272 gspwr S2QH 0 273 if not pollstep 1 274 put gout 7 gsprd S2MB1 275 ret gspfail ESEC2 276 end 277 ret gspfinish 278 end 279 note Shared GSP FMC completion, selected only after the profile-specific SEC2 exchange. 280 fn gspfinish to long 281 if not pollstep 2 282 ret gspfail EMASK 283 end 284 if not pollstep 3 285 put gout 10 gsprd GMB1 286 ret gspfail ELOCK 287 end 288 m0 = gsprd GMB0 289 put gout 9 m0 290 if ne m0 0 291 ret gspfail EFMC 292 end 293 gspwr GOS get gin 2 294 cp = gsprd GCPUCTL 295 put gout 11 cp 296 if eq and cp CPUACT 0 297 ret gspfail ERISCV 298 end 299 ret gspfail EOK 300 end 301 note announce new command-queue elements to GSP-RM (after the ring write and its fence) 302 fn gspnotify to void 303 gspwr GQH 0 304 end