interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / gpu / driver / gsp / mmio_bm.om

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