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.31 2005/02/14 11:21:48 scottl Exp $
28 * $DragonFly: src/usr.sbin/acpi/acpidump/acpi.c,v 1.7 2008/07/19 13:50:51 swildner Exp $
31 #include <sys/param.h>
32 #include <sys/endian.h>
46 #define BEGIN_COMMENT "/*\n"
47 #define END_COMMENT " */\n"
49 static void acpi_print_string(char *s
, size_t length
);
50 static void acpi_print_gas(struct ACPIgas
*gas
);
51 static int acpi_get_fadt_revision(struct FADTbody
*fadt
);
52 static void acpi_handle_fadt(struct ACPIsdt
*fadt
);
53 static void acpi_print_cpu(u_char cpu_id
);
54 static void acpi_print_local_apic(u_char cpu_id
, u_char apic_id
,
56 static void acpi_print_io_apic(u_char apic_id
, u_int32_t int_base
,
58 static void acpi_print_mps_flags(u_int16_t flags
);
59 static void acpi_print_intr(u_int32_t intr
, u_int16_t mps_flags
);
60 static void acpi_print_apic(struct MADT_APIC
*mp
);
61 static void acpi_handle_apic(struct ACPIsdt
*sdp
);
62 static void acpi_handle_hpet(struct ACPIsdt
*sdp
);
63 static void acpi_print_sdt(struct ACPIsdt
*sdp
);
64 static void acpi_print_fadt(struct ACPIsdt
*sdp
);
65 static void acpi_print_facs(struct FACSbody
*facs
);
66 static void acpi_print_dsdt(struct ACPIsdt
*dsdp
);
67 static struct ACPIsdt
*acpi_map_sdt(vm_offset_t pa
);
68 static void acpi_print_rsd_ptr(struct ACPIrsdp
*rp
);
69 static void acpi_handle_rsdt(struct ACPIsdt
*rsdp
);
71 /* Size of an address. 32-bit for ACPI 1.0, 64-bit for ACPI 2.0 and up. */
75 acpi_print_string(char *s
, size_t length
)
79 /* Trim trailing spaces and NULLs */
80 while (length
> 0 && (s
[length
- 1] == ' ' || s
[length
- 1] == '\0'))
90 acpi_print_gas(struct ACPIgas
*gas
)
92 switch(gas
->address_space_id
) {
94 printf("0x%08lx:%u[%u] (Memory)", (u_long
)gas
->address
,
95 gas
->bit_offset
, gas
->bit_width
);
98 printf("0x%02lx:%u[%u] (IO)", (u_long
)gas
->address
,
99 gas
->bit_offset
, gas
->bit_width
);
102 printf("%x:%x+0x%x (PCI)", (uint16_t)(gas
->address
>> 32),
103 (uint16_t)((gas
->address
>> 16) & 0xffff),
104 (uint16_t)gas
->address
);
106 /* XXX How to handle these below? */
107 case ACPI_GAS_EMBEDDED
:
108 printf("0x%x:%u[%u] (EC)", (uint16_t)gas
->address
,
109 gas
->bit_offset
, gas
->bit_width
);
112 printf("0x%x:%u[%u] (SMBus)", (uint16_t)gas
->address
,
113 gas
->bit_offset
, gas
->bit_width
);
117 printf("0x%08lx (?)", (u_long
)gas
->address
);
122 /* The FADT revision indicates whether we use the DSDT or X_DSDT addresses. */
124 acpi_get_fadt_revision(struct FADTbody
*fadt
)
128 /* Set the FADT revision separately from the RSDP version. */
129 if (addr_size
== 8) {
133 * A few systems (e.g., IBM T23) have an RSDP that claims
134 * revision 2 but the 64 bit addresses are invalid. If
135 * revision 2 and the 32 bit address is non-zero but the
136 * 32 and 64 bit versions don't match, prefer the 32 bit
137 * version for all subsequent tables.
139 if (fadt
->facs_ptr
!= 0 &&
140 (fadt
->x_facs_ptr
& 0xffffffff) != fadt
->facs_ptr
)
144 return (fadt_revision
);
148 acpi_handle_fadt(struct ACPIsdt
*sdp
)
150 struct ACPIsdt
*dsdp
;
151 struct FACSbody
*facs
;
152 struct FADTbody
*fadt
;
155 fadt
= (struct FADTbody
*)sdp
->body
;
156 acpi_print_fadt(sdp
);
158 fadt_revision
= acpi_get_fadt_revision(fadt
);
159 if (fadt_revision
== 1)
160 facs
= (struct FACSbody
*)acpi_map_sdt(fadt
->facs_ptr
);
162 facs
= (struct FACSbody
*)acpi_map_sdt(fadt
->x_facs_ptr
);
163 if (memcmp(facs
->signature
, "FACS", 4) != 0 || facs
->len
< 64)
164 errx(1, "FACS is corrupt");
165 acpi_print_facs(facs
);
167 if (fadt_revision
== 1)
168 dsdp
= (struct ACPIsdt
*)acpi_map_sdt(fadt
->dsdt_ptr
);
170 dsdp
= (struct ACPIsdt
*)acpi_map_sdt(fadt
->x_dsdt_ptr
);
171 if (acpi_checksum(dsdp
, dsdp
->len
))
172 errx(1, "DSDT is corrupt");
173 acpi_print_dsdt(dsdp
);
177 acpi_print_cpu(u_char cpu_id
)
180 printf("\tACPI CPU=");
184 printf("%d\n", (u_int
)cpu_id
);
188 acpi_print_local_apic(u_char cpu_id
, u_char apic_id
, u_int32_t flags
)
190 acpi_print_cpu(cpu_id
);
192 if (flags
& ACPI_MADT_APIC_LOCAL_FLAG_ENABLED
)
197 printf("\tAPIC ID=%d\n", (u_int
)apic_id
);
201 acpi_print_io_apic(u_char apic_id
, u_int32_t int_base
, u_int64_t apic_addr
)
203 printf("\tAPIC ID=%d\n", (u_int
)apic_id
);
204 printf("\tINT BASE=%d\n", int_base
);
205 printf("\tADDR=0x%016jx\n", apic_addr
);
209 acpi_print_mps_flags(u_int16_t flags
)
212 printf("\tFlags={Polarity=");
213 switch (flags
& MPS_INT_FLAG_POLARITY_MASK
) {
214 case MPS_INT_FLAG_POLARITY_CONFORM
:
215 printf("conforming");
217 case MPS_INT_FLAG_POLARITY_HIGH
:
220 case MPS_INT_FLAG_POLARITY_LOW
:
224 printf("0x%x", flags
& MPS_INT_FLAG_POLARITY_MASK
);
227 printf(", Trigger=");
228 switch (flags
& MPS_INT_FLAG_TRIGGER_MASK
) {
229 case MPS_INT_FLAG_TRIGGER_CONFORM
:
230 printf("conforming");
232 case MPS_INT_FLAG_TRIGGER_EDGE
:
235 case MPS_INT_FLAG_TRIGGER_LEVEL
:
239 printf("0x%x", (flags
& MPS_INT_FLAG_TRIGGER_MASK
) >> 2);
245 acpi_print_intr(u_int32_t intr
, u_int16_t mps_flags
)
248 printf("\tINTR=%d\n", (u_int
)intr
);
249 acpi_print_mps_flags(mps_flags
);
252 const char *apic_types
[] = { "Local APIC", "IO APIC", "INT Override", "NMI",
253 "Local NMI", "Local APIC Override", "IO SAPIC",
254 "Local SAPIC", "Platform Interrupt" };
255 const char *platform_int_types
[] = { "PMI", "INIT",
256 "Corrected Platform Error" };
259 acpi_print_apic(struct MADT_APIC
*mp
)
262 printf("\tType=%s\n", apic_types
[mp
->type
]);
264 case ACPI_MADT_APIC_TYPE_LOCAL_APIC
:
265 acpi_print_local_apic(mp
->body
.local_apic
.cpu_id
,
266 mp
->body
.local_apic
.apic_id
, mp
->body
.local_apic
.flags
);
268 case ACPI_MADT_APIC_TYPE_IO_APIC
:
269 acpi_print_io_apic(mp
->body
.io_apic
.apic_id
,
270 mp
->body
.io_apic
.int_base
,
271 mp
->body
.io_apic
.apic_addr
);
273 case ACPI_MADT_APIC_TYPE_INT_OVERRIDE
:
274 printf("\tBUS=%d\n", (u_int
)mp
->body
.int_override
.bus
);
275 printf("\tIRQ=%d\n", (u_int
)mp
->body
.int_override
.source
);
276 acpi_print_intr(mp
->body
.int_override
.intr
,
277 mp
->body
.int_override
.mps_flags
);
279 case ACPI_MADT_APIC_TYPE_NMI
:
280 acpi_print_intr(mp
->body
.nmi
.intr
, mp
->body
.nmi
.mps_flags
);
282 case ACPI_MADT_APIC_TYPE_LOCAL_NMI
:
283 acpi_print_cpu(mp
->body
.local_nmi
.cpu_id
);
284 printf("\tLINT Pin=%d\n", mp
->body
.local_nmi
.lintpin
);
285 acpi_print_mps_flags(mp
->body
.local_nmi
.mps_flags
);
287 case ACPI_MADT_APIC_TYPE_LOCAL_OVERRIDE
:
288 printf("\tLocal APIC ADDR=0x%016jx\n",
289 mp
->body
.local_apic_override
.apic_addr
);
291 case ACPI_MADT_APIC_TYPE_IO_SAPIC
:
292 acpi_print_io_apic(mp
->body
.io_sapic
.apic_id
,
293 mp
->body
.io_sapic
.int_base
,
294 mp
->body
.io_sapic
.apic_addr
);
296 case ACPI_MADT_APIC_TYPE_LOCAL_SAPIC
:
297 acpi_print_local_apic(mp
->body
.local_sapic
.cpu_id
,
298 mp
->body
.local_sapic
.apic_id
, mp
->body
.local_sapic
.flags
);
299 printf("\tAPIC EID=%d\n", (u_int
)mp
->body
.local_sapic
.apic_eid
);
301 case ACPI_MADT_APIC_TYPE_INT_SRC
:
302 printf("\tType=%s\n",
303 platform_int_types
[mp
->body
.int_src
.type
]);
304 printf("\tCPU ID=%d\n", (u_int
)mp
->body
.int_src
.cpu_id
);
305 printf("\tCPU EID=%d\n", (u_int
)mp
->body
.int_src
.cpu_id
);
306 printf("\tSAPIC Vector=%d\n",
307 (u_int
)mp
->body
.int_src
.sapic_vector
);
308 acpi_print_intr(mp
->body
.int_src
.intr
,
309 mp
->body
.int_src
.mps_flags
);
312 printf("\tUnknown type %d\n", (u_int
)mp
->type
);
318 acpi_handle_apic(struct ACPIsdt
*sdp
)
320 struct MADTbody
*madtp
;
321 struct MADT_APIC
*madt_apicp
;
323 printf(BEGIN_COMMENT
);
325 madtp
= (struct MADTbody
*) sdp
->body
;
326 printf("\tLocal APIC ADDR=0x%08x\n", madtp
->lapic_addr
);
328 if (madtp
->flags
& ACPI_APIC_FLAG_PCAT_COMPAT
)
331 madt_apicp
= (struct MADT_APIC
*)madtp
->body
;
332 while (((uintptr_t)madt_apicp
) - ((uintptr_t)sdp
) < sdp
->len
) {
334 acpi_print_apic(madt_apicp
);
335 madt_apicp
= (struct MADT_APIC
*) ((char *)madt_apicp
+
342 acpi_handle_hpet(struct ACPIsdt
*sdp
)
344 struct HPETbody
*hpetp
;
346 printf(BEGIN_COMMENT
);
348 hpetp
= (struct HPETbody
*) sdp
->body
;
349 printf("\tHPET Number=%d\n", hpetp
->hpet_number
);
350 printf("\tADDR=0x%08x\n", hpetp
->base_addr
);
351 printf("\tHW Rev=0x%x\n", hpetp
->block_hwrev
);
352 printf("\tComparitors=%d\n", hpetp
->block_comparitors
);
353 printf("\tCounter Size=%d\n", hpetp
->block_counter_size
);
354 printf("\tLegacy IRQ routing capable={");
355 if (hpetp
->block_legacy_capable
)
359 printf("\tPCI Vendor ID=0x%04x\n", hpetp
->block_pcivendor
);
360 printf("\tMinimal Tick=%d\n", hpetp
->clock_tick
);
365 acpi_handle_ecdt(struct ACPIsdt
*sdp
)
367 struct ECDTbody
*ecdt
;
369 printf(BEGIN_COMMENT
);
371 ecdt
= (struct ECDTbody
*) sdp
->body
;
372 printf("\tEC_CONTROL=");
373 acpi_print_gas(&ecdt
->ec_control
);
374 printf("\n\tEC_DATA=");
375 acpi_print_gas(&ecdt
->ec_data
);
376 printf("\n\tUID=%#x, ", ecdt
->uid
);
377 printf("GPE_BIT=%#x\n", ecdt
->gpe_bit
);
378 printf("\tEC_ID=%s\n", ecdt
->ec_id
);
383 acpi_handle_mcfg(struct ACPIsdt
*sdp
)
385 struct MCFGbody
*mcfg
;
388 printf(BEGIN_COMMENT
);
390 mcfg
= (struct MCFGbody
*) sdp
->body
;
392 e
= (sdp
->len
- ((caddr_t
)&mcfg
->s
[0] - (caddr_t
)sdp
)) /
394 for (i
= 0; i
< e
; i
++, mcfg
++) {
396 printf("\tBase Address= 0x%016jx\n", mcfg
->s
[i
].baseaddr
);
397 printf("\tSegment Group= 0x%04x\n", mcfg
->s
[i
].seg_grp
);
398 printf("\tStart Bus= %d\n", mcfg
->s
[i
].start
);
399 printf("\tEnd Bus= %d\n", mcfg
->s
[i
].end
);
405 acpi_print_sdt(struct ACPIsdt
*sdp
)
408 acpi_print_string(sdp
->signature
, 4);
409 printf(": Length=%d, Revision=%d, Checksum=%d,\n",
410 sdp
->len
, sdp
->rev
, sdp
->check
);
412 acpi_print_string(sdp
->oemid
, 6);
413 printf(", OEM Table ID=");
414 acpi_print_string(sdp
->oemtblid
, 8);
415 printf(", OEM Revision=0x%x,\n", sdp
->oemrev
);
416 printf("\tCreator ID=");
417 acpi_print_string(sdp
->creator
, 4);
418 printf(", Creator Revision=0x%x\n", sdp
->crerev
);
422 acpi_print_rsdt(struct ACPIsdt
*rsdp
)
427 printf(BEGIN_COMMENT
);
428 acpi_print_sdt(rsdp
);
429 entries
= (rsdp
->len
- SIZEOF_SDT_HDR
) / addr_size
;
430 printf("\tEntries={ ");
431 for (i
= 0; i
< entries
; i
++) {
436 addr
= le32dec((char*)rsdp
->body
+ i
* addr_size
);
439 addr
= le64dec((char*)rsdp
->body
+ i
* addr_size
);
445 printf("0x%08lx", addr
);
451 static const char *acpi_pm_profiles
[] = {
452 "Unspecified", "Desktop", "Mobile", "Workstation",
453 "Enterprise Server", "SOHO Server", "Appliance PC"
457 acpi_print_fadt(struct ACPIsdt
*sdp
)
459 struct FADTbody
*fadt
;
463 fadt
= (struct FADTbody
*)sdp
->body
;
464 printf(BEGIN_COMMENT
);
466 printf(" \tFACS=0x%x, DSDT=0x%x\n", fadt
->facs_ptr
,
468 printf("\tINT_MODEL=%s\n", fadt
->int_model
? "APIC" : "PIC");
469 if (fadt
->pm_profile
>= sizeof(acpi_pm_profiles
) / sizeof(char *))
472 pm
= acpi_pm_profiles
[fadt
->pm_profile
];
473 printf("\tPreferred_PM_Profile=%s (%d)\n", pm
, fadt
->pm_profile
);
474 printf("\tSCI_INT=%d\n", fadt
->sci_int
);
475 printf("\tSMI_CMD=0x%x, ", fadt
->smi_cmd
);
476 printf("ACPI_ENABLE=0x%x, ", fadt
->acpi_enable
);
477 printf("ACPI_DISABLE=0x%x, ", fadt
->acpi_disable
);
478 printf("S4BIOS_REQ=0x%x\n", fadt
->s4biosreq
);
479 printf("\tPSTATE_CNT=0x%x\n", fadt
->pstate_cnt
);
480 printf("\tPM1a_EVT_BLK=0x%x-0x%x\n",
482 fadt
->pm1a_evt_blk
+ fadt
->pm1_evt_len
- 1);
483 if (fadt
->pm1b_evt_blk
!= 0)
484 printf("\tPM1b_EVT_BLK=0x%x-0x%x\n",
486 fadt
->pm1b_evt_blk
+ fadt
->pm1_evt_len
- 1);
487 printf("\tPM1a_CNT_BLK=0x%x-0x%x\n",
489 fadt
->pm1a_cnt_blk
+ fadt
->pm1_cnt_len
- 1);
490 if (fadt
->pm1b_cnt_blk
!= 0)
491 printf("\tPM1b_CNT_BLK=0x%x-0x%x\n",
493 fadt
->pm1b_cnt_blk
+ fadt
->pm1_cnt_len
- 1);
494 if (fadt
->pm2_cnt_blk
!= 0)
495 printf("\tPM2_CNT_BLK=0x%x-0x%x\n",
497 fadt
->pm2_cnt_blk
+ fadt
->pm2_cnt_len
- 1);
498 printf("\tPM_TMR_BLK=0x%x-0x%x\n",
500 fadt
->pm_tmr_blk
+ fadt
->pm_tmr_len
- 1);
501 if (fadt
->gpe0_blk
!= 0)
502 printf("\tGPE0_BLK=0x%x-0x%x\n",
504 fadt
->gpe0_blk
+ fadt
->gpe0_len
- 1);
505 if (fadt
->gpe1_blk
!= 0)
506 printf("\tGPE1_BLK=0x%x-0x%x, GPE1_BASE=%d\n",
508 fadt
->gpe1_blk
+ fadt
->gpe1_len
- 1,
510 if (fadt
->cst_cnt
!= 0)
511 printf("\tCST_CNT=0x%x\n", fadt
->cst_cnt
);
512 printf("\tP_LVL2_LAT=%d us, P_LVL3_LAT=%d us\n",
513 fadt
->p_lvl2_lat
, fadt
->p_lvl3_lat
);
514 printf("\tFLUSH_SIZE=%d, FLUSH_STRIDE=%d\n",
515 fadt
->flush_size
, fadt
->flush_stride
);
516 printf("\tDUTY_OFFSET=%d, DUTY_WIDTH=%d\n",
517 fadt
->duty_off
, fadt
->duty_width
);
518 printf("\tDAY_ALRM=%d, MON_ALRM=%d, CENTURY=%d\n",
519 fadt
->day_alrm
, fadt
->mon_alrm
, fadt
->century
);
521 #define PRINTFLAG(var, flag) do { \
522 if ((var) & FADT_FLAG_## flag) { \
523 printf("%c%s", sep, #flag); sep = ','; \
527 printf("\tIAPC_BOOT_ARCH=");
529 PRINTFLAG(fadt
->iapc_boot_arch
, LEGACY_DEV
);
530 PRINTFLAG(fadt
->iapc_boot_arch
, 8042);
531 if (fadt
->iapc_boot_arch
!= 0)
537 PRINTFLAG(fadt
->flags
, WBINVD
);
538 PRINTFLAG(fadt
->flags
, WBINVD_FLUSH
);
539 PRINTFLAG(fadt
->flags
, PROC_C1
);
540 PRINTFLAG(fadt
->flags
, P_LVL2_UP
);
541 PRINTFLAG(fadt
->flags
, PWR_BUTTON
);
542 PRINTFLAG(fadt
->flags
, SLP_BUTTON
);
543 PRINTFLAG(fadt
->flags
, FIX_RTC
);
544 PRINTFLAG(fadt
->flags
, RTC_S4
);
545 PRINTFLAG(fadt
->flags
, TMR_VAL_EXT
);
546 PRINTFLAG(fadt
->flags
, DCK_CAP
);
547 PRINTFLAG(fadt
->flags
, RESET_REG
);
548 PRINTFLAG(fadt
->flags
, SEALED_CASE
);
549 PRINTFLAG(fadt
->flags
, HEADLESS
);
550 PRINTFLAG(fadt
->flags
, CPU_SW_SLP
);
551 if (fadt
->flags
!= 0)
556 if (fadt
->flags
& FADT_FLAG_RESET_REG
) {
557 printf("\tRESET_REG=");
558 acpi_print_gas(&fadt
->reset_reg
);
559 printf(", RESET_VALUE=%#x\n", fadt
->reset_value
);
561 if (acpi_get_fadt_revision(fadt
) > 1) {
562 printf("\tX_FACS=0x%08lx, ", (u_long
)fadt
->x_facs_ptr
);
563 printf("X_DSDT=0x%08lx\n", (u_long
)fadt
->x_dsdt_ptr
);
564 printf("\tX_PM1a_EVT_BLK=");
565 acpi_print_gas(&fadt
->x_pm1a_evt_blk
);
566 if (fadt
->x_pm1b_evt_blk
.address
!= 0) {
567 printf("\n\tX_PM1b_EVT_BLK=");
568 acpi_print_gas(&fadt
->x_pm1b_evt_blk
);
570 printf("\n\tX_PM1a_CNT_BLK=");
571 acpi_print_gas(&fadt
->x_pm1a_cnt_blk
);
572 if (fadt
->x_pm1b_cnt_blk
.address
!= 0) {
573 printf("\n\tX_PM1b_CNT_BLK=");
574 acpi_print_gas(&fadt
->x_pm1b_cnt_blk
);
576 if (fadt
->x_pm1b_cnt_blk
.address
!= 0) {
577 printf("\n\tX_PM2_CNT_BLK=");
578 acpi_print_gas(&fadt
->x_pm2_cnt_blk
);
580 printf("\n\tX_PM_TMR_BLK=");
581 acpi_print_gas(&fadt
->x_pm_tmr_blk
);
582 if (fadt
->x_gpe0_blk
.address
!= 0) {
583 printf("\n\tX_GPE0_BLK=");
584 acpi_print_gas(&fadt
->x_gpe0_blk
);
586 if (fadt
->x_gpe1_blk
.address
!= 0) {
587 printf("\n\tX_GPE1_BLK=");
588 acpi_print_gas(&fadt
->x_gpe1_blk
);
597 acpi_print_facs(struct FACSbody
*facs
)
599 printf(BEGIN_COMMENT
);
600 printf(" FACS:\tLength=%u, ", facs
->len
);
601 printf("HwSig=0x%08x, ", facs
->hw_sig
);
602 printf("Firm_Wake_Vec=0x%08x\n", facs
->firm_wake_vec
);
604 printf("\tGlobal_Lock=");
605 if (facs
->global_lock
!= 0) {
606 if (facs
->global_lock
& FACS_FLAG_LOCK_PENDING
)
608 if (facs
->global_lock
& FACS_FLAG_LOCK_OWNED
)
614 if (facs
->flags
& FACS_FLAG_S4BIOS_F
)
618 if (facs
->x_firm_wake_vec
!= 0) {
619 printf("\tX_Firm_Wake_Vec=%08lx\n",
620 (u_long
)facs
->x_firm_wake_vec
);
622 printf("\tVersion=%u\n", facs
->version
);
628 acpi_print_dsdt(struct ACPIsdt
*dsdp
)
630 printf(BEGIN_COMMENT
);
631 acpi_print_sdt(dsdp
);
636 acpi_checksum(void *p
, size_t length
)
649 static struct ACPIsdt
*
650 acpi_map_sdt(vm_offset_t pa
)
654 sp
= acpi_map_physical(pa
, sizeof(struct ACPIsdt
));
655 sp
= acpi_map_physical(pa
, sp
->len
);
660 acpi_print_rsd_ptr(struct ACPIrsdp
*rp
)
662 printf(BEGIN_COMMENT
);
663 printf(" RSD PTR: OEM=");
664 acpi_print_string(rp
->oem
, 6);
665 printf(", ACPI_Rev=%s (%d)\n", rp
->revision
< 2 ? "1.0x" : "2.0x",
667 if (rp
->revision
< 2) {
668 printf("\tRSDT=0x%08x, cksum=%u\n", rp
->rsdt_addr
, rp
->sum
);
670 printf("\tXSDT=0x%08lx, length=%u, cksum=%u\n",
671 (u_long
)rp
->xsdt_addr
, rp
->length
, rp
->xsum
);
677 acpi_handle_rsdt(struct ACPIsdt
*rsdp
)
683 acpi_print_rsdt(rsdp
);
684 entries
= (rsdp
->len
- SIZEOF_SDT_HDR
) / addr_size
;
685 for (i
= 0; i
< entries
; i
++) {
688 addr
= le32dec((char*)rsdp
->body
+ i
* addr_size
);
691 addr
= le64dec((char*)rsdp
->body
+ i
* addr_size
);
697 sdp
= (struct ACPIsdt
*)acpi_map_sdt(addr
);
698 if (acpi_checksum(sdp
, sdp
->len
)) {
699 warnx("RSDT entry %d (sig %.4s) is corrupt", i
,
703 if (!memcmp(sdp
->signature
, "FACP", 4))
704 acpi_handle_fadt(sdp
);
705 else if (!memcmp(sdp
->signature
, "APIC", 4))
706 acpi_handle_apic(sdp
);
707 else if (!memcmp(sdp
->signature
, "HPET", 4))
708 acpi_handle_hpet(sdp
);
709 else if (!memcmp(sdp
->signature
, "ECDT", 4))
710 acpi_handle_ecdt(sdp
);
711 else if (!memcmp(sdp
->signature
, "MCFG", 4))
712 acpi_handle_mcfg(sdp
);
714 printf(BEGIN_COMMENT
);
722 sdt_load_devmem(void)
725 struct ACPIsdt
*rsdp
;
727 rp
= acpi_find_rsd_ptr();
729 errx(1, "Can't find ACPI information");
732 acpi_print_rsd_ptr(rp
);
733 if (rp
->revision
< 2) {
734 rsdp
= (struct ACPIsdt
*)acpi_map_sdt(rp
->rsdt_addr
);
735 if (memcmp(rsdp
->signature
, "RSDT", 4) != 0 ||
736 acpi_checksum(rsdp
, rsdp
->len
) != 0)
737 errx(1, "RSDT is corrupted");
738 addr_size
= sizeof(uint32_t);
740 rsdp
= (struct ACPIsdt
*)acpi_map_sdt(rp
->xsdt_addr
);
741 if (memcmp(rsdp
->signature
, "XSDT", 4) != 0 ||
742 acpi_checksum(rsdp
, rsdp
->len
) != 0)
743 errx(1, "XSDT is corrupted");
744 addr_size
= sizeof(uint64_t);
749 /* Write the DSDT to a file, concatenating any SSDTs (if present). */
751 write_dsdt(int fd
, struct ACPIsdt
*rsdt
, struct ACPIsdt
*dsdt
)
754 struct ACPIsdt
*ssdt
;
757 /* Create a new checksum to account for the DSDT and any SSDTs. */
761 sum
= acpi_checksum(dsdt
->body
, dsdt
->len
- SIZEOF_SDT_HDR
);
762 ssdt
= sdt_from_rsdt(rsdt
, "SSDT", NULL
);
763 while (ssdt
!= NULL
) {
764 sdt
.len
+= ssdt
->len
- SIZEOF_SDT_HDR
;
765 sum
+= acpi_checksum(ssdt
->body
,
766 ssdt
->len
- SIZEOF_SDT_HDR
);
767 ssdt
= sdt_from_rsdt(rsdt
, "SSDT", ssdt
);
769 sum
+= acpi_checksum(&sdt
, SIZEOF_SDT_HDR
);
773 /* Write out the DSDT header and body. */
774 write(fd
, &sdt
, SIZEOF_SDT_HDR
);
775 write(fd
, dsdt
->body
, dsdt
->len
- SIZEOF_SDT_HDR
);
777 /* Write out any SSDTs (if present.) */
779 ssdt
= sdt_from_rsdt(rsdt
, "SSDT", NULL
);
780 while (ssdt
!= NULL
) {
781 write(fd
, ssdt
->body
, ssdt
->len
- SIZEOF_SDT_HDR
);
782 ssdt
= sdt_from_rsdt(rsdt
, "SSDT", ssdt
);
789 dsdt_save_file(char *outfile
, struct ACPIsdt
*rsdt
, struct ACPIsdt
*dsdp
)
794 assert(outfile
!= NULL
);
795 mode
= S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IROTH
;
796 fd
= open(outfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, mode
);
798 perror("dsdt_save_file");
801 write_dsdt(fd
, rsdt
, dsdp
);
806 aml_disassemble(struct ACPIsdt
*rsdt
, struct ACPIsdt
*dsdp
)
808 char buf
[PATH_MAX
], tmpstr
[PATH_MAX
];
815 tmpdir
= getenv("TMPDIR");
818 strncpy(tmpstr
, tmpdir
, sizeof(tmpstr
));
819 strncat(tmpstr
, "/acpidump.", sizeof(tmpstr
) - strlen(tmpdir
));
820 if (realpath(tmpstr
, buf
) == NULL
) {
821 perror("realpath tmp file");
824 strncpy(tmpstr
, buf
, sizeof(tmpstr
));
826 tmpext
= tmpstr
+ len
;
827 strncpy(tmpext
, "XXXXXX", sizeof(tmpstr
) - len
);
828 fd
= mkstemp(tmpstr
);
830 perror("iasl tmp file");
833 write_dsdt(fd
, rsdt
, dsdp
);
836 /* Run iasl -d on the temp file */
838 close(STDOUT_FILENO
);
840 close(STDERR_FILENO
);
841 execl("/usr/sbin/iasl", "iasl", "-d", tmpstr
, NULL
);
848 /* Dump iasl's output to stdout */
849 strncpy(tmpext
, "dsl", sizeof(tmpstr
) - len
);
850 fp
= fopen(tmpstr
, "r");
853 perror("iasl tmp file (read)");
856 while ((len
= fread(buf
, 1, sizeof(buf
), fp
)) > 0)
857 fwrite(buf
, 1, len
, stdout
);
862 sdt_print_all(struct ACPIsdt
*rsdp
)
864 acpi_handle_rsdt(rsdp
);
867 /* Fetch a table matching the given signature via the RSDT. */
869 sdt_from_rsdt(struct ACPIsdt
*rsdt
, const char *sig
, struct ACPIsdt
*last
)
875 entries
= (rsdt
->len
- SIZEOF_SDT_HDR
) / addr_size
;
876 for (i
= 0; i
< entries
; i
++) {
879 addr
= le32dec((char*)rsdt
->body
+ i
* addr_size
);
882 addr
= le64dec((char*)rsdt
->body
+ i
* addr_size
);
887 sdt
= (struct ACPIsdt
*)acpi_map_sdt(addr
);
893 if (memcmp(sdt
->signature
, sig
, strlen(sig
)))
895 if (acpi_checksum(sdt
, sdt
->len
))
896 errx(1, "RSDT entry %d is corrupt", i
);
904 dsdt_from_fadt(struct FADTbody
*fadt
)
908 /* Use the DSDT address if it is version 1, otherwise use X_DSDT. */
909 if (acpi_get_fadt_revision(fadt
) == 1)
910 sdt
= (struct ACPIsdt
*)acpi_map_sdt(fadt
->dsdt_ptr
);
912 sdt
= (struct ACPIsdt
*)acpi_map_sdt(fadt
->x_dsdt_ptr
);
913 if (acpi_checksum(sdt
, sdt
->len
))
914 errx(1, "DSDT is corrupt\n");