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 / aienux / kernel / arm64 / acpi.om

263 lines · 5378 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/kernel/arm64/acpi.om: Pure-Omega ACPI 2.0 RSDP/XSDT walker + MADT/FADT/SPCR/MCFG/IORT discovery.
3note Discovers: up to 64 GICC MPIDRs (20 Grace cores on Spark), GICD, GICR, GITS (MADT type 0x0f),
4note FADT PSCI conduit (SMC vs HVC), SPCR UART (16550 @ 0x16A00000 or PL011), MCFG segs 0..15, and IORT PA/len.
5
6const ACPI_MAX_CPUS ulong 64
7const ACPI_MAX_MCFG ulong 16
8
9note acpi_info slots:
10note 0=rsdp_pa, 1=xsdt_pa, 2=gicd_pa, 3=gicr_pa, 4=gicr_len, 5=gits_pa,
11note 6=ncpus, 7=psci_conduit (0=none,1=SMC,2=HVC), 8=spcr_base, 9=spcr_kind (1=16550,2=PL011),
12note 10=iort_pa, 11=iort_len, 12=nmcfg, 13=madt_pa, 14=madt_len, 15=fadt_pa
13global acpi_info ulong 16
14global acpi_cpu_mpidr ulong 64
15global acpi_cpu_class ulong 64
16global acpi_mcfg_base ulong 16
17global acpi_mcfg_seg ulong 16
18global acpi_mcfg_sbus ulong 16
19global acpi_mcfg_ebus ulong 16
20
21fn acpi_reset to void
22for i ulong 16
23put acpi_info i 0
24put acpi_mcfg_base i 0
25put acpi_mcfg_seg i 0
26put acpi_mcfg_sbus i 0
27put acpi_mcfg_ebus i 0
28end
29for j ulong 64
30put acpi_cpu_mpidr j 0
31put acpi_cpu_class j 0
32end
33end
34
35fn acpi_raw_sum_ok pa ulong n ulong to bool
36if or eq pa 0 lt n 20
37ret false
38end
39acc = ulong 0
40i = ulong 0
41while lt i n bound 65536
42acc = and add acc fwld add pa i 1 0xff
43i = add i 1
44end
45ret eq acc 0
46end
47
48fn acpi_parse_madt pa ulong length ulong to bool
49if lt length 44
50ret false
51end
52if not acpi_raw_sum_ok pa length
53ret false
54end
55put acpi_info 13 pa
56put acpi_info 14 length
57pos = ulong 44
58while lt pos length bound 4096
59if gt add pos 2 length
60ret false
61end
62etype = fwld add pa pos 1
63elen = fwld add pa add pos 1 1
64if or lt elen 2 gt add pos elen length
65ret false
66end
67e = add pa pos
68if eq etype 0x0b
69note GICC (ACPI 6.5 Table 5.36): +12 flags, +60 GICR base, +68 MPIDR (8B: 68..75), +76 efficiency class (1B)
70if ge elen 76
71flags = fwld add e 12 4
72if ne and flags 9 0
73nc = get acpi_info 6
74if lt nc ACPI_MAX_CPUS
75mpidr = and fwld add e 68 8 0x000000ff00ffffff
76put acpi_cpu_mpidr nc mpidr
77if ge elen 77
78put acpi_cpu_class nc fwld add e 76 1
79end
80put acpi_info 6 add nc 1
81end
82if eq get acpi_info 3 0
83gcr = fwld add e 60 8
84if ne gcr 0
85put acpi_info 3 gcr
86put acpi_info 4 0x20000
87end
88end
89end
90end
91else
92if eq etype 0x0c
93note GICD (length >= 24): +8 Physical Base Address
94if ge elen 24
95put acpi_info 2 fwld add e 8 8
96end
97else
98if eq etype 0x0e
99note GICR Redistributor Discovery Range (length >= 16): +4 base, +12 length
100if ge elen 16
101put acpi_info 3 fwld add e 4 8
102put acpi_info 4 fwld add e 12 4
103end
104else
105if eq etype 0x0f
106note GIC ITS (length >= 20): +8 Physical Base Address (strictly MADT-discovered)
107if ge elen 20
108if eq get acpi_info 5 0
109put acpi_info 5 fwld add e 8 8
110end
111end
112end
113end
114end
115end
116pos = add pos elen
117end
118ret ne get acpi_info 2 0
119end
120
121fn acpi_parse_fadt pa ulong length ulong to void
122if lt length 131
123ret
124end
125if not acpi_raw_sum_ok pa length
126ret
127end
128put acpi_info 15 pa
129note FADT ARM_BOOT_ARCH at offset 129 (2 bytes): bit 0 PSCI_COMPLIANT, bit 1 PSCI_USE_HVC
130arch = fwld add pa 129 2
131if ne and arch 1 0
132if ne and arch 2 0
133put acpi_info 7 2
134else
135put acpi_info 7 1
136end
137end
138end
139
140fn acpi_parse_spcr pa ulong length ulong to void
141if lt length 52
142ret
143end
144if not acpi_raw_sum_ok pa length
145ret
146end
147itype = fwld add pa 36 1
148base = fwld add pa 44 8
149if eq base 0
150ret
151end
152put acpi_info 8 base
153if eq itype 3
154put acpi_info 9 2
155else
156if or eq itype 0 or eq itype 1 eq itype 18
157put acpi_info 9 1
158end
159end
160end
161
162fn acpi_parse_mcfg pa ulong length ulong to void
163if lt length 44
164ret
165end
166if not acpi_raw_sum_ok pa length
167ret
168end
169pos = ulong 44
170while le add pos 16 length bound 32
171idx = get acpi_info 12
172if lt idx ACPI_MAX_MCFG
173e = add pa pos
174put acpi_mcfg_base idx fwld e 8
175put acpi_mcfg_seg idx fwld add e 8 2
176put acpi_mcfg_sbus idx fwld add e 10 1
177put acpi_mcfg_ebus idx fwld add e 11 1
178put acpi_info 12 add idx 1
179end
180pos = add pos 16
181end
182end
183
184note Walk ACPI 2.0 RSDP -> XSDT and parse APIC (MADT), FACP (FADT), SPCR, MCFG, IORT.
185fn acpi_parse_rsdp rsdp_pa ulong to bool
186acpi_reset
187if eq rsdp_pa 0
188ret false
189end
190note "RSD PTR " = 0x2052545020445352 LE
191if ne fwld rsdp_pa 8 0x2052545020445352
192ret false
193end
194if not acpi_raw_sum_ok rsdp_pa 20
195ret false
196end
197rev = fwld add rsdp_pa 15 1
198if lt rev 2
199ret false
200end
201rlen = fwld add rsdp_pa 20 4
202if or lt rlen 36 not acpi_raw_sum_ok rsdp_pa rlen
203ret false
204end
205xsdt = fwld add rsdp_pa 24 8
206if eq xsdt 0
207ret false
208end
209note "XSDT" = 0x54445358 LE
210if ne fwld xsdt 4 0x54445358
211ret false
212end
213xlen = fwld add xsdt 4 4
214if or lt xlen 36 not acpi_raw_sum_ok xsdt xlen
215ret false
216end
217put acpi_info 0 rsdp_pa
218put acpi_info 1 xsdt
219nents = div sub xlen 36 8
220i = ulong 0
221while lt i nents bound 128
222tpa = fwld add add xsdt 36 mul i 8 8
223if ne tpa 0
224sig = fwld tpa 4
225tlen = fwld add tpa 4 4
226if ge tlen 36
227note "APIC"=0x43495041, "FACP"=0x50434146, "SPCR"=0x52435053, "MCFG"=0x4746434d, "IORT"=0x54524f49
228if eq sig 0x43495041
229ok = acpi_parse_madt tpa tlen
230end
231if eq sig 0x50434146
232acpi_parse_fadt tpa tlen
233end
234if eq sig 0x52435053
235acpi_parse_spcr tpa tlen
236end
237if eq sig 0x4746434d
238acpi_parse_mcfg tpa tlen
239end
240if eq sig 0x54524f49
241if acpi_raw_sum_ok tpa tlen
242put acpi_info 10 tpa
243put acpi_info 11 tlen
244end
245end
246end
247end
248i = add i 1
249end
250ret ne get acpi_info 2 0
251end
252
253fn acpi_mcfg_ecam_for_seg seg ulong to ulong
254n = get acpi_info 12
255i = ulong 0
256while lt i n bound 16
257if eq get acpi_mcfg_seg i seg
258ret get acpi_mcfg_base i
259end
260i = add i 1
261end
262ret 0
263end