blob: 325fbbab7f89621c266cf543baf7b72c9fc11104 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/slab.h>
adurbin@google.comf0f4c342006-09-26 10:52:39 +020035#include <linux/bootmem.h>
36#include <linux/ioport.h>
Yinghai Lua31f8202009-05-06 10:06:15 -070037#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Thomas Gleixnerb72d0db2009-08-29 16:24:51 +020039#include <asm/pci_x86.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <asm/pgtable.h>
41#include <asm/io_apic.h>
42#include <asm/apic.h>
43#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <asm/mpspec.h>
Alexey Starikovskiydfac2182008-04-04 23:41:50 +040045#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Adrian Bunke8924ac2006-09-26 10:52:35 +020047static int __initdata acpi_force = 0;
Zhao Yakui237889b2008-12-17 16:55:18 +080048u32 acpi_rsdt_forced;
Len Brownc636f752009-05-19 23:47:38 -040049int acpi_disabled;
Andi Kleendf3bb572006-09-26 10:52:33 +020050EXPORT_SYMBOL(acpi_disabled);
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#ifdef CONFIG_X86_64
Ingo Molnar1dcdd3d2009-01-28 17:55:37 +010053# include <asm/proto.h>
Haicheng Li0271f912010-02-04 19:06:33 +080054# include <asm/numa_64.h>
Len Brown4be44fc2005-08-05 00:44:28 -040055#endif /* X86 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57#define BAD_MADT_ENTRY(entry, end) ( \
58 (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +030059 ((struct acpi_subtable_header *)entry)->length < sizeof(*entry))
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61#define PREFIX "ACPI: "
62
Andrew Morton90d53902006-11-02 22:07:18 -080063int acpi_noirq; /* skip ACPI IRQ initialization */
Yinghai Lu6e4be1f2008-02-05 00:01:48 -080064int acpi_pci_disabled; /* skip ACPI PCI scan and IRQ initialization */
65EXPORT_SYMBOL(acpi_pci_disabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066int acpi_ht __initdata = 1; /* enable HT */
67
68int acpi_lapic;
69int acpi_ioapic;
70int acpi_strict;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +030072u8 acpi_sci_flags __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073int acpi_sci_override_gsi __initdata;
74int acpi_skip_timer_override __initdata;
Andi Kleenfa18f472006-11-14 16:57:46 +010075int acpi_use_timer_override __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77#ifdef CONFIG_X86_LOCAL_APIC
78static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
79#endif
80
81#ifndef __HAVE_ARCH_CMPXCHG
82#warning ACPI uses CMPXCHG, i486 and later hardware
83#endif
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085/* --------------------------------------------------------------------------
86 Boot-time Configuration
87 -------------------------------------------------------------------------- */
88
89/*
90 * The default interrupt routing model is PIC (8259). This gets
Simon Arlott27b46d72007-10-20 01:13:56 +020091 * overridden if IOAPICs are enumerated (below).
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 */
Len Brown4be44fc2005-08-05 00:44:28 -040093enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96/*
Eric W. Biederman988856e2010-03-30 01:07:15 -070097 * ISA irqs by default are the first 16 gsis but can be
98 * any gsi as specified by an interrupt source override.
99 */
100static u32 isa_irq_to_gsi[NR_IRQS_LEGACY] __read_mostly = {
101 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
102};
103
104static unsigned int gsi_to_irq(unsigned int gsi)
105{
106 unsigned int irq = gsi + NR_IRQS_LEGACY;
107 unsigned int i;
108
109 for (i = 0; i < NR_IRQS_LEGACY; i++) {
110 if (isa_irq_to_gsi[i] == gsi) {
111 return i;
112 }
113 }
114
115 /* Provide an identity mapping of gsi == irq
116 * except on truly weird platforms that have
117 * non isa irqs in the first 16 gsis.
118 */
119 if (gsi >= NR_IRQS_LEGACY)
120 irq = gsi;
121 else
122 irq = gsi_end + 1 + gsi;
123
124 return irq;
125}
126
127static u32 irq_to_gsi(int irq)
128{
129 unsigned int gsi;
130
131 if (irq < NR_IRQS_LEGACY)
132 gsi = isa_irq_to_gsi[irq];
133 else if (irq <= gsi_end)
134 gsi = irq;
135 else if (irq <= (gsi_end + NR_IRQS_LEGACY))
136 gsi = irq - gsi_end;
137 else
138 gsi = 0xffffffff;
139
140 return gsi;
141}
142
143/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
145 * to map the target physical address. The problem is that set_fixmap()
146 * provides a single page, and it is possible that the page is not
147 * sufficient.
148 * By using this area, we can map up to MAX_IO_APICS pages temporarily,
149 * i.e. until the next __va_range() call.
150 *
151 * Important Safety Note: The fixed I/O APIC page numbers are *subtracted*
152 * from the fixed base. That's why we start at FIX_IO_APIC_BASE_END and
153 * count idx down while incrementing the phys address.
154 */
Jan Beulich2fdf0742007-12-13 08:33:59 +0000155char *__init __acpi_map_table(unsigned long phys, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Yinghai Luf34fa822008-07-09 20:16:36 -0700158 if (!phys || !size)
159 return NULL;
160
Yinghai Lu7d972772009-02-07 15:39:41 -0800161 return early_ioremap(phys, size);
162}
163void __init __acpi_unmap_table(char *map, unsigned long size)
164{
165 if (!map || !size)
166 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Yinghai Lu7d972772009-02-07 15:39:41 -0800168 early_iounmap(map, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171#ifdef CONFIG_X86_LOCAL_APIC
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300172static int __init acpi_parse_madt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
Len Brown4be44fc2005-08-05 00:44:28 -0400174 struct acpi_table_madt *madt = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300176 if (!cpu_has_apic)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 return -EINVAL;
178
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300179 madt = (struct acpi_table_madt *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 if (!madt) {
181 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
182 return -ENODEV;
183 }
184
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300185 if (madt->address) {
186 acpi_lapic_addr = (u64) madt->address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188 printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300189 madt->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 }
191
Ingo Molnar306db032009-01-28 03:43:47 +0100192 default_acpi_madt_oem_check(madt->header.oem_id,
193 madt->header.oem_table_id);
Len Brown4be44fc2005-08-05 00:44:28 -0400194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 return 0;
196}
197
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400198static void __cpuinit acpi_register_lapic(int id, u8 enabled)
199{
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700200 unsigned int ver = 0;
201
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400202 if (!enabled) {
203 ++disabled_cpus;
204 return;
205 }
206
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700207 if (boot_cpu_physical_apicid != -1U)
208 ver = apic_version[boot_cpu_physical_apicid];
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700209
210 generic_processor_info(id, ver);
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400211}
212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213static int __init
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800214acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
215{
216 struct acpi_madt_local_x2apic *processor = NULL;
217
218 processor = (struct acpi_madt_local_x2apic *)header;
219
220 if (BAD_MADT_ENTRY(processor, end))
221 return -EINVAL;
222
223 acpi_table_print_madt_entry(header);
224
225#ifdef CONFIG_X86_X2APIC
226 /*
227 * We need to register disabled CPU as well to permit
228 * counting disabled CPUs. This allows us to size
229 * cpus_possible_map more accurately, to permit
230 * to not preallocating memory for all NR_CPUS
231 * when we use CPU hotplug.
232 */
233 acpi_register_lapic(processor->local_apic_id, /* APIC ID */
234 processor->lapic_flags & ACPI_MADT_ENABLED);
235#else
236 printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
237#endif
238
239 return 0;
240}
241
242static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300243acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300245 struct acpi_madt_local_apic *processor = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300247 processor = (struct acpi_madt_local_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 if (BAD_MADT_ENTRY(processor, end))
250 return -EINVAL;
251
252 acpi_table_print_madt_entry(header);
253
Ashok Raj7f66ae42006-02-03 21:51:50 +0100254 /*
255 * We need to register disabled CPU as well to permit
256 * counting disabled CPUs. This allows us to size
257 * cpus_possible_map more accurately, to permit
258 * to not preallocating memory for all NR_CPUS
259 * when we use CPU hotplug.
260 */
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400261 acpi_register_lapic(processor->id, /* APIC ID */
262 processor->lapic_flags & ACPI_MADT_ENABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264 return 0;
265}
266
267static int __init
Jack Steinerac049c12008-03-28 14:12:09 -0500268acpi_parse_sapic(struct acpi_subtable_header *header, const unsigned long end)
269{
270 struct acpi_madt_local_sapic *processor = NULL;
271
272 processor = (struct acpi_madt_local_sapic *)header;
273
274 if (BAD_MADT_ENTRY(processor, end))
275 return -EINVAL;
276
277 acpi_table_print_madt_entry(header);
278
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400279 acpi_register_lapic((processor->id << 8) | processor->eid,/* APIC ID */
280 processor->lapic_flags & ACPI_MADT_ENABLED);
Jack Steinerac049c12008-03-28 14:12:09 -0500281
282 return 0;
283}
284
285static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300286acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400287 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300289 struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300291 lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293 if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
294 return -EINVAL;
295
296 acpi_lapic_addr = lapic_addr_ovr->address;
297
298 return 0;
299}
300
301static int __init
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800302acpi_parse_x2apic_nmi(struct acpi_subtable_header *header,
303 const unsigned long end)
304{
305 struct acpi_madt_local_x2apic_nmi *x2apic_nmi = NULL;
306
307 x2apic_nmi = (struct acpi_madt_local_x2apic_nmi *)header;
308
309 if (BAD_MADT_ENTRY(x2apic_nmi, end))
310 return -EINVAL;
311
312 acpi_table_print_madt_entry(header);
313
314 if (x2apic_nmi->lint != 1)
315 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
316
317 return 0;
318}
319
320static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300321acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300323 struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300325 lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
327 if (BAD_MADT_ENTRY(lapic_nmi, end))
328 return -EINVAL;
329
330 acpi_table_print_madt_entry(header);
331
332 if (lapic_nmi->lint != 1)
333 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
334
335 return 0;
336}
337
Len Brown4be44fc2005-08-05 00:44:28 -0400338#endif /*CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Len Brown84663612005-08-24 12:09:07 -0400340#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300343acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300345 struct acpi_madt_io_apic *ioapic = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300347 ioapic = (struct acpi_madt_io_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
349 if (BAD_MADT_ENTRY(ioapic, end))
350 return -EINVAL;
Len Brown4be44fc2005-08-05 00:44:28 -0400351
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 acpi_table_print_madt_entry(header);
353
Len Brown4be44fc2005-08-05 00:44:28 -0400354 mp_register_ioapic(ioapic->id,
355 ioapic->address, ioapic->global_irq_base);
356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 return 0;
358}
359
360/*
361 * Parse Interrupt Source Override for the ACPI SCI
362 */
Eric W. Biederman9d2062b2010-03-30 01:07:05 -0700363static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger, u32 gsi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
365 if (trigger == 0) /* compatible SCI trigger is level */
366 trigger = 3;
367
368 if (polarity == 0) /* compatible SCI polarity is low */
369 polarity = 3;
370
371 /* Command-line over-ride via acpi_sci= */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300372 if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
373 trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300375 if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
376 polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
378 /*
Len Brown4be44fc2005-08-05 00:44:28 -0400379 * mp_config_acpi_legacy_irqs() already setup IRQs < 16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 * If GSI is < 16, this will update its flags,
381 * else it will create a new mp_irqs[] entry.
382 */
Eric W. Biederman9d2062b2010-03-30 01:07:05 -0700383 mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385 /*
386 * stash over-ride to indicate we've been here
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300387 * and for later update of acpi_gbl_FADT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 */
Len Brown7bdd21c2006-12-02 02:27:46 -0500389 acpi_sci_override_gsi = gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 return;
391}
392
393static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300394acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400395 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300397 struct acpi_madt_interrupt_override *intsrc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300399 intsrc = (struct acpi_madt_interrupt_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
401 if (BAD_MADT_ENTRY(intsrc, end))
402 return -EINVAL;
403
404 acpi_table_print_madt_entry(header);
405
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300406 if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
Eric W. Biederman9d2062b2010-03-30 01:07:05 -0700407 acpi_sci_ioapic_setup(intsrc->source_irq,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300408 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
Eric W. Biederman9d2062b2010-03-30 01:07:05 -0700409 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
410 intsrc->global_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 return 0;
412 }
413
414 if (acpi_skip_timer_override &&
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300415 intsrc->source_irq == 0 && intsrc->global_irq == 2) {
Len Brown4be44fc2005-08-05 00:44:28 -0400416 printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
417 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 }
419
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300420 mp_override_legacy_irq(intsrc->source_irq,
421 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
422 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
423 intsrc->global_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
425 return 0;
426}
427
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300429acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300431 struct acpi_madt_nmi_source *nmi_src = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300433 nmi_src = (struct acpi_madt_nmi_source *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435 if (BAD_MADT_ENTRY(nmi_src, end))
436 return -EINVAL;
437
438 acpi_table_print_madt_entry(header);
439
440 /* TBD: Support nimsrc entries? */
441
442 return 0;
443}
444
Len Brown4be44fc2005-08-05 00:44:28 -0400445#endif /* CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447/*
448 * acpi_pic_sci_set_trigger()
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300449 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 * use ELCR to set PIC-mode trigger type for SCI
451 *
452 * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
453 * it may require Edge Trigger -- use "acpi_sci=edge"
454 *
455 * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
456 * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
Simon Arlott27b46d72007-10-20 01:13:56 +0200457 * ECLR1 is IRQs 0-7 (IRQ 0, 1, 2 must be 0)
458 * ECLR2 is IRQs 8-15 (IRQ 8, 13 must be 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 */
460
Len Brown4be44fc2005-08-05 00:44:28 -0400461void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462{
463 unsigned int mask = 1 << irq;
464 unsigned int old, new;
465
466 /* Real old ELCR mask */
467 old = inb(0x4d0) | (inb(0x4d1) << 8);
468
469 /*
Simon Arlott27b46d72007-10-20 01:13:56 +0200470 * If we use ACPI to set PCI IRQs, then we should clear ELCR
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 * since we will set it correctly as we enable the PCI irq
472 * routing.
473 */
474 new = acpi_noirq ? old : 0;
475
476 /*
477 * Update SCI information in the ELCR, it isn't in the PCI
478 * routing tables..
479 */
480 switch (trigger) {
Len Brown4be44fc2005-08-05 00:44:28 -0400481 case 1: /* Edge - clear */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 new &= ~mask;
483 break;
Len Brown4be44fc2005-08-05 00:44:28 -0400484 case 3: /* Level - set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 new |= mask;
486 break;
487 }
488
489 if (old == new)
490 return;
491
492 printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
493 outb(new, 0x4d0);
494 outb(new >> 8, 0x4d1);
495}
496
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
498{
Eric W. Biederman988856e2010-03-30 01:07:15 -0700499 *irq = gsi_to_irq(gsi);
Yinghai Lu18dce6b2010-02-10 01:20:05 -0800500
501#ifdef CONFIG_X86_IO_APIC
502 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
503 setup_IO_APIC_irq_extra(gsi);
504#endif
505
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 return 0;
507}
508
Eric W. Biederman2c2df842010-03-30 01:07:02 -0700509int acpi_isa_irq_to_gsi(unsigned isa_irq, u32 *gsi)
510{
511 if (isa_irq >= 16)
512 return -1;
Eric W. Biederman988856e2010-03-30 01:07:15 -0700513 *gsi = irq_to_gsi(isa_irq);
Eric W. Biederman2c2df842010-03-30 01:07:02 -0700514 return 0;
515}
516
Kenji Kaneshige1f3a6a12005-07-28 14:42:00 -0400517/*
518 * success: return IRQ number (>=0)
519 * failure: return < 0
520 */
Yinghai Lue5198072009-05-15 13:05:16 -0700521int acpi_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522{
523 unsigned int irq;
524 unsigned int plat_gsi = gsi;
525
526#ifdef CONFIG_PCI
527 /*
528 * Make sure all (legacy) PCI IRQs are set as level-triggered.
529 */
530 if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
Yinghai Lue5198072009-05-15 13:05:16 -0700531 if (trigger == ACPI_LEVEL_SENSITIVE)
Len Brown4be44fc2005-08-05 00:44:28 -0400532 eisa_set_level_irq(gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 }
534#endif
535
536#ifdef CONFIG_X86_IO_APIC
537 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) {
Yinghai Lue5198072009-05-15 13:05:16 -0700538 plat_gsi = mp_register_gsi(dev, gsi, trigger, polarity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 }
540#endif
Eric W. Biederman988856e2010-03-30 01:07:15 -0700541 irq = gsi_to_irq(plat_gsi);
Yinghai Lu18dce6b2010-02-10 01:20:05 -0800542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 return irq;
544}
Len Brown4be44fc2005-08-05 00:44:28 -0400545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546/*
547 * ACPI based hotplug support for CPU
548 */
549#ifdef CONFIG_ACPI_HOTPLUG_CPU
Alex Chiangd8191fa2010-02-22 12:11:39 -0700550#include <acpi/processor.h>
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100551
Haicheng Li0271f912010-02-04 19:06:33 +0800552static void acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
553{
554#ifdef CONFIG_ACPI_NUMA
555 int nid;
556
557 nid = acpi_get_node(handle);
558 if (nid == -1 || !node_online(nid))
559 return;
560#ifdef CONFIG_X86_64
561 apicid_to_node[physid] = nid;
562 numa_set_node(cpu, nid);
563#else /* CONFIG_X86_32 */
564 apicid_2_node[physid] = nid;
565 cpu_to_node_map[cpu] = nid;
566#endif
567
568#endif
569}
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100570
571static int __cpuinit _acpi_map_lsapic(acpi_handle handle, int *pcpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572{
Ashok Raj73fea172006-09-26 10:52:35 +0200573 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
574 union acpi_object *obj;
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300575 struct acpi_madt_local_apic *lapic;
Rusty Russellee943a82008-12-31 18:08:47 -0800576 cpumask_var_t tmp_map, new_map;
Ashok Raj73fea172006-09-26 10:52:35 +0200577 u8 physid;
578 int cpu;
Rusty Russellee943a82008-12-31 18:08:47 -0800579 int retval = -ENOMEM;
Ashok Raj73fea172006-09-26 10:52:35 +0200580
581 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
582 return -EINVAL;
583
584 if (!buffer.length || !buffer.pointer)
585 return -EINVAL;
586
587 obj = buffer.pointer;
588 if (obj->type != ACPI_TYPE_BUFFER ||
589 obj->buffer.length < sizeof(*lapic)) {
590 kfree(buffer.pointer);
591 return -EINVAL;
592 }
593
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300594 lapic = (struct acpi_madt_local_apic *)obj->buffer.pointer;
Ashok Raj73fea172006-09-26 10:52:35 +0200595
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300596 if (lapic->header.type != ACPI_MADT_TYPE_LOCAL_APIC ||
597 !(lapic->lapic_flags & ACPI_MADT_ENABLED)) {
Ashok Raj73fea172006-09-26 10:52:35 +0200598 kfree(buffer.pointer);
599 return -EINVAL;
600 }
601
602 physid = lapic->id;
603
604 kfree(buffer.pointer);
605 buffer.length = ACPI_ALLOCATE_BUFFER;
606 buffer.pointer = NULL;
607
Rusty Russellee943a82008-12-31 18:08:47 -0800608 if (!alloc_cpumask_var(&tmp_map, GFP_KERNEL))
609 goto out;
610
611 if (!alloc_cpumask_var(&new_map, GFP_KERNEL))
612 goto free_tmp_map;
613
614 cpumask_copy(tmp_map, cpu_present_mask);
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400615 acpi_register_lapic(physid, lapic->lapic_flags & ACPI_MADT_ENABLED);
Ashok Raj73fea172006-09-26 10:52:35 +0200616
617 /*
618 * If mp_register_lapic successfully generates a new logical cpu
619 * number, then the following will get us exactly what was mapped
620 */
Rusty Russellee943a82008-12-31 18:08:47 -0800621 cpumask_andnot(new_map, cpu_present_mask, tmp_map);
622 if (cpumask_empty(new_map)) {
Ashok Raj73fea172006-09-26 10:52:35 +0200623 printk ("Unable to map lapic to logical cpu number\n");
Rusty Russellee943a82008-12-31 18:08:47 -0800624 retval = -EINVAL;
625 goto free_new_map;
Ashok Raj73fea172006-09-26 10:52:35 +0200626 }
627
Alex Chiangd8191fa2010-02-22 12:11:39 -0700628 acpi_processor_set_pdc(handle);
629
Rusty Russellee943a82008-12-31 18:08:47 -0800630 cpu = cpumask_first(new_map);
Haicheng Li0271f912010-02-04 19:06:33 +0800631 acpi_map_cpu2node(handle, cpu, physid);
Ashok Raj73fea172006-09-26 10:52:35 +0200632
633 *pcpu = cpu;
Rusty Russellee943a82008-12-31 18:08:47 -0800634 retval = 0;
635
636free_new_map:
637 free_cpumask_var(new_map);
638free_tmp_map:
639 free_cpumask_var(tmp_map);
640out:
641 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642}
Len Brown4be44fc2005-08-05 00:44:28 -0400643
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100644/* wrapper to silence section mismatch warning */
645int __ref acpi_map_lsapic(acpi_handle handle, int *pcpu)
646{
647 return _acpi_map_lsapic(handle, pcpu);
648}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649EXPORT_SYMBOL(acpi_map_lsapic);
650
Len Brown4be44fc2005-08-05 00:44:28 -0400651int acpi_unmap_lsapic(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652{
Mike Travis71fff5e2007-10-19 20:35:03 +0200653 per_cpu(x86_cpu_to_apicid, cpu) = -1;
Mike Travis96289372008-12-31 18:08:46 -0800654 set_cpu_present(cpu, false);
Ashok Raj73fea172006-09-26 10:52:35 +0200655 num_processors--;
656
657 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658}
Len Brown4be44fc2005-08-05 00:44:28 -0400659
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660EXPORT_SYMBOL(acpi_unmap_lsapic);
Len Brown4be44fc2005-08-05 00:44:28 -0400661#endif /* CONFIG_ACPI_HOTPLUG_CPU */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
Len Brown4be44fc2005-08-05 00:44:28 -0400663int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700664{
665 /* TBD */
666 return -EINVAL;
667}
Len Brown4be44fc2005-08-05 00:44:28 -0400668
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700669EXPORT_SYMBOL(acpi_register_ioapic);
670
Len Brown4be44fc2005-08-05 00:44:28 -0400671int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700672{
673 /* TBD */
674 return -EINVAL;
675}
Len Brown4be44fc2005-08-05 00:44:28 -0400676
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700677EXPORT_SYMBOL(acpi_unregister_ioapic);
678
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300679static int __init acpi_parse_sbf(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300681 struct acpi_table_boot *sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300683 sb = (struct acpi_table_boot *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 if (!sb) {
685 printk(KERN_WARNING PREFIX "Unable to map SBF\n");
686 return -ENODEV;
687 }
688
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300689 sbf_port = sb->cmos_index; /* Save CMOS port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
691 return 0;
692}
693
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694#ifdef CONFIG_HPET_TIMER
john stultz2d0c87c2007-02-16 01:28:18 -0800695#include <asm/hpet.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
Aaron Durbina1dfd852007-07-21 17:11:39 +0200697static struct __initdata resource *hpet_res;
698
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300699static int __init acpi_parse_hpet(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700{
701 struct acpi_table_hpet *hpet_tbl;
702
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300703 hpet_tbl = (struct acpi_table_hpet *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 if (!hpet_tbl) {
705 printk(KERN_WARNING PREFIX "Unable to map HPET\n");
706 return -ENODEV;
707 }
708
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300709 if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 printk(KERN_WARNING PREFIX "HPET timers must be located in "
711 "memory.\n");
712 return -1;
713 }
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200714
john stultz2d0c87c2007-02-16 01:28:18 -0800715 hpet_address = hpet_tbl->address.address;
Suresh Siddhac8bc6f32009-08-04 12:07:09 -0700716 hpet_blockid = hpet_tbl->sequence;
Thomas Gleixnerf4df73c2007-11-15 21:41:50 -0500717
718 /*
719 * Some broken BIOSes advertise HPET at 0x0. We really do not
720 * want to allocate a resource there.
721 */
722 if (!hpet_address) {
723 printk(KERN_WARNING PREFIX
724 "HPET id: %#x base: %#lx is invalid\n",
725 hpet_tbl->id, hpet_address);
726 return 0;
727 }
728#ifdef CONFIG_X86_64
729 /*
730 * Some even more broken BIOSes advertise HPET at
731 * 0xfed0000000000000 instead of 0xfed00000. Fix it up and add
732 * some noise:
733 */
734 if (hpet_address == 0xfed0000000000000UL) {
735 if (!hpet_force_user) {
736 printk(KERN_WARNING PREFIX "HPET id: %#x "
737 "base: 0xfed0000000000000 is bogus\n "
738 "try hpet=force on the kernel command line to "
739 "fix it up to 0xfed00000.\n", hpet_tbl->id);
740 hpet_address = 0;
741 return 0;
742 }
743 printk(KERN_WARNING PREFIX
744 "HPET id: %#x base: 0xfed0000000000000 fixed up "
745 "to 0xfed00000.\n", hpet_tbl->id);
746 hpet_address >>= 32;
747 }
748#endif
Len Brown4be44fc2005-08-05 00:44:28 -0400749 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
john stultz2d0c87c2007-02-16 01:28:18 -0800750 hpet_tbl->id, hpet_address);
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200751
Aaron Durbina1dfd852007-07-21 17:11:39 +0200752 /*
753 * Allocate and initialize the HPET firmware resource for adding into
754 * the resource tree during the lateinit timeframe.
755 */
756#define HPET_RESOURCE_NAME_SIZE 9
757 hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
758
Aaron Durbina1dfd852007-07-21 17:11:39 +0200759 hpet_res->name = (void *)&hpet_res[1];
760 hpet_res->flags = IORESOURCE_MEM;
761 snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE, "HPET %u",
762 hpet_tbl->sequence);
763
764 hpet_res->start = hpet_address;
765 hpet_res->end = hpet_address + (1 * 1024) - 1;
766
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 return 0;
768}
Aaron Durbina1dfd852007-07-21 17:11:39 +0200769
770/*
771 * hpet_insert_resource inserts the HPET resources used into the resource
772 * tree.
773 */
774static __init int hpet_insert_resource(void)
775{
776 if (!hpet_res)
777 return 1;
778
779 return insert_resource(&iomem_resource, hpet_res);
780}
781
782late_initcall(hpet_insert_resource);
783
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784#else
785#define acpi_parse_hpet NULL
786#endif
787
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300788static int __init acpi_parse_fadt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789{
Jason Davis90660ec2005-04-16 15:24:53 -0700790
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791#ifdef CONFIG_X86_PM_TIMER
792 /* detect the location of the ACPI PM Timer */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300793 if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 /* FADT rev. 2 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300795 if (acpi_gbl_FADT.xpm_timer_block.space_id !=
Len Brown4be44fc2005-08-05 00:44:28 -0400796 ACPI_ADR_SPACE_SYSTEM_IO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 return 0;
798
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300799 pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
David Shaohua Lie6e87b42005-09-21 01:35:00 -0400800 /*
801 * "X" fields are optional extensions to the original V1.0
802 * fields, so we must selectively expand V1.0 fields if the
803 * corresponding X field is zero.
804 */
805 if (!pmtmr_ioport)
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300806 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 } else {
808 /* FADT rev. 1 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300809 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 }
811 if (pmtmr_ioport)
Len Brown4be44fc2005-08-05 00:44:28 -0400812 printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
813 pmtmr_ioport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814#endif
815 return 0;
816}
817
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818#ifdef CONFIG_X86_LOCAL_APIC
819/*
820 * Parse LAPIC entries in MADT
821 * returns 0 on success, < 0 on error
822 */
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400823
824static void __init acpi_register_lapic_address(unsigned long address)
825{
826 mp_lapic_addr = address;
827
828 set_fixmap_nocache(FIX_APIC_BASE, address);
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700829 if (boot_cpu_physical_apicid == -1U) {
Yinghai Lu4c9961d2008-07-11 18:44:16 -0700830 boot_cpu_physical_apicid = read_apic_id();
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700831 apic_version[boot_cpu_physical_apicid] =
832 GET_APIC_VERSION(apic_read(APIC_LVR));
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700833 }
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400834}
835
Yinghai Lucbf9bd62008-02-19 03:21:06 -0800836static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
837{
838 int count;
839
840 if (!cpu_has_apic)
841 return -ENODEV;
842
843 /*
844 * Note that the LAPIC address is obtained from the MADT (32-bit value)
845 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
846 */
847
848 count =
849 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
850 acpi_parse_lapic_addr_ovr, 0);
851 if (count < 0) {
852 printk(KERN_ERR PREFIX
853 "Error parsing LAPIC address override entry\n");
854 return count;
855 }
856
857 acpi_register_lapic_address(acpi_lapic_addr);
858
859 return count;
860}
861
Len Brown4be44fc2005-08-05 00:44:28 -0400862static int __init acpi_parse_madt_lapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863{
864 int count;
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800865 int x2count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
Andi Kleen0fcd2702006-04-11 12:54:36 +0200867 if (!cpu_has_apic)
868 return -ENODEV;
869
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300870 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 * Note that the LAPIC address is obtained from the MADT (32-bit value)
872 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
873 */
874
Len Brown4be44fc2005-08-05 00:44:28 -0400875 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300876 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
Len Brown4be44fc2005-08-05 00:44:28 -0400877 acpi_parse_lapic_addr_ovr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 if (count < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400879 printk(KERN_ERR PREFIX
880 "Error parsing LAPIC address override entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 return count;
882 }
883
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400884 acpi_register_lapic_address(acpi_lapic_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
Jack Steinerac049c12008-03-28 14:12:09 -0500886 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
887 acpi_parse_sapic, MAX_APICS);
888
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800889 if (!count) {
890 x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
891 acpi_parse_x2apic, MAX_APICS);
Jack Steinerac049c12008-03-28 14:12:09 -0500892 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
893 acpi_parse_lapic, MAX_APICS);
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800894 }
895 if (!count && !x2count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
897 /* TBD: Cleanup to allow fallback to MPS */
898 return -ENODEV;
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800899 } else if (count < 0 || x2count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
901 /* TBD: Cleanup to allow fallback to MPS */
902 return count;
903 }
904
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800905 x2count =
906 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI,
907 acpi_parse_x2apic_nmi, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400908 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300909 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0);
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800910 if (count < 0 || x2count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
912 /* TBD: Cleanup to allow fallback to MPS */
913 return count;
914 }
915 return 0;
916}
Len Brown4be44fc2005-08-05 00:44:28 -0400917#endif /* CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
Len Brown84663612005-08-24 12:09:07 -0400919#ifdef CONFIG_X86_IO_APIC
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400920#define MP_ISA_BUS 0
921
Yinghai Lud49c4282008-06-08 18:31:54 -0700922#ifdef CONFIG_X86_ES7000
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400923extern int es7000_plat;
924#endif
925
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530926static void assign_to_mp_irq(struct mpc_intsrc *m,
927 struct mpc_intsrc *mp_irq)
Yinghai Lufcfa1462008-06-18 17:29:31 -0700928{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530929 memcpy(mp_irq, m, sizeof(struct mpc_intsrc));
Yinghai Lufcfa1462008-06-18 17:29:31 -0700930}
931
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530932static int mp_irq_cmp(struct mpc_intsrc *mp_irq,
933 struct mpc_intsrc *m)
Yinghai Lufcfa1462008-06-18 17:29:31 -0700934{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530935 return memcmp(mp_irq, m, sizeof(struct mpc_intsrc));
Yinghai Lufcfa1462008-06-18 17:29:31 -0700936}
937
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530938static void save_mp_irq(struct mpc_intsrc *m)
Yinghai Lufcfa1462008-06-18 17:29:31 -0700939{
940 int i;
941
942 for (i = 0; i < mp_irq_entries; i++) {
943 if (!mp_irq_cmp(&mp_irqs[i], m))
944 return;
945 }
946
947 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
948 if (++mp_irq_entries == MAX_IRQ_SOURCES)
949 panic("Max # of irq sources exceeded!!\n");
950}
951
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400952void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
953{
Yinghai Lu6df88092008-06-15 18:19:46 -0700954 int ioapic;
955 int pin;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530956 struct mpc_intsrc mp_irq;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400957
958 /*
959 * Convert 'gsi' to 'ioapic.pin'.
960 */
961 ioapic = mp_find_ioapic(gsi);
962 if (ioapic < 0)
963 return;
Jeremy Fitzhardingec3e137d2009-02-09 12:05:47 -0800964 pin = mp_find_ioapic_pin(ioapic, gsi);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400965
966 /*
967 * TBD: This check is for faulty timer entries, where the override
968 * erroneously sets the trigger to level, resulting in a HUGE
969 * increase of timer interrupts!
970 */
971 if ((bus_irq == 0) && (trigger == 3))
972 trigger = 1;
973
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530974 mp_irq.type = MP_INTSRC;
975 mp_irq.irqtype = mp_INT;
976 mp_irq.irqflag = (trigger << 2) | polarity;
977 mp_irq.srcbus = MP_ISA_BUS;
978 mp_irq.srcbusirq = bus_irq; /* IRQ */
979 mp_irq.dstapic = mp_ioapics[ioapic].apicid; /* APIC ID */
980 mp_irq.dstirq = pin; /* INTIN# */
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400981
Yinghai Lufcfa1462008-06-18 17:29:31 -0700982 save_mp_irq(&mp_irq);
Eric W. Biederman988856e2010-03-30 01:07:15 -0700983
984 isa_irq_to_gsi[bus_irq] = gsi;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400985}
986
987void __init mp_config_acpi_legacy_irqs(void)
988{
Yinghai Lu6df88092008-06-15 18:19:46 -0700989 int i;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530990 struct mpc_intsrc mp_irq;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400991
992#if defined (CONFIG_MCA) || defined (CONFIG_EISA)
993 /*
994 * Fabricate the legacy ISA bus (bus #31).
995 */
996 mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
997#endif
998 set_bit(MP_ISA_BUS, mp_bus_not_pci);
Thomas Gleixnercfc1b9a2008-07-21 21:35:38 +0200999 pr_debug("Bus #%d is ISA\n", MP_ISA_BUS);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001000
Yinghai Lud49c4282008-06-08 18:31:54 -07001001#ifdef CONFIG_X86_ES7000
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001002 /*
1003 * Older generations of ES7000 have no legacy identity mappings
1004 */
1005 if (es7000_plat == 1)
1006 return;
1007#endif
1008
1009 /*
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001010 * Use the default configuration for the IRQs 0-15. Unless
1011 * overridden by (MADT) interrupt source override entries.
1012 */
1013 for (i = 0; i < 16; i++) {
Eric W. Biederman0fd52672010-03-30 01:07:06 -07001014 int ioapic, pin;
1015 unsigned int dstapic;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001016 int idx;
Eric W. Biederman0fd52672010-03-30 01:07:06 -07001017 u32 gsi;
1018
1019 /* Locate the gsi that irq i maps to. */
1020 if (acpi_isa_irq_to_gsi(i, &gsi))
1021 continue;
1022
1023 /*
1024 * Locate the IOAPIC that manages the ISA IRQ.
1025 */
1026 ioapic = mp_find_ioapic(gsi);
1027 if (ioapic < 0)
1028 continue;
1029 pin = mp_find_ioapic_pin(ioapic, gsi);
1030 dstapic = mp_ioapics[ioapic].apicid;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001031
1032 for (idx = 0; idx < mp_irq_entries; idx++) {
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301033 struct mpc_intsrc *irq = mp_irqs + idx;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001034
1035 /* Do we already have a mapping for this ISA IRQ? */
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301036 if (irq->srcbus == MP_ISA_BUS && irq->srcbusirq == i)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001037 break;
1038
1039 /* Do we already have a mapping for this IOAPIC pin */
Eric W. Biederman0fd52672010-03-30 01:07:06 -07001040 if (irq->dstapic == dstapic && irq->dstirq == pin)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001041 break;
1042 }
1043
1044 if (idx != mp_irq_entries) {
1045 printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
1046 continue; /* IRQ already used */
1047 }
1048
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301049 mp_irq.type = MP_INTSRC;
1050 mp_irq.irqflag = 0; /* Conforming */
1051 mp_irq.srcbus = MP_ISA_BUS;
1052 mp_irq.dstapic = dstapic;
1053 mp_irq.irqtype = mp_INT;
1054 mp_irq.srcbusirq = i; /* Identity mapped */
Eric W. Biederman0fd52672010-03-30 01:07:06 -07001055 mp_irq.dstirq = pin;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001056
Yinghai Lufcfa1462008-06-18 17:29:31 -07001057 save_mp_irq(&mp_irq);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001058 }
1059}
1060
Yinghai Lue5198072009-05-15 13:05:16 -07001061static int mp_config_acpi_gsi(struct device *dev, u32 gsi, int trigger,
Yinghai Lua31f8202009-05-06 10:06:15 -07001062 int polarity)
1063{
1064#ifdef CONFIG_X86_MPPARSE
1065 struct mpc_intsrc mp_irq;
1066 struct pci_dev *pdev;
1067 unsigned char number;
1068 unsigned int devfn;
1069 int ioapic;
1070 u8 pin;
1071
1072 if (!acpi_ioapic)
1073 return 0;
1074 if (!dev)
1075 return 0;
1076 if (dev->bus != &pci_bus_type)
1077 return 0;
1078
1079 pdev = to_pci_dev(dev);
1080 number = pdev->bus->number;
1081 devfn = pdev->devfn;
1082 pin = pdev->pin;
1083 /* print the entry should happen on mptable identically */
1084 mp_irq.type = MP_INTSRC;
1085 mp_irq.irqtype = mp_INT;
Yinghai Lue5198072009-05-15 13:05:16 -07001086 mp_irq.irqflag = (trigger == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
Yinghai Lua31f8202009-05-06 10:06:15 -07001087 (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
1088 mp_irq.srcbus = number;
1089 mp_irq.srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
1090 ioapic = mp_find_ioapic(gsi);
Yinghai Lubdfe8ac2009-05-06 10:07:41 -07001091 mp_irq.dstapic = mp_ioapics[ioapic].apicid;
Yinghai Lua31f8202009-05-06 10:06:15 -07001092 mp_irq.dstirq = mp_find_ioapic_pin(ioapic, gsi);
1093
1094 save_mp_irq(&mp_irq);
1095#endif
1096 return 0;
1097}
1098
Yinghai Lue5198072009-05-15 13:05:16 -07001099int mp_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001100{
1101 int ioapic;
1102 int ioapic_pin;
Yinghai Lue5198072009-05-15 13:05:16 -07001103 struct io_apic_irq_attr irq_attr;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001104
1105 if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
1106 return gsi;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001107
1108 /* Don't set up the ACPI SCI because it's already set up */
1109 if (acpi_gbl_FADT.sci_interrupt == gsi)
1110 return gsi;
1111
1112 ioapic = mp_find_ioapic(gsi);
1113 if (ioapic < 0) {
1114 printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
1115 return gsi;
1116 }
1117
Jeremy Fitzhardingec3e137d2009-02-09 12:05:47 -08001118 ioapic_pin = mp_find_ioapic_pin(ioapic, gsi);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001119
1120#ifdef CONFIG_X86_32
1121 if (ioapic_renumber_irq)
1122 gsi = ioapic_renumber_irq(ioapic, gsi);
1123#endif
1124
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001125 if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
1126 printk(KERN_ERR "Invalid reference to IOAPIC pin "
Yinghai Lubdfe8ac2009-05-06 10:07:41 -07001127 "%d-%d\n", mp_ioapics[ioapic].apicid,
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001128 ioapic_pin);
1129 return gsi;
1130 }
Yinghai Luf1bdb522009-05-15 13:05:16 -07001131
1132 if (enable_update_mptable)
1133 mp_config_acpi_gsi(dev, gsi, trigger, polarity);
Yinghai Lub9e03532009-05-06 10:05:32 -07001134
Yinghai Lue5198072009-05-15 13:05:16 -07001135 set_io_apic_irq_attr(&irq_attr, ioapic, ioapic_pin,
1136 trigger == ACPI_EDGE_SENSITIVE ? 0 : 1,
1137 polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
Eric W. Biederman988856e2010-03-30 01:07:15 -07001138 io_apic_set_pci_routing(dev, gsi_to_irq(gsi), &irq_attr);
Yinghai Lub9e03532009-05-06 10:05:32 -07001139
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001140 return gsi;
1141}
1142
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143/*
1144 * Parse IOAPIC related entries in MADT
1145 * returns 0 on success, < 0 on error
1146 */
Len Brown4be44fc2005-08-05 00:44:28 -04001147static int __init acpi_parse_madt_ioapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148{
1149 int count;
1150
1151 /*
1152 * ACPI interpreter is required to complete interrupt setup,
1153 * so if it is off, don't enumerate the io-apics with ACPI.
1154 * If MPS is present, it will handle them,
1155 * otherwise the system will stay in PIC mode
1156 */
Jeremy Fitzhardinge6b2b1712009-06-08 02:53:50 -07001157 if (acpi_disabled || acpi_noirq)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001160 if (!cpu_has_apic)
Andi Kleend3b6a342006-04-07 19:49:39 +02001161 return -ENODEV;
1162
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001164 * if "noapic" boot option, don't look for IO-APICs
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 */
1166 if (skip_ioapic_setup) {
1167 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
Len Brown4be44fc2005-08-05 00:44:28 -04001168 "due to 'noapic' option.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 return -ENODEV;
1170 }
1171
Len Brown4be44fc2005-08-05 00:44:28 -04001172 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001173 acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
Len Brown4be44fc2005-08-05 00:44:28 -04001174 MAX_IO_APICS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 if (!count) {
1176 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
1177 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -04001178 } else if (count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
1180 return count;
1181 }
1182
Len Brown4be44fc2005-08-05 00:44:28 -04001183 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001184 acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr,
Yinghai Lu71f521b2008-08-19 20:50:03 -07001185 nr_irqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 if (count < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -04001187 printk(KERN_ERR PREFIX
1188 "Error parsing interrupt source overrides entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 /* TBD: Cleanup to allow fallback to MPS */
1190 return count;
1191 }
1192
1193 /*
1194 * If BIOS did not supply an INT_SRC_OVR for the SCI
1195 * pretend we got one so we can set the SCI flags.
1196 */
1197 if (!acpi_sci_override_gsi)
Eric W. Biederman9d2062b2010-03-30 01:07:05 -07001198 acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0,
1199 acpi_gbl_FADT.sci_interrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001201 /* Fill in identity legacy mappings where no override */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 mp_config_acpi_legacy_irqs();
1203
Len Brown4be44fc2005-08-05 00:44:28 -04001204 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001205 acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src,
Yinghai Lu71f521b2008-08-19 20:50:03 -07001206 nr_irqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 if (count < 0) {
1208 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
1209 /* TBD: Cleanup to allow fallback to MPS */
1210 return count;
1211 }
1212
1213 return 0;
1214}
1215#else
1216static inline int acpi_parse_madt_ioapic_entries(void)
1217{
1218 return -1;
1219}
Len Brown84663612005-08-24 12:09:07 -04001220#endif /* !CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001222static void __init early_acpi_process_madt(void)
1223{
1224#ifdef CONFIG_X86_LOCAL_APIC
1225 int error;
1226
1227 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1228
1229 /*
1230 * Parse MADT LAPIC entries
1231 */
1232 error = early_acpi_parse_madt_lapic_addr_ovr();
1233 if (!error) {
1234 acpi_lapic = 1;
1235 smp_found_config = 1;
1236 }
1237 if (error == -EINVAL) {
1238 /*
1239 * Dell Precision Workstation 410, 610 come here.
1240 */
1241 printk(KERN_ERR PREFIX
1242 "Invalid BIOS MADT, disabling ACPI\n");
1243 disable_acpi();
1244 }
1245 }
1246#endif
1247}
1248
Len Brown4be44fc2005-08-05 00:44:28 -04001249static void __init acpi_process_madt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250{
1251#ifdef CONFIG_X86_LOCAL_APIC
Len Brown7f8f97c2007-02-10 21:28:03 -05001252 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253
Len Brown7f8f97c2007-02-10 21:28:03 -05001254 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
1256 /*
1257 * Parse MADT LAPIC entries
1258 */
1259 error = acpi_parse_madt_lapic_entries();
1260 if (!error) {
1261 acpi_lapic = 1;
1262
1263 /*
1264 * Parse MADT IO-APIC entries
1265 */
1266 error = acpi_parse_madt_ioapic_entries();
1267 if (!error) {
1268 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 acpi_ioapic = 1;
1270
1271 smp_found_config = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 }
1273 }
1274 if (error == -EINVAL) {
1275 /*
1276 * Dell Precision Workstation 410, 610 come here.
1277 */
Len Brown4be44fc2005-08-05 00:44:28 -04001278 printk(KERN_ERR PREFIX
1279 "Invalid BIOS MADT, disabling ACPI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 disable_acpi();
1281 }
Len Brown7b37b5f2008-12-23 01:47:42 -05001282 } else {
1283 /*
1284 * ACPI found no MADT, and so ACPI wants UP PIC mode.
1285 * In the event an MPS table was found, forget it.
1286 * Boot with "acpi=off" to use MPS on such a system.
1287 */
1288 if (smp_found_config) {
1289 printk(KERN_WARNING PREFIX
1290 "No APIC-table, disabling MPS\n");
1291 smp_found_config = 0;
1292 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 }
Yinghai Lu69b88af2008-12-05 22:45:50 -08001294
1295 /*
1296 * ACPI supports both logical (e.g. Hyper-Threading) and physical
1297 * processors, where MPS only supports physical.
1298 */
1299 if (acpi_lapic && acpi_ioapic)
1300 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
1301 "information\n");
1302 else if (acpi_lapic)
1303 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
1304 "configuration information\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305#endif
1306 return;
1307}
1308
Jeff Garzik18552562007-10-03 15:15:40 -04001309static int __init disable_acpi_irq(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001310{
1311 if (!acpi_force) {
1312 printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
1313 d->ident);
1314 acpi_noirq_set();
1315 }
1316 return 0;
1317}
1318
Jeff Garzik18552562007-10-03 15:15:40 -04001319static int __init disable_acpi_pci(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001320{
1321 if (!acpi_force) {
1322 printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
1323 d->ident);
1324 acpi_disable_pci();
1325 }
1326 return 0;
1327}
Andrey Paninaea00142005-06-25 14:54:42 -07001328
Jeff Garzik18552562007-10-03 15:15:40 -04001329static int __init dmi_disable_acpi(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001330{
1331 if (!acpi_force) {
Len Brown4be44fc2005-08-05 00:44:28 -04001332 printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
Andrey Paninaea00142005-06-25 14:54:42 -07001333 disable_acpi();
1334 } else {
1335 printk(KERN_NOTICE
1336 "Warning: DMI blacklist says broken, but acpi forced\n");
1337 }
1338 return 0;
1339}
1340
1341/*
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001342 * Force ignoring BIOS IRQ0 pin2 override
1343 */
1344static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
1345{
Ingo Molnar8d89adf2008-10-07 06:47:52 +02001346 /*
1347 * The ati_ixp4x0_rev() early PCI quirk should have set
1348 * the acpi_skip_timer_override flag already:
1349 */
1350 if (!acpi_skip_timer_override) {
1351 WARN(1, KERN_ERR "ati_ixp4x0 quirk not complete.\n");
1352 pr_notice("%s detected: Ignoring BIOS IRQ0 pin2 override\n",
1353 d->ident);
1354 acpi_skip_timer_override = 1;
1355 }
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001356 return 0;
1357}
1358
1359/*
Andrey Paninaea00142005-06-25 14:54:42 -07001360 * If your system is blacklisted here, but you find that acpi=force
Zhang Rui5b4c0b62009-04-01 01:49:42 -04001361 * works for you, please contact linux-acpi@vger.kernel.org
Andrey Paninaea00142005-06-25 14:54:42 -07001362 */
1363static struct dmi_system_id __initdata acpi_dmi_table[] = {
1364 /*
1365 * Boxes that need ACPI disabled
1366 */
1367 {
Len Brown4be44fc2005-08-05 00:44:28 -04001368 .callback = dmi_disable_acpi,
1369 .ident = "IBM Thinkpad",
1370 .matches = {
1371 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1372 DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
1373 },
1374 },
Andrey Paninaea00142005-06-25 14:54:42 -07001375
1376 /*
Andrey Paninaea00142005-06-25 14:54:42 -07001377 * Boxes that need ACPI PCI IRQ routing disabled
1378 */
1379 {
Len Brown4be44fc2005-08-05 00:44:28 -04001380 .callback = disable_acpi_irq,
1381 .ident = "ASUS A7V",
1382 .matches = {
1383 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
1384 DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
1385 /* newer BIOS, Revision 1011, does work */
1386 DMI_MATCH(DMI_BIOS_VERSION,
1387 "ASUS A7V ACPI BIOS Revision 1007"),
1388 },
1389 },
Len Brown74586fc2007-03-08 02:48:30 -05001390 {
1391 /*
1392 * Latest BIOS for IBM 600E (1.16) has bad pcinum
1393 * for LPC bridge, which is needed for the PCI
1394 * interrupt links to work. DSDT fix is in bug 5966.
1395 * 2645, 2646 model numbers are shared with 600/600E/600X
1396 */
1397 .callback = disable_acpi_irq,
1398 .ident = "IBM Thinkpad 600 Series 2645",
1399 .matches = {
1400 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1401 DMI_MATCH(DMI_BOARD_NAME, "2645"),
1402 },
1403 },
1404 {
1405 .callback = disable_acpi_irq,
1406 .ident = "IBM Thinkpad 600 Series 2646",
1407 .matches = {
1408 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1409 DMI_MATCH(DMI_BOARD_NAME, "2646"),
1410 },
1411 },
Andrey Paninaea00142005-06-25 14:54:42 -07001412 /*
1413 * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
1414 */
Len Brown4be44fc2005-08-05 00:44:28 -04001415 { /* _BBN 0 bug */
1416 .callback = disable_acpi_pci,
1417 .ident = "ASUS PR-DLS",
1418 .matches = {
1419 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1420 DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
1421 DMI_MATCH(DMI_BIOS_VERSION,
1422 "ASUS PR-DLS ACPI BIOS Revision 1010"),
1423 DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
1424 },
1425 },
Andrey Paninaea00142005-06-25 14:54:42 -07001426 {
Len Brown4be44fc2005-08-05 00:44:28 -04001427 .callback = disable_acpi_pci,
1428 .ident = "Acer TravelMate 36x Laptop",
1429 .matches = {
1430 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
1431 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
1432 },
1433 },
Andreas Herrmann35af2822008-10-22 13:08:31 +02001434 {}
1435};
1436
1437/* second table for DMI checks that should run after early-quirks */
1438static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
Matthew Garrett9340e1c2008-07-01 01:12:06 +01001439 /*
1440 * HP laptops which use a DSDT reporting as HP/SB400/10000,
1441 * which includes some code which overrides all temperature
1442 * trip points to 16C if the INTIN2 input of the I/O APIC
1443 * is enabled. This input is incorrectly designated the
1444 * ISA IRQ 0 via an interrupt source override even though
1445 * it is wired to the output of the master 8259A and INTIN0
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001446 * is not connected at all. Force ignoring BIOS IRQ0 pin2
1447 * override in that cases.
1448 */
1449 {
1450 .callback = dmi_ignore_irq0_timer_override,
Rafael J. Wysockie84956f2008-10-06 11:59:29 +02001451 .ident = "HP nx6115 laptop",
1452 .matches = {
1453 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1454 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6115"),
1455 },
1456 },
1457 {
1458 .callback = dmi_ignore_irq0_timer_override,
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001459 .ident = "HP NX6125 laptop",
1460 .matches = {
1461 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1462 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
1463 },
1464 },
1465 {
1466 .callback = dmi_ignore_irq0_timer_override,
1467 .ident = "HP NX6325 laptop",
1468 .matches = {
1469 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1470 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
1471 },
1472 },
Rafael J. Wysockie84956f2008-10-06 11:59:29 +02001473 {
1474 .callback = dmi_ignore_irq0_timer_override,
1475 .ident = "HP 6715b laptop",
1476 .matches = {
1477 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1478 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
1479 },
1480 },
Len Brown4be44fc2005-08-05 00:44:28 -04001481 {}
Andrey Paninaea00142005-06-25 14:54:42 -07001482};
1483
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484/*
1485 * acpi_boot_table_init() and acpi_boot_init()
1486 * called from setup_arch(), always.
1487 * 1. checksums all tables
1488 * 2. enumerates lapics
1489 * 3. enumerates io-apics
1490 *
1491 * acpi_table_init() is separate to allow reading SRAT without
1492 * other side effects.
1493 *
1494 * side effects of acpi_boot_init:
1495 * acpi_lapic = 1 if LAPIC found
1496 * acpi_ioapic = 1 if IOAPIC found
1497 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
1498 * if acpi_blacklisted() acpi_disabled = 1;
1499 * acpi_irq_model=...
1500 * ...
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 */
1502
Len Brown8558e392010-01-06 16:11:06 -05001503void __init acpi_boot_table_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504{
Andrey Paninaea00142005-06-25 14:54:42 -07001505 dmi_check_system(acpi_dmi_table);
Andrey Paninaea00142005-06-25 14:54:42 -07001506
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 /*
1508 * If acpi_disabled, bail out
1509 * One exception: acpi=ht continues far enough to enumerate LAPICs
1510 */
1511 if (acpi_disabled && !acpi_ht)
Len Brown8558e392010-01-06 16:11:06 -05001512 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001514 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 * Initialize the ACPI boot-time table parser.
1516 */
Len Brown8558e392010-01-06 16:11:06 -05001517 if (acpi_table_init()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 disable_acpi();
Len Brown8558e392010-01-06 16:11:06 -05001519 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001522 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
1524 /*
1525 * blacklist may disable ACPI entirely
1526 */
Len Brown8558e392010-01-06 16:11:06 -05001527 if (acpi_blacklisted()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 if (acpi_force) {
1529 printk(KERN_WARNING PREFIX "acpi=force override\n");
1530 } else {
1531 printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
1532 disable_acpi();
Len Brown8558e392010-01-06 16:11:06 -05001533 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 }
1535 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536}
1537
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001538int __init early_acpi_boot_init(void)
1539{
1540 /*
1541 * If acpi_disabled, bail out
1542 * One exception: acpi=ht continues far enough to enumerate LAPICs
1543 */
1544 if (acpi_disabled && !acpi_ht)
1545 return 1;
1546
1547 /*
1548 * Process the Multiple APIC Description Table (MADT), if present
1549 */
1550 early_acpi_process_madt();
1551
1552 return 0;
1553}
1554
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555int __init acpi_boot_init(void)
1556{
Andreas Herrmann35af2822008-10-22 13:08:31 +02001557 /* those are executed after early-quirks are executed */
1558 dmi_check_system(acpi_dmi_table_late);
1559
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 /*
1561 * If acpi_disabled, bail out
1562 * One exception: acpi=ht continues far enough to enumerate LAPICs
1563 */
1564 if (acpi_disabled && !acpi_ht)
Len Brown4be44fc2005-08-05 00:44:28 -04001565 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001567 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
1569 /*
1570 * set sci_int and PM timer address
1571 */
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +03001572 acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573
1574 /*
1575 * Process the Multiple APIC Description Table (MADT), if present
1576 */
1577 acpi_process_madt();
1578
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001579 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
Thomas Gleixnerb72d0db2009-08-29 16:24:51 +02001581 if (!acpi_noirq)
1582 x86_init.pci.init = pci_acpi_init;
1583
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 return 0;
1585}
Rusty Russell1a3f2392006-09-26 10:52:32 +02001586
1587static int __init parse_acpi(char *arg)
1588{
1589 if (!arg)
1590 return -EINVAL;
1591
1592 /* "acpi=off" disables both ACPI table parsing and interpreter */
1593 if (strcmp(arg, "off") == 0) {
1594 disable_acpi();
1595 }
1596 /* acpi=force to over-ride black-list */
1597 else if (strcmp(arg, "force") == 0) {
1598 acpi_force = 1;
1599 acpi_ht = 1;
1600 acpi_disabled = 0;
1601 }
1602 /* acpi=strict disables out-of-spec workarounds */
1603 else if (strcmp(arg, "strict") == 0) {
1604 acpi_strict = 1;
1605 }
1606 /* Limit ACPI just to boot-time to enable HT */
1607 else if (strcmp(arg, "ht") == 0) {
Len Brown4c81ba42010-03-14 16:28:46 -04001608 if (!acpi_force) {
1609 printk(KERN_WARNING "acpi=ht will be removed in Linux-2.6.35\n");
Rusty Russell1a3f2392006-09-26 10:52:32 +02001610 disable_acpi();
Len Brown4c81ba42010-03-14 16:28:46 -04001611 }
Rusty Russell1a3f2392006-09-26 10:52:32 +02001612 acpi_ht = 1;
1613 }
Zhao Yakui237889b2008-12-17 16:55:18 +08001614 /* acpi=rsdt use RSDT instead of XSDT */
1615 else if (strcmp(arg, "rsdt") == 0) {
1616 acpi_rsdt_forced = 1;
1617 }
Rusty Russell1a3f2392006-09-26 10:52:32 +02001618 /* "acpi=noirq" disables ACPI interrupt routing */
1619 else if (strcmp(arg, "noirq") == 0) {
1620 acpi_noirq_set();
1621 } else {
1622 /* Core will printk when we return error. */
1623 return -EINVAL;
1624 }
1625 return 0;
1626}
1627early_param("acpi", parse_acpi);
1628
1629/* FIXME: Using pci= for an ACPI parameter is a travesty. */
1630static int __init parse_pci(char *arg)
1631{
1632 if (arg && strcmp(arg, "noacpi") == 0)
1633 acpi_disable_pci();
1634 return 0;
1635}
1636early_param("pci", parse_pci);
1637
Yinghai Lu3c999f12008-06-20 16:11:20 -07001638int __init acpi_mps_check(void)
1639{
1640#if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
1641/* mptable code is not built-in*/
1642 if (acpi_disabled || acpi_noirq) {
1643 printk(KERN_WARNING "MPS support code is not built-in.\n"
1644 "Using acpi=off or acpi=noirq or pci=noacpi "
1645 "may have problem\n");
1646 return 1;
1647 }
1648#endif
1649 return 0;
1650}
1651
Rusty Russell1a3f2392006-09-26 10:52:32 +02001652#ifdef CONFIG_X86_IO_APIC
1653static int __init parse_acpi_skip_timer_override(char *arg)
1654{
1655 acpi_skip_timer_override = 1;
1656 return 0;
1657}
1658early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
Andi Kleenfa18f472006-11-14 16:57:46 +01001659
1660static int __init parse_acpi_use_timer_override(char *arg)
1661{
1662 acpi_use_timer_override = 1;
1663 return 0;
1664}
1665early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001666#endif /* CONFIG_X86_IO_APIC */
1667
1668static int __init setup_acpi_sci(char *s)
1669{
1670 if (!s)
1671 return -EINVAL;
1672 if (!strcmp(s, "edge"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001673 acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
1674 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001675 else if (!strcmp(s, "level"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001676 acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
1677 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001678 else if (!strcmp(s, "high"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001679 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
1680 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001681 else if (!strcmp(s, "low"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001682 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
1683 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001684 else
1685 return -EINVAL;
1686 return 0;
1687}
1688early_param("acpi_sci", setup_acpi_sci);
Andrew Mortond0a90812006-10-20 14:30:27 -07001689
1690int __acpi_acquire_global_lock(unsigned int *lock)
1691{
1692 unsigned int old, new, val;
1693 do {
1694 old = *lock;
1695 new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
1696 val = cmpxchg(lock, old, new);
1697 } while (unlikely (val != old));
1698 return (new < 3) ? -1 : 0;
1699}
1700
1701int __acpi_release_global_lock(unsigned int *lock)
1702{
1703 unsigned int old, new, val;
1704 do {
1705 old = *lock;
1706 new = old & ~0x3;
1707 val = cmpxchg(lock, old, new);
1708 } while (unlikely (val != old));
1709 return old & 0x1;
1710}