2 * Copyright (c) 1998 Doug Rabson
3 * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * $FreeBSD: src/usr.sbin/acpi/acpidump/acpi.c,v 1.25 2004/06/30 03:23:51 njl Exp $
28 * $DragonFly: src/usr.sbin/acpi/acpidump/acpi.c,v 1.2 2004/08/23 16:03:44 joerg Exp $
31 #include <sys/param.h>
32 #include <sys/endian.h>
44 #define BEGIN_COMMENT "/*\n"
45 #define END_COMMENT " */\n"
47 static void acpi_print_string(char *s, size_t length);
48 static void acpi_print_gas(struct ACPIgas *gas);
49 static int acpi_get_fadt_revision(struct FADTbody *fadt);
50 static void acpi_handle_fadt(struct ACPIsdt *fadt);
51 static void acpi_print_cpu(u_char cpu_id);
52 static void acpi_print_local_apic(u_char cpu_id, u_char apic_id,
54 static void acpi_print_io_apic(u_char apic_id, u_int32_t int_base,
56 static void acpi_print_mps_flags(u_int16_t flags);
57 static void acpi_print_intr(u_int32_t intr, u_int16_t mps_flags);
58 static void acpi_print_apic(struct MADT_APIC *mp);
59 static void acpi_handle_apic(struct ACPIsdt *sdp);
60 static void acpi_handle_hpet(struct ACPIsdt *sdp);
61 static void acpi_print_sdt(struct ACPIsdt *sdp);
62 static void acpi_print_fadt(struct ACPIsdt *sdp);
63 static void acpi_print_facs(struct FACSbody *facs);
64 static void acpi_print_dsdt(struct ACPIsdt *dsdp);
65 static struct ACPIsdt *acpi_map_sdt(vm_offset_t pa);
66 static void acpi_print_rsd_ptr(struct ACPIrsdp *rp);
67 static void acpi_handle_rsdt(struct ACPIsdt *rsdp);
69 /* Size of an address. 32-bit for ACPI 1.0, 64-bit for ACPI 2.0 and up. */
73 acpi_print_string(char *s, size_t length)
77 /* Trim trailing spaces and NULLs */
78 while (length > 0 && (s[length - 1] == ' ' || s[length - 1] == '\0'))
88 acpi_print_gas(struct ACPIgas *gas)
90 switch(gas->address_space_id) {
92 printf("0x%08lx:%u[%u] (Memory)", (u_long)gas->address,
93 gas->bit_offset, gas->bit_width);
96 printf("0x%02lx:%u[%u] (IO)", (u_long)gas->address,
97 gas->bit_offset, gas->bit_width);
100 printf("%x:%x+0x%x (PCI)", (uint16_t)(gas->address >> 32),
101 (uint16_t)((gas->address >> 16) & 0xffff),
102 (uint16_t)gas->address);
104 /* XXX How to handle these below? */
105 case ACPI_GAS_EMBEDDED:
106 printf("0x%x:%u[%u] (EC)", (uint16_t)gas->address,
107 gas->bit_offset, gas->bit_width);
110 printf("0x%x:%u[%u] (SMBus)", (uint16_t)gas->address,
111 gas->bit_offset, gas->bit_width);
115 printf("0x%08lx (?)", (u_long)gas->address);
120 /* The FADT revision indicates whether we use the DSDT or X_DSDT addresses. */
122 acpi_get_fadt_revision(struct FADTbody *fadt)
126 /* Set the FADT revision separately from the RSDP version. */
127 if (addr_size == 8) {
131 * A few systems (e.g., IBM T23) have an RSDP that claims
132 * revision 2 but the 64 bit addresses are invalid. If
133 * revision 2 and the 32 bit address is non-zero but the
134 * 32 and 64 bit versions don't match, prefer the 32 bit
135 * version for all subsequent tables.
137 if (fadt->facs_ptr != 0 &&
138 (fadt->x_facs_ptr & 0xffffffff) != fadt->facs_ptr)
142 return (fadt_revision);
146 acpi_handle_fadt(struct ACPIsdt *sdp)
148 struct ACPIsdt *dsdp;
149 struct FACSbody *facs;
150 struct FADTbody *fadt;
153 fadt = (struct FADTbody *)sdp->body;
154 acpi_print_fadt(sdp);
156 fadt_revision = acpi_get_fadt_revision(fadt);
157 if (fadt_revision == 1)
158 facs = (struct FACSbody *)acpi_map_sdt(fadt->facs_ptr);
160 facs = (struct FACSbody *)acpi_map_sdt(fadt->x_facs_ptr);
161 if (memcmp(facs->signature, "FACS", 4) != 0 || facs->len < 64)
162 errx(1, "FACS is corrupt");
163 acpi_print_facs(facs);
165 if (fadt_revision == 1)
166 dsdp = (struct ACPIsdt *)acpi_map_sdt(fadt->dsdt_ptr);
168 dsdp = (struct ACPIsdt *)acpi_map_sdt(fadt->x_dsdt_ptr);
169 if (acpi_checksum(dsdp, dsdp->len))
170 errx(1, "DSDT is corrupt");
171 acpi_print_dsdt(dsdp);
175 acpi_print_cpu(u_char cpu_id)
178 printf("\tACPI CPU=");
182 printf("%d\n", (u_int)cpu_id);
186 acpi_print_local_apic(u_char cpu_id, u_char apic_id, u_int32_t flags)
188 acpi_print_cpu(cpu_id);
190 if (flags & ACPI_MADT_APIC_LOCAL_FLAG_ENABLED)
195 printf("\tAPIC ID=%d\n", (u_int)apic_id);
199 acpi_print_io_apic(u_char apic_id, u_int32_t int_base, u_int64_t apic_addr)
201 printf("\tAPIC ID=%d\n", (u_int)apic_id);
202 printf("\tINT BASE=%d\n", int_base);
203 printf("\tADDR=0x%016jx\n", apic_addr);
207 acpi_print_mps_flags(u_int16_t flags)
210 printf("\tFlags={Polarity=");
211 switch (flags & MPS_INT_FLAG_POLARITY_MASK) {
212 case MPS_INT_FLAG_POLARITY_CONFORM:
213 printf("conforming");
215 case MPS_INT_FLAG_POLARITY_HIGH:
218 case MPS_INT_FLAG_POLARITY_LOW:
222 printf("0x%x", flags & MPS_INT_FLAG_POLARITY_MASK);
225 printf(", Trigger=");
226 switch (flags & MPS_INT_FLAG_TRIGGER_MASK) {
227 case MPS_INT_FLAG_TRIGGER_CONFORM:
228 printf("conforming");
230 case MPS_INT_FLAG_TRIGGER_EDGE:
233 case MPS_INT_FLAG_TRIGGER_LEVEL:
237 printf("0x%x", (flags & MPS_INT_FLAG_TRIGGER_MASK) >> 2);
243 acpi_print_intr(u_int32_t intr, u_int16_t mps_flags)
246 printf("\tINTR=%d\n", (u_int)intr);
247 acpi_print_mps_flags(mps_flags);
250 const char *apic_types[] = { "Local APIC", "IO APIC", "INT Override", "NMI",
251 "Local NMI", "Local APIC Override", "IO SAPIC",
252 "Local SAPIC", "Platform Interrupt" };
253 const char *platform_int_types[] = { "PMI", "INIT",
254 "Corrected Platform Error" };
257 acpi_print_apic(struct MADT_APIC *mp)
260 printf("\tType=%s\n", apic_types[mp->type]);
262 case ACPI_MADT_APIC_TYPE_LOCAL_APIC:
263 acpi_print_local_apic(mp->body.local_apic.cpu_id,
264 mp->body.local_apic.apic_id, mp->body.local_apic.flags);
266 case ACPI_MADT_APIC_TYPE_IO_APIC:
267 acpi_print_io_apic(mp->body.io_apic.apic_id,
268 mp->body.io_apic.int_base,
269 mp->body.io_apic.apic_addr);
271 case ACPI_MADT_APIC_TYPE_INT_OVERRIDE:
272 printf("\tBUS=%d\n", (u_int)mp->body.int_override.bus);
273 printf("\tIRQ=%d\n", (u_int)mp->body.int_override.source);
274 acpi_print_intr(mp->body.int_override.intr,
275 mp->body.int_override.mps_flags);
277 case ACPI_MADT_APIC_TYPE_NMI:
278 acpi_print_intr(mp->body.nmi.intr, mp->body.nmi.mps_flags);
280 case ACPI_MADT_APIC_TYPE_LOCAL_NMI:
281 acpi_print_cpu(mp->body.local_nmi.cpu_id);
282 printf("\tLINT Pin=%d\n", mp->body.local_nmi.lintpin);
283 acpi_print_mps_flags(mp->body.local_nmi.mps_flags);
285 case ACPI_MADT_APIC_TYPE_LOCAL_OVERRIDE:
286 printf("\tLocal APIC ADDR=0x%016jx\n",
287 mp->body.local_apic_override.apic_addr);
289 case ACPI_MADT_APIC_TYPE_IO_SAPIC:
290 acpi_print_io_apic(mp->body.io_sapic.apic_id,
291 mp->body.io_sapic.int_base,
292 mp->body.io_sapic.apic_addr);
294 case ACPI_MADT_APIC_TYPE_LOCAL_SAPIC:
295 acpi_print_local_apic(mp->body.local_sapic.cpu_id,
296 mp->body.local_sapic.apic_id, mp->body.local_sapic.flags);
297 printf("\tAPIC EID=%d\n", (u_int)mp->body.local_sapic.apic_eid);
299 case ACPI_MADT_APIC_TYPE_INT_SRC:
300 printf("\tType=%s\n",
301 platform_int_types[mp->body.int_src.type]);
302 printf("\tCPU ID=%d\n", (u_int)mp->body.int_src.cpu_id);
303 printf("\tCPU EID=%d\n", (u_int)mp->body.int_src.cpu_id);
304 printf("\tSAPIC Vector=%d\n",
305 (u_int)mp->body.int_src.sapic_vector);
306 acpi_print_intr(mp->body.int_src.intr,
307 mp->body.int_src.mps_flags);
310 printf("\tUnknown type %d\n", (u_int)mp->type);
316 acpi_handle_apic(struct ACPIsdt *sdp)
318 struct MADTbody *madtp;
319 struct MADT_APIC *madt_apicp;
321 printf(BEGIN_COMMENT);
323 madtp = (struct MADTbody *) sdp->body;
324 printf("\tLocal APIC ADDR=0x%08x\n", madtp->lapic_addr);
326 if (madtp->flags & ACPI_APIC_FLAG_PCAT_COMPAT)
329 madt_apicp = (struct MADT_APIC *)madtp->body;
330 while (((uintptr_t)madt_apicp) - ((uintptr_t)sdp) < sdp->len) {
332 acpi_print_apic(madt_apicp);
333 madt_apicp = (struct MADT_APIC *) ((char *)madt_apicp +
340 acpi_handle_hpet(struct ACPIsdt *sdp)
342 struct HPETbody *hpetp;
344 printf(BEGIN_COMMENT);
346 hpetp = (struct HPETbody *) sdp->body;
347 printf("\tHPET Number=%d\n", hpetp->hpet_number);
348 printf("\tADDR=0x%08x\n", hpetp->base_addr);
349 printf("\tHW Rev=0x%x\n", hpetp->block_hwrev);
350 printf("\tComparitors=%d\n", hpetp->block_comparitors);
351 printf("\tCounter Size=%d\n", hpetp->block_counter_size);
352 printf("\tLegacy IRQ routing capable={");
353 if (hpetp->block_legacy_capable)
357 printf("\tPCI Vendor ID=0x%04x\n", hpetp->block_pcivendor);
358 printf("\tMinimal Tick=%d\n", hpetp->clock_tick);
363 acpi_handle_ecdt(struct ACPIsdt *sdp)
365 struct ECDTbody *ecdt;
367 printf(BEGIN_COMMENT);
369 ecdt = (struct ECDTbody *) sdp->body;
370 printf("\tEC_CONTROL=");
371 acpi_print_gas(&ecdt->ec_control);
372 printf("\n\tEC_DATA=");
373 acpi_print_gas(&ecdt->ec_data);
374 printf("\n\tUID=%#x, ", ecdt->uid);
375 printf("GPE_BIT=%#x\n", ecdt->gpe_bit);
376 printf("\tEC_ID=%s\n", ecdt->ec_id);
381 acpi_print_sdt(struct ACPIsdt *sdp)
384 acpi_print_string(sdp->signature, 4);
385 printf(": Length=%d, Revision=%d, Checksum=%d,\n",
386 sdp->len, sdp->rev, sdp->check);
388 acpi_print_string(sdp->oemid, 6);
389 printf(", OEM Table ID=");
390 acpi_print_string(sdp->oemtblid, 8);
391 printf(", OEM Revision=0x%x,\n", sdp->oemrev);
392 printf("\tCreator ID=");
393 acpi_print_string(sdp->creator, 4);
394 printf(", Creator Revision=0x%x\n", sdp->crerev);
398 acpi_print_rsdt(struct ACPIsdt *rsdp)
403 printf(BEGIN_COMMENT);
404 acpi_print_sdt(rsdp);
405 entries = (rsdp->len - SIZEOF_SDT_HDR) / addr_size;
406 printf("\tEntries={ ");
407 for (i = 0; i < entries; i++) {
412 addr = le32dec((char*)rsdp->body + i * addr_size);
415 addr = le64dec((char*)rsdp->body + i * addr_size);
421 printf("0x%08lx", addr);
427 static const char *acpi_pm_profiles[] = {
428 "Unspecified", "Desktop", "Mobile", "Workstation",
429 "Enterprise Server", "SOHO Server", "Appliance PC"
433 acpi_print_fadt(struct ACPIsdt *sdp)
435 struct FADTbody *fadt;
439 fadt = (struct FADTbody *)sdp->body;
440 printf(BEGIN_COMMENT);
442 printf(" \tFACS=0x%x, DSDT=0x%x\n", fadt->facs_ptr,
444 printf("\tINT_MODEL=%s\n", fadt->int_model ? "APIC" : "PIC");
445 if (fadt->pm_profile >= sizeof(acpi_pm_profiles) / sizeof(char *))
448 pm = acpi_pm_profiles[fadt->pm_profile];
449 printf("\tPreferred_PM_Profile=%s (%d)\n", pm, fadt->pm_profile);
450 printf("\tSCI_INT=%d\n", fadt->sci_int);
451 printf("\tSMI_CMD=0x%x, ", fadt->smi_cmd);
452 printf("ACPI_ENABLE=0x%x, ", fadt->acpi_enable);
453 printf("ACPI_DISABLE=0x%x, ", fadt->acpi_disable);
454 printf("S4BIOS_REQ=0x%x\n", fadt->s4biosreq);
455 printf("\tPSTATE_CNT=0x%x\n", fadt->pstate_cnt);
456 printf("\tPM1a_EVT_BLK=0x%x-0x%x\n",
458 fadt->pm1a_evt_blk + fadt->pm1_evt_len - 1);
459 if (fadt->pm1b_evt_blk != 0)
460 printf("\tPM1b_EVT_BLK=0x%x-0x%x\n",
462 fadt->pm1b_evt_blk + fadt->pm1_evt_len - 1);
463 printf("\tPM1a_CNT_BLK=0x%x-0x%x\n",
465 fadt->pm1a_cnt_blk + fadt->pm1_cnt_len - 1);
466 if (fadt->pm1b_cnt_blk != 0)
467 printf("\tPM1b_CNT_BLK=0x%x-0x%x\n",
469 fadt->pm1b_cnt_blk + fadt->pm1_cnt_len - 1);
470 if (fadt->pm2_cnt_blk != 0)
471 printf("\tPM2_CNT_BLK=0x%x-0x%x\n",
473 fadt->pm2_cnt_blk + fadt->pm2_cnt_len - 1);
474 printf("\tPM_TMR_BLK=0x%x-0x%x\n",
476 fadt->pm_tmr_blk + fadt->pm_tmr_len - 1);
477 if (fadt->gpe0_blk != 0)
478 printf("\tGPE0_BLK=0x%x-0x%x\n",
480 fadt->gpe0_blk + fadt->gpe0_len - 1);
481 if (fadt->gpe1_blk != 0)
482 printf("\tGPE1_BLK=0x%x-0x%x, GPE1_BASE=%d\n",
484 fadt->gpe1_blk + fadt->gpe1_len - 1,
486 if (fadt->cst_cnt != 0)
487 printf("\tCST_CNT=0x%x\n", fadt->cst_cnt);
488 printf("\tP_LVL2_LAT=%d us, P_LVL3_LAT=%d us\n",
489 fadt->p_lvl2_lat, fadt->p_lvl3_lat);
490 printf("\tFLUSH_SIZE=%d, FLUSH_STRIDE=%d\n",
491 fadt->flush_size, fadt->flush_stride);
492 printf("\tDUTY_OFFSET=%d, DUTY_WIDTH=%d\n",
493 fadt->duty_off, fadt->duty_width);
494 printf("\tDAY_ALRM=%d, MON_ALRM=%d, CENTURY=%d\n",
495 fadt->day_alrm, fadt->mon_alrm, fadt->century);
497 #define PRINTFLAG(var, flag) do { \
498 if ((var) & FADT_FLAG_## flag) { \
499 printf("%c%s", sep, #flag); sep = ','; \
503 printf("\tIAPC_BOOT_ARCH=");
505 PRINTFLAG(fadt->iapc_boot_arch, LEGACY_DEV);
506 PRINTFLAG(fadt->iapc_boot_arch, 8042);
507 if (fadt->iapc_boot_arch != 0)
513 PRINTFLAG(fadt->flags, WBINVD);
514 PRINTFLAG(fadt->flags, WBINVD_FLUSH);
515 PRINTFLAG(fadt->flags, PROC_C1);
516 PRINTFLAG(fadt->flags, P_LVL2_UP);
517 PRINTFLAG(fadt->flags, PWR_BUTTON);
518 PRINTFLAG(fadt->flags, SLP_BUTTON);
519 PRINTFLAG(fadt->flags, FIX_RTC);
520 PRINTFLAG(fadt->flags, RTC_S4);
521 PRINTFLAG(fadt->flags, TMR_VAL_EXT);
522 PRINTFLAG(fadt->flags, DCK_CAP);
523 PRINTFLAG(fadt->flags, RESET_REG);
524 PRINTFLAG(fadt->flags, SEALED_CASE);
525 PRINTFLAG(fadt->flags, HEADLESS);
526 PRINTFLAG(fadt->flags, CPU_SW_SLP);
527 if (fadt->flags != 0)
532 if (fadt->flags & FADT_FLAG_RESET_REG) {
533 printf("\tRESET_REG=");
534 acpi_print_gas(&fadt->reset_reg);
535 printf(", RESET_VALUE=%#x\n", fadt->reset_value);
537 if (acpi_get_fadt_revision(fadt) > 1) {
538 printf("\tX_FACS=0x%08lx, ", (u_long)fadt->x_facs_ptr);
539 printf("X_DSDT=0x%08lx\n", (u_long)fadt->x_dsdt_ptr);
540 printf("\tX_PM1a_EVT_BLK=");
541 acpi_print_gas(&fadt->x_pm1a_evt_blk);
542 if (fadt->x_pm1b_evt_blk.address != 0) {
543 printf("\n\tX_PM1b_EVT_BLK=");
544 acpi_print_gas(&fadt->x_pm1b_evt_blk);
546 printf("\n\tX_PM1a_CNT_BLK=");
547 acpi_print_gas(&fadt->x_pm1a_cnt_blk);
548 if (fadt->x_pm1b_cnt_blk.address != 0) {
549 printf("\n\tX_PM1b_CNT_BLK=");
550 acpi_print_gas(&fadt->x_pm1b_cnt_blk);
552 if (fadt->x_pm1b_cnt_blk.address != 0) {
553 printf("\n\tX_PM2_CNT_BLK=");
554 acpi_print_gas(&fadt->x_pm2_cnt_blk);
556 printf("\n\tX_PM_TMR_BLK=");
557 acpi_print_gas(&fadt->x_pm_tmr_blk);
558 if (fadt->x_gpe0_blk.address != 0) {
559 printf("\n\tX_GPE0_BLK=");
560 acpi_print_gas(&fadt->x_gpe0_blk);
562 if (fadt->x_gpe1_blk.address != 0) {
563 printf("\n\tX_GPE1_BLK=");
564 acpi_print_gas(&fadt->x_gpe1_blk);
573 acpi_print_facs(struct FACSbody *facs)
575 printf(BEGIN_COMMENT);
576 printf(" FACS:\tLength=%u, ", facs->len);
577 printf("HwSig=0x%08x, ", facs->hw_sig);
578 printf("Firm_Wake_Vec=0x%08x\n", facs->firm_wake_vec);
580 printf("\tGlobal_Lock=");
581 if (facs->global_lock != 0) {
582 if (facs->global_lock & FACS_FLAG_LOCK_PENDING)
584 if (facs->global_lock & FACS_FLAG_LOCK_OWNED)
590 if (facs->flags & FACS_FLAG_S4BIOS_F)
594 if (facs->x_firm_wake_vec != 0) {
595 printf("\tX_Firm_Wake_Vec=%08lx\n",
596 (u_long)facs->x_firm_wake_vec);
598 printf("\tVersion=%u\n", facs->version);
604 acpi_print_dsdt(struct ACPIsdt *dsdp)
606 printf(BEGIN_COMMENT);
607 acpi_print_sdt(dsdp);
612 acpi_checksum(void *p, size_t length)
625 static struct ACPIsdt *
626 acpi_map_sdt(vm_offset_t pa)
630 sp = acpi_map_physical(pa, sizeof(struct ACPIsdt));
631 sp = acpi_map_physical(pa, sp->len);
636 acpi_print_rsd_ptr(struct ACPIrsdp *rp)
638 printf(BEGIN_COMMENT);
639 printf(" RSD PTR: OEM=");
640 acpi_print_string(rp->oem, 6);
641 printf(", ACPI_Rev=%s (%d)\n", rp->revision < 2 ? "1.0x" : "2.0x",
643 if (rp->revision < 2) {
644 printf("\tRSDT=0x%08x, cksum=%u\n", rp->rsdt_addr, rp->sum);
646 printf("\tXSDT=0x%08lx, length=%u, cksum=%u\n",
647 (u_long)rp->xsdt_addr, rp->length, rp->xsum);
653 acpi_handle_rsdt(struct ACPIsdt *rsdp)
659 acpi_print_rsdt(rsdp);
660 entries = (rsdp->len - SIZEOF_SDT_HDR) / addr_size;
661 for (i = 0; i < entries; i++) {
664 addr = le32dec((char*)rsdp->body + i * addr_size);
667 addr = le64dec((char*)rsdp->body + i * addr_size);
673 sdp = (struct ACPIsdt *)acpi_map_sdt(addr);
674 if (acpi_checksum(sdp, sdp->len))
675 errx(1, "RSDT entry %d is corrupt", i);
676 if (!memcmp(sdp->signature, "FACP", 4))
677 acpi_handle_fadt(sdp);
678 else if (!memcmp(sdp->signature, "APIC", 4))
679 acpi_handle_apic(sdp);
680 else if (!memcmp(sdp->signature, "HPET", 4))
681 acpi_handle_hpet(sdp);
682 else if (!memcmp(sdp->signature, "ECDT", 4))
683 acpi_handle_ecdt(sdp);
685 printf(BEGIN_COMMENT);
693 sdt_load_devmem(void)
696 struct ACPIsdt *rsdp;
698 rp = acpi_find_rsd_ptr();
700 errx(1, "Can't find ACPI information");
703 acpi_print_rsd_ptr(rp);
704 if (rp->revision < 2) {
705 rsdp = (struct ACPIsdt *)acpi_map_sdt(rp->rsdt_addr);
706 if (memcmp(rsdp->signature, "RSDT", 4) != 0 ||
707 acpi_checksum(rsdp, rsdp->len) != 0)
708 errx(1, "RSDT is corrupted");
709 addr_size = sizeof(uint32_t);
711 rsdp = (struct ACPIsdt *)acpi_map_sdt(rp->xsdt_addr);
712 if (memcmp(rsdp->signature, "XSDT", 4) != 0 ||
713 acpi_checksum(rsdp, rsdp->len) != 0)
714 errx(1, "XSDT is corrupted");
715 addr_size = sizeof(uint64_t);
721 dsdt_save_file(char *outfile, struct ACPIsdt *dsdp)
726 assert(outfile != NULL);
727 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
728 fd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, mode);
730 perror("dsdt_save_file");
733 write(fd, dsdp, SIZEOF_SDT_HDR);
734 write(fd, dsdp->body, dsdp->len - SIZEOF_SDT_HDR);
739 aml_disassemble(struct ACPIsdt *dsdp)
741 char tmpstr[32], buf[256];
745 strcpy(tmpstr, "/tmp/acpidump.XXXXXX");
746 fd = mkstemp(tmpstr);
748 perror("iasl tmp file");
752 /* Dump DSDT to the temp file */
753 write(fd, dsdp, SIZEOF_SDT_HDR);
754 write(fd, dsdp->body, dsdp->len - SIZEOF_SDT_HDR);
757 /* Run iasl -d on the temp file */
759 close(STDOUT_FILENO);
761 close(STDERR_FILENO);
762 execl("/usr/sbin/iasl", "iasl", "-d", tmpstr, 0);
769 /* Dump iasl's output to stdout */
770 fp = fopen("acpidump.dsl", "r");
771 unlink("acpidump.dsl");
773 perror("iasl tmp file (read)");
776 while ((len = fread(buf, 1, sizeof(buf), fp)) > 0)
777 fwrite(buf, 1, len, stdout);
782 sdt_print_all(struct ACPIsdt *rsdp)
784 acpi_handle_rsdt(rsdp);
787 /* Fetch a table matching the given signature via the RSDT */
789 sdt_from_rsdt(struct ACPIsdt *rsdt, const char *sig)
795 entries = (rsdt->len - SIZEOF_SDT_HDR) / addr_size;
796 for (i = 0; i < entries; i++) {
799 addr = le32dec((char*)rsdt->body + i * addr_size);
802 addr = le64dec((char*)rsdt->body + i * addr_size);
807 sdt = (struct ACPIsdt *)acpi_map_sdt(addr);
808 if (memcmp(sdt->signature, sig, strlen(sig)))
810 if (acpi_checksum(sdt, sdt->len))
811 errx(1, "RSDT entry %d is corrupt", i);
819 dsdt_from_fadt(struct FADTbody *fadt)
823 /* Use the DSDT address if it is version 1, otherwise use X_DSDT. */
824 if (acpi_get_fadt_revision(fadt) == 1)
825 sdt = (struct ACPIsdt *)acpi_map_sdt(fadt->dsdt_ptr);
827 sdt = (struct ACPIsdt *)acpi_map_sdt(fadt->x_dsdt_ptr);
828 if (acpi_checksum(sdt, sdt->len))
829 errx(1, "DSDT is corrupt\n");