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.6 2007/01/10 12:23:23 hsu 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_handle_mcfg(struct ACPIsdt
*sdp
)
383 struct MCFGbody
*mcfg
;
386 printf(BEGIN_COMMENT
);
388 mcfg
= (struct MCFGbody
*) sdp
->body
;
390 e
= (sdp
->len
- ((caddr_t
)&mcfg
->s
[0] - (caddr_t
)sdp
)) /
392 for (i
= 0; i
< e
; i
++, mcfg
++) {
394 printf("\tBase Address= 0x%016jx\n", mcfg
->s
[i
].baseaddr
);
395 printf("\tSegment Group= 0x%04x\n", mcfg
->s
[i
].seg_grp
);
396 printf("\tStart Bus= %d\n", mcfg
->s
[i
].start
);
397 printf("\tEnd Bus= %d\n", mcfg
->s
[i
].end
);
403 acpi_print_sdt(struct ACPIsdt
*sdp
)
406 acpi_print_string(sdp
->signature
, 4);
407 printf(": Length=%d, Revision=%d, Checksum=%d,\n",
408 sdp
->len
, sdp
->rev
, sdp
->check
);
410 acpi_print_string(sdp
->oemid
, 6);
411 printf(", OEM Table ID=");
412 acpi_print_string(sdp
->oemtblid
, 8);
413 printf(", OEM Revision=0x%x,\n", sdp
->oemrev
);
414 printf("\tCreator ID=");
415 acpi_print_string(sdp
->creator
, 4);
416 printf(", Creator Revision=0x%x\n", sdp
->crerev
);
420 acpi_print_rsdt(struct ACPIsdt
*rsdp
)
425 printf(BEGIN_COMMENT
);
426 acpi_print_sdt(rsdp
);
427 entries
= (rsdp
->len
- SIZEOF_SDT_HDR
) / addr_size
;
428 printf("\tEntries={ ");
429 for (i
= 0; i
< entries
; i
++) {
434 addr
= le32dec((char*)rsdp
->body
+ i
* addr_size
);
437 addr
= le64dec((char*)rsdp
->body
+ i
* addr_size
);
443 printf("0x%08lx", addr
);
449 static const char *acpi_pm_profiles
[] = {
450 "Unspecified", "Desktop", "Mobile", "Workstation",
451 "Enterprise Server", "SOHO Server", "Appliance PC"
455 acpi_print_fadt(struct ACPIsdt
*sdp
)
457 struct FADTbody
*fadt
;
461 fadt
= (struct FADTbody
*)sdp
->body
;
462 printf(BEGIN_COMMENT
);
464 printf(" \tFACS=0x%x, DSDT=0x%x\n", fadt
->facs_ptr
,
466 printf("\tINT_MODEL=%s\n", fadt
->int_model
? "APIC" : "PIC");
467 if (fadt
->pm_profile
>= sizeof(acpi_pm_profiles
) / sizeof(char *))
470 pm
= acpi_pm_profiles
[fadt
->pm_profile
];
471 printf("\tPreferred_PM_Profile=%s (%d)\n", pm
, fadt
->pm_profile
);
472 printf("\tSCI_INT=%d\n", fadt
->sci_int
);
473 printf("\tSMI_CMD=0x%x, ", fadt
->smi_cmd
);
474 printf("ACPI_ENABLE=0x%x, ", fadt
->acpi_enable
);
475 printf("ACPI_DISABLE=0x%x, ", fadt
->acpi_disable
);
476 printf("S4BIOS_REQ=0x%x\n", fadt
->s4biosreq
);
477 printf("\tPSTATE_CNT=0x%x\n", fadt
->pstate_cnt
);
478 printf("\tPM1a_EVT_BLK=0x%x-0x%x\n",
480 fadt
->pm1a_evt_blk
+ fadt
->pm1_evt_len
- 1);
481 if (fadt
->pm1b_evt_blk
!= 0)
482 printf("\tPM1b_EVT_BLK=0x%x-0x%x\n",
484 fadt
->pm1b_evt_blk
+ fadt
->pm1_evt_len
- 1);
485 printf("\tPM1a_CNT_BLK=0x%x-0x%x\n",
487 fadt
->pm1a_cnt_blk
+ fadt
->pm1_cnt_len
- 1);
488 if (fadt
->pm1b_cnt_blk
!= 0)
489 printf("\tPM1b_CNT_BLK=0x%x-0x%x\n",
491 fadt
->pm1b_cnt_blk
+ fadt
->pm1_cnt_len
- 1);
492 if (fadt
->pm2_cnt_blk
!= 0)
493 printf("\tPM2_CNT_BLK=0x%x-0x%x\n",
495 fadt
->pm2_cnt_blk
+ fadt
->pm2_cnt_len
- 1);
496 printf("\tPM_TMR_BLK=0x%x-0x%x\n",
498 fadt
->pm_tmr_blk
+ fadt
->pm_tmr_len
- 1);
499 if (fadt
->gpe0_blk
!= 0)
500 printf("\tGPE0_BLK=0x%x-0x%x\n",
502 fadt
->gpe0_blk
+ fadt
->gpe0_len
- 1);
503 if (fadt
->gpe1_blk
!= 0)
504 printf("\tGPE1_BLK=0x%x-0x%x, GPE1_BASE=%d\n",
506 fadt
->gpe1_blk
+ fadt
->gpe1_len
- 1,
508 if (fadt
->cst_cnt
!= 0)
509 printf("\tCST_CNT=0x%x\n", fadt
->cst_cnt
);
510 printf("\tP_LVL2_LAT=%d us, P_LVL3_LAT=%d us\n",
511 fadt
->p_lvl2_lat
, fadt
->p_lvl3_lat
);
512 printf("\tFLUSH_SIZE=%d, FLUSH_STRIDE=%d\n",
513 fadt
->flush_size
, fadt
->flush_stride
);
514 printf("\tDUTY_OFFSET=%d, DUTY_WIDTH=%d\n",
515 fadt
->duty_off
, fadt
->duty_width
);
516 printf("\tDAY_ALRM=%d, MON_ALRM=%d, CENTURY=%d\n",
517 fadt
->day_alrm
, fadt
->mon_alrm
, fadt
->century
);
519 #define PRINTFLAG(var, flag) do { \
520 if ((var) & FADT_FLAG_## flag) { \
521 printf("%c%s", sep, #flag); sep = ','; \
525 printf("\tIAPC_BOOT_ARCH=");
527 PRINTFLAG(fadt
->iapc_boot_arch
, LEGACY_DEV
);
528 PRINTFLAG(fadt
->iapc_boot_arch
, 8042);
529 if (fadt
->iapc_boot_arch
!= 0)
535 PRINTFLAG(fadt
->flags
, WBINVD
);
536 PRINTFLAG(fadt
->flags
, WBINVD_FLUSH
);
537 PRINTFLAG(fadt
->flags
, PROC_C1
);
538 PRINTFLAG(fadt
->flags
, P_LVL2_UP
);
539 PRINTFLAG(fadt
->flags
, PWR_BUTTON
);
540 PRINTFLAG(fadt
->flags
, SLP_BUTTON
);
541 PRINTFLAG(fadt
->flags
, FIX_RTC
);
542 PRINTFLAG(fadt
->flags
, RTC_S4
);
543 PRINTFLAG(fadt
->flags
, TMR_VAL_EXT
);
544 PRINTFLAG(fadt
->flags
, DCK_CAP
);
545 PRINTFLAG(fadt
->flags
, RESET_REG
);
546 PRINTFLAG(fadt
->flags
, SEALED_CASE
);
547 PRINTFLAG(fadt
->flags
, HEADLESS
);
548 PRINTFLAG(fadt
->flags
, CPU_SW_SLP
);
549 if (fadt
->flags
!= 0)
554 if (fadt
->flags
& FADT_FLAG_RESET_REG
) {
555 printf("\tRESET_REG=");
556 acpi_print_gas(&fadt
->reset_reg
);
557 printf(", RESET_VALUE=%#x\n", fadt
->reset_value
);
559 if (acpi_get_fadt_revision(fadt
) > 1) {
560 printf("\tX_FACS=0x%08lx, ", (u_long
)fadt
->x_facs_ptr
);
561 printf("X_DSDT=0x%08lx\n", (u_long
)fadt
->x_dsdt_ptr
);
562 printf("\tX_PM1a_EVT_BLK=");
563 acpi_print_gas(&fadt
->x_pm1a_evt_blk
);
564 if (fadt
->x_pm1b_evt_blk
.address
!= 0) {
565 printf("\n\tX_PM1b_EVT_BLK=");
566 acpi_print_gas(&fadt
->x_pm1b_evt_blk
);
568 printf("\n\tX_PM1a_CNT_BLK=");
569 acpi_print_gas(&fadt
->x_pm1a_cnt_blk
);
570 if (fadt
->x_pm1b_cnt_blk
.address
!= 0) {
571 printf("\n\tX_PM1b_CNT_BLK=");
572 acpi_print_gas(&fadt
->x_pm1b_cnt_blk
);
574 if (fadt
->x_pm1b_cnt_blk
.address
!= 0) {
575 printf("\n\tX_PM2_CNT_BLK=");
576 acpi_print_gas(&fadt
->x_pm2_cnt_blk
);
578 printf("\n\tX_PM_TMR_BLK=");
579 acpi_print_gas(&fadt
->x_pm_tmr_blk
);
580 if (fadt
->x_gpe0_blk
.address
!= 0) {
581 printf("\n\tX_GPE0_BLK=");
582 acpi_print_gas(&fadt
->x_gpe0_blk
);
584 if (fadt
->x_gpe1_blk
.address
!= 0) {
585 printf("\n\tX_GPE1_BLK=");
586 acpi_print_gas(&fadt
->x_gpe1_blk
);
595 acpi_print_facs(struct FACSbody
*facs
)
597 printf(BEGIN_COMMENT
);
598 printf(" FACS:\tLength=%u, ", facs
->len
);
599 printf("HwSig=0x%08x, ", facs
->hw_sig
);
600 printf("Firm_Wake_Vec=0x%08x\n", facs
->firm_wake_vec
);
602 printf("\tGlobal_Lock=");
603 if (facs
->global_lock
!= 0) {
604 if (facs
->global_lock
& FACS_FLAG_LOCK_PENDING
)
606 if (facs
->global_lock
& FACS_FLAG_LOCK_OWNED
)
612 if (facs
->flags
& FACS_FLAG_S4BIOS_F
)
616 if (facs
->x_firm_wake_vec
!= 0) {
617 printf("\tX_Firm_Wake_Vec=%08lx\n",
618 (u_long
)facs
->x_firm_wake_vec
);
620 printf("\tVersion=%u\n", facs
->version
);
626 acpi_print_dsdt(struct ACPIsdt
*dsdp
)
628 printf(BEGIN_COMMENT
);
629 acpi_print_sdt(dsdp
);
634 acpi_checksum(void *p
, size_t length
)
647 static struct ACPIsdt
*
648 acpi_map_sdt(vm_offset_t pa
)
652 sp
= acpi_map_physical(pa
, sizeof(struct ACPIsdt
));
653 sp
= acpi_map_physical(pa
, sp
->len
);
658 acpi_print_rsd_ptr(struct ACPIrsdp
*rp
)
660 printf(BEGIN_COMMENT
);
661 printf(" RSD PTR: OEM=");
662 acpi_print_string(rp
->oem
, 6);
663 printf(", ACPI_Rev=%s (%d)\n", rp
->revision
< 2 ? "1.0x" : "2.0x",
665 if (rp
->revision
< 2) {
666 printf("\tRSDT=0x%08x, cksum=%u\n", rp
->rsdt_addr
, rp
->sum
);
668 printf("\tXSDT=0x%08lx, length=%u, cksum=%u\n",
669 (u_long
)rp
->xsdt_addr
, rp
->length
, rp
->xsum
);
675 acpi_handle_rsdt(struct ACPIsdt
*rsdp
)
681 acpi_print_rsdt(rsdp
);
682 entries
= (rsdp
->len
- SIZEOF_SDT_HDR
) / addr_size
;
683 for (i
= 0; i
< entries
; i
++) {
686 addr
= le32dec((char*)rsdp
->body
+ i
* addr_size
);
689 addr
= le64dec((char*)rsdp
->body
+ i
* addr_size
);
695 sdp
= (struct ACPIsdt
*)acpi_map_sdt(addr
);
696 if (acpi_checksum(sdp
, sdp
->len
)) {
697 warnx("RSDT entry %d (sig %.4s) is corrupt", i
,
701 if (!memcmp(sdp
->signature
, "FACP", 4))
702 acpi_handle_fadt(sdp
);
703 else if (!memcmp(sdp
->signature
, "APIC", 4))
704 acpi_handle_apic(sdp
);
705 else if (!memcmp(sdp
->signature
, "HPET", 4))
706 acpi_handle_hpet(sdp
);
707 else if (!memcmp(sdp
->signature
, "ECDT", 4))
708 acpi_handle_ecdt(sdp
);
709 else if (!memcmp(sdp
->signature
, "MCFG", 4))
710 acpi_handle_mcfg(sdp
);
712 printf(BEGIN_COMMENT
);
720 sdt_load_devmem(void)
723 struct ACPIsdt
*rsdp
;
725 rp
= acpi_find_rsd_ptr();
727 errx(1, "Can't find ACPI information");
730 acpi_print_rsd_ptr(rp
);
731 if (rp
->revision
< 2) {
732 rsdp
= (struct ACPIsdt
*)acpi_map_sdt(rp
->rsdt_addr
);
733 if (memcmp(rsdp
->signature
, "RSDT", 4) != 0 ||
734 acpi_checksum(rsdp
, rsdp
->len
) != 0)
735 errx(1, "RSDT is corrupted");
736 addr_size
= sizeof(uint32_t);
738 rsdp
= (struct ACPIsdt
*)acpi_map_sdt(rp
->xsdt_addr
);
739 if (memcmp(rsdp
->signature
, "XSDT", 4) != 0 ||
740 acpi_checksum(rsdp
, rsdp
->len
) != 0)
741 errx(1, "XSDT is corrupted");
742 addr_size
= sizeof(uint64_t);
747 /* Write the DSDT to a file, concatenating any SSDTs (if present). */
749 write_dsdt(int fd
, struct ACPIsdt
*rsdt
, struct ACPIsdt
*dsdt
)
752 struct ACPIsdt
*ssdt
;
755 /* Create a new checksum to account for the DSDT and any SSDTs. */
759 sum
= acpi_checksum(dsdt
->body
, dsdt
->len
- SIZEOF_SDT_HDR
);
760 ssdt
= sdt_from_rsdt(rsdt
, "SSDT", NULL
);
761 while (ssdt
!= NULL
) {
762 sdt
.len
+= ssdt
->len
- SIZEOF_SDT_HDR
;
763 sum
+= acpi_checksum(ssdt
->body
,
764 ssdt
->len
- SIZEOF_SDT_HDR
);
765 ssdt
= sdt_from_rsdt(rsdt
, "SSDT", ssdt
);
767 sum
+= acpi_checksum(&sdt
, SIZEOF_SDT_HDR
);
771 /* Write out the DSDT header and body. */
772 write(fd
, &sdt
, SIZEOF_SDT_HDR
);
773 write(fd
, dsdt
->body
, dsdt
->len
- SIZEOF_SDT_HDR
);
775 /* Write out any SSDTs (if present.) */
777 ssdt
= sdt_from_rsdt(rsdt
, "SSDT", NULL
);
778 while (ssdt
!= NULL
) {
779 write(fd
, ssdt
->body
, ssdt
->len
- SIZEOF_SDT_HDR
);
780 ssdt
= sdt_from_rsdt(rsdt
, "SSDT", ssdt
);
787 dsdt_save_file(char *outfile
, struct ACPIsdt
*rsdt
, struct ACPIsdt
*dsdp
)
792 assert(outfile
!= NULL
);
793 mode
= S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IROTH
;
794 fd
= open(outfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, mode
);
796 perror("dsdt_save_file");
799 write_dsdt(fd
, rsdt
, dsdp
);
804 aml_disassemble(struct ACPIsdt
*rsdt
, struct ACPIsdt
*dsdp
)
806 char tmpstr
[32], buf
[256];
810 strcpy(tmpstr
, "/tmp/acpidump.XXXXXX");
811 fd
= mkstemp(tmpstr
);
813 perror("iasl tmp file");
816 write_dsdt(fd
, rsdt
, dsdp
);
819 /* Run iasl -d on the temp file */
821 close(STDOUT_FILENO
);
823 close(STDERR_FILENO
);
824 execl("/usr/sbin/iasl", "iasl", "-d", tmpstr
, 0);
831 /* Dump iasl's output to stdout */
832 fp
= fopen("acpidump.dsl", "r");
833 unlink("acpidump.dsl");
835 perror("iasl tmp file (read)");
838 while ((len
= fread(buf
, 1, sizeof(buf
), fp
)) > 0)
839 fwrite(buf
, 1, len
, stdout
);
844 sdt_print_all(struct ACPIsdt
*rsdp
)
846 acpi_handle_rsdt(rsdp
);
849 /* Fetch a table matching the given signature via the RSDT. */
851 sdt_from_rsdt(struct ACPIsdt
*rsdt
, const char *sig
, struct ACPIsdt
*last
)
857 entries
= (rsdt
->len
- SIZEOF_SDT_HDR
) / addr_size
;
858 for (i
= 0; i
< entries
; i
++) {
861 addr
= le32dec((char*)rsdt
->body
+ i
* addr_size
);
864 addr
= le64dec((char*)rsdt
->body
+ i
* addr_size
);
869 sdt
= (struct ACPIsdt
*)acpi_map_sdt(addr
);
875 if (memcmp(sdt
->signature
, sig
, strlen(sig
)))
877 if (acpi_checksum(sdt
, sdt
->len
))
878 errx(1, "RSDT entry %d is corrupt", i
);
886 dsdt_from_fadt(struct FADTbody
*fadt
)
890 /* Use the DSDT address if it is version 1, otherwise use X_DSDT. */
891 if (acpi_get_fadt_revision(fadt
) == 1)
892 sdt
= (struct ACPIsdt
*)acpi_map_sdt(fadt
->dsdt_ptr
);
894 sdt
= (struct ACPIsdt
*)acpi_map_sdt(fadt
->x_dsdt_ptr
);
895 if (acpi_checksum(sdt
, sdt
->len
))
896 errx(1, "DSDT is corrupt\n");