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/mmio.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 / mmio.om` 292 lines ยท 8017 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 ememdw c ulong to ulong 110 ret add mul and shr c 8 255 DWBLK and shr c 2 63 111 end 112 fn maskrel h ulong to bool 113 if eq h 0 114 ret false 115 end 116 ret ne and h PRIVMSK PRIVLCK 117 end 118 fn gsppm to bool 119 if eq get gspmode 0 0 120 ret simpmok 121 end 122 fd = fopen gpmp 0 get gpmn 0 524288 0 123 if lt fd 0 124 ret false 125 end 126 n = read int fd gpmb ulong 0 16 127 r = fclose int fd 128 if ne n long len pmact 129 ret false 130 end 131 for i ulong len pmact 132 if ne get gpmb i get pmact i 133 ret false 134 end 135 end 136 ret true 137 end 138 note step 8 condition: MAILBOX0, MAILBOX1 only when MAILBOX0 is the argument address, then HWCFG2 139 fn lockdone to bool 140 m0 = gsprd GMB0 141 put gout 9 m0 142 pa = get gin 1 143 if ne m0 0 144 if eq m0 and pa M32 145 m1 = gsprd GMB1 146 put gout 10 m1 147 if eq m1 shr pa 32 148 ret false 149 end 150 end 151 end 152 h = gsprd GHWCFG2 153 put gout 8 h 154 ret or eq and h LOCKDN 0 ne m0 0 155 end 156 note one check of wait k (0 step 1, 1 step 6, 2 step 7, 3 step 8): true when it is over 157 fn pollonce k ulong to bool 158 if eq k 0 159 hd = gsprd S2QH 160 ret eq hd gsprd S2QT 161 end 162 if eq k 1 163 mb = gsprd S2MB0 164 put gout 6 mb 165 ret ne mb CMDBUSY 166 end 167 if eq k 2 168 hw = gsprd GHWCFG2 169 put gout 8 hw 170 ret maskrel hw 171 end 172 ret lockdone 173 end 174 note wait k with budget gin 3+k (a uint32): checks, then budget, then pause, as the C loop; the polls 175 note used go to gout k. Inner loops stop themselves at 999998 passes, so no loop reaches its bound. 176 fn pollstep k ulong to bool 177 b = get gin add 3 k 178 n = ulong 0 179 ok = false 180 stop = false 181 while not stop bound 4400 182 c = ulong 0 183 while true bound 999999 184 if pollonce k 185 ok = true 186 stop = true 187 break 188 end 189 if ge n b 190 stop = true 191 break 192 end 193 gsppause 194 n = add n 1 195 c = add c 1 196 if eq c 999998 197 break 198 end 199 end 200 end 201 put gout k n 202 ret ok 203 end 204 note step 3: whole dwords little-endian, then a short tail zero-padded 205 fn ememput ln ulong to void 206 i = ulong 0 207 while le add i 4 ln bound 300 208 v = or ulong get gpkt i shl ulong get gpkt add i 1 8 209 v = or v or shl ulong get gpkt add i 2 16 shl ulong get gpkt add i 3 24 210 gspwr S2EMD v 211 i = add i 4 212 end 213 if lt i ln 214 t = ulong 0 215 k = ulong 0 216 while lt add i k ln bound 4 217 t = or t shl ulong get gpkt add i k mul 8 k 218 k = add k 1 219 end 220 gspwr S2EMD t 221 end 222 end 223 fn gspfail e long to long 224 put gstage 0 e 225 ret e 226 end 227 note steps 1-11; returns the stage (also in gstage). Budgets and app_version are uint32 in the C 228 note struct: a value above that range is refused as an argument error. 229 fn gspboot to long 230 for i ulong 12 231 put gout i 0 232 end 233 put gstage 0 EARG 234 ln = get gin 0 235 if or eq ln 0 gt ln CHBYTES 236 ret EARG 237 end 238 for j ulong 5 239 if gt get gin add 2 j M32 240 ret EARG 241 end 242 end 243 if not gsppm 244 ret gspfail EPM 245 end 246 if not pollstep 0 247 ret gspfail EBUSY 248 end 249 gspwr S2EMC AINCW 250 st = ememdw gsprd S2EMC 251 ememput ln 252 dw = div add ln 3 4 253 put gout 4 dw 254 ea = gsprd S2EMC 255 put gout 5 ea 256 if ne and sub ememdw ea st M32 dw 257 ret gspfail EEMEM 258 end 259 gspwr S2QT sub mul dw 4 4 260 gspwr S2QH 0 261 if not pollstep 1 262 put gout 7 gsprd S2MB1 263 ret gspfail ESEC2 264 end 265 ret gspfinish 266 end 267 note Shared GSP FMC completion, selected only after the profile-specific SEC2 exchange. 268 fn gspfinish to long 269 if not pollstep 2 270 ret gspfail EMASK 271 end 272 if not pollstep 3 273 put gout 10 gsprd GMB1 274 ret gspfail ELOCK 275 end 276 m0 = gsprd GMB0 277 put gout 9 m0 278 if ne m0 0 279 ret gspfail EFMC 280 end 281 gspwr GOS get gin 2 282 cp = gsprd GCPUCTL 283 put gout 11 cp 284 if eq and cp CPUACT 0 285 ret gspfail ERISCV 286 end 287 ret gspfail EOK 288 end 289 note announce new command-queue elements to GSP-RM (after the ring write and its fence) 290 fn gspnotify to void 291 gspwr GQH 0 292 end