blob: 0061ea2630615efe9e1f3af3fd8d851821c9f3b0 [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>
Yinghai Lua31f8202009-05-06 10:06:15 -070036#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Thomas Gleixnerb72d0db2009-08-29 16:24:51 +020038#include <asm/pci_x86.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <asm/pgtable.h>
40#include <asm/io_apic.h>
41#include <asm/apic.h>
42#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <asm/mpspec.h>
Alexey Starikovskiydfac2182008-04-04 23:41:50 +040044#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Adrian Bunke8924ac2006-09-26 10:52:35 +020046static int __initdata acpi_force = 0;
Zhao Yakui237889b2008-12-17 16:55:18 +080047u32 acpi_rsdt_forced;
Len Brownc636f752009-05-19 23:47:38 -040048int acpi_disabled;
Andi Kleendf3bb572006-09-26 10:52:33 +020049EXPORT_SYMBOL(acpi_disabled);
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#ifdef CONFIG_X86_64
Ingo Molnar1dcdd3d2009-01-28 17:55:37 +010052# include <asm/proto.h>
Haicheng Li0271f912010-02-04 19:06:33 +080053# include <asm/numa_64.h>
Len Brown4be44fc2005-08-05 00:44:28 -040054#endif /* X86 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#define BAD_MADT_ENTRY(entry, end) ( \
57 (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +030058 ((struct acpi_subtable_header *)entry)->length < sizeof(*entry))
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#define PREFIX "ACPI: "
61
Andrew Morton90d53902006-11-02 22:07:18 -080062int acpi_noirq; /* skip ACPI IRQ initialization */
Yinghai Lu6e4be1f2008-02-05 00:01:48 -080063int acpi_pci_disabled; /* skip ACPI PCI scan and IRQ initialization */
64EXPORT_SYMBOL(acpi_pci_disabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065int acpi_ht __initdata = 1; /* enable HT */
66
67int acpi_lapic;
68int acpi_ioapic;
69int acpi_strict;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +030071u8 acpi_sci_flags __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072int acpi_sci_override_gsi __initdata;
73int acpi_skip_timer_override __initdata;
Andi Kleenfa18f472006-11-14 16:57:46 +010074int acpi_use_timer_override __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76#ifdef CONFIG_X86_LOCAL_APIC
77static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
78#endif
79
80#ifndef __HAVE_ARCH_CMPXCHG
81#warning ACPI uses CMPXCHG, i486 and later hardware
82#endif
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084/* --------------------------------------------------------------------------
85 Boot-time Configuration
86 -------------------------------------------------------------------------- */
87
88/*
89 * The default interrupt routing model is PIC (8259). This gets
Simon Arlott27b46d72007-10-20 01:13:56 +020090 * overridden if IOAPICs are enumerated (below).
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 */
Len Brown4be44fc2005-08-05 00:44:28 -040092enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95/*
96 * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
97 * to map the target physical address. The problem is that set_fixmap()
98 * provides a single page, and it is possible that the page is not
99 * sufficient.
100 * By using this area, we can map up to MAX_IO_APICS pages temporarily,
101 * i.e. until the next __va_range() call.
102 *
103 * Important Safety Note: The fixed I/O APIC page numbers are *subtracted*
104 * from the fixed base. That's why we start at FIX_IO_APIC_BASE_END and
105 * count idx down while incrementing the phys address.
106 */
Jan Beulich2fdf0742007-12-13 08:33:59 +0000107char *__init __acpi_map_table(unsigned long phys, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Yinghai Luf34fa822008-07-09 20:16:36 -0700110 if (!phys || !size)
111 return NULL;
112
Yinghai Lu7d972772009-02-07 15:39:41 -0800113 return early_ioremap(phys, size);
114}
115void __init __acpi_unmap_table(char *map, unsigned long size)
116{
117 if (!map || !size)
118 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Yinghai Lu7d972772009-02-07 15:39:41 -0800120 early_iounmap(map, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#ifdef CONFIG_X86_LOCAL_APIC
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300124static int __init acpi_parse_madt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
Len Brown4be44fc2005-08-05 00:44:28 -0400126 struct acpi_table_madt *madt = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300128 if (!cpu_has_apic)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 return -EINVAL;
130
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300131 madt = (struct acpi_table_madt *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 if (!madt) {
133 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
134 return -ENODEV;
135 }
136
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300137 if (madt->address) {
138 acpi_lapic_addr = (u64) madt->address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140 printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300141 madt->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 }
143
Ingo Molnar306db032009-01-28 03:43:47 +0100144 default_acpi_madt_oem_check(madt->header.oem_id,
145 madt->header.oem_table_id);
Len Brown4be44fc2005-08-05 00:44:28 -0400146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 return 0;
148}
149
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400150static void __cpuinit acpi_register_lapic(int id, u8 enabled)
151{
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700152 unsigned int ver = 0;
153
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400154 if (!enabled) {
155 ++disabled_cpus;
156 return;
157 }
158
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700159 if (boot_cpu_physical_apicid != -1U)
160 ver = apic_version[boot_cpu_physical_apicid];
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700161
162 generic_processor_info(id, ver);
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400163}
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165static int __init
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800166acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
167{
168 struct acpi_madt_local_x2apic *processor = NULL;
169
170 processor = (struct acpi_madt_local_x2apic *)header;
171
172 if (BAD_MADT_ENTRY(processor, end))
173 return -EINVAL;
174
175 acpi_table_print_madt_entry(header);
176
177#ifdef CONFIG_X86_X2APIC
178 /*
179 * We need to register disabled CPU as well to permit
180 * counting disabled CPUs. This allows us to size
181 * cpus_possible_map more accurately, to permit
182 * to not preallocating memory for all NR_CPUS
183 * when we use CPU hotplug.
184 */
185 acpi_register_lapic(processor->local_apic_id, /* APIC ID */
186 processor->lapic_flags & ACPI_MADT_ENABLED);
187#else
188 printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
189#endif
190
191 return 0;
192}
193
194static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300195acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300197 struct acpi_madt_local_apic *processor = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300199 processor = (struct acpi_madt_local_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 if (BAD_MADT_ENTRY(processor, end))
202 return -EINVAL;
203
204 acpi_table_print_madt_entry(header);
205
Ashok Raj7f66ae42006-02-03 21:51:50 +0100206 /*
207 * We need to register disabled CPU as well to permit
208 * counting disabled CPUs. This allows us to size
209 * cpus_possible_map more accurately, to permit
210 * to not preallocating memory for all NR_CPUS
211 * when we use CPU hotplug.
212 */
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400213 acpi_register_lapic(processor->id, /* APIC ID */
214 processor->lapic_flags & ACPI_MADT_ENABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216 return 0;
217}
218
219static int __init
Jack Steinerac049c12008-03-28 14:12:09 -0500220acpi_parse_sapic(struct acpi_subtable_header *header, const unsigned long end)
221{
222 struct acpi_madt_local_sapic *processor = NULL;
223
224 processor = (struct acpi_madt_local_sapic *)header;
225
226 if (BAD_MADT_ENTRY(processor, end))
227 return -EINVAL;
228
229 acpi_table_print_madt_entry(header);
230
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400231 acpi_register_lapic((processor->id << 8) | processor->eid,/* APIC ID */
232 processor->lapic_flags & ACPI_MADT_ENABLED);
Jack Steinerac049c12008-03-28 14:12:09 -0500233
234 return 0;
235}
236
237static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300238acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400239 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300241 struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300243 lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245 if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
246 return -EINVAL;
247
248 acpi_lapic_addr = lapic_addr_ovr->address;
249
250 return 0;
251}
252
253static int __init
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800254acpi_parse_x2apic_nmi(struct acpi_subtable_header *header,
255 const unsigned long end)
256{
257 struct acpi_madt_local_x2apic_nmi *x2apic_nmi = NULL;
258
259 x2apic_nmi = (struct acpi_madt_local_x2apic_nmi *)header;
260
261 if (BAD_MADT_ENTRY(x2apic_nmi, end))
262 return -EINVAL;
263
264 acpi_table_print_madt_entry(header);
265
266 if (x2apic_nmi->lint != 1)
267 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
268
269 return 0;
270}
271
272static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300273acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300275 struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300277 lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
279 if (BAD_MADT_ENTRY(lapic_nmi, end))
280 return -EINVAL;
281
282 acpi_table_print_madt_entry(header);
283
284 if (lapic_nmi->lint != 1)
285 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
286
287 return 0;
288}
289
Len Brown4be44fc2005-08-05 00:44:28 -0400290#endif /*CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Len Brown84663612005-08-24 12:09:07 -0400292#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300295acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300297 struct acpi_madt_io_apic *ioapic = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300299 ioapic = (struct acpi_madt_io_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301 if (BAD_MADT_ENTRY(ioapic, end))
302 return -EINVAL;
Len Brown4be44fc2005-08-05 00:44:28 -0400303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 acpi_table_print_madt_entry(header);
305
Len Brown4be44fc2005-08-05 00:44:28 -0400306 mp_register_ioapic(ioapic->id,
307 ioapic->address, ioapic->global_irq_base);
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 return 0;
310}
311
312/*
313 * Parse Interrupt Source Override for the ACPI SCI
314 */
Len Browne82c3542006-12-21 01:29:59 -0500315static void __init acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316{
317 if (trigger == 0) /* compatible SCI trigger is level */
318 trigger = 3;
319
320 if (polarity == 0) /* compatible SCI polarity is low */
321 polarity = 3;
322
323 /* Command-line over-ride via acpi_sci= */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300324 if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
325 trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300327 if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
328 polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330 /*
Len Brown4be44fc2005-08-05 00:44:28 -0400331 * mp_config_acpi_legacy_irqs() already setup IRQs < 16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 * If GSI is < 16, this will update its flags,
333 * else it will create a new mp_irqs[] entry.
334 */
Len Brown7bdd21c2006-12-02 02:27:46 -0500335 mp_override_legacy_irq(gsi, polarity, trigger, gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
337 /*
338 * stash over-ride to indicate we've been here
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300339 * and for later update of acpi_gbl_FADT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 */
Len Brown7bdd21c2006-12-02 02:27:46 -0500341 acpi_sci_override_gsi = gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 return;
343}
344
345static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300346acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400347 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300349 struct acpi_madt_interrupt_override *intsrc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300351 intsrc = (struct acpi_madt_interrupt_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353 if (BAD_MADT_ENTRY(intsrc, end))
354 return -EINVAL;
355
356 acpi_table_print_madt_entry(header);
357
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300358 if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
Len Brown7bdd21c2006-12-02 02:27:46 -0500359 acpi_sci_ioapic_setup(intsrc->global_irq,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300360 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
361 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 return 0;
363 }
364
365 if (acpi_skip_timer_override &&
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300366 intsrc->source_irq == 0 && intsrc->global_irq == 2) {
Len Brown4be44fc2005-08-05 00:44:28 -0400367 printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
368 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 }
370
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300371 mp_override_legacy_irq(intsrc->source_irq,
372 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
373 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
374 intsrc->global_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376 return 0;
377}
378
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300380acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300382 struct acpi_madt_nmi_source *nmi_src = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300384 nmi_src = (struct acpi_madt_nmi_source *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
386 if (BAD_MADT_ENTRY(nmi_src, end))
387 return -EINVAL;
388
389 acpi_table_print_madt_entry(header);
390
391 /* TBD: Support nimsrc entries? */
392
393 return 0;
394}
395
Len Brown4be44fc2005-08-05 00:44:28 -0400396#endif /* CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398/*
399 * acpi_pic_sci_set_trigger()
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300400 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 * use ELCR to set PIC-mode trigger type for SCI
402 *
403 * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
404 * it may require Edge Trigger -- use "acpi_sci=edge"
405 *
406 * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
407 * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
Simon Arlott27b46d72007-10-20 01:13:56 +0200408 * ECLR1 is IRQs 0-7 (IRQ 0, 1, 2 must be 0)
409 * ECLR2 is IRQs 8-15 (IRQ 8, 13 must be 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 */
411
Len Brown4be44fc2005-08-05 00:44:28 -0400412void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413{
414 unsigned int mask = 1 << irq;
415 unsigned int old, new;
416
417 /* Real old ELCR mask */
418 old = inb(0x4d0) | (inb(0x4d1) << 8);
419
420 /*
Simon Arlott27b46d72007-10-20 01:13:56 +0200421 * If we use ACPI to set PCI IRQs, then we should clear ELCR
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 * since we will set it correctly as we enable the PCI irq
423 * routing.
424 */
425 new = acpi_noirq ? old : 0;
426
427 /*
428 * Update SCI information in the ELCR, it isn't in the PCI
429 * routing tables..
430 */
431 switch (trigger) {
Len Brown4be44fc2005-08-05 00:44:28 -0400432 case 1: /* Edge - clear */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 new &= ~mask;
434 break;
Len Brown4be44fc2005-08-05 00:44:28 -0400435 case 3: /* Level - set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 new |= mask;
437 break;
438 }
439
440 if (old == new)
441 return;
442
443 printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
444 outb(new, 0x4d0);
445 outb(new >> 8, 0x4d1);
446}
447
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
449{
Eric W. Biedermanf023d762006-10-04 02:16:52 -0700450 *irq = gsi;
Yinghai Lu18dce6b2010-02-10 01:20:05 -0800451
452#ifdef CONFIG_X86_IO_APIC
453 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
454 setup_IO_APIC_irq_extra(gsi);
455#endif
456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 return 0;
458}
459
Kenji Kaneshige1f3a6a12005-07-28 14:42:00 -0400460/*
461 * success: return IRQ number (>=0)
462 * failure: return < 0
463 */
Yinghai Lue5198072009-05-15 13:05:16 -0700464int acpi_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465{
466 unsigned int irq;
467 unsigned int plat_gsi = gsi;
468
469#ifdef CONFIG_PCI
470 /*
471 * Make sure all (legacy) PCI IRQs are set as level-triggered.
472 */
473 if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
Yinghai Lue5198072009-05-15 13:05:16 -0700474 if (trigger == ACPI_LEVEL_SENSITIVE)
Len Brown4be44fc2005-08-05 00:44:28 -0400475 eisa_set_level_irq(gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 }
477#endif
478
479#ifdef CONFIG_X86_IO_APIC
480 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) {
Yinghai Lue5198072009-05-15 13:05:16 -0700481 plat_gsi = mp_register_gsi(dev, gsi, trigger, polarity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 }
483#endif
Yinghai Lu18dce6b2010-02-10 01:20:05 -0800484 irq = plat_gsi;
485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 return irq;
487}
Len Brown4be44fc2005-08-05 00:44:28 -0400488
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489/*
490 * ACPI based hotplug support for CPU
491 */
492#ifdef CONFIG_ACPI_HOTPLUG_CPU
Alex Chiangd8191fa2010-02-22 12:11:39 -0700493#include <acpi/processor.h>
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100494
Haicheng Li0271f912010-02-04 19:06:33 +0800495static void acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
496{
497#ifdef CONFIG_ACPI_NUMA
498 int nid;
499
500 nid = acpi_get_node(handle);
501 if (nid == -1 || !node_online(nid))
502 return;
503#ifdef CONFIG_X86_64
504 apicid_to_node[physid] = nid;
505 numa_set_node(cpu, nid);
506#else /* CONFIG_X86_32 */
507 apicid_2_node[physid] = nid;
508 cpu_to_node_map[cpu] = nid;
509#endif
510
511#endif
512}
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100513
514static int __cpuinit _acpi_map_lsapic(acpi_handle handle, int *pcpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515{
Ashok Raj73fea172006-09-26 10:52:35 +0200516 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
517 union acpi_object *obj;
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300518 struct acpi_madt_local_apic *lapic;
Rusty Russellee943a82008-12-31 18:08:47 -0800519 cpumask_var_t tmp_map, new_map;
Ashok Raj73fea172006-09-26 10:52:35 +0200520 u8 physid;
521 int cpu;
Rusty Russellee943a82008-12-31 18:08:47 -0800522 int retval = -ENOMEM;
Ashok Raj73fea172006-09-26 10:52:35 +0200523
524 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
525 return -EINVAL;
526
527 if (!buffer.length || !buffer.pointer)
528 return -EINVAL;
529
530 obj = buffer.pointer;
531 if (obj->type != ACPI_TYPE_BUFFER ||
532 obj->buffer.length < sizeof(*lapic)) {
533 kfree(buffer.pointer);
534 return -EINVAL;
535 }
536
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300537 lapic = (struct acpi_madt_local_apic *)obj->buffer.pointer;
Ashok Raj73fea172006-09-26 10:52:35 +0200538
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300539 if (lapic->header.type != ACPI_MADT_TYPE_LOCAL_APIC ||
540 !(lapic->lapic_flags & ACPI_MADT_ENABLED)) {
Ashok Raj73fea172006-09-26 10:52:35 +0200541 kfree(buffer.pointer);
542 return -EINVAL;
543 }
544
545 physid = lapic->id;
546
547 kfree(buffer.pointer);
548 buffer.length = ACPI_ALLOCATE_BUFFER;
549 buffer.pointer = NULL;
550
Rusty Russellee943a82008-12-31 18:08:47 -0800551 if (!alloc_cpumask_var(&tmp_map, GFP_KERNEL))
552 goto out;
553
554 if (!alloc_cpumask_var(&new_map, GFP_KERNEL))
555 goto free_tmp_map;
556
557 cpumask_copy(tmp_map, cpu_present_mask);
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400558 acpi_register_lapic(physid, lapic->lapic_flags & ACPI_MADT_ENABLED);
Ashok Raj73fea172006-09-26 10:52:35 +0200559
560 /*
561 * If mp_register_lapic successfully generates a new logical cpu
562 * number, then the following will get us exactly what was mapped
563 */
Rusty Russellee943a82008-12-31 18:08:47 -0800564 cpumask_andnot(new_map, cpu_present_mask, tmp_map);
565 if (cpumask_empty(new_map)) {
Ashok Raj73fea172006-09-26 10:52:35 +0200566 printk ("Unable to map lapic to logical cpu number\n");
Rusty Russellee943a82008-12-31 18:08:47 -0800567 retval = -EINVAL;
568 goto free_new_map;
Ashok Raj73fea172006-09-26 10:52:35 +0200569 }
570
Alex Chiangd8191fa2010-02-22 12:11:39 -0700571 acpi_processor_set_pdc(handle);
572
Rusty Russellee943a82008-12-31 18:08:47 -0800573 cpu = cpumask_first(new_map);
Haicheng Li0271f912010-02-04 19:06:33 +0800574 acpi_map_cpu2node(handle, cpu, physid);
Ashok Raj73fea172006-09-26 10:52:35 +0200575
576 *pcpu = cpu;
Rusty Russellee943a82008-12-31 18:08:47 -0800577 retval = 0;
578
579free_new_map:
580 free_cpumask_var(new_map);
581free_tmp_map:
582 free_cpumask_var(tmp_map);
583out:
584 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585}
Len Brown4be44fc2005-08-05 00:44:28 -0400586
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100587/* wrapper to silence section mismatch warning */
588int __ref acpi_map_lsapic(acpi_handle handle, int *pcpu)
589{
590 return _acpi_map_lsapic(handle, pcpu);
591}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592EXPORT_SYMBOL(acpi_map_lsapic);
593
Len Brown4be44fc2005-08-05 00:44:28 -0400594int acpi_unmap_lsapic(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595{
Mike Travis71fff5e2007-10-19 20:35:03 +0200596 per_cpu(x86_cpu_to_apicid, cpu) = -1;
Mike Travis96289372008-12-31 18:08:46 -0800597 set_cpu_present(cpu, false);
Ashok Raj73fea172006-09-26 10:52:35 +0200598 num_processors--;
599
600 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601}
Len Brown4be44fc2005-08-05 00:44:28 -0400602
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603EXPORT_SYMBOL(acpi_unmap_lsapic);
Len Brown4be44fc2005-08-05 00:44:28 -0400604#endif /* CONFIG_ACPI_HOTPLUG_CPU */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
Len Brown4be44fc2005-08-05 00:44:28 -0400606int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700607{
608 /* TBD */
609 return -EINVAL;
610}
Len Brown4be44fc2005-08-05 00:44:28 -0400611
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700612EXPORT_SYMBOL(acpi_register_ioapic);
613
Len Brown4be44fc2005-08-05 00:44:28 -0400614int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700615{
616 /* TBD */
617 return -EINVAL;
618}
Len Brown4be44fc2005-08-05 00:44:28 -0400619
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700620EXPORT_SYMBOL(acpi_unregister_ioapic);
621
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300622static int __init acpi_parse_sbf(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300624 struct acpi_table_boot *sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300626 sb = (struct acpi_table_boot *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 if (!sb) {
628 printk(KERN_WARNING PREFIX "Unable to map SBF\n");
629 return -ENODEV;
630 }
631
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300632 sbf_port = sb->cmos_index; /* Save CMOS port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
634 return 0;
635}
636
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637#ifdef CONFIG_HPET_TIMER
john stultz2d0c87c2007-02-16 01:28:18 -0800638#include <asm/hpet.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
Aaron Durbina1dfd852007-07-21 17:11:39 +0200640static struct __initdata resource *hpet_res;
641
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300642static int __init acpi_parse_hpet(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643{
644 struct acpi_table_hpet *hpet_tbl;
645
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300646 hpet_tbl = (struct acpi_table_hpet *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 if (!hpet_tbl) {
648 printk(KERN_WARNING PREFIX "Unable to map HPET\n");
649 return -ENODEV;
650 }
651
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300652 if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 printk(KERN_WARNING PREFIX "HPET timers must be located in "
654 "memory.\n");
655 return -1;
656 }
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200657
john stultz2d0c87c2007-02-16 01:28:18 -0800658 hpet_address = hpet_tbl->address.address;
Suresh Siddhac8bc6f32009-08-04 12:07:09 -0700659 hpet_blockid = hpet_tbl->sequence;
Thomas Gleixnerf4df73c2007-11-15 21:41:50 -0500660
661 /*
662 * Some broken BIOSes advertise HPET at 0x0. We really do not
663 * want to allocate a resource there.
664 */
665 if (!hpet_address) {
666 printk(KERN_WARNING PREFIX
667 "HPET id: %#x base: %#lx is invalid\n",
668 hpet_tbl->id, hpet_address);
669 return 0;
670 }
671#ifdef CONFIG_X86_64
672 /*
673 * Some even more broken BIOSes advertise HPET at
674 * 0xfed0000000000000 instead of 0xfed00000. Fix it up and add
675 * some noise:
676 */
677 if (hpet_address == 0xfed0000000000000UL) {
678 if (!hpet_force_user) {
679 printk(KERN_WARNING PREFIX "HPET id: %#x "
680 "base: 0xfed0000000000000 is bogus\n "
681 "try hpet=force on the kernel command line to "
682 "fix it up to 0xfed00000.\n", hpet_tbl->id);
683 hpet_address = 0;
684 return 0;
685 }
686 printk(KERN_WARNING PREFIX
687 "HPET id: %#x base: 0xfed0000000000000 fixed up "
688 "to 0xfed00000.\n", hpet_tbl->id);
689 hpet_address >>= 32;
690 }
691#endif
Len Brown4be44fc2005-08-05 00:44:28 -0400692 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
john stultz2d0c87c2007-02-16 01:28:18 -0800693 hpet_tbl->id, hpet_address);
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200694
Aaron Durbina1dfd852007-07-21 17:11:39 +0200695 /*
696 * Allocate and initialize the HPET firmware resource for adding into
697 * the resource tree during the lateinit timeframe.
698 */
699#define HPET_RESOURCE_NAME_SIZE 9
700 hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
701
Aaron Durbina1dfd852007-07-21 17:11:39 +0200702 hpet_res->name = (void *)&hpet_res[1];
703 hpet_res->flags = IORESOURCE_MEM;
704 snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE, "HPET %u",
705 hpet_tbl->sequence);
706
707 hpet_res->start = hpet_address;
708 hpet_res->end = hpet_address + (1 * 1024) - 1;
709
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 return 0;
711}
Aaron Durbina1dfd852007-07-21 17:11:39 +0200712
713/*
714 * hpet_insert_resource inserts the HPET resources used into the resource
715 * tree.
716 */
717static __init int hpet_insert_resource(void)
718{
719 if (!hpet_res)
720 return 1;
721
722 return insert_resource(&iomem_resource, hpet_res);
723}
724
725late_initcall(hpet_insert_resource);
726
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727#else
728#define acpi_parse_hpet NULL
729#endif
730
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300731static int __init acpi_parse_fadt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732{
Jason Davis90660ec2005-04-16 15:24:53 -0700733
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734#ifdef CONFIG_X86_PM_TIMER
735 /* detect the location of the ACPI PM Timer */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300736 if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 /* FADT rev. 2 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300738 if (acpi_gbl_FADT.xpm_timer_block.space_id !=
Len Brown4be44fc2005-08-05 00:44:28 -0400739 ACPI_ADR_SPACE_SYSTEM_IO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 return 0;
741
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300742 pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
David Shaohua Lie6e87b42005-09-21 01:35:00 -0400743 /*
744 * "X" fields are optional extensions to the original V1.0
745 * fields, so we must selectively expand V1.0 fields if the
746 * corresponding X field is zero.
747 */
748 if (!pmtmr_ioport)
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300749 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 } else {
751 /* FADT rev. 1 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300752 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 }
754 if (pmtmr_ioport)
Len Brown4be44fc2005-08-05 00:44:28 -0400755 printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
756 pmtmr_ioport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757#endif
758 return 0;
759}
760
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761#ifdef CONFIG_X86_LOCAL_APIC
762/*
763 * Parse LAPIC entries in MADT
764 * returns 0 on success, < 0 on error
765 */
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400766
767static void __init acpi_register_lapic_address(unsigned long address)
768{
769 mp_lapic_addr = address;
770
771 set_fixmap_nocache(FIX_APIC_BASE, address);
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700772 if (boot_cpu_physical_apicid == -1U) {
Yinghai Lu4c9961d2008-07-11 18:44:16 -0700773 boot_cpu_physical_apicid = read_apic_id();
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700774 apic_version[boot_cpu_physical_apicid] =
775 GET_APIC_VERSION(apic_read(APIC_LVR));
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700776 }
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400777}
778
Yinghai Lucbf9bd62008-02-19 03:21:06 -0800779static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
780{
781 int count;
782
783 if (!cpu_has_apic)
784 return -ENODEV;
785
786 /*
787 * Note that the LAPIC address is obtained from the MADT (32-bit value)
788 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
789 */
790
791 count =
792 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
793 acpi_parse_lapic_addr_ovr, 0);
794 if (count < 0) {
795 printk(KERN_ERR PREFIX
796 "Error parsing LAPIC address override entry\n");
797 return count;
798 }
799
800 acpi_register_lapic_address(acpi_lapic_addr);
801
802 return count;
803}
804
Len Brown4be44fc2005-08-05 00:44:28 -0400805static int __init acpi_parse_madt_lapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806{
807 int count;
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800808 int x2count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Andi Kleen0fcd2702006-04-11 12:54:36 +0200810 if (!cpu_has_apic)
811 return -ENODEV;
812
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300813 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 * Note that the LAPIC address is obtained from the MADT (32-bit value)
815 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
816 */
817
Len Brown4be44fc2005-08-05 00:44:28 -0400818 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300819 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
Len Brown4be44fc2005-08-05 00:44:28 -0400820 acpi_parse_lapic_addr_ovr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 if (count < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400822 printk(KERN_ERR PREFIX
823 "Error parsing LAPIC address override entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 return count;
825 }
826
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400827 acpi_register_lapic_address(acpi_lapic_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Jack Steinerac049c12008-03-28 14:12:09 -0500829 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
830 acpi_parse_sapic, MAX_APICS);
831
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800832 if (!count) {
833 x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
834 acpi_parse_x2apic, MAX_APICS);
Jack Steinerac049c12008-03-28 14:12:09 -0500835 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
836 acpi_parse_lapic, MAX_APICS);
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800837 }
838 if (!count && !x2count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
840 /* TBD: Cleanup to allow fallback to MPS */
841 return -ENODEV;
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800842 } else if (count < 0 || x2count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
844 /* TBD: Cleanup to allow fallback to MPS */
845 return count;
846 }
847
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800848 x2count =
849 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI,
850 acpi_parse_x2apic_nmi, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400851 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300852 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0);
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800853 if (count < 0 || x2count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
855 /* TBD: Cleanup to allow fallback to MPS */
856 return count;
857 }
858 return 0;
859}
Len Brown4be44fc2005-08-05 00:44:28 -0400860#endif /* CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
Len Brown84663612005-08-24 12:09:07 -0400862#ifdef CONFIG_X86_IO_APIC
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400863#define MP_ISA_BUS 0
864
Yinghai Lud49c4282008-06-08 18:31:54 -0700865#ifdef CONFIG_X86_ES7000
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400866extern int es7000_plat;
867#endif
868
Yinghai Lu3f4a7392009-02-08 16:18:03 -0800869int __init acpi_probe_gsi(void)
870{
871 int idx;
872 int gsi;
873 int max_gsi = 0;
874
875 if (acpi_disabled)
876 return 0;
877
878 if (!acpi_ioapic)
879 return 0;
880
881 max_gsi = 0;
882 for (idx = 0; idx < nr_ioapics; idx++) {
Feng Tang2a4ab642009-07-07 23:01:15 -0400883 gsi = mp_gsi_routing[idx].gsi_end;
Yinghai Lu3f4a7392009-02-08 16:18:03 -0800884
885 if (gsi > max_gsi)
886 max_gsi = gsi;
887 }
888
889 return max_gsi + 1;
890}
891
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530892static void assign_to_mp_irq(struct mpc_intsrc *m,
893 struct mpc_intsrc *mp_irq)
Yinghai Lufcfa1462008-06-18 17:29:31 -0700894{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530895 memcpy(mp_irq, m, sizeof(struct mpc_intsrc));
Yinghai Lufcfa1462008-06-18 17:29:31 -0700896}
897
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530898static int mp_irq_cmp(struct mpc_intsrc *mp_irq,
899 struct mpc_intsrc *m)
Yinghai Lufcfa1462008-06-18 17:29:31 -0700900{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530901 return memcmp(mp_irq, m, sizeof(struct mpc_intsrc));
Yinghai Lufcfa1462008-06-18 17:29:31 -0700902}
903
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530904static void save_mp_irq(struct mpc_intsrc *m)
Yinghai Lufcfa1462008-06-18 17:29:31 -0700905{
906 int i;
907
908 for (i = 0; i < mp_irq_entries; i++) {
909 if (!mp_irq_cmp(&mp_irqs[i], m))
910 return;
911 }
912
913 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
914 if (++mp_irq_entries == MAX_IRQ_SOURCES)
915 panic("Max # of irq sources exceeded!!\n");
916}
917
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400918void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
919{
Yinghai Lu6df88092008-06-15 18:19:46 -0700920 int ioapic;
921 int pin;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530922 struct mpc_intsrc mp_irq;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400923
924 /*
925 * Convert 'gsi' to 'ioapic.pin'.
926 */
927 ioapic = mp_find_ioapic(gsi);
928 if (ioapic < 0)
929 return;
Jeremy Fitzhardingec3e137d2009-02-09 12:05:47 -0800930 pin = mp_find_ioapic_pin(ioapic, gsi);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400931
932 /*
933 * TBD: This check is for faulty timer entries, where the override
934 * erroneously sets the trigger to level, resulting in a HUGE
935 * increase of timer interrupts!
936 */
937 if ((bus_irq == 0) && (trigger == 3))
938 trigger = 1;
939
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530940 mp_irq.type = MP_INTSRC;
941 mp_irq.irqtype = mp_INT;
942 mp_irq.irqflag = (trigger << 2) | polarity;
943 mp_irq.srcbus = MP_ISA_BUS;
944 mp_irq.srcbusirq = bus_irq; /* IRQ */
945 mp_irq.dstapic = mp_ioapics[ioapic].apicid; /* APIC ID */
946 mp_irq.dstirq = pin; /* INTIN# */
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400947
Yinghai Lufcfa1462008-06-18 17:29:31 -0700948 save_mp_irq(&mp_irq);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400949}
950
951void __init mp_config_acpi_legacy_irqs(void)
952{
Yinghai Lu6df88092008-06-15 18:19:46 -0700953 int i;
954 int ioapic;
955 unsigned int dstapic;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530956 struct mpc_intsrc mp_irq;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400957
958#if defined (CONFIG_MCA) || defined (CONFIG_EISA)
959 /*
960 * Fabricate the legacy ISA bus (bus #31).
961 */
962 mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
963#endif
964 set_bit(MP_ISA_BUS, mp_bus_not_pci);
Thomas Gleixnercfc1b9a2008-07-21 21:35:38 +0200965 pr_debug("Bus #%d is ISA\n", MP_ISA_BUS);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400966
Yinghai Lud49c4282008-06-08 18:31:54 -0700967#ifdef CONFIG_X86_ES7000
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400968 /*
969 * Older generations of ES7000 have no legacy identity mappings
970 */
971 if (es7000_plat == 1)
972 return;
973#endif
974
975 /*
976 * Locate the IOAPIC that manages the ISA IRQs (0-15).
977 */
978 ioapic = mp_find_ioapic(0);
979 if (ioapic < 0)
980 return;
Jaswinder Singh Rajputb5ba7e62009-01-12 17:46:17 +0530981 dstapic = mp_ioapics[ioapic].apicid;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400982
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400983 /*
984 * Use the default configuration for the IRQs 0-15. Unless
985 * overridden by (MADT) interrupt source override entries.
986 */
987 for (i = 0; i < 16; i++) {
988 int idx;
989
990 for (idx = 0; idx < mp_irq_entries; idx++) {
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530991 struct mpc_intsrc *irq = mp_irqs + idx;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400992
993 /* Do we already have a mapping for this ISA IRQ? */
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530994 if (irq->srcbus == MP_ISA_BUS && irq->srcbusirq == i)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400995 break;
996
997 /* Do we already have a mapping for this IOAPIC pin */
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530998 if (irq->dstapic == dstapic && irq->dstirq == i)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400999 break;
1000 }
1001
1002 if (idx != mp_irq_entries) {
1003 printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
1004 continue; /* IRQ already used */
1005 }
1006
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301007 mp_irq.type = MP_INTSRC;
1008 mp_irq.irqflag = 0; /* Conforming */
1009 mp_irq.srcbus = MP_ISA_BUS;
1010 mp_irq.dstapic = dstapic;
1011 mp_irq.irqtype = mp_INT;
1012 mp_irq.srcbusirq = i; /* Identity mapped */
1013 mp_irq.dstirq = i;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001014
Yinghai Lufcfa1462008-06-18 17:29:31 -07001015 save_mp_irq(&mp_irq);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001016 }
1017}
1018
Yinghai Lue5198072009-05-15 13:05:16 -07001019static int mp_config_acpi_gsi(struct device *dev, u32 gsi, int trigger,
Yinghai Lua31f8202009-05-06 10:06:15 -07001020 int polarity)
1021{
1022#ifdef CONFIG_X86_MPPARSE
1023 struct mpc_intsrc mp_irq;
1024 struct pci_dev *pdev;
1025 unsigned char number;
1026 unsigned int devfn;
1027 int ioapic;
1028 u8 pin;
1029
1030 if (!acpi_ioapic)
1031 return 0;
1032 if (!dev)
1033 return 0;
1034 if (dev->bus != &pci_bus_type)
1035 return 0;
1036
1037 pdev = to_pci_dev(dev);
1038 number = pdev->bus->number;
1039 devfn = pdev->devfn;
1040 pin = pdev->pin;
1041 /* print the entry should happen on mptable identically */
1042 mp_irq.type = MP_INTSRC;
1043 mp_irq.irqtype = mp_INT;
Yinghai Lue5198072009-05-15 13:05:16 -07001044 mp_irq.irqflag = (trigger == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
Yinghai Lua31f8202009-05-06 10:06:15 -07001045 (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
1046 mp_irq.srcbus = number;
1047 mp_irq.srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
1048 ioapic = mp_find_ioapic(gsi);
Yinghai Lubdfe8ac2009-05-06 10:07:41 -07001049 mp_irq.dstapic = mp_ioapics[ioapic].apicid;
Yinghai Lua31f8202009-05-06 10:06:15 -07001050 mp_irq.dstirq = mp_find_ioapic_pin(ioapic, gsi);
1051
1052 save_mp_irq(&mp_irq);
1053#endif
1054 return 0;
1055}
1056
Yinghai Lue5198072009-05-15 13:05:16 -07001057int mp_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001058{
1059 int ioapic;
1060 int ioapic_pin;
Yinghai Lue5198072009-05-15 13:05:16 -07001061 struct io_apic_irq_attr irq_attr;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001062
1063 if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
1064 return gsi;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001065
1066 /* Don't set up the ACPI SCI because it's already set up */
1067 if (acpi_gbl_FADT.sci_interrupt == gsi)
1068 return gsi;
1069
1070 ioapic = mp_find_ioapic(gsi);
1071 if (ioapic < 0) {
1072 printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
1073 return gsi;
1074 }
1075
Jeremy Fitzhardingec3e137d2009-02-09 12:05:47 -08001076 ioapic_pin = mp_find_ioapic_pin(ioapic, gsi);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001077
1078#ifdef CONFIG_X86_32
1079 if (ioapic_renumber_irq)
1080 gsi = ioapic_renumber_irq(ioapic, gsi);
1081#endif
1082
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001083 if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
1084 printk(KERN_ERR "Invalid reference to IOAPIC pin "
Yinghai Lubdfe8ac2009-05-06 10:07:41 -07001085 "%d-%d\n", mp_ioapics[ioapic].apicid,
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001086 ioapic_pin);
1087 return gsi;
1088 }
Yinghai Luf1bdb522009-05-15 13:05:16 -07001089
1090 if (enable_update_mptable)
1091 mp_config_acpi_gsi(dev, gsi, trigger, polarity);
Yinghai Lub9e03532009-05-06 10:05:32 -07001092
Yinghai Lue5198072009-05-15 13:05:16 -07001093 set_io_apic_irq_attr(&irq_attr, ioapic, ioapic_pin,
1094 trigger == ACPI_EDGE_SENSITIVE ? 0 : 1,
1095 polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
1096 io_apic_set_pci_routing(dev, gsi, &irq_attr);
Yinghai Lub9e03532009-05-06 10:05:32 -07001097
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001098 return gsi;
1099}
1100
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101/*
1102 * Parse IOAPIC related entries in MADT
1103 * returns 0 on success, < 0 on error
1104 */
Len Brown4be44fc2005-08-05 00:44:28 -04001105static int __init acpi_parse_madt_ioapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106{
1107 int count;
1108
1109 /*
1110 * ACPI interpreter is required to complete interrupt setup,
1111 * so if it is off, don't enumerate the io-apics with ACPI.
1112 * If MPS is present, it will handle them,
1113 * otherwise the system will stay in PIC mode
1114 */
Jeremy Fitzhardinge6b2b1712009-06-08 02:53:50 -07001115 if (acpi_disabled || acpi_noirq)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001118 if (!cpu_has_apic)
Andi Kleend3b6a342006-04-07 19:49:39 +02001119 return -ENODEV;
1120
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001122 * if "noapic" boot option, don't look for IO-APICs
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 */
1124 if (skip_ioapic_setup) {
1125 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
Len Brown4be44fc2005-08-05 00:44:28 -04001126 "due to 'noapic' option.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 return -ENODEV;
1128 }
1129
Len Brown4be44fc2005-08-05 00:44:28 -04001130 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001131 acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
Len Brown4be44fc2005-08-05 00:44:28 -04001132 MAX_IO_APICS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 if (!count) {
1134 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
1135 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -04001136 } else if (count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
1138 return count;
1139 }
1140
Len Brown4be44fc2005-08-05 00:44:28 -04001141 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001142 acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr,
Yinghai Lu71f521b2008-08-19 20:50:03 -07001143 nr_irqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 if (count < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -04001145 printk(KERN_ERR PREFIX
1146 "Error parsing interrupt source overrides entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 /* TBD: Cleanup to allow fallback to MPS */
1148 return count;
1149 }
1150
1151 /*
1152 * If BIOS did not supply an INT_SRC_OVR for the SCI
1153 * pretend we got one so we can set the SCI flags.
1154 */
1155 if (!acpi_sci_override_gsi)
Alexey Starikovskiycee324b2007-02-02 19:48:22 +03001156 acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001158 /* Fill in identity legacy mappings where no override */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 mp_config_acpi_legacy_irqs();
1160
Len Brown4be44fc2005-08-05 00:44:28 -04001161 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001162 acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src,
Yinghai Lu71f521b2008-08-19 20:50:03 -07001163 nr_irqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 if (count < 0) {
1165 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
1166 /* TBD: Cleanup to allow fallback to MPS */
1167 return count;
1168 }
1169
1170 return 0;
1171}
1172#else
1173static inline int acpi_parse_madt_ioapic_entries(void)
1174{
1175 return -1;
1176}
Len Brown84663612005-08-24 12:09:07 -04001177#endif /* !CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001179static void __init early_acpi_process_madt(void)
1180{
1181#ifdef CONFIG_X86_LOCAL_APIC
1182 int error;
1183
1184 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1185
1186 /*
1187 * Parse MADT LAPIC entries
1188 */
1189 error = early_acpi_parse_madt_lapic_addr_ovr();
1190 if (!error) {
1191 acpi_lapic = 1;
1192 smp_found_config = 1;
1193 }
1194 if (error == -EINVAL) {
1195 /*
1196 * Dell Precision Workstation 410, 610 come here.
1197 */
1198 printk(KERN_ERR PREFIX
1199 "Invalid BIOS MADT, disabling ACPI\n");
1200 disable_acpi();
1201 }
1202 }
1203#endif
1204}
1205
Len Brown4be44fc2005-08-05 00:44:28 -04001206static void __init acpi_process_madt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207{
1208#ifdef CONFIG_X86_LOCAL_APIC
Len Brown7f8f97c2007-02-10 21:28:03 -05001209 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
Len Brown7f8f97c2007-02-10 21:28:03 -05001211 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
1213 /*
1214 * Parse MADT LAPIC entries
1215 */
1216 error = acpi_parse_madt_lapic_entries();
1217 if (!error) {
1218 acpi_lapic = 1;
1219
1220 /*
1221 * Parse MADT IO-APIC entries
1222 */
1223 error = acpi_parse_madt_ioapic_entries();
1224 if (!error) {
1225 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 acpi_ioapic = 1;
1227
1228 smp_found_config = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 }
1230 }
1231 if (error == -EINVAL) {
1232 /*
1233 * Dell Precision Workstation 410, 610 come here.
1234 */
Len Brown4be44fc2005-08-05 00:44:28 -04001235 printk(KERN_ERR PREFIX
1236 "Invalid BIOS MADT, disabling ACPI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 disable_acpi();
1238 }
Len Brown7b37b5f2008-12-23 01:47:42 -05001239 } else {
1240 /*
1241 * ACPI found no MADT, and so ACPI wants UP PIC mode.
1242 * In the event an MPS table was found, forget it.
1243 * Boot with "acpi=off" to use MPS on such a system.
1244 */
1245 if (smp_found_config) {
1246 printk(KERN_WARNING PREFIX
1247 "No APIC-table, disabling MPS\n");
1248 smp_found_config = 0;
1249 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 }
Yinghai Lu69b88af2008-12-05 22:45:50 -08001251
1252 /*
1253 * ACPI supports both logical (e.g. Hyper-Threading) and physical
1254 * processors, where MPS only supports physical.
1255 */
1256 if (acpi_lapic && acpi_ioapic)
1257 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
1258 "information\n");
1259 else if (acpi_lapic)
1260 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
1261 "configuration information\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262#endif
1263 return;
1264}
1265
Jeff Garzik18552562007-10-03 15:15:40 -04001266static int __init disable_acpi_irq(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001267{
1268 if (!acpi_force) {
1269 printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
1270 d->ident);
1271 acpi_noirq_set();
1272 }
1273 return 0;
1274}
1275
Jeff Garzik18552562007-10-03 15:15:40 -04001276static int __init disable_acpi_pci(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001277{
1278 if (!acpi_force) {
1279 printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
1280 d->ident);
1281 acpi_disable_pci();
1282 }
1283 return 0;
1284}
Andrey Paninaea00142005-06-25 14:54:42 -07001285
Jeff Garzik18552562007-10-03 15:15:40 -04001286static int __init dmi_disable_acpi(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001287{
1288 if (!acpi_force) {
Len Brown4be44fc2005-08-05 00:44:28 -04001289 printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
Andrey Paninaea00142005-06-25 14:54:42 -07001290 disable_acpi();
1291 } else {
1292 printk(KERN_NOTICE
1293 "Warning: DMI blacklist says broken, but acpi forced\n");
1294 }
1295 return 0;
1296}
1297
1298/*
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001299 * Force ignoring BIOS IRQ0 pin2 override
1300 */
1301static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
1302{
Ingo Molnar8d89adf2008-10-07 06:47:52 +02001303 /*
1304 * The ati_ixp4x0_rev() early PCI quirk should have set
1305 * the acpi_skip_timer_override flag already:
1306 */
1307 if (!acpi_skip_timer_override) {
1308 WARN(1, KERN_ERR "ati_ixp4x0 quirk not complete.\n");
1309 pr_notice("%s detected: Ignoring BIOS IRQ0 pin2 override\n",
1310 d->ident);
1311 acpi_skip_timer_override = 1;
1312 }
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001313 return 0;
1314}
1315
1316/*
Andrey Paninaea00142005-06-25 14:54:42 -07001317 * If your system is blacklisted here, but you find that acpi=force
Zhang Rui5b4c0b62009-04-01 01:49:42 -04001318 * works for you, please contact linux-acpi@vger.kernel.org
Andrey Paninaea00142005-06-25 14:54:42 -07001319 */
1320static struct dmi_system_id __initdata acpi_dmi_table[] = {
1321 /*
1322 * Boxes that need ACPI disabled
1323 */
1324 {
Len Brown4be44fc2005-08-05 00:44:28 -04001325 .callback = dmi_disable_acpi,
1326 .ident = "IBM Thinkpad",
1327 .matches = {
1328 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1329 DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
1330 },
1331 },
Andrey Paninaea00142005-06-25 14:54:42 -07001332
1333 /*
Andrey Paninaea00142005-06-25 14:54:42 -07001334 * Boxes that need ACPI PCI IRQ routing disabled
1335 */
1336 {
Len Brown4be44fc2005-08-05 00:44:28 -04001337 .callback = disable_acpi_irq,
1338 .ident = "ASUS A7V",
1339 .matches = {
1340 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
1341 DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
1342 /* newer BIOS, Revision 1011, does work */
1343 DMI_MATCH(DMI_BIOS_VERSION,
1344 "ASUS A7V ACPI BIOS Revision 1007"),
1345 },
1346 },
Len Brown74586fc2007-03-08 02:48:30 -05001347 {
1348 /*
1349 * Latest BIOS for IBM 600E (1.16) has bad pcinum
1350 * for LPC bridge, which is needed for the PCI
1351 * interrupt links to work. DSDT fix is in bug 5966.
1352 * 2645, 2646 model numbers are shared with 600/600E/600X
1353 */
1354 .callback = disable_acpi_irq,
1355 .ident = "IBM Thinkpad 600 Series 2645",
1356 .matches = {
1357 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1358 DMI_MATCH(DMI_BOARD_NAME, "2645"),
1359 },
1360 },
1361 {
1362 .callback = disable_acpi_irq,
1363 .ident = "IBM Thinkpad 600 Series 2646",
1364 .matches = {
1365 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1366 DMI_MATCH(DMI_BOARD_NAME, "2646"),
1367 },
1368 },
Andrey Paninaea00142005-06-25 14:54:42 -07001369 /*
1370 * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
1371 */
Len Brown4be44fc2005-08-05 00:44:28 -04001372 { /* _BBN 0 bug */
1373 .callback = disable_acpi_pci,
1374 .ident = "ASUS PR-DLS",
1375 .matches = {
1376 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1377 DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
1378 DMI_MATCH(DMI_BIOS_VERSION,
1379 "ASUS PR-DLS ACPI BIOS Revision 1010"),
1380 DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
1381 },
1382 },
Andrey Paninaea00142005-06-25 14:54:42 -07001383 {
Len Brown4be44fc2005-08-05 00:44:28 -04001384 .callback = disable_acpi_pci,
1385 .ident = "Acer TravelMate 36x Laptop",
1386 .matches = {
1387 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
1388 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
1389 },
1390 },
Andreas Herrmann35af2822008-10-22 13:08:31 +02001391 {}
1392};
1393
1394/* second table for DMI checks that should run after early-quirks */
1395static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
Matthew Garrett9340e1c2008-07-01 01:12:06 +01001396 /*
1397 * HP laptops which use a DSDT reporting as HP/SB400/10000,
1398 * which includes some code which overrides all temperature
1399 * trip points to 16C if the INTIN2 input of the I/O APIC
1400 * is enabled. This input is incorrectly designated the
1401 * ISA IRQ 0 via an interrupt source override even though
1402 * it is wired to the output of the master 8259A and INTIN0
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001403 * is not connected at all. Force ignoring BIOS IRQ0 pin2
1404 * override in that cases.
1405 */
1406 {
1407 .callback = dmi_ignore_irq0_timer_override,
Rafael J. Wysockie84956f2008-10-06 11:59:29 +02001408 .ident = "HP nx6115 laptop",
1409 .matches = {
1410 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1411 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6115"),
1412 },
1413 },
1414 {
1415 .callback = dmi_ignore_irq0_timer_override,
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001416 .ident = "HP NX6125 laptop",
1417 .matches = {
1418 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1419 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
1420 },
1421 },
1422 {
1423 .callback = dmi_ignore_irq0_timer_override,
1424 .ident = "HP NX6325 laptop",
1425 .matches = {
1426 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1427 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
1428 },
1429 },
Rafael J. Wysockie84956f2008-10-06 11:59:29 +02001430 {
1431 .callback = dmi_ignore_irq0_timer_override,
1432 .ident = "HP 6715b laptop",
1433 .matches = {
1434 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1435 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
1436 },
1437 },
Len Brown4be44fc2005-08-05 00:44:28 -04001438 {}
Andrey Paninaea00142005-06-25 14:54:42 -07001439};
1440
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441/*
1442 * acpi_boot_table_init() and acpi_boot_init()
1443 * called from setup_arch(), always.
1444 * 1. checksums all tables
1445 * 2. enumerates lapics
1446 * 3. enumerates io-apics
1447 *
1448 * acpi_table_init() is separate to allow reading SRAT without
1449 * other side effects.
1450 *
1451 * side effects of acpi_boot_init:
1452 * acpi_lapic = 1 if LAPIC found
1453 * acpi_ioapic = 1 if IOAPIC found
1454 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
1455 * if acpi_blacklisted() acpi_disabled = 1;
1456 * acpi_irq_model=...
1457 * ...
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 */
1459
Len Brown8558e392010-01-06 16:11:06 -05001460void __init acpi_boot_table_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461{
Andrey Paninaea00142005-06-25 14:54:42 -07001462 dmi_check_system(acpi_dmi_table);
Andrey Paninaea00142005-06-25 14:54:42 -07001463
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 /*
1465 * If acpi_disabled, bail out
1466 * One exception: acpi=ht continues far enough to enumerate LAPICs
1467 */
1468 if (acpi_disabled && !acpi_ht)
Len Brown8558e392010-01-06 16:11:06 -05001469 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001471 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 * Initialize the ACPI boot-time table parser.
1473 */
Len Brown8558e392010-01-06 16:11:06 -05001474 if (acpi_table_init()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 disable_acpi();
Len Brown8558e392010-01-06 16:11:06 -05001476 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001479 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
1481 /*
1482 * blacklist may disable ACPI entirely
1483 */
Len Brown8558e392010-01-06 16:11:06 -05001484 if (acpi_blacklisted()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 if (acpi_force) {
1486 printk(KERN_WARNING PREFIX "acpi=force override\n");
1487 } else {
1488 printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
1489 disable_acpi();
Len Brown8558e392010-01-06 16:11:06 -05001490 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 }
1492 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493}
1494
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001495int __init early_acpi_boot_init(void)
1496{
1497 /*
1498 * If acpi_disabled, bail out
1499 * One exception: acpi=ht continues far enough to enumerate LAPICs
1500 */
1501 if (acpi_disabled && !acpi_ht)
1502 return 1;
1503
1504 /*
1505 * Process the Multiple APIC Description Table (MADT), if present
1506 */
1507 early_acpi_process_madt();
1508
1509 return 0;
1510}
1511
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512int __init acpi_boot_init(void)
1513{
Andreas Herrmann35af2822008-10-22 13:08:31 +02001514 /* those are executed after early-quirks are executed */
1515 dmi_check_system(acpi_dmi_table_late);
1516
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 /*
1518 * If acpi_disabled, bail out
1519 * One exception: acpi=ht continues far enough to enumerate LAPICs
1520 */
1521 if (acpi_disabled && !acpi_ht)
Len Brown4be44fc2005-08-05 00:44:28 -04001522 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001524 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
1526 /*
1527 * set sci_int and PM timer address
1528 */
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +03001529 acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
1531 /*
1532 * Process the Multiple APIC Description Table (MADT), if present
1533 */
1534 acpi_process_madt();
1535
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001536 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
Thomas Gleixnerb72d0db2009-08-29 16:24:51 +02001538 if (!acpi_noirq)
1539 x86_init.pci.init = pci_acpi_init;
1540
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 return 0;
1542}
Rusty Russell1a3f2392006-09-26 10:52:32 +02001543
1544static int __init parse_acpi(char *arg)
1545{
1546 if (!arg)
1547 return -EINVAL;
1548
1549 /* "acpi=off" disables both ACPI table parsing and interpreter */
1550 if (strcmp(arg, "off") == 0) {
1551 disable_acpi();
1552 }
1553 /* acpi=force to over-ride black-list */
1554 else if (strcmp(arg, "force") == 0) {
1555 acpi_force = 1;
1556 acpi_ht = 1;
1557 acpi_disabled = 0;
1558 }
1559 /* acpi=strict disables out-of-spec workarounds */
1560 else if (strcmp(arg, "strict") == 0) {
1561 acpi_strict = 1;
1562 }
1563 /* Limit ACPI just to boot-time to enable HT */
1564 else if (strcmp(arg, "ht") == 0) {
Len Brown4c81ba42010-03-14 16:28:46 -04001565 if (!acpi_force) {
1566 printk(KERN_WARNING "acpi=ht will be removed in Linux-2.6.35\n");
Rusty Russell1a3f2392006-09-26 10:52:32 +02001567 disable_acpi();
Len Brown4c81ba42010-03-14 16:28:46 -04001568 }
Rusty Russell1a3f2392006-09-26 10:52:32 +02001569 acpi_ht = 1;
1570 }
Zhao Yakui237889b2008-12-17 16:55:18 +08001571 /* acpi=rsdt use RSDT instead of XSDT */
1572 else if (strcmp(arg, "rsdt") == 0) {
1573 acpi_rsdt_forced = 1;
1574 }
Rusty Russell1a3f2392006-09-26 10:52:32 +02001575 /* "acpi=noirq" disables ACPI interrupt routing */
1576 else if (strcmp(arg, "noirq") == 0) {
1577 acpi_noirq_set();
1578 } else {
1579 /* Core will printk when we return error. */
1580 return -EINVAL;
1581 }
1582 return 0;
1583}
1584early_param("acpi", parse_acpi);
1585
1586/* FIXME: Using pci= for an ACPI parameter is a travesty. */
1587static int __init parse_pci(char *arg)
1588{
1589 if (arg && strcmp(arg, "noacpi") == 0)
1590 acpi_disable_pci();
1591 return 0;
1592}
1593early_param("pci", parse_pci);
1594
Yinghai Lu3c999f12008-06-20 16:11:20 -07001595int __init acpi_mps_check(void)
1596{
1597#if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
1598/* mptable code is not built-in*/
1599 if (acpi_disabled || acpi_noirq) {
1600 printk(KERN_WARNING "MPS support code is not built-in.\n"
1601 "Using acpi=off or acpi=noirq or pci=noacpi "
1602 "may have problem\n");
1603 return 1;
1604 }
1605#endif
1606 return 0;
1607}
1608
Rusty Russell1a3f2392006-09-26 10:52:32 +02001609#ifdef CONFIG_X86_IO_APIC
1610static int __init parse_acpi_skip_timer_override(char *arg)
1611{
1612 acpi_skip_timer_override = 1;
1613 return 0;
1614}
1615early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
Andi Kleenfa18f472006-11-14 16:57:46 +01001616
1617static int __init parse_acpi_use_timer_override(char *arg)
1618{
1619 acpi_use_timer_override = 1;
1620 return 0;
1621}
1622early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001623#endif /* CONFIG_X86_IO_APIC */
1624
1625static int __init setup_acpi_sci(char *s)
1626{
1627 if (!s)
1628 return -EINVAL;
1629 if (!strcmp(s, "edge"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001630 acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
1631 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001632 else if (!strcmp(s, "level"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001633 acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
1634 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001635 else if (!strcmp(s, "high"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001636 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
1637 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001638 else if (!strcmp(s, "low"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001639 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
1640 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001641 else
1642 return -EINVAL;
1643 return 0;
1644}
1645early_param("acpi_sci", setup_acpi_sci);
Andrew Mortond0a90812006-10-20 14:30:27 -07001646
1647int __acpi_acquire_global_lock(unsigned int *lock)
1648{
1649 unsigned int old, new, val;
1650 do {
1651 old = *lock;
1652 new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
1653 val = cmpxchg(lock, old, new);
1654 } while (unlikely (val != old));
1655 return (new < 3) ? -1 : 0;
1656}
1657
1658int __acpi_release_global_lock(unsigned int *lock)
1659{
1660 unsigned int old, new, val;
1661 do {
1662 old = *lock;
1663 new = old & ~0x3;
1664 val = cmpxchg(lock, old, new);
1665 } while (unlikely (val != old));
1666 return old & 0x1;
1667}