blob: a31a579a47ca31fbcec827b8ac08624ae38bd186 [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;
Rusty Russell1a3f2392006-09-26 10:52:32 +020050
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>
Jack Steinerae261862008-03-28 14:12:06 -050061#include <asm/genapic.h>
Linus Torvalds637029c2006-02-27 20:41:56 -080062
Len Brown4be44fc2005-08-05 00:44:28 -040063#else /* X86 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65#ifdef CONFIG_X86_LOCAL_APIC
66#include <mach_apic.h>
67#include <mach_mpparse.h>
Len Brown4be44fc2005-08-05 00:44:28 -040068#endif /* CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Len Brown4be44fc2005-08-05 00:44:28 -040070#endif /* X86 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72#define BAD_MADT_ENTRY(entry, end) ( \
73 (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +030074 ((struct acpi_subtable_header *)entry)->length < sizeof(*entry))
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76#define PREFIX "ACPI: "
77
Andrew Morton90d53902006-11-02 22:07:18 -080078int acpi_noirq; /* skip ACPI IRQ initialization */
Yinghai Lu6e4be1f2008-02-05 00:01:48 -080079int acpi_pci_disabled; /* skip ACPI PCI scan and IRQ initialization */
80EXPORT_SYMBOL(acpi_pci_disabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081int acpi_ht __initdata = 1; /* enable HT */
82
83int acpi_lapic;
84int acpi_ioapic;
85int acpi_strict;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Maciej W. Rozycki471694e2008-07-01 01:11:35 +010087static int disable_irq0_through_ioapic __initdata;
88
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +030089u8 acpi_sci_flags __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090int acpi_sci_override_gsi __initdata;
91int acpi_skip_timer_override __initdata;
Andi Kleenfa18f472006-11-14 16:57:46 +010092int acpi_use_timer_override __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94#ifdef CONFIG_X86_LOCAL_APIC
95static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
96#endif
97
98#ifndef __HAVE_ARCH_CMPXCHG
99#warning ACPI uses CMPXCHG, i486 and later hardware
100#endif
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102/* --------------------------------------------------------------------------
103 Boot-time Configuration
104 -------------------------------------------------------------------------- */
105
106/*
107 * The default interrupt routing model is PIC (8259). This gets
Simon Arlott27b46d72007-10-20 01:13:56 +0200108 * overridden if IOAPICs are enumerated (below).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 */
Len Brown4be44fc2005-08-05 00:44:28 -0400110enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113/*
114 * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
115 * to map the target physical address. The problem is that set_fixmap()
116 * provides a single page, and it is possible that the page is not
117 * sufficient.
118 * By using this area, we can map up to MAX_IO_APICS pages temporarily,
119 * i.e. until the next __va_range() call.
120 *
121 * Important Safety Note: The fixed I/O APIC page numbers are *subtracted*
122 * from the fixed base. That's why we start at FIX_IO_APIC_BASE_END and
123 * count idx down while incrementing the phys address.
124 */
Jan Beulich2fdf0742007-12-13 08:33:59 +0000125char *__init __acpi_map_table(unsigned long phys, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
127 unsigned long base, offset, mapped_size;
128 int idx;
129
Yinghai Luf34fa822008-07-09 20:16:36 -0700130 if (!phys || !size)
131 return NULL;
132
133 if (phys+size <= (max_pfn_mapped << PAGE_SHIFT))
Len Brown4be44fc2005-08-05 00:44:28 -0400134 return __va(phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 offset = phys & (PAGE_SIZE - 1);
137 mapped_size = PAGE_SIZE - offset;
Yinghai Luf34fa822008-07-09 20:16:36 -0700138 clear_fixmap(FIX_ACPI_END);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 set_fixmap(FIX_ACPI_END, phys);
140 base = fix_to_virt(FIX_ACPI_END);
141
142 /*
143 * Most cases can be covered by the below.
144 */
145 idx = FIX_ACPI_END;
146 while (mapped_size < size) {
147 if (--idx < FIX_ACPI_BEGIN)
148 return NULL; /* cannot handle this */
149 phys += PAGE_SIZE;
Yinghai Luf34fa822008-07-09 20:16:36 -0700150 clear_fixmap(idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 set_fixmap(idx, phys);
152 mapped_size += PAGE_SIZE;
153 }
154
Len Brown4be44fc2005-08-05 00:44:28 -0400155 return ((unsigned char *)base + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158#ifdef CONFIG_PCI_MMCONFIG
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700159/* The physical address of the MMCONFIG aperture. Set from ACPI tables. */
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300160struct acpi_mcfg_allocation *pci_mmcfg_config;
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700161int pci_mmcfg_config_num;
162
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300163int __init acpi_parse_mcfg(struct acpi_table_header *header)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
165 struct acpi_table_mcfg *mcfg;
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700166 unsigned long i;
167 int config_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300169 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 return -EINVAL;
171
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300172 mcfg = (struct acpi_table_mcfg *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700174 /* how many config structures do we have */
175 pci_mmcfg_config_num = 0;
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300176 i = header->length - sizeof(struct acpi_table_mcfg);
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300177 while (i >= sizeof(struct acpi_mcfg_allocation)) {
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700178 ++pci_mmcfg_config_num;
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300179 i -= sizeof(struct acpi_mcfg_allocation);
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700180 };
181 if (pci_mmcfg_config_num == 0) {
182 printk(KERN_ERR PREFIX "MMCONFIG has no entries\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 return -ENODEV;
184 }
185
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700186 config_size = pci_mmcfg_config_num * sizeof(*pci_mmcfg_config);
187 pci_mmcfg_config = kmalloc(config_size, GFP_KERNEL);
188 if (!pci_mmcfg_config) {
189 printk(KERN_WARNING PREFIX
190 "No memory for MCFG config tables\n");
191 return -ENOMEM;
192 }
193
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300194 memcpy(pci_mmcfg_config, &mcfg[1], config_size);
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700195 for (i = 0; i < pci_mmcfg_config_num; ++i) {
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300196 if (pci_mmcfg_config[i].address > 0xFFFFFFFF) {
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700197 printk(KERN_ERR PREFIX
198 "MMCONFIG not in low 4GB of memory\n");
Konrad Rzeszutekacc7c2e2006-06-15 12:08:30 -0400199 kfree(pci_mmcfg_config);
200 pci_mmcfg_config_num = 0;
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700201 return -ENODEV;
202 }
203 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205 return 0;
206}
Len Brown4be44fc2005-08-05 00:44:28 -0400207#endif /* CONFIG_PCI_MMCONFIG */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209#ifdef CONFIG_X86_LOCAL_APIC
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300210static int __init acpi_parse_madt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
Len Brown4be44fc2005-08-05 00:44:28 -0400212 struct acpi_table_madt *madt = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300214 if (!cpu_has_apic)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 return -EINVAL;
216
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300217 madt = (struct acpi_table_madt *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 if (!madt) {
219 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
220 return -ENODEV;
221 }
222
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300223 if (madt->address) {
224 acpi_lapic_addr = (u64) madt->address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226 printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300227 madt->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 }
229
230 acpi_madt_oem_check(madt->header.oem_id, madt->header.oem_table_id);
Len Brown4be44fc2005-08-05 00:44:28 -0400231
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 return 0;
233}
234
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400235static void __cpuinit acpi_register_lapic(int id, u8 enabled)
236{
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700237 unsigned int ver = 0;
238
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400239 if (!enabled) {
240 ++disabled_cpus;
241 return;
242 }
243
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700244#ifdef CONFIG_X86_32
245 if (boot_cpu_physical_apicid != -1U)
246 ver = apic_version[boot_cpu_physical_apicid];
247#endif
248
249 generic_processor_info(id, ver);
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400250}
251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300253acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300255 struct acpi_madt_local_apic *processor = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300257 processor = (struct acpi_madt_local_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
259 if (BAD_MADT_ENTRY(processor, end))
260 return -EINVAL;
261
262 acpi_table_print_madt_entry(header);
263
Ashok Raj7f66ae42006-02-03 21:51:50 +0100264 /*
265 * We need to register disabled CPU as well to permit
266 * counting disabled CPUs. This allows us to size
267 * cpus_possible_map more accurately, to permit
268 * to not preallocating memory for all NR_CPUS
269 * when we use CPU hotplug.
270 */
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400271 acpi_register_lapic(processor->id, /* APIC ID */
272 processor->lapic_flags & ACPI_MADT_ENABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274 return 0;
275}
276
277static int __init
Jack Steinerac049c12008-03-28 14:12:09 -0500278acpi_parse_sapic(struct acpi_subtable_header *header, const unsigned long end)
279{
280 struct acpi_madt_local_sapic *processor = NULL;
281
282 processor = (struct acpi_madt_local_sapic *)header;
283
284 if (BAD_MADT_ENTRY(processor, end))
285 return -EINVAL;
286
287 acpi_table_print_madt_entry(header);
288
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400289 acpi_register_lapic((processor->id << 8) | processor->eid,/* APIC ID */
290 processor->lapic_flags & ACPI_MADT_ENABLED);
Jack Steinerac049c12008-03-28 14:12:09 -0500291
292 return 0;
293}
294
295static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300296acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400297 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300299 struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300301 lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
303 if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
304 return -EINVAL;
305
306 acpi_lapic_addr = lapic_addr_ovr->address;
307
308 return 0;
309}
310
311static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300312acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300314 struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300316 lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
318 if (BAD_MADT_ENTRY(lapic_nmi, end))
319 return -EINVAL;
320
321 acpi_table_print_madt_entry(header);
322
323 if (lapic_nmi->lint != 1)
324 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
325
326 return 0;
327}
328
Len Brown4be44fc2005-08-05 00:44:28 -0400329#endif /*CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Len Brown84663612005-08-24 12:09:07 -0400331#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
333static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300334acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300336 struct acpi_madt_io_apic *ioapic = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300338 ioapic = (struct acpi_madt_io_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340 if (BAD_MADT_ENTRY(ioapic, end))
341 return -EINVAL;
Len Brown4be44fc2005-08-05 00:44:28 -0400342
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 acpi_table_print_madt_entry(header);
344
Len Brown4be44fc2005-08-05 00:44:28 -0400345 mp_register_ioapic(ioapic->id,
346 ioapic->address, ioapic->global_irq_base);
347
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 return 0;
349}
350
351/*
352 * Parse Interrupt Source Override for the ACPI SCI
353 */
Len Browne82c3542006-12-21 01:29:59 -0500354static void __init acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355{
356 if (trigger == 0) /* compatible SCI trigger is level */
357 trigger = 3;
358
359 if (polarity == 0) /* compatible SCI polarity is low */
360 polarity = 3;
361
362 /* Command-line over-ride via acpi_sci= */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300363 if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
364 trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300366 if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
367 polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
369 /*
Len Brown4be44fc2005-08-05 00:44:28 -0400370 * mp_config_acpi_legacy_irqs() already setup IRQs < 16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 * If GSI is < 16, this will update its flags,
372 * else it will create a new mp_irqs[] entry.
373 */
Len Brown7bdd21c2006-12-02 02:27:46 -0500374 mp_override_legacy_irq(gsi, polarity, trigger, gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376 /*
377 * stash over-ride to indicate we've been here
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300378 * and for later update of acpi_gbl_FADT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 */
Len Brown7bdd21c2006-12-02 02:27:46 -0500380 acpi_sci_override_gsi = gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 return;
382}
383
384static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300385acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400386 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300388 struct acpi_madt_interrupt_override *intsrc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300390 intsrc = (struct acpi_madt_interrupt_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 if (BAD_MADT_ENTRY(intsrc, end))
393 return -EINVAL;
394
395 acpi_table_print_madt_entry(header);
396
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300397 if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
Len Brown7bdd21c2006-12-02 02:27:46 -0500398 acpi_sci_ioapic_setup(intsrc->global_irq,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300399 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
400 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 return 0;
402 }
403
404 if (acpi_skip_timer_override &&
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300405 intsrc->source_irq == 0 && intsrc->global_irq == 2) {
Len Brown4be44fc2005-08-05 00:44:28 -0400406 printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
407 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 }
409
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300410 mp_override_legacy_irq(intsrc->source_irq,
411 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
412 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
413 intsrc->global_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415 return 0;
416}
417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300419acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300421 struct acpi_madt_nmi_source *nmi_src = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300423 nmi_src = (struct acpi_madt_nmi_source *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
425 if (BAD_MADT_ENTRY(nmi_src, end))
426 return -EINVAL;
427
428 acpi_table_print_madt_entry(header);
429
430 /* TBD: Support nimsrc entries? */
431
432 return 0;
433}
434
Len Brown4be44fc2005-08-05 00:44:28 -0400435#endif /* CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437/*
438 * acpi_pic_sci_set_trigger()
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300439 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 * use ELCR to set PIC-mode trigger type for SCI
441 *
442 * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
443 * it may require Edge Trigger -- use "acpi_sci=edge"
444 *
445 * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
446 * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
Simon Arlott27b46d72007-10-20 01:13:56 +0200447 * ECLR1 is IRQs 0-7 (IRQ 0, 1, 2 must be 0)
448 * ECLR2 is IRQs 8-15 (IRQ 8, 13 must be 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 */
450
Len Brown4be44fc2005-08-05 00:44:28 -0400451void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452{
453 unsigned int mask = 1 << irq;
454 unsigned int old, new;
455
456 /* Real old ELCR mask */
457 old = inb(0x4d0) | (inb(0x4d1) << 8);
458
459 /*
Simon Arlott27b46d72007-10-20 01:13:56 +0200460 * If we use ACPI to set PCI IRQs, then we should clear ELCR
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 * since we will set it correctly as we enable the PCI irq
462 * routing.
463 */
464 new = acpi_noirq ? old : 0;
465
466 /*
467 * Update SCI information in the ELCR, it isn't in the PCI
468 * routing tables..
469 */
470 switch (trigger) {
Len Brown4be44fc2005-08-05 00:44:28 -0400471 case 1: /* Edge - clear */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 new &= ~mask;
473 break;
Len Brown4be44fc2005-08-05 00:44:28 -0400474 case 3: /* Level - set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 new |= mask;
476 break;
477 }
478
479 if (old == new)
480 return;
481
482 printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
483 outb(new, 0x4d0);
484 outb(new >> 8, 0x4d1);
485}
486
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
488{
Eric W. Biedermanf023d762006-10-04 02:16:52 -0700489 *irq = gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 return 0;
491}
492
Kenji Kaneshige1f3a6a12005-07-28 14:42:00 -0400493/*
494 * success: return IRQ number (>=0)
495 * failure: return < 0
496 */
Len Browncb654692005-12-28 02:43:51 -0500497int acpi_register_gsi(u32 gsi, int triggering, int polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498{
499 unsigned int irq;
500 unsigned int plat_gsi = gsi;
501
502#ifdef CONFIG_PCI
503 /*
504 * Make sure all (legacy) PCI IRQs are set as level-triggered.
505 */
506 if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
Len Browncb654692005-12-28 02:43:51 -0500507 if (triggering == ACPI_LEVEL_SENSITIVE)
Len Brown4be44fc2005-08-05 00:44:28 -0400508 eisa_set_level_irq(gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 }
510#endif
511
512#ifdef CONFIG_X86_IO_APIC
513 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) {
Len Browncb654692005-12-28 02:43:51 -0500514 plat_gsi = mp_register_gsi(gsi, triggering, polarity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 }
516#endif
517 acpi_gsi_to_irq(plat_gsi, &irq);
518 return irq;
519}
Len Brown4be44fc2005-08-05 00:44:28 -0400520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521/*
522 * ACPI based hotplug support for CPU
523 */
524#ifdef CONFIG_ACPI_HOTPLUG_CPU
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100525
526static int __cpuinit _acpi_map_lsapic(acpi_handle handle, int *pcpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527{
Ashok Raj73fea172006-09-26 10:52:35 +0200528 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
529 union acpi_object *obj;
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300530 struct acpi_madt_local_apic *lapic;
Ashok Raj73fea172006-09-26 10:52:35 +0200531 cpumask_t tmp_map, new_map;
532 u8 physid;
533 int cpu;
534
535 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
536 return -EINVAL;
537
538 if (!buffer.length || !buffer.pointer)
539 return -EINVAL;
540
541 obj = buffer.pointer;
542 if (obj->type != ACPI_TYPE_BUFFER ||
543 obj->buffer.length < sizeof(*lapic)) {
544 kfree(buffer.pointer);
545 return -EINVAL;
546 }
547
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300548 lapic = (struct acpi_madt_local_apic *)obj->buffer.pointer;
Ashok Raj73fea172006-09-26 10:52:35 +0200549
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300550 if (lapic->header.type != ACPI_MADT_TYPE_LOCAL_APIC ||
551 !(lapic->lapic_flags & ACPI_MADT_ENABLED)) {
Ashok Raj73fea172006-09-26 10:52:35 +0200552 kfree(buffer.pointer);
553 return -EINVAL;
554 }
555
556 physid = lapic->id;
557
558 kfree(buffer.pointer);
559 buffer.length = ACPI_ALLOCATE_BUFFER;
560 buffer.pointer = NULL;
561
562 tmp_map = cpu_present_map;
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 */
569 cpus_andnot(new_map, cpu_present_map, tmp_map);
570 if (cpus_empty(new_map)) {
571 printk ("Unable to map lapic to logical cpu number\n");
572 return -EINVAL;
573 }
574
575 cpu = first_cpu(new_map);
576
577 *pcpu = cpu;
578 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579}
Len Brown4be44fc2005-08-05 00:44:28 -0400580
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100581/* wrapper to silence section mismatch warning */
582int __ref acpi_map_lsapic(acpi_handle handle, int *pcpu)
583{
584 return _acpi_map_lsapic(handle, pcpu);
585}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586EXPORT_SYMBOL(acpi_map_lsapic);
587
Len Brown4be44fc2005-08-05 00:44:28 -0400588int acpi_unmap_lsapic(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589{
Mike Travis71fff5e2007-10-19 20:35:03 +0200590 per_cpu(x86_cpu_to_apicid, cpu) = -1;
Ashok Raj73fea172006-09-26 10:52:35 +0200591 cpu_clear(cpu, cpu_present_map);
592 num_processors--;
593
594 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595}
Len Brown4be44fc2005-08-05 00:44:28 -0400596
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597EXPORT_SYMBOL(acpi_unmap_lsapic);
Len Brown4be44fc2005-08-05 00:44:28 -0400598#endif /* CONFIG_ACPI_HOTPLUG_CPU */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Len Brown4be44fc2005-08-05 00:44:28 -0400600int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700601{
602 /* TBD */
603 return -EINVAL;
604}
Len Brown4be44fc2005-08-05 00:44:28 -0400605
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700606EXPORT_SYMBOL(acpi_register_ioapic);
607
Len Brown4be44fc2005-08-05 00:44:28 -0400608int acpi_unregister_ioapic(acpi_handle handle, 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_unregister_ioapic);
615
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300616static int __init acpi_parse_sbf(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300618 struct acpi_table_boot *sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300620 sb = (struct acpi_table_boot *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 if (!sb) {
622 printk(KERN_WARNING PREFIX "Unable to map SBF\n");
623 return -ENODEV;
624 }
625
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300626 sbf_port = sb->cmos_index; /* Save CMOS port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
628 return 0;
629}
630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631#ifdef CONFIG_HPET_TIMER
john stultz2d0c87c2007-02-16 01:28:18 -0800632#include <asm/hpet.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
Aaron Durbina1dfd852007-07-21 17:11:39 +0200634static struct __initdata resource *hpet_res;
635
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300636static int __init acpi_parse_hpet(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637{
638 struct acpi_table_hpet *hpet_tbl;
639
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300640 hpet_tbl = (struct acpi_table_hpet *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 if (!hpet_tbl) {
642 printk(KERN_WARNING PREFIX "Unable to map HPET\n");
643 return -ENODEV;
644 }
645
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300646 if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 printk(KERN_WARNING PREFIX "HPET timers must be located in "
648 "memory.\n");
649 return -1;
650 }
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200651
john stultz2d0c87c2007-02-16 01:28:18 -0800652 hpet_address = hpet_tbl->address.address;
Thomas Gleixnerf4df73c2007-11-15 21:41:50 -0500653
654 /*
655 * Some broken BIOSes advertise HPET at 0x0. We really do not
656 * want to allocate a resource there.
657 */
658 if (!hpet_address) {
659 printk(KERN_WARNING PREFIX
660 "HPET id: %#x base: %#lx is invalid\n",
661 hpet_tbl->id, hpet_address);
662 return 0;
663 }
664#ifdef CONFIG_X86_64
665 /*
666 * Some even more broken BIOSes advertise HPET at
667 * 0xfed0000000000000 instead of 0xfed00000. Fix it up and add
668 * some noise:
669 */
670 if (hpet_address == 0xfed0000000000000UL) {
671 if (!hpet_force_user) {
672 printk(KERN_WARNING PREFIX "HPET id: %#x "
673 "base: 0xfed0000000000000 is bogus\n "
674 "try hpet=force on the kernel command line to "
675 "fix it up to 0xfed00000.\n", hpet_tbl->id);
676 hpet_address = 0;
677 return 0;
678 }
679 printk(KERN_WARNING PREFIX
680 "HPET id: %#x base: 0xfed0000000000000 fixed up "
681 "to 0xfed00000.\n", hpet_tbl->id);
682 hpet_address >>= 32;
683 }
684#endif
Len Brown4be44fc2005-08-05 00:44:28 -0400685 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
john stultz2d0c87c2007-02-16 01:28:18 -0800686 hpet_tbl->id, hpet_address);
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200687
Aaron Durbina1dfd852007-07-21 17:11:39 +0200688 /*
689 * Allocate and initialize the HPET firmware resource for adding into
690 * the resource tree during the lateinit timeframe.
691 */
692#define HPET_RESOURCE_NAME_SIZE 9
693 hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
694
Aaron Durbina1dfd852007-07-21 17:11:39 +0200695 hpet_res->name = (void *)&hpet_res[1];
696 hpet_res->flags = IORESOURCE_MEM;
697 snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE, "HPET %u",
698 hpet_tbl->sequence);
699
700 hpet_res->start = hpet_address;
701 hpet_res->end = hpet_address + (1 * 1024) - 1;
702
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 return 0;
704}
Aaron Durbina1dfd852007-07-21 17:11:39 +0200705
706/*
707 * hpet_insert_resource inserts the HPET resources used into the resource
708 * tree.
709 */
710static __init int hpet_insert_resource(void)
711{
712 if (!hpet_res)
713 return 1;
714
715 return insert_resource(&iomem_resource, hpet_res);
716}
717
718late_initcall(hpet_insert_resource);
719
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720#else
721#define acpi_parse_hpet NULL
722#endif
723
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300724static int __init acpi_parse_fadt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725{
Jason Davis90660ec2005-04-16 15:24:53 -0700726
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727#ifdef CONFIG_X86_PM_TIMER
728 /* detect the location of the ACPI PM Timer */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300729 if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 /* FADT rev. 2 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300731 if (acpi_gbl_FADT.xpm_timer_block.space_id !=
Len Brown4be44fc2005-08-05 00:44:28 -0400732 ACPI_ADR_SPACE_SYSTEM_IO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 return 0;
734
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300735 pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
David Shaohua Lie6e87b42005-09-21 01:35:00 -0400736 /*
737 * "X" fields are optional extensions to the original V1.0
738 * fields, so we must selectively expand V1.0 fields if the
739 * corresponding X field is zero.
740 */
741 if (!pmtmr_ioport)
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300742 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 } else {
744 /* FADT rev. 1 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300745 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 }
747 if (pmtmr_ioport)
Len Brown4be44fc2005-08-05 00:44:28 -0400748 printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
749 pmtmr_ioport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750#endif
751 return 0;
752}
753
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754#ifdef CONFIG_X86_LOCAL_APIC
755/*
756 * Parse LAPIC entries in MADT
757 * returns 0 on success, < 0 on error
758 */
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400759
760static void __init acpi_register_lapic_address(unsigned long address)
761{
762 mp_lapic_addr = address;
763
764 set_fixmap_nocache(FIX_APIC_BASE, address);
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700765 if (boot_cpu_physical_apicid == -1U) {
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400766 boot_cpu_physical_apicid = GET_APIC_ID(read_apic_id());
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700767#ifdef CONFIG_X86_32
768 apic_version[boot_cpu_physical_apicid] =
769 GET_APIC_VERSION(apic_read(APIC_LVR));
770#endif
771 }
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400772}
773
Yinghai Lucbf9bd62008-02-19 03:21:06 -0800774static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
775{
776 int count;
777
778 if (!cpu_has_apic)
779 return -ENODEV;
780
781 /*
782 * Note that the LAPIC address is obtained from the MADT (32-bit value)
783 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
784 */
785
786 count =
787 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
788 acpi_parse_lapic_addr_ovr, 0);
789 if (count < 0) {
790 printk(KERN_ERR PREFIX
791 "Error parsing LAPIC address override entry\n");
792 return count;
793 }
794
795 acpi_register_lapic_address(acpi_lapic_addr);
796
797 return count;
798}
799
Len Brown4be44fc2005-08-05 00:44:28 -0400800static int __init acpi_parse_madt_lapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801{
802 int count;
803
Andi Kleen0fcd2702006-04-11 12:54:36 +0200804 if (!cpu_has_apic)
805 return -ENODEV;
806
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300807 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 * Note that the LAPIC address is obtained from the MADT (32-bit value)
809 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
810 */
811
Len Brown4be44fc2005-08-05 00:44:28 -0400812 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300813 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
Len Brown4be44fc2005-08-05 00:44:28 -0400814 acpi_parse_lapic_addr_ovr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 if (count < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400816 printk(KERN_ERR PREFIX
817 "Error parsing LAPIC address override entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 return count;
819 }
820
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400821 acpi_register_lapic_address(acpi_lapic_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Jack Steinerac049c12008-03-28 14:12:09 -0500823 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
824 acpi_parse_sapic, MAX_APICS);
825
826 if (!count)
827 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
828 acpi_parse_lapic, MAX_APICS);
Len Brown4be44fc2005-08-05 00:44:28 -0400829 if (!count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
831 /* TBD: Cleanup to allow fallback to MPS */
832 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400833 } else if (count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
835 /* TBD: Cleanup to allow fallback to MPS */
836 return count;
837 }
838
Len Brown4be44fc2005-08-05 00:44:28 -0400839 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300840 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 if (count < 0) {
842 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
843 /* TBD: Cleanup to allow fallback to MPS */
844 return count;
845 }
846 return 0;
847}
Len Brown4be44fc2005-08-05 00:44:28 -0400848#endif /* CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
Len Brown84663612005-08-24 12:09:07 -0400850#ifdef CONFIG_X86_IO_APIC
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400851#define MP_ISA_BUS 0
852
Yinghai Lud49c4282008-06-08 18:31:54 -0700853#ifdef CONFIG_X86_ES7000
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400854extern int es7000_plat;
855#endif
856
Alexey Starikovskiy5f895142008-05-14 19:03:04 +0400857static struct {
858 int apic_id;
859 int gsi_base;
860 int gsi_end;
861 DECLARE_BITMAP(pin_programmed, MP_MAX_IOAPIC_PIN + 1);
862} mp_ioapic_routing[MAX_IO_APICS];
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400863
864static int mp_find_ioapic(int gsi)
865{
866 int i = 0;
867
868 /* Find the IOAPIC that manages this GSI. */
869 for (i = 0; i < nr_ioapics; i++) {
870 if ((gsi >= mp_ioapic_routing[i].gsi_base)
871 && (gsi <= mp_ioapic_routing[i].gsi_end))
872 return i;
873 }
874
875 printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
876 return -1;
877}
878
879static u8 __init uniq_ioapic_id(u8 id)
880{
881#ifdef CONFIG_X86_32
882 if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
883 !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
884 return io_apic_get_unique_id(nr_ioapics, id);
885 else
886 return id;
887#else
888 int i;
889 DECLARE_BITMAP(used, 256);
890 bitmap_zero(used, 256);
891 for (i = 0; i < nr_ioapics; i++) {
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400892 struct mp_config_ioapic *ia = &mp_ioapics[i];
893 __set_bit(ia->mp_apicid, used);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400894 }
895 if (!test_bit(id, used))
896 return id;
897 return find_first_zero_bit(used, 256);
898#endif
899}
900
901static int bad_ioapic(unsigned long address)
902{
903 if (nr_ioapics >= MAX_IO_APICS) {
904 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
905 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
906 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
907 }
908 if (!address) {
909 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
910 " found in table, skipping!\n");
911 return 1;
912 }
913 return 0;
914}
915
916void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
917{
918 int idx = 0;
919
920 if (bad_ioapic(address))
921 return;
922
923 idx = nr_ioapics;
924
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400925 mp_ioapics[idx].mp_type = MP_IOAPIC;
926 mp_ioapics[idx].mp_flags = MPC_APIC_USABLE;
927 mp_ioapics[idx].mp_apicaddr = address;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400928
929 set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400930 mp_ioapics[idx].mp_apicid = uniq_ioapic_id(id);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400931#ifdef CONFIG_X86_32
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400932 mp_ioapics[idx].mp_apicver = io_apic_get_version(idx);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400933#else
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400934 mp_ioapics[idx].mp_apicver = 0;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400935#endif
936 /*
937 * Build basic GSI lookup table to facilitate gsi->io_apic lookups
938 * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
939 */
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400940 mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].mp_apicid;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400941 mp_ioapic_routing[idx].gsi_base = gsi_base;
942 mp_ioapic_routing[idx].gsi_end = gsi_base +
943 io_apic_get_redir_entries(idx);
944
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400945 printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%lx, "
946 "GSI %d-%d\n", idx, mp_ioapics[idx].mp_apicid,
947 mp_ioapics[idx].mp_apicver, mp_ioapics[idx].mp_apicaddr,
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400948 mp_ioapic_routing[idx].gsi_base, mp_ioapic_routing[idx].gsi_end);
949
950 nr_ioapics++;
951}
952
Yinghai Lufcfa1462008-06-18 17:29:31 -0700953static void assign_to_mp_irq(struct mp_config_intsrc *m,
954 struct mp_config_intsrc *mp_irq)
955{
956 memcpy(mp_irq, m, sizeof(struct mp_config_intsrc));
957}
958
959static int mp_irq_cmp(struct mp_config_intsrc *mp_irq,
960 struct mp_config_intsrc *m)
961{
962 return memcmp(mp_irq, m, sizeof(struct mp_config_intsrc));
963}
964
965static void save_mp_irq(struct mp_config_intsrc *m)
966{
967 int i;
968
969 for (i = 0; i < mp_irq_entries; i++) {
970 if (!mp_irq_cmp(&mp_irqs[i], m))
971 return;
972 }
973
974 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
975 if (++mp_irq_entries == MAX_IRQ_SOURCES)
976 panic("Max # of irq sources exceeded!!\n");
977}
978
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400979void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
980{
Yinghai Lu6df88092008-06-15 18:19:46 -0700981 int ioapic;
982 int pin;
Yinghai Lufcfa1462008-06-18 17:29:31 -0700983 struct mp_config_intsrc mp_irq;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400984
Maciej W. Rozycki471694e2008-07-01 01:11:35 +0100985 /* Skip the 8254 timer interrupt (IRQ 0) if requested. */
986 if (bus_irq == 0 && disable_irq0_through_ioapic)
987 return;
988
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400989 /*
990 * Convert 'gsi' to 'ioapic.pin'.
991 */
992 ioapic = mp_find_ioapic(gsi);
993 if (ioapic < 0)
994 return;
995 pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
996
997 /*
998 * TBD: This check is for faulty timer entries, where the override
999 * erroneously sets the trigger to level, resulting in a HUGE
1000 * increase of timer interrupts!
1001 */
1002 if ((bus_irq == 0) && (trigger == 3))
1003 trigger = 1;
1004
Yinghai Lufcfa1462008-06-18 17:29:31 -07001005 mp_irq.mp_type = MP_INTSRC;
1006 mp_irq.mp_irqtype = mp_INT;
1007 mp_irq.mp_irqflag = (trigger << 2) | polarity;
1008 mp_irq.mp_srcbus = MP_ISA_BUS;
1009 mp_irq.mp_srcbusirq = bus_irq; /* IRQ */
1010 mp_irq.mp_dstapic = mp_ioapics[ioapic].mp_apicid; /* APIC ID */
1011 mp_irq.mp_dstirq = pin; /* INTIN# */
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001012
Yinghai Lufcfa1462008-06-18 17:29:31 -07001013 save_mp_irq(&mp_irq);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001014}
1015
1016void __init mp_config_acpi_legacy_irqs(void)
1017{
Yinghai Lu6df88092008-06-15 18:19:46 -07001018 int i;
1019 int ioapic;
1020 unsigned int dstapic;
Yinghai Lufcfa1462008-06-18 17:29:31 -07001021 struct mp_config_intsrc mp_irq;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001022
1023#if defined (CONFIG_MCA) || defined (CONFIG_EISA)
1024 /*
1025 * Fabricate the legacy ISA bus (bus #31).
1026 */
1027 mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
1028#endif
1029 set_bit(MP_ISA_BUS, mp_bus_not_pci);
1030 Dprintk("Bus #%d is ISA\n", MP_ISA_BUS);
1031
Yinghai Lud49c4282008-06-08 18:31:54 -07001032#ifdef CONFIG_X86_ES7000
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001033 /*
1034 * Older generations of ES7000 have no legacy identity mappings
1035 */
1036 if (es7000_plat == 1)
1037 return;
1038#endif
1039
1040 /*
1041 * Locate the IOAPIC that manages the ISA IRQs (0-15).
1042 */
1043 ioapic = mp_find_ioapic(0);
1044 if (ioapic < 0)
1045 return;
Yinghai Lu6df88092008-06-15 18:19:46 -07001046 dstapic = mp_ioapics[ioapic].mp_apicid;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001047
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001048 /*
1049 * Use the default configuration for the IRQs 0-15. Unless
1050 * overridden by (MADT) interrupt source override entries.
1051 */
1052 for (i = 0; i < 16; i++) {
1053 int idx;
1054
Maciej W. Rozycki471694e2008-07-01 01:11:35 +01001055 /* Skip the 8254 timer interrupt (IRQ 0) if requested. */
1056 if (i == 0 && disable_irq0_through_ioapic)
1057 continue;
1058
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001059 for (idx = 0; idx < mp_irq_entries; idx++) {
Alexey Starikovskiy2fddb6e282008-05-14 19:03:17 +04001060 struct mp_config_intsrc *irq = mp_irqs + idx;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001061
1062 /* Do we already have a mapping for this ISA IRQ? */
Alexey Starikovskiy2fddb6e282008-05-14 19:03:17 +04001063 if (irq->mp_srcbus == MP_ISA_BUS
1064 && irq->mp_srcbusirq == i)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001065 break;
1066
1067 /* Do we already have a mapping for this IOAPIC pin */
Yinghai Lu6df88092008-06-15 18:19:46 -07001068 if (irq->mp_dstapic == dstapic &&
1069 irq->mp_dstirq == i)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001070 break;
1071 }
1072
1073 if (idx != mp_irq_entries) {
1074 printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
1075 continue; /* IRQ already used */
1076 }
1077
Yinghai Lufcfa1462008-06-18 17:29:31 -07001078 mp_irq.mp_type = MP_INTSRC;
1079 mp_irq.mp_irqflag = 0; /* Conforming */
1080 mp_irq.mp_srcbus = MP_ISA_BUS;
1081 mp_irq.mp_dstapic = dstapic;
1082 mp_irq.mp_irqtype = mp_INT;
1083 mp_irq.mp_srcbusirq = i; /* Identity mapped */
1084 mp_irq.mp_dstirq = i;
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}
1089
1090int mp_register_gsi(u32 gsi, int triggering, int polarity)
1091{
1092 int ioapic;
1093 int ioapic_pin;
1094#ifdef CONFIG_X86_32
1095#define MAX_GSI_NUM 4096
1096#define IRQ_COMPRESSION_START 64
1097
1098 static int pci_irq = IRQ_COMPRESSION_START;
1099 /*
1100 * Mapping between Global System Interrupts, which
1101 * represent all possible interrupts, and IRQs
1102 * assigned to actual devices.
1103 */
1104 static int gsi_to_irq[MAX_GSI_NUM];
1105#else
1106
1107 if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
1108 return gsi;
1109#endif
1110
1111 /* Don't set up the ACPI SCI because it's already set up */
1112 if (acpi_gbl_FADT.sci_interrupt == gsi)
1113 return gsi;
1114
1115 ioapic = mp_find_ioapic(gsi);
1116 if (ioapic < 0) {
1117 printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
1118 return gsi;
1119 }
1120
1121 ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
1122
1123#ifdef CONFIG_X86_32
1124 if (ioapic_renumber_irq)
1125 gsi = ioapic_renumber_irq(ioapic, gsi);
1126#endif
1127
1128 /*
1129 * Avoid pin reprogramming. PRTs typically include entries
1130 * with redundant pin->gsi mappings (but unique PCI devices);
1131 * we only program the IOAPIC on the first.
1132 */
1133 if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
1134 printk(KERN_ERR "Invalid reference to IOAPIC pin "
1135 "%d-%d\n", mp_ioapic_routing[ioapic].apic_id,
1136 ioapic_pin);
1137 return gsi;
1138 }
1139 if (test_bit(ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed)) {
1140 Dprintk(KERN_DEBUG "Pin %d-%d already programmed\n",
1141 mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
1142#ifdef CONFIG_X86_32
1143 return (gsi < IRQ_COMPRESSION_START ? gsi : gsi_to_irq[gsi]);
1144#else
1145 return gsi;
1146#endif
1147 }
1148
1149 set_bit(ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed);
1150#ifdef CONFIG_X86_32
1151 /*
1152 * For GSI >= 64, use IRQ compression
1153 */
1154 if ((gsi >= IRQ_COMPRESSION_START)
1155 && (triggering == ACPI_LEVEL_SENSITIVE)) {
1156 /*
1157 * For PCI devices assign IRQs in order, avoiding gaps
1158 * due to unused I/O APIC pins.
1159 */
1160 int irq = gsi;
1161 if (gsi < MAX_GSI_NUM) {
1162 /*
1163 * Retain the VIA chipset work-around (gsi > 15), but
1164 * avoid a problem where the 8254 timer (IRQ0) is setup
1165 * via an override (so it's not on pin 0 of the ioapic),
1166 * and at the same time, the pin 0 interrupt is a PCI
1167 * type. The gsi > 15 test could cause these two pins
1168 * to be shared as IRQ0, and they are not shareable.
1169 * So test for this condition, and if necessary, avoid
1170 * the pin collision.
1171 */
1172 gsi = pci_irq++;
1173 /*
1174 * Don't assign IRQ used by ACPI SCI
1175 */
1176 if (gsi == acpi_gbl_FADT.sci_interrupt)
1177 gsi = pci_irq++;
1178 gsi_to_irq[irq] = gsi;
1179 } else {
1180 printk(KERN_ERR "GSI %u is too high\n", gsi);
1181 return gsi;
1182 }
1183 }
1184#endif
1185 io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
1186 triggering == ACPI_EDGE_SENSITIVE ? 0 : 1,
1187 polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
1188 return gsi;
1189}
1190
Yinghai Lu2944e162008-06-01 13:17:38 -07001191int mp_config_acpi_gsi(unsigned char number, unsigned int devfn, u8 pin,
1192 u32 gsi, int triggering, int polarity)
1193{
Yinghai Lufcfa1462008-06-18 17:29:31 -07001194#ifdef CONFIG_X86_MPPARSE
1195 struct mp_config_intsrc mp_irq;
Yinghai Lu2944e162008-06-01 13:17:38 -07001196 int ioapic;
1197
Yinghai Lufcfa1462008-06-18 17:29:31 -07001198 if (!acpi_ioapic)
Yinghai Lud867e532008-06-14 01:26:41 -07001199 return 0;
1200
Yinghai Lu2944e162008-06-01 13:17:38 -07001201 /* print the entry should happen on mptable identically */
Yinghai Lufcfa1462008-06-18 17:29:31 -07001202 mp_irq.mp_type = MP_INTSRC;
1203 mp_irq.mp_irqtype = mp_INT;
1204 mp_irq.mp_irqflag = (triggering == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
Yinghai Lu2944e162008-06-01 13:17:38 -07001205 (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
Yinghai Lufcfa1462008-06-18 17:29:31 -07001206 mp_irq.mp_srcbus = number;
1207 mp_irq.mp_srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
Yinghai Lu2944e162008-06-01 13:17:38 -07001208 ioapic = mp_find_ioapic(gsi);
Yinghai Lufcfa1462008-06-18 17:29:31 -07001209 mp_irq.mp_dstapic = mp_ioapic_routing[ioapic].apic_id;
1210 mp_irq.mp_dstirq = gsi - mp_ioapic_routing[ioapic].gsi_base;
Yinghai Lu2944e162008-06-01 13:17:38 -07001211
Yinghai Lufcfa1462008-06-18 17:29:31 -07001212 save_mp_irq(&mp_irq);
1213#endif
Yinghai Lu2944e162008-06-01 13:17:38 -07001214 return 0;
1215}
1216
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217/*
1218 * Parse IOAPIC related entries in MADT
1219 * returns 0 on success, < 0 on error
1220 */
Len Brown4be44fc2005-08-05 00:44:28 -04001221static int __init acpi_parse_madt_ioapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222{
1223 int count;
1224
1225 /*
1226 * ACPI interpreter is required to complete interrupt setup,
1227 * so if it is off, don't enumerate the io-apics with ACPI.
1228 * If MPS is present, it will handle them,
1229 * otherwise the system will stay in PIC mode
1230 */
1231 if (acpi_disabled || acpi_noirq) {
1232 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -04001233 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001235 if (!cpu_has_apic)
Andi Kleend3b6a342006-04-07 19:49:39 +02001236 return -ENODEV;
1237
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001239 * if "noapic" boot option, don't look for IO-APICs
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 */
1241 if (skip_ioapic_setup) {
1242 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
Len Brown4be44fc2005-08-05 00:44:28 -04001243 "due to 'noapic' option.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 return -ENODEV;
1245 }
1246
Len Brown4be44fc2005-08-05 00:44:28 -04001247 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001248 acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
Len Brown4be44fc2005-08-05 00:44:28 -04001249 MAX_IO_APICS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 if (!count) {
1251 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
1252 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -04001253 } else if (count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
1255 return count;
1256 }
1257
Len Brown4be44fc2005-08-05 00:44:28 -04001258 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001259 acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr,
Len Brown4be44fc2005-08-05 00:44:28 -04001260 NR_IRQ_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 if (count < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -04001262 printk(KERN_ERR PREFIX
1263 "Error parsing interrupt source overrides entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 /* TBD: Cleanup to allow fallback to MPS */
1265 return count;
1266 }
1267
1268 /*
1269 * If BIOS did not supply an INT_SRC_OVR for the SCI
1270 * pretend we got one so we can set the SCI flags.
1271 */
1272 if (!acpi_sci_override_gsi)
Alexey Starikovskiycee324b2007-02-02 19:48:22 +03001273 acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
1275 /* Fill in identity legacy mapings where no override */
1276 mp_config_acpi_legacy_irqs();
1277
Len Brown4be44fc2005-08-05 00:44:28 -04001278 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001279 acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src,
Len Brown4be44fc2005-08-05 00:44:28 -04001280 NR_IRQ_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 if (count < 0) {
1282 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
1283 /* TBD: Cleanup to allow fallback to MPS */
1284 return count;
1285 }
1286
1287 return 0;
1288}
1289#else
1290static inline int acpi_parse_madt_ioapic_entries(void)
1291{
1292 return -1;
1293}
Len Brown84663612005-08-24 12:09:07 -04001294#endif /* !CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001296static void __init early_acpi_process_madt(void)
1297{
1298#ifdef CONFIG_X86_LOCAL_APIC
1299 int error;
1300
1301 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1302
1303 /*
1304 * Parse MADT LAPIC entries
1305 */
1306 error = early_acpi_parse_madt_lapic_addr_ovr();
1307 if (!error) {
1308 acpi_lapic = 1;
1309 smp_found_config = 1;
1310 }
1311 if (error == -EINVAL) {
1312 /*
1313 * Dell Precision Workstation 410, 610 come here.
1314 */
1315 printk(KERN_ERR PREFIX
1316 "Invalid BIOS MADT, disabling ACPI\n");
1317 disable_acpi();
1318 }
1319 }
1320#endif
1321}
1322
Len Brown4be44fc2005-08-05 00:44:28 -04001323static void __init acpi_process_madt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324{
1325#ifdef CONFIG_X86_LOCAL_APIC
Len Brown7f8f97c2007-02-10 21:28:03 -05001326 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
Len Brown7f8f97c2007-02-10 21:28:03 -05001328 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
1330 /*
1331 * Parse MADT LAPIC entries
1332 */
1333 error = acpi_parse_madt_lapic_entries();
1334 if (!error) {
1335 acpi_lapic = 1;
1336
Venkatesh Pallipadi911a62d2005-09-03 15:56:31 -07001337#ifdef CONFIG_X86_GENERICARCH
1338 generic_bigsmp_probe();
1339#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 /*
1341 * Parse MADT IO-APIC entries
1342 */
1343 error = acpi_parse_madt_ioapic_entries();
1344 if (!error) {
1345 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
1346 acpi_irq_balance_set(NULL);
1347 acpi_ioapic = 1;
1348
1349 smp_found_config = 1;
Ingo Molnar3c43f032007-05-02 19:27:04 +02001350 setup_apic_routing();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 }
1352 }
1353 if (error == -EINVAL) {
1354 /*
1355 * Dell Precision Workstation 410, 610 come here.
1356 */
Len Brown4be44fc2005-08-05 00:44:28 -04001357 printk(KERN_ERR PREFIX
1358 "Invalid BIOS MADT, disabling ACPI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 disable_acpi();
1360 }
1361 }
1362#endif
1363 return;
1364}
1365
Jeff Garzik18552562007-10-03 15:15:40 -04001366static int __init disable_acpi_irq(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001367{
1368 if (!acpi_force) {
1369 printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
1370 d->ident);
1371 acpi_noirq_set();
1372 }
1373 return 0;
1374}
1375
Jeff Garzik18552562007-10-03 15:15:40 -04001376static int __init disable_acpi_pci(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001377{
1378 if (!acpi_force) {
1379 printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
1380 d->ident);
1381 acpi_disable_pci();
1382 }
1383 return 0;
1384}
Andrey Paninaea00142005-06-25 14:54:42 -07001385
Jeff Garzik18552562007-10-03 15:15:40 -04001386static int __init dmi_disable_acpi(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001387{
1388 if (!acpi_force) {
Len Brown4be44fc2005-08-05 00:44:28 -04001389 printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
Andrey Paninaea00142005-06-25 14:54:42 -07001390 disable_acpi();
1391 } else {
1392 printk(KERN_NOTICE
1393 "Warning: DMI blacklist says broken, but acpi forced\n");
1394 }
1395 return 0;
1396}
1397
1398/*
1399 * Limit ACPI to CPU enumeration for HT
1400 */
Jeff Garzik18552562007-10-03 15:15:40 -04001401static int __init force_acpi_ht(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001402{
1403 if (!acpi_force) {
Len Brown4be44fc2005-08-05 00:44:28 -04001404 printk(KERN_NOTICE "%s detected: force use of acpi=ht\n",
1405 d->ident);
Andrey Paninaea00142005-06-25 14:54:42 -07001406 disable_acpi();
1407 acpi_ht = 1;
1408 } else {
1409 printk(KERN_NOTICE
1410 "Warning: acpi=force overrules DMI blacklist: acpi=ht\n");
1411 }
1412 return 0;
1413}
1414
1415/*
Matthew Garrett9340e1c2008-07-01 01:12:06 +01001416 * Don't register any I/O APIC entries for the 8254 timer IRQ.
1417 */
1418static int __init
1419dmi_disable_irq0_through_ioapic(const struct dmi_system_id *d)
1420{
1421 pr_notice("%s detected: disabling IRQ 0 through I/O APIC\n", d->ident);
1422 disable_irq0_through_ioapic = 1;
1423 return 0;
1424}
1425
1426/*
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001427 * Force ignoring BIOS IRQ0 pin2 override
1428 */
1429static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
1430{
1431 pr_notice("%s detected: Ignoring BIOS IRQ0 pin2 override\n", d->ident);
1432 acpi_skip_timer_override = 1;
1433 force_mask_ioapic_irq_2();
1434 return 0;
1435}
1436
1437/*
Andrey Paninaea00142005-06-25 14:54:42 -07001438 * If your system is blacklisted here, but you find that acpi=force
1439 * works for you, please contact acpi-devel@sourceforge.net
1440 */
1441static struct dmi_system_id __initdata acpi_dmi_table[] = {
1442 /*
1443 * Boxes that need ACPI disabled
1444 */
1445 {
Len Brown4be44fc2005-08-05 00:44:28 -04001446 .callback = dmi_disable_acpi,
1447 .ident = "IBM Thinkpad",
1448 .matches = {
1449 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1450 DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
1451 },
1452 },
Andrey Paninaea00142005-06-25 14:54:42 -07001453
1454 /*
1455 * Boxes that need acpi=ht
1456 */
1457 {
Len Brown4be44fc2005-08-05 00:44:28 -04001458 .callback = force_acpi_ht,
1459 .ident = "FSC Primergy T850",
1460 .matches = {
1461 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
1462 DMI_MATCH(DMI_PRODUCT_NAME, "PRIMERGY T850"),
1463 },
1464 },
Andrey Paninaea00142005-06-25 14:54:42 -07001465 {
Len Brown4be44fc2005-08-05 00:44:28 -04001466 .callback = force_acpi_ht,
Len Brown4be44fc2005-08-05 00:44:28 -04001467 .ident = "HP VISUALIZE NT Workstation",
1468 .matches = {
1469 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
1470 DMI_MATCH(DMI_PRODUCT_NAME, "HP VISUALIZE NT Workstation"),
1471 },
1472 },
Andrey Paninaea00142005-06-25 14:54:42 -07001473 {
Len Brown4be44fc2005-08-05 00:44:28 -04001474 .callback = force_acpi_ht,
1475 .ident = "Compaq Workstation W8000",
1476 .matches = {
1477 DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
1478 DMI_MATCH(DMI_PRODUCT_NAME, "Workstation W8000"),
1479 },
1480 },
Andrey Paninaea00142005-06-25 14:54:42 -07001481 {
Len Brown4be44fc2005-08-05 00:44:28 -04001482 .callback = force_acpi_ht,
1483 .ident = "ASUS P4B266",
1484 .matches = {
1485 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1486 DMI_MATCH(DMI_BOARD_NAME, "P4B266"),
1487 },
1488 },
Andrey Paninaea00142005-06-25 14:54:42 -07001489 {
Len Brown4be44fc2005-08-05 00:44:28 -04001490 .callback = force_acpi_ht,
1491 .ident = "ASUS P2B-DS",
1492 .matches = {
1493 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1494 DMI_MATCH(DMI_BOARD_NAME, "P2B-DS"),
1495 },
1496 },
Andrey Paninaea00142005-06-25 14:54:42 -07001497 {
Len Brown4be44fc2005-08-05 00:44:28 -04001498 .callback = force_acpi_ht,
1499 .ident = "ASUS CUR-DLS",
1500 .matches = {
1501 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1502 DMI_MATCH(DMI_BOARD_NAME, "CUR-DLS"),
1503 },
1504 },
Andrey Paninaea00142005-06-25 14:54:42 -07001505 {
Len Brown4be44fc2005-08-05 00:44:28 -04001506 .callback = force_acpi_ht,
1507 .ident = "ABIT i440BX-W83977",
1508 .matches = {
1509 DMI_MATCH(DMI_BOARD_VENDOR, "ABIT <http://www.abit.com>"),
1510 DMI_MATCH(DMI_BOARD_NAME, "i440BX-W83977 (BP6)"),
1511 },
1512 },
Andrey Paninaea00142005-06-25 14:54:42 -07001513 {
Len Brown4be44fc2005-08-05 00:44:28 -04001514 .callback = force_acpi_ht,
1515 .ident = "IBM Bladecenter",
1516 .matches = {
1517 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1518 DMI_MATCH(DMI_BOARD_NAME, "IBM eServer BladeCenter HS20"),
1519 },
1520 },
Andrey Paninaea00142005-06-25 14:54:42 -07001521 {
Len Brown4be44fc2005-08-05 00:44:28 -04001522 .callback = force_acpi_ht,
1523 .ident = "IBM eServer xSeries 360",
1524 .matches = {
1525 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1526 DMI_MATCH(DMI_BOARD_NAME, "eServer xSeries 360"),
1527 },
1528 },
Andrey Paninaea00142005-06-25 14:54:42 -07001529 {
Len Brown4be44fc2005-08-05 00:44:28 -04001530 .callback = force_acpi_ht,
1531 .ident = "IBM eserver xSeries 330",
1532 .matches = {
1533 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1534 DMI_MATCH(DMI_BOARD_NAME, "eserver xSeries 330"),
1535 },
1536 },
Andrey Paninaea00142005-06-25 14:54:42 -07001537 {
Len Brown4be44fc2005-08-05 00:44:28 -04001538 .callback = force_acpi_ht,
1539 .ident = "IBM eserver xSeries 440",
1540 .matches = {
1541 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1542 DMI_MATCH(DMI_PRODUCT_NAME, "eserver xSeries 440"),
1543 },
1544 },
Andrey Paninaea00142005-06-25 14:54:42 -07001545
Andrey Paninaea00142005-06-25 14:54:42 -07001546 /*
1547 * Boxes that need ACPI PCI IRQ routing disabled
1548 */
1549 {
Len Brown4be44fc2005-08-05 00:44:28 -04001550 .callback = disable_acpi_irq,
1551 .ident = "ASUS A7V",
1552 .matches = {
1553 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
1554 DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
1555 /* newer BIOS, Revision 1011, does work */
1556 DMI_MATCH(DMI_BIOS_VERSION,
1557 "ASUS A7V ACPI BIOS Revision 1007"),
1558 },
1559 },
Len Brown74586fc2007-03-08 02:48:30 -05001560 {
1561 /*
1562 * Latest BIOS for IBM 600E (1.16) has bad pcinum
1563 * for LPC bridge, which is needed for the PCI
1564 * interrupt links to work. DSDT fix is in bug 5966.
1565 * 2645, 2646 model numbers are shared with 600/600E/600X
1566 */
1567 .callback = disable_acpi_irq,
1568 .ident = "IBM Thinkpad 600 Series 2645",
1569 .matches = {
1570 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1571 DMI_MATCH(DMI_BOARD_NAME, "2645"),
1572 },
1573 },
1574 {
1575 .callback = disable_acpi_irq,
1576 .ident = "IBM Thinkpad 600 Series 2646",
1577 .matches = {
1578 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1579 DMI_MATCH(DMI_BOARD_NAME, "2646"),
1580 },
1581 },
Andrey Paninaea00142005-06-25 14:54:42 -07001582 /*
1583 * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
1584 */
Len Brown4be44fc2005-08-05 00:44:28 -04001585 { /* _BBN 0 bug */
1586 .callback = disable_acpi_pci,
1587 .ident = "ASUS PR-DLS",
1588 .matches = {
1589 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1590 DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
1591 DMI_MATCH(DMI_BIOS_VERSION,
1592 "ASUS PR-DLS ACPI BIOS Revision 1010"),
1593 DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
1594 },
1595 },
Andrey Paninaea00142005-06-25 14:54:42 -07001596 {
Len Brown4be44fc2005-08-05 00:44:28 -04001597 .callback = disable_acpi_pci,
1598 .ident = "Acer TravelMate 36x Laptop",
1599 .matches = {
1600 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
1601 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
1602 },
1603 },
Matthew Garrett9340e1c2008-07-01 01:12:06 +01001604 /*
1605 * HP laptops which use a DSDT reporting as HP/SB400/10000,
1606 * which includes some code which overrides all temperature
1607 * trip points to 16C if the INTIN2 input of the I/O APIC
1608 * is enabled. This input is incorrectly designated the
1609 * ISA IRQ 0 via an interrupt source override even though
1610 * it is wired to the output of the master 8259A and INTIN0
1611 * is not connected at all. Abandon any attempts to route
1612 * IRQ 0 through the I/O APIC therefore.
1613 */
1614 {
1615 .callback = dmi_disable_irq0_through_ioapic,
1616 .ident = "HP NX6125 laptop",
1617 .matches = {
1618 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1619 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
1620 },
1621 },
1622 {
1623 .callback = dmi_disable_irq0_through_ioapic,
1624 .ident = "HP NX6325 laptop",
1625 .matches = {
1626 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1627 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
1628 },
1629 },
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001630 /*
1631 * HP laptops which use a DSDT reporting as HP/SB400/10000,
1632 * which includes some code which overrides all temperature
1633 * trip points to 16C if the INTIN2 input of the I/O APIC
1634 * is enabled. This input is incorrectly designated the
1635 * ISA IRQ 0 via an interrupt source override even though
1636 * it is wired to the output of the master 8259A and INTIN0
1637 * is not connected at all. Force ignoring BIOS IRQ0 pin2
1638 * override in that cases.
1639 */
1640 {
1641 .callback = dmi_ignore_irq0_timer_override,
1642 .ident = "HP NX6125 laptop",
1643 .matches = {
1644 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1645 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
1646 },
1647 },
1648 {
1649 .callback = dmi_ignore_irq0_timer_override,
1650 .ident = "HP NX6325 laptop",
1651 .matches = {
1652 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1653 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
1654 },
1655 },
Len Brown4be44fc2005-08-05 00:44:28 -04001656 {}
Andrey Paninaea00142005-06-25 14:54:42 -07001657};
1658
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659/*
1660 * acpi_boot_table_init() and acpi_boot_init()
1661 * called from setup_arch(), always.
1662 * 1. checksums all tables
1663 * 2. enumerates lapics
1664 * 3. enumerates io-apics
1665 *
1666 * acpi_table_init() is separate to allow reading SRAT without
1667 * other side effects.
1668 *
1669 * side effects of acpi_boot_init:
1670 * acpi_lapic = 1 if LAPIC found
1671 * acpi_ioapic = 1 if IOAPIC found
1672 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
1673 * if acpi_blacklisted() acpi_disabled = 1;
1674 * acpi_irq_model=...
1675 * ...
1676 *
1677 * return value: (currently ignored)
1678 * 0: success
1679 * !0: failure
1680 */
1681
Len Brown4be44fc2005-08-05 00:44:28 -04001682int __init acpi_boot_table_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683{
1684 int error;
1685
Andrey Paninaea00142005-06-25 14:54:42 -07001686 dmi_check_system(acpi_dmi_table);
Andrey Paninaea00142005-06-25 14:54:42 -07001687
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 /*
1689 * If acpi_disabled, bail out
1690 * One exception: acpi=ht continues far enough to enumerate LAPICs
1691 */
1692 if (acpi_disabled && !acpi_ht)
Len Brown4be44fc2005-08-05 00:44:28 -04001693 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001695 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 * Initialize the ACPI boot-time table parser.
1697 */
1698 error = acpi_table_init();
1699 if (error) {
1700 disable_acpi();
1701 return error;
1702 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001704 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
1706 /*
1707 * blacklist may disable ACPI entirely
1708 */
1709 error = acpi_blacklisted();
1710 if (error) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 if (acpi_force) {
1712 printk(KERN_WARNING PREFIX "acpi=force override\n");
1713 } else {
1714 printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
1715 disable_acpi();
1716 return error;
1717 }
1718 }
1719
1720 return 0;
1721}
1722
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001723int __init early_acpi_boot_init(void)
1724{
1725 /*
1726 * If acpi_disabled, bail out
1727 * One exception: acpi=ht continues far enough to enumerate LAPICs
1728 */
1729 if (acpi_disabled && !acpi_ht)
1730 return 1;
1731
1732 /*
1733 * Process the Multiple APIC Description Table (MADT), if present
1734 */
1735 early_acpi_process_madt();
1736
1737 return 0;
1738}
1739
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740int __init acpi_boot_init(void)
1741{
1742 /*
1743 * If acpi_disabled, bail out
1744 * One exception: acpi=ht continues far enough to enumerate LAPICs
1745 */
1746 if (acpi_disabled && !acpi_ht)
Len Brown4be44fc2005-08-05 00:44:28 -04001747 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001749 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750
1751 /*
1752 * set sci_int and PM timer address
1753 */
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +03001754 acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
1756 /*
1757 * Process the Multiple APIC Description Table (MADT), if present
1758 */
1759 acpi_process_madt();
1760
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001761 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762
1763 return 0;
1764}
Rusty Russell1a3f2392006-09-26 10:52:32 +02001765
1766static int __init parse_acpi(char *arg)
1767{
1768 if (!arg)
1769 return -EINVAL;
1770
1771 /* "acpi=off" disables both ACPI table parsing and interpreter */
1772 if (strcmp(arg, "off") == 0) {
1773 disable_acpi();
1774 }
1775 /* acpi=force to over-ride black-list */
1776 else if (strcmp(arg, "force") == 0) {
1777 acpi_force = 1;
1778 acpi_ht = 1;
1779 acpi_disabled = 0;
1780 }
1781 /* acpi=strict disables out-of-spec workarounds */
1782 else if (strcmp(arg, "strict") == 0) {
1783 acpi_strict = 1;
1784 }
1785 /* Limit ACPI just to boot-time to enable HT */
1786 else if (strcmp(arg, "ht") == 0) {
1787 if (!acpi_force)
1788 disable_acpi();
1789 acpi_ht = 1;
1790 }
1791 /* "acpi=noirq" disables ACPI interrupt routing */
1792 else if (strcmp(arg, "noirq") == 0) {
1793 acpi_noirq_set();
1794 } else {
1795 /* Core will printk when we return error. */
1796 return -EINVAL;
1797 }
1798 return 0;
1799}
1800early_param("acpi", parse_acpi);
1801
1802/* FIXME: Using pci= for an ACPI parameter is a travesty. */
1803static int __init parse_pci(char *arg)
1804{
1805 if (arg && strcmp(arg, "noacpi") == 0)
1806 acpi_disable_pci();
1807 return 0;
1808}
1809early_param("pci", parse_pci);
1810
Yinghai Lu3c999f12008-06-20 16:11:20 -07001811int __init acpi_mps_check(void)
1812{
1813#if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
1814/* mptable code is not built-in*/
1815 if (acpi_disabled || acpi_noirq) {
1816 printk(KERN_WARNING "MPS support code is not built-in.\n"
1817 "Using acpi=off or acpi=noirq or pci=noacpi "
1818 "may have problem\n");
1819 return 1;
1820 }
1821#endif
1822 return 0;
1823}
1824
Rusty Russell1a3f2392006-09-26 10:52:32 +02001825#ifdef CONFIG_X86_IO_APIC
1826static int __init parse_acpi_skip_timer_override(char *arg)
1827{
1828 acpi_skip_timer_override = 1;
1829 return 0;
1830}
1831early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
Andi Kleenfa18f472006-11-14 16:57:46 +01001832
1833static int __init parse_acpi_use_timer_override(char *arg)
1834{
1835 acpi_use_timer_override = 1;
1836 return 0;
1837}
1838early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001839#endif /* CONFIG_X86_IO_APIC */
1840
1841static int __init setup_acpi_sci(char *s)
1842{
1843 if (!s)
1844 return -EINVAL;
1845 if (!strcmp(s, "edge"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001846 acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
1847 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001848 else if (!strcmp(s, "level"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001849 acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
1850 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001851 else if (!strcmp(s, "high"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001852 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
1853 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001854 else if (!strcmp(s, "low"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001855 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
1856 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001857 else
1858 return -EINVAL;
1859 return 0;
1860}
1861early_param("acpi_sci", setup_acpi_sci);
Andrew Mortond0a90812006-10-20 14:30:27 -07001862
1863int __acpi_acquire_global_lock(unsigned int *lock)
1864{
1865 unsigned int old, new, val;
1866 do {
1867 old = *lock;
1868 new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
1869 val = cmpxchg(lock, old, new);
1870 } while (unlikely (val != old));
1871 return (new < 3) ? -1 : 0;
1872}
1873
1874int __acpi_release_global_lock(unsigned int *lock)
1875{
1876 unsigned int old, new, val;
1877 do {
1878 old = *lock;
1879 new = old & ~0x3;
1880 val = cmpxchg(lock, old, new);
1881 } while (unlikely (val != old));
1882 return old & 0x1;
1883}