2 * acpi_tables.c - ACPI Boot-Time Table Parsing
4 * Copyright (C) 2001 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26 #include <linux/config.h>
27 #include <linux/init.h>
28 #include <linux/kernel.h>
29 #include <linux/sched.h>
30 #include <linux/smp.h>
31 #include <linux/string.h>
32 #include <linux/types.h>
33 #include <linux/irq.h>
34 #include <linux/errno.h>
35 #include <linux/acpi.h>
36 #include <linux/bootmem.h>
38 #define PREFIX "ACPI: "
40 #define ACPI_MAX_TABLES 256
42 static char *acpi_table_signatures
[ACPI_TABLE_COUNT
] = {
43 [ACPI_TABLE_UNKNOWN
] = "????",
64 static char *mps_inti_flags_polarity
[] = { "dfl", "high", "res", "low" };
65 static char *mps_inti_flags_trigger
[] = { "dfl", "edge", "res", "level" };
67 /* System Description Table (RSDT/XSDT) */
68 struct acpi_table_sdt
{
70 enum acpi_table_id id
;
72 } __attribute__ ((packed
));
74 static unsigned long sdt_pa
; /* Physical Address */
75 static unsigned long sdt_count
; /* Table count */
77 static struct acpi_table_sdt sdt_entry
[ACPI_MAX_TABLES
];
81 struct acpi_table_header
*header
,
82 unsigned long phys_addr
)
89 /* Some table signatures aren't good table names */
91 if (!strncmp((char *) &header
->signature
,
92 acpi_table_signatures
[ACPI_APIC
],
93 sizeof(header
->signature
))) {
96 else if (!strncmp((char *) &header
->signature
,
97 acpi_table_signatures
[ACPI_FADT
],
98 sizeof(header
->signature
))) {
102 name
= header
->signature
;
104 printk(KERN_DEBUG PREFIX
"%.4s (v%3.3d %6.6s %8.8s 0x%08x %.4s 0x%08x) @ 0x%p\n",
105 name
, header
->revision
, header
->oem_id
,
106 header
->oem_table_id
, header
->oem_revision
,
107 header
->asl_compiler_id
, header
->asl_compiler_revision
,
113 acpi_table_print_madt_entry (
114 acpi_table_entry_header
*header
)
119 switch (header
->type
) {
121 case ACPI_MADT_LAPIC
:
123 struct acpi_table_lapic
*p
=
124 (struct acpi_table_lapic
*) header
;
125 printk(KERN_INFO PREFIX
"LAPIC (acpi_id[0x%02x] lapic_id[0x%02x] %s)\n",
126 p
->acpi_id
, p
->id
, p
->flags
.enabled
?"enabled":"disabled");
130 case ACPI_MADT_IOAPIC
:
132 struct acpi_table_ioapic
*p
=
133 (struct acpi_table_ioapic
*) header
;
134 printk(KERN_INFO PREFIX
"IOAPIC (id[0x%02x] address[0x%08x] gsi_base[%d])\n",
135 p
->id
, p
->address
, p
->global_irq_base
);
139 case ACPI_MADT_INT_SRC_OVR
:
141 struct acpi_table_int_src_ovr
*p
=
142 (struct acpi_table_int_src_ovr
*) header
;
143 printk(KERN_INFO PREFIX
"INT_SRC_OVR (bus %d bus_irq %d global_irq %d %s %s)\n",
144 p
->bus
, p
->bus_irq
, p
->global_irq
,
145 mps_inti_flags_polarity
[p
->flags
.polarity
],
146 mps_inti_flags_trigger
[p
->flags
.trigger
]);
147 if(p
->flags
.reserved
)
148 printk(KERN_INFO PREFIX
"INT_SRC_OVR unexpected reserved flags: 0x%x\n",
154 case ACPI_MADT_NMI_SRC
:
156 struct acpi_table_nmi_src
*p
=
157 (struct acpi_table_nmi_src
*) header
;
158 printk(KERN_INFO PREFIX
"NMI_SRC (%s %s global_irq %d)\n",
159 mps_inti_flags_polarity
[p
->flags
.polarity
],
160 mps_inti_flags_trigger
[p
->flags
.trigger
], p
->global_irq
);
164 case ACPI_MADT_LAPIC_NMI
:
166 struct acpi_table_lapic_nmi
*p
=
167 (struct acpi_table_lapic_nmi
*) header
;
168 printk(KERN_INFO PREFIX
"LAPIC_NMI (acpi_id[0x%02x] %s %s lint[0x%x])\n",
170 mps_inti_flags_polarity
[p
->flags
.polarity
],
171 mps_inti_flags_trigger
[p
->flags
.trigger
], p
->lint
);
175 case ACPI_MADT_LAPIC_ADDR_OVR
:
177 struct acpi_table_lapic_addr_ovr
*p
=
178 (struct acpi_table_lapic_addr_ovr
*) header
;
179 printk(KERN_INFO PREFIX
"LAPIC_ADDR_OVR (address[%p])\n",
180 (void *) (unsigned long) p
->address
);
184 case ACPI_MADT_IOSAPIC
:
186 struct acpi_table_iosapic
*p
=
187 (struct acpi_table_iosapic
*) header
;
188 printk(KERN_INFO PREFIX
"IOSAPIC (id[0x%x] address[%p] gsi_base[%d])\n",
189 p
->id
, (void *) (unsigned long) p
->address
, p
->global_irq_base
);
193 case ACPI_MADT_LSAPIC
:
195 struct acpi_table_lsapic
*p
=
196 (struct acpi_table_lsapic
*) header
;
197 printk(KERN_INFO PREFIX
"LSAPIC (acpi_id[0x%02x] lsapic_id[0x%02x] lsapic_eid[0x%02x] %s)\n",
198 p
->acpi_id
, p
->id
, p
->eid
, p
->flags
.enabled
?"enabled":"disabled");
202 case ACPI_MADT_PLAT_INT_SRC
:
204 struct acpi_table_plat_int_src
*p
=
205 (struct acpi_table_plat_int_src
*) header
;
206 printk(KERN_INFO PREFIX
"PLAT_INT_SRC (%s %s type[0x%x] id[0x%04x] eid[0x%x] iosapic_vector[0x%x] global_irq[0x%x]\n",
207 mps_inti_flags_polarity
[p
->flags
.polarity
],
208 mps_inti_flags_trigger
[p
->flags
.trigger
],
209 p
->type
, p
->id
, p
->eid
, p
->iosapic_vector
, p
->global_irq
);
214 printk(KERN_WARNING PREFIX
"Found unsupported MADT entry (type = 0x%x)\n",
222 acpi_table_compute_checksum (
224 unsigned long length
)
226 u8
*p
= (u8
*) table_pointer
;
227 unsigned long remains
= length
;
228 unsigned long sum
= 0;
240 * acpi_get_table_header_early()
241 * for acpi_blacklisted(), acpi_table_get_sdt()
244 acpi_get_table_header_early (
245 enum acpi_table_id id
,
246 struct acpi_table_header
**header
)
249 enum acpi_table_id temp_id
;
251 /* DSDT is different from the rest */
257 /* Locate the table. */
259 for (i
= 0; i
< sdt_count
; i
++) {
260 if (sdt_entry
[i
].id
!= temp_id
)
263 __acpi_map_table(sdt_entry
[i
].pa
, sdt_entry
[i
].size
);
265 printk(KERN_WARNING PREFIX
"Unable to map %s\n",
266 acpi_table_signatures
[temp_id
]);
273 printk(KERN_WARNING PREFIX
"%s not present\n",
274 acpi_table_signatures
[id
]);
278 /* Map the DSDT header via the pointer in the FADT */
279 if (id
== ACPI_DSDT
) {
280 struct fadt_descriptor_rev2
*fadt
= (struct fadt_descriptor_rev2
*) *header
;
282 if (fadt
->revision
== 3 && fadt
->Xdsdt
) {
283 *header
= (void *) __acpi_map_table(fadt
->Xdsdt
,
284 sizeof(struct acpi_table_header
));
285 } else if (fadt
->V1_dsdt
) {
286 *header
= (void *) __acpi_map_table(fadt
->V1_dsdt
,
287 sizeof(struct acpi_table_header
));
292 printk(KERN_WARNING PREFIX
"Unable to map DSDT\n");
302 acpi_table_parse_madt_family (
303 enum acpi_table_id id
,
304 unsigned long madt_size
,
306 acpi_madt_entry_handler handler
,
307 unsigned int max_entries
)
310 acpi_table_entry_header
*entry
;
311 unsigned int count
= 0;
312 unsigned long madt_end
;
318 /* Locate the MADT (if exists). There should only be one. */
320 for (i
= 0; i
< sdt_count
; i
++) {
321 if (sdt_entry
[i
].id
!= id
)
324 __acpi_map_table(sdt_entry
[i
].pa
, sdt_entry
[i
].size
);
326 printk(KERN_WARNING PREFIX
"Unable to map %s\n",
327 acpi_table_signatures
[id
]);
334 printk(KERN_WARNING PREFIX
"%s not present\n",
335 acpi_table_signatures
[id
]);
339 madt_end
= (unsigned long) madt
+ sdt_entry
[i
].size
;
341 /* Parse all entries looking for a match. */
343 entry
= (acpi_table_entry_header
*)
344 ((unsigned long) madt
+ madt_size
);
346 while (((unsigned long) entry
) + sizeof(acpi_table_entry_header
) < madt_end
) {
347 if (entry
->type
== entry_id
&&
348 (!max_entries
|| count
++ < max_entries
))
349 if (handler(entry
, madt_end
))
352 entry
= (acpi_table_entry_header
*)
353 ((unsigned long) entry
+ entry
->length
);
355 if (max_entries
&& count
> max_entries
) {
356 printk(KERN_WARNING PREFIX
"[%s:0x%02x] ignored %i entries of "
357 "%i found\n", acpi_table_signatures
[id
], entry_id
,
358 count
- max_entries
, count
);
366 acpi_table_parse_madt (
367 enum acpi_madt_entry_id id
,
368 acpi_madt_entry_handler handler
,
369 unsigned int max_entries
)
371 return acpi_table_parse_madt_family(ACPI_APIC
, sizeof(struct acpi_table_madt
),
372 id
, handler
, max_entries
);
378 enum acpi_table_id id
,
379 acpi_table_handler handler
)
387 for (i
= 0; i
< sdt_count
; i
++) {
388 if (sdt_entry
[i
].id
!= id
)
392 handler(sdt_entry
[i
].pa
, sdt_entry
[i
].size
);
395 printk(KERN_WARNING PREFIX
"%d duplicate %s table ignored.\n",
396 count
, acpi_table_signatures
[id
]);
405 struct acpi_table_rsdp
*rsdp
)
407 struct acpi_table_header
*header
= NULL
;
408 unsigned int i
, id
= 0;
413 /* First check XSDT (but only on ACPI 2.0-compatible systems) */
415 if ((rsdp
->revision
>= 2) &&
416 (((struct acpi20_table_rsdp
*)rsdp
)->xsdt_address
)) {
418 struct acpi_table_xsdt
*mapped_xsdt
= NULL
;
420 sdt_pa
= ((struct acpi20_table_rsdp
*)rsdp
)->xsdt_address
;
422 /* map in just the header */
423 header
= (struct acpi_table_header
*)
424 __acpi_map_table(sdt_pa
, sizeof(struct acpi_table_header
));
427 printk(KERN_WARNING PREFIX
"Unable to map XSDT header\n");
431 /* remap in the entire table before processing */
432 mapped_xsdt
= (struct acpi_table_xsdt
*)
433 __acpi_map_table(sdt_pa
, header
->length
);
435 printk(KERN_WARNING PREFIX
"Unable to map XSDT\n");
438 header
= &mapped_xsdt
->header
;
440 if (strncmp(header
->signature
, "XSDT", 4)) {
441 printk(KERN_WARNING PREFIX
"XSDT signature incorrect\n");
445 if (acpi_table_compute_checksum(header
, header
->length
)) {
446 printk(KERN_WARNING PREFIX
"Invalid XSDT checksum\n");
450 sdt_count
= (header
->length
- sizeof(struct acpi_table_header
)) >> 3;
451 if (sdt_count
> ACPI_MAX_TABLES
) {
452 printk(KERN_WARNING PREFIX
"Truncated %lu XSDT entries\n",
453 (sdt_count
- ACPI_MAX_TABLES
));
454 sdt_count
= ACPI_MAX_TABLES
;
457 for (i
= 0; i
< sdt_count
; i
++)
458 sdt_entry
[i
].pa
= (unsigned long) mapped_xsdt
->entry
[i
];
461 /* Then check RSDT */
463 else if (rsdp
->rsdt_address
) {
465 struct acpi_table_rsdt
*mapped_rsdt
= NULL
;
467 sdt_pa
= rsdp
->rsdt_address
;
469 /* map in just the header */
470 header
= (struct acpi_table_header
*)
471 __acpi_map_table(sdt_pa
, sizeof(struct acpi_table_header
));
473 printk(KERN_WARNING PREFIX
"Unable to map RSDT header\n");
477 /* remap in the entire table before processing */
478 mapped_rsdt
= (struct acpi_table_rsdt
*)
479 __acpi_map_table(sdt_pa
, header
->length
);
481 printk(KERN_WARNING PREFIX
"Unable to map RSDT\n");
484 header
= &mapped_rsdt
->header
;
486 if (strncmp(header
->signature
, "RSDT", 4)) {
487 printk(KERN_WARNING PREFIX
"RSDT signature incorrect\n");
491 if (acpi_table_compute_checksum(header
, header
->length
)) {
492 printk(KERN_WARNING PREFIX
"Invalid RSDT checksum\n");
496 sdt_count
= (header
->length
- sizeof(struct acpi_table_header
)) >> 2;
497 if (sdt_count
> ACPI_MAX_TABLES
) {
498 printk(KERN_WARNING PREFIX
"Truncated %lu RSDT entries\n",
499 (sdt_count
- ACPI_MAX_TABLES
));
500 sdt_count
= ACPI_MAX_TABLES
;
503 for (i
= 0; i
< sdt_count
; i
++)
504 sdt_entry
[i
].pa
= (unsigned long) mapped_rsdt
->entry
[i
];
508 printk(KERN_WARNING PREFIX
"No System Description Table (RSDT/XSDT) specified in RSDP\n");
512 acpi_table_print(header
, sdt_pa
);
514 for (i
= 0; i
< sdt_count
; i
++) {
516 /* map in just the header */
517 header
= (struct acpi_table_header
*)
518 __acpi_map_table(sdt_entry
[i
].pa
,
519 sizeof(struct acpi_table_header
));
523 /* remap in the entire table before processing */
524 header
= (struct acpi_table_header
*)
525 __acpi_map_table(sdt_entry
[i
].pa
,
530 acpi_table_print(header
, sdt_entry
[i
].pa
);
532 if (acpi_table_compute_checksum(header
, header
->length
)) {
533 printk(KERN_WARNING
" >>> ERROR: Invalid checksum\n");
537 sdt_entry
[i
].size
= header
->length
;
539 for (id
= 0; id
< ACPI_TABLE_COUNT
; id
++) {
540 if (!strncmp((char *) &header
->signature
,
541 acpi_table_signatures
[id
],
542 sizeof(header
->signature
))) {
543 sdt_entry
[i
].id
= id
;
549 * The DSDT is *not* in the RSDT (why not? no idea.) but we want
550 * to print its info, because this is what people usually blacklist
551 * against. Unfortunately, we don't know the phys_addr, so just
552 * print 0. Maybe no one will notice.
554 if(!acpi_get_table_header_early(ACPI_DSDT
, &header
))
555 acpi_table_print(header
, 0);
563 * find RSDP, find and checksum SDT/XSDT.
564 * checksum all tables, print SDT/XSDT
566 * result: sdt_entry[] is initialized
570 acpi_table_init (void)
572 struct acpi_table_rsdp
*rsdp
= NULL
;
573 unsigned long rsdp_phys
= 0;
576 /* Locate and map the Root System Description Table (RSDP) */
578 rsdp_phys
= acpi_find_rsdp();
580 printk(KERN_ERR PREFIX
"Unable to locate RSDP\n");
584 rsdp
= (struct acpi_table_rsdp
*) __va(rsdp_phys
);
586 printk(KERN_WARNING PREFIX
"Unable to map RSDP\n");
590 printk(KERN_DEBUG PREFIX
"RSDP (v%3.3d %6.6s ) @ 0x%p\n",
591 rsdp
->revision
, rsdp
->oem_id
, (void *) rsdp_phys
);
593 if (rsdp
->revision
< 2)
594 result
= acpi_table_compute_checksum(rsdp
, sizeof(struct acpi_table_rsdp
));
596 result
= acpi_table_compute_checksum(rsdp
, ((struct acpi20_table_rsdp
*)rsdp
)->length
);
599 printk(KERN_WARNING
" >>> ERROR: Invalid checksum\n");
603 /* Locate and map the System Description table (RSDT/XSDT) */
605 if (acpi_table_get_sdt(rsdp
))