blob: 4c2aaea42930e3fdd4ab755c1fec5f02cf1a8245 [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>
Ingo Molnar183fe062008-07-09 11:32:10 +020040#include <asm/genapic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/mpspec.h>
Alexey Starikovskiydfac2182008-04-04 23:41:50 +040043#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Glauber de Oliveira Costaf6bc4022008-03-19 14:25:53 -030045#ifdef CONFIG_X86_LOCAL_APIC
46# include <mach_apic.h>
47#endif
48
Adrian Bunke8924ac2006-09-26 10:52:35 +020049static int __initdata acpi_force = 0;
Zhao Yakui237889b2008-12-17 16:55:18 +080050u32 acpi_rsdt_forced;
Andi Kleendf3bb572006-09-26 10:52:33 +020051#ifdef CONFIG_ACPI
52int acpi_disabled = 0;
53#else
54int acpi_disabled = 1;
55#endif
56EXPORT_SYMBOL(acpi_disabled);
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#ifdef CONFIG_X86_64
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#include <asm/proto.h>
Linus Torvalds637029c2006-02-27 20:41:56 -080061
Len Brown4be44fc2005-08-05 00:44:28 -040062#else /* X86 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64#ifdef CONFIG_X86_LOCAL_APIC
65#include <mach_apic.h>
66#include <mach_mpparse.h>
Len Brown4be44fc2005-08-05 00:44:28 -040067#endif /* CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Len Brown4be44fc2005-08-05 00:44:28 -040069#endif /* X86 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71#define BAD_MADT_ENTRY(entry, end) ( \
72 (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +030073 ((struct acpi_subtable_header *)entry)->length < sizeof(*entry))
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75#define PREFIX "ACPI: "
76
Andrew Morton90d53902006-11-02 22:07:18 -080077int acpi_noirq; /* skip ACPI IRQ initialization */
Yinghai Lu6e4be1f2008-02-05 00:01:48 -080078int acpi_pci_disabled; /* skip ACPI PCI scan and IRQ initialization */
79EXPORT_SYMBOL(acpi_pci_disabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080int acpi_ht __initdata = 1; /* enable HT */
81
82int acpi_lapic;
83int acpi_ioapic;
84int acpi_strict;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +030086u8 acpi_sci_flags __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087int acpi_sci_override_gsi __initdata;
88int acpi_skip_timer_override __initdata;
Andi Kleenfa18f472006-11-14 16:57:46 +010089int acpi_use_timer_override __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91#ifdef CONFIG_X86_LOCAL_APIC
92static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
93#endif
94
95#ifndef __HAVE_ARCH_CMPXCHG
96#warning ACPI uses CMPXCHG, i486 and later hardware
97#endif
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/* --------------------------------------------------------------------------
100 Boot-time Configuration
101 -------------------------------------------------------------------------- */
102
103/*
104 * The default interrupt routing model is PIC (8259). This gets
Simon Arlott27b46d72007-10-20 01:13:56 +0200105 * overridden if IOAPICs are enumerated (below).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 */
Len Brown4be44fc2005-08-05 00:44:28 -0400107enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110/*
111 * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
112 * to map the target physical address. The problem is that set_fixmap()
113 * provides a single page, and it is possible that the page is not
114 * sufficient.
115 * By using this area, we can map up to MAX_IO_APICS pages temporarily,
116 * i.e. until the next __va_range() call.
117 *
118 * Important Safety Note: The fixed I/O APIC page numbers are *subtracted*
119 * from the fixed base. That's why we start at FIX_IO_APIC_BASE_END and
120 * count idx down while incrementing the phys address.
121 */
Jan Beulich2fdf0742007-12-13 08:33:59 +0000122char *__init __acpi_map_table(unsigned long phys, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
Jeremy Fitzhardinge05876f82009-02-07 15:39:40 -0800124
Yinghai Luf34fa822008-07-09 20:16:36 -0700125 if (!phys || !size)
126 return NULL;
127
Yinghai Lu7d972772009-02-07 15:39:41 -0800128 return early_ioremap(phys, size);
129}
130void __init __acpi_unmap_table(char *map, unsigned long size)
131{
132 if (!map || !size)
133 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Yinghai Lu7d972772009-02-07 15:39:41 -0800135 early_iounmap(map, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138#ifdef CONFIG_PCI_MMCONFIG
Pavel Vasilyev1339c362008-10-15 17:33:48 -0400139
140static int acpi_mcfg_64bit_base_addr __initdata = FALSE;
141
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700142/* The physical address of the MMCONFIG aperture. Set from ACPI tables. */
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300143struct acpi_mcfg_allocation *pci_mmcfg_config;
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700144int pci_mmcfg_config_num;
145
John Kellera726c602008-07-29 14:34:16 -0500146static int __init acpi_mcfg_oem_check(struct acpi_table_mcfg *mcfg)
147{
148 if (!strcmp(mcfg->header.oem_id, "SGI"))
149 acpi_mcfg_64bit_base_addr = TRUE;
150
151 return 0;
152}
153
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300154int __init acpi_parse_mcfg(struct acpi_table_header *header)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
156 struct acpi_table_mcfg *mcfg;
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700157 unsigned long i;
158 int config_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300160 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 return -EINVAL;
162
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300163 mcfg = (struct acpi_table_mcfg *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700165 /* how many config structures do we have */
166 pci_mmcfg_config_num = 0;
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300167 i = header->length - sizeof(struct acpi_table_mcfg);
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300168 while (i >= sizeof(struct acpi_mcfg_allocation)) {
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700169 ++pci_mmcfg_config_num;
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300170 i -= sizeof(struct acpi_mcfg_allocation);
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700171 };
172 if (pci_mmcfg_config_num == 0) {
173 printk(KERN_ERR PREFIX "MMCONFIG has no entries\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 return -ENODEV;
175 }
176
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700177 config_size = pci_mmcfg_config_num * sizeof(*pci_mmcfg_config);
178 pci_mmcfg_config = kmalloc(config_size, GFP_KERNEL);
179 if (!pci_mmcfg_config) {
180 printk(KERN_WARNING PREFIX
181 "No memory for MCFG config tables\n");
182 return -ENOMEM;
183 }
184
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300185 memcpy(pci_mmcfg_config, &mcfg[1], config_size);
John Kellera726c602008-07-29 14:34:16 -0500186
187 acpi_mcfg_oem_check(mcfg);
188
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700189 for (i = 0; i < pci_mmcfg_config_num; ++i) {
John Kellera726c602008-07-29 14:34:16 -0500190 if ((pci_mmcfg_config[i].address > 0xFFFFFFFF) &&
191 !acpi_mcfg_64bit_base_addr) {
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700192 printk(KERN_ERR PREFIX
193 "MMCONFIG not in low 4GB of memory\n");
Konrad Rzeszutekacc7c2e2006-06-15 12:08:30 -0400194 kfree(pci_mmcfg_config);
195 pci_mmcfg_config_num = 0;
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700196 return -ENODEV;
197 }
198 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 return 0;
201}
Len Brown4be44fc2005-08-05 00:44:28 -0400202#endif /* CONFIG_PCI_MMCONFIG */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204#ifdef CONFIG_X86_LOCAL_APIC
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300205static int __init acpi_parse_madt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206{
Len Brown4be44fc2005-08-05 00:44:28 -0400207 struct acpi_table_madt *madt = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300209 if (!cpu_has_apic)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 return -EINVAL;
211
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300212 madt = (struct acpi_table_madt *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 if (!madt) {
214 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
215 return -ENODEV;
216 }
217
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300218 if (madt->address) {
219 acpi_lapic_addr = (u64) madt->address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221 printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300222 madt->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 }
224
225 acpi_madt_oem_check(madt->header.oem_id, madt->header.oem_table_id);
Len Brown4be44fc2005-08-05 00:44:28 -0400226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 return 0;
228}
229
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400230static void __cpuinit acpi_register_lapic(int id, u8 enabled)
231{
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700232 unsigned int ver = 0;
233
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400234 if (!enabled) {
235 ++disabled_cpus;
236 return;
237 }
238
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700239 if (boot_cpu_physical_apicid != -1U)
240 ver = apic_version[boot_cpu_physical_apicid];
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700241
242 generic_processor_info(id, ver);
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400243}
244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300246acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300248 struct acpi_madt_local_apic *processor = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300250 processor = (struct acpi_madt_local_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
252 if (BAD_MADT_ENTRY(processor, end))
253 return -EINVAL;
254
255 acpi_table_print_madt_entry(header);
256
Ashok Raj7f66ae42006-02-03 21:51:50 +0100257 /*
258 * We need to register disabled CPU as well to permit
259 * counting disabled CPUs. This allows us to size
260 * cpus_possible_map more accurately, to permit
261 * to not preallocating memory for all NR_CPUS
262 * when we use CPU hotplug.
263 */
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400264 acpi_register_lapic(processor->id, /* APIC ID */
265 processor->lapic_flags & ACPI_MADT_ENABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267 return 0;
268}
269
270static int __init
Jack Steinerac049c12008-03-28 14:12:09 -0500271acpi_parse_sapic(struct acpi_subtable_header *header, const unsigned long end)
272{
273 struct acpi_madt_local_sapic *processor = NULL;
274
275 processor = (struct acpi_madt_local_sapic *)header;
276
277 if (BAD_MADT_ENTRY(processor, end))
278 return -EINVAL;
279
280 acpi_table_print_madt_entry(header);
281
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400282 acpi_register_lapic((processor->id << 8) | processor->eid,/* APIC ID */
283 processor->lapic_flags & ACPI_MADT_ENABLED);
Jack Steinerac049c12008-03-28 14:12:09 -0500284
285 return 0;
286}
287
288static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300289acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400290 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300292 struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300294 lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296 if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
297 return -EINVAL;
298
299 acpi_lapic_addr = lapic_addr_ovr->address;
300
301 return 0;
302}
303
304static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300305acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300307 struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300309 lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311 if (BAD_MADT_ENTRY(lapic_nmi, end))
312 return -EINVAL;
313
314 acpi_table_print_madt_entry(header);
315
316 if (lapic_nmi->lint != 1)
317 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
318
319 return 0;
320}
321
Len Brown4be44fc2005-08-05 00:44:28 -0400322#endif /*CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Len Brown84663612005-08-24 12:09:07 -0400324#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
326static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300327acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300329 struct acpi_madt_io_apic *ioapic = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300331 ioapic = (struct acpi_madt_io_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
333 if (BAD_MADT_ENTRY(ioapic, end))
334 return -EINVAL;
Len Brown4be44fc2005-08-05 00:44:28 -0400335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 acpi_table_print_madt_entry(header);
337
Len Brown4be44fc2005-08-05 00:44:28 -0400338 mp_register_ioapic(ioapic->id,
339 ioapic->address, ioapic->global_irq_base);
340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 return 0;
342}
343
344/*
345 * Parse Interrupt Source Override for the ACPI SCI
346 */
Len Browne82c3542006-12-21 01:29:59 -0500347static void __init acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
349 if (trigger == 0) /* compatible SCI trigger is level */
350 trigger = 3;
351
352 if (polarity == 0) /* compatible SCI polarity is low */
353 polarity = 3;
354
355 /* Command-line over-ride via acpi_sci= */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300356 if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
357 trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300359 if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
360 polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 /*
Len Brown4be44fc2005-08-05 00:44:28 -0400363 * mp_config_acpi_legacy_irqs() already setup IRQs < 16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 * If GSI is < 16, this will update its flags,
365 * else it will create a new mp_irqs[] entry.
366 */
Len Brown7bdd21c2006-12-02 02:27:46 -0500367 mp_override_legacy_irq(gsi, polarity, trigger, gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
369 /*
370 * stash over-ride to indicate we've been here
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300371 * and for later update of acpi_gbl_FADT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 */
Len Brown7bdd21c2006-12-02 02:27:46 -0500373 acpi_sci_override_gsi = gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 return;
375}
376
377static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300378acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400379 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300381 struct acpi_madt_interrupt_override *intsrc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300383 intsrc = (struct acpi_madt_interrupt_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385 if (BAD_MADT_ENTRY(intsrc, end))
386 return -EINVAL;
387
388 acpi_table_print_madt_entry(header);
389
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300390 if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
Len Brown7bdd21c2006-12-02 02:27:46 -0500391 acpi_sci_ioapic_setup(intsrc->global_irq,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300392 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
393 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 return 0;
395 }
396
397 if (acpi_skip_timer_override &&
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300398 intsrc->source_irq == 0 && intsrc->global_irq == 2) {
Len Brown4be44fc2005-08-05 00:44:28 -0400399 printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
400 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 }
402
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300403 mp_override_legacy_irq(intsrc->source_irq,
404 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
405 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
406 intsrc->global_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
408 return 0;
409}
410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300412acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300414 struct acpi_madt_nmi_source *nmi_src = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300416 nmi_src = (struct acpi_madt_nmi_source *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418 if (BAD_MADT_ENTRY(nmi_src, end))
419 return -EINVAL;
420
421 acpi_table_print_madt_entry(header);
422
423 /* TBD: Support nimsrc entries? */
424
425 return 0;
426}
427
Len Brown4be44fc2005-08-05 00:44:28 -0400428#endif /* CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430/*
431 * acpi_pic_sci_set_trigger()
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300432 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 * use ELCR to set PIC-mode trigger type for SCI
434 *
435 * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
436 * it may require Edge Trigger -- use "acpi_sci=edge"
437 *
438 * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
439 * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
Simon Arlott27b46d72007-10-20 01:13:56 +0200440 * ECLR1 is IRQs 0-7 (IRQ 0, 1, 2 must be 0)
441 * ECLR2 is IRQs 8-15 (IRQ 8, 13 must be 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 */
443
Len Brown4be44fc2005-08-05 00:44:28 -0400444void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
446 unsigned int mask = 1 << irq;
447 unsigned int old, new;
448
449 /* Real old ELCR mask */
450 old = inb(0x4d0) | (inb(0x4d1) << 8);
451
452 /*
Simon Arlott27b46d72007-10-20 01:13:56 +0200453 * If we use ACPI to set PCI IRQs, then we should clear ELCR
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 * since we will set it correctly as we enable the PCI irq
455 * routing.
456 */
457 new = acpi_noirq ? old : 0;
458
459 /*
460 * Update SCI information in the ELCR, it isn't in the PCI
461 * routing tables..
462 */
463 switch (trigger) {
Len Brown4be44fc2005-08-05 00:44:28 -0400464 case 1: /* Edge - clear */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 new &= ~mask;
466 break;
Len Brown4be44fc2005-08-05 00:44:28 -0400467 case 3: /* Level - set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 new |= mask;
469 break;
470 }
471
472 if (old == new)
473 return;
474
475 printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
476 outb(new, 0x4d0);
477 outb(new >> 8, 0x4d1);
478}
479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
481{
Eric W. Biedermanf023d762006-10-04 02:16:52 -0700482 *irq = gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 return 0;
484}
485
Kenji Kaneshige1f3a6a12005-07-28 14:42:00 -0400486/*
487 * success: return IRQ number (>=0)
488 * failure: return < 0
489 */
Len Browncb654692005-12-28 02:43:51 -0500490int acpi_register_gsi(u32 gsi, int triggering, int polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
492 unsigned int irq;
493 unsigned int plat_gsi = gsi;
494
495#ifdef CONFIG_PCI
496 /*
497 * Make sure all (legacy) PCI IRQs are set as level-triggered.
498 */
499 if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
Len Browncb654692005-12-28 02:43:51 -0500500 if (triggering == ACPI_LEVEL_SENSITIVE)
Len Brown4be44fc2005-08-05 00:44:28 -0400501 eisa_set_level_irq(gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 }
503#endif
504
505#ifdef CONFIG_X86_IO_APIC
506 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) {
Len Browncb654692005-12-28 02:43:51 -0500507 plat_gsi = mp_register_gsi(gsi, triggering, polarity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 }
509#endif
510 acpi_gsi_to_irq(plat_gsi, &irq);
511 return irq;
512}
Len Brown4be44fc2005-08-05 00:44:28 -0400513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514/*
515 * ACPI based hotplug support for CPU
516 */
517#ifdef CONFIG_ACPI_HOTPLUG_CPU
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100518
519static int __cpuinit _acpi_map_lsapic(acpi_handle handle, int *pcpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520{
Ashok Raj73fea172006-09-26 10:52:35 +0200521 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
522 union acpi_object *obj;
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300523 struct acpi_madt_local_apic *lapic;
Rusty Russellee943a82008-12-31 18:08:47 -0800524 cpumask_var_t tmp_map, new_map;
Ashok Raj73fea172006-09-26 10:52:35 +0200525 u8 physid;
526 int cpu;
Rusty Russellee943a82008-12-31 18:08:47 -0800527 int retval = -ENOMEM;
Ashok Raj73fea172006-09-26 10:52:35 +0200528
529 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
530 return -EINVAL;
531
532 if (!buffer.length || !buffer.pointer)
533 return -EINVAL;
534
535 obj = buffer.pointer;
536 if (obj->type != ACPI_TYPE_BUFFER ||
537 obj->buffer.length < sizeof(*lapic)) {
538 kfree(buffer.pointer);
539 return -EINVAL;
540 }
541
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300542 lapic = (struct acpi_madt_local_apic *)obj->buffer.pointer;
Ashok Raj73fea172006-09-26 10:52:35 +0200543
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300544 if (lapic->header.type != ACPI_MADT_TYPE_LOCAL_APIC ||
545 !(lapic->lapic_flags & ACPI_MADT_ENABLED)) {
Ashok Raj73fea172006-09-26 10:52:35 +0200546 kfree(buffer.pointer);
547 return -EINVAL;
548 }
549
550 physid = lapic->id;
551
552 kfree(buffer.pointer);
553 buffer.length = ACPI_ALLOCATE_BUFFER;
554 buffer.pointer = NULL;
555
Rusty Russellee943a82008-12-31 18:08:47 -0800556 if (!alloc_cpumask_var(&tmp_map, GFP_KERNEL))
557 goto out;
558
559 if (!alloc_cpumask_var(&new_map, GFP_KERNEL))
560 goto free_tmp_map;
561
562 cpumask_copy(tmp_map, cpu_present_mask);
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400563 acpi_register_lapic(physid, lapic->lapic_flags & ACPI_MADT_ENABLED);
Ashok Raj73fea172006-09-26 10:52:35 +0200564
565 /*
566 * If mp_register_lapic successfully generates a new logical cpu
567 * number, then the following will get us exactly what was mapped
568 */
Rusty Russellee943a82008-12-31 18:08:47 -0800569 cpumask_andnot(new_map, cpu_present_mask, tmp_map);
570 if (cpumask_empty(new_map)) {
Ashok Raj73fea172006-09-26 10:52:35 +0200571 printk ("Unable to map lapic to logical cpu number\n");
Rusty Russellee943a82008-12-31 18:08:47 -0800572 retval = -EINVAL;
573 goto free_new_map;
Ashok Raj73fea172006-09-26 10:52:35 +0200574 }
575
Rusty Russellee943a82008-12-31 18:08:47 -0800576 cpu = cpumask_first(new_map);
Ashok Raj73fea172006-09-26 10:52:35 +0200577
578 *pcpu = cpu;
Rusty Russellee943a82008-12-31 18:08:47 -0800579 retval = 0;
580
581free_new_map:
582 free_cpumask_var(new_map);
583free_tmp_map:
584 free_cpumask_var(tmp_map);
585out:
586 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587}
Len Brown4be44fc2005-08-05 00:44:28 -0400588
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100589/* wrapper to silence section mismatch warning */
590int __ref acpi_map_lsapic(acpi_handle handle, int *pcpu)
591{
592 return _acpi_map_lsapic(handle, pcpu);
593}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594EXPORT_SYMBOL(acpi_map_lsapic);
595
Len Brown4be44fc2005-08-05 00:44:28 -0400596int acpi_unmap_lsapic(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597{
Mike Travis71fff5e2007-10-19 20:35:03 +0200598 per_cpu(x86_cpu_to_apicid, cpu) = -1;
Mike Travis96289372008-12-31 18:08:46 -0800599 set_cpu_present(cpu, false);
Ashok Raj73fea172006-09-26 10:52:35 +0200600 num_processors--;
601
602 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603}
Len Brown4be44fc2005-08-05 00:44:28 -0400604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605EXPORT_SYMBOL(acpi_unmap_lsapic);
Len Brown4be44fc2005-08-05 00:44:28 -0400606#endif /* CONFIG_ACPI_HOTPLUG_CPU */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Len Brown4be44fc2005-08-05 00:44:28 -0400608int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700609{
610 /* TBD */
611 return -EINVAL;
612}
Len Brown4be44fc2005-08-05 00:44:28 -0400613
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700614EXPORT_SYMBOL(acpi_register_ioapic);
615
Len Brown4be44fc2005-08-05 00:44:28 -0400616int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700617{
618 /* TBD */
619 return -EINVAL;
620}
Len Brown4be44fc2005-08-05 00:44:28 -0400621
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700622EXPORT_SYMBOL(acpi_unregister_ioapic);
623
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300624static int __init acpi_parse_sbf(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300626 struct acpi_table_boot *sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300628 sb = (struct acpi_table_boot *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 if (!sb) {
630 printk(KERN_WARNING PREFIX "Unable to map SBF\n");
631 return -ENODEV;
632 }
633
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300634 sbf_port = sb->cmos_index; /* Save CMOS port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
636 return 0;
637}
638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639#ifdef CONFIG_HPET_TIMER
john stultz2d0c87c2007-02-16 01:28:18 -0800640#include <asm/hpet.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Aaron Durbina1dfd852007-07-21 17:11:39 +0200642static struct __initdata resource *hpet_res;
643
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300644static int __init acpi_parse_hpet(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645{
646 struct acpi_table_hpet *hpet_tbl;
647
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300648 hpet_tbl = (struct acpi_table_hpet *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 if (!hpet_tbl) {
650 printk(KERN_WARNING PREFIX "Unable to map HPET\n");
651 return -ENODEV;
652 }
653
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300654 if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 printk(KERN_WARNING PREFIX "HPET timers must be located in "
656 "memory.\n");
657 return -1;
658 }
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200659
john stultz2d0c87c2007-02-16 01:28:18 -0800660 hpet_address = hpet_tbl->address.address;
Thomas Gleixnerf4df73c2007-11-15 21:41:50 -0500661
662 /*
663 * Some broken BIOSes advertise HPET at 0x0. We really do not
664 * want to allocate a resource there.
665 */
666 if (!hpet_address) {
667 printk(KERN_WARNING PREFIX
668 "HPET id: %#x base: %#lx is invalid\n",
669 hpet_tbl->id, hpet_address);
670 return 0;
671 }
672#ifdef CONFIG_X86_64
673 /*
674 * Some even more broken BIOSes advertise HPET at
675 * 0xfed0000000000000 instead of 0xfed00000. Fix it up and add
676 * some noise:
677 */
678 if (hpet_address == 0xfed0000000000000UL) {
679 if (!hpet_force_user) {
680 printk(KERN_WARNING PREFIX "HPET id: %#x "
681 "base: 0xfed0000000000000 is bogus\n "
682 "try hpet=force on the kernel command line to "
683 "fix it up to 0xfed00000.\n", hpet_tbl->id);
684 hpet_address = 0;
685 return 0;
686 }
687 printk(KERN_WARNING PREFIX
688 "HPET id: %#x base: 0xfed0000000000000 fixed up "
689 "to 0xfed00000.\n", hpet_tbl->id);
690 hpet_address >>= 32;
691 }
692#endif
Len Brown4be44fc2005-08-05 00:44:28 -0400693 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
john stultz2d0c87c2007-02-16 01:28:18 -0800694 hpet_tbl->id, hpet_address);
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200695
Aaron Durbina1dfd852007-07-21 17:11:39 +0200696 /*
697 * Allocate and initialize the HPET firmware resource for adding into
698 * the resource tree during the lateinit timeframe.
699 */
700#define HPET_RESOURCE_NAME_SIZE 9
701 hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
702
Aaron Durbina1dfd852007-07-21 17:11:39 +0200703 hpet_res->name = (void *)&hpet_res[1];
704 hpet_res->flags = IORESOURCE_MEM;
705 snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE, "HPET %u",
706 hpet_tbl->sequence);
707
708 hpet_res->start = hpet_address;
709 hpet_res->end = hpet_address + (1 * 1024) - 1;
710
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 return 0;
712}
Aaron Durbina1dfd852007-07-21 17:11:39 +0200713
714/*
715 * hpet_insert_resource inserts the HPET resources used into the resource
716 * tree.
717 */
718static __init int hpet_insert_resource(void)
719{
720 if (!hpet_res)
721 return 1;
722
723 return insert_resource(&iomem_resource, hpet_res);
724}
725
726late_initcall(hpet_insert_resource);
727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728#else
729#define acpi_parse_hpet NULL
730#endif
731
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300732static int __init acpi_parse_fadt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733{
Jason Davis90660ec2005-04-16 15:24:53 -0700734
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735#ifdef CONFIG_X86_PM_TIMER
736 /* detect the location of the ACPI PM Timer */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300737 if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 /* FADT rev. 2 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300739 if (acpi_gbl_FADT.xpm_timer_block.space_id !=
Len Brown4be44fc2005-08-05 00:44:28 -0400740 ACPI_ADR_SPACE_SYSTEM_IO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 return 0;
742
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300743 pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
David Shaohua Lie6e87b42005-09-21 01:35:00 -0400744 /*
745 * "X" fields are optional extensions to the original V1.0
746 * fields, so we must selectively expand V1.0 fields if the
747 * corresponding X field is zero.
748 */
749 if (!pmtmr_ioport)
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300750 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 } else {
752 /* FADT rev. 1 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300753 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 }
755 if (pmtmr_ioport)
Len Brown4be44fc2005-08-05 00:44:28 -0400756 printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
757 pmtmr_ioport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758#endif
759 return 0;
760}
761
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762#ifdef CONFIG_X86_LOCAL_APIC
763/*
764 * Parse LAPIC entries in MADT
765 * returns 0 on success, < 0 on error
766 */
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400767
768static void __init acpi_register_lapic_address(unsigned long address)
769{
770 mp_lapic_addr = address;
771
772 set_fixmap_nocache(FIX_APIC_BASE, address);
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700773 if (boot_cpu_physical_apicid == -1U) {
Yinghai Lu4c9961d2008-07-11 18:44:16 -0700774 boot_cpu_physical_apicid = read_apic_id();
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700775 apic_version[boot_cpu_physical_apicid] =
776 GET_APIC_VERSION(apic_read(APIC_LVR));
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700777 }
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400778}
779
Yinghai Lucbf9bd62008-02-19 03:21:06 -0800780static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
781{
782 int count;
783
784 if (!cpu_has_apic)
785 return -ENODEV;
786
787 /*
788 * Note that the LAPIC address is obtained from the MADT (32-bit value)
789 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
790 */
791
792 count =
793 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
794 acpi_parse_lapic_addr_ovr, 0);
795 if (count < 0) {
796 printk(KERN_ERR PREFIX
797 "Error parsing LAPIC address override entry\n");
798 return count;
799 }
800
801 acpi_register_lapic_address(acpi_lapic_addr);
802
803 return count;
804}
805
Len Brown4be44fc2005-08-05 00:44:28 -0400806static int __init acpi_parse_madt_lapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807{
808 int count;
809
Andi Kleen0fcd2702006-04-11 12:54:36 +0200810 if (!cpu_has_apic)
811 return -ENODEV;
812
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300813 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 * Note that the LAPIC address is obtained from the MADT (32-bit value)
815 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
816 */
817
Len Brown4be44fc2005-08-05 00:44:28 -0400818 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300819 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
Len Brown4be44fc2005-08-05 00:44:28 -0400820 acpi_parse_lapic_addr_ovr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 if (count < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400822 printk(KERN_ERR PREFIX
823 "Error parsing LAPIC address override entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 return count;
825 }
826
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400827 acpi_register_lapic_address(acpi_lapic_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Jack Steinerac049c12008-03-28 14:12:09 -0500829 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
830 acpi_parse_sapic, MAX_APICS);
831
832 if (!count)
833 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
834 acpi_parse_lapic, MAX_APICS);
Len Brown4be44fc2005-08-05 00:44:28 -0400835 if (!count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
837 /* TBD: Cleanup to allow fallback to MPS */
838 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400839 } else if (count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
841 /* TBD: Cleanup to allow fallback to MPS */
842 return count;
843 }
844
Len Brown4be44fc2005-08-05 00:44:28 -0400845 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300846 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 if (count < 0) {
848 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
849 /* TBD: Cleanup to allow fallback to MPS */
850 return count;
851 }
852 return 0;
853}
Len Brown4be44fc2005-08-05 00:44:28 -0400854#endif /* CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
Len Brown84663612005-08-24 12:09:07 -0400856#ifdef CONFIG_X86_IO_APIC
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400857#define MP_ISA_BUS 0
858
Yinghai Lud49c4282008-06-08 18:31:54 -0700859#ifdef CONFIG_X86_ES7000
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400860extern int es7000_plat;
861#endif
862
Alexey Starikovskiy5f895142008-05-14 19:03:04 +0400863static struct {
864 int apic_id;
865 int gsi_base;
866 int gsi_end;
867 DECLARE_BITMAP(pin_programmed, MP_MAX_IOAPIC_PIN + 1);
868} mp_ioapic_routing[MAX_IO_APICS];
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400869
870static int mp_find_ioapic(int gsi)
871{
872 int i = 0;
873
874 /* Find the IOAPIC that manages this GSI. */
875 for (i = 0; i < nr_ioapics; i++) {
876 if ((gsi >= mp_ioapic_routing[i].gsi_base)
877 && (gsi <= mp_ioapic_routing[i].gsi_end))
878 return i;
879 }
880
881 printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
882 return -1;
883}
884
885static u8 __init uniq_ioapic_id(u8 id)
886{
887#ifdef CONFIG_X86_32
888 if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
889 !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
890 return io_apic_get_unique_id(nr_ioapics, id);
891 else
892 return id;
893#else
894 int i;
895 DECLARE_BITMAP(used, 256);
896 bitmap_zero(used, 256);
897 for (i = 0; i < nr_ioapics; i++) {
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400898 struct mp_config_ioapic *ia = &mp_ioapics[i];
899 __set_bit(ia->mp_apicid, used);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400900 }
901 if (!test_bit(id, used))
902 return id;
903 return find_first_zero_bit(used, 256);
904#endif
905}
906
907static int bad_ioapic(unsigned long address)
908{
909 if (nr_ioapics >= MAX_IO_APICS) {
910 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
911 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
912 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
913 }
914 if (!address) {
915 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
916 " found in table, skipping!\n");
917 return 1;
918 }
919 return 0;
920}
921
922void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
923{
924 int idx = 0;
925
926 if (bad_ioapic(address))
927 return;
928
929 idx = nr_ioapics;
930
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400931 mp_ioapics[idx].mp_type = MP_IOAPIC;
932 mp_ioapics[idx].mp_flags = MPC_APIC_USABLE;
933 mp_ioapics[idx].mp_apicaddr = address;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400934
935 set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400936 mp_ioapics[idx].mp_apicid = uniq_ioapic_id(id);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400937#ifdef CONFIG_X86_32
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400938 mp_ioapics[idx].mp_apicver = io_apic_get_version(idx);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400939#else
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400940 mp_ioapics[idx].mp_apicver = 0;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400941#endif
942 /*
943 * Build basic GSI lookup table to facilitate gsi->io_apic lookups
944 * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
945 */
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400946 mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].mp_apicid;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400947 mp_ioapic_routing[idx].gsi_base = gsi_base;
948 mp_ioapic_routing[idx].gsi_end = gsi_base +
949 io_apic_get_redir_entries(idx);
950
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400951 printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%lx, "
952 "GSI %d-%d\n", idx, mp_ioapics[idx].mp_apicid,
953 mp_ioapics[idx].mp_apicver, mp_ioapics[idx].mp_apicaddr,
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400954 mp_ioapic_routing[idx].gsi_base, mp_ioapic_routing[idx].gsi_end);
955
956 nr_ioapics++;
957}
958
Yinghai Lufcfa1462008-06-18 17:29:31 -0700959static void assign_to_mp_irq(struct mp_config_intsrc *m,
960 struct mp_config_intsrc *mp_irq)
961{
962 memcpy(mp_irq, m, sizeof(struct mp_config_intsrc));
963}
964
965static int mp_irq_cmp(struct mp_config_intsrc *mp_irq,
966 struct mp_config_intsrc *m)
967{
968 return memcmp(mp_irq, m, sizeof(struct mp_config_intsrc));
969}
970
971static void save_mp_irq(struct mp_config_intsrc *m)
972{
973 int i;
974
975 for (i = 0; i < mp_irq_entries; i++) {
976 if (!mp_irq_cmp(&mp_irqs[i], m))
977 return;
978 }
979
980 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
981 if (++mp_irq_entries == MAX_IRQ_SOURCES)
982 panic("Max # of irq sources exceeded!!\n");
983}
984
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400985void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
986{
Yinghai Lu6df88092008-06-15 18:19:46 -0700987 int ioapic;
988 int pin;
Yinghai Lufcfa1462008-06-18 17:29:31 -0700989 struct mp_config_intsrc mp_irq;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400990
991 /*
992 * Convert 'gsi' to 'ioapic.pin'.
993 */
994 ioapic = mp_find_ioapic(gsi);
995 if (ioapic < 0)
996 return;
997 pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
998
999 /*
1000 * TBD: This check is for faulty timer entries, where the override
1001 * erroneously sets the trigger to level, resulting in a HUGE
1002 * increase of timer interrupts!
1003 */
1004 if ((bus_irq == 0) && (trigger == 3))
1005 trigger = 1;
1006
Yinghai Lufcfa1462008-06-18 17:29:31 -07001007 mp_irq.mp_type = MP_INTSRC;
1008 mp_irq.mp_irqtype = mp_INT;
1009 mp_irq.mp_irqflag = (trigger << 2) | polarity;
1010 mp_irq.mp_srcbus = MP_ISA_BUS;
1011 mp_irq.mp_srcbusirq = bus_irq; /* IRQ */
1012 mp_irq.mp_dstapic = mp_ioapics[ioapic].mp_apicid; /* APIC ID */
1013 mp_irq.mp_dstirq = pin; /* INTIN# */
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001014
Yinghai Lufcfa1462008-06-18 17:29:31 -07001015 save_mp_irq(&mp_irq);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001016}
1017
1018void __init mp_config_acpi_legacy_irqs(void)
1019{
Yinghai Lu6df88092008-06-15 18:19:46 -07001020 int i;
1021 int ioapic;
1022 unsigned int dstapic;
Yinghai Lufcfa1462008-06-18 17:29:31 -07001023 struct mp_config_intsrc mp_irq;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001024
1025#if defined (CONFIG_MCA) || defined (CONFIG_EISA)
1026 /*
1027 * Fabricate the legacy ISA bus (bus #31).
1028 */
1029 mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
1030#endif
1031 set_bit(MP_ISA_BUS, mp_bus_not_pci);
Thomas Gleixnercfc1b9a2008-07-21 21:35:38 +02001032 pr_debug("Bus #%d is ISA\n", MP_ISA_BUS);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001033
Yinghai Lud49c4282008-06-08 18:31:54 -07001034#ifdef CONFIG_X86_ES7000
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001035 /*
1036 * Older generations of ES7000 have no legacy identity mappings
1037 */
1038 if (es7000_plat == 1)
1039 return;
1040#endif
1041
1042 /*
1043 * Locate the IOAPIC that manages the ISA IRQs (0-15).
1044 */
1045 ioapic = mp_find_ioapic(0);
1046 if (ioapic < 0)
1047 return;
Yinghai Lu6df88092008-06-15 18:19:46 -07001048 dstapic = mp_ioapics[ioapic].mp_apicid;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001049
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001050 /*
1051 * Use the default configuration for the IRQs 0-15. Unless
1052 * overridden by (MADT) interrupt source override entries.
1053 */
1054 for (i = 0; i < 16; i++) {
1055 int idx;
1056
1057 for (idx = 0; idx < mp_irq_entries; idx++) {
Alexey Starikovskiy2fddb6e282008-05-14 19:03:17 +04001058 struct mp_config_intsrc *irq = mp_irqs + idx;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001059
1060 /* Do we already have a mapping for this ISA IRQ? */
Alexey Starikovskiy2fddb6e282008-05-14 19:03:17 +04001061 if (irq->mp_srcbus == MP_ISA_BUS
1062 && irq->mp_srcbusirq == i)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001063 break;
1064
1065 /* Do we already have a mapping for this IOAPIC pin */
Yinghai Lu6df88092008-06-15 18:19:46 -07001066 if (irq->mp_dstapic == dstapic &&
1067 irq->mp_dstirq == i)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001068 break;
1069 }
1070
1071 if (idx != mp_irq_entries) {
1072 printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
1073 continue; /* IRQ already used */
1074 }
1075
Yinghai Lufcfa1462008-06-18 17:29:31 -07001076 mp_irq.mp_type = MP_INTSRC;
1077 mp_irq.mp_irqflag = 0; /* Conforming */
1078 mp_irq.mp_srcbus = MP_ISA_BUS;
1079 mp_irq.mp_dstapic = dstapic;
1080 mp_irq.mp_irqtype = mp_INT;
1081 mp_irq.mp_srcbusirq = i; /* Identity mapped */
1082 mp_irq.mp_dstirq = i;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001083
Yinghai Lufcfa1462008-06-18 17:29:31 -07001084 save_mp_irq(&mp_irq);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001085 }
1086}
1087
1088int mp_register_gsi(u32 gsi, int triggering, int polarity)
1089{
1090 int ioapic;
1091 int ioapic_pin;
1092#ifdef CONFIG_X86_32
1093#define MAX_GSI_NUM 4096
1094#define IRQ_COMPRESSION_START 64
1095
1096 static int pci_irq = IRQ_COMPRESSION_START;
1097 /*
1098 * Mapping between Global System Interrupts, which
1099 * represent all possible interrupts, and IRQs
1100 * assigned to actual devices.
1101 */
1102 static int gsi_to_irq[MAX_GSI_NUM];
1103#else
1104
1105 if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
1106 return gsi;
1107#endif
1108
1109 /* Don't set up the ACPI SCI because it's already set up */
1110 if (acpi_gbl_FADT.sci_interrupt == gsi)
1111 return gsi;
1112
1113 ioapic = mp_find_ioapic(gsi);
1114 if (ioapic < 0) {
1115 printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
1116 return gsi;
1117 }
1118
1119 ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
1120
1121#ifdef CONFIG_X86_32
1122 if (ioapic_renumber_irq)
1123 gsi = ioapic_renumber_irq(ioapic, gsi);
1124#endif
1125
1126 /*
1127 * Avoid pin reprogramming. PRTs typically include entries
1128 * with redundant pin->gsi mappings (but unique PCI devices);
1129 * we only program the IOAPIC on the first.
1130 */
1131 if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
1132 printk(KERN_ERR "Invalid reference to IOAPIC pin "
1133 "%d-%d\n", mp_ioapic_routing[ioapic].apic_id,
1134 ioapic_pin);
1135 return gsi;
1136 }
1137 if (test_bit(ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed)) {
Gustavo F. Padovan55410792008-10-15 10:37:04 -03001138 pr_debug("Pin %d-%d already programmed\n",
Thomas Gleixnercfc1b9a2008-07-21 21:35:38 +02001139 mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001140#ifdef CONFIG_X86_32
1141 return (gsi < IRQ_COMPRESSION_START ? gsi : gsi_to_irq[gsi]);
1142#else
1143 return gsi;
1144#endif
1145 }
1146
1147 set_bit(ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed);
1148#ifdef CONFIG_X86_32
1149 /*
1150 * For GSI >= 64, use IRQ compression
1151 */
1152 if ((gsi >= IRQ_COMPRESSION_START)
1153 && (triggering == ACPI_LEVEL_SENSITIVE)) {
1154 /*
1155 * For PCI devices assign IRQs in order, avoiding gaps
1156 * due to unused I/O APIC pins.
1157 */
1158 int irq = gsi;
1159 if (gsi < MAX_GSI_NUM) {
1160 /*
1161 * Retain the VIA chipset work-around (gsi > 15), but
1162 * avoid a problem where the 8254 timer (IRQ0) is setup
1163 * via an override (so it's not on pin 0 of the ioapic),
1164 * and at the same time, the pin 0 interrupt is a PCI
1165 * type. The gsi > 15 test could cause these two pins
1166 * to be shared as IRQ0, and they are not shareable.
1167 * So test for this condition, and if necessary, avoid
1168 * the pin collision.
1169 */
1170 gsi = pci_irq++;
1171 /*
1172 * Don't assign IRQ used by ACPI SCI
1173 */
1174 if (gsi == acpi_gbl_FADT.sci_interrupt)
1175 gsi = pci_irq++;
1176 gsi_to_irq[irq] = gsi;
1177 } else {
1178 printk(KERN_ERR "GSI %u is too high\n", gsi);
1179 return gsi;
1180 }
1181 }
1182#endif
1183 io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
1184 triggering == ACPI_EDGE_SENSITIVE ? 0 : 1,
1185 polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
1186 return gsi;
1187}
1188
Yinghai Lu2944e162008-06-01 13:17:38 -07001189int mp_config_acpi_gsi(unsigned char number, unsigned int devfn, u8 pin,
1190 u32 gsi, int triggering, int polarity)
1191{
Yinghai Lufcfa1462008-06-18 17:29:31 -07001192#ifdef CONFIG_X86_MPPARSE
1193 struct mp_config_intsrc mp_irq;
Yinghai Lu2944e162008-06-01 13:17:38 -07001194 int ioapic;
1195
Yinghai Lufcfa1462008-06-18 17:29:31 -07001196 if (!acpi_ioapic)
Yinghai Lud867e532008-06-14 01:26:41 -07001197 return 0;
1198
Yinghai Lu2944e162008-06-01 13:17:38 -07001199 /* print the entry should happen on mptable identically */
Yinghai Lufcfa1462008-06-18 17:29:31 -07001200 mp_irq.mp_type = MP_INTSRC;
1201 mp_irq.mp_irqtype = mp_INT;
1202 mp_irq.mp_irqflag = (triggering == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
Yinghai Lu2944e162008-06-01 13:17:38 -07001203 (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
Yinghai Lufcfa1462008-06-18 17:29:31 -07001204 mp_irq.mp_srcbus = number;
1205 mp_irq.mp_srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
Yinghai Lu2944e162008-06-01 13:17:38 -07001206 ioapic = mp_find_ioapic(gsi);
Yinghai Lufcfa1462008-06-18 17:29:31 -07001207 mp_irq.mp_dstapic = mp_ioapic_routing[ioapic].apic_id;
1208 mp_irq.mp_dstirq = gsi - mp_ioapic_routing[ioapic].gsi_base;
Yinghai Lu2944e162008-06-01 13:17:38 -07001209
Yinghai Lufcfa1462008-06-18 17:29:31 -07001210 save_mp_irq(&mp_irq);
1211#endif
Yinghai Lu2944e162008-06-01 13:17:38 -07001212 return 0;
1213}
1214
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215/*
1216 * Parse IOAPIC related entries in MADT
1217 * returns 0 on success, < 0 on error
1218 */
Len Brown4be44fc2005-08-05 00:44:28 -04001219static int __init acpi_parse_madt_ioapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220{
1221 int count;
1222
1223 /*
1224 * ACPI interpreter is required to complete interrupt setup,
1225 * so if it is off, don't enumerate the io-apics with ACPI.
1226 * If MPS is present, it will handle them,
1227 * otherwise the system will stay in PIC mode
1228 */
1229 if (acpi_disabled || acpi_noirq) {
1230 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -04001231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001233 if (!cpu_has_apic)
Andi Kleend3b6a342006-04-07 19:49:39 +02001234 return -ENODEV;
1235
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001237 * if "noapic" boot option, don't look for IO-APICs
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 */
1239 if (skip_ioapic_setup) {
1240 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
Len Brown4be44fc2005-08-05 00:44:28 -04001241 "due to 'noapic' option.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 return -ENODEV;
1243 }
1244
Len Brown4be44fc2005-08-05 00:44:28 -04001245 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001246 acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
Len Brown4be44fc2005-08-05 00:44:28 -04001247 MAX_IO_APICS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 if (!count) {
1249 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
1250 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -04001251 } else if (count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
1253 return count;
1254 }
1255
Len Brown4be44fc2005-08-05 00:44:28 -04001256 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001257 acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr,
Yinghai Lu71f521b2008-08-19 20:50:03 -07001258 nr_irqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 if (count < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -04001260 printk(KERN_ERR PREFIX
1261 "Error parsing interrupt source overrides entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 /* TBD: Cleanup to allow fallback to MPS */
1263 return count;
1264 }
1265
1266 /*
1267 * If BIOS did not supply an INT_SRC_OVR for the SCI
1268 * pretend we got one so we can set the SCI flags.
1269 */
1270 if (!acpi_sci_override_gsi)
Alexey Starikovskiycee324b2007-02-02 19:48:22 +03001271 acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
1273 /* Fill in identity legacy mapings where no override */
1274 mp_config_acpi_legacy_irqs();
1275
Len Brown4be44fc2005-08-05 00:44:28 -04001276 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001277 acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src,
Yinghai Lu71f521b2008-08-19 20:50:03 -07001278 nr_irqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 if (count < 0) {
1280 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
1281 /* TBD: Cleanup to allow fallback to MPS */
1282 return count;
1283 }
1284
1285 return 0;
1286}
1287#else
1288static inline int acpi_parse_madt_ioapic_entries(void)
1289{
1290 return -1;
1291}
Len Brown84663612005-08-24 12:09:07 -04001292#endif /* !CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001294static void __init early_acpi_process_madt(void)
1295{
1296#ifdef CONFIG_X86_LOCAL_APIC
1297 int error;
1298
1299 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1300
1301 /*
1302 * Parse MADT LAPIC entries
1303 */
1304 error = early_acpi_parse_madt_lapic_addr_ovr();
1305 if (!error) {
1306 acpi_lapic = 1;
1307 smp_found_config = 1;
1308 }
1309 if (error == -EINVAL) {
1310 /*
1311 * Dell Precision Workstation 410, 610 come here.
1312 */
1313 printk(KERN_ERR PREFIX
1314 "Invalid BIOS MADT, disabling ACPI\n");
1315 disable_acpi();
1316 }
1317 }
1318#endif
1319}
1320
Len Brown4be44fc2005-08-05 00:44:28 -04001321static void __init acpi_process_madt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322{
1323#ifdef CONFIG_X86_LOCAL_APIC
Len Brown7f8f97c2007-02-10 21:28:03 -05001324 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
Len Brown7f8f97c2007-02-10 21:28:03 -05001326 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
1328 /*
1329 * Parse MADT LAPIC entries
1330 */
1331 error = acpi_parse_madt_lapic_entries();
1332 if (!error) {
1333 acpi_lapic = 1;
1334
Venkatesh Pallipadi911a62d2005-09-03 15:56:31 -07001335#ifdef CONFIG_X86_GENERICARCH
1336 generic_bigsmp_probe();
1337#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 /*
1339 * Parse MADT IO-APIC entries
1340 */
1341 error = acpi_parse_madt_ioapic_entries();
1342 if (!error) {
1343 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 acpi_ioapic = 1;
1345
1346 smp_found_config = 1;
Suresh Siddha6e1cb382008-07-10 11:16:58 -07001347#ifdef CONFIG_X86_32
Ingo Molnar3c43f032007-05-02 19:27:04 +02001348 setup_apic_routing();
Suresh Siddha6e1cb382008-07-10 11:16:58 -07001349#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 }
1351 }
1352 if (error == -EINVAL) {
1353 /*
1354 * Dell Precision Workstation 410, 610 come here.
1355 */
Len Brown4be44fc2005-08-05 00:44:28 -04001356 printk(KERN_ERR PREFIX
1357 "Invalid BIOS MADT, disabling ACPI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 disable_acpi();
1359 }
Len Brown7b37b5f2008-12-23 01:47:42 -05001360 } else {
1361 /*
1362 * ACPI found no MADT, and so ACPI wants UP PIC mode.
1363 * In the event an MPS table was found, forget it.
1364 * Boot with "acpi=off" to use MPS on such a system.
1365 */
1366 if (smp_found_config) {
1367 printk(KERN_WARNING PREFIX
1368 "No APIC-table, disabling MPS\n");
1369 smp_found_config = 0;
1370 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 }
Yinghai Lu69b88af2008-12-05 22:45:50 -08001372
1373 /*
1374 * ACPI supports both logical (e.g. Hyper-Threading) and physical
1375 * processors, where MPS only supports physical.
1376 */
1377 if (acpi_lapic && acpi_ioapic)
1378 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
1379 "information\n");
1380 else if (acpi_lapic)
1381 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
1382 "configuration information\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383#endif
1384 return;
1385}
1386
Jeff Garzik18552562007-10-03 15:15:40 -04001387static int __init disable_acpi_irq(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001388{
1389 if (!acpi_force) {
1390 printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
1391 d->ident);
1392 acpi_noirq_set();
1393 }
1394 return 0;
1395}
1396
Jeff Garzik18552562007-10-03 15:15:40 -04001397static int __init disable_acpi_pci(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001398{
1399 if (!acpi_force) {
1400 printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
1401 d->ident);
1402 acpi_disable_pci();
1403 }
1404 return 0;
1405}
Andrey Paninaea00142005-06-25 14:54:42 -07001406
Jeff Garzik18552562007-10-03 15:15:40 -04001407static int __init dmi_disable_acpi(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001408{
1409 if (!acpi_force) {
Len Brown4be44fc2005-08-05 00:44:28 -04001410 printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
Andrey Paninaea00142005-06-25 14:54:42 -07001411 disable_acpi();
1412 } else {
1413 printk(KERN_NOTICE
1414 "Warning: DMI blacklist says broken, but acpi forced\n");
1415 }
1416 return 0;
1417}
1418
1419/*
1420 * Limit ACPI to CPU enumeration for HT
1421 */
Jeff Garzik18552562007-10-03 15:15:40 -04001422static int __init force_acpi_ht(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001423{
1424 if (!acpi_force) {
Len Brown4be44fc2005-08-05 00:44:28 -04001425 printk(KERN_NOTICE "%s detected: force use of acpi=ht\n",
1426 d->ident);
Andrey Paninaea00142005-06-25 14:54:42 -07001427 disable_acpi();
1428 acpi_ht = 1;
1429 } else {
1430 printk(KERN_NOTICE
1431 "Warning: acpi=force overrules DMI blacklist: acpi=ht\n");
1432 }
1433 return 0;
1434}
1435
1436/*
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001437 * Force ignoring BIOS IRQ0 pin2 override
1438 */
1439static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
1440{
Ingo Molnar8d89adf2008-10-07 06:47:52 +02001441 /*
1442 * The ati_ixp4x0_rev() early PCI quirk should have set
1443 * the acpi_skip_timer_override flag already:
1444 */
1445 if (!acpi_skip_timer_override) {
1446 WARN(1, KERN_ERR "ati_ixp4x0 quirk not complete.\n");
1447 pr_notice("%s detected: Ignoring BIOS IRQ0 pin2 override\n",
1448 d->ident);
1449 acpi_skip_timer_override = 1;
1450 }
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001451 return 0;
1452}
1453
1454/*
Andrey Paninaea00142005-06-25 14:54:42 -07001455 * If your system is blacklisted here, but you find that acpi=force
1456 * works for you, please contact acpi-devel@sourceforge.net
1457 */
1458static struct dmi_system_id __initdata acpi_dmi_table[] = {
1459 /*
1460 * Boxes that need ACPI disabled
1461 */
1462 {
Len Brown4be44fc2005-08-05 00:44:28 -04001463 .callback = dmi_disable_acpi,
1464 .ident = "IBM Thinkpad",
1465 .matches = {
1466 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1467 DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
1468 },
1469 },
Andrey Paninaea00142005-06-25 14:54:42 -07001470
1471 /*
1472 * Boxes that need acpi=ht
1473 */
1474 {
Len Brown4be44fc2005-08-05 00:44:28 -04001475 .callback = force_acpi_ht,
1476 .ident = "FSC Primergy T850",
1477 .matches = {
1478 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
1479 DMI_MATCH(DMI_PRODUCT_NAME, "PRIMERGY T850"),
1480 },
1481 },
Andrey Paninaea00142005-06-25 14:54:42 -07001482 {
Len Brown4be44fc2005-08-05 00:44:28 -04001483 .callback = force_acpi_ht,
Len Brown4be44fc2005-08-05 00:44:28 -04001484 .ident = "HP VISUALIZE NT Workstation",
1485 .matches = {
1486 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
1487 DMI_MATCH(DMI_PRODUCT_NAME, "HP VISUALIZE NT Workstation"),
1488 },
1489 },
Andrey Paninaea00142005-06-25 14:54:42 -07001490 {
Len Brown4be44fc2005-08-05 00:44:28 -04001491 .callback = force_acpi_ht,
1492 .ident = "Compaq Workstation W8000",
1493 .matches = {
1494 DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
1495 DMI_MATCH(DMI_PRODUCT_NAME, "Workstation W8000"),
1496 },
1497 },
Andrey Paninaea00142005-06-25 14:54:42 -07001498 {
Len Brown4be44fc2005-08-05 00:44:28 -04001499 .callback = force_acpi_ht,
1500 .ident = "ASUS P4B266",
1501 .matches = {
1502 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1503 DMI_MATCH(DMI_BOARD_NAME, "P4B266"),
1504 },
1505 },
Andrey Paninaea00142005-06-25 14:54:42 -07001506 {
Len Brown4be44fc2005-08-05 00:44:28 -04001507 .callback = force_acpi_ht,
1508 .ident = "ASUS P2B-DS",
1509 .matches = {
1510 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1511 DMI_MATCH(DMI_BOARD_NAME, "P2B-DS"),
1512 },
1513 },
Andrey Paninaea00142005-06-25 14:54:42 -07001514 {
Len Brown4be44fc2005-08-05 00:44:28 -04001515 .callback = force_acpi_ht,
1516 .ident = "ASUS CUR-DLS",
1517 .matches = {
1518 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1519 DMI_MATCH(DMI_BOARD_NAME, "CUR-DLS"),
1520 },
1521 },
Andrey Paninaea00142005-06-25 14:54:42 -07001522 {
Len Brown4be44fc2005-08-05 00:44:28 -04001523 .callback = force_acpi_ht,
1524 .ident = "ABIT i440BX-W83977",
1525 .matches = {
1526 DMI_MATCH(DMI_BOARD_VENDOR, "ABIT <http://www.abit.com>"),
1527 DMI_MATCH(DMI_BOARD_NAME, "i440BX-W83977 (BP6)"),
1528 },
1529 },
Andrey Paninaea00142005-06-25 14:54:42 -07001530 {
Len Brown4be44fc2005-08-05 00:44:28 -04001531 .callback = force_acpi_ht,
1532 .ident = "IBM Bladecenter",
1533 .matches = {
1534 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1535 DMI_MATCH(DMI_BOARD_NAME, "IBM eServer BladeCenter HS20"),
1536 },
1537 },
Andrey Paninaea00142005-06-25 14:54:42 -07001538 {
Len Brown4be44fc2005-08-05 00:44:28 -04001539 .callback = force_acpi_ht,
1540 .ident = "IBM eServer xSeries 360",
1541 .matches = {
1542 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1543 DMI_MATCH(DMI_BOARD_NAME, "eServer xSeries 360"),
1544 },
1545 },
Andrey Paninaea00142005-06-25 14:54:42 -07001546 {
Len Brown4be44fc2005-08-05 00:44:28 -04001547 .callback = force_acpi_ht,
1548 .ident = "IBM eserver xSeries 330",
1549 .matches = {
1550 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1551 DMI_MATCH(DMI_BOARD_NAME, "eserver xSeries 330"),
1552 },
1553 },
Andrey Paninaea00142005-06-25 14:54:42 -07001554 {
Len Brown4be44fc2005-08-05 00:44:28 -04001555 .callback = force_acpi_ht,
1556 .ident = "IBM eserver xSeries 440",
1557 .matches = {
1558 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1559 DMI_MATCH(DMI_PRODUCT_NAME, "eserver xSeries 440"),
1560 },
1561 },
Andrey Paninaea00142005-06-25 14:54:42 -07001562
Andrey Paninaea00142005-06-25 14:54:42 -07001563 /*
1564 * Boxes that need ACPI PCI IRQ routing disabled
1565 */
1566 {
Len Brown4be44fc2005-08-05 00:44:28 -04001567 .callback = disable_acpi_irq,
1568 .ident = "ASUS A7V",
1569 .matches = {
1570 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
1571 DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
1572 /* newer BIOS, Revision 1011, does work */
1573 DMI_MATCH(DMI_BIOS_VERSION,
1574 "ASUS A7V ACPI BIOS Revision 1007"),
1575 },
1576 },
Len Brown74586fc2007-03-08 02:48:30 -05001577 {
1578 /*
1579 * Latest BIOS for IBM 600E (1.16) has bad pcinum
1580 * for LPC bridge, which is needed for the PCI
1581 * interrupt links to work. DSDT fix is in bug 5966.
1582 * 2645, 2646 model numbers are shared with 600/600E/600X
1583 */
1584 .callback = disable_acpi_irq,
1585 .ident = "IBM Thinkpad 600 Series 2645",
1586 .matches = {
1587 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1588 DMI_MATCH(DMI_BOARD_NAME, "2645"),
1589 },
1590 },
1591 {
1592 .callback = disable_acpi_irq,
1593 .ident = "IBM Thinkpad 600 Series 2646",
1594 .matches = {
1595 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1596 DMI_MATCH(DMI_BOARD_NAME, "2646"),
1597 },
1598 },
Andrey Paninaea00142005-06-25 14:54:42 -07001599 /*
1600 * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
1601 */
Len Brown4be44fc2005-08-05 00:44:28 -04001602 { /* _BBN 0 bug */
1603 .callback = disable_acpi_pci,
1604 .ident = "ASUS PR-DLS",
1605 .matches = {
1606 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1607 DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
1608 DMI_MATCH(DMI_BIOS_VERSION,
1609 "ASUS PR-DLS ACPI BIOS Revision 1010"),
1610 DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
1611 },
1612 },
Andrey Paninaea00142005-06-25 14:54:42 -07001613 {
Len Brown4be44fc2005-08-05 00:44:28 -04001614 .callback = disable_acpi_pci,
1615 .ident = "Acer TravelMate 36x Laptop",
1616 .matches = {
1617 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
1618 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
1619 },
1620 },
Andreas Herrmann35af2822008-10-22 13:08:31 +02001621 {}
1622};
1623
1624/* second table for DMI checks that should run after early-quirks */
1625static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
Matthew Garrett9340e1c2008-07-01 01:12:06 +01001626 /*
1627 * HP laptops which use a DSDT reporting as HP/SB400/10000,
1628 * which includes some code which overrides all temperature
1629 * trip points to 16C if the INTIN2 input of the I/O APIC
1630 * is enabled. This input is incorrectly designated the
1631 * ISA IRQ 0 via an interrupt source override even though
1632 * it is wired to the output of the master 8259A and INTIN0
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001633 * is not connected at all. Force ignoring BIOS IRQ0 pin2
1634 * override in that cases.
1635 */
1636 {
1637 .callback = dmi_ignore_irq0_timer_override,
Rafael J. Wysockie84956f2008-10-06 11:59:29 +02001638 .ident = "HP nx6115 laptop",
1639 .matches = {
1640 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1641 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6115"),
1642 },
1643 },
1644 {
1645 .callback = dmi_ignore_irq0_timer_override,
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001646 .ident = "HP NX6125 laptop",
1647 .matches = {
1648 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1649 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
1650 },
1651 },
1652 {
1653 .callback = dmi_ignore_irq0_timer_override,
1654 .ident = "HP NX6325 laptop",
1655 .matches = {
1656 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1657 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
1658 },
1659 },
Rafael J. Wysockie84956f2008-10-06 11:59:29 +02001660 {
1661 .callback = dmi_ignore_irq0_timer_override,
1662 .ident = "HP 6715b laptop",
1663 .matches = {
1664 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1665 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
1666 },
1667 },
Len Brown4be44fc2005-08-05 00:44:28 -04001668 {}
Andrey Paninaea00142005-06-25 14:54:42 -07001669};
1670
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671/*
1672 * acpi_boot_table_init() and acpi_boot_init()
1673 * called from setup_arch(), always.
1674 * 1. checksums all tables
1675 * 2. enumerates lapics
1676 * 3. enumerates io-apics
1677 *
1678 * acpi_table_init() is separate to allow reading SRAT without
1679 * other side effects.
1680 *
1681 * side effects of acpi_boot_init:
1682 * acpi_lapic = 1 if LAPIC found
1683 * acpi_ioapic = 1 if IOAPIC found
1684 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
1685 * if acpi_blacklisted() acpi_disabled = 1;
1686 * acpi_irq_model=...
1687 * ...
1688 *
1689 * return value: (currently ignored)
1690 * 0: success
1691 * !0: failure
1692 */
1693
Len Brown4be44fc2005-08-05 00:44:28 -04001694int __init acpi_boot_table_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695{
1696 int error;
1697
Andrey Paninaea00142005-06-25 14:54:42 -07001698 dmi_check_system(acpi_dmi_table);
Andrey Paninaea00142005-06-25 14:54:42 -07001699
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 /*
1701 * If acpi_disabled, bail out
1702 * One exception: acpi=ht continues far enough to enumerate LAPICs
1703 */
1704 if (acpi_disabled && !acpi_ht)
Len Brown4be44fc2005-08-05 00:44:28 -04001705 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001707 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 * Initialize the ACPI boot-time table parser.
1709 */
1710 error = acpi_table_init();
1711 if (error) {
1712 disable_acpi();
1713 return error;
1714 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001716 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717
1718 /*
1719 * blacklist may disable ACPI entirely
1720 */
1721 error = acpi_blacklisted();
1722 if (error) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 if (acpi_force) {
1724 printk(KERN_WARNING PREFIX "acpi=force override\n");
1725 } else {
1726 printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
1727 disable_acpi();
1728 return error;
1729 }
1730 }
1731
1732 return 0;
1733}
1734
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001735int __init early_acpi_boot_init(void)
1736{
1737 /*
1738 * If acpi_disabled, bail out
1739 * One exception: acpi=ht continues far enough to enumerate LAPICs
1740 */
1741 if (acpi_disabled && !acpi_ht)
1742 return 1;
1743
1744 /*
1745 * Process the Multiple APIC Description Table (MADT), if present
1746 */
1747 early_acpi_process_madt();
1748
1749 return 0;
1750}
1751
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752int __init acpi_boot_init(void)
1753{
Andreas Herrmann35af2822008-10-22 13:08:31 +02001754 /* those are executed after early-quirks are executed */
1755 dmi_check_system(acpi_dmi_table_late);
1756
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 /*
1758 * If acpi_disabled, bail out
1759 * One exception: acpi=ht continues far enough to enumerate LAPICs
1760 */
1761 if (acpi_disabled && !acpi_ht)
Len Brown4be44fc2005-08-05 00:44:28 -04001762 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001764 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765
1766 /*
1767 * set sci_int and PM timer address
1768 */
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +03001769 acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
1771 /*
1772 * Process the Multiple APIC Description Table (MADT), if present
1773 */
1774 acpi_process_madt();
1775
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001776 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777
1778 return 0;
1779}
Rusty Russell1a3f2392006-09-26 10:52:32 +02001780
1781static int __init parse_acpi(char *arg)
1782{
1783 if (!arg)
1784 return -EINVAL;
1785
1786 /* "acpi=off" disables both ACPI table parsing and interpreter */
1787 if (strcmp(arg, "off") == 0) {
1788 disable_acpi();
1789 }
1790 /* acpi=force to over-ride black-list */
1791 else if (strcmp(arg, "force") == 0) {
1792 acpi_force = 1;
1793 acpi_ht = 1;
1794 acpi_disabled = 0;
1795 }
1796 /* acpi=strict disables out-of-spec workarounds */
1797 else if (strcmp(arg, "strict") == 0) {
1798 acpi_strict = 1;
1799 }
1800 /* Limit ACPI just to boot-time to enable HT */
1801 else if (strcmp(arg, "ht") == 0) {
1802 if (!acpi_force)
1803 disable_acpi();
1804 acpi_ht = 1;
1805 }
Zhao Yakui237889b2008-12-17 16:55:18 +08001806 /* acpi=rsdt use RSDT instead of XSDT */
1807 else if (strcmp(arg, "rsdt") == 0) {
1808 acpi_rsdt_forced = 1;
1809 }
Rusty Russell1a3f2392006-09-26 10:52:32 +02001810 /* "acpi=noirq" disables ACPI interrupt routing */
1811 else if (strcmp(arg, "noirq") == 0) {
1812 acpi_noirq_set();
1813 } else {
1814 /* Core will printk when we return error. */
1815 return -EINVAL;
1816 }
1817 return 0;
1818}
1819early_param("acpi", parse_acpi);
1820
1821/* FIXME: Using pci= for an ACPI parameter is a travesty. */
1822static int __init parse_pci(char *arg)
1823{
1824 if (arg && strcmp(arg, "noacpi") == 0)
1825 acpi_disable_pci();
1826 return 0;
1827}
1828early_param("pci", parse_pci);
1829
Yinghai Lu3c999f12008-06-20 16:11:20 -07001830int __init acpi_mps_check(void)
1831{
1832#if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
1833/* mptable code is not built-in*/
1834 if (acpi_disabled || acpi_noirq) {
1835 printk(KERN_WARNING "MPS support code is not built-in.\n"
1836 "Using acpi=off or acpi=noirq or pci=noacpi "
1837 "may have problem\n");
1838 return 1;
1839 }
1840#endif
1841 return 0;
1842}
1843
Rusty Russell1a3f2392006-09-26 10:52:32 +02001844#ifdef CONFIG_X86_IO_APIC
1845static int __init parse_acpi_skip_timer_override(char *arg)
1846{
1847 acpi_skip_timer_override = 1;
1848 return 0;
1849}
1850early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
Andi Kleenfa18f472006-11-14 16:57:46 +01001851
1852static int __init parse_acpi_use_timer_override(char *arg)
1853{
1854 acpi_use_timer_override = 1;
1855 return 0;
1856}
1857early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001858#endif /* CONFIG_X86_IO_APIC */
1859
1860static int __init setup_acpi_sci(char *s)
1861{
1862 if (!s)
1863 return -EINVAL;
1864 if (!strcmp(s, "edge"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001865 acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
1866 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001867 else if (!strcmp(s, "level"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001868 acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
1869 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001870 else if (!strcmp(s, "high"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001871 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
1872 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001873 else if (!strcmp(s, "low"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001874 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
1875 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001876 else
1877 return -EINVAL;
1878 return 0;
1879}
1880early_param("acpi_sci", setup_acpi_sci);
Andrew Mortond0a90812006-10-20 14:30:27 -07001881
1882int __acpi_acquire_global_lock(unsigned int *lock)
1883{
1884 unsigned int old, new, val;
1885 do {
1886 old = *lock;
1887 new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
1888 val = cmpxchg(lock, old, new);
1889 } while (unlikely (val != old));
1890 return (new < 3) ? -1 : 0;
1891}
1892
1893int __acpi_release_global_lock(unsigned int *lock)
1894{
1895 unsigned int old, new, val;
1896 do {
1897 old = *lock;
1898 new = old & ~0x3;
1899 val = cmpxchg(lock, old, new);
1900 } while (unlikely (val != old));
1901 return old & 0x1;
1902}