blob: d4acedf07866ef8c2d704816236b1e491016ae77 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * boot.c - Architecture-Specific Low-Level ACPI Boot Support
3 *
4 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
5 * Copyright (C) 2001 Jun Nakajima <jun.nakajima@intel.com>
6 *
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 */
25
26#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/acpi.h>
Thomas Gleixnerd66bea52007-02-16 01:27:57 -080028#include <linux/acpi_pmtmr.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/efi.h>
Ashok Raj73fea172006-09-26 10:52:35 +020030#include <linux/cpumask.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/module.h>
Andrey Paninaea00142005-06-25 14:54:42 -070032#include <linux/dmi.h>
Nick Pigginb33fa1f2005-10-01 02:34:42 +100033#include <linux/irq.h>
adurbin@google.comf0f4c342006-09-26 10:52:39 +020034#include <linux/bootmem.h>
35#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#include <asm/pgtable.h>
38#include <asm/io_apic.h>
39#include <asm/apic.h>
40#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <asm/mpspec.h>
Alexey Starikovskiydfac2182008-04-04 23:41:50 +040042#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Adrian Bunke8924ac2006-09-26 10:52:35 +020044static int __initdata acpi_force = 0;
Zhao Yakui237889b2008-12-17 16:55:18 +080045u32 acpi_rsdt_forced;
Len Brownc636f752009-05-19 23:47:38 -040046int acpi_disabled;
Andi Kleendf3bb572006-09-26 10:52:33 +020047EXPORT_SYMBOL(acpi_disabled);
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#ifdef CONFIG_X86_64
Ingo Molnar1dcdd3d2009-01-28 17:55:37 +010050# include <asm/proto.h>
Len Brown4be44fc2005-08-05 00:44:28 -040051#endif /* X86 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#define BAD_MADT_ENTRY(entry, end) ( \
54 (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +030055 ((struct acpi_subtable_header *)entry)->length < sizeof(*entry))
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57#define PREFIX "ACPI: "
58
Andrew Morton90d53902006-11-02 22:07:18 -080059int acpi_noirq; /* skip ACPI IRQ initialization */
Yinghai Lu6e4be1f2008-02-05 00:01:48 -080060int acpi_pci_disabled; /* skip ACPI PCI scan and IRQ initialization */
61EXPORT_SYMBOL(acpi_pci_disabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062int acpi_ht __initdata = 1; /* enable HT */
63
64int acpi_lapic;
65int acpi_ioapic;
66int acpi_strict;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +030068u8 acpi_sci_flags __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069int acpi_sci_override_gsi __initdata;
70int acpi_skip_timer_override __initdata;
Andi Kleenfa18f472006-11-14 16:57:46 +010071int acpi_use_timer_override __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73#ifdef CONFIG_X86_LOCAL_APIC
74static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
75#endif
76
77#ifndef __HAVE_ARCH_CMPXCHG
78#warning ACPI uses CMPXCHG, i486 and later hardware
79#endif
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081/* --------------------------------------------------------------------------
82 Boot-time Configuration
83 -------------------------------------------------------------------------- */
84
85/*
86 * The default interrupt routing model is PIC (8259). This gets
Simon Arlott27b46d72007-10-20 01:13:56 +020087 * overridden if IOAPICs are enumerated (below).
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 */
Len Brown4be44fc2005-08-05 00:44:28 -040089enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92/*
93 * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
94 * to map the target physical address. The problem is that set_fixmap()
95 * provides a single page, and it is possible that the page is not
96 * sufficient.
97 * By using this area, we can map up to MAX_IO_APICS pages temporarily,
98 * i.e. until the next __va_range() call.
99 *
100 * Important Safety Note: The fixed I/O APIC page numbers are *subtracted*
101 * from the fixed base. That's why we start at FIX_IO_APIC_BASE_END and
102 * count idx down while incrementing the phys address.
103 */
Jan Beulich2fdf0742007-12-13 08:33:59 +0000104char *__init __acpi_map_table(unsigned long phys, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Yinghai Luf34fa822008-07-09 20:16:36 -0700107 if (!phys || !size)
108 return NULL;
109
Yinghai Lu7d972772009-02-07 15:39:41 -0800110 return early_ioremap(phys, size);
111}
112void __init __acpi_unmap_table(char *map, unsigned long size)
113{
114 if (!map || !size)
115 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Yinghai Lu7d972772009-02-07 15:39:41 -0800117 early_iounmap(map, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120#ifdef CONFIG_PCI_MMCONFIG
Pavel Vasilyev1339c362008-10-15 17:33:48 -0400121
122static int acpi_mcfg_64bit_base_addr __initdata = FALSE;
123
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700124/* The physical address of the MMCONFIG aperture. Set from ACPI tables. */
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300125struct acpi_mcfg_allocation *pci_mmcfg_config;
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700126int pci_mmcfg_config_num;
127
John Kellera726c602008-07-29 14:34:16 -0500128static int __init acpi_mcfg_oem_check(struct acpi_table_mcfg *mcfg)
129{
130 if (!strcmp(mcfg->header.oem_id, "SGI"))
131 acpi_mcfg_64bit_base_addr = TRUE;
132
133 return 0;
134}
135
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300136int __init acpi_parse_mcfg(struct acpi_table_header *header)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
138 struct acpi_table_mcfg *mcfg;
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700139 unsigned long i;
140 int config_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300142 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 return -EINVAL;
144
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300145 mcfg = (struct acpi_table_mcfg *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700147 /* how many config structures do we have */
148 pci_mmcfg_config_num = 0;
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300149 i = header->length - sizeof(struct acpi_table_mcfg);
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300150 while (i >= sizeof(struct acpi_mcfg_allocation)) {
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700151 ++pci_mmcfg_config_num;
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300152 i -= sizeof(struct acpi_mcfg_allocation);
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700153 };
154 if (pci_mmcfg_config_num == 0) {
155 printk(KERN_ERR PREFIX "MMCONFIG has no entries\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 return -ENODEV;
157 }
158
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700159 config_size = pci_mmcfg_config_num * sizeof(*pci_mmcfg_config);
160 pci_mmcfg_config = kmalloc(config_size, GFP_KERNEL);
161 if (!pci_mmcfg_config) {
162 printk(KERN_WARNING PREFIX
163 "No memory for MCFG config tables\n");
164 return -ENOMEM;
165 }
166
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300167 memcpy(pci_mmcfg_config, &mcfg[1], config_size);
John Kellera726c602008-07-29 14:34:16 -0500168
169 acpi_mcfg_oem_check(mcfg);
170
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700171 for (i = 0; i < pci_mmcfg_config_num; ++i) {
John Kellera726c602008-07-29 14:34:16 -0500172 if ((pci_mmcfg_config[i].address > 0xFFFFFFFF) &&
173 !acpi_mcfg_64bit_base_addr) {
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700174 printk(KERN_ERR PREFIX
175 "MMCONFIG not in low 4GB of memory\n");
Konrad Rzeszutekacc7c2e2006-06-15 12:08:30 -0400176 kfree(pci_mmcfg_config);
177 pci_mmcfg_config_num = 0;
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700178 return -ENODEV;
179 }
180 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
182 return 0;
183}
Len Brown4be44fc2005-08-05 00:44:28 -0400184#endif /* CONFIG_PCI_MMCONFIG */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186#ifdef CONFIG_X86_LOCAL_APIC
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300187static int __init acpi_parse_madt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188{
Len Brown4be44fc2005-08-05 00:44:28 -0400189 struct acpi_table_madt *madt = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300191 if (!cpu_has_apic)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 return -EINVAL;
193
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300194 madt = (struct acpi_table_madt *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 if (!madt) {
196 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
197 return -ENODEV;
198 }
199
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300200 if (madt->address) {
201 acpi_lapic_addr = (u64) madt->address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203 printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300204 madt->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 }
206
Ingo Molnar306db032009-01-28 03:43:47 +0100207 default_acpi_madt_oem_check(madt->header.oem_id,
208 madt->header.oem_table_id);
Len Brown4be44fc2005-08-05 00:44:28 -0400209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 return 0;
211}
212
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400213static void __cpuinit acpi_register_lapic(int id, u8 enabled)
214{
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700215 unsigned int ver = 0;
216
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400217 if (!enabled) {
218 ++disabled_cpus;
219 return;
220 }
221
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700222 if (boot_cpu_physical_apicid != -1U)
223 ver = apic_version[boot_cpu_physical_apicid];
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700224
225 generic_processor_info(id, ver);
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400226}
227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228static int __init
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800229acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
230{
231 struct acpi_madt_local_x2apic *processor = NULL;
232
233 processor = (struct acpi_madt_local_x2apic *)header;
234
235 if (BAD_MADT_ENTRY(processor, end))
236 return -EINVAL;
237
238 acpi_table_print_madt_entry(header);
239
240#ifdef CONFIG_X86_X2APIC
241 /*
242 * We need to register disabled CPU as well to permit
243 * counting disabled CPUs. This allows us to size
244 * cpus_possible_map more accurately, to permit
245 * to not preallocating memory for all NR_CPUS
246 * when we use CPU hotplug.
247 */
248 acpi_register_lapic(processor->local_apic_id, /* APIC ID */
249 processor->lapic_flags & ACPI_MADT_ENABLED);
250#else
251 printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
252#endif
253
254 return 0;
255}
256
257static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300258acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300260 struct acpi_madt_local_apic *processor = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300262 processor = (struct acpi_madt_local_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264 if (BAD_MADT_ENTRY(processor, end))
265 return -EINVAL;
266
267 acpi_table_print_madt_entry(header);
268
Ashok Raj7f66ae42006-02-03 21:51:50 +0100269 /*
270 * We need to register disabled CPU as well to permit
271 * counting disabled CPUs. This allows us to size
272 * cpus_possible_map more accurately, to permit
273 * to not preallocating memory for all NR_CPUS
274 * when we use CPU hotplug.
275 */
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400276 acpi_register_lapic(processor->id, /* APIC ID */
277 processor->lapic_flags & ACPI_MADT_ENABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
279 return 0;
280}
281
282static int __init
Jack Steinerac049c12008-03-28 14:12:09 -0500283acpi_parse_sapic(struct acpi_subtable_header *header, const unsigned long end)
284{
285 struct acpi_madt_local_sapic *processor = NULL;
286
287 processor = (struct acpi_madt_local_sapic *)header;
288
289 if (BAD_MADT_ENTRY(processor, end))
290 return -EINVAL;
291
292 acpi_table_print_madt_entry(header);
293
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400294 acpi_register_lapic((processor->id << 8) | processor->eid,/* APIC ID */
295 processor->lapic_flags & ACPI_MADT_ENABLED);
Jack Steinerac049c12008-03-28 14:12:09 -0500296
297 return 0;
298}
299
300static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300301acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400302 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300304 struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300306 lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308 if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
309 return -EINVAL;
310
311 acpi_lapic_addr = lapic_addr_ovr->address;
312
313 return 0;
314}
315
316static int __init
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800317acpi_parse_x2apic_nmi(struct acpi_subtable_header *header,
318 const unsigned long end)
319{
320 struct acpi_madt_local_x2apic_nmi *x2apic_nmi = NULL;
321
322 x2apic_nmi = (struct acpi_madt_local_x2apic_nmi *)header;
323
324 if (BAD_MADT_ENTRY(x2apic_nmi, end))
325 return -EINVAL;
326
327 acpi_table_print_madt_entry(header);
328
329 if (x2apic_nmi->lint != 1)
330 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
331
332 return 0;
333}
334
335static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300336acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300338 struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300340 lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342 if (BAD_MADT_ENTRY(lapic_nmi, end))
343 return -EINVAL;
344
345 acpi_table_print_madt_entry(header);
346
347 if (lapic_nmi->lint != 1)
348 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
349
350 return 0;
351}
352
Len Brown4be44fc2005-08-05 00:44:28 -0400353#endif /*CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Len Brown84663612005-08-24 12:09:07 -0400355#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300358acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300360 struct acpi_madt_io_apic *ioapic = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300362 ioapic = (struct acpi_madt_io_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364 if (BAD_MADT_ENTRY(ioapic, end))
365 return -EINVAL;
Len Brown4be44fc2005-08-05 00:44:28 -0400366
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 acpi_table_print_madt_entry(header);
368
Len Brown4be44fc2005-08-05 00:44:28 -0400369 mp_register_ioapic(ioapic->id,
370 ioapic->address, ioapic->global_irq_base);
371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 return 0;
373}
374
375/*
376 * Parse Interrupt Source Override for the ACPI SCI
377 */
Len Browne82c3542006-12-21 01:29:59 -0500378static void __init acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
380 if (trigger == 0) /* compatible SCI trigger is level */
381 trigger = 3;
382
383 if (polarity == 0) /* compatible SCI polarity is low */
384 polarity = 3;
385
386 /* Command-line over-ride via acpi_sci= */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300387 if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
388 trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300390 if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
391 polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393 /*
Len Brown4be44fc2005-08-05 00:44:28 -0400394 * mp_config_acpi_legacy_irqs() already setup IRQs < 16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 * If GSI is < 16, this will update its flags,
396 * else it will create a new mp_irqs[] entry.
397 */
Len Brown7bdd21c2006-12-02 02:27:46 -0500398 mp_override_legacy_irq(gsi, polarity, trigger, gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400 /*
401 * stash over-ride to indicate we've been here
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300402 * and for later update of acpi_gbl_FADT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 */
Len Brown7bdd21c2006-12-02 02:27:46 -0500404 acpi_sci_override_gsi = gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 return;
406}
407
408static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300409acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400410 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300412 struct acpi_madt_interrupt_override *intsrc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300414 intsrc = (struct acpi_madt_interrupt_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
416 if (BAD_MADT_ENTRY(intsrc, end))
417 return -EINVAL;
418
419 acpi_table_print_madt_entry(header);
420
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300421 if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
Len Brown7bdd21c2006-12-02 02:27:46 -0500422 acpi_sci_ioapic_setup(intsrc->global_irq,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300423 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
424 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 return 0;
426 }
427
428 if (acpi_skip_timer_override &&
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300429 intsrc->source_irq == 0 && intsrc->global_irq == 2) {
Len Brown4be44fc2005-08-05 00:44:28 -0400430 printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
431 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 }
433
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300434 mp_override_legacy_irq(intsrc->source_irq,
435 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
436 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
437 intsrc->global_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
439 return 0;
440}
441
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300443acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300445 struct acpi_madt_nmi_source *nmi_src = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300447 nmi_src = (struct acpi_madt_nmi_source *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 if (BAD_MADT_ENTRY(nmi_src, end))
450 return -EINVAL;
451
452 acpi_table_print_madt_entry(header);
453
454 /* TBD: Support nimsrc entries? */
455
456 return 0;
457}
458
Len Brown4be44fc2005-08-05 00:44:28 -0400459#endif /* CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461/*
462 * acpi_pic_sci_set_trigger()
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300463 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 * use ELCR to set PIC-mode trigger type for SCI
465 *
466 * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
467 * it may require Edge Trigger -- use "acpi_sci=edge"
468 *
469 * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
470 * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
Simon Arlott27b46d72007-10-20 01:13:56 +0200471 * ECLR1 is IRQs 0-7 (IRQ 0, 1, 2 must be 0)
472 * ECLR2 is IRQs 8-15 (IRQ 8, 13 must be 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 */
474
Len Brown4be44fc2005-08-05 00:44:28 -0400475void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476{
477 unsigned int mask = 1 << irq;
478 unsigned int old, new;
479
480 /* Real old ELCR mask */
481 old = inb(0x4d0) | (inb(0x4d1) << 8);
482
483 /*
Simon Arlott27b46d72007-10-20 01:13:56 +0200484 * If we use ACPI to set PCI IRQs, then we should clear ELCR
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 * since we will set it correctly as we enable the PCI irq
486 * routing.
487 */
488 new = acpi_noirq ? old : 0;
489
490 /*
491 * Update SCI information in the ELCR, it isn't in the PCI
492 * routing tables..
493 */
494 switch (trigger) {
Len Brown4be44fc2005-08-05 00:44:28 -0400495 case 1: /* Edge - clear */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 new &= ~mask;
497 break;
Len Brown4be44fc2005-08-05 00:44:28 -0400498 case 3: /* Level - set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 new |= mask;
500 break;
501 }
502
503 if (old == new)
504 return;
505
506 printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
507 outb(new, 0x4d0);
508 outb(new >> 8, 0x4d1);
509}
510
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
512{
Eric W. Biedermanf023d762006-10-04 02:16:52 -0700513 *irq = gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 return 0;
515}
516
Kenji Kaneshige1f3a6a12005-07-28 14:42:00 -0400517/*
518 * success: return IRQ number (>=0)
519 * failure: return < 0
520 */
Len Browncb654692005-12-28 02:43:51 -0500521int acpi_register_gsi(u32 gsi, int triggering, int polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522{
523 unsigned int irq;
524 unsigned int plat_gsi = gsi;
525
526#ifdef CONFIG_PCI
527 /*
528 * Make sure all (legacy) PCI IRQs are set as level-triggered.
529 */
530 if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
Len Browncb654692005-12-28 02:43:51 -0500531 if (triggering == ACPI_LEVEL_SENSITIVE)
Len Brown4be44fc2005-08-05 00:44:28 -0400532 eisa_set_level_irq(gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 }
534#endif
535
536#ifdef CONFIG_X86_IO_APIC
537 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) {
Len Browncb654692005-12-28 02:43:51 -0500538 plat_gsi = mp_register_gsi(gsi, triggering, polarity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 }
540#endif
541 acpi_gsi_to_irq(plat_gsi, &irq);
542 return irq;
543}
Len Brown4be44fc2005-08-05 00:44:28 -0400544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545/*
546 * ACPI based hotplug support for CPU
547 */
548#ifdef CONFIG_ACPI_HOTPLUG_CPU
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100549
550static int __cpuinit _acpi_map_lsapic(acpi_handle handle, int *pcpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551{
Ashok Raj73fea172006-09-26 10:52:35 +0200552 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
553 union acpi_object *obj;
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300554 struct acpi_madt_local_apic *lapic;
Rusty Russellee943a82008-12-31 18:08:47 -0800555 cpumask_var_t tmp_map, new_map;
Ashok Raj73fea172006-09-26 10:52:35 +0200556 u8 physid;
557 int cpu;
Rusty Russellee943a82008-12-31 18:08:47 -0800558 int retval = -ENOMEM;
Ashok Raj73fea172006-09-26 10:52:35 +0200559
560 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
561 return -EINVAL;
562
563 if (!buffer.length || !buffer.pointer)
564 return -EINVAL;
565
566 obj = buffer.pointer;
567 if (obj->type != ACPI_TYPE_BUFFER ||
568 obj->buffer.length < sizeof(*lapic)) {
569 kfree(buffer.pointer);
570 return -EINVAL;
571 }
572
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300573 lapic = (struct acpi_madt_local_apic *)obj->buffer.pointer;
Ashok Raj73fea172006-09-26 10:52:35 +0200574
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300575 if (lapic->header.type != ACPI_MADT_TYPE_LOCAL_APIC ||
576 !(lapic->lapic_flags & ACPI_MADT_ENABLED)) {
Ashok Raj73fea172006-09-26 10:52:35 +0200577 kfree(buffer.pointer);
578 return -EINVAL;
579 }
580
581 physid = lapic->id;
582
583 kfree(buffer.pointer);
584 buffer.length = ACPI_ALLOCATE_BUFFER;
585 buffer.pointer = NULL;
586
Rusty Russellee943a82008-12-31 18:08:47 -0800587 if (!alloc_cpumask_var(&tmp_map, GFP_KERNEL))
588 goto out;
589
590 if (!alloc_cpumask_var(&new_map, GFP_KERNEL))
591 goto free_tmp_map;
592
593 cpumask_copy(tmp_map, cpu_present_mask);
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400594 acpi_register_lapic(physid, lapic->lapic_flags & ACPI_MADT_ENABLED);
Ashok Raj73fea172006-09-26 10:52:35 +0200595
596 /*
597 * If mp_register_lapic successfully generates a new logical cpu
598 * number, then the following will get us exactly what was mapped
599 */
Rusty Russellee943a82008-12-31 18:08:47 -0800600 cpumask_andnot(new_map, cpu_present_mask, tmp_map);
601 if (cpumask_empty(new_map)) {
Ashok Raj73fea172006-09-26 10:52:35 +0200602 printk ("Unable to map lapic to logical cpu number\n");
Rusty Russellee943a82008-12-31 18:08:47 -0800603 retval = -EINVAL;
604 goto free_new_map;
Ashok Raj73fea172006-09-26 10:52:35 +0200605 }
606
Rusty Russellee943a82008-12-31 18:08:47 -0800607 cpu = cpumask_first(new_map);
Ashok Raj73fea172006-09-26 10:52:35 +0200608
609 *pcpu = cpu;
Rusty Russellee943a82008-12-31 18:08:47 -0800610 retval = 0;
611
612free_new_map:
613 free_cpumask_var(new_map);
614free_tmp_map:
615 free_cpumask_var(tmp_map);
616out:
617 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618}
Len Brown4be44fc2005-08-05 00:44:28 -0400619
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100620/* wrapper to silence section mismatch warning */
621int __ref acpi_map_lsapic(acpi_handle handle, int *pcpu)
622{
623 return _acpi_map_lsapic(handle, pcpu);
624}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625EXPORT_SYMBOL(acpi_map_lsapic);
626
Len Brown4be44fc2005-08-05 00:44:28 -0400627int acpi_unmap_lsapic(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628{
Mike Travis71fff5e2007-10-19 20:35:03 +0200629 per_cpu(x86_cpu_to_apicid, cpu) = -1;
Mike Travis96289372008-12-31 18:08:46 -0800630 set_cpu_present(cpu, false);
Ashok Raj73fea172006-09-26 10:52:35 +0200631 num_processors--;
632
633 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634}
Len Brown4be44fc2005-08-05 00:44:28 -0400635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636EXPORT_SYMBOL(acpi_unmap_lsapic);
Len Brown4be44fc2005-08-05 00:44:28 -0400637#endif /* CONFIG_ACPI_HOTPLUG_CPU */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Len Brown4be44fc2005-08-05 00:44:28 -0400639int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700640{
641 /* TBD */
642 return -EINVAL;
643}
Len Brown4be44fc2005-08-05 00:44:28 -0400644
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700645EXPORT_SYMBOL(acpi_register_ioapic);
646
Len Brown4be44fc2005-08-05 00:44:28 -0400647int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700648{
649 /* TBD */
650 return -EINVAL;
651}
Len Brown4be44fc2005-08-05 00:44:28 -0400652
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700653EXPORT_SYMBOL(acpi_unregister_ioapic);
654
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300655static int __init acpi_parse_sbf(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300657 struct acpi_table_boot *sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300659 sb = (struct acpi_table_boot *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 if (!sb) {
661 printk(KERN_WARNING PREFIX "Unable to map SBF\n");
662 return -ENODEV;
663 }
664
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300665 sbf_port = sb->cmos_index; /* Save CMOS port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
667 return 0;
668}
669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670#ifdef CONFIG_HPET_TIMER
john stultz2d0c87c2007-02-16 01:28:18 -0800671#include <asm/hpet.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Aaron Durbina1dfd852007-07-21 17:11:39 +0200673static struct __initdata resource *hpet_res;
674
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300675static int __init acpi_parse_hpet(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676{
677 struct acpi_table_hpet *hpet_tbl;
678
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300679 hpet_tbl = (struct acpi_table_hpet *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 if (!hpet_tbl) {
681 printk(KERN_WARNING PREFIX "Unable to map HPET\n");
682 return -ENODEV;
683 }
684
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300685 if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 printk(KERN_WARNING PREFIX "HPET timers must be located in "
687 "memory.\n");
688 return -1;
689 }
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200690
john stultz2d0c87c2007-02-16 01:28:18 -0800691 hpet_address = hpet_tbl->address.address;
Thomas Gleixnerf4df73c2007-11-15 21:41:50 -0500692
693 /*
694 * Some broken BIOSes advertise HPET at 0x0. We really do not
695 * want to allocate a resource there.
696 */
697 if (!hpet_address) {
698 printk(KERN_WARNING PREFIX
699 "HPET id: %#x base: %#lx is invalid\n",
700 hpet_tbl->id, hpet_address);
701 return 0;
702 }
703#ifdef CONFIG_X86_64
704 /*
705 * Some even more broken BIOSes advertise HPET at
706 * 0xfed0000000000000 instead of 0xfed00000. Fix it up and add
707 * some noise:
708 */
709 if (hpet_address == 0xfed0000000000000UL) {
710 if (!hpet_force_user) {
711 printk(KERN_WARNING PREFIX "HPET id: %#x "
712 "base: 0xfed0000000000000 is bogus\n "
713 "try hpet=force on the kernel command line to "
714 "fix it up to 0xfed00000.\n", hpet_tbl->id);
715 hpet_address = 0;
716 return 0;
717 }
718 printk(KERN_WARNING PREFIX
719 "HPET id: %#x base: 0xfed0000000000000 fixed up "
720 "to 0xfed00000.\n", hpet_tbl->id);
721 hpet_address >>= 32;
722 }
723#endif
Len Brown4be44fc2005-08-05 00:44:28 -0400724 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
john stultz2d0c87c2007-02-16 01:28:18 -0800725 hpet_tbl->id, hpet_address);
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200726
Aaron Durbina1dfd852007-07-21 17:11:39 +0200727 /*
728 * Allocate and initialize the HPET firmware resource for adding into
729 * the resource tree during the lateinit timeframe.
730 */
731#define HPET_RESOURCE_NAME_SIZE 9
732 hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
733
Aaron Durbina1dfd852007-07-21 17:11:39 +0200734 hpet_res->name = (void *)&hpet_res[1];
735 hpet_res->flags = IORESOURCE_MEM;
736 snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE, "HPET %u",
737 hpet_tbl->sequence);
738
739 hpet_res->start = hpet_address;
740 hpet_res->end = hpet_address + (1 * 1024) - 1;
741
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 return 0;
743}
Aaron Durbina1dfd852007-07-21 17:11:39 +0200744
745/*
746 * hpet_insert_resource inserts the HPET resources used into the resource
747 * tree.
748 */
749static __init int hpet_insert_resource(void)
750{
751 if (!hpet_res)
752 return 1;
753
754 return insert_resource(&iomem_resource, hpet_res);
755}
756
757late_initcall(hpet_insert_resource);
758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759#else
760#define acpi_parse_hpet NULL
761#endif
762
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300763static int __init acpi_parse_fadt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764{
Jason Davis90660ec2005-04-16 15:24:53 -0700765
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766#ifdef CONFIG_X86_PM_TIMER
767 /* detect the location of the ACPI PM Timer */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300768 if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 /* FADT rev. 2 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300770 if (acpi_gbl_FADT.xpm_timer_block.space_id !=
Len Brown4be44fc2005-08-05 00:44:28 -0400771 ACPI_ADR_SPACE_SYSTEM_IO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 return 0;
773
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300774 pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
David Shaohua Lie6e87b42005-09-21 01:35:00 -0400775 /*
776 * "X" fields are optional extensions to the original V1.0
777 * fields, so we must selectively expand V1.0 fields if the
778 * corresponding X field is zero.
779 */
780 if (!pmtmr_ioport)
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300781 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 } else {
783 /* FADT rev. 1 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300784 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 }
786 if (pmtmr_ioport)
Len Brown4be44fc2005-08-05 00:44:28 -0400787 printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
788 pmtmr_ioport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789#endif
790 return 0;
791}
792
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793#ifdef CONFIG_X86_LOCAL_APIC
794/*
795 * Parse LAPIC entries in MADT
796 * returns 0 on success, < 0 on error
797 */
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400798
799static void __init acpi_register_lapic_address(unsigned long address)
800{
801 mp_lapic_addr = address;
802
803 set_fixmap_nocache(FIX_APIC_BASE, address);
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700804 if (boot_cpu_physical_apicid == -1U) {
Yinghai Lu4c9961d2008-07-11 18:44:16 -0700805 boot_cpu_physical_apicid = read_apic_id();
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700806 apic_version[boot_cpu_physical_apicid] =
807 GET_APIC_VERSION(apic_read(APIC_LVR));
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700808 }
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400809}
810
Yinghai Lucbf9bd62008-02-19 03:21:06 -0800811static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
812{
813 int count;
814
815 if (!cpu_has_apic)
816 return -ENODEV;
817
818 /*
819 * Note that the LAPIC address is obtained from the MADT (32-bit value)
820 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
821 */
822
823 count =
824 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
825 acpi_parse_lapic_addr_ovr, 0);
826 if (count < 0) {
827 printk(KERN_ERR PREFIX
828 "Error parsing LAPIC address override entry\n");
829 return count;
830 }
831
832 acpi_register_lapic_address(acpi_lapic_addr);
833
834 return count;
835}
836
Len Brown4be44fc2005-08-05 00:44:28 -0400837static int __init acpi_parse_madt_lapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838{
839 int count;
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800840 int x2count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
Andi Kleen0fcd2702006-04-11 12:54:36 +0200842 if (!cpu_has_apic)
843 return -ENODEV;
844
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300845 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 * Note that the LAPIC address is obtained from the MADT (32-bit value)
847 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
848 */
849
Len Brown4be44fc2005-08-05 00:44:28 -0400850 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300851 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
Len Brown4be44fc2005-08-05 00:44:28 -0400852 acpi_parse_lapic_addr_ovr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 if (count < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400854 printk(KERN_ERR PREFIX
855 "Error parsing LAPIC address override entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 return count;
857 }
858
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400859 acpi_register_lapic_address(acpi_lapic_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Jack Steinerac049c12008-03-28 14:12:09 -0500861 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
862 acpi_parse_sapic, MAX_APICS);
863
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800864 if (!count) {
865 x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
866 acpi_parse_x2apic, MAX_APICS);
Jack Steinerac049c12008-03-28 14:12:09 -0500867 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
868 acpi_parse_lapic, MAX_APICS);
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800869 }
870 if (!count && !x2count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
872 /* TBD: Cleanup to allow fallback to MPS */
873 return -ENODEV;
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800874 } else if (count < 0 || x2count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
876 /* TBD: Cleanup to allow fallback to MPS */
877 return count;
878 }
879
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800880 x2count =
881 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI,
882 acpi_parse_x2apic_nmi, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400883 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300884 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0);
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800885 if (count < 0 || x2count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
887 /* TBD: Cleanup to allow fallback to MPS */
888 return count;
889 }
890 return 0;
891}
Len Brown4be44fc2005-08-05 00:44:28 -0400892#endif /* CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
Len Brown84663612005-08-24 12:09:07 -0400894#ifdef CONFIG_X86_IO_APIC
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400895#define MP_ISA_BUS 0
896
Yinghai Lud49c4282008-06-08 18:31:54 -0700897#ifdef CONFIG_X86_ES7000
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400898extern int es7000_plat;
899#endif
900
Alexey Starikovskiy5f895142008-05-14 19:03:04 +0400901static struct {
902 int apic_id;
903 int gsi_base;
904 int gsi_end;
905 DECLARE_BITMAP(pin_programmed, MP_MAX_IOAPIC_PIN + 1);
906} mp_ioapic_routing[MAX_IO_APICS];
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400907
Jeremy Fitzhardinge4924e222009-02-09 12:05:47 -0800908int mp_find_ioapic(int gsi)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400909{
910 int i = 0;
911
912 /* Find the IOAPIC that manages this GSI. */
913 for (i = 0; i < nr_ioapics; i++) {
914 if ((gsi >= mp_ioapic_routing[i].gsi_base)
915 && (gsi <= mp_ioapic_routing[i].gsi_end))
916 return i;
917 }
918
919 printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
920 return -1;
921}
922
Jeremy Fitzhardingec3e137d2009-02-09 12:05:47 -0800923int mp_find_ioapic_pin(int ioapic, int gsi)
924{
925 if (WARN_ON(ioapic == -1))
926 return -1;
927 if (WARN_ON(gsi > mp_ioapic_routing[ioapic].gsi_end))
928 return -1;
929
930 return gsi - mp_ioapic_routing[ioapic].gsi_base;
931}
932
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400933static u8 __init uniq_ioapic_id(u8 id)
934{
935#ifdef CONFIG_X86_32
936 if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
937 !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
938 return io_apic_get_unique_id(nr_ioapics, id);
939 else
940 return id;
941#else
942 int i;
943 DECLARE_BITMAP(used, 256);
944 bitmap_zero(used, 256);
945 for (i = 0; i < nr_ioapics; i++) {
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530946 struct mpc_ioapic *ia = &mp_ioapics[i];
947 __set_bit(ia->apicid, used);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400948 }
949 if (!test_bit(id, used))
950 return id;
951 return find_first_zero_bit(used, 256);
952#endif
953}
954
955static int bad_ioapic(unsigned long address)
956{
957 if (nr_ioapics >= MAX_IO_APICS) {
958 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
959 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
960 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
961 }
962 if (!address) {
963 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
964 " found in table, skipping!\n");
965 return 1;
966 }
967 return 0;
968}
969
970void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
971{
972 int idx = 0;
973
974 if (bad_ioapic(address))
975 return;
976
977 idx = nr_ioapics;
978
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530979 mp_ioapics[idx].type = MP_IOAPIC;
980 mp_ioapics[idx].flags = MPC_APIC_USABLE;
981 mp_ioapics[idx].apicaddr = address;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400982
983 set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530984 mp_ioapics[idx].apicid = uniq_ioapic_id(id);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400985#ifdef CONFIG_X86_32
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530986 mp_ioapics[idx].apicver = io_apic_get_version(idx);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400987#else
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530988 mp_ioapics[idx].apicver = 0;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400989#endif
990 /*
991 * Build basic GSI lookup table to facilitate gsi->io_apic lookups
992 * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
993 */
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530994 mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].apicid;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400995 mp_ioapic_routing[idx].gsi_base = gsi_base;
996 mp_ioapic_routing[idx].gsi_end = gsi_base +
997 io_apic_get_redir_entries(idx);
998
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530999 printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
1000 "GSI %d-%d\n", idx, mp_ioapics[idx].apicid,
1001 mp_ioapics[idx].apicver, mp_ioapics[idx].apicaddr,
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001002 mp_ioapic_routing[idx].gsi_base, mp_ioapic_routing[idx].gsi_end);
1003
1004 nr_ioapics++;
1005}
1006
Yinghai Lu3f4a7392009-02-08 16:18:03 -08001007int __init acpi_probe_gsi(void)
1008{
1009 int idx;
1010 int gsi;
1011 int max_gsi = 0;
1012
1013 if (acpi_disabled)
1014 return 0;
1015
1016 if (!acpi_ioapic)
1017 return 0;
1018
1019 max_gsi = 0;
1020 for (idx = 0; idx < nr_ioapics; idx++) {
1021 gsi = mp_ioapic_routing[idx].gsi_end;
1022
1023 if (gsi > max_gsi)
1024 max_gsi = gsi;
1025 }
1026
1027 return max_gsi + 1;
1028}
1029
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301030static void assign_to_mp_irq(struct mpc_intsrc *m,
1031 struct mpc_intsrc *mp_irq)
Yinghai Lufcfa1462008-06-18 17:29:31 -07001032{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301033 memcpy(mp_irq, m, sizeof(struct mpc_intsrc));
Yinghai Lufcfa1462008-06-18 17:29:31 -07001034}
1035
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301036static int mp_irq_cmp(struct mpc_intsrc *mp_irq,
1037 struct mpc_intsrc *m)
Yinghai Lufcfa1462008-06-18 17:29:31 -07001038{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301039 return memcmp(mp_irq, m, sizeof(struct mpc_intsrc));
Yinghai Lufcfa1462008-06-18 17:29:31 -07001040}
1041
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301042static void save_mp_irq(struct mpc_intsrc *m)
Yinghai Lufcfa1462008-06-18 17:29:31 -07001043{
1044 int i;
1045
1046 for (i = 0; i < mp_irq_entries; i++) {
1047 if (!mp_irq_cmp(&mp_irqs[i], m))
1048 return;
1049 }
1050
1051 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
1052 if (++mp_irq_entries == MAX_IRQ_SOURCES)
1053 panic("Max # of irq sources exceeded!!\n");
1054}
1055
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001056void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
1057{
Yinghai Lu6df88092008-06-15 18:19:46 -07001058 int ioapic;
1059 int pin;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301060 struct mpc_intsrc mp_irq;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001061
1062 /*
1063 * Convert 'gsi' to 'ioapic.pin'.
1064 */
1065 ioapic = mp_find_ioapic(gsi);
1066 if (ioapic < 0)
1067 return;
Jeremy Fitzhardingec3e137d2009-02-09 12:05:47 -08001068 pin = mp_find_ioapic_pin(ioapic, gsi);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001069
1070 /*
1071 * TBD: This check is for faulty timer entries, where the override
1072 * erroneously sets the trigger to level, resulting in a HUGE
1073 * increase of timer interrupts!
1074 */
1075 if ((bus_irq == 0) && (trigger == 3))
1076 trigger = 1;
1077
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301078 mp_irq.type = MP_INTSRC;
1079 mp_irq.irqtype = mp_INT;
1080 mp_irq.irqflag = (trigger << 2) | polarity;
1081 mp_irq.srcbus = MP_ISA_BUS;
1082 mp_irq.srcbusirq = bus_irq; /* IRQ */
1083 mp_irq.dstapic = mp_ioapics[ioapic].apicid; /* APIC ID */
1084 mp_irq.dstirq = pin; /* INTIN# */
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001085
Yinghai Lufcfa1462008-06-18 17:29:31 -07001086 save_mp_irq(&mp_irq);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001087}
1088
1089void __init mp_config_acpi_legacy_irqs(void)
1090{
Yinghai Lu6df88092008-06-15 18:19:46 -07001091 int i;
1092 int ioapic;
1093 unsigned int dstapic;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301094 struct mpc_intsrc mp_irq;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001095
1096#if defined (CONFIG_MCA) || defined (CONFIG_EISA)
1097 /*
1098 * Fabricate the legacy ISA bus (bus #31).
1099 */
1100 mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
1101#endif
1102 set_bit(MP_ISA_BUS, mp_bus_not_pci);
Thomas Gleixnercfc1b9a2008-07-21 21:35:38 +02001103 pr_debug("Bus #%d is ISA\n", MP_ISA_BUS);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001104
Yinghai Lud49c4282008-06-08 18:31:54 -07001105#ifdef CONFIG_X86_ES7000
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001106 /*
1107 * Older generations of ES7000 have no legacy identity mappings
1108 */
1109 if (es7000_plat == 1)
1110 return;
1111#endif
1112
1113 /*
1114 * Locate the IOAPIC that manages the ISA IRQs (0-15).
1115 */
1116 ioapic = mp_find_ioapic(0);
1117 if (ioapic < 0)
1118 return;
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +05301119 dstapic = mp_ioapics[ioapic].apicid;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001120
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001121 /*
1122 * Use the default configuration for the IRQs 0-15. Unless
1123 * overridden by (MADT) interrupt source override entries.
1124 */
1125 for (i = 0; i < 16; i++) {
1126 int idx;
1127
1128 for (idx = 0; idx < mp_irq_entries; idx++) {
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301129 struct mpc_intsrc *irq = mp_irqs + idx;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001130
1131 /* Do we already have a mapping for this ISA IRQ? */
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301132 if (irq->srcbus == MP_ISA_BUS && irq->srcbusirq == i)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001133 break;
1134
1135 /* Do we already have a mapping for this IOAPIC pin */
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301136 if (irq->dstapic == dstapic && irq->dstirq == i)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001137 break;
1138 }
1139
1140 if (idx != mp_irq_entries) {
1141 printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
1142 continue; /* IRQ already used */
1143 }
1144
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301145 mp_irq.type = MP_INTSRC;
1146 mp_irq.irqflag = 0; /* Conforming */
1147 mp_irq.srcbus = MP_ISA_BUS;
1148 mp_irq.dstapic = dstapic;
1149 mp_irq.irqtype = mp_INT;
1150 mp_irq.srcbusirq = i; /* Identity mapped */
1151 mp_irq.dstirq = i;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001152
Yinghai Lufcfa1462008-06-18 17:29:31 -07001153 save_mp_irq(&mp_irq);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001154 }
1155}
1156
1157int mp_register_gsi(u32 gsi, int triggering, int polarity)
1158{
1159 int ioapic;
1160 int ioapic_pin;
1161#ifdef CONFIG_X86_32
1162#define MAX_GSI_NUM 4096
1163#define IRQ_COMPRESSION_START 64
1164
1165 static int pci_irq = IRQ_COMPRESSION_START;
1166 /*
1167 * Mapping between Global System Interrupts, which
1168 * represent all possible interrupts, and IRQs
1169 * assigned to actual devices.
1170 */
1171 static int gsi_to_irq[MAX_GSI_NUM];
1172#else
1173
1174 if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
1175 return gsi;
1176#endif
1177
1178 /* Don't set up the ACPI SCI because it's already set up */
1179 if (acpi_gbl_FADT.sci_interrupt == gsi)
1180 return gsi;
1181
1182 ioapic = mp_find_ioapic(gsi);
1183 if (ioapic < 0) {
1184 printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
1185 return gsi;
1186 }
1187
Jeremy Fitzhardingec3e137d2009-02-09 12:05:47 -08001188 ioapic_pin = mp_find_ioapic_pin(ioapic, gsi);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001189
1190#ifdef CONFIG_X86_32
1191 if (ioapic_renumber_irq)
1192 gsi = ioapic_renumber_irq(ioapic, gsi);
1193#endif
1194
1195 /*
1196 * Avoid pin reprogramming. PRTs typically include entries
1197 * with redundant pin->gsi mappings (but unique PCI devices);
1198 * we only program the IOAPIC on the first.
1199 */
1200 if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
1201 printk(KERN_ERR "Invalid reference to IOAPIC pin "
1202 "%d-%d\n", mp_ioapic_routing[ioapic].apic_id,
1203 ioapic_pin);
1204 return gsi;
1205 }
1206 if (test_bit(ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed)) {
Gustavo F. Padovan55410792008-10-15 10:37:04 -03001207 pr_debug("Pin %d-%d already programmed\n",
Thomas Gleixnercfc1b9a2008-07-21 21:35:38 +02001208 mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001209#ifdef CONFIG_X86_32
1210 return (gsi < IRQ_COMPRESSION_START ? gsi : gsi_to_irq[gsi]);
1211#else
1212 return gsi;
1213#endif
1214 }
1215
1216 set_bit(ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed);
1217#ifdef CONFIG_X86_32
1218 /*
1219 * For GSI >= 64, use IRQ compression
1220 */
1221 if ((gsi >= IRQ_COMPRESSION_START)
1222 && (triggering == ACPI_LEVEL_SENSITIVE)) {
1223 /*
1224 * For PCI devices assign IRQs in order, avoiding gaps
1225 * due to unused I/O APIC pins.
1226 */
1227 int irq = gsi;
1228 if (gsi < MAX_GSI_NUM) {
1229 /*
1230 * Retain the VIA chipset work-around (gsi > 15), but
1231 * avoid a problem where the 8254 timer (IRQ0) is setup
1232 * via an override (so it's not on pin 0 of the ioapic),
1233 * and at the same time, the pin 0 interrupt is a PCI
1234 * type. The gsi > 15 test could cause these two pins
1235 * to be shared as IRQ0, and they are not shareable.
1236 * So test for this condition, and if necessary, avoid
1237 * the pin collision.
1238 */
1239 gsi = pci_irq++;
1240 /*
1241 * Don't assign IRQ used by ACPI SCI
1242 */
1243 if (gsi == acpi_gbl_FADT.sci_interrupt)
1244 gsi = pci_irq++;
1245 gsi_to_irq[irq] = gsi;
1246 } else {
1247 printk(KERN_ERR "GSI %u is too high\n", gsi);
1248 return gsi;
1249 }
1250 }
1251#endif
1252 io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
1253 triggering == ACPI_EDGE_SENSITIVE ? 0 : 1,
1254 polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
1255 return gsi;
1256}
1257
Yinghai Lu2944e162008-06-01 13:17:38 -07001258int mp_config_acpi_gsi(unsigned char number, unsigned int devfn, u8 pin,
1259 u32 gsi, int triggering, int polarity)
1260{
Yinghai Lufcfa1462008-06-18 17:29:31 -07001261#ifdef CONFIG_X86_MPPARSE
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301262 struct mpc_intsrc mp_irq;
Yinghai Lu2944e162008-06-01 13:17:38 -07001263 int ioapic;
1264
Yinghai Lufcfa1462008-06-18 17:29:31 -07001265 if (!acpi_ioapic)
Yinghai Lud867e532008-06-14 01:26:41 -07001266 return 0;
1267
Yinghai Lu2944e162008-06-01 13:17:38 -07001268 /* print the entry should happen on mptable identically */
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301269 mp_irq.type = MP_INTSRC;
1270 mp_irq.irqtype = mp_INT;
1271 mp_irq.irqflag = (triggering == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
Yinghai Lu2944e162008-06-01 13:17:38 -07001272 (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301273 mp_irq.srcbus = number;
1274 mp_irq.srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
Yinghai Lu2944e162008-06-01 13:17:38 -07001275 ioapic = mp_find_ioapic(gsi);
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301276 mp_irq.dstapic = mp_ioapic_routing[ioapic].apic_id;
Jeremy Fitzhardingec3e137d2009-02-09 12:05:47 -08001277 mp_irq.dstirq = mp_find_ioapic_pin(ioapic, gsi);
Yinghai Lu2944e162008-06-01 13:17:38 -07001278
Yinghai Lufcfa1462008-06-18 17:29:31 -07001279 save_mp_irq(&mp_irq);
1280#endif
Yinghai Lu2944e162008-06-01 13:17:38 -07001281 return 0;
1282}
1283
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284/*
1285 * Parse IOAPIC related entries in MADT
1286 * returns 0 on success, < 0 on error
1287 */
Len Brown4be44fc2005-08-05 00:44:28 -04001288static int __init acpi_parse_madt_ioapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289{
1290 int count;
1291
1292 /*
1293 * ACPI interpreter is required to complete interrupt setup,
1294 * so if it is off, don't enumerate the io-apics with ACPI.
1295 * If MPS is present, it will handle them,
1296 * otherwise the system will stay in PIC mode
1297 */
1298 if (acpi_disabled || acpi_noirq) {
1299 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -04001300 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001302 if (!cpu_has_apic)
Andi Kleend3b6a342006-04-07 19:49:39 +02001303 return -ENODEV;
1304
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001306 * if "noapic" boot option, don't look for IO-APICs
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 */
1308 if (skip_ioapic_setup) {
1309 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
Len Brown4be44fc2005-08-05 00:44:28 -04001310 "due to 'noapic' option.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 return -ENODEV;
1312 }
1313
Len Brown4be44fc2005-08-05 00:44:28 -04001314 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001315 acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
Len Brown4be44fc2005-08-05 00:44:28 -04001316 MAX_IO_APICS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 if (!count) {
1318 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
1319 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -04001320 } else if (count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
1322 return count;
1323 }
1324
Len Brown4be44fc2005-08-05 00:44:28 -04001325 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001326 acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr,
Yinghai Lu71f521b2008-08-19 20:50:03 -07001327 nr_irqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 if (count < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -04001329 printk(KERN_ERR PREFIX
1330 "Error parsing interrupt source overrides entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 /* TBD: Cleanup to allow fallback to MPS */
1332 return count;
1333 }
1334
1335 /*
1336 * If BIOS did not supply an INT_SRC_OVR for the SCI
1337 * pretend we got one so we can set the SCI flags.
1338 */
1339 if (!acpi_sci_override_gsi)
Alexey Starikovskiycee324b2007-02-02 19:48:22 +03001340 acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341
1342 /* Fill in identity legacy mapings where no override */
1343 mp_config_acpi_legacy_irqs();
1344
Len Brown4be44fc2005-08-05 00:44:28 -04001345 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001346 acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src,
Yinghai Lu71f521b2008-08-19 20:50:03 -07001347 nr_irqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 if (count < 0) {
1349 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
1350 /* TBD: Cleanup to allow fallback to MPS */
1351 return count;
1352 }
1353
1354 return 0;
1355}
1356#else
1357static inline int acpi_parse_madt_ioapic_entries(void)
1358{
1359 return -1;
1360}
Len Brown84663612005-08-24 12:09:07 -04001361#endif /* !CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001363static void __init early_acpi_process_madt(void)
1364{
1365#ifdef CONFIG_X86_LOCAL_APIC
1366 int error;
1367
1368 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1369
1370 /*
1371 * Parse MADT LAPIC entries
1372 */
1373 error = early_acpi_parse_madt_lapic_addr_ovr();
1374 if (!error) {
1375 acpi_lapic = 1;
1376 smp_found_config = 1;
1377 }
1378 if (error == -EINVAL) {
1379 /*
1380 * Dell Precision Workstation 410, 610 come here.
1381 */
1382 printk(KERN_ERR PREFIX
1383 "Invalid BIOS MADT, disabling ACPI\n");
1384 disable_acpi();
1385 }
1386 }
1387#endif
1388}
1389
Len Brown4be44fc2005-08-05 00:44:28 -04001390static void __init acpi_process_madt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391{
1392#ifdef CONFIG_X86_LOCAL_APIC
Len Brown7f8f97c2007-02-10 21:28:03 -05001393 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
Len Brown7f8f97c2007-02-10 21:28:03 -05001395 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396
1397 /*
1398 * Parse MADT LAPIC entries
1399 */
1400 error = acpi_parse_madt_lapic_entries();
1401 if (!error) {
1402 acpi_lapic = 1;
1403
Yinghai Lu26f7ef12009-01-29 14:19:22 -08001404#ifdef CONFIG_X86_BIGSMP
Venkatesh Pallipadi911a62d2005-09-03 15:56:31 -07001405 generic_bigsmp_probe();
1406#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 /*
1408 * Parse MADT IO-APIC entries
1409 */
1410 error = acpi_parse_madt_ioapic_entries();
1411 if (!error) {
1412 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 acpi_ioapic = 1;
1414
1415 smp_found_config = 1;
Ingo Molnar72ce0162009-01-28 06:50:47 +01001416 if (apic->setup_apic_routing)
1417 apic->setup_apic_routing();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 }
1419 }
1420 if (error == -EINVAL) {
1421 /*
1422 * Dell Precision Workstation 410, 610 come here.
1423 */
Len Brown4be44fc2005-08-05 00:44:28 -04001424 printk(KERN_ERR PREFIX
1425 "Invalid BIOS MADT, disabling ACPI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 disable_acpi();
1427 }
Len Brown7b37b5f2008-12-23 01:47:42 -05001428 } else {
1429 /*
1430 * ACPI found no MADT, and so ACPI wants UP PIC mode.
1431 * In the event an MPS table was found, forget it.
1432 * Boot with "acpi=off" to use MPS on such a system.
1433 */
1434 if (smp_found_config) {
1435 printk(KERN_WARNING PREFIX
1436 "No APIC-table, disabling MPS\n");
1437 smp_found_config = 0;
1438 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 }
Yinghai Lu69b88af2008-12-05 22:45:50 -08001440
1441 /*
1442 * ACPI supports both logical (e.g. Hyper-Threading) and physical
1443 * processors, where MPS only supports physical.
1444 */
1445 if (acpi_lapic && acpi_ioapic)
1446 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
1447 "information\n");
1448 else if (acpi_lapic)
1449 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
1450 "configuration information\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451#endif
1452 return;
1453}
1454
Jeff Garzik18552562007-10-03 15:15:40 -04001455static int __init disable_acpi_irq(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001456{
1457 if (!acpi_force) {
1458 printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
1459 d->ident);
1460 acpi_noirq_set();
1461 }
1462 return 0;
1463}
1464
Jeff Garzik18552562007-10-03 15:15:40 -04001465static int __init disable_acpi_pci(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001466{
1467 if (!acpi_force) {
1468 printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
1469 d->ident);
1470 acpi_disable_pci();
1471 }
1472 return 0;
1473}
Andrey Paninaea00142005-06-25 14:54:42 -07001474
Jeff Garzik18552562007-10-03 15:15:40 -04001475static int __init dmi_disable_acpi(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001476{
1477 if (!acpi_force) {
Len Brown4be44fc2005-08-05 00:44:28 -04001478 printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
Andrey Paninaea00142005-06-25 14:54:42 -07001479 disable_acpi();
1480 } else {
1481 printk(KERN_NOTICE
1482 "Warning: DMI blacklist says broken, but acpi forced\n");
1483 }
1484 return 0;
1485}
1486
1487/*
1488 * Limit ACPI to CPU enumeration for HT
1489 */
Jeff Garzik18552562007-10-03 15:15:40 -04001490static int __init force_acpi_ht(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001491{
1492 if (!acpi_force) {
Len Brown4be44fc2005-08-05 00:44:28 -04001493 printk(KERN_NOTICE "%s detected: force use of acpi=ht\n",
1494 d->ident);
Andrey Paninaea00142005-06-25 14:54:42 -07001495 disable_acpi();
1496 acpi_ht = 1;
1497 } else {
1498 printk(KERN_NOTICE
1499 "Warning: acpi=force overrules DMI blacklist: acpi=ht\n");
1500 }
1501 return 0;
1502}
1503
1504/*
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001505 * Force ignoring BIOS IRQ0 pin2 override
1506 */
1507static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
1508{
Ingo Molnar8d89adf2008-10-07 06:47:52 +02001509 /*
1510 * The ati_ixp4x0_rev() early PCI quirk should have set
1511 * the acpi_skip_timer_override flag already:
1512 */
1513 if (!acpi_skip_timer_override) {
1514 WARN(1, KERN_ERR "ati_ixp4x0 quirk not complete.\n");
1515 pr_notice("%s detected: Ignoring BIOS IRQ0 pin2 override\n",
1516 d->ident);
1517 acpi_skip_timer_override = 1;
1518 }
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001519 return 0;
1520}
1521
1522/*
Andrey Paninaea00142005-06-25 14:54:42 -07001523 * If your system is blacklisted here, but you find that acpi=force
Zhang Rui5b4c0b62009-04-01 01:49:42 -04001524 * works for you, please contact linux-acpi@vger.kernel.org
Andrey Paninaea00142005-06-25 14:54:42 -07001525 */
1526static struct dmi_system_id __initdata acpi_dmi_table[] = {
1527 /*
1528 * Boxes that need ACPI disabled
1529 */
1530 {
Len Brown4be44fc2005-08-05 00:44:28 -04001531 .callback = dmi_disable_acpi,
1532 .ident = "IBM Thinkpad",
1533 .matches = {
1534 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1535 DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
1536 },
1537 },
Andrey Paninaea00142005-06-25 14:54:42 -07001538
1539 /*
1540 * Boxes that need acpi=ht
1541 */
1542 {
Len Brown4be44fc2005-08-05 00:44:28 -04001543 .callback = force_acpi_ht,
1544 .ident = "FSC Primergy T850",
1545 .matches = {
1546 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
1547 DMI_MATCH(DMI_PRODUCT_NAME, "PRIMERGY T850"),
1548 },
1549 },
Andrey Paninaea00142005-06-25 14:54:42 -07001550 {
Len Brown4be44fc2005-08-05 00:44:28 -04001551 .callback = force_acpi_ht,
Len Brown4be44fc2005-08-05 00:44:28 -04001552 .ident = "HP VISUALIZE NT Workstation",
1553 .matches = {
1554 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
1555 DMI_MATCH(DMI_PRODUCT_NAME, "HP VISUALIZE NT Workstation"),
1556 },
1557 },
Andrey Paninaea00142005-06-25 14:54:42 -07001558 {
Len Brown4be44fc2005-08-05 00:44:28 -04001559 .callback = force_acpi_ht,
1560 .ident = "Compaq Workstation W8000",
1561 .matches = {
1562 DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
1563 DMI_MATCH(DMI_PRODUCT_NAME, "Workstation W8000"),
1564 },
1565 },
Andrey Paninaea00142005-06-25 14:54:42 -07001566 {
Len Brown4be44fc2005-08-05 00:44:28 -04001567 .callback = force_acpi_ht,
1568 .ident = "ASUS P4B266",
1569 .matches = {
1570 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1571 DMI_MATCH(DMI_BOARD_NAME, "P4B266"),
1572 },
1573 },
Andrey Paninaea00142005-06-25 14:54:42 -07001574 {
Len Brown4be44fc2005-08-05 00:44:28 -04001575 .callback = force_acpi_ht,
1576 .ident = "ASUS P2B-DS",
1577 .matches = {
1578 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1579 DMI_MATCH(DMI_BOARD_NAME, "P2B-DS"),
1580 },
1581 },
Andrey Paninaea00142005-06-25 14:54:42 -07001582 {
Len Brown4be44fc2005-08-05 00:44:28 -04001583 .callback = force_acpi_ht,
1584 .ident = "ASUS CUR-DLS",
1585 .matches = {
1586 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1587 DMI_MATCH(DMI_BOARD_NAME, "CUR-DLS"),
1588 },
1589 },
Andrey Paninaea00142005-06-25 14:54:42 -07001590 {
Len Brown4be44fc2005-08-05 00:44:28 -04001591 .callback = force_acpi_ht,
1592 .ident = "ABIT i440BX-W83977",
1593 .matches = {
1594 DMI_MATCH(DMI_BOARD_VENDOR, "ABIT <http://www.abit.com>"),
1595 DMI_MATCH(DMI_BOARD_NAME, "i440BX-W83977 (BP6)"),
1596 },
1597 },
Andrey Paninaea00142005-06-25 14:54:42 -07001598 {
Len Brown4be44fc2005-08-05 00:44:28 -04001599 .callback = force_acpi_ht,
1600 .ident = "IBM Bladecenter",
1601 .matches = {
1602 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1603 DMI_MATCH(DMI_BOARD_NAME, "IBM eServer BladeCenter HS20"),
1604 },
1605 },
Andrey Paninaea00142005-06-25 14:54:42 -07001606 {
Len Brown4be44fc2005-08-05 00:44:28 -04001607 .callback = force_acpi_ht,
1608 .ident = "IBM eServer xSeries 360",
1609 .matches = {
1610 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1611 DMI_MATCH(DMI_BOARD_NAME, "eServer xSeries 360"),
1612 },
1613 },
Andrey Paninaea00142005-06-25 14:54:42 -07001614 {
Len Brown4be44fc2005-08-05 00:44:28 -04001615 .callback = force_acpi_ht,
1616 .ident = "IBM eserver xSeries 330",
1617 .matches = {
1618 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1619 DMI_MATCH(DMI_BOARD_NAME, "eserver xSeries 330"),
1620 },
1621 },
Andrey Paninaea00142005-06-25 14:54:42 -07001622 {
Len Brown4be44fc2005-08-05 00:44:28 -04001623 .callback = force_acpi_ht,
1624 .ident = "IBM eserver xSeries 440",
1625 .matches = {
1626 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1627 DMI_MATCH(DMI_PRODUCT_NAME, "eserver xSeries 440"),
1628 },
1629 },
Andrey Paninaea00142005-06-25 14:54:42 -07001630
Andrey Paninaea00142005-06-25 14:54:42 -07001631 /*
1632 * Boxes that need ACPI PCI IRQ routing disabled
1633 */
1634 {
Len Brown4be44fc2005-08-05 00:44:28 -04001635 .callback = disable_acpi_irq,
1636 .ident = "ASUS A7V",
1637 .matches = {
1638 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
1639 DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
1640 /* newer BIOS, Revision 1011, does work */
1641 DMI_MATCH(DMI_BIOS_VERSION,
1642 "ASUS A7V ACPI BIOS Revision 1007"),
1643 },
1644 },
Len Brown74586fc2007-03-08 02:48:30 -05001645 {
1646 /*
1647 * Latest BIOS for IBM 600E (1.16) has bad pcinum
1648 * for LPC bridge, which is needed for the PCI
1649 * interrupt links to work. DSDT fix is in bug 5966.
1650 * 2645, 2646 model numbers are shared with 600/600E/600X
1651 */
1652 .callback = disable_acpi_irq,
1653 .ident = "IBM Thinkpad 600 Series 2645",
1654 .matches = {
1655 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1656 DMI_MATCH(DMI_BOARD_NAME, "2645"),
1657 },
1658 },
1659 {
1660 .callback = disable_acpi_irq,
1661 .ident = "IBM Thinkpad 600 Series 2646",
1662 .matches = {
1663 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1664 DMI_MATCH(DMI_BOARD_NAME, "2646"),
1665 },
1666 },
Andrey Paninaea00142005-06-25 14:54:42 -07001667 /*
1668 * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
1669 */
Len Brown4be44fc2005-08-05 00:44:28 -04001670 { /* _BBN 0 bug */
1671 .callback = disable_acpi_pci,
1672 .ident = "ASUS PR-DLS",
1673 .matches = {
1674 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1675 DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
1676 DMI_MATCH(DMI_BIOS_VERSION,
1677 "ASUS PR-DLS ACPI BIOS Revision 1010"),
1678 DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
1679 },
1680 },
Andrey Paninaea00142005-06-25 14:54:42 -07001681 {
Len Brown4be44fc2005-08-05 00:44:28 -04001682 .callback = disable_acpi_pci,
1683 .ident = "Acer TravelMate 36x Laptop",
1684 .matches = {
1685 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
1686 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
1687 },
1688 },
Andreas Herrmann35af2822008-10-22 13:08:31 +02001689 {}
1690};
1691
1692/* second table for DMI checks that should run after early-quirks */
1693static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
Matthew Garrett9340e1c2008-07-01 01:12:06 +01001694 /*
1695 * HP laptops which use a DSDT reporting as HP/SB400/10000,
1696 * which includes some code which overrides all temperature
1697 * trip points to 16C if the INTIN2 input of the I/O APIC
1698 * is enabled. This input is incorrectly designated the
1699 * ISA IRQ 0 via an interrupt source override even though
1700 * it is wired to the output of the master 8259A and INTIN0
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001701 * is not connected at all. Force ignoring BIOS IRQ0 pin2
1702 * override in that cases.
1703 */
1704 {
1705 .callback = dmi_ignore_irq0_timer_override,
Rafael J. Wysockie84956f2008-10-06 11:59:29 +02001706 .ident = "HP nx6115 laptop",
1707 .matches = {
1708 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1709 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6115"),
1710 },
1711 },
1712 {
1713 .callback = dmi_ignore_irq0_timer_override,
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001714 .ident = "HP NX6125 laptop",
1715 .matches = {
1716 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1717 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
1718 },
1719 },
1720 {
1721 .callback = dmi_ignore_irq0_timer_override,
1722 .ident = "HP NX6325 laptop",
1723 .matches = {
1724 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1725 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
1726 },
1727 },
Rafael J. Wysockie84956f2008-10-06 11:59:29 +02001728 {
1729 .callback = dmi_ignore_irq0_timer_override,
1730 .ident = "HP 6715b laptop",
1731 .matches = {
1732 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1733 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
1734 },
1735 },
Len Brown4be44fc2005-08-05 00:44:28 -04001736 {}
Andrey Paninaea00142005-06-25 14:54:42 -07001737};
1738
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739/*
1740 * acpi_boot_table_init() and acpi_boot_init()
1741 * called from setup_arch(), always.
1742 * 1. checksums all tables
1743 * 2. enumerates lapics
1744 * 3. enumerates io-apics
1745 *
1746 * acpi_table_init() is separate to allow reading SRAT without
1747 * other side effects.
1748 *
1749 * side effects of acpi_boot_init:
1750 * acpi_lapic = 1 if LAPIC found
1751 * acpi_ioapic = 1 if IOAPIC found
1752 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
1753 * if acpi_blacklisted() acpi_disabled = 1;
1754 * acpi_irq_model=...
1755 * ...
1756 *
1757 * return value: (currently ignored)
1758 * 0: success
1759 * !0: failure
1760 */
1761
Len Brown4be44fc2005-08-05 00:44:28 -04001762int __init acpi_boot_table_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763{
1764 int error;
1765
Andrey Paninaea00142005-06-25 14:54:42 -07001766 dmi_check_system(acpi_dmi_table);
Andrey Paninaea00142005-06-25 14:54:42 -07001767
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 /*
1769 * If acpi_disabled, bail out
1770 * One exception: acpi=ht continues far enough to enumerate LAPICs
1771 */
1772 if (acpi_disabled && !acpi_ht)
Len Brown4be44fc2005-08-05 00:44:28 -04001773 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001775 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 * Initialize the ACPI boot-time table parser.
1777 */
1778 error = acpi_table_init();
1779 if (error) {
1780 disable_acpi();
1781 return error;
1782 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001784 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785
1786 /*
1787 * blacklist may disable ACPI entirely
1788 */
1789 error = acpi_blacklisted();
1790 if (error) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 if (acpi_force) {
1792 printk(KERN_WARNING PREFIX "acpi=force override\n");
1793 } else {
1794 printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
1795 disable_acpi();
1796 return error;
1797 }
1798 }
1799
1800 return 0;
1801}
1802
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001803int __init early_acpi_boot_init(void)
1804{
1805 /*
1806 * If acpi_disabled, bail out
1807 * One exception: acpi=ht continues far enough to enumerate LAPICs
1808 */
1809 if (acpi_disabled && !acpi_ht)
1810 return 1;
1811
1812 /*
1813 * Process the Multiple APIC Description Table (MADT), if present
1814 */
1815 early_acpi_process_madt();
1816
1817 return 0;
1818}
1819
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820int __init acpi_boot_init(void)
1821{
Andreas Herrmann35af2822008-10-22 13:08:31 +02001822 /* those are executed after early-quirks are executed */
1823 dmi_check_system(acpi_dmi_table_late);
1824
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 /*
1826 * If acpi_disabled, bail out
1827 * One exception: acpi=ht continues far enough to enumerate LAPICs
1828 */
1829 if (acpi_disabled && !acpi_ht)
Len Brown4be44fc2005-08-05 00:44:28 -04001830 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001832 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833
1834 /*
1835 * set sci_int and PM timer address
1836 */
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +03001837 acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838
1839 /*
1840 * Process the Multiple APIC Description Table (MADT), if present
1841 */
1842 acpi_process_madt();
1843
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001844 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845
1846 return 0;
1847}
Rusty Russell1a3f2392006-09-26 10:52:32 +02001848
1849static int __init parse_acpi(char *arg)
1850{
1851 if (!arg)
1852 return -EINVAL;
1853
1854 /* "acpi=off" disables both ACPI table parsing and interpreter */
1855 if (strcmp(arg, "off") == 0) {
1856 disable_acpi();
1857 }
1858 /* acpi=force to over-ride black-list */
1859 else if (strcmp(arg, "force") == 0) {
1860 acpi_force = 1;
1861 acpi_ht = 1;
1862 acpi_disabled = 0;
1863 }
1864 /* acpi=strict disables out-of-spec workarounds */
1865 else if (strcmp(arg, "strict") == 0) {
1866 acpi_strict = 1;
1867 }
1868 /* Limit ACPI just to boot-time to enable HT */
1869 else if (strcmp(arg, "ht") == 0) {
1870 if (!acpi_force)
1871 disable_acpi();
1872 acpi_ht = 1;
1873 }
Zhao Yakui237889b2008-12-17 16:55:18 +08001874 /* acpi=rsdt use RSDT instead of XSDT */
1875 else if (strcmp(arg, "rsdt") == 0) {
1876 acpi_rsdt_forced = 1;
1877 }
Rusty Russell1a3f2392006-09-26 10:52:32 +02001878 /* "acpi=noirq" disables ACPI interrupt routing */
1879 else if (strcmp(arg, "noirq") == 0) {
1880 acpi_noirq_set();
1881 } else {
1882 /* Core will printk when we return error. */
1883 return -EINVAL;
1884 }
1885 return 0;
1886}
1887early_param("acpi", parse_acpi);
1888
1889/* FIXME: Using pci= for an ACPI parameter is a travesty. */
1890static int __init parse_pci(char *arg)
1891{
1892 if (arg && strcmp(arg, "noacpi") == 0)
1893 acpi_disable_pci();
1894 return 0;
1895}
1896early_param("pci", parse_pci);
1897
Yinghai Lu3c999f12008-06-20 16:11:20 -07001898int __init acpi_mps_check(void)
1899{
1900#if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
1901/* mptable code is not built-in*/
1902 if (acpi_disabled || acpi_noirq) {
1903 printk(KERN_WARNING "MPS support code is not built-in.\n"
1904 "Using acpi=off or acpi=noirq or pci=noacpi "
1905 "may have problem\n");
1906 return 1;
1907 }
1908#endif
1909 return 0;
1910}
1911
Rusty Russell1a3f2392006-09-26 10:52:32 +02001912#ifdef CONFIG_X86_IO_APIC
1913static int __init parse_acpi_skip_timer_override(char *arg)
1914{
1915 acpi_skip_timer_override = 1;
1916 return 0;
1917}
1918early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
Andi Kleenfa18f472006-11-14 16:57:46 +01001919
1920static int __init parse_acpi_use_timer_override(char *arg)
1921{
1922 acpi_use_timer_override = 1;
1923 return 0;
1924}
1925early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001926#endif /* CONFIG_X86_IO_APIC */
1927
1928static int __init setup_acpi_sci(char *s)
1929{
1930 if (!s)
1931 return -EINVAL;
1932 if (!strcmp(s, "edge"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001933 acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
1934 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001935 else if (!strcmp(s, "level"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001936 acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
1937 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001938 else if (!strcmp(s, "high"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001939 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
1940 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001941 else if (!strcmp(s, "low"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001942 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
1943 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001944 else
1945 return -EINVAL;
1946 return 0;
1947}
1948early_param("acpi_sci", setup_acpi_sci);
Andrew Mortond0a90812006-10-20 14:30:27 -07001949
1950int __acpi_acquire_global_lock(unsigned int *lock)
1951{
1952 unsigned int old, new, val;
1953 do {
1954 old = *lock;
1955 new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
1956 val = cmpxchg(lock, old, new);
1957 } while (unlikely (val != old));
1958 return (new < 3) ? -1 : 0;
1959}
1960
1961int __acpi_release_global_lock(unsigned int *lock)
1962{
1963 unsigned int old, new, val;
1964 do {
1965 old = *lock;
1966 new = old & ~0x3;
1967 val = cmpxchg(lock, old, new);
1968 } while (unlikely (val != old));
1969 return old & 0x1;
1970}