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