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_INFO 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] global_irq_base[0x%x])\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] global_irq_base[0x%x] address[%p])\n",
189 p->id, p->global_irq_base, (void *) (unsigned long) p->address);
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)
309 acpi_table_entry_header *entry = NULL;
310 unsigned long count = 0;
311 unsigned long madt_end = 0;
317 /* Locate the MADT (if exists). There should only be one. */
319 for (i = 0; i < sdt_count; i++) {
320 if (sdt_entry[i].id != id)
323 __acpi_map_table(sdt_entry[i].pa, sdt_entry[i].size);
325 printk(KERN_WARNING PREFIX "Unable to map %s\n",
326 acpi_table_signatures[id]);
333 printk(KERN_WARNING PREFIX "%s not present\n",
334 acpi_table_signatures[id]);
338 madt_end = (unsigned long) madt + sdt_entry[i].size;
340 /* Parse all entries looking for a match. */
342 entry = (acpi_table_entry_header *)
343 ((unsigned long) madt + madt_size);
345 while (((unsigned long) entry) < madt_end) {
346 if (entry->type == entry_id) {
350 entry = (acpi_table_entry_header *)
351 ((unsigned long) entry + entry->length);
359 acpi_table_parse_madt (
360 enum acpi_madt_entry_id id,
361 acpi_madt_entry_handler handler)
363 return acpi_table_parse_madt_family(ACPI_APIC, sizeof(struct acpi_table_madt),
370 enum acpi_table_id id,
371 acpi_table_handler handler)
379 for (i = 0; i < sdt_count; i++) {
380 if (sdt_entry[i].id != id)
382 handler(sdt_entry[i].pa, sdt_entry[i].size);
392 struct acpi_table_rsdp *rsdp)
394 struct acpi_table_header *header = NULL;
395 unsigned int i, id = 0;
400 /* First check XSDT (but only on ACPI 2.0-compatible systems) */
402 if ((rsdp->revision >= 2) &&
403 (((struct acpi20_table_rsdp*)rsdp)->xsdt_address)) {
405 struct acpi_table_xsdt *mapped_xsdt = NULL;
407 sdt_pa = ((struct acpi20_table_rsdp*)rsdp)->xsdt_address;
409 /* map in just the header */
410 header = (struct acpi_table_header *)
411 __acpi_map_table(sdt_pa, sizeof(struct acpi_table_header));
414 printk(KERN_WARNING PREFIX "Unable to map XSDT header\n");
418 /* remap in the entire table before processing */
419 mapped_xsdt = (struct acpi_table_xsdt *)
420 __acpi_map_table(sdt_pa, header->length);
422 printk(KERN_WARNING PREFIX "Unable to map XSDT\n");
425 header = &mapped_xsdt->header;
427 if (strncmp(header->signature, "XSDT", 4)) {
428 printk(KERN_WARNING PREFIX "XSDT signature incorrect\n");
432 if (acpi_table_compute_checksum(header, header->length)) {
433 printk(KERN_WARNING PREFIX "Invalid XSDT checksum\n");
437 sdt_count = (header->length - sizeof(struct acpi_table_header)) >> 3;
438 if (sdt_count > ACPI_MAX_TABLES) {
439 printk(KERN_WARNING PREFIX "Truncated %lu XSDT entries\n",
440 (sdt_count - ACPI_MAX_TABLES));
441 sdt_count = ACPI_MAX_TABLES;
444 for (i = 0; i < sdt_count; i++)
445 sdt_entry[i].pa = (unsigned long) mapped_xsdt->entry[i];
448 /* Then check RSDT */
450 else if (rsdp->rsdt_address) {
452 struct acpi_table_rsdt *mapped_rsdt = NULL;
454 sdt_pa = rsdp->rsdt_address;
456 /* map in just the header */
457 header = (struct acpi_table_header *)
458 __acpi_map_table(sdt_pa, sizeof(struct acpi_table_header));
460 printk(KERN_WARNING PREFIX "Unable to map RSDT header\n");
464 /* remap in the entire table before processing */
465 mapped_rsdt = (struct acpi_table_rsdt *)
466 __acpi_map_table(sdt_pa, header->length);
468 printk(KERN_WARNING PREFIX "Unable to map RSDT\n");
471 header = &mapped_rsdt->header;
473 if (strncmp(header->signature, "RSDT", 4)) {
474 printk(KERN_WARNING PREFIX "RSDT signature incorrect\n");
478 if (acpi_table_compute_checksum(header, header->length)) {
479 printk(KERN_WARNING PREFIX "Invalid RSDT checksum\n");
483 sdt_count = (header->length - sizeof(struct acpi_table_header)) >> 2;
484 if (sdt_count > ACPI_MAX_TABLES) {
485 printk(KERN_WARNING PREFIX "Truncated %lu RSDT entries\n",
486 (sdt_count - ACPI_MAX_TABLES));
487 sdt_count = ACPI_MAX_TABLES;
490 for (i = 0; i < sdt_count; i++)
491 sdt_entry[i].pa = (unsigned long) mapped_rsdt->entry[i];
495 printk(KERN_WARNING PREFIX "No System Description Table (RSDT/XSDT) specified in RSDP\n");
499 acpi_table_print(header, sdt_pa);
501 for (i = 0; i < sdt_count; i++) {
503 /* map in just the header */
504 header = (struct acpi_table_header *)
505 __acpi_map_table(sdt_entry[i].pa,
506 sizeof(struct acpi_table_header));
510 /* remap in the entire table before processing */
511 header = (struct acpi_table_header *)
512 __acpi_map_table(sdt_entry[i].pa,
517 acpi_table_print(header, sdt_entry[i].pa);
519 if (acpi_table_compute_checksum(header, header->length)) {
520 printk(KERN_WARNING " >>> ERROR: Invalid checksum\n");
524 sdt_entry[i].size = header->length;
526 for (id = 0; id < ACPI_TABLE_COUNT; id++) {
527 if (!strncmp((char *) &header->signature,
528 acpi_table_signatures[id],
529 sizeof(header->signature))) {
530 sdt_entry[i].id = id;
536 * The DSDT is *not* in the RSDT (why not? no idea.) but we want
537 * to print its info, because this is what people usually blacklist
538 * against. Unfortunately, we don't know the phys_addr, so just
539 * print 0. Maybe no one will notice.
541 if(!acpi_get_table_header_early(ACPI_DSDT, &header))
542 acpi_table_print(header, 0);
549 acpi_table_init (void)
551 struct acpi_table_rsdp *rsdp = NULL;
552 unsigned long rsdp_phys = 0;
555 /* Locate and map the Root System Description Table (RSDP) */
557 rsdp_phys = acpi_find_rsdp();
559 printk(KERN_ERR PREFIX "Unable to locate RSDP\n");
563 rsdp = (struct acpi_table_rsdp *) __va(rsdp_phys);
565 printk(KERN_WARNING PREFIX "Unable to map RSDP\n");
569 printk(KERN_INFO PREFIX "RSDP (v%3.3d %6.6s ) @ 0x%p\n",
570 rsdp->revision, rsdp->oem_id, (void *) rsdp_phys);
572 if (rsdp->revision < 2)
573 result = acpi_table_compute_checksum(rsdp, sizeof(struct acpi_table_rsdp));
575 result = acpi_table_compute_checksum(rsdp, ((struct acpi20_table_rsdp *)rsdp)->length);
578 printk(KERN_WARNING " >>> ERROR: Invalid checksum\n");
582 /* Locate and map the System Description table (RSDT/XSDT) */
584 if (acpi_table_get_sdt(rsdp))