ACPICA: Remove duplicate table manager
[linux-3.10.git] / drivers / acpi / tables.c
1 /*
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/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
39 #define ACPI_MAX_TABLES         128
40
41 static char *mps_inti_flags_polarity[] = { "dfl", "high", "res", "low" };
42 static char *mps_inti_flags_trigger[] = { "dfl", "edge", "res", "level" };
43
44 static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES] __initdata;
45
46 void acpi_table_print_madt_entry(acpi_table_entry_header * header)
47 {
48         if (!header)
49                 return;
50
51         switch (header->type) {
52
53         case ACPI_MADT_LAPIC:
54                 {
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                 }
62                 break;
63
64         case ACPI_MADT_IOAPIC:
65                 {
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                 }
72                 break;
73
74         case ACPI_MADT_INT_SRC_OVR:
75                 {
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);
87
88                 }
89                 break;
90
91         case ACPI_MADT_NMI_SRC:
92                 {
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                 }
101                 break;
102
103         case ACPI_MADT_LAPIC_NMI:
104                 {
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                 }
114                 break;
115
116         case ACPI_MADT_LAPIC_ADDR_OVR:
117                 {
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                 }
124                 break;
125
126         case ACPI_MADT_IOSAPIC:
127                 {
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                 }
135                 break;
136
137         case ACPI_MADT_LSAPIC:
138                 {
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                 }
146                 break;
147
148         case ACPI_MADT_PLAT_INT_SRC:
149                 {
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                 }
159                 break;
160
161         default:
162                 printk(KERN_WARNING PREFIX
163                        "Found unsupported MADT entry (type = 0x%x)\n",
164                        header->type);
165                 break;
166         }
167 }
168
169
170 int __init
171 acpi_table_parse_madt_family(char *id,
172                              unsigned long madt_size,
173                              int entry_id,
174                              acpi_madt_entry_handler handler,
175                              unsigned int max_entries)
176 {
177         struct acpi_table_header *madt = NULL;
178         acpi_table_entry_header *entry;
179         unsigned int count = 0;
180         unsigned long madt_end;
181
182         if (!handler)
183                 return -EINVAL;
184
185         /* Locate the MADT (if exists). There should only be one. */
186
187         acpi_get_table(id, 0, &madt);
188
189         if (!madt) {
190                 printk(KERN_WARNING PREFIX "%4.4s not present\n", id);
191                 return -ENODEV;
192         }
193
194         madt_end = (unsigned long)madt + madt->length;
195
196         /* Parse all entries looking for a match. */
197
198         entry = (acpi_table_entry_header *)
199             ((unsigned long)madt + madt_size);
200
201         while (((unsigned long)entry) + sizeof(acpi_table_entry_header) <
202                madt_end) {
203                 if (entry->type == entry_id
204                     && (!max_entries || count++ < max_entries))
205                         if (handler(entry, madt_end))
206                                 return -EINVAL;
207
208                 entry = (acpi_table_entry_header *)
209                     ((unsigned long)entry + entry->length);
210         }
211         if (max_entries && count > max_entries) {
212                 printk(KERN_WARNING PREFIX "[%4.4s:0x%02x] ignored %i entries of "
213                        "%i found\n", id, entry_id, count - max_entries, count);
214         }
215
216         return count;
217 }
218
219 int __init
220 acpi_table_parse_madt(enum acpi_madt_entry_id id,
221                       acpi_madt_entry_handler handler, unsigned int max_entries)
222 {
223         return acpi_table_parse_madt_family("APIC",
224                                             sizeof(struct acpi_table_madt), id,
225                                             handler, max_entries);
226 }
227
228 int __init acpi_table_parse(char *id, acpi_table_handler handler)
229 {
230         struct acpi_table_header *table = NULL;
231
232         if (!handler)
233                 return -EINVAL;
234
235         acpi_get_table(id, 0, &table);
236         if (table) {
237                 handler(table);
238                 return 1;
239         } else
240                 return 0;
241 }
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
252 int __init acpi_table_init(void)
253 {
254         acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
255         return 0;
256 }