blob: 962ff29fbf076ee4e842c5b50629d54e56ebd643 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/kernel.h>
28#include <linux/sched.h>
29#include <linux/smp.h>
30#include <linux/string.h>
31#include <linux/types.h>
32#include <linux/irq.h>
33#include <linux/errno.h>
34#include <linux/acpi.h>
35#include <linux/bootmem.h>
36
37#define PREFIX "ACPI: "
38
Len Brown04348e62005-12-30 02:44:59 -050039#define ACPI_MAX_TABLES 128
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Linus Torvalds1da177e2005-04-16 15:20:36 -070041static char *mps_inti_flags_polarity[] = { "dfl", "high", "res", "low" };
42static char *mps_inti_flags_trigger[] = { "dfl", "edge", "res", "level" };
43
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +030044static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES] __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Len Brown4be44fc2005-08-05 00:44:28 -040046void acpi_table_print_madt_entry(acpi_table_entry_header * header)
Linus Torvalds1da177e2005-04-16 15:20:36 -070047{
48 if (!header)
49 return;
50
51 switch (header->type) {
52
53 case ACPI_MADT_LAPIC:
Len Brown4be44fc2005-08-05 00:44:28 -040054 {
55 struct acpi_table_lapic *p =
56 (struct acpi_table_lapic *)header;
57 printk(KERN_INFO PREFIX
58 "LAPIC (acpi_id[0x%02x] lapic_id[0x%02x] %s)\n",
59 p->acpi_id, p->id,
60 p->flags.enabled ? "enabled" : "disabled");
61 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 break;
63
64 case ACPI_MADT_IOAPIC:
Len Brown4be44fc2005-08-05 00:44:28 -040065 {
66 struct acpi_table_ioapic *p =
67 (struct acpi_table_ioapic *)header;
68 printk(KERN_INFO PREFIX
69 "IOAPIC (id[0x%02x] address[0x%08x] gsi_base[%d])\n",
70 p->id, p->address, p->global_irq_base);
71 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 break;
73
74 case ACPI_MADT_INT_SRC_OVR:
Len Brown4be44fc2005-08-05 00:44:28 -040075 {
76 struct acpi_table_int_src_ovr *p =
77 (struct acpi_table_int_src_ovr *)header;
78 printk(KERN_INFO PREFIX
79 "INT_SRC_OVR (bus %d bus_irq %d global_irq %d %s %s)\n",
80 p->bus, p->bus_irq, p->global_irq,
81 mps_inti_flags_polarity[p->flags.polarity],
82 mps_inti_flags_trigger[p->flags.trigger]);
83 if (p->flags.reserved)
84 printk(KERN_INFO PREFIX
85 "INT_SRC_OVR unexpected reserved flags: 0x%x\n",
86 p->flags.reserved);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Len Brown4be44fc2005-08-05 00:44:28 -040088 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 break;
90
91 case ACPI_MADT_NMI_SRC:
Len Brown4be44fc2005-08-05 00:44:28 -040092 {
93 struct acpi_table_nmi_src *p =
94 (struct acpi_table_nmi_src *)header;
95 printk(KERN_INFO PREFIX
96 "NMI_SRC (%s %s global_irq %d)\n",
97 mps_inti_flags_polarity[p->flags.polarity],
98 mps_inti_flags_trigger[p->flags.trigger],
99 p->global_irq);
100 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 break;
102
103 case ACPI_MADT_LAPIC_NMI:
Len Brown4be44fc2005-08-05 00:44:28 -0400104 {
105 struct acpi_table_lapic_nmi *p =
106 (struct acpi_table_lapic_nmi *)header;
107 printk(KERN_INFO PREFIX
108 "LAPIC_NMI (acpi_id[0x%02x] %s %s lint[0x%x])\n",
109 p->acpi_id,
110 mps_inti_flags_polarity[p->flags.polarity],
111 mps_inti_flags_trigger[p->flags.trigger],
112 p->lint);
113 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 break;
115
116 case ACPI_MADT_LAPIC_ADDR_OVR:
Len Brown4be44fc2005-08-05 00:44:28 -0400117 {
118 struct acpi_table_lapic_addr_ovr *p =
119 (struct acpi_table_lapic_addr_ovr *)header;
120 printk(KERN_INFO PREFIX
121 "LAPIC_ADDR_OVR (address[%p])\n",
122 (void *)(unsigned long)p->address);
123 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 break;
125
126 case ACPI_MADT_IOSAPIC:
Len Brown4be44fc2005-08-05 00:44:28 -0400127 {
128 struct acpi_table_iosapic *p =
129 (struct acpi_table_iosapic *)header;
130 printk(KERN_INFO PREFIX
131 "IOSAPIC (id[0x%x] address[%p] gsi_base[%d])\n",
132 p->id, (void *)(unsigned long)p->address,
133 p->global_irq_base);
134 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 break;
136
137 case ACPI_MADT_LSAPIC:
Len Brown4be44fc2005-08-05 00:44:28 -0400138 {
139 struct acpi_table_lsapic *p =
140 (struct acpi_table_lsapic *)header;
141 printk(KERN_INFO PREFIX
142 "LSAPIC (acpi_id[0x%02x] lsapic_id[0x%02x] lsapic_eid[0x%02x] %s)\n",
143 p->acpi_id, p->id, p->eid,
144 p->flags.enabled ? "enabled" : "disabled");
145 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 break;
147
148 case ACPI_MADT_PLAT_INT_SRC:
Len Brown4be44fc2005-08-05 00:44:28 -0400149 {
150 struct acpi_table_plat_int_src *p =
151 (struct acpi_table_plat_int_src *)header;
152 printk(KERN_INFO PREFIX
153 "PLAT_INT_SRC (%s %s type[0x%x] id[0x%04x] eid[0x%x] iosapic_vector[0x%x] global_irq[0x%x]\n",
154 mps_inti_flags_polarity[p->flags.polarity],
155 mps_inti_flags_trigger[p->flags.trigger],
156 p->type, p->id, p->eid, p->iosapic_vector,
157 p->global_irq);
158 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 break;
160
161 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400162 printk(KERN_WARNING PREFIX
163 "Found unsupported MADT entry (type = 0x%x)\n",
164 header->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 break;
166 }
167}
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170int __init
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300171acpi_table_parse_madt_family(char *id,
Len Brown4be44fc2005-08-05 00:44:28 -0400172 unsigned long madt_size,
173 int entry_id,
174 acpi_madt_entry_handler handler,
175 unsigned int max_entries)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176{
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300177 struct acpi_table_header *madt = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400178 acpi_table_entry_header *entry;
179 unsigned int count = 0;
180 unsigned long madt_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
182 if (!handler)
183 return -EINVAL;
184
185 /* Locate the MADT (if exists). There should only be one. */
186
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300187 acpi_get_table(id, 0, &madt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189 if (!madt) {
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300190 printk(KERN_WARNING PREFIX "%4.4s not present\n", id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 return -ENODEV;
192 }
193
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300194 madt_end = (unsigned long)madt + madt->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
196 /* Parse all entries looking for a match. */
197
198 entry = (acpi_table_entry_header *)
Len Brown4be44fc2005-08-05 00:44:28 -0400199 ((unsigned long)madt + madt_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Len Brown4be44fc2005-08-05 00:44:28 -0400201 while (((unsigned long)entry) + sizeof(acpi_table_entry_header) <
202 madt_end) {
203 if (entry->type == entry_id
204 && (!max_entries || count++ < max_entries))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 if (handler(entry, madt_end))
206 return -EINVAL;
207
208 entry = (acpi_table_entry_header *)
Len Brown4be44fc2005-08-05 00:44:28 -0400209 ((unsigned long)entry + entry->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 }
211 if (max_entries && count > max_entries) {
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300212 printk(KERN_WARNING PREFIX "[%4.4s:0x%02x] ignored %i entries of "
213 "%i found\n", id, entry_id, count - max_entries, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 }
215
216 return count;
217}
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219int __init
Len Brown4be44fc2005-08-05 00:44:28 -0400220acpi_table_parse_madt(enum acpi_madt_entry_id id,
221 acpi_madt_entry_handler handler, unsigned int max_entries)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300223 return acpi_table_parse_madt_family("APIC",
Len Brown4be44fc2005-08-05 00:44:28 -0400224 sizeof(struct acpi_table_madt), id,
225 handler, max_entries);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226}
227
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300228int __init acpi_table_parse(char *id, acpi_table_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300230 struct acpi_table_header *table = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 if (!handler)
233 return -EINVAL;
234
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300235 acpi_get_table(id, 0, &table);
236 if (table) {
237 handler(table);
238 return 1;
239 } else
240 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241}
242
243/*
244 * acpi_table_init()
245 *
246 * find RSDP, find and checksum SDT/XSDT.
247 * checksum all tables, print SDT/XSDT
248 *
249 * result: sdt_entry[] is initialized
250 */
251
Len Brown4be44fc2005-08-05 00:44:28 -0400252int __init acpi_table_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300254 acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 return 0;
256}