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
omega-mv / gpu / driver / gsp / mmio_bm.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note gsp/mmio_bm.om: Zero-syscall bare-metal MMIO seam for GB20B SEC2/GSP boot & sequencer. |
| 3 | note Drop-in replacement for gsp/mmio.om in SPARK.EFI (no mapget/mapset/fopen/sleepns). |
| 4 | note Requires gsp/bm_hal.om before it; provides gsprd/gspwr/gsppm/gsppause/gspdelay/gspfinish/ |
| 5 | note gspnotify/pollstep/ememdw/gspfail for sec2.om, seq.om, seqcore.om, and dispatch.om. |
| 6 | note gspmode = 2 selects bare-metal bm_hal.om BAR0 + CNTVCT_EL0 deadline timer. |
| 7 | |
| 8 | const S2MB0 ulong 8650816 |
| 9 | const S2MB1 ulong 8650820 |
| 10 | const S2EMC ulong 8653504 |
| 11 | const S2EMD ulong 8653508 |
| 12 | const S2QH ulong 8653824 |
| 13 | const S2QT ulong 8653828 |
| 14 | const GMB0 ulong 1114176 |
| 15 | const GMB1 ulong 1114180 |
| 16 | const GOS ulong 1114240 |
| 17 | const GHWCFG2 ulong 1114356 |
| 18 | const GQH ulong 1117184 |
| 19 | const GCPUCTL ulong 1119112 |
| 20 | |
| 21 | const AINCW ulong 16777216 |
| 22 | const DWBLK ulong 64 |
| 23 | const CHBYTES ulong 1024 |
| 24 | const CMDBUSY ulong 3221342974 |
| 25 | const PRIVLCK ulong 3135193344 |
| 26 | const PRIVMSK ulong 4294967040 |
| 27 | const LOCKDN ulong 8192 |
| 28 | const CPUACT ulong 128 |
| 29 | const M32 ulong 4294967295 |
| 30 | |
| 31 | const EOK long 0 |
| 32 | const EARG long -1 |
| 33 | const EBUSY long -2 |
| 34 | const EEMEM long -3 |
| 35 | const ESEC2 long -4 |
| 36 | const EMASK long -5 |
| 37 | const ELOCK long -6 |
| 38 | const EFMC long -7 |
| 39 | const ERISCV long -8 |
| 40 | const EPM long -9 |
| 41 | |
| 42 | global gspmode ulong 1 |
| 43 | global gsppns long 1 |
| 44 | global gspd0ok ulong 1 |
| 45 | global gpkt uchar 1024 |
| 46 | global gin ulong 7 |
| 47 | global gstage long 1 |
| 48 | global gout ulong 12 |
| 49 | |
| 50 | fn gsprd off ulong to ulong |
| 51 | if ne get gspmode 0 2 |
| 52 | trap 9 |
| 53 | end |
| 54 | ret bmbarrd32 off |
| 55 | end |
| 56 | |
| 57 | fn gspwr off ulong v ulong to void |
| 58 | if ne get gspmode 0 2 |
| 59 | trap 9 |
| 60 | end |
| 61 | bmbarwr32 off v |
| 62 | end |
| 63 | |
| 64 | fn gsppause to void |
| 65 | us = ulong 10 |
| 66 | if gt get gsppns 0 0 |
| 67 | us = div add ulong get gsppns 0 999 1000 |
| 68 | end |
| 69 | r = bmdelayus us |
| 70 | end |
| 71 | |
| 72 | fn gspdelay us ulong to long |
| 73 | ret bmdelayus us |
| 74 | end |
| 75 | |
| 76 | fn ememdw c ulong to ulong |
| 77 | ret add mul and shr c 8 255 DWBLK and shr c 2 63 |
| 78 | end |
| 79 | |
| 80 | fn maskrel h ulong to bool |
| 81 | if eq h 0 |
| 82 | ret false |
| 83 | end |
| 84 | ret ne and h PRIVMSK PRIVLCK |
| 85 | end |
| 86 | |
| 87 | note Bare-metal D0 check: Piece 2 pcie.om verifies PCIe PMCSR D0 before GSP boot and sets gspd0ok=1. |
| 88 | fn gsppm to bool |
| 89 | ret eq get gspd0ok 0 1 |
| 90 | end |
| 91 | |
| 92 | fn lockdone to bool |
| 93 | m0 = gsprd GMB0 |
| 94 | put gout 9 m0 |
| 95 | pa = get gin 1 |
| 96 | if ne m0 0 |
| 97 | if eq m0 and pa M32 |
| 98 | m1 = gsprd GMB1 |
| 99 | put gout 10 m1 |
| 100 | if eq m1 shr pa 32 |
| 101 | ret false |
| 102 | end |
| 103 | end |
| 104 | end |
| 105 | h = gsprd GHWCFG2 |
| 106 | put gout 8 h |
| 107 | if not maskrel h |
| 108 | ret false |
| 109 | end |
| 110 | if eq and m0 PRIVMSK PRIVLCK |
| 111 | ret false |
| 112 | end |
| 113 | ret or eq and h LOCKDN 0 ne m0 0 |
| 114 | end |
| 115 | |
| 116 | fn pollonce k ulong to bool |
| 117 | if eq k 0 |
| 118 | hd = gsprd S2QH |
| 119 | ret eq hd gsprd S2QT |
| 120 | end |
| 121 | if eq k 1 |
| 122 | mb = gsprd S2MB0 |
| 123 | put gout 6 mb |
| 124 | ret ne mb CMDBUSY |
| 125 | end |
| 126 | if eq k 2 |
| 127 | hw = gsprd GHWCFG2 |
| 128 | put gout 8 hw |
| 129 | ret maskrel hw |
| 130 | end |
| 131 | ret lockdone |
| 132 | end |
| 133 | |
| 134 | fn pollstep k ulong to bool |
| 135 | b = get gin add 3 k |
| 136 | n = ulong 0 |
| 137 | ok = false |
| 138 | stop = false |
| 139 | while not stop bound 4400 |
| 140 | c = ulong 0 |
| 141 | while true bound 999999 |
| 142 | if pollonce k |
| 143 | ok = true |
| 144 | stop = true |
| 145 | break |
| 146 | end |
| 147 | if ge n b |
| 148 | stop = true |
| 149 | break |
| 150 | end |
| 151 | gsppause |
| 152 | n = add n 1 |
| 153 | c = add c 1 |
| 154 | if eq c 999998 |
| 155 | break |
| 156 | end |
| 157 | end |
| 158 | end |
| 159 | put gout k n |
| 160 | ret ok |
| 161 | end |
| 162 | |
| 163 | fn gspfail e long to long |
| 164 | put gstage 0 e |
| 165 | ret e |
| 166 | end |
| 167 | |
| 168 | note Shared GSP FMC completion after SEC2 COTv2 reply. |
| 169 | fn gspfinish to long |
| 170 | if not pollstep 2 |
| 171 | ret gspfail EMASK |
| 172 | end |
| 173 | if not pollstep 3 |
| 174 | put gout 10 gsprd GMB1 |
| 175 | ret gspfail ELOCK |
| 176 | end |
| 177 | m0 = gsprd GMB0 |
| 178 | put gout 9 m0 |
| 179 | if ne m0 0 |
| 180 | ret gspfail EFMC |
| 181 | end |
| 182 | gspwr GOS get gin 2 |
| 183 | cp = gsprd GCPUCTL |
| 184 | put gout 11 cp |
| 185 | if eq and cp CPUACT 0 |
| 186 | ret gspfail ERISCV |
| 187 | end |
| 188 | ret gspfail EOK |
| 189 | end |
| 190 | |
| 191 | note Announce new cmdq elements to GSP-RM: PGSP_QUEUE_HEAD(0) = 0 after DSB SY. |
| 192 | fn gspnotify to void |
| 193 | bmdsb |
| 194 | gspwr GQH 0 |
| 195 | end |