blob: a2bf25b05e1c08156d77571505e162c51fbc7075 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * acpi_tables.c - ACPI Boot-Time Table Parsing
3 *
4 * Copyright (C) 2001 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
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.
12 *
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.
17 *
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
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 *
24 */
25
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>
37
38#define PREFIX "ACPI: "
39
40#define ACPI_MAX_TABLES 256
41
42static char *acpi_table_signatures[ACPI_TABLE_COUNT] = {
Len Brown4be44fc2005-08-05 00:44:28 -040043 [ACPI_TABLE_UNKNOWN] = "????",
44 [ACPI_APIC] = "APIC",
45 [ACPI_BOOT] = "BOOT",
46 [ACPI_DBGP] = "DBGP",
47 [ACPI_DSDT] = "DSDT",
48 [ACPI_ECDT] = "ECDT",
49 [ACPI_ETDT] = "ETDT",
50 [ACPI_FADT] = "FACP",
51 [ACPI_FACS] = "FACS",
52 [ACPI_OEMX] = "OEM",
53 [ACPI_PSDT] = "PSDT",
54 [ACPI_SBST] = "SBST",
55 [ACPI_SLIT] = "SLIT",
56 [ACPI_SPCR] = "SPCR",
57 [ACPI_SRAT] = "SRAT",
58 [ACPI_SSDT] = "SSDT",
59 [ACPI_SPMI] = "SPMI",
60 [ACPI_HPET] = "HPET",
61 [ACPI_MCFG] = "MCFG",
Linus Torvalds1da177e2005-04-16 15:20:36 -070062};
63
64static char *mps_inti_flags_polarity[] = { "dfl", "high", "res", "low" };
65static char *mps_inti_flags_trigger[] = { "dfl", "edge", "res", "level" };
66
67/* System Description Table (RSDT/XSDT) */
68struct acpi_table_sdt {
Len Brown4be44fc2005-08-05 00:44:28 -040069 unsigned long pa;
70 enum acpi_table_id id;
71 unsigned long size;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072} __attribute__ ((packed));
73
Len Brown4be44fc2005-08-05 00:44:28 -040074static unsigned long sdt_pa; /* Physical Address */
75static unsigned long sdt_count; /* Table count */
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Len Brown4be44fc2005-08-05 00:44:28 -040077static struct acpi_table_sdt sdt_entry[ACPI_MAX_TABLES];
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Len Brown4be44fc2005-08-05 00:44:28 -040079void acpi_table_print(struct acpi_table_header *header, unsigned long phys_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
Len Brown4be44fc2005-08-05 00:44:28 -040081 char *name = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83 if (!header)
84 return;
85
86 /* Some table signatures aren't good table names */
87
Len Brown4be44fc2005-08-05 00:44:28 -040088 if (!strncmp((char *)&header->signature,
89 acpi_table_signatures[ACPI_APIC],
90 sizeof(header->signature))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 name = "MADT";
Len Brown4be44fc2005-08-05 00:44:28 -040092 } else if (!strncmp((char *)&header->signature,
93 acpi_table_signatures[ACPI_FADT],
94 sizeof(header->signature))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 name = "FADT";
Len Brown4be44fc2005-08-05 00:44:28 -040096 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 name = header->signature;
98
Len Brown4be44fc2005-08-05 00:44:28 -040099 printk(KERN_DEBUG PREFIX
100 "%.4s (v%3.3d %6.6s %8.8s 0x%08x %.4s 0x%08x) @ 0x%p\n", name,
101 header->revision, header->oem_id, header->oem_table_id,
102 header->oem_revision, header->asl_compiler_id,
103 header->asl_compiler_revision, (void *)phys_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
105
Len Brown4be44fc2005-08-05 00:44:28 -0400106void acpi_table_print_madt_entry(acpi_table_entry_header * header)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
108 if (!header)
109 return;
110
111 switch (header->type) {
112
113 case ACPI_MADT_LAPIC:
Len Brown4be44fc2005-08-05 00:44:28 -0400114 {
115 struct acpi_table_lapic *p =
116 (struct acpi_table_lapic *)header;
117 printk(KERN_INFO PREFIX
118 "LAPIC (acpi_id[0x%02x] lapic_id[0x%02x] %s)\n",
119 p->acpi_id, p->id,
120 p->flags.enabled ? "enabled" : "disabled");
121 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 break;
123
124 case ACPI_MADT_IOAPIC:
Len Brown4be44fc2005-08-05 00:44:28 -0400125 {
126 struct acpi_table_ioapic *p =
127 (struct acpi_table_ioapic *)header;
128 printk(KERN_INFO PREFIX
129 "IOAPIC (id[0x%02x] address[0x%08x] gsi_base[%d])\n",
130 p->id, p->address, p->global_irq_base);
131 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 break;
133
134 case ACPI_MADT_INT_SRC_OVR:
Len Brown4be44fc2005-08-05 00:44:28 -0400135 {
136 struct acpi_table_int_src_ovr *p =
137 (struct acpi_table_int_src_ovr *)header;
138 printk(KERN_INFO PREFIX
139 "INT_SRC_OVR (bus %d bus_irq %d global_irq %d %s %s)\n",
140 p->bus, p->bus_irq, p->global_irq,
141 mps_inti_flags_polarity[p->flags.polarity],
142 mps_inti_flags_trigger[p->flags.trigger]);
143 if (p->flags.reserved)
144 printk(KERN_INFO PREFIX
145 "INT_SRC_OVR unexpected reserved flags: 0x%x\n",
146 p->flags.reserved);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Len Brown4be44fc2005-08-05 00:44:28 -0400148 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 break;
150
151 case ACPI_MADT_NMI_SRC:
Len Brown4be44fc2005-08-05 00:44:28 -0400152 {
153 struct acpi_table_nmi_src *p =
154 (struct acpi_table_nmi_src *)header;
155 printk(KERN_INFO PREFIX
156 "NMI_SRC (%s %s global_irq %d)\n",
157 mps_inti_flags_polarity[p->flags.polarity],
158 mps_inti_flags_trigger[p->flags.trigger],
159 p->global_irq);
160 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 break;
162
163 case ACPI_MADT_LAPIC_NMI:
Len Brown4be44fc2005-08-05 00:44:28 -0400164 {
165 struct acpi_table_lapic_nmi *p =
166 (struct acpi_table_lapic_nmi *)header;
167 printk(KERN_INFO PREFIX
168 "LAPIC_NMI (acpi_id[0x%02x] %s %s lint[0x%x])\n",
169 p->acpi_id,
170 mps_inti_flags_polarity[p->flags.polarity],
171 mps_inti_flags_trigger[p->flags.trigger],
172 p->lint);
173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 break;
175
176 case ACPI_MADT_LAPIC_ADDR_OVR:
Len Brown4be44fc2005-08-05 00:44:28 -0400177 {
178 struct acpi_table_lapic_addr_ovr *p =
179 (struct acpi_table_lapic_addr_ovr *)header;
180 printk(KERN_INFO PREFIX
181 "LAPIC_ADDR_OVR (address[%p])\n",
182 (void *)(unsigned long)p->address);
183 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 break;
185
186 case ACPI_MADT_IOSAPIC:
Len Brown4be44fc2005-08-05 00:44:28 -0400187 {
188 struct acpi_table_iosapic *p =
189 (struct acpi_table_iosapic *)header;
190 printk(KERN_INFO PREFIX
191 "IOSAPIC (id[0x%x] address[%p] gsi_base[%d])\n",
192 p->id, (void *)(unsigned long)p->address,
193 p->global_irq_base);
194 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 break;
196
197 case ACPI_MADT_LSAPIC:
Len Brown4be44fc2005-08-05 00:44:28 -0400198 {
199 struct acpi_table_lsapic *p =
200 (struct acpi_table_lsapic *)header;
201 printk(KERN_INFO PREFIX
202 "LSAPIC (acpi_id[0x%02x] lsapic_id[0x%02x] lsapic_eid[0x%02x] %s)\n",
203 p->acpi_id, p->id, p->eid,
204 p->flags.enabled ? "enabled" : "disabled");
205 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 break;
207
208 case ACPI_MADT_PLAT_INT_SRC:
Len Brown4be44fc2005-08-05 00:44:28 -0400209 {
210 struct acpi_table_plat_int_src *p =
211 (struct acpi_table_plat_int_src *)header;
212 printk(KERN_INFO PREFIX
213 "PLAT_INT_SRC (%s %s type[0x%x] id[0x%04x] eid[0x%x] iosapic_vector[0x%x] global_irq[0x%x]\n",
214 mps_inti_flags_polarity[p->flags.polarity],
215 mps_inti_flags_trigger[p->flags.trigger],
216 p->type, p->id, p->eid, p->iosapic_vector,
217 p->global_irq);
218 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 break;
220
221 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400222 printk(KERN_WARNING PREFIX
223 "Found unsupported MADT entry (type = 0x%x)\n",
224 header->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 break;
226 }
227}
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229static int
Len Brown4be44fc2005-08-05 00:44:28 -0400230acpi_table_compute_checksum(void *table_pointer, unsigned long length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
Len Brown4be44fc2005-08-05 00:44:28 -0400232 u8 *p = (u8 *) table_pointer;
233 unsigned long remains = length;
234 unsigned long sum = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
236 if (!p || !length)
237 return -EINVAL;
238
239 while (remains--)
240 sum += *p++;
241
242 return (sum & 0xFF);
243}
244
245/*
246 * acpi_get_table_header_early()
247 * for acpi_blacklisted(), acpi_table_get_sdt()
248 */
249int __init
Len Brown4be44fc2005-08-05 00:44:28 -0400250acpi_get_table_header_early(enum acpi_table_id id,
251 struct acpi_table_header **header)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
253 unsigned int i;
254 enum acpi_table_id temp_id;
255
256 /* DSDT is different from the rest */
257 if (id == ACPI_DSDT)
258 temp_id = ACPI_FADT;
259 else
260 temp_id = id;
261
262 /* Locate the table. */
263
264 for (i = 0; i < sdt_count; i++) {
265 if (sdt_entry[i].id != temp_id)
266 continue;
267 *header = (void *)
Len Brown4be44fc2005-08-05 00:44:28 -0400268 __acpi_map_table(sdt_entry[i].pa, sdt_entry[i].size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 if (!*header) {
270 printk(KERN_WARNING PREFIX "Unable to map %s\n",
271 acpi_table_signatures[temp_id]);
272 return -ENODEV;
273 }
274 break;
275 }
276
277 if (!*header) {
278 printk(KERN_WARNING PREFIX "%s not present\n",
279 acpi_table_signatures[id]);
280 return -ENODEV;
281 }
282
283 /* Map the DSDT header via the pointer in the FADT */
284 if (id == ACPI_DSDT) {
Len Brown4be44fc2005-08-05 00:44:28 -0400285 struct fadt_descriptor_rev2 *fadt =
286 (struct fadt_descriptor_rev2 *)*header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288 if (fadt->revision == 3 && fadt->Xdsdt) {
Len Brown4be44fc2005-08-05 00:44:28 -0400289 *header = (void *)__acpi_map_table(fadt->Xdsdt,
290 sizeof(struct
291 acpi_table_header));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 } else if (fadt->V1_dsdt) {
Len Brown4be44fc2005-08-05 00:44:28 -0400293 *header = (void *)__acpi_map_table(fadt->V1_dsdt,
294 sizeof(struct
295 acpi_table_header));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 } else
297 *header = NULL;
298
299 if (!*header) {
300 printk(KERN_WARNING PREFIX "Unable to map DSDT\n");
301 return -ENODEV;
302 }
303 }
304
305 return 0;
306}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308int __init
Len Brown4be44fc2005-08-05 00:44:28 -0400309acpi_table_parse_madt_family(enum acpi_table_id id,
310 unsigned long madt_size,
311 int entry_id,
312 acpi_madt_entry_handler handler,
313 unsigned int max_entries)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
Len Brown4be44fc2005-08-05 00:44:28 -0400315 void *madt = NULL;
316 acpi_table_entry_header *entry;
317 unsigned int count = 0;
318 unsigned long madt_end;
319 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321 if (!handler)
322 return -EINVAL;
323
324 /* Locate the MADT (if exists). There should only be one. */
325
326 for (i = 0; i < sdt_count; i++) {
327 if (sdt_entry[i].id != id)
328 continue;
329 madt = (void *)
Len Brown4be44fc2005-08-05 00:44:28 -0400330 __acpi_map_table(sdt_entry[i].pa, sdt_entry[i].size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 if (!madt) {
332 printk(KERN_WARNING PREFIX "Unable to map %s\n",
333 acpi_table_signatures[id]);
334 return -ENODEV;
335 }
336 break;
337 }
338
339 if (!madt) {
340 printk(KERN_WARNING PREFIX "%s not present\n",
341 acpi_table_signatures[id]);
342 return -ENODEV;
343 }
344
Len Brown4be44fc2005-08-05 00:44:28 -0400345 madt_end = (unsigned long)madt + sdt_entry[i].size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 /* Parse all entries looking for a match. */
348
349 entry = (acpi_table_entry_header *)
Len Brown4be44fc2005-08-05 00:44:28 -0400350 ((unsigned long)madt + madt_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Len Brown4be44fc2005-08-05 00:44:28 -0400352 while (((unsigned long)entry) + sizeof(acpi_table_entry_header) <
353 madt_end) {
354 if (entry->type == entry_id
355 && (!max_entries || count++ < max_entries))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 if (handler(entry, madt_end))
357 return -EINVAL;
358
359 entry = (acpi_table_entry_header *)
Len Brown4be44fc2005-08-05 00:44:28 -0400360 ((unsigned long)entry + entry->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
362 if (max_entries && count > max_entries) {
363 printk(KERN_WARNING PREFIX "[%s:0x%02x] ignored %i entries of "
364 "%i found\n", acpi_table_signatures[id], entry_id,
365 count - max_entries, count);
366 }
367
368 return count;
369}
370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371int __init
Len Brown4be44fc2005-08-05 00:44:28 -0400372acpi_table_parse_madt(enum acpi_madt_entry_id id,
373 acpi_madt_entry_handler handler, unsigned int max_entries)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374{
Len Brown4be44fc2005-08-05 00:44:28 -0400375 return acpi_table_parse_madt_family(ACPI_APIC,
376 sizeof(struct acpi_table_madt), id,
377 handler, max_entries);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378}
379
Len Brown4be44fc2005-08-05 00:44:28 -0400380int __init acpi_table_parse(enum acpi_table_id id, acpi_table_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381{
Len Brown4be44fc2005-08-05 00:44:28 -0400382 int count = 0;
383 unsigned int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385 if (!handler)
386 return -EINVAL;
387
388 for (i = 0; i < sdt_count; i++) {
389 if (sdt_entry[i].id != id)
390 continue;
391 count++;
392 if (count == 1)
393 handler(sdt_entry[i].pa, sdt_entry[i].size);
394
395 else
Len Brown4be44fc2005-08-05 00:44:28 -0400396 printk(KERN_WARNING PREFIX
397 "%d duplicate %s table ignored.\n", count,
398 acpi_table_signatures[id]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 }
400
401 return count;
402}
403
Len Brown4be44fc2005-08-05 00:44:28 -0400404static int __init acpi_table_get_sdt(struct acpi_table_rsdp *rsdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405{
406 struct acpi_table_header *header = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400407 unsigned int i, id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 if (!rsdp)
410 return -EINVAL;
411
412 /* First check XSDT (but only on ACPI 2.0-compatible systems) */
413
414 if ((rsdp->revision >= 2) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400415 (((struct acpi20_table_rsdp *)rsdp)->xsdt_address)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Len Brown4be44fc2005-08-05 00:44:28 -0400417 struct acpi_table_xsdt *mapped_xsdt = NULL;
418
419 sdt_pa = ((struct acpi20_table_rsdp *)rsdp)->xsdt_address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
421 /* map in just the header */
422 header = (struct acpi_table_header *)
Len Brown4be44fc2005-08-05 00:44:28 -0400423 __acpi_map_table(sdt_pa, sizeof(struct acpi_table_header));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
425 if (!header) {
Len Brown4be44fc2005-08-05 00:44:28 -0400426 printk(KERN_WARNING PREFIX
427 "Unable to map XSDT header\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 return -ENODEV;
429 }
430
431 /* remap in the entire table before processing */
432 mapped_xsdt = (struct acpi_table_xsdt *)
Len Brown4be44fc2005-08-05 00:44:28 -0400433 __acpi_map_table(sdt_pa, header->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 if (!mapped_xsdt) {
435 printk(KERN_WARNING PREFIX "Unable to map XSDT\n");
436 return -ENODEV;
437 }
438 header = &mapped_xsdt->header;
439
440 if (strncmp(header->signature, "XSDT", 4)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400441 printk(KERN_WARNING PREFIX
442 "XSDT signature incorrect\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 return -ENODEV;
444 }
445
446 if (acpi_table_compute_checksum(header, header->length)) {
447 printk(KERN_WARNING PREFIX "Invalid XSDT checksum\n");
448 return -ENODEV;
449 }
450
Len Brown4be44fc2005-08-05 00:44:28 -0400451 sdt_count =
452 (header->length - sizeof(struct acpi_table_header)) >> 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 if (sdt_count > ACPI_MAX_TABLES) {
Len Brown4be44fc2005-08-05 00:44:28 -0400454 printk(KERN_WARNING PREFIX
455 "Truncated %lu XSDT entries\n",
456 (sdt_count - ACPI_MAX_TABLES));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 sdt_count = ACPI_MAX_TABLES;
458 }
459
460 for (i = 0; i < sdt_count; i++)
Len Brown4be44fc2005-08-05 00:44:28 -0400461 sdt_entry[i].pa = (unsigned long)mapped_xsdt->entry[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 }
463
464 /* Then check RSDT */
465
466 else if (rsdp->rsdt_address) {
467
Len Brown4be44fc2005-08-05 00:44:28 -0400468 struct acpi_table_rsdt *mapped_rsdt = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
470 sdt_pa = rsdp->rsdt_address;
471
472 /* map in just the header */
473 header = (struct acpi_table_header *)
Len Brown4be44fc2005-08-05 00:44:28 -0400474 __acpi_map_table(sdt_pa, sizeof(struct acpi_table_header));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 if (!header) {
Len Brown4be44fc2005-08-05 00:44:28 -0400476 printk(KERN_WARNING PREFIX
477 "Unable to map RSDT header\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 return -ENODEV;
479 }
480
481 /* remap in the entire table before processing */
482 mapped_rsdt = (struct acpi_table_rsdt *)
Len Brown4be44fc2005-08-05 00:44:28 -0400483 __acpi_map_table(sdt_pa, header->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 if (!mapped_rsdt) {
485 printk(KERN_WARNING PREFIX "Unable to map RSDT\n");
486 return -ENODEV;
487 }
488 header = &mapped_rsdt->header;
489
490 if (strncmp(header->signature, "RSDT", 4)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400491 printk(KERN_WARNING PREFIX
492 "RSDT signature incorrect\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 return -ENODEV;
494 }
495
496 if (acpi_table_compute_checksum(header, header->length)) {
497 printk(KERN_WARNING PREFIX "Invalid RSDT checksum\n");
498 return -ENODEV;
499 }
500
Len Brown4be44fc2005-08-05 00:44:28 -0400501 sdt_count =
502 (header->length - sizeof(struct acpi_table_header)) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 if (sdt_count > ACPI_MAX_TABLES) {
Len Brown4be44fc2005-08-05 00:44:28 -0400504 printk(KERN_WARNING PREFIX
505 "Truncated %lu RSDT entries\n",
506 (sdt_count - ACPI_MAX_TABLES));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 sdt_count = ACPI_MAX_TABLES;
508 }
509
510 for (i = 0; i < sdt_count; i++)
Len Brown4be44fc2005-08-05 00:44:28 -0400511 sdt_entry[i].pa = (unsigned long)mapped_rsdt->entry[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 }
513
514 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400515 printk(KERN_WARNING PREFIX
516 "No System Description Table (RSDT/XSDT) specified in RSDP\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 return -ENODEV;
518 }
519
520 acpi_table_print(header, sdt_pa);
521
522 for (i = 0; i < sdt_count; i++) {
523
524 /* map in just the header */
525 header = (struct acpi_table_header *)
Len Brown4be44fc2005-08-05 00:44:28 -0400526 __acpi_map_table(sdt_entry[i].pa,
527 sizeof(struct acpi_table_header));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 if (!header)
529 continue;
530
531 /* remap in the entire table before processing */
532 header = (struct acpi_table_header *)
Len Brown4be44fc2005-08-05 00:44:28 -0400533 __acpi_map_table(sdt_entry[i].pa, header->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 if (!header)
535 continue;
Len Brown4be44fc2005-08-05 00:44:28 -0400536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 acpi_table_print(header, sdt_entry[i].pa);
538
539 if (acpi_table_compute_checksum(header, header->length)) {
540 printk(KERN_WARNING " >>> ERROR: Invalid checksum\n");
541 continue;
542 }
543
544 sdt_entry[i].size = header->length;
545
546 for (id = 0; id < ACPI_TABLE_COUNT; id++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400547 if (!strncmp((char *)&header->signature,
548 acpi_table_signatures[id],
549 sizeof(header->signature))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 sdt_entry[i].id = id;
551 }
552 }
553 }
554
555 /*
556 * The DSDT is *not* in the RSDT (why not? no idea.) but we want
557 * to print its info, because this is what people usually blacklist
558 * against. Unfortunately, we don't know the phys_addr, so just
559 * print 0. Maybe no one will notice.
560 */
Len Brown4be44fc2005-08-05 00:44:28 -0400561 if (!acpi_get_table_header_early(ACPI_DSDT, &header))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 acpi_table_print(header, 0);
563
564 return 0;
565}
566
567/*
568 * acpi_table_init()
569 *
570 * find RSDP, find and checksum SDT/XSDT.
571 * checksum all tables, print SDT/XSDT
572 *
573 * result: sdt_entry[] is initialized
574 */
575
Len Brown4be44fc2005-08-05 00:44:28 -0400576int __init acpi_table_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577{
Len Brown4be44fc2005-08-05 00:44:28 -0400578 struct acpi_table_rsdp *rsdp = NULL;
579 unsigned long rsdp_phys = 0;
580 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
582 /* Locate and map the Root System Description Table (RSDP) */
583
584 rsdp_phys = acpi_find_rsdp();
585 if (!rsdp_phys) {
586 printk(KERN_ERR PREFIX "Unable to locate RSDP\n");
587 return -ENODEV;
588 }
589
Len Brown4be44fc2005-08-05 00:44:28 -0400590 rsdp = (struct acpi_table_rsdp *)__va(rsdp_phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 if (!rsdp) {
592 printk(KERN_WARNING PREFIX "Unable to map RSDP\n");
593 return -ENODEV;
594 }
595
Len Brown4be44fc2005-08-05 00:44:28 -0400596 printk(KERN_DEBUG PREFIX
597 "RSDP (v%3.3d %6.6s ) @ 0x%p\n",
598 rsdp->revision, rsdp->oem_id, (void *)rsdp_phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
600 if (rsdp->revision < 2)
Len Brown4be44fc2005-08-05 00:44:28 -0400601 result =
602 acpi_table_compute_checksum(rsdp,
603 sizeof(struct acpi_table_rsdp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 else
Len Brown4be44fc2005-08-05 00:44:28 -0400605 result =
606 acpi_table_compute_checksum(rsdp,
607 ((struct acpi20_table_rsdp *)
608 rsdp)->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
610 if (result) {
611 printk(KERN_WARNING " >>> ERROR: Invalid checksum\n");
612 return -ENODEV;
613 }
614
615 /* Locate and map the System Description table (RSDT/XSDT) */
616
617 if (acpi_table_get_sdt(rsdp))
618 return -ENODEV;
619
620 return 0;
621}