1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 1998 Doug Rabson 5 * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org> 6 * Copyright (c) 2020 Alexander Motin <mav@FreeBSD.org> 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 * $FreeBSD$ 31 */ 32 33 #include <sys/param.h> 34 #include <sys/endian.h> 35 #include <sys/stat.h> 36 #include <sys/wait.h> 37 #include <assert.h> 38 #include <err.h> 39 #include <fcntl.h> 40 #include <paths.h> 41 #include <stdio.h> 42 #include <stdint.h> 43 #include <stdlib.h> 44 #include <string.h> 45 #include <unistd.h> 46 #include <uuid.h> 47 48 #include "acpidump.h" 49 50 #define BEGIN_COMMENT "/*\n" 51 #define END_COMMENT " */\n" 52 53 static void acpi_print_string(char *s, size_t length); 54 static void acpi_print_gas(ACPI_GENERIC_ADDRESS *gas); 55 static int acpi_get_fadt_revision(ACPI_TABLE_FADT *fadt); 56 static void acpi_handle_fadt(ACPI_TABLE_HEADER *fadt); 57 static void acpi_print_cpu(u_char cpu_id); 58 static void acpi_print_cpu_uid(uint32_t uid, char *uid_string); 59 static void acpi_print_local_apic(uint32_t apic_id, uint32_t flags); 60 static void acpi_print_io_apic(uint32_t apic_id, uint32_t int_base, 61 uint64_t apic_addr); 62 static void acpi_print_mps_flags(uint16_t flags); 63 static void acpi_print_intr(uint32_t intr, uint16_t mps_flags); 64 static void acpi_print_local_nmi(u_int lint, uint16_t mps_flags); 65 static void acpi_print_madt(ACPI_SUBTABLE_HEADER *mp); 66 static void acpi_handle_madt(ACPI_TABLE_HEADER *sdp); 67 static void acpi_handle_ecdt(ACPI_TABLE_HEADER *sdp); 68 static void acpi_handle_hpet(ACPI_TABLE_HEADER *sdp); 69 static void acpi_handle_mcfg(ACPI_TABLE_HEADER *sdp); 70 static void acpi_handle_slit(ACPI_TABLE_HEADER *sdp); 71 static void acpi_handle_wddt(ACPI_TABLE_HEADER *sdp); 72 static void acpi_handle_lpit(ACPI_TABLE_HEADER *sdp); 73 static void acpi_print_srat_cpu(uint32_t apic_id, uint32_t proximity_domain, 74 uint32_t flags); 75 static void acpi_print_srat_memory(ACPI_SRAT_MEM_AFFINITY *mp); 76 static void acpi_print_srat(ACPI_SUBTABLE_HEADER *srat); 77 static void acpi_handle_srat(ACPI_TABLE_HEADER *sdp); 78 static void acpi_handle_tcpa(ACPI_TABLE_HEADER *sdp); 79 static void acpi_print_nfit(ACPI_NFIT_HEADER *nfit); 80 static void acpi_handle_nfit(ACPI_TABLE_HEADER *sdp); 81 static void acpi_print_sdt(ACPI_TABLE_HEADER *sdp); 82 static void acpi_print_fadt(ACPI_TABLE_HEADER *sdp); 83 static void acpi_print_facs(ACPI_TABLE_FACS *facs); 84 static void acpi_print_dsdt(ACPI_TABLE_HEADER *dsdp); 85 static ACPI_TABLE_HEADER *acpi_map_sdt(vm_offset_t pa); 86 static void acpi_print_rsd_ptr(ACPI_TABLE_RSDP *rp); 87 static void acpi_handle_rsdt(ACPI_TABLE_HEADER *rsdp); 88 static void acpi_walk_subtables(ACPI_TABLE_HEADER *table, void *first, 89 void (*action)(ACPI_SUBTABLE_HEADER *)); 90 static void acpi_walk_nfit(ACPI_TABLE_HEADER *table, void *first, 91 void (*action)(ACPI_NFIT_HEADER *)); 92 93 /* Size of an address. 32-bit for ACPI 1.0, 64-bit for ACPI 2.0 and up. */ 94 static int addr_size; 95 96 /* Strings used in the TCPA table */ 97 static const char *tcpa_event_type_strings[] = { 98 "PREBOOT Certificate", 99 "POST Code", 100 "Unused", 101 "No Action", 102 "Separator", 103 "Action", 104 "Event Tag", 105 "S-CRTM Contents", 106 "S-CRTM Version", 107 "CPU Microcode", 108 "Platform Config Flags", 109 "Table of Devices", 110 "Compact Hash", 111 "IPL", 112 "IPL Partition Data", 113 "Non-Host Code", 114 "Non-Host Config", 115 "Non-Host Info" 116 }; 117 118 static const char *TCPA_pcclient_strings[] = { 119 "<undefined>", 120 "SMBIOS", 121 "BIS Certificate", 122 "POST BIOS ROM Strings", 123 "ESCD", 124 "CMOS", 125 "NVRAM", 126 "Option ROM Execute", 127 "Option ROM Configurateion", 128 "<undefined>", 129 "Option ROM Microcode Update ", 130 "S-CRTM Version String", 131 "S-CRTM Contents", 132 "POST Contents", 133 "Table of Devices", 134 }; 135 136 #define PRINTFLAG_END() printflag_end() 137 138 static char pf_sep = '{'; 139 140 static void 141 printflag_end(void) 142 { 143 144 if (pf_sep != '{') { 145 printf("}"); 146 pf_sep = '{'; 147 } 148 printf("\n"); 149 } 150 151 static void 152 printflag(uint64_t var, uint64_t mask, const char *name) 153 { 154 155 if (var & mask) { 156 printf("%c%s", pf_sep, name); 157 pf_sep = ','; 158 } 159 } 160 161 static void 162 acpi_print_string(char *s, size_t length) 163 { 164 int c; 165 166 /* Trim trailing spaces and NULLs */ 167 while (length > 0 && (s[length - 1] == ' ' || s[length - 1] == '\0')) 168 length--; 169 170 while (length--) { 171 c = *s++; 172 putchar(c); 173 } 174 } 175 176 static void 177 acpi_print_gas(ACPI_GENERIC_ADDRESS *gas) 178 { 179 switch(gas->SpaceId) { 180 case ACPI_GAS_MEMORY: 181 printf("0x%016jx:%u[%u] (Memory)", (uintmax_t)gas->Address, 182 gas->BitOffset, gas->BitWidth); 183 break; 184 case ACPI_GAS_IO: 185 printf("0x%02jx:%u[%u] (IO)", (uintmax_t)gas->Address, 186 gas->BitOffset, gas->BitWidth); 187 break; 188 case ACPI_GAS_PCI: 189 printf("%x:%x+0x%x:%u[%u] (PCI)", (uint16_t)(gas->Address >> 32), 190 (uint16_t)((gas->Address >> 16) & 0xffff), 191 (uint16_t)gas->Address, gas->BitOffset, gas->BitWidth); 192 break; 193 /* XXX How to handle these below? */ 194 case ACPI_GAS_EMBEDDED: 195 printf("0x%x:%u[%u] (EC)", (uint16_t)gas->Address, 196 gas->BitOffset, gas->BitWidth); 197 break; 198 case ACPI_GAS_SMBUS: 199 printf("0x%x:%u[%u] (SMBus)", (uint16_t)gas->Address, 200 gas->BitOffset, gas->BitWidth); 201 break; 202 case ACPI_GAS_CMOS: 203 case ACPI_GAS_PCIBAR: 204 case ACPI_GAS_DATATABLE: 205 case ACPI_GAS_FIXED: 206 default: 207 printf("0x%016jx (?)", (uintmax_t)gas->Address); 208 break; 209 } 210 } 211 212 /* The FADT revision indicates whether we use the DSDT or X_DSDT addresses. */ 213 static int 214 acpi_get_fadt_revision(ACPI_TABLE_FADT *fadt) 215 { 216 int fadt_revision; 217 218 /* Set the FADT revision separately from the RSDP version. */ 219 if (addr_size == 8) { 220 fadt_revision = 2; 221 222 /* 223 * A few systems (e.g., IBM T23) have an RSDP that claims 224 * revision 2 but the 64 bit addresses are invalid. If 225 * revision 2 and the 32 bit address is non-zero but the 226 * 32 and 64 bit versions don't match, prefer the 32 bit 227 * version for all subsequent tables. 228 */ 229 if (fadt->Facs != 0 && 230 (fadt->XFacs & 0xffffffff) != fadt->Facs) 231 fadt_revision = 1; 232 } else 233 fadt_revision = 1; 234 return (fadt_revision); 235 } 236 237 static void 238 acpi_handle_fadt(ACPI_TABLE_HEADER *sdp) 239 { 240 ACPI_TABLE_HEADER *dsdp; 241 ACPI_TABLE_FACS *facs; 242 ACPI_TABLE_FADT *fadt; 243 vm_offset_t addr; 244 int fadt_revision; 245 246 fadt = (ACPI_TABLE_FADT *)sdp; 247 acpi_print_fadt(sdp); 248 249 fadt_revision = acpi_get_fadt_revision(fadt); 250 if (fadt_revision == 1) 251 addr = fadt->Facs; 252 else 253 addr = fadt->XFacs; 254 if (addr != 0) { 255 facs = (ACPI_TABLE_FACS *)acpi_map_sdt(addr); 256 257 if (memcmp(facs->Signature, ACPI_SIG_FACS, 4) != 0 || 258 facs->Length < 64) 259 errx(1, "FACS is corrupt"); 260 acpi_print_facs(facs); 261 } 262 263 if (fadt_revision == 1) 264 dsdp = (ACPI_TABLE_HEADER *)acpi_map_sdt(fadt->Dsdt); 265 else 266 dsdp = (ACPI_TABLE_HEADER *)acpi_map_sdt(fadt->XDsdt); 267 if (acpi_checksum(dsdp, dsdp->Length)) 268 errx(1, "DSDT is corrupt"); 269 acpi_print_dsdt(dsdp); 270 } 271 272 static void 273 acpi_walk_subtables(ACPI_TABLE_HEADER *table, void *first, 274 void (*action)(ACPI_SUBTABLE_HEADER *)) 275 { 276 ACPI_SUBTABLE_HEADER *subtable; 277 char *end; 278 279 subtable = first; 280 end = (char *)table + table->Length; 281 while ((char *)subtable < end) { 282 printf("\n"); 283 if (subtable->Length < sizeof(ACPI_SUBTABLE_HEADER)) { 284 warnx("invalid subtable length %u", subtable->Length); 285 return; 286 } 287 action(subtable); 288 subtable = (ACPI_SUBTABLE_HEADER *)((char *)subtable + 289 subtable->Length); 290 } 291 } 292 293 static void 294 acpi_walk_nfit(ACPI_TABLE_HEADER *table, void *first, 295 void (*action)(ACPI_NFIT_HEADER *)) 296 { 297 ACPI_NFIT_HEADER *subtable; 298 char *end; 299 300 subtable = first; 301 end = (char *)table + table->Length; 302 while ((char *)subtable < end) { 303 printf("\n"); 304 if (subtable->Length < sizeof(ACPI_NFIT_HEADER)) { 305 warnx("invalid subtable length %u", subtable->Length); 306 return; 307 } 308 action(subtable); 309 subtable = (ACPI_NFIT_HEADER *)((char *)subtable + 310 subtable->Length); 311 } 312 } 313 314 static void 315 acpi_print_cpu(u_char cpu_id) 316 { 317 318 printf("\tACPI CPU="); 319 if (cpu_id == 0xff) 320 printf("ALL\n"); 321 else 322 printf("%d\n", (u_int)cpu_id); 323 } 324 325 static void 326 acpi_print_cpu_uid(uint32_t uid, char *uid_string) 327 { 328 329 printf("\tUID=%d", uid); 330 if (uid_string != NULL) 331 printf(" (%s)", uid_string); 332 printf("\n"); 333 } 334 335 static void 336 acpi_print_local_apic(uint32_t apic_id, uint32_t flags) 337 { 338 339 printf("\tFlags={"); 340 if (flags & ACPI_MADT_ENABLED) 341 printf("ENABLED"); 342 else 343 printf("DISABLED"); 344 printf("}\n"); 345 printf("\tAPIC ID=%d\n", apic_id); 346 } 347 348 static void 349 acpi_print_io_apic(uint32_t apic_id, uint32_t int_base, uint64_t apic_addr) 350 { 351 352 printf("\tAPIC ID=%d\n", apic_id); 353 printf("\tINT BASE=%d\n", int_base); 354 printf("\tADDR=0x%016jx\n", (uintmax_t)apic_addr); 355 } 356 357 static void 358 acpi_print_mps_flags(uint16_t flags) 359 { 360 361 printf("\tFlags={Polarity="); 362 switch (flags & ACPI_MADT_POLARITY_MASK) { 363 case ACPI_MADT_POLARITY_CONFORMS: 364 printf("conforming"); 365 break; 366 case ACPI_MADT_POLARITY_ACTIVE_HIGH: 367 printf("active-hi"); 368 break; 369 case ACPI_MADT_POLARITY_ACTIVE_LOW: 370 printf("active-lo"); 371 break; 372 default: 373 printf("0x%x", flags & ACPI_MADT_POLARITY_MASK); 374 break; 375 } 376 printf(", Trigger="); 377 switch (flags & ACPI_MADT_TRIGGER_MASK) { 378 case ACPI_MADT_TRIGGER_CONFORMS: 379 printf("conforming"); 380 break; 381 case ACPI_MADT_TRIGGER_EDGE: 382 printf("edge"); 383 break; 384 case ACPI_MADT_TRIGGER_LEVEL: 385 printf("level"); 386 break; 387 default: 388 printf("0x%x", (flags & ACPI_MADT_TRIGGER_MASK) >> 2); 389 } 390 printf("}\n"); 391 } 392 393 static void 394 acpi_print_gicc_flags(uint32_t flags) 395 { 396 397 printf("\tFlags={Performance intr="); 398 if (flags & ACPI_MADT_PERFORMANCE_IRQ_MODE) 399 printf("edge"); 400 else 401 printf("level"); 402 printf(", VGIC intr="); 403 if (flags & ACPI_MADT_VGIC_IRQ_MODE) 404 printf("edge"); 405 else 406 printf("level"); 407 printf("}\n"); 408 } 409 410 static void 411 acpi_print_intr(uint32_t intr, uint16_t mps_flags) 412 { 413 414 printf("\tINTR=%d\n", intr); 415 acpi_print_mps_flags(mps_flags); 416 } 417 418 static void 419 acpi_print_local_nmi(u_int lint, uint16_t mps_flags) 420 { 421 422 printf("\tLINT Pin=%d\n", lint); 423 acpi_print_mps_flags(mps_flags); 424 } 425 426 static const char *apic_types[] = { 427 [ACPI_MADT_TYPE_LOCAL_APIC] = "Local APIC", 428 [ACPI_MADT_TYPE_IO_APIC] = "IO APIC", 429 [ACPI_MADT_TYPE_INTERRUPT_OVERRIDE] = "INT Override", 430 [ACPI_MADT_TYPE_NMI_SOURCE] = "NMI", 431 [ACPI_MADT_TYPE_LOCAL_APIC_NMI] = "Local APIC NMI", 432 [ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE] = "Local APIC Override", 433 [ACPI_MADT_TYPE_IO_SAPIC] = "IO SAPIC", 434 [ACPI_MADT_TYPE_LOCAL_SAPIC] = "Local SAPIC", 435 [ACPI_MADT_TYPE_INTERRUPT_SOURCE] = "Platform Interrupt", 436 [ACPI_MADT_TYPE_LOCAL_X2APIC] = "Local X2APIC", 437 [ACPI_MADT_TYPE_LOCAL_X2APIC_NMI] = "Local X2APIC NMI", 438 [ACPI_MADT_TYPE_GENERIC_INTERRUPT] = "GIC CPU Interface Structure", 439 [ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR] = "GIC Distributor Structure", 440 [ACPI_MADT_TYPE_GENERIC_MSI_FRAME] = "GICv2m MSI Frame", 441 [ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR] = "GIC Redistributor Structure", 442 [ACPI_MADT_TYPE_GENERIC_TRANSLATOR] = "GIC ITS Structure" 443 }; 444 445 static const char *platform_int_types[] = { "0 (unknown)", "PMI", "INIT", 446 "Corrected Platform Error" }; 447 448 static void 449 acpi_print_madt(ACPI_SUBTABLE_HEADER *mp) 450 { 451 ACPI_MADT_LOCAL_APIC *lapic; 452 ACPI_MADT_IO_APIC *ioapic; 453 ACPI_MADT_INTERRUPT_OVERRIDE *over; 454 ACPI_MADT_NMI_SOURCE *nmi; 455 ACPI_MADT_LOCAL_APIC_NMI *lapic_nmi; 456 ACPI_MADT_LOCAL_APIC_OVERRIDE *lapic_over; 457 ACPI_MADT_IO_SAPIC *iosapic; 458 ACPI_MADT_LOCAL_SAPIC *lsapic; 459 ACPI_MADT_INTERRUPT_SOURCE *isrc; 460 ACPI_MADT_LOCAL_X2APIC *x2apic; 461 ACPI_MADT_LOCAL_X2APIC_NMI *x2apic_nmi; 462 ACPI_MADT_GENERIC_INTERRUPT *gicc; 463 ACPI_MADT_GENERIC_DISTRIBUTOR *gicd; 464 ACPI_MADT_GENERIC_REDISTRIBUTOR *gicr; 465 ACPI_MADT_GENERIC_TRANSLATOR *gict; 466 467 if (mp->Type < nitems(apic_types)) 468 printf("\tType=%s\n", apic_types[mp->Type]); 469 else 470 printf("\tType=%d (unknown)\n", mp->Type); 471 switch (mp->Type) { 472 case ACPI_MADT_TYPE_LOCAL_APIC: 473 lapic = (ACPI_MADT_LOCAL_APIC *)mp; 474 acpi_print_cpu(lapic->ProcessorId); 475 acpi_print_local_apic(lapic->Id, lapic->LapicFlags); 476 break; 477 case ACPI_MADT_TYPE_IO_APIC: 478 ioapic = (ACPI_MADT_IO_APIC *)mp; 479 acpi_print_io_apic(ioapic->Id, ioapic->GlobalIrqBase, 480 ioapic->Address); 481 break; 482 case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE: 483 over = (ACPI_MADT_INTERRUPT_OVERRIDE *)mp; 484 printf("\tBUS=%d\n", (u_int)over->Bus); 485 printf("\tIRQ=%d\n", (u_int)over->SourceIrq); 486 acpi_print_intr(over->GlobalIrq, over->IntiFlags); 487 break; 488 case ACPI_MADT_TYPE_NMI_SOURCE: 489 nmi = (ACPI_MADT_NMI_SOURCE *)mp; 490 acpi_print_intr(nmi->GlobalIrq, nmi->IntiFlags); 491 break; 492 case ACPI_MADT_TYPE_LOCAL_APIC_NMI: 493 lapic_nmi = (ACPI_MADT_LOCAL_APIC_NMI *)mp; 494 acpi_print_cpu(lapic_nmi->ProcessorId); 495 acpi_print_local_nmi(lapic_nmi->Lint, lapic_nmi->IntiFlags); 496 break; 497 case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE: 498 lapic_over = (ACPI_MADT_LOCAL_APIC_OVERRIDE *)mp; 499 printf("\tLocal APIC ADDR=0x%016jx\n", 500 (uintmax_t)lapic_over->Address); 501 break; 502 case ACPI_MADT_TYPE_IO_SAPIC: 503 iosapic = (ACPI_MADT_IO_SAPIC *)mp; 504 acpi_print_io_apic(iosapic->Id, iosapic->GlobalIrqBase, 505 iosapic->Address); 506 break; 507 case ACPI_MADT_TYPE_LOCAL_SAPIC: 508 lsapic = (ACPI_MADT_LOCAL_SAPIC *)mp; 509 acpi_print_cpu(lsapic->ProcessorId); 510 acpi_print_local_apic(lsapic->Id, lsapic->LapicFlags); 511 printf("\tAPIC EID=%d\n", (u_int)lsapic->Eid); 512 if (mp->Length > __offsetof(ACPI_MADT_LOCAL_SAPIC, Uid)) 513 acpi_print_cpu_uid(lsapic->Uid, lsapic->UidString); 514 break; 515 case ACPI_MADT_TYPE_INTERRUPT_SOURCE: 516 isrc = (ACPI_MADT_INTERRUPT_SOURCE *)mp; 517 if (isrc->Type < nitems(platform_int_types)) 518 printf("\tType=%s\n", platform_int_types[isrc->Type]); 519 else 520 printf("\tType=%d (unknown)\n", isrc->Type); 521 printf("\tAPIC ID=%d\n", (u_int)isrc->Id); 522 printf("\tAPIC EID=%d\n", (u_int)isrc->Eid); 523 printf("\tSAPIC Vector=%d\n", (u_int)isrc->IoSapicVector); 524 acpi_print_intr(isrc->GlobalIrq, isrc->IntiFlags); 525 break; 526 case ACPI_MADT_TYPE_LOCAL_X2APIC: 527 x2apic = (ACPI_MADT_LOCAL_X2APIC *)mp; 528 acpi_print_cpu_uid(x2apic->Uid, NULL); 529 acpi_print_local_apic(x2apic->LocalApicId, x2apic->LapicFlags); 530 break; 531 case ACPI_MADT_TYPE_LOCAL_X2APIC_NMI: 532 x2apic_nmi = (ACPI_MADT_LOCAL_X2APIC_NMI *)mp; 533 acpi_print_cpu_uid(x2apic_nmi->Uid, NULL); 534 acpi_print_local_nmi(x2apic_nmi->Lint, x2apic_nmi->IntiFlags); 535 break; 536 case ACPI_MADT_TYPE_GENERIC_INTERRUPT: 537 gicc = (ACPI_MADT_GENERIC_INTERRUPT *)mp; 538 acpi_print_cpu_uid(gicc->Uid, NULL); 539 printf("\tCPU INTERFACE=%x\n", gicc->CpuInterfaceNumber); 540 acpi_print_gicc_flags(gicc->Flags); 541 printf("\tParking Protocol Version=%x\n", gicc->ParkingVersion); 542 printf("\tPERF INTR=%d\n", gicc->PerformanceInterrupt); 543 printf("\tParked ADDR=%016jx\n", 544 (uintmax_t)gicc->ParkedAddress); 545 printf("\tBase ADDR=%016jx\n", (uintmax_t)gicc->BaseAddress); 546 printf("\tGICV=%016jx\n", (uintmax_t)gicc->GicvBaseAddress); 547 printf("\tGICH=%016jx\n", (uintmax_t)gicc->GichBaseAddress); 548 printf("\tVGIC INTR=%d\n", gicc->VgicInterrupt); 549 printf("\tGICR ADDR=%016jx\n", 550 (uintmax_t)gicc->GicrBaseAddress); 551 printf("\tMPIDR=%jx\n", (uintmax_t)gicc->ArmMpidr); 552 printf("\tEfficency Class=%d\n", (u_int)gicc->EfficiencyClass); 553 break; 554 case ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR: 555 gicd = (ACPI_MADT_GENERIC_DISTRIBUTOR *)mp; 556 printf("\tGIC ID=%d\n", (u_int)gicd->GicId); 557 printf("\tBase ADDR=%016jx\n", (uintmax_t)gicd->BaseAddress); 558 printf("\tVector Base=%d\n", gicd->GlobalIrqBase); 559 printf("\tGIC VERSION=%d\n", (u_int)gicd->Version); 560 break; 561 case ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR: 562 gicr = (ACPI_MADT_GENERIC_REDISTRIBUTOR *)mp; 563 printf("\tBase ADDR=%016jx\n", (uintmax_t)gicr->BaseAddress); 564 printf("\tLength=%08x\n", gicr->Length); 565 break; 566 case ACPI_MADT_TYPE_GENERIC_TRANSLATOR: 567 gict = (ACPI_MADT_GENERIC_TRANSLATOR *)mp; 568 printf("\tGIC ITS ID=%d\n", gict->TranslationId); 569 printf("\tBase ADDR=%016jx\n", (uintmax_t)gict->BaseAddress); 570 break; 571 } 572 } 573 574 static void 575 acpi_handle_madt(ACPI_TABLE_HEADER *sdp) 576 { 577 ACPI_TABLE_MADT *madt; 578 579 printf(BEGIN_COMMENT); 580 acpi_print_sdt(sdp); 581 madt = (ACPI_TABLE_MADT *)sdp; 582 printf("\tLocal APIC ADDR=0x%08x\n", madt->Address); 583 printf("\tFlags={"); 584 if (madt->Flags & ACPI_MADT_PCAT_COMPAT) 585 printf("PC-AT"); 586 printf("}\n"); 587 acpi_walk_subtables(sdp, (madt + 1), acpi_print_madt); 588 printf(END_COMMENT); 589 } 590 591 static void 592 acpi_handle_bert(ACPI_TABLE_HEADER *sdp) 593 { 594 ACPI_TABLE_BERT *bert; 595 596 printf(BEGIN_COMMENT); 597 acpi_print_sdt(sdp); 598 bert = (ACPI_TABLE_BERT *)sdp; 599 printf("\tRegionLength=%d\n", bert->RegionLength); 600 printf("\tAddress=0x%016jx\n", bert->Address); 601 printf(END_COMMENT); 602 } 603 604 static void 605 acpi_print_whea(ACPI_WHEA_HEADER *w) 606 { 607 608 printf("\n\tAction=%d\n", w->Action); 609 printf("\tInstruction=%d\n", w->Instruction); 610 printf("\tFlags=%02x\n", w->Flags); 611 printf("\tRegisterRegion="); 612 acpi_print_gas(&w->RegisterRegion); 613 printf("\n\tValue=0x%016jx\n", w->Value); 614 printf("\tMask=0x%016jx\n", w->Mask); 615 } 616 617 static void 618 acpi_handle_einj(ACPI_TABLE_HEADER *sdp) 619 { 620 ACPI_TABLE_EINJ *einj; 621 ACPI_WHEA_HEADER *w; 622 u_int i; 623 624 printf(BEGIN_COMMENT); 625 acpi_print_sdt(sdp); 626 einj = (ACPI_TABLE_EINJ *)sdp; 627 printf("\tHeaderLength=%d\n", einj->HeaderLength); 628 printf("\tFlags=0x%02x\n", einj->Flags); 629 printf("\tEntries=%d\n", einj->Entries); 630 w = (ACPI_WHEA_HEADER *)(einj + 1); 631 for (i = 0; i < MIN(einj->Entries, (sdp->Length - 632 sizeof(ACPI_TABLE_EINJ)) / sizeof(ACPI_WHEA_HEADER)); i++) 633 acpi_print_whea(w + i); 634 printf(END_COMMENT); 635 } 636 637 static void 638 acpi_handle_erst(ACPI_TABLE_HEADER *sdp) 639 { 640 ACPI_TABLE_ERST *erst; 641 ACPI_WHEA_HEADER *w; 642 u_int i; 643 644 printf(BEGIN_COMMENT); 645 acpi_print_sdt(sdp); 646 erst = (ACPI_TABLE_ERST *)sdp; 647 printf("\tHeaderLength=%d\n", erst->HeaderLength); 648 printf("\tEntries=%d\n", erst->Entries); 649 w = (ACPI_WHEA_HEADER *)(erst + 1); 650 for (i = 0; i < MIN(erst->Entries, (sdp->Length - 651 sizeof(ACPI_TABLE_ERST)) / sizeof(ACPI_WHEA_HEADER)); i++) 652 acpi_print_whea(w + i); 653 printf(END_COMMENT); 654 } 655 656 static void 657 acpi_print_hest_bank(ACPI_HEST_IA_ERROR_BANK *b) 658 { 659 660 printf("\tBank:\n"); 661 printf("\t\tBankNumber=%d\n", b->BankNumber); 662 printf("\t\tClearStatusOnInit=%d\n", b->ClearStatusOnInit); 663 printf("\t\tStatusFormat=%d\n", b->StatusFormat); 664 printf("\t\tControlRegister=%x\n", b->ControlRegister); 665 printf("\t\tControlData=%jx\n", b->ControlData); 666 printf("\t\tStatusRegister=%x\n", b->StatusRegister); 667 printf("\t\tAddressRegister=%x\n", b->AddressRegister); 668 printf("\t\tMiscRegister=%x\n", b->MiscRegister); 669 } 670 671 static void 672 acpi_print_hest_notify(ACPI_HEST_NOTIFY *n) 673 { 674 675 printf("\t\tType=%d\n", n->Type); 676 printf("\t\tLength=%d\n", n->Length); 677 printf("\t\tConfigWriteEnable=%04x\n", n->ConfigWriteEnable); 678 printf("\t\tPollInterval=%d\n", n->PollInterval); 679 printf("\t\tVector=%d\n", n->Vector); 680 printf("\t\tPollingThresholdValue=%d\n", n->PollingThresholdValue); 681 printf("\t\tPollingThresholdWindow=%d\n", n->PollingThresholdWindow); 682 printf("\t\tErrorThresholdValue=%d\n", n->ErrorThresholdValue); 683 printf("\t\tErrorThresholdWindow=%d\n", n->ErrorThresholdWindow); 684 } 685 686 static void 687 acpi_print_hest_aer(ACPI_HEST_AER_COMMON *a) 688 { 689 690 printf("\tFlags=%02x\n", a->Flags); 691 printf("\tEnabled=%d\n", a->Enabled); 692 printf("\tRecordsToPreallocate=%d\n", a->RecordsToPreallocate); 693 printf("\tMaxSectionsPerRecord=%d\n", a->MaxSectionsPerRecord); 694 printf("\tBus=%d\n", a->Bus); 695 printf("\tDevice=%d\n", a->Device); 696 printf("\tFunction=%d\n", a->Function); 697 printf("\tDeviceControl=%d\n", a->DeviceControl); 698 printf("\tUncorrectableMask=%d\n", a->UncorrectableMask); 699 printf("\tUncorrectableSeverity=%d\n", a->UncorrectableSeverity); 700 printf("\tCorrectableMask=%d\n", a->CorrectableMask); 701 printf("\tAdvancedCapabilities=%d\n", a->AdvancedCapabilities); 702 } 703 704 static int 705 acpi_handle_hest_structure(void *addr, int remaining) 706 { 707 ACPI_HEST_HEADER *hdr = addr; 708 int i; 709 710 if (remaining < (int)sizeof(ACPI_HEST_HEADER)) 711 return (-1); 712 713 printf("\n\tType=%d\n", hdr->Type); 714 printf("\tSourceId=%d\n", hdr->SourceId); 715 switch (hdr->Type) { 716 case ACPI_HEST_TYPE_IA32_CHECK: { 717 ACPI_HEST_IA_MACHINE_CHECK *s = addr; 718 printf("\tFlags=%02x\n", s->Flags); 719 printf("\tEnabled=%d\n", s->Enabled); 720 printf("\tRecordsToPreallocate=%d\n", s->RecordsToPreallocate); 721 printf("\tMaxSectionsPerRecord=%d\n", s->MaxSectionsPerRecord); 722 printf("\tGlobalCapabilityData=%jd\n", s->GlobalCapabilityData); 723 printf("\tGlobalControlData=%jd\n", s->GlobalControlData); 724 printf("\tNumHardwareBanks=%d\n", s->NumHardwareBanks); 725 for (i = 0; i < s->NumHardwareBanks; i++) { 726 acpi_print_hest_bank((ACPI_HEST_IA_ERROR_BANK *) 727 (s + 1) + i); 728 } 729 return (sizeof(*s) + s->NumHardwareBanks * 730 sizeof(ACPI_HEST_IA_ERROR_BANK)); 731 } 732 case ACPI_HEST_TYPE_IA32_CORRECTED_CHECK: { 733 ACPI_HEST_IA_CORRECTED *s = addr; 734 printf("\tFlags=%02x\n", s->Flags); 735 printf("\tEnabled=%d\n", s->Enabled); 736 printf("\tRecordsToPreallocate=%d\n", s->RecordsToPreallocate); 737 printf("\tMaxSectionsPerRecord=%d\n", s->MaxSectionsPerRecord); 738 printf("\tNotify:\n"); 739 acpi_print_hest_notify(&s->Notify); 740 printf("\tNumHardwareBanks=%d\n", s->NumHardwareBanks); 741 for (i = 0; i < s->NumHardwareBanks; i++) { 742 acpi_print_hest_bank((ACPI_HEST_IA_ERROR_BANK *) 743 (s + 1) + i); 744 } 745 return (sizeof(*s) + s->NumHardwareBanks * 746 sizeof(ACPI_HEST_IA_ERROR_BANK)); 747 } 748 case ACPI_HEST_TYPE_IA32_NMI: { 749 ACPI_HEST_IA_NMI *s = addr; 750 printf("\tRecordsToPreallocate=%d\n", s->RecordsToPreallocate); 751 printf("\tMaxSectionsPerRecord=%d\n", s->MaxSectionsPerRecord); 752 printf("\tMaxRawDataLength=%d\n", s->MaxRawDataLength); 753 return (sizeof(*s)); 754 } 755 case ACPI_HEST_TYPE_AER_ROOT_PORT: { 756 ACPI_HEST_AER_ROOT *s = addr; 757 acpi_print_hest_aer(&s->Aer); 758 printf("\tRootErrorCommand=%d\n", s->RootErrorCommand); 759 return (sizeof(*s)); 760 } 761 case ACPI_HEST_TYPE_AER_ENDPOINT: { 762 ACPI_HEST_AER *s = addr; 763 acpi_print_hest_aer(&s->Aer); 764 return (sizeof(*s)); 765 } 766 case ACPI_HEST_TYPE_AER_BRIDGE: { 767 ACPI_HEST_AER_BRIDGE *s = addr; 768 acpi_print_hest_aer(&s->Aer); 769 printf("\tUncorrectableMask2=%d\n", s->UncorrectableMask2); 770 printf("\tUncorrectableSeverity2=%d\n", s->UncorrectableSeverity2); 771 printf("\tAdvancedCapabilities2=%d\n", s->AdvancedCapabilities2); 772 return (sizeof(*s)); 773 } 774 case ACPI_HEST_TYPE_GENERIC_ERROR: { 775 ACPI_HEST_GENERIC *s = addr; 776 printf("\tRelatedSourceId=%d\n", s->RelatedSourceId); 777 printf("\tEnabled=%d\n", s->Enabled); 778 printf("\tRecordsToPreallocate=%d\n", s->RecordsToPreallocate); 779 printf("\tMaxSectionsPerRecord=%d\n", s->MaxSectionsPerRecord); 780 printf("\tMaxRawDataLength=%d\n", s->MaxRawDataLength); 781 printf("\tErrorStatusAddress="); 782 acpi_print_gas(&s->ErrorStatusAddress); 783 printf("\n"); 784 printf("\tNotify:\n"); 785 acpi_print_hest_notify(&s->Notify); 786 printf("\tErrorBlockLength=%d\n", s->ErrorBlockLength); 787 return (sizeof(*s)); 788 } 789 case ACPI_HEST_TYPE_GENERIC_ERROR_V2: { 790 ACPI_HEST_GENERIC_V2 *s = addr; 791 printf("\tRelatedSourceId=%d\n", s->RelatedSourceId); 792 printf("\tEnabled=%d\n", s->Enabled); 793 printf("\tRecordsToPreallocate=%d\n", s->RecordsToPreallocate); 794 printf("\tMaxSectionsPerRecord=%d\n", s->MaxSectionsPerRecord); 795 printf("\tMaxRawDataLength=%d\n", s->MaxRawDataLength); 796 printf("\tErrorStatusAddress="); 797 acpi_print_gas(&s->ErrorStatusAddress); 798 printf("\n"); 799 printf("\tNotify:\n"); 800 acpi_print_hest_notify(&s->Notify); 801 printf("\tErrorBlockLength=%d\n", s->ErrorBlockLength); 802 printf("\tReadAckRegister="); 803 acpi_print_gas(&s->ReadAckRegister); 804 printf("\n"); 805 printf("\tReadAckPreserve=%jd\n", s->ReadAckPreserve); 806 printf("\tReadAckWrite=%jd\n", s->ReadAckWrite); 807 return (sizeof(*s)); 808 } 809 case ACPI_HEST_TYPE_IA32_DEFERRED_CHECK: { 810 ACPI_HEST_IA_DEFERRED_CHECK *s = addr; 811 printf("\tFlags=%02x\n", s->Flags); 812 printf("\tEnabled=%d\n", s->Enabled); 813 printf("\tRecordsToPreallocate=%d\n", s->RecordsToPreallocate); 814 printf("\tMaxSectionsPerRecord=%d\n", s->MaxSectionsPerRecord); 815 printf("\tNotify:\n"); 816 acpi_print_hest_notify(&s->Notify); 817 printf("\tNumHardwareBanks=%d\n", s->NumHardwareBanks); 818 for (i = 0; i < s->NumHardwareBanks; i++) { 819 acpi_print_hest_bank((ACPI_HEST_IA_ERROR_BANK *) 820 (s + 1) + i); 821 } 822 return (sizeof(*s) + s->NumHardwareBanks * 823 sizeof(ACPI_HEST_IA_ERROR_BANK)); 824 } 825 default: 826 return (-1); 827 } 828 } 829 830 static void 831 acpi_handle_hest(ACPI_TABLE_HEADER *sdp) 832 { 833 char *cp; 834 int remaining, consumed; 835 ACPI_TABLE_HEST *hest; 836 837 printf(BEGIN_COMMENT); 838 acpi_print_sdt(sdp); 839 hest = (ACPI_TABLE_HEST *)sdp; 840 printf("\tErrorSourceCount=%d\n", hest->ErrorSourceCount); 841 842 remaining = sdp->Length - sizeof(ACPI_TABLE_HEST); 843 while (remaining > 0) { 844 cp = (char *)sdp + sdp->Length - remaining; 845 consumed = acpi_handle_hest_structure(cp, remaining); 846 if (consumed <= 0) 847 break; 848 else 849 remaining -= consumed; 850 } 851 printf(END_COMMENT); 852 } 853 854 static void 855 acpi_handle_hpet(ACPI_TABLE_HEADER *sdp) 856 { 857 ACPI_TABLE_HPET *hpet; 858 859 printf(BEGIN_COMMENT); 860 acpi_print_sdt(sdp); 861 hpet = (ACPI_TABLE_HPET *)sdp; 862 printf("\tHPET Number=%d\n", hpet->Sequence); 863 printf("\tADDR="); 864 acpi_print_gas(&hpet->Address); 865 printf("\n\tHW Rev=0x%x\n", hpet->Id & ACPI_HPET_ID_HARDWARE_REV_ID); 866 printf("\tComparators=%d\n", (hpet->Id & ACPI_HPET_ID_COMPARATORS) >> 867 8); 868 printf("\tCounter Size=%d\n", hpet->Id & ACPI_HPET_ID_COUNT_SIZE_CAP ? 869 1 : 0); 870 printf("\tLegacy IRQ routing capable={"); 871 if (hpet->Id & ACPI_HPET_ID_LEGACY_CAPABLE) 872 printf("TRUE}\n"); 873 else 874 printf("FALSE}\n"); 875 printf("\tPCI Vendor ID=0x%04x\n", hpet->Id >> 16); 876 printf("\tMinimal Tick=%d\n", hpet->MinimumTick); 877 printf("\tFlags=0x%02x\n", hpet->Flags); 878 printf(END_COMMENT); 879 } 880 881 static void 882 acpi_handle_ecdt(ACPI_TABLE_HEADER *sdp) 883 { 884 ACPI_TABLE_ECDT *ecdt; 885 886 printf(BEGIN_COMMENT); 887 acpi_print_sdt(sdp); 888 ecdt = (ACPI_TABLE_ECDT *)sdp; 889 printf("\tEC_CONTROL="); 890 acpi_print_gas(&ecdt->Control); 891 printf("\n\tEC_DATA="); 892 acpi_print_gas(&ecdt->Data); 893 printf("\n\tUID=%#x, ", ecdt->Uid); 894 printf("GPE_BIT=%#x\n", ecdt->Gpe); 895 printf("\tEC_ID=%s\n", ecdt->Id); 896 printf(END_COMMENT); 897 } 898 899 static void 900 acpi_handle_mcfg(ACPI_TABLE_HEADER *sdp) 901 { 902 ACPI_TABLE_MCFG *mcfg; 903 ACPI_MCFG_ALLOCATION *alloc; 904 u_int i, entries; 905 906 printf(BEGIN_COMMENT); 907 acpi_print_sdt(sdp); 908 mcfg = (ACPI_TABLE_MCFG *)sdp; 909 entries = (sdp->Length - sizeof(ACPI_TABLE_MCFG)) / 910 sizeof(ACPI_MCFG_ALLOCATION); 911 alloc = (ACPI_MCFG_ALLOCATION *)(mcfg + 1); 912 for (i = 0; i < entries; i++, alloc++) { 913 printf("\n"); 914 printf("\tBase Address=0x%016jx\n", (uintmax_t)alloc->Address); 915 printf("\tSegment Group=0x%04x\n", alloc->PciSegment); 916 printf("\tStart Bus=%d\n", alloc->StartBusNumber); 917 printf("\tEnd Bus=%d\n", alloc->EndBusNumber); 918 } 919 printf(END_COMMENT); 920 } 921 922 static void 923 acpi_handle_slit(ACPI_TABLE_HEADER *sdp) 924 { 925 ACPI_TABLE_SLIT *slit; 926 UINT64 i, j; 927 928 printf(BEGIN_COMMENT); 929 acpi_print_sdt(sdp); 930 slit = (ACPI_TABLE_SLIT *)sdp; 931 printf("\tLocality Count=%ju\n", (uintmax_t)slit->LocalityCount); 932 printf("\n\t "); 933 for (i = 0; i < slit->LocalityCount; i++) 934 printf(" %3ju", (uintmax_t)i); 935 printf("\n\t +"); 936 for (i = 0; i < slit->LocalityCount; i++) 937 printf("----"); 938 printf("\n"); 939 for (i = 0; i < slit->LocalityCount; i++) { 940 printf("\t %3ju |", (uintmax_t)i); 941 for (j = 0; j < slit->LocalityCount; j++) 942 printf(" %3d", 943 slit->Entry[i * slit->LocalityCount + j]); 944 printf("\n"); 945 } 946 printf(END_COMMENT); 947 } 948 949 static void 950 acpi_handle_wddt(ACPI_TABLE_HEADER *sdp) 951 { 952 ACPI_TABLE_WDDT *wddt; 953 954 printf(BEGIN_COMMENT); 955 acpi_print_sdt(sdp); 956 wddt = (ACPI_TABLE_WDDT *)sdp; 957 printf("\tSpecVersion=0x%04x, TableVersion=0x%04x\n", 958 wddt->SpecVersion, wddt->TableVersion); 959 printf("\tPciVendorId=0x%04x, Address=", wddt->PciVendorId); 960 acpi_print_gas(&wddt->Address); 961 printf("\n\tMaxCount=%u, MinCount=%u, Period=%ums\n", 962 wddt->MaxCount, wddt->MinCount, wddt->Period); 963 964 #define PRINTFLAG(var, flag) printflag((var), ACPI_WDDT_## flag, #flag) 965 printf("\tStatus="); 966 PRINTFLAG(wddt->Status, AVAILABLE); 967 PRINTFLAG(wddt->Status, ACTIVE); 968 PRINTFLAG(wddt->Status, TCO_OS_OWNED); 969 PRINTFLAG(wddt->Status, USER_RESET); 970 PRINTFLAG(wddt->Status, WDT_RESET); 971 PRINTFLAG(wddt->Status, POWER_FAIL); 972 PRINTFLAG(wddt->Status, UNKNOWN_RESET); 973 PRINTFLAG_END(); 974 printf("\tCapability="); 975 PRINTFLAG(wddt->Capability, AUTO_RESET); 976 PRINTFLAG(wddt->Capability, ALERT_SUPPORT); 977 PRINTFLAG_END(); 978 #undef PRINTFLAG 979 980 printf(END_COMMENT); 981 } 982 983 static void 984 acpi_print_native_lpit(ACPI_LPIT_NATIVE *nl) 985 { 986 printf("\tEntryTrigger="); 987 acpi_print_gas(&nl->EntryTrigger); 988 printf("\n\tResidency=%u\n", nl->Residency); 989 printf("\tLatency=%u\n", nl->Latency); 990 if (nl->Header.Flags & ACPI_LPIT_NO_COUNTER) 991 printf("\tResidencyCounter=Not Present"); 992 else { 993 printf("\tResidencyCounter="); 994 acpi_print_gas(&nl->ResidencyCounter); 995 printf("\n"); 996 } 997 if (nl->CounterFrequency) 998 printf("\tCounterFrequency=%ju\n", nl->CounterFrequency); 999 else 1000 printf("\tCounterFrequency=TSC\n"); 1001 } 1002 1003 static void 1004 acpi_print_lpit(ACPI_LPIT_HEADER *lpit) 1005 { 1006 if (lpit->Type == ACPI_LPIT_TYPE_NATIVE_CSTATE) 1007 printf("\tType=ACPI_LPIT_TYPE_NATIVE_CSTATE\n"); 1008 else 1009 warnx("unknown LPIT type %u", lpit->Type); 1010 1011 printf("\tLength=%u\n", lpit->Length); 1012 printf("\tUniqueId=0x%04x\n", lpit->UniqueId); 1013 #define PRINTFLAG(var, flag) printflag((var), ACPI_LPIT_## flag, #flag) 1014 printf("\tFlags="); 1015 PRINTFLAG(lpit->Flags, STATE_DISABLED); 1016 PRINTFLAG_END(); 1017 #undef PRINTFLAG 1018 1019 if (lpit->Type == ACPI_LPIT_TYPE_NATIVE_CSTATE) 1020 return acpi_print_native_lpit((ACPI_LPIT_NATIVE *)lpit); 1021 } 1022 1023 static void 1024 acpi_walk_lpit(ACPI_TABLE_HEADER *table, void *first, 1025 void (*action)(ACPI_LPIT_HEADER *)) 1026 { 1027 ACPI_LPIT_HEADER *subtable; 1028 char *end; 1029 1030 subtable = first; 1031 end = (char *)table + table->Length; 1032 while ((char *)subtable < end) { 1033 printf("\n"); 1034 if (subtable->Length < sizeof(ACPI_LPIT_HEADER)) { 1035 warnx("invalid subtable length %u", subtable->Length); 1036 return; 1037 } 1038 action(subtable); 1039 subtable = (ACPI_LPIT_HEADER *)((char *)subtable + 1040 subtable->Length); 1041 } 1042 } 1043 1044 static void 1045 acpi_handle_lpit(ACPI_TABLE_HEADER *sdp) 1046 { 1047 ACPI_TABLE_LPIT *lpit; 1048 1049 printf(BEGIN_COMMENT); 1050 acpi_print_sdt(sdp); 1051 lpit = (ACPI_TABLE_LPIT *)sdp; 1052 acpi_walk_lpit(sdp, (lpit + 1), acpi_print_lpit); 1053 1054 printf(END_COMMENT); 1055 } 1056 1057 static void 1058 acpi_print_srat_cpu(uint32_t apic_id, uint32_t proximity_domain, 1059 uint32_t flags) 1060 { 1061 1062 printf("\tFlags={"); 1063 if (flags & ACPI_SRAT_CPU_ENABLED) 1064 printf("ENABLED"); 1065 else 1066 printf("DISABLED"); 1067 printf("}\n"); 1068 printf("\tAPIC ID=%d\n", apic_id); 1069 printf("\tProximity Domain=%d\n", proximity_domain); 1070 } 1071 1072 static char * 1073 acpi_tcpa_evname(struct TCPAevent *event) 1074 { 1075 struct TCPApc_event *pc_event; 1076 char *eventname = NULL; 1077 1078 pc_event = (struct TCPApc_event *)(event + 1); 1079 1080 switch(event->event_type) { 1081 case PREBOOT: 1082 case POST_CODE: 1083 case UNUSED: 1084 case NO_ACTION: 1085 case SEPARATOR: 1086 case SCRTM_CONTENTS: 1087 case SCRTM_VERSION: 1088 case CPU_MICROCODE: 1089 case PLATFORM_CONFIG_FLAGS: 1090 case TABLE_OF_DEVICES: 1091 case COMPACT_HASH: 1092 case IPL: 1093 case IPL_PARTITION_DATA: 1094 case NONHOST_CODE: 1095 case NONHOST_CONFIG: 1096 case NONHOST_INFO: 1097 asprintf(&eventname, "%s", 1098 tcpa_event_type_strings[event->event_type]); 1099 break; 1100 1101 case ACTION: 1102 eventname = calloc(event->event_size + 1, sizeof(char)); 1103 memcpy(eventname, pc_event, event->event_size); 1104 break; 1105 1106 case EVENT_TAG: 1107 switch (pc_event->event_id) { 1108 case SMBIOS: 1109 case BIS_CERT: 1110 case CMOS: 1111 case NVRAM: 1112 case OPTION_ROM_EXEC: 1113 case OPTION_ROM_CONFIG: 1114 case S_CRTM_VERSION: 1115 case POST_BIOS_ROM: 1116 case ESCD: 1117 case OPTION_ROM_MICROCODE: 1118 case S_CRTM_CONTENTS: 1119 case POST_CONTENTS: 1120 asprintf(&eventname, "%s", 1121 TCPA_pcclient_strings[pc_event->event_id]); 1122 break; 1123 1124 default: 1125 asprintf(&eventname, "<unknown tag 0x%02x>", 1126 pc_event->event_id); 1127 break; 1128 } 1129 break; 1130 1131 default: 1132 asprintf(&eventname, "<unknown 0x%02x>", event->event_type); 1133 break; 1134 } 1135 1136 return eventname; 1137 } 1138 1139 static void 1140 acpi_print_tcpa(struct TCPAevent *event) 1141 { 1142 int i; 1143 char *eventname; 1144 1145 eventname = acpi_tcpa_evname(event); 1146 1147 printf("\t%d", event->pcr_index); 1148 printf(" 0x"); 1149 for (i = 0; i < 20; i++) 1150 printf("%02x", event->pcr_value[i]); 1151 printf(" [%s]\n", eventname ? eventname : "<unknown>"); 1152 1153 free(eventname); 1154 } 1155 1156 static void 1157 acpi_handle_tcpa(ACPI_TABLE_HEADER *sdp) 1158 { 1159 struct TCPAbody *tcpa; 1160 struct TCPAevent *event; 1161 uintmax_t len, paddr; 1162 unsigned char *vaddr = NULL; 1163 unsigned char *vend = NULL; 1164 1165 printf(BEGIN_COMMENT); 1166 acpi_print_sdt(sdp); 1167 tcpa = (struct TCPAbody *) sdp; 1168 1169 switch (tcpa->platform_class) { 1170 case ACPI_TCPA_BIOS_CLIENT: 1171 len = tcpa->client.log_max_len; 1172 paddr = tcpa->client.log_start_addr; 1173 break; 1174 1175 case ACPI_TCPA_BIOS_SERVER: 1176 len = tcpa->server.log_max_len; 1177 paddr = tcpa->server.log_start_addr; 1178 break; 1179 1180 default: 1181 printf("XXX"); 1182 printf(END_COMMENT); 1183 return; 1184 } 1185 printf("\tClass %u Base Address 0x%jx Length %ju\n\n", 1186 tcpa->platform_class, paddr, len); 1187 1188 if (len == 0) { 1189 printf("\tEmpty TCPA table\n"); 1190 printf(END_COMMENT); 1191 return; 1192 } 1193 if(sdp->Revision == 1){ 1194 printf("\tOLD TCPA spec log found. Dumping not supported.\n"); 1195 printf(END_COMMENT); 1196 return; 1197 } 1198 1199 vaddr = (unsigned char *)acpi_map_physical(paddr, len); 1200 vend = vaddr + len; 1201 1202 while (vaddr != NULL) { 1203 if ((vaddr + sizeof(struct TCPAevent) >= vend)|| 1204 (vaddr + sizeof(struct TCPAevent) < vaddr)) 1205 break; 1206 event = (struct TCPAevent *)(void *)vaddr; 1207 if (vaddr + event->event_size >= vend) 1208 break; 1209 if (vaddr + event->event_size < vaddr) 1210 break; 1211 if (event->event_type == 0 && event->event_size == 0) 1212 break; 1213 #if 0 1214 { 1215 unsigned int i, j, k; 1216 1217 printf("\n\tsize %d\n\t\t%p ", event->event_size, vaddr); 1218 for (j = 0, i = 0; i < 1219 sizeof(struct TCPAevent) + event->event_size; i++) { 1220 printf("%02x ", vaddr[i]); 1221 if ((i+1) % 8 == 0) { 1222 for (k = 0; k < 8; k++) 1223 printf("%c", isprint(vaddr[j+k]) ? 1224 vaddr[j+k] : '.'); 1225 printf("\n\t\t%p ", &vaddr[i + 1]); 1226 j = i + 1; 1227 } 1228 } 1229 printf("\n"); } 1230 #endif 1231 acpi_print_tcpa(event); 1232 1233 vaddr += sizeof(struct TCPAevent) + event->event_size; 1234 } 1235 1236 printf(END_COMMENT); 1237 } 1238 static void acpi_handle_tpm2(ACPI_TABLE_HEADER *sdp) 1239 { 1240 ACPI_TABLE_TPM2 *tpm2; 1241 1242 printf (BEGIN_COMMENT); 1243 acpi_print_sdt(sdp); 1244 tpm2 = (ACPI_TABLE_TPM2 *) sdp; 1245 printf ("\t\tControlArea=%jx\n", tpm2->ControlAddress); 1246 printf ("\t\tStartMethod=%x\n", tpm2->StartMethod); 1247 printf (END_COMMENT); 1248 } 1249 1250 static const char * 1251 devscope_type2str(int type) 1252 { 1253 static char typebuf[16]; 1254 1255 switch (type) { 1256 case 1: 1257 return ("PCI Endpoint Device"); 1258 case 2: 1259 return ("PCI Sub-Hierarchy"); 1260 case 3: 1261 return ("IOAPIC"); 1262 case 4: 1263 return ("HPET"); 1264 default: 1265 snprintf(typebuf, sizeof(typebuf), "%d", type); 1266 return (typebuf); 1267 } 1268 } 1269 1270 static int 1271 acpi_handle_dmar_devscope(void *addr, int remaining) 1272 { 1273 char sep; 1274 int pathlen; 1275 ACPI_DMAR_PCI_PATH *path, *pathend; 1276 ACPI_DMAR_DEVICE_SCOPE *devscope = addr; 1277 1278 if (remaining < (int)sizeof(ACPI_DMAR_DEVICE_SCOPE)) 1279 return (-1); 1280 1281 if (remaining < devscope->Length) 1282 return (-1); 1283 1284 printf("\n"); 1285 printf("\t\tType=%s\n", devscope_type2str(devscope->EntryType)); 1286 printf("\t\tLength=%d\n", devscope->Length); 1287 printf("\t\tEnumerationId=%d\n", devscope->EnumerationId); 1288 printf("\t\tStartBusNumber=%d\n", devscope->Bus); 1289 1290 path = (ACPI_DMAR_PCI_PATH *)(devscope + 1); 1291 pathlen = devscope->Length - sizeof(ACPI_DMAR_DEVICE_SCOPE); 1292 pathend = path + pathlen / sizeof(ACPI_DMAR_PCI_PATH); 1293 if (path < pathend) { 1294 sep = '{'; 1295 printf("\t\tPath="); 1296 do { 1297 printf("%c%d:%d", sep, path->Device, path->Function); 1298 sep=','; 1299 path++; 1300 } while (path < pathend); 1301 printf("}\n"); 1302 } 1303 1304 return (devscope->Length); 1305 } 1306 1307 static void 1308 acpi_handle_dmar_drhd(ACPI_DMAR_HARDWARE_UNIT *drhd) 1309 { 1310 char *cp; 1311 int remaining, consumed; 1312 1313 printf("\n"); 1314 printf("\tType=DRHD\n"); 1315 printf("\tLength=%d\n", drhd->Header.Length); 1316 1317 #define PRINTFLAG(var, flag) printflag((var), ACPI_DMAR_## flag, #flag) 1318 1319 printf("\tFlags="); 1320 PRINTFLAG(drhd->Flags, INCLUDE_ALL); 1321 PRINTFLAG_END(); 1322 1323 #undef PRINTFLAG 1324 1325 printf("\tSegment=%d\n", drhd->Segment); 1326 printf("\tAddress=0x%016jx\n", (uintmax_t)drhd->Address); 1327 1328 remaining = drhd->Header.Length - sizeof(ACPI_DMAR_HARDWARE_UNIT); 1329 if (remaining > 0) 1330 printf("\tDevice Scope:"); 1331 while (remaining > 0) { 1332 cp = (char *)drhd + drhd->Header.Length - remaining; 1333 consumed = acpi_handle_dmar_devscope(cp, remaining); 1334 if (consumed <= 0) 1335 break; 1336 else 1337 remaining -= consumed; 1338 } 1339 } 1340 1341 static void 1342 acpi_handle_dmar_rmrr(ACPI_DMAR_RESERVED_MEMORY *rmrr) 1343 { 1344 char *cp; 1345 int remaining, consumed; 1346 1347 printf("\n"); 1348 printf("\tType=RMRR\n"); 1349 printf("\tLength=%d\n", rmrr->Header.Length); 1350 printf("\tSegment=%d\n", rmrr->Segment); 1351 printf("\tBaseAddress=0x%016jx\n", (uintmax_t)rmrr->BaseAddress); 1352 printf("\tLimitAddress=0x%016jx\n", (uintmax_t)rmrr->EndAddress); 1353 1354 remaining = rmrr->Header.Length - sizeof(ACPI_DMAR_RESERVED_MEMORY); 1355 if (remaining > 0) 1356 printf("\tDevice Scope:"); 1357 while (remaining > 0) { 1358 cp = (char *)rmrr + rmrr->Header.Length - remaining; 1359 consumed = acpi_handle_dmar_devscope(cp, remaining); 1360 if (consumed <= 0) 1361 break; 1362 else 1363 remaining -= consumed; 1364 } 1365 } 1366 1367 static void 1368 acpi_handle_dmar_atsr(ACPI_DMAR_ATSR *atsr) 1369 { 1370 char *cp; 1371 int remaining, consumed; 1372 1373 printf("\n"); 1374 printf("\tType=ATSR\n"); 1375 printf("\tLength=%d\n", atsr->Header.Length); 1376 1377 #define PRINTFLAG(var, flag) printflag((var), ACPI_DMAR_## flag, #flag) 1378 1379 printf("\tFlags="); 1380 PRINTFLAG(atsr->Flags, ALL_PORTS); 1381 PRINTFLAG_END(); 1382 1383 #undef PRINTFLAG 1384 1385 printf("\tSegment=%d\n", atsr->Segment); 1386 1387 remaining = atsr->Header.Length - sizeof(ACPI_DMAR_ATSR); 1388 if (remaining > 0) 1389 printf("\tDevice Scope:"); 1390 while (remaining > 0) { 1391 cp = (char *)atsr + atsr->Header.Length - remaining; 1392 consumed = acpi_handle_dmar_devscope(cp, remaining); 1393 if (consumed <= 0) 1394 break; 1395 else 1396 remaining -= consumed; 1397 } 1398 } 1399 1400 static void 1401 acpi_handle_dmar_rhsa(ACPI_DMAR_RHSA *rhsa) 1402 { 1403 1404 printf("\n"); 1405 printf("\tType=RHSA\n"); 1406 printf("\tLength=%d\n", rhsa->Header.Length); 1407 printf("\tBaseAddress=0x%016jx\n", (uintmax_t)rhsa->BaseAddress); 1408 printf("\tProximityDomain=0x%08x\n", rhsa->ProximityDomain); 1409 } 1410 1411 static int 1412 acpi_handle_dmar_remapping_structure(void *addr, int remaining) 1413 { 1414 ACPI_DMAR_HEADER *hdr = addr; 1415 1416 if (remaining < (int)sizeof(ACPI_DMAR_HEADER)) 1417 return (-1); 1418 1419 if (remaining < hdr->Length) 1420 return (-1); 1421 1422 switch (hdr->Type) { 1423 case ACPI_DMAR_TYPE_HARDWARE_UNIT: 1424 acpi_handle_dmar_drhd(addr); 1425 break; 1426 case ACPI_DMAR_TYPE_RESERVED_MEMORY: 1427 acpi_handle_dmar_rmrr(addr); 1428 break; 1429 case ACPI_DMAR_TYPE_ROOT_ATS: 1430 acpi_handle_dmar_atsr(addr); 1431 break; 1432 case ACPI_DMAR_TYPE_HARDWARE_AFFINITY: 1433 acpi_handle_dmar_rhsa(addr); 1434 break; 1435 default: 1436 printf("\n"); 1437 printf("\tType=%d\n", hdr->Type); 1438 printf("\tLength=%d\n", hdr->Length); 1439 break; 1440 } 1441 return (hdr->Length); 1442 } 1443 1444 #ifndef ACPI_DMAR_X2APIC_OPT_OUT 1445 #define ACPI_DMAR_X2APIC_OPT_OUT (0x2) 1446 #endif 1447 1448 static void 1449 acpi_handle_dmar(ACPI_TABLE_HEADER *sdp) 1450 { 1451 char *cp; 1452 int remaining, consumed; 1453 ACPI_TABLE_DMAR *dmar; 1454 1455 printf(BEGIN_COMMENT); 1456 acpi_print_sdt(sdp); 1457 dmar = (ACPI_TABLE_DMAR *)sdp; 1458 printf("\tHost Address Width=%d\n", dmar->Width + 1); 1459 1460 #define PRINTFLAG(var, flag) printflag((var), ACPI_DMAR_## flag, #flag) 1461 1462 printf("\tFlags="); 1463 PRINTFLAG(dmar->Flags, INTR_REMAP); 1464 PRINTFLAG(dmar->Flags, X2APIC_OPT_OUT); 1465 PRINTFLAG_END(); 1466 1467 #undef PRINTFLAG 1468 1469 remaining = sdp->Length - sizeof(ACPI_TABLE_DMAR); 1470 while (remaining > 0) { 1471 cp = (char *)sdp + sdp->Length - remaining; 1472 consumed = acpi_handle_dmar_remapping_structure(cp, remaining); 1473 if (consumed <= 0) 1474 break; 1475 else 1476 remaining -= consumed; 1477 } 1478 1479 printf(END_COMMENT); 1480 } 1481 1482 static void 1483 acpi_print_srat_memory(ACPI_SRAT_MEM_AFFINITY *mp) 1484 { 1485 1486 printf("\tFlags={"); 1487 if (mp->Flags & ACPI_SRAT_MEM_ENABLED) 1488 printf("ENABLED"); 1489 else 1490 printf("DISABLED"); 1491 if (mp->Flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) 1492 printf(",HOT_PLUGGABLE"); 1493 if (mp->Flags & ACPI_SRAT_MEM_NON_VOLATILE) 1494 printf(",NON_VOLATILE"); 1495 printf("}\n"); 1496 printf("\tBase Address=0x%016jx\n", (uintmax_t)mp->BaseAddress); 1497 printf("\tLength=0x%016jx\n", (uintmax_t)mp->Length); 1498 printf("\tProximity Domain=%d\n", mp->ProximityDomain); 1499 } 1500 1501 static const char *srat_types[] = { 1502 [ACPI_SRAT_TYPE_CPU_AFFINITY] = "CPU", 1503 [ACPI_SRAT_TYPE_MEMORY_AFFINITY] = "Memory", 1504 [ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY] = "X2APIC", 1505 [ACPI_SRAT_TYPE_GICC_AFFINITY] = "GICC", 1506 [ACPI_SRAT_TYPE_GIC_ITS_AFFINITY] = "GIC ITS", 1507 }; 1508 1509 static void 1510 acpi_print_srat(ACPI_SUBTABLE_HEADER *srat) 1511 { 1512 ACPI_SRAT_CPU_AFFINITY *cpu; 1513 ACPI_SRAT_X2APIC_CPU_AFFINITY *x2apic; 1514 ACPI_SRAT_GICC_AFFINITY *gic; 1515 1516 if (srat->Type < nitems(srat_types)) 1517 printf("\tType=%s\n", srat_types[srat->Type]); 1518 else 1519 printf("\tType=%d (unknown)\n", srat->Type); 1520 switch (srat->Type) { 1521 case ACPI_SRAT_TYPE_CPU_AFFINITY: 1522 cpu = (ACPI_SRAT_CPU_AFFINITY *)srat; 1523 acpi_print_srat_cpu(cpu->ApicId, 1524 cpu->ProximityDomainHi[2] << 24 | 1525 cpu->ProximityDomainHi[1] << 16 | 1526 cpu->ProximityDomainHi[0] << 0 | 1527 cpu->ProximityDomainLo, cpu->Flags); 1528 break; 1529 case ACPI_SRAT_TYPE_MEMORY_AFFINITY: 1530 acpi_print_srat_memory((ACPI_SRAT_MEM_AFFINITY *)srat); 1531 break; 1532 case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY: 1533 x2apic = (ACPI_SRAT_X2APIC_CPU_AFFINITY *)srat; 1534 acpi_print_srat_cpu(x2apic->ApicId, x2apic->ProximityDomain, 1535 x2apic->Flags); 1536 break; 1537 case ACPI_SRAT_TYPE_GICC_AFFINITY: 1538 gic = (ACPI_SRAT_GICC_AFFINITY *)srat; 1539 acpi_print_srat_cpu(gic->AcpiProcessorUid, gic->ProximityDomain, 1540 gic->Flags); 1541 break; 1542 } 1543 } 1544 1545 static void 1546 acpi_handle_srat(ACPI_TABLE_HEADER *sdp) 1547 { 1548 ACPI_TABLE_SRAT *srat; 1549 1550 printf(BEGIN_COMMENT); 1551 acpi_print_sdt(sdp); 1552 srat = (ACPI_TABLE_SRAT *)sdp; 1553 printf("\tTable Revision=%d\n", srat->TableRevision); 1554 acpi_walk_subtables(sdp, (srat + 1), acpi_print_srat); 1555 printf(END_COMMENT); 1556 } 1557 1558 static const char *nfit_types[] = { 1559 [ACPI_NFIT_TYPE_SYSTEM_ADDRESS] = "System Address", 1560 [ACPI_NFIT_TYPE_MEMORY_MAP] = "Memory Map", 1561 [ACPI_NFIT_TYPE_INTERLEAVE] = "Interleave", 1562 [ACPI_NFIT_TYPE_SMBIOS] = "SMBIOS", 1563 [ACPI_NFIT_TYPE_CONTROL_REGION] = "Control Region", 1564 [ACPI_NFIT_TYPE_DATA_REGION] = "Data Region", 1565 [ACPI_NFIT_TYPE_FLUSH_ADDRESS] = "Flush Address" 1566 }; 1567 1568 1569 static void 1570 acpi_print_nfit(ACPI_NFIT_HEADER *nfit) 1571 { 1572 char *uuidstr; 1573 uint32_t status; 1574 1575 ACPI_NFIT_SYSTEM_ADDRESS *sysaddr; 1576 ACPI_NFIT_MEMORY_MAP *mmap; 1577 ACPI_NFIT_INTERLEAVE *ileave; 1578 ACPI_NFIT_SMBIOS *smbios; 1579 ACPI_NFIT_CONTROL_REGION *ctlreg; 1580 ACPI_NFIT_DATA_REGION *datareg; 1581 ACPI_NFIT_FLUSH_ADDRESS *fladdr; 1582 1583 if (nfit->Type < nitems(nfit_types)) 1584 printf("\tType=%s\n", nfit_types[nfit->Type]); 1585 else 1586 printf("\tType=%u (unknown)\n", nfit->Type); 1587 switch (nfit->Type) { 1588 case ACPI_NFIT_TYPE_SYSTEM_ADDRESS: 1589 sysaddr = (ACPI_NFIT_SYSTEM_ADDRESS *)nfit; 1590 printf("\tRangeIndex=%u\n", (u_int)sysaddr->RangeIndex); 1591 printf("\tProximityDomain=%u\n", 1592 (u_int)sysaddr->ProximityDomain); 1593 uuid_to_string((uuid_t *)(sysaddr->RangeGuid), 1594 &uuidstr, &status); 1595 if (status != uuid_s_ok) 1596 errx(1, "uuid_to_string: status=%u", status); 1597 printf("\tRangeGuid=%s\n", uuidstr); 1598 free(uuidstr); 1599 printf("\tAddress=0x%016jx\n", (uintmax_t)sysaddr->Address); 1600 printf("\tLength=0x%016jx\n", (uintmax_t)sysaddr->Length); 1601 printf("\tMemoryMapping=0x%016jx\n", 1602 (uintmax_t)sysaddr->MemoryMapping); 1603 1604 #define PRINTFLAG(var, flag) printflag((var), ACPI_NFIT_## flag, #flag) 1605 1606 printf("\tFlags="); 1607 PRINTFLAG(sysaddr->Flags, ADD_ONLINE_ONLY); 1608 PRINTFLAG(sysaddr->Flags, PROXIMITY_VALID); 1609 PRINTFLAG_END(); 1610 1611 #undef PRINTFLAG 1612 1613 break; 1614 case ACPI_NFIT_TYPE_MEMORY_MAP: 1615 mmap = (ACPI_NFIT_MEMORY_MAP *)nfit; 1616 printf("\tDeviceHandle=%u\n", (u_int)mmap->DeviceHandle); 1617 printf("\tPhysicalId=%u\n", (u_int)mmap->PhysicalId); 1618 printf("\tRegionId=%u\n", (u_int)mmap->RegionId); 1619 printf("\tRangeIndex=%u\n", (u_int)mmap->RangeIndex); 1620 printf("\tRegionIndex=%u\n", (u_int)mmap->RegionIndex); 1621 printf("\tRegionSize=0x%016jx\n", (uintmax_t)mmap->RegionSize); 1622 printf("\tRegionOffset=0x%016jx\n", 1623 (uintmax_t)mmap->RegionOffset); 1624 printf("\tAddress=0x%016jx\n", (uintmax_t)mmap->Address); 1625 printf("\tInterleaveIndex=%u\n", (u_int)mmap->InterleaveIndex); 1626 printf("\tInterleaveWays=%u\n", (u_int)mmap->InterleaveWays); 1627 1628 #define PRINTFLAG(var, flag) printflag((var), ACPI_NFIT_MEM_## flag, #flag) 1629 1630 printf("\tFlags="); 1631 PRINTFLAG(mmap->Flags, SAVE_FAILED); 1632 PRINTFLAG(mmap->Flags, RESTORE_FAILED); 1633 PRINTFLAG(mmap->Flags, FLUSH_FAILED); 1634 PRINTFLAG(mmap->Flags, NOT_ARMED); 1635 PRINTFLAG(mmap->Flags, HEALTH_OBSERVED); 1636 PRINTFLAG(mmap->Flags, HEALTH_ENABLED); 1637 PRINTFLAG(mmap->Flags, MAP_FAILED); 1638 PRINTFLAG_END(); 1639 1640 #undef PRINTFLAG 1641 1642 break; 1643 case ACPI_NFIT_TYPE_INTERLEAVE: 1644 ileave = (ACPI_NFIT_INTERLEAVE *)nfit; 1645 printf("\tInterleaveIndex=%u\n", 1646 (u_int)ileave->InterleaveIndex); 1647 printf("\tLineCount=%u\n", (u_int)ileave->LineCount); 1648 printf("\tLineSize=%u\n", (u_int)ileave->LineSize); 1649 /* XXX ileave->LineOffset[i] output is not supported */ 1650 break; 1651 case ACPI_NFIT_TYPE_SMBIOS: 1652 smbios = (ACPI_NFIT_SMBIOS *)nfit; 1653 /* XXX smbios->Data[x] output is not supported */ 1654 break; 1655 case ACPI_NFIT_TYPE_CONTROL_REGION: 1656 ctlreg = (ACPI_NFIT_CONTROL_REGION *)nfit; 1657 printf("\tRegionIndex=%u\n", (u_int)ctlreg->RegionIndex); 1658 printf("\tVendorId=0x%04x\n", (u_int)ctlreg->VendorId); 1659 printf("\tDeviceId=0x%04x\n", (u_int)ctlreg->DeviceId); 1660 printf("\tRevisionId=%u\n", (u_int)ctlreg->RevisionId); 1661 printf("\tSubsystemVendorId=0x%04x\n", 1662 (u_int)ctlreg->SubsystemVendorId); 1663 printf("\tSubsystemDeviceId=0x%04x\n", 1664 (u_int)ctlreg->SubsystemDeviceId); 1665 printf("\tSubsystemRevisionId=%u\n", 1666 (u_int)ctlreg->SubsystemRevisionId); 1667 printf("\tValidFields=0x%02x\n", (u_int)ctlreg->ValidFields); 1668 printf("\tManufacturingLocation=%u\n", 1669 (u_int)ctlreg->ManufacturingLocation); 1670 printf("\tManufacturingDate=%u\n", 1671 (u_int)ctlreg->ManufacturingDate); 1672 printf("\tSerialNumber=%u\n", 1673 (u_int)ctlreg->SerialNumber); 1674 printf("\tCode=0x%04x\n", (u_int)ctlreg->Code); 1675 printf("\tWindows=%u\n", (u_int)ctlreg->Windows); 1676 printf("\tWindowSize=0x%016jx\n", 1677 (uintmax_t)ctlreg->WindowSize); 1678 printf("\tCommandOffset=0x%016jx\n", 1679 (uintmax_t)ctlreg->CommandOffset); 1680 printf("\tCommandSize=0x%016jx\n", 1681 (uintmax_t)ctlreg->CommandSize); 1682 printf("\tStatusOffset=0x%016jx\n", 1683 (uintmax_t)ctlreg->StatusOffset); 1684 printf("\tStatusSize=0x%016jx\n", 1685 (uintmax_t)ctlreg->StatusSize); 1686 1687 #define PRINTFLAG(var, flag) printflag((var), ACPI_NFIT_## flag, #flag) 1688 1689 printf("\tFlags="); 1690 PRINTFLAG(ctlreg->Flags, CONTROL_BUFFERED); 1691 PRINTFLAG_END(); 1692 1693 #undef PRINTFLAG 1694 1695 break; 1696 case ACPI_NFIT_TYPE_DATA_REGION: 1697 datareg = (ACPI_NFIT_DATA_REGION *)nfit; 1698 printf("\tRegionIndex=%u\n", (u_int)datareg->RegionIndex); 1699 printf("\tWindows=%u\n", (u_int)datareg->Windows); 1700 printf("\tOffset=0x%016jx\n", (uintmax_t)datareg->Offset); 1701 printf("\tSize=0x%016jx\n", (uintmax_t)datareg->Size); 1702 printf("\tCapacity=0x%016jx\n", (uintmax_t)datareg->Capacity); 1703 printf("\tStartAddress=0x%016jx\n", 1704 (uintmax_t)datareg->StartAddress); 1705 break; 1706 case ACPI_NFIT_TYPE_FLUSH_ADDRESS: 1707 fladdr = (ACPI_NFIT_FLUSH_ADDRESS *)nfit; 1708 printf("\tDeviceHandle=%u\n", (u_int)fladdr->DeviceHandle); 1709 printf("\tHintCount=%u\n", (u_int)fladdr->HintCount); 1710 /* XXX fladdr->HintAddress[i] output is not supported */ 1711 break; 1712 } 1713 } 1714 1715 static void 1716 acpi_handle_nfit(ACPI_TABLE_HEADER *sdp) 1717 { 1718 ACPI_TABLE_NFIT *nfit; 1719 1720 printf(BEGIN_COMMENT); 1721 acpi_print_sdt(sdp); 1722 nfit = (ACPI_TABLE_NFIT *)sdp; 1723 acpi_walk_nfit(sdp, (nfit + 1), acpi_print_nfit); 1724 printf(END_COMMENT); 1725 } 1726 1727 static void 1728 acpi_print_sdt(ACPI_TABLE_HEADER *sdp) 1729 { 1730 printf(" "); 1731 acpi_print_string(sdp->Signature, ACPI_NAMESEG_SIZE); 1732 printf(": Length=%d, Revision=%d, Checksum=%d,\n", 1733 sdp->Length, sdp->Revision, sdp->Checksum); 1734 printf("\tOEMID="); 1735 acpi_print_string(sdp->OemId, ACPI_OEM_ID_SIZE); 1736 printf(", OEM Table ID="); 1737 acpi_print_string(sdp->OemTableId, ACPI_OEM_TABLE_ID_SIZE); 1738 printf(", OEM Revision=0x%x,\n", sdp->OemRevision); 1739 printf("\tCreator ID="); 1740 acpi_print_string(sdp->AslCompilerId, ACPI_NAMESEG_SIZE); 1741 printf(", Creator Revision=0x%x\n", sdp->AslCompilerRevision); 1742 } 1743 1744 static void 1745 acpi_print_rsdt(ACPI_TABLE_HEADER *rsdp) 1746 { 1747 ACPI_TABLE_RSDT *rsdt; 1748 ACPI_TABLE_XSDT *xsdt; 1749 int i, entries; 1750 1751 rsdt = (ACPI_TABLE_RSDT *)rsdp; 1752 xsdt = (ACPI_TABLE_XSDT *)rsdp; 1753 printf(BEGIN_COMMENT); 1754 acpi_print_sdt(rsdp); 1755 entries = (rsdp->Length - sizeof(ACPI_TABLE_HEADER)) / addr_size; 1756 printf("\tEntries={ "); 1757 for (i = 0; i < entries; i++) { 1758 if (i > 0) 1759 printf(", "); 1760 if (addr_size == 4) 1761 printf("0x%08x", le32toh(rsdt->TableOffsetEntry[i])); 1762 else 1763 printf("0x%016jx", 1764 (uintmax_t)le64toh(xsdt->TableOffsetEntry[i])); 1765 } 1766 printf(" }\n"); 1767 printf(END_COMMENT); 1768 } 1769 1770 static const char *acpi_pm_profiles[] = { 1771 "Unspecified", "Desktop", "Mobile", "Workstation", 1772 "Enterprise Server", "SOHO Server", "Appliance PC" 1773 }; 1774 1775 static void 1776 acpi_print_fadt(ACPI_TABLE_HEADER *sdp) 1777 { 1778 ACPI_TABLE_FADT *fadt; 1779 const char *pm; 1780 1781 fadt = (ACPI_TABLE_FADT *)sdp; 1782 printf(BEGIN_COMMENT); 1783 acpi_print_sdt(sdp); 1784 printf(" \tFACS=0x%x, DSDT=0x%x\n", fadt->Facs, 1785 fadt->Dsdt); 1786 printf("\tINT_MODEL=%s\n", fadt->Model ? "APIC" : "PIC"); 1787 if (fadt->PreferredProfile >= sizeof(acpi_pm_profiles) / sizeof(char *)) 1788 pm = "Reserved"; 1789 else 1790 pm = acpi_pm_profiles[fadt->PreferredProfile]; 1791 printf("\tPreferred_PM_Profile=%s (%d)\n", pm, fadt->PreferredProfile); 1792 printf("\tSCI_INT=%d\n", fadt->SciInterrupt); 1793 printf("\tSMI_CMD=0x%x, ", fadt->SmiCommand); 1794 printf("ACPI_ENABLE=0x%x, ", fadt->AcpiEnable); 1795 printf("ACPI_DISABLE=0x%x, ", fadt->AcpiDisable); 1796 printf("S4BIOS_REQ=0x%x\n", fadt->S4BiosRequest); 1797 printf("\tPSTATE_CNT=0x%x\n", fadt->PstateControl); 1798 printf("\tPM1a_EVT_BLK=0x%x-0x%x\n", 1799 fadt->Pm1aEventBlock, 1800 fadt->Pm1aEventBlock + fadt->Pm1EventLength - 1); 1801 if (fadt->Pm1bEventBlock != 0) 1802 printf("\tPM1b_EVT_BLK=0x%x-0x%x\n", 1803 fadt->Pm1bEventBlock, 1804 fadt->Pm1bEventBlock + fadt->Pm1EventLength - 1); 1805 printf("\tPM1a_CNT_BLK=0x%x-0x%x\n", 1806 fadt->Pm1aControlBlock, 1807 fadt->Pm1aControlBlock + fadt->Pm1ControlLength - 1); 1808 if (fadt->Pm1bControlBlock != 0) 1809 printf("\tPM1b_CNT_BLK=0x%x-0x%x\n", 1810 fadt->Pm1bControlBlock, 1811 fadt->Pm1bControlBlock + fadt->Pm1ControlLength - 1); 1812 if (fadt->Pm2ControlBlock != 0) 1813 printf("\tPM2_CNT_BLK=0x%x-0x%x\n", 1814 fadt->Pm2ControlBlock, 1815 fadt->Pm2ControlBlock + fadt->Pm2ControlLength - 1); 1816 printf("\tPM_TMR_BLK=0x%x-0x%x\n", 1817 fadt->PmTimerBlock, 1818 fadt->PmTimerBlock + fadt->PmTimerLength - 1); 1819 if (fadt->Gpe0Block != 0) 1820 printf("\tGPE0_BLK=0x%x-0x%x\n", 1821 fadt->Gpe0Block, 1822 fadt->Gpe0Block + fadt->Gpe0BlockLength - 1); 1823 if (fadt->Gpe1Block != 0) 1824 printf("\tGPE1_BLK=0x%x-0x%x, GPE1_BASE=%d\n", 1825 fadt->Gpe1Block, 1826 fadt->Gpe1Block + fadt->Gpe1BlockLength - 1, 1827 fadt->Gpe1Base); 1828 if (fadt->CstControl != 0) 1829 printf("\tCST_CNT=0x%x\n", fadt->CstControl); 1830 printf("\tP_LVL2_LAT=%d us, P_LVL3_LAT=%d us\n", 1831 fadt->C2Latency, fadt->C3Latency); 1832 printf("\tFLUSH_SIZE=%d, FLUSH_STRIDE=%d\n", 1833 fadt->FlushSize, fadt->FlushStride); 1834 printf("\tDUTY_OFFSET=%d, DUTY_WIDTH=%d\n", 1835 fadt->DutyOffset, fadt->DutyWidth); 1836 printf("\tDAY_ALRM=%d, MON_ALRM=%d, CENTURY=%d\n", 1837 fadt->DayAlarm, fadt->MonthAlarm, fadt->Century); 1838 1839 #define PRINTFLAG(var, flag) printflag((var), ACPI_FADT_## flag, #flag) 1840 1841 printf("\tIAPC_BOOT_ARCH="); 1842 PRINTFLAG(fadt->BootFlags, LEGACY_DEVICES); 1843 PRINTFLAG(fadt->BootFlags, 8042); 1844 PRINTFLAG(fadt->BootFlags, NO_VGA); 1845 PRINTFLAG(fadt->BootFlags, NO_MSI); 1846 PRINTFLAG(fadt->BootFlags, NO_ASPM); 1847 PRINTFLAG(fadt->BootFlags, NO_CMOS_RTC); 1848 PRINTFLAG_END(); 1849 1850 printf("\tFlags="); 1851 PRINTFLAG(fadt->Flags, WBINVD); 1852 PRINTFLAG(fadt->Flags, WBINVD_FLUSH); 1853 PRINTFLAG(fadt->Flags, C1_SUPPORTED); 1854 PRINTFLAG(fadt->Flags, C2_MP_SUPPORTED); 1855 PRINTFLAG(fadt->Flags, POWER_BUTTON); 1856 PRINTFLAG(fadt->Flags, SLEEP_BUTTON); 1857 PRINTFLAG(fadt->Flags, FIXED_RTC); 1858 PRINTFLAG(fadt->Flags, S4_RTC_WAKE); 1859 PRINTFLAG(fadt->Flags, 32BIT_TIMER); 1860 PRINTFLAG(fadt->Flags, DOCKING_SUPPORTED); 1861 PRINTFLAG(fadt->Flags, RESET_REGISTER); 1862 PRINTFLAG(fadt->Flags, SEALED_CASE); 1863 PRINTFLAG(fadt->Flags, HEADLESS); 1864 PRINTFLAG(fadt->Flags, SLEEP_TYPE); 1865 PRINTFLAG(fadt->Flags, PCI_EXPRESS_WAKE); 1866 PRINTFLAG(fadt->Flags, PLATFORM_CLOCK); 1867 PRINTFLAG(fadt->Flags, S4_RTC_VALID); 1868 PRINTFLAG(fadt->Flags, REMOTE_POWER_ON); 1869 PRINTFLAG(fadt->Flags, APIC_CLUSTER); 1870 PRINTFLAG(fadt->Flags, APIC_PHYSICAL); 1871 PRINTFLAG(fadt->Flags, HW_REDUCED); 1872 PRINTFLAG(fadt->Flags, LOW_POWER_S0); 1873 PRINTFLAG_END(); 1874 1875 #undef PRINTFLAG 1876 1877 if (fadt->Flags & ACPI_FADT_RESET_REGISTER) { 1878 printf("\tRESET_REG="); 1879 acpi_print_gas(&fadt->ResetRegister); 1880 printf(", RESET_VALUE=%#x\n", fadt->ResetValue); 1881 } 1882 if (acpi_get_fadt_revision(fadt) > 1) { 1883 printf("\tX_FACS=0x%016jx, ", (uintmax_t)fadt->XFacs); 1884 printf("X_DSDT=0x%016jx\n", (uintmax_t)fadt->XDsdt); 1885 printf("\tX_PM1a_EVT_BLK="); 1886 acpi_print_gas(&fadt->XPm1aEventBlock); 1887 if (fadt->XPm1bEventBlock.Address != 0) { 1888 printf("\n\tX_PM1b_EVT_BLK="); 1889 acpi_print_gas(&fadt->XPm1bEventBlock); 1890 } 1891 printf("\n\tX_PM1a_CNT_BLK="); 1892 acpi_print_gas(&fadt->XPm1aControlBlock); 1893 if (fadt->XPm1bControlBlock.Address != 0) { 1894 printf("\n\tX_PM1b_CNT_BLK="); 1895 acpi_print_gas(&fadt->XPm1bControlBlock); 1896 } 1897 if (fadt->XPm2ControlBlock.Address != 0) { 1898 printf("\n\tX_PM2_CNT_BLK="); 1899 acpi_print_gas(&fadt->XPm2ControlBlock); 1900 } 1901 printf("\n\tX_PM_TMR_BLK="); 1902 acpi_print_gas(&fadt->XPmTimerBlock); 1903 if (fadt->XGpe0Block.Address != 0) { 1904 printf("\n\tX_GPE0_BLK="); 1905 acpi_print_gas(&fadt->XGpe0Block); 1906 } 1907 if (fadt->XGpe1Block.Address != 0) { 1908 printf("\n\tX_GPE1_BLK="); 1909 acpi_print_gas(&fadt->XGpe1Block); 1910 } 1911 printf("\n"); 1912 } 1913 1914 printf(END_COMMENT); 1915 } 1916 1917 static void 1918 acpi_print_facs(ACPI_TABLE_FACS *facs) 1919 { 1920 printf(BEGIN_COMMENT); 1921 printf(" FACS:\tLength=%u, ", facs->Length); 1922 printf("HwSig=0x%08x, ", facs->HardwareSignature); 1923 printf("Firm_Wake_Vec=0x%08x\n", facs->FirmwareWakingVector); 1924 1925 printf("\tGlobal_Lock="); 1926 if (facs->GlobalLock != 0) { 1927 if (facs->GlobalLock & ACPI_GLOCK_PENDING) 1928 printf("PENDING,"); 1929 if (facs->GlobalLock & ACPI_GLOCK_OWNED) 1930 printf("OWNED"); 1931 } 1932 printf("\n"); 1933 1934 printf("\tFlags="); 1935 if (facs->Flags & ACPI_FACS_S4_BIOS_PRESENT) 1936 printf("S4BIOS"); 1937 printf("\n"); 1938 1939 if (facs->XFirmwareWakingVector != 0) 1940 printf("\tX_Firm_Wake_Vec=%016jx\n", 1941 (uintmax_t)facs->XFirmwareWakingVector); 1942 printf("\tVersion=%u\n", facs->Version); 1943 1944 printf(END_COMMENT); 1945 } 1946 1947 static void 1948 acpi_print_dsdt(ACPI_TABLE_HEADER *dsdp) 1949 { 1950 printf(BEGIN_COMMENT); 1951 acpi_print_sdt(dsdp); 1952 printf(END_COMMENT); 1953 } 1954 1955 int 1956 acpi_checksum(void *p, size_t length) 1957 { 1958 uint8_t *bp; 1959 uint8_t sum; 1960 1961 bp = p; 1962 sum = 0; 1963 while (length--) 1964 sum += *bp++; 1965 1966 return (sum); 1967 } 1968 1969 static ACPI_TABLE_HEADER * 1970 acpi_map_sdt(vm_offset_t pa) 1971 { 1972 ACPI_TABLE_HEADER *sp; 1973 1974 sp = acpi_map_physical(pa, sizeof(ACPI_TABLE_HEADER)); 1975 sp = acpi_map_physical(pa, sp->Length); 1976 return (sp); 1977 } 1978 1979 static void 1980 acpi_print_rsd_ptr(ACPI_TABLE_RSDP *rp) 1981 { 1982 printf(BEGIN_COMMENT); 1983 printf(" RSD PTR: OEM="); 1984 acpi_print_string(rp->OemId, ACPI_OEM_ID_SIZE); 1985 printf(", ACPI_Rev=%s (%d)\n", rp->Revision < 2 ? "1.0x" : "2.0x", 1986 rp->Revision); 1987 if (rp->Revision < 2) { 1988 printf("\tRSDT=0x%08x, cksum=%u\n", rp->RsdtPhysicalAddress, 1989 rp->Checksum); 1990 } else { 1991 printf("\tXSDT=0x%016jx, length=%u, cksum=%u\n", 1992 (uintmax_t)rp->XsdtPhysicalAddress, rp->Length, 1993 rp->ExtendedChecksum); 1994 } 1995 printf(END_COMMENT); 1996 } 1997 1998 static void 1999 acpi_handle_rsdt(ACPI_TABLE_HEADER *rsdp) 2000 { 2001 ACPI_TABLE_HEADER *sdp; 2002 ACPI_TABLE_RSDT *rsdt; 2003 ACPI_TABLE_XSDT *xsdt; 2004 vm_offset_t addr; 2005 int entries, i; 2006 2007 acpi_print_rsdt(rsdp); 2008 rsdt = (ACPI_TABLE_RSDT *)rsdp; 2009 xsdt = (ACPI_TABLE_XSDT *)rsdp; 2010 entries = (rsdp->Length - sizeof(ACPI_TABLE_HEADER)) / addr_size; 2011 for (i = 0; i < entries; i++) { 2012 if (addr_size == 4) 2013 addr = le32toh(rsdt->TableOffsetEntry[i]); 2014 else 2015 addr = le64toh(xsdt->TableOffsetEntry[i]); 2016 if (addr == 0) 2017 continue; 2018 sdp = (ACPI_TABLE_HEADER *)acpi_map_sdt(addr); 2019 if (acpi_checksum(sdp, sdp->Length)) { 2020 warnx("RSDT entry %d (sig %.4s) is corrupt", i, 2021 sdp->Signature); 2022 continue; 2023 } 2024 if (!memcmp(sdp->Signature, ACPI_SIG_BERT, 4)) 2025 acpi_handle_bert(sdp); 2026 else if (!memcmp(sdp->Signature, ACPI_SIG_EINJ, 4)) 2027 acpi_handle_einj(sdp); 2028 else if (!memcmp(sdp->Signature, ACPI_SIG_ERST, 4)) 2029 acpi_handle_erst(sdp); 2030 else if (!memcmp(sdp->Signature, ACPI_SIG_FADT, 4)) 2031 acpi_handle_fadt(sdp); 2032 else if (!memcmp(sdp->Signature, ACPI_SIG_MADT, 4)) 2033 acpi_handle_madt(sdp); 2034 else if (!memcmp(sdp->Signature, ACPI_SIG_HEST, 4)) 2035 acpi_handle_hest(sdp); 2036 else if (!memcmp(sdp->Signature, ACPI_SIG_HPET, 4)) 2037 acpi_handle_hpet(sdp); 2038 else if (!memcmp(sdp->Signature, ACPI_SIG_ECDT, 4)) 2039 acpi_handle_ecdt(sdp); 2040 else if (!memcmp(sdp->Signature, ACPI_SIG_MCFG, 4)) 2041 acpi_handle_mcfg(sdp); 2042 else if (!memcmp(sdp->Signature, ACPI_SIG_SLIT, 4)) 2043 acpi_handle_slit(sdp); 2044 else if (!memcmp(sdp->Signature, ACPI_SIG_SRAT, 4)) 2045 acpi_handle_srat(sdp); 2046 else if (!memcmp(sdp->Signature, ACPI_SIG_TCPA, 4)) 2047 acpi_handle_tcpa(sdp); 2048 else if (!memcmp(sdp->Signature, ACPI_SIG_DMAR, 4)) 2049 acpi_handle_dmar(sdp); 2050 else if (!memcmp(sdp->Signature, ACPI_SIG_NFIT, 4)) 2051 acpi_handle_nfit(sdp); 2052 else if (!memcmp(sdp->Signature, ACPI_SIG_WDDT, 4)) 2053 acpi_handle_wddt(sdp); 2054 else if (!memcmp(sdp->Signature, ACPI_SIG_LPIT, 4)) 2055 acpi_handle_lpit(sdp); 2056 else if (!memcmp(sdp->Signature, ACPI_SIG_TPM2, 4)) 2057 acpi_handle_tpm2(sdp); 2058 else { 2059 printf(BEGIN_COMMENT); 2060 acpi_print_sdt(sdp); 2061 printf(END_COMMENT); 2062 } 2063 } 2064 } 2065 2066 ACPI_TABLE_HEADER * 2067 sdt_load_devmem(void) 2068 { 2069 ACPI_TABLE_RSDP *rp; 2070 ACPI_TABLE_HEADER *rsdp; 2071 2072 rp = acpi_find_rsd_ptr(); 2073 if (!rp) 2074 errx(1, "Can't find ACPI information"); 2075 2076 if (tflag) 2077 acpi_print_rsd_ptr(rp); 2078 if (rp->Revision < 2) { 2079 rsdp = (ACPI_TABLE_HEADER *)acpi_map_sdt(rp->RsdtPhysicalAddress); 2080 if (memcmp(rsdp->Signature, "RSDT", 4) != 0 || 2081 acpi_checksum(rsdp, rsdp->Length) != 0) 2082 errx(1, "RSDT is corrupted"); 2083 addr_size = sizeof(uint32_t); 2084 } else { 2085 rsdp = (ACPI_TABLE_HEADER *)acpi_map_sdt(rp->XsdtPhysicalAddress); 2086 if (memcmp(rsdp->Signature, "XSDT", 4) != 0 || 2087 acpi_checksum(rsdp, rsdp->Length) != 0) 2088 errx(1, "XSDT is corrupted"); 2089 addr_size = sizeof(uint64_t); 2090 } 2091 return (rsdp); 2092 } 2093 2094 /* Write the DSDT to a file, concatenating any SSDTs (if present). */ 2095 static int 2096 write_dsdt(int fd, ACPI_TABLE_HEADER *rsdt, ACPI_TABLE_HEADER *dsdt) 2097 { 2098 ACPI_TABLE_HEADER sdt; 2099 ACPI_TABLE_HEADER *ssdt; 2100 uint8_t sum; 2101 2102 /* Create a new checksum to account for the DSDT and any SSDTs. */ 2103 sdt = *dsdt; 2104 if (rsdt != NULL) { 2105 sdt.Checksum = 0; 2106 sum = acpi_checksum(dsdt + 1, dsdt->Length - 2107 sizeof(ACPI_TABLE_HEADER)); 2108 ssdt = sdt_from_rsdt(rsdt, ACPI_SIG_SSDT, NULL); 2109 while (ssdt != NULL) { 2110 sdt.Length += ssdt->Length - sizeof(ACPI_TABLE_HEADER); 2111 sum += acpi_checksum(ssdt + 1, 2112 ssdt->Length - sizeof(ACPI_TABLE_HEADER)); 2113 ssdt = sdt_from_rsdt(rsdt, ACPI_SIG_SSDT, ssdt); 2114 } 2115 sum += acpi_checksum(&sdt, sizeof(ACPI_TABLE_HEADER)); 2116 sdt.Checksum -= sum; 2117 } 2118 2119 /* Write out the DSDT header and body. */ 2120 write(fd, &sdt, sizeof(ACPI_TABLE_HEADER)); 2121 write(fd, dsdt + 1, dsdt->Length - sizeof(ACPI_TABLE_HEADER)); 2122 2123 /* Write out any SSDTs (if present.) */ 2124 if (rsdt != NULL) { 2125 ssdt = sdt_from_rsdt(rsdt, "SSDT", NULL); 2126 while (ssdt != NULL) { 2127 write(fd, ssdt + 1, ssdt->Length - 2128 sizeof(ACPI_TABLE_HEADER)); 2129 ssdt = sdt_from_rsdt(rsdt, "SSDT", ssdt); 2130 } 2131 } 2132 return (0); 2133 } 2134 2135 void 2136 dsdt_save_file(char *outfile, ACPI_TABLE_HEADER *rsdt, ACPI_TABLE_HEADER *dsdp) 2137 { 2138 int fd; 2139 mode_t mode; 2140 2141 assert(outfile != NULL); 2142 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; 2143 fd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, mode); 2144 if (fd == -1) { 2145 perror("dsdt_save_file"); 2146 return; 2147 } 2148 write_dsdt(fd, rsdt, dsdp); 2149 close(fd); 2150 } 2151 2152 void 2153 aml_disassemble(ACPI_TABLE_HEADER *rsdt, ACPI_TABLE_HEADER *dsdp) 2154 { 2155 char buf[PATH_MAX], tmpstr[PATH_MAX], wrkdir[PATH_MAX]; 2156 const char *iname = "/acpdump.din"; 2157 const char *oname = "/acpdump.dsl"; 2158 const char *tmpdir; 2159 FILE *fp; 2160 size_t len; 2161 int fd, status; 2162 pid_t pid; 2163 2164 tmpdir = getenv("TMPDIR"); 2165 if (tmpdir == NULL) 2166 tmpdir = _PATH_TMP; 2167 if (realpath(tmpdir, buf) == NULL) { 2168 perror("realpath tmp dir"); 2169 return; 2170 } 2171 len = sizeof(wrkdir) - strlen(iname); 2172 if ((size_t)snprintf(wrkdir, len, "%s/acpidump.XXXXXX", buf) > len-1 ) { 2173 fprintf(stderr, "$TMPDIR too long\n"); 2174 return; 2175 } 2176 if (mkdtemp(wrkdir) == NULL) { 2177 perror("mkdtemp tmp working dir"); 2178 return; 2179 } 2180 len = (size_t)snprintf(tmpstr, sizeof(tmpstr), "%s%s", wrkdir, iname); 2181 assert(len <= sizeof(tmpstr) - 1); 2182 fd = open(tmpstr, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); 2183 if (fd < 0) { 2184 perror("iasl tmp file"); 2185 return; 2186 } 2187 write_dsdt(fd, rsdt, dsdp); 2188 close(fd); 2189 2190 /* Run iasl -d on the temp file */ 2191 if ((pid = fork()) == 0) { 2192 close(STDOUT_FILENO); 2193 if (vflag == 0) 2194 close(STDERR_FILENO); 2195 execl("/usr/sbin/iasl", "iasl", "-d", tmpstr, NULL); 2196 err(1, "exec"); 2197 } 2198 if (pid > 0) 2199 wait(&status); 2200 if (unlink(tmpstr) < 0) { 2201 perror("unlink"); 2202 goto out; 2203 } 2204 if (pid < 0) { 2205 perror("fork"); 2206 goto out; 2207 } 2208 if (status != 0) { 2209 fprintf(stderr, "iast exit status = %d\n", status); 2210 } 2211 2212 /* Dump iasl's output to stdout */ 2213 len = (size_t)snprintf(tmpstr, sizeof(tmpstr), "%s%s", wrkdir, oname); 2214 assert(len <= sizeof(tmpstr) - 1); 2215 fp = fopen(tmpstr, "r"); 2216 if (unlink(tmpstr) < 0) { 2217 perror("unlink"); 2218 goto out; 2219 } 2220 if (fp == NULL) { 2221 perror("iasl tmp file (read)"); 2222 goto out; 2223 } 2224 while ((len = fread(buf, 1, sizeof(buf), fp)) > 0) 2225 fwrite(buf, 1, len, stdout); 2226 fclose(fp); 2227 2228 out: 2229 if (rmdir(wrkdir) < 0) 2230 perror("rmdir"); 2231 } 2232 2233 void 2234 sdt_print_all(ACPI_TABLE_HEADER *rsdp) 2235 { 2236 acpi_handle_rsdt(rsdp); 2237 } 2238 2239 /* Fetch a table matching the given signature via the RSDT. */ 2240 ACPI_TABLE_HEADER * 2241 sdt_from_rsdt(ACPI_TABLE_HEADER *rsdp, const char *sig, ACPI_TABLE_HEADER *last) 2242 { 2243 ACPI_TABLE_HEADER *sdt; 2244 ACPI_TABLE_RSDT *rsdt; 2245 ACPI_TABLE_XSDT *xsdt; 2246 vm_offset_t addr; 2247 int entries, i; 2248 2249 rsdt = (ACPI_TABLE_RSDT *)rsdp; 2250 xsdt = (ACPI_TABLE_XSDT *)rsdp; 2251 entries = (rsdp->Length - sizeof(ACPI_TABLE_HEADER)) / addr_size; 2252 for (i = 0; i < entries; i++) { 2253 if (addr_size == 4) 2254 addr = le32toh(rsdt->TableOffsetEntry[i]); 2255 else 2256 addr = le64toh(xsdt->TableOffsetEntry[i]); 2257 if (addr == 0) 2258 continue; 2259 sdt = (ACPI_TABLE_HEADER *)acpi_map_sdt(addr); 2260 if (last != NULL) { 2261 if (sdt == last) 2262 last = NULL; 2263 continue; 2264 } 2265 if (memcmp(sdt->Signature, sig, strlen(sig))) 2266 continue; 2267 if (acpi_checksum(sdt, sdt->Length)) 2268 errx(1, "RSDT entry %d is corrupt", i); 2269 return (sdt); 2270 } 2271 2272 return (NULL); 2273 } 2274 2275 ACPI_TABLE_HEADER * 2276 dsdt_from_fadt(ACPI_TABLE_FADT *fadt) 2277 { 2278 ACPI_TABLE_HEADER *sdt; 2279 2280 /* Use the DSDT address if it is version 1, otherwise use XDSDT. */ 2281 if (acpi_get_fadt_revision(fadt) == 1) 2282 sdt = (ACPI_TABLE_HEADER *)acpi_map_sdt(fadt->Dsdt); 2283 else 2284 sdt = (ACPI_TABLE_HEADER *)acpi_map_sdt(fadt->XDsdt); 2285 if (acpi_checksum(sdt, sdt->Length)) 2286 errx(1, "DSDT is corrupt\n"); 2287 return (sdt); 2288 } 2289