blob: 3ee92f28a4b264d5d92dcc4823c418e558e390d5 [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/*
97 * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
98 * to map the target physical address. The problem is that set_fixmap()
99 * provides a single page, and it is possible that the page is not
100 * sufficient.
101 * By using this area, we can map up to MAX_IO_APICS pages temporarily,
102 * i.e. until the next __va_range() call.
103 *
104 * Important Safety Note: The fixed I/O APIC page numbers are *subtracted*
105 * from the fixed base. That's why we start at FIX_IO_APIC_BASE_END and
106 * count idx down while incrementing the phys address.
107 */
Jan Beulich2fdf0742007-12-13 08:33:59 +0000108char *__init __acpi_map_table(unsigned long phys, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Yinghai Luf34fa822008-07-09 20:16:36 -0700111 if (!phys || !size)
112 return NULL;
113
Yinghai Lu7d972772009-02-07 15:39:41 -0800114 return early_ioremap(phys, size);
115}
116void __init __acpi_unmap_table(char *map, unsigned long size)
117{
118 if (!map || !size)
119 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Yinghai Lu7d972772009-02-07 15:39:41 -0800121 early_iounmap(map, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124#ifdef CONFIG_X86_LOCAL_APIC
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300125static int __init acpi_parse_madt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
Len Brown4be44fc2005-08-05 00:44:28 -0400127 struct acpi_table_madt *madt = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300129 if (!cpu_has_apic)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 return -EINVAL;
131
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300132 madt = (struct acpi_table_madt *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 if (!madt) {
134 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
135 return -ENODEV;
136 }
137
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300138 if (madt->address) {
139 acpi_lapic_addr = (u64) madt->address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141 printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300142 madt->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 }
144
Ingo Molnar306db032009-01-28 03:43:47 +0100145 default_acpi_madt_oem_check(madt->header.oem_id,
146 madt->header.oem_table_id);
Len Brown4be44fc2005-08-05 00:44:28 -0400147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 return 0;
149}
150
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400151static void __cpuinit acpi_register_lapic(int id, u8 enabled)
152{
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700153 unsigned int ver = 0;
154
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400155 if (!enabled) {
156 ++disabled_cpus;
157 return;
158 }
159
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700160 if (boot_cpu_physical_apicid != -1U)
161 ver = apic_version[boot_cpu_physical_apicid];
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700162
163 generic_processor_info(id, ver);
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400164}
165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166static int __init
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800167acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
168{
169 struct acpi_madt_local_x2apic *processor = NULL;
170
171 processor = (struct acpi_madt_local_x2apic *)header;
172
173 if (BAD_MADT_ENTRY(processor, end))
174 return -EINVAL;
175
176 acpi_table_print_madt_entry(header);
177
178#ifdef CONFIG_X86_X2APIC
179 /*
180 * We need to register disabled CPU as well to permit
181 * counting disabled CPUs. This allows us to size
182 * cpus_possible_map more accurately, to permit
183 * to not preallocating memory for all NR_CPUS
184 * when we use CPU hotplug.
185 */
186 acpi_register_lapic(processor->local_apic_id, /* APIC ID */
187 processor->lapic_flags & ACPI_MADT_ENABLED);
188#else
189 printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
190#endif
191
192 return 0;
193}
194
195static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300196acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300198 struct acpi_madt_local_apic *processor = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300200 processor = (struct acpi_madt_local_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202 if (BAD_MADT_ENTRY(processor, end))
203 return -EINVAL;
204
205 acpi_table_print_madt_entry(header);
206
Ashok Raj7f66ae42006-02-03 21:51:50 +0100207 /*
208 * We need to register disabled CPU as well to permit
209 * counting disabled CPUs. This allows us to size
210 * cpus_possible_map more accurately, to permit
211 * to not preallocating memory for all NR_CPUS
212 * when we use CPU hotplug.
213 */
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400214 acpi_register_lapic(processor->id, /* APIC ID */
215 processor->lapic_flags & ACPI_MADT_ENABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 return 0;
218}
219
220static int __init
Jack Steinerac049c12008-03-28 14:12:09 -0500221acpi_parse_sapic(struct acpi_subtable_header *header, const unsigned long end)
222{
223 struct acpi_madt_local_sapic *processor = NULL;
224
225 processor = (struct acpi_madt_local_sapic *)header;
226
227 if (BAD_MADT_ENTRY(processor, end))
228 return -EINVAL;
229
230 acpi_table_print_madt_entry(header);
231
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400232 acpi_register_lapic((processor->id << 8) | processor->eid,/* APIC ID */
233 processor->lapic_flags & ACPI_MADT_ENABLED);
Jack Steinerac049c12008-03-28 14:12:09 -0500234
235 return 0;
236}
237
238static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300239acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400240 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300242 struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300244 lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
246 if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
247 return -EINVAL;
248
249 acpi_lapic_addr = lapic_addr_ovr->address;
250
251 return 0;
252}
253
254static int __init
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800255acpi_parse_x2apic_nmi(struct acpi_subtable_header *header,
256 const unsigned long end)
257{
258 struct acpi_madt_local_x2apic_nmi *x2apic_nmi = NULL;
259
260 x2apic_nmi = (struct acpi_madt_local_x2apic_nmi *)header;
261
262 if (BAD_MADT_ENTRY(x2apic_nmi, end))
263 return -EINVAL;
264
265 acpi_table_print_madt_entry(header);
266
267 if (x2apic_nmi->lint != 1)
268 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
269
270 return 0;
271}
272
273static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300274acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300276 struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300278 lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280 if (BAD_MADT_ENTRY(lapic_nmi, end))
281 return -EINVAL;
282
283 acpi_table_print_madt_entry(header);
284
285 if (lapic_nmi->lint != 1)
286 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
287
288 return 0;
289}
290
Len Brown4be44fc2005-08-05 00:44:28 -0400291#endif /*CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Len Brown84663612005-08-24 12:09:07 -0400293#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
295static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300296acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300298 struct acpi_madt_io_apic *ioapic = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300300 ioapic = (struct acpi_madt_io_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302 if (BAD_MADT_ENTRY(ioapic, end))
303 return -EINVAL;
Len Brown4be44fc2005-08-05 00:44:28 -0400304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 acpi_table_print_madt_entry(header);
306
Len Brown4be44fc2005-08-05 00:44:28 -0400307 mp_register_ioapic(ioapic->id,
308 ioapic->address, ioapic->global_irq_base);
309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 return 0;
311}
312
313/*
314 * Parse Interrupt Source Override for the ACPI SCI
315 */
Eric W. Biederman9d2062b2010-03-30 01:07:05 -0700316static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger, u32 gsi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
318 if (trigger == 0) /* compatible SCI trigger is level */
319 trigger = 3;
320
321 if (polarity == 0) /* compatible SCI polarity is low */
322 polarity = 3;
323
324 /* Command-line over-ride via acpi_sci= */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300325 if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
326 trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300328 if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
329 polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
331 /*
Len Brown4be44fc2005-08-05 00:44:28 -0400332 * mp_config_acpi_legacy_irqs() already setup IRQs < 16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 * If GSI is < 16, this will update its flags,
334 * else it will create a new mp_irqs[] entry.
335 */
Eric W. Biederman9d2062b2010-03-30 01:07:05 -0700336 mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
338 /*
339 * stash over-ride to indicate we've been here
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300340 * and for later update of acpi_gbl_FADT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 */
Len Brown7bdd21c2006-12-02 02:27:46 -0500342 acpi_sci_override_gsi = gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 return;
344}
345
346static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300347acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400348 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300350 struct acpi_madt_interrupt_override *intsrc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300352 intsrc = (struct acpi_madt_interrupt_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354 if (BAD_MADT_ENTRY(intsrc, end))
355 return -EINVAL;
356
357 acpi_table_print_madt_entry(header);
358
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300359 if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
Eric W. Biederman9d2062b2010-03-30 01:07:05 -0700360 acpi_sci_ioapic_setup(intsrc->source_irq,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300361 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
Eric W. Biederman9d2062b2010-03-30 01:07:05 -0700362 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
363 intsrc->global_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 return 0;
365 }
366
367 if (acpi_skip_timer_override &&
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300368 intsrc->source_irq == 0 && intsrc->global_irq == 2) {
Len Brown4be44fc2005-08-05 00:44:28 -0400369 printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
370 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 }
372
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300373 mp_override_legacy_irq(intsrc->source_irq,
374 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
375 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
376 intsrc->global_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
378 return 0;
379}
380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300382acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300384 struct acpi_madt_nmi_source *nmi_src = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300386 nmi_src = (struct acpi_madt_nmi_source *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388 if (BAD_MADT_ENTRY(nmi_src, end))
389 return -EINVAL;
390
391 acpi_table_print_madt_entry(header);
392
393 /* TBD: Support nimsrc entries? */
394
395 return 0;
396}
397
Len Brown4be44fc2005-08-05 00:44:28 -0400398#endif /* CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400/*
401 * acpi_pic_sci_set_trigger()
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300402 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 * use ELCR to set PIC-mode trigger type for SCI
404 *
405 * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
406 * it may require Edge Trigger -- use "acpi_sci=edge"
407 *
408 * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
409 * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
Simon Arlott27b46d72007-10-20 01:13:56 +0200410 * ECLR1 is IRQs 0-7 (IRQ 0, 1, 2 must be 0)
411 * ECLR2 is IRQs 8-15 (IRQ 8, 13 must be 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 */
413
Len Brown4be44fc2005-08-05 00:44:28 -0400414void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
416 unsigned int mask = 1 << irq;
417 unsigned int old, new;
418
419 /* Real old ELCR mask */
420 old = inb(0x4d0) | (inb(0x4d1) << 8);
421
422 /*
Simon Arlott27b46d72007-10-20 01:13:56 +0200423 * If we use ACPI to set PCI IRQs, then we should clear ELCR
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 * since we will set it correctly as we enable the PCI irq
425 * routing.
426 */
427 new = acpi_noirq ? old : 0;
428
429 /*
430 * Update SCI information in the ELCR, it isn't in the PCI
431 * routing tables..
432 */
433 switch (trigger) {
Len Brown4be44fc2005-08-05 00:44:28 -0400434 case 1: /* Edge - clear */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 new &= ~mask;
436 break;
Len Brown4be44fc2005-08-05 00:44:28 -0400437 case 3: /* Level - set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 new |= mask;
439 break;
440 }
441
442 if (old == new)
443 return;
444
445 printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
446 outb(new, 0x4d0);
447 outb(new >> 8, 0x4d1);
448}
449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
451{
Eric W. Biedermanf023d762006-10-04 02:16:52 -0700452 *irq = gsi;
Yinghai Lu18dce6b2010-02-10 01:20:05 -0800453
454#ifdef CONFIG_X86_IO_APIC
455 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
456 setup_IO_APIC_irq_extra(gsi);
457#endif
458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 return 0;
460}
461
Eric W. Biederman2c2df842010-03-30 01:07:02 -0700462int acpi_isa_irq_to_gsi(unsigned isa_irq, u32 *gsi)
463{
464 if (isa_irq >= 16)
465 return -1;
466 *gsi = isa_irq;
467 return 0;
468}
469
Kenji Kaneshige1f3a6a12005-07-28 14:42:00 -0400470/*
471 * success: return IRQ number (>=0)
472 * failure: return < 0
473 */
Yinghai Lue5198072009-05-15 13:05:16 -0700474int acpi_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475{
476 unsigned int irq;
477 unsigned int plat_gsi = gsi;
478
479#ifdef CONFIG_PCI
480 /*
481 * Make sure all (legacy) PCI IRQs are set as level-triggered.
482 */
483 if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
Yinghai Lue5198072009-05-15 13:05:16 -0700484 if (trigger == ACPI_LEVEL_SENSITIVE)
Len Brown4be44fc2005-08-05 00:44:28 -0400485 eisa_set_level_irq(gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 }
487#endif
488
489#ifdef CONFIG_X86_IO_APIC
490 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) {
Yinghai Lue5198072009-05-15 13:05:16 -0700491 plat_gsi = mp_register_gsi(dev, gsi, trigger, polarity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 }
493#endif
Yinghai Lu18dce6b2010-02-10 01:20:05 -0800494 irq = plat_gsi;
495
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 return irq;
497}
Len Brown4be44fc2005-08-05 00:44:28 -0400498
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499/*
500 * ACPI based hotplug support for CPU
501 */
502#ifdef CONFIG_ACPI_HOTPLUG_CPU
Alex Chiangd8191fa2010-02-22 12:11:39 -0700503#include <acpi/processor.h>
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100504
Haicheng Li0271f912010-02-04 19:06:33 +0800505static void acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
506{
507#ifdef CONFIG_ACPI_NUMA
508 int nid;
509
510 nid = acpi_get_node(handle);
511 if (nid == -1 || !node_online(nid))
512 return;
513#ifdef CONFIG_X86_64
514 apicid_to_node[physid] = nid;
515 numa_set_node(cpu, nid);
516#else /* CONFIG_X86_32 */
517 apicid_2_node[physid] = nid;
518 cpu_to_node_map[cpu] = nid;
519#endif
520
521#endif
522}
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100523
524static int __cpuinit _acpi_map_lsapic(acpi_handle handle, int *pcpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
Ashok Raj73fea172006-09-26 10:52:35 +0200526 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
527 union acpi_object *obj;
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300528 struct acpi_madt_local_apic *lapic;
Rusty Russellee943a82008-12-31 18:08:47 -0800529 cpumask_var_t tmp_map, new_map;
Ashok Raj73fea172006-09-26 10:52:35 +0200530 u8 physid;
531 int cpu;
Rusty Russellee943a82008-12-31 18:08:47 -0800532 int retval = -ENOMEM;
Ashok Raj73fea172006-09-26 10:52:35 +0200533
534 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
535 return -EINVAL;
536
537 if (!buffer.length || !buffer.pointer)
538 return -EINVAL;
539
540 obj = buffer.pointer;
541 if (obj->type != ACPI_TYPE_BUFFER ||
542 obj->buffer.length < sizeof(*lapic)) {
543 kfree(buffer.pointer);
544 return -EINVAL;
545 }
546
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300547 lapic = (struct acpi_madt_local_apic *)obj->buffer.pointer;
Ashok Raj73fea172006-09-26 10:52:35 +0200548
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300549 if (lapic->header.type != ACPI_MADT_TYPE_LOCAL_APIC ||
550 !(lapic->lapic_flags & ACPI_MADT_ENABLED)) {
Ashok Raj73fea172006-09-26 10:52:35 +0200551 kfree(buffer.pointer);
552 return -EINVAL;
553 }
554
555 physid = lapic->id;
556
557 kfree(buffer.pointer);
558 buffer.length = ACPI_ALLOCATE_BUFFER;
559 buffer.pointer = NULL;
560
Rusty Russellee943a82008-12-31 18:08:47 -0800561 if (!alloc_cpumask_var(&tmp_map, GFP_KERNEL))
562 goto out;
563
564 if (!alloc_cpumask_var(&new_map, GFP_KERNEL))
565 goto free_tmp_map;
566
567 cpumask_copy(tmp_map, cpu_present_mask);
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400568 acpi_register_lapic(physid, lapic->lapic_flags & ACPI_MADT_ENABLED);
Ashok Raj73fea172006-09-26 10:52:35 +0200569
570 /*
571 * If mp_register_lapic successfully generates a new logical cpu
572 * number, then the following will get us exactly what was mapped
573 */
Rusty Russellee943a82008-12-31 18:08:47 -0800574 cpumask_andnot(new_map, cpu_present_mask, tmp_map);
575 if (cpumask_empty(new_map)) {
Ashok Raj73fea172006-09-26 10:52:35 +0200576 printk ("Unable to map lapic to logical cpu number\n");
Rusty Russellee943a82008-12-31 18:08:47 -0800577 retval = -EINVAL;
578 goto free_new_map;
Ashok Raj73fea172006-09-26 10:52:35 +0200579 }
580
Alex Chiangd8191fa2010-02-22 12:11:39 -0700581 acpi_processor_set_pdc(handle);
582
Rusty Russellee943a82008-12-31 18:08:47 -0800583 cpu = cpumask_first(new_map);
Haicheng Li0271f912010-02-04 19:06:33 +0800584 acpi_map_cpu2node(handle, cpu, physid);
Ashok Raj73fea172006-09-26 10:52:35 +0200585
586 *pcpu = cpu;
Rusty Russellee943a82008-12-31 18:08:47 -0800587 retval = 0;
588
589free_new_map:
590 free_cpumask_var(new_map);
591free_tmp_map:
592 free_cpumask_var(tmp_map);
593out:
594 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595}
Len Brown4be44fc2005-08-05 00:44:28 -0400596
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100597/* wrapper to silence section mismatch warning */
598int __ref acpi_map_lsapic(acpi_handle handle, int *pcpu)
599{
600 return _acpi_map_lsapic(handle, pcpu);
601}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602EXPORT_SYMBOL(acpi_map_lsapic);
603
Len Brown4be44fc2005-08-05 00:44:28 -0400604int acpi_unmap_lsapic(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605{
Mike Travis71fff5e2007-10-19 20:35:03 +0200606 per_cpu(x86_cpu_to_apicid, cpu) = -1;
Mike Travis96289372008-12-31 18:08:46 -0800607 set_cpu_present(cpu, false);
Ashok Raj73fea172006-09-26 10:52:35 +0200608 num_processors--;
609
610 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611}
Len Brown4be44fc2005-08-05 00:44:28 -0400612
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613EXPORT_SYMBOL(acpi_unmap_lsapic);
Len Brown4be44fc2005-08-05 00:44:28 -0400614#endif /* CONFIG_ACPI_HOTPLUG_CPU */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Len Brown4be44fc2005-08-05 00:44:28 -0400616int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700617{
618 /* TBD */
619 return -EINVAL;
620}
Len Brown4be44fc2005-08-05 00:44:28 -0400621
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700622EXPORT_SYMBOL(acpi_register_ioapic);
623
Len Brown4be44fc2005-08-05 00:44:28 -0400624int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700625{
626 /* TBD */
627 return -EINVAL;
628}
Len Brown4be44fc2005-08-05 00:44:28 -0400629
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700630EXPORT_SYMBOL(acpi_unregister_ioapic);
631
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300632static int __init acpi_parse_sbf(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300634 struct acpi_table_boot *sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300636 sb = (struct acpi_table_boot *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 if (!sb) {
638 printk(KERN_WARNING PREFIX "Unable to map SBF\n");
639 return -ENODEV;
640 }
641
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300642 sbf_port = sb->cmos_index; /* Save CMOS port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
644 return 0;
645}
646
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647#ifdef CONFIG_HPET_TIMER
john stultz2d0c87c2007-02-16 01:28:18 -0800648#include <asm/hpet.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Aaron Durbina1dfd852007-07-21 17:11:39 +0200650static struct __initdata resource *hpet_res;
651
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300652static int __init acpi_parse_hpet(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653{
654 struct acpi_table_hpet *hpet_tbl;
655
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300656 hpet_tbl = (struct acpi_table_hpet *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 if (!hpet_tbl) {
658 printk(KERN_WARNING PREFIX "Unable to map HPET\n");
659 return -ENODEV;
660 }
661
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300662 if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 printk(KERN_WARNING PREFIX "HPET timers must be located in "
664 "memory.\n");
665 return -1;
666 }
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200667
john stultz2d0c87c2007-02-16 01:28:18 -0800668 hpet_address = hpet_tbl->address.address;
Suresh Siddhac8bc6f32009-08-04 12:07:09 -0700669 hpet_blockid = hpet_tbl->sequence;
Thomas Gleixnerf4df73c2007-11-15 21:41:50 -0500670
671 /*
672 * Some broken BIOSes advertise HPET at 0x0. We really do not
673 * want to allocate a resource there.
674 */
675 if (!hpet_address) {
676 printk(KERN_WARNING PREFIX
677 "HPET id: %#x base: %#lx is invalid\n",
678 hpet_tbl->id, hpet_address);
679 return 0;
680 }
681#ifdef CONFIG_X86_64
682 /*
683 * Some even more broken BIOSes advertise HPET at
684 * 0xfed0000000000000 instead of 0xfed00000. Fix it up and add
685 * some noise:
686 */
687 if (hpet_address == 0xfed0000000000000UL) {
688 if (!hpet_force_user) {
689 printk(KERN_WARNING PREFIX "HPET id: %#x "
690 "base: 0xfed0000000000000 is bogus\n "
691 "try hpet=force on the kernel command line to "
692 "fix it up to 0xfed00000.\n", hpet_tbl->id);
693 hpet_address = 0;
694 return 0;
695 }
696 printk(KERN_WARNING PREFIX
697 "HPET id: %#x base: 0xfed0000000000000 fixed up "
698 "to 0xfed00000.\n", hpet_tbl->id);
699 hpet_address >>= 32;
700 }
701#endif
Len Brown4be44fc2005-08-05 00:44:28 -0400702 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
john stultz2d0c87c2007-02-16 01:28:18 -0800703 hpet_tbl->id, hpet_address);
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200704
Aaron Durbina1dfd852007-07-21 17:11:39 +0200705 /*
706 * Allocate and initialize the HPET firmware resource for adding into
707 * the resource tree during the lateinit timeframe.
708 */
709#define HPET_RESOURCE_NAME_SIZE 9
710 hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
711
Aaron Durbina1dfd852007-07-21 17:11:39 +0200712 hpet_res->name = (void *)&hpet_res[1];
713 hpet_res->flags = IORESOURCE_MEM;
714 snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE, "HPET %u",
715 hpet_tbl->sequence);
716
717 hpet_res->start = hpet_address;
718 hpet_res->end = hpet_address + (1 * 1024) - 1;
719
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 return 0;
721}
Aaron Durbina1dfd852007-07-21 17:11:39 +0200722
723/*
724 * hpet_insert_resource inserts the HPET resources used into the resource
725 * tree.
726 */
727static __init int hpet_insert_resource(void)
728{
729 if (!hpet_res)
730 return 1;
731
732 return insert_resource(&iomem_resource, hpet_res);
733}
734
735late_initcall(hpet_insert_resource);
736
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737#else
738#define acpi_parse_hpet NULL
739#endif
740
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300741static int __init acpi_parse_fadt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742{
Jason Davis90660ec2005-04-16 15:24:53 -0700743
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744#ifdef CONFIG_X86_PM_TIMER
745 /* detect the location of the ACPI PM Timer */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300746 if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 /* FADT rev. 2 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300748 if (acpi_gbl_FADT.xpm_timer_block.space_id !=
Len Brown4be44fc2005-08-05 00:44:28 -0400749 ACPI_ADR_SPACE_SYSTEM_IO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 return 0;
751
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300752 pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
David Shaohua Lie6e87b42005-09-21 01:35:00 -0400753 /*
754 * "X" fields are optional extensions to the original V1.0
755 * fields, so we must selectively expand V1.0 fields if the
756 * corresponding X field is zero.
757 */
758 if (!pmtmr_ioport)
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300759 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 } else {
761 /* FADT rev. 1 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300762 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 }
764 if (pmtmr_ioport)
Len Brown4be44fc2005-08-05 00:44:28 -0400765 printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
766 pmtmr_ioport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767#endif
768 return 0;
769}
770
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771#ifdef CONFIG_X86_LOCAL_APIC
772/*
773 * Parse LAPIC entries in MADT
774 * returns 0 on success, < 0 on error
775 */
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400776
777static void __init acpi_register_lapic_address(unsigned long address)
778{
779 mp_lapic_addr = address;
780
781 set_fixmap_nocache(FIX_APIC_BASE, address);
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700782 if (boot_cpu_physical_apicid == -1U) {
Yinghai Lu4c9961d2008-07-11 18:44:16 -0700783 boot_cpu_physical_apicid = read_apic_id();
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700784 apic_version[boot_cpu_physical_apicid] =
785 GET_APIC_VERSION(apic_read(APIC_LVR));
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700786 }
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400787}
788
Yinghai Lucbf9bd62008-02-19 03:21:06 -0800789static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
790{
791 int count;
792
793 if (!cpu_has_apic)
794 return -ENODEV;
795
796 /*
797 * Note that the LAPIC address is obtained from the MADT (32-bit value)
798 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
799 */
800
801 count =
802 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
803 acpi_parse_lapic_addr_ovr, 0);
804 if (count < 0) {
805 printk(KERN_ERR PREFIX
806 "Error parsing LAPIC address override entry\n");
807 return count;
808 }
809
810 acpi_register_lapic_address(acpi_lapic_addr);
811
812 return count;
813}
814
Len Brown4be44fc2005-08-05 00:44:28 -0400815static int __init acpi_parse_madt_lapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816{
817 int count;
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800818 int x2count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
Andi Kleen0fcd2702006-04-11 12:54:36 +0200820 if (!cpu_has_apic)
821 return -ENODEV;
822
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300823 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 * Note that the LAPIC address is obtained from the MADT (32-bit value)
825 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
826 */
827
Len Brown4be44fc2005-08-05 00:44:28 -0400828 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300829 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
Len Brown4be44fc2005-08-05 00:44:28 -0400830 acpi_parse_lapic_addr_ovr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 if (count < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400832 printk(KERN_ERR PREFIX
833 "Error parsing LAPIC address override entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 return count;
835 }
836
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400837 acpi_register_lapic_address(acpi_lapic_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
Jack Steinerac049c12008-03-28 14:12:09 -0500839 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
840 acpi_parse_sapic, MAX_APICS);
841
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800842 if (!count) {
843 x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
844 acpi_parse_x2apic, MAX_APICS);
Jack Steinerac049c12008-03-28 14:12:09 -0500845 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
846 acpi_parse_lapic, MAX_APICS);
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800847 }
848 if (!count && !x2count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
850 /* TBD: Cleanup to allow fallback to MPS */
851 return -ENODEV;
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800852 } else if (count < 0 || x2count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
854 /* TBD: Cleanup to allow fallback to MPS */
855 return count;
856 }
857
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800858 x2count =
859 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI,
860 acpi_parse_x2apic_nmi, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400861 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300862 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0);
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800863 if (count < 0 || x2count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
865 /* TBD: Cleanup to allow fallback to MPS */
866 return count;
867 }
868 return 0;
869}
Len Brown4be44fc2005-08-05 00:44:28 -0400870#endif /* CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
Len Brown84663612005-08-24 12:09:07 -0400872#ifdef CONFIG_X86_IO_APIC
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400873#define MP_ISA_BUS 0
874
Yinghai Lud49c4282008-06-08 18:31:54 -0700875#ifdef CONFIG_X86_ES7000
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400876extern int es7000_plat;
877#endif
878
Yinghai Lu3f4a7392009-02-08 16:18:03 -0800879int __init acpi_probe_gsi(void)
880{
881 int idx;
882 int gsi;
883 int max_gsi = 0;
884
885 if (acpi_disabled)
886 return 0;
887
888 if (!acpi_ioapic)
889 return 0;
890
891 max_gsi = 0;
892 for (idx = 0; idx < nr_ioapics; idx++) {
Feng Tang2a4ab642009-07-07 23:01:15 -0400893 gsi = mp_gsi_routing[idx].gsi_end;
Yinghai Lu3f4a7392009-02-08 16:18:03 -0800894
895 if (gsi > max_gsi)
896 max_gsi = gsi;
897 }
898
899 return max_gsi + 1;
900}
901
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530902static void assign_to_mp_irq(struct mpc_intsrc *m,
903 struct mpc_intsrc *mp_irq)
Yinghai Lufcfa1462008-06-18 17:29:31 -0700904{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530905 memcpy(mp_irq, m, sizeof(struct mpc_intsrc));
Yinghai Lufcfa1462008-06-18 17:29:31 -0700906}
907
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530908static int mp_irq_cmp(struct mpc_intsrc *mp_irq,
909 struct mpc_intsrc *m)
Yinghai Lufcfa1462008-06-18 17:29:31 -0700910{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530911 return memcmp(mp_irq, m, sizeof(struct mpc_intsrc));
Yinghai Lufcfa1462008-06-18 17:29:31 -0700912}
913
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530914static void save_mp_irq(struct mpc_intsrc *m)
Yinghai Lufcfa1462008-06-18 17:29:31 -0700915{
916 int i;
917
918 for (i = 0; i < mp_irq_entries; i++) {
919 if (!mp_irq_cmp(&mp_irqs[i], m))
920 return;
921 }
922
923 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
924 if (++mp_irq_entries == MAX_IRQ_SOURCES)
925 panic("Max # of irq sources exceeded!!\n");
926}
927
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400928void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
929{
Yinghai Lu6df88092008-06-15 18:19:46 -0700930 int ioapic;
931 int pin;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530932 struct mpc_intsrc mp_irq;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400933
934 /*
935 * Convert 'gsi' to 'ioapic.pin'.
936 */
937 ioapic = mp_find_ioapic(gsi);
938 if (ioapic < 0)
939 return;
Jeremy Fitzhardingec3e137d2009-02-09 12:05:47 -0800940 pin = mp_find_ioapic_pin(ioapic, gsi);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400941
942 /*
943 * TBD: This check is for faulty timer entries, where the override
944 * erroneously sets the trigger to level, resulting in a HUGE
945 * increase of timer interrupts!
946 */
947 if ((bus_irq == 0) && (trigger == 3))
948 trigger = 1;
949
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530950 mp_irq.type = MP_INTSRC;
951 mp_irq.irqtype = mp_INT;
952 mp_irq.irqflag = (trigger << 2) | polarity;
953 mp_irq.srcbus = MP_ISA_BUS;
954 mp_irq.srcbusirq = bus_irq; /* IRQ */
955 mp_irq.dstapic = mp_ioapics[ioapic].apicid; /* APIC ID */
956 mp_irq.dstirq = pin; /* INTIN# */
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400957
Yinghai Lufcfa1462008-06-18 17:29:31 -0700958 save_mp_irq(&mp_irq);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400959}
960
961void __init mp_config_acpi_legacy_irqs(void)
962{
Yinghai Lu6df88092008-06-15 18:19:46 -0700963 int i;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530964 struct mpc_intsrc mp_irq;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400965
966#if defined (CONFIG_MCA) || defined (CONFIG_EISA)
967 /*
968 * Fabricate the legacy ISA bus (bus #31).
969 */
970 mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
971#endif
972 set_bit(MP_ISA_BUS, mp_bus_not_pci);
Thomas Gleixnercfc1b9a2008-07-21 21:35:38 +0200973 pr_debug("Bus #%d is ISA\n", MP_ISA_BUS);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400974
Yinghai Lud49c4282008-06-08 18:31:54 -0700975#ifdef CONFIG_X86_ES7000
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400976 /*
977 * Older generations of ES7000 have no legacy identity mappings
978 */
979 if (es7000_plat == 1)
980 return;
981#endif
982
983 /*
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400984 * 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++) {
Eric W. Biederman0fd52672010-03-30 01:07:06 -0700988 int ioapic, pin;
989 unsigned int dstapic;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400990 int idx;
Eric W. Biederman0fd52672010-03-30 01:07:06 -0700991 u32 gsi;
992
993 /* Locate the gsi that irq i maps to. */
994 if (acpi_isa_irq_to_gsi(i, &gsi))
995 continue;
996
997 /*
998 * Locate the IOAPIC that manages the ISA IRQ.
999 */
1000 ioapic = mp_find_ioapic(gsi);
1001 if (ioapic < 0)
1002 continue;
1003 pin = mp_find_ioapic_pin(ioapic, gsi);
1004 dstapic = mp_ioapics[ioapic].apicid;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001005
1006 for (idx = 0; idx < mp_irq_entries; idx++) {
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301007 struct mpc_intsrc *irq = mp_irqs + idx;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001008
1009 /* Do we already have a mapping for this ISA IRQ? */
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301010 if (irq->srcbus == MP_ISA_BUS && irq->srcbusirq == i)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001011 break;
1012
1013 /* Do we already have a mapping for this IOAPIC pin */
Eric W. Biederman0fd52672010-03-30 01:07:06 -07001014 if (irq->dstapic == dstapic && irq->dstirq == pin)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001015 break;
1016 }
1017
1018 if (idx != mp_irq_entries) {
1019 printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
1020 continue; /* IRQ already used */
1021 }
1022
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301023 mp_irq.type = MP_INTSRC;
1024 mp_irq.irqflag = 0; /* Conforming */
1025 mp_irq.srcbus = MP_ISA_BUS;
1026 mp_irq.dstapic = dstapic;
1027 mp_irq.irqtype = mp_INT;
1028 mp_irq.srcbusirq = i; /* Identity mapped */
Eric W. Biederman0fd52672010-03-30 01:07:06 -07001029 mp_irq.dstirq = pin;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001030
Yinghai Lufcfa1462008-06-18 17:29:31 -07001031 save_mp_irq(&mp_irq);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001032 }
1033}
1034
Yinghai Lue5198072009-05-15 13:05:16 -07001035static int mp_config_acpi_gsi(struct device *dev, u32 gsi, int trigger,
Yinghai Lua31f8202009-05-06 10:06:15 -07001036 int polarity)
1037{
1038#ifdef CONFIG_X86_MPPARSE
1039 struct mpc_intsrc mp_irq;
1040 struct pci_dev *pdev;
1041 unsigned char number;
1042 unsigned int devfn;
1043 int ioapic;
1044 u8 pin;
1045
1046 if (!acpi_ioapic)
1047 return 0;
1048 if (!dev)
1049 return 0;
1050 if (dev->bus != &pci_bus_type)
1051 return 0;
1052
1053 pdev = to_pci_dev(dev);
1054 number = pdev->bus->number;
1055 devfn = pdev->devfn;
1056 pin = pdev->pin;
1057 /* print the entry should happen on mptable identically */
1058 mp_irq.type = MP_INTSRC;
1059 mp_irq.irqtype = mp_INT;
Yinghai Lue5198072009-05-15 13:05:16 -07001060 mp_irq.irqflag = (trigger == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
Yinghai Lua31f8202009-05-06 10:06:15 -07001061 (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
1062 mp_irq.srcbus = number;
1063 mp_irq.srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
1064 ioapic = mp_find_ioapic(gsi);
Yinghai Lubdfe8ac2009-05-06 10:07:41 -07001065 mp_irq.dstapic = mp_ioapics[ioapic].apicid;
Yinghai Lua31f8202009-05-06 10:06:15 -07001066 mp_irq.dstirq = mp_find_ioapic_pin(ioapic, gsi);
1067
1068 save_mp_irq(&mp_irq);
1069#endif
1070 return 0;
1071}
1072
Yinghai Lue5198072009-05-15 13:05:16 -07001073int mp_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001074{
1075 int ioapic;
1076 int ioapic_pin;
Yinghai Lue5198072009-05-15 13:05:16 -07001077 struct io_apic_irq_attr irq_attr;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001078
1079 if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
1080 return gsi;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001081
1082 /* Don't set up the ACPI SCI because it's already set up */
1083 if (acpi_gbl_FADT.sci_interrupt == gsi)
1084 return gsi;
1085
1086 ioapic = mp_find_ioapic(gsi);
1087 if (ioapic < 0) {
1088 printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
1089 return gsi;
1090 }
1091
Jeremy Fitzhardingec3e137d2009-02-09 12:05:47 -08001092 ioapic_pin = mp_find_ioapic_pin(ioapic, gsi);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001093
1094#ifdef CONFIG_X86_32
1095 if (ioapic_renumber_irq)
1096 gsi = ioapic_renumber_irq(ioapic, gsi);
1097#endif
1098
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001099 if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
1100 printk(KERN_ERR "Invalid reference to IOAPIC pin "
Yinghai Lubdfe8ac2009-05-06 10:07:41 -07001101 "%d-%d\n", mp_ioapics[ioapic].apicid,
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001102 ioapic_pin);
1103 return gsi;
1104 }
Yinghai Luf1bdb522009-05-15 13:05:16 -07001105
1106 if (enable_update_mptable)
1107 mp_config_acpi_gsi(dev, gsi, trigger, polarity);
Yinghai Lub9e03532009-05-06 10:05:32 -07001108
Yinghai Lue5198072009-05-15 13:05:16 -07001109 set_io_apic_irq_attr(&irq_attr, ioapic, ioapic_pin,
1110 trigger == ACPI_EDGE_SENSITIVE ? 0 : 1,
1111 polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
1112 io_apic_set_pci_routing(dev, gsi, &irq_attr);
Yinghai Lub9e03532009-05-06 10:05:32 -07001113
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001114 return gsi;
1115}
1116
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117/*
1118 * Parse IOAPIC related entries in MADT
1119 * returns 0 on success, < 0 on error
1120 */
Len Brown4be44fc2005-08-05 00:44:28 -04001121static int __init acpi_parse_madt_ioapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122{
1123 int count;
1124
1125 /*
1126 * ACPI interpreter is required to complete interrupt setup,
1127 * so if it is off, don't enumerate the io-apics with ACPI.
1128 * If MPS is present, it will handle them,
1129 * otherwise the system will stay in PIC mode
1130 */
Jeremy Fitzhardinge6b2b1712009-06-08 02:53:50 -07001131 if (acpi_disabled || acpi_noirq)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001134 if (!cpu_has_apic)
Andi Kleend3b6a342006-04-07 19:49:39 +02001135 return -ENODEV;
1136
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001138 * if "noapic" boot option, don't look for IO-APICs
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 */
1140 if (skip_ioapic_setup) {
1141 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
Len Brown4be44fc2005-08-05 00:44:28 -04001142 "due to 'noapic' option.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 return -ENODEV;
1144 }
1145
Len Brown4be44fc2005-08-05 00:44:28 -04001146 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001147 acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
Len Brown4be44fc2005-08-05 00:44:28 -04001148 MAX_IO_APICS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 if (!count) {
1150 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
1151 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -04001152 } else if (count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
1154 return count;
1155 }
1156
Len Brown4be44fc2005-08-05 00:44:28 -04001157 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001158 acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr,
Yinghai Lu71f521b2008-08-19 20:50:03 -07001159 nr_irqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 if (count < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -04001161 printk(KERN_ERR PREFIX
1162 "Error parsing interrupt source overrides entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 /* TBD: Cleanup to allow fallback to MPS */
1164 return count;
1165 }
1166
1167 /*
1168 * If BIOS did not supply an INT_SRC_OVR for the SCI
1169 * pretend we got one so we can set the SCI flags.
1170 */
1171 if (!acpi_sci_override_gsi)
Eric W. Biederman9d2062b2010-03-30 01:07:05 -07001172 acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0,
1173 acpi_gbl_FADT.sci_interrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001175 /* Fill in identity legacy mappings where no override */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 mp_config_acpi_legacy_irqs();
1177
Len Brown4be44fc2005-08-05 00:44:28 -04001178 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001179 acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src,
Yinghai Lu71f521b2008-08-19 20:50:03 -07001180 nr_irqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 if (count < 0) {
1182 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
1183 /* TBD: Cleanup to allow fallback to MPS */
1184 return count;
1185 }
1186
1187 return 0;
1188}
1189#else
1190static inline int acpi_parse_madt_ioapic_entries(void)
1191{
1192 return -1;
1193}
Len Brown84663612005-08-24 12:09:07 -04001194#endif /* !CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001196static void __init early_acpi_process_madt(void)
1197{
1198#ifdef CONFIG_X86_LOCAL_APIC
1199 int error;
1200
1201 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1202
1203 /*
1204 * Parse MADT LAPIC entries
1205 */
1206 error = early_acpi_parse_madt_lapic_addr_ovr();
1207 if (!error) {
1208 acpi_lapic = 1;
1209 smp_found_config = 1;
1210 }
1211 if (error == -EINVAL) {
1212 /*
1213 * Dell Precision Workstation 410, 610 come here.
1214 */
1215 printk(KERN_ERR PREFIX
1216 "Invalid BIOS MADT, disabling ACPI\n");
1217 disable_acpi();
1218 }
1219 }
1220#endif
1221}
1222
Len Brown4be44fc2005-08-05 00:44:28 -04001223static void __init acpi_process_madt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224{
1225#ifdef CONFIG_X86_LOCAL_APIC
Len Brown7f8f97c2007-02-10 21:28:03 -05001226 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
Len Brown7f8f97c2007-02-10 21:28:03 -05001228 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
1230 /*
1231 * Parse MADT LAPIC entries
1232 */
1233 error = acpi_parse_madt_lapic_entries();
1234 if (!error) {
1235 acpi_lapic = 1;
1236
1237 /*
1238 * Parse MADT IO-APIC entries
1239 */
1240 error = acpi_parse_madt_ioapic_entries();
1241 if (!error) {
1242 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 acpi_ioapic = 1;
1244
1245 smp_found_config = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 }
1247 }
1248 if (error == -EINVAL) {
1249 /*
1250 * Dell Precision Workstation 410, 610 come here.
1251 */
Len Brown4be44fc2005-08-05 00:44:28 -04001252 printk(KERN_ERR PREFIX
1253 "Invalid BIOS MADT, disabling ACPI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 disable_acpi();
1255 }
Len Brown7b37b5f2008-12-23 01:47:42 -05001256 } else {
1257 /*
1258 * ACPI found no MADT, and so ACPI wants UP PIC mode.
1259 * In the event an MPS table was found, forget it.
1260 * Boot with "acpi=off" to use MPS on such a system.
1261 */
1262 if (smp_found_config) {
1263 printk(KERN_WARNING PREFIX
1264 "No APIC-table, disabling MPS\n");
1265 smp_found_config = 0;
1266 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 }
Yinghai Lu69b88af2008-12-05 22:45:50 -08001268
1269 /*
1270 * ACPI supports both logical (e.g. Hyper-Threading) and physical
1271 * processors, where MPS only supports physical.
1272 */
1273 if (acpi_lapic && acpi_ioapic)
1274 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
1275 "information\n");
1276 else if (acpi_lapic)
1277 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
1278 "configuration information\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279#endif
1280 return;
1281}
1282
Jeff Garzik18552562007-10-03 15:15:40 -04001283static int __init disable_acpi_irq(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001284{
1285 if (!acpi_force) {
1286 printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
1287 d->ident);
1288 acpi_noirq_set();
1289 }
1290 return 0;
1291}
1292
Jeff Garzik18552562007-10-03 15:15:40 -04001293static int __init disable_acpi_pci(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001294{
1295 if (!acpi_force) {
1296 printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
1297 d->ident);
1298 acpi_disable_pci();
1299 }
1300 return 0;
1301}
Andrey Paninaea00142005-06-25 14:54:42 -07001302
Jeff Garzik18552562007-10-03 15:15:40 -04001303static int __init dmi_disable_acpi(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001304{
1305 if (!acpi_force) {
Len Brown4be44fc2005-08-05 00:44:28 -04001306 printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
Andrey Paninaea00142005-06-25 14:54:42 -07001307 disable_acpi();
1308 } else {
1309 printk(KERN_NOTICE
1310 "Warning: DMI blacklist says broken, but acpi forced\n");
1311 }
1312 return 0;
1313}
1314
1315/*
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001316 * Force ignoring BIOS IRQ0 pin2 override
1317 */
1318static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
1319{
Ingo Molnar8d89adf2008-10-07 06:47:52 +02001320 /*
1321 * The ati_ixp4x0_rev() early PCI quirk should have set
1322 * the acpi_skip_timer_override flag already:
1323 */
1324 if (!acpi_skip_timer_override) {
1325 WARN(1, KERN_ERR "ati_ixp4x0 quirk not complete.\n");
1326 pr_notice("%s detected: Ignoring BIOS IRQ0 pin2 override\n",
1327 d->ident);
1328 acpi_skip_timer_override = 1;
1329 }
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001330 return 0;
1331}
1332
1333/*
Andrey Paninaea00142005-06-25 14:54:42 -07001334 * If your system is blacklisted here, but you find that acpi=force
Zhang Rui5b4c0b62009-04-01 01:49:42 -04001335 * works for you, please contact linux-acpi@vger.kernel.org
Andrey Paninaea00142005-06-25 14:54:42 -07001336 */
1337static struct dmi_system_id __initdata acpi_dmi_table[] = {
1338 /*
1339 * Boxes that need ACPI disabled
1340 */
1341 {
Len Brown4be44fc2005-08-05 00:44:28 -04001342 .callback = dmi_disable_acpi,
1343 .ident = "IBM Thinkpad",
1344 .matches = {
1345 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1346 DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
1347 },
1348 },
Andrey Paninaea00142005-06-25 14:54:42 -07001349
1350 /*
Andrey Paninaea00142005-06-25 14:54:42 -07001351 * Boxes that need ACPI PCI IRQ routing disabled
1352 */
1353 {
Len Brown4be44fc2005-08-05 00:44:28 -04001354 .callback = disable_acpi_irq,
1355 .ident = "ASUS A7V",
1356 .matches = {
1357 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
1358 DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
1359 /* newer BIOS, Revision 1011, does work */
1360 DMI_MATCH(DMI_BIOS_VERSION,
1361 "ASUS A7V ACPI BIOS Revision 1007"),
1362 },
1363 },
Len Brown74586fc2007-03-08 02:48:30 -05001364 {
1365 /*
1366 * Latest BIOS for IBM 600E (1.16) has bad pcinum
1367 * for LPC bridge, which is needed for the PCI
1368 * interrupt links to work. DSDT fix is in bug 5966.
1369 * 2645, 2646 model numbers are shared with 600/600E/600X
1370 */
1371 .callback = disable_acpi_irq,
1372 .ident = "IBM Thinkpad 600 Series 2645",
1373 .matches = {
1374 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1375 DMI_MATCH(DMI_BOARD_NAME, "2645"),
1376 },
1377 },
1378 {
1379 .callback = disable_acpi_irq,
1380 .ident = "IBM Thinkpad 600 Series 2646",
1381 .matches = {
1382 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1383 DMI_MATCH(DMI_BOARD_NAME, "2646"),
1384 },
1385 },
Andrey Paninaea00142005-06-25 14:54:42 -07001386 /*
1387 * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
1388 */
Len Brown4be44fc2005-08-05 00:44:28 -04001389 { /* _BBN 0 bug */
1390 .callback = disable_acpi_pci,
1391 .ident = "ASUS PR-DLS",
1392 .matches = {
1393 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1394 DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
1395 DMI_MATCH(DMI_BIOS_VERSION,
1396 "ASUS PR-DLS ACPI BIOS Revision 1010"),
1397 DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
1398 },
1399 },
Andrey Paninaea00142005-06-25 14:54:42 -07001400 {
Len Brown4be44fc2005-08-05 00:44:28 -04001401 .callback = disable_acpi_pci,
1402 .ident = "Acer TravelMate 36x Laptop",
1403 .matches = {
1404 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
1405 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
1406 },
1407 },
Andreas Herrmann35af2822008-10-22 13:08:31 +02001408 {}
1409};
1410
1411/* second table for DMI checks that should run after early-quirks */
1412static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
Matthew Garrett9340e1c2008-07-01 01:12:06 +01001413 /*
1414 * HP laptops which use a DSDT reporting as HP/SB400/10000,
1415 * which includes some code which overrides all temperature
1416 * trip points to 16C if the INTIN2 input of the I/O APIC
1417 * is enabled. This input is incorrectly designated the
1418 * ISA IRQ 0 via an interrupt source override even though
1419 * it is wired to the output of the master 8259A and INTIN0
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001420 * is not connected at all. Force ignoring BIOS IRQ0 pin2
1421 * override in that cases.
1422 */
1423 {
1424 .callback = dmi_ignore_irq0_timer_override,
Rafael J. Wysockie84956f2008-10-06 11:59:29 +02001425 .ident = "HP nx6115 laptop",
1426 .matches = {
1427 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1428 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6115"),
1429 },
1430 },
1431 {
1432 .callback = dmi_ignore_irq0_timer_override,
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001433 .ident = "HP NX6125 laptop",
1434 .matches = {
1435 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1436 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
1437 },
1438 },
1439 {
1440 .callback = dmi_ignore_irq0_timer_override,
1441 .ident = "HP NX6325 laptop",
1442 .matches = {
1443 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1444 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
1445 },
1446 },
Rafael J. Wysockie84956f2008-10-06 11:59:29 +02001447 {
1448 .callback = dmi_ignore_irq0_timer_override,
1449 .ident = "HP 6715b laptop",
1450 .matches = {
1451 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1452 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
1453 },
1454 },
Len Brown4be44fc2005-08-05 00:44:28 -04001455 {}
Andrey Paninaea00142005-06-25 14:54:42 -07001456};
1457
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458/*
1459 * acpi_boot_table_init() and acpi_boot_init()
1460 * called from setup_arch(), always.
1461 * 1. checksums all tables
1462 * 2. enumerates lapics
1463 * 3. enumerates io-apics
1464 *
1465 * acpi_table_init() is separate to allow reading SRAT without
1466 * other side effects.
1467 *
1468 * side effects of acpi_boot_init:
1469 * acpi_lapic = 1 if LAPIC found
1470 * acpi_ioapic = 1 if IOAPIC found
1471 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
1472 * if acpi_blacklisted() acpi_disabled = 1;
1473 * acpi_irq_model=...
1474 * ...
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 */
1476
Len Brown8558e392010-01-06 16:11:06 -05001477void __init acpi_boot_table_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478{
Andrey Paninaea00142005-06-25 14:54:42 -07001479 dmi_check_system(acpi_dmi_table);
Andrey Paninaea00142005-06-25 14:54:42 -07001480
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 /*
1482 * If acpi_disabled, bail out
1483 * One exception: acpi=ht continues far enough to enumerate LAPICs
1484 */
1485 if (acpi_disabled && !acpi_ht)
Len Brown8558e392010-01-06 16:11:06 -05001486 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001488 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 * Initialize the ACPI boot-time table parser.
1490 */
Len Brown8558e392010-01-06 16:11:06 -05001491 if (acpi_table_init()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 disable_acpi();
Len Brown8558e392010-01-06 16:11:06 -05001493 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001496 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
1498 /*
1499 * blacklist may disable ACPI entirely
1500 */
Len Brown8558e392010-01-06 16:11:06 -05001501 if (acpi_blacklisted()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 if (acpi_force) {
1503 printk(KERN_WARNING PREFIX "acpi=force override\n");
1504 } else {
1505 printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
1506 disable_acpi();
Len Brown8558e392010-01-06 16:11:06 -05001507 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 }
1509 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510}
1511
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001512int __init early_acpi_boot_init(void)
1513{
1514 /*
1515 * If acpi_disabled, bail out
1516 * One exception: acpi=ht continues far enough to enumerate LAPICs
1517 */
1518 if (acpi_disabled && !acpi_ht)
1519 return 1;
1520
1521 /*
1522 * Process the Multiple APIC Description Table (MADT), if present
1523 */
1524 early_acpi_process_madt();
1525
1526 return 0;
1527}
1528
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529int __init acpi_boot_init(void)
1530{
Andreas Herrmann35af2822008-10-22 13:08:31 +02001531 /* those are executed after early-quirks are executed */
1532 dmi_check_system(acpi_dmi_table_late);
1533
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 /*
1535 * If acpi_disabled, bail out
1536 * One exception: acpi=ht continues far enough to enumerate LAPICs
1537 */
1538 if (acpi_disabled && !acpi_ht)
Len Brown4be44fc2005-08-05 00:44:28 -04001539 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001541 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
1543 /*
1544 * set sci_int and PM timer address
1545 */
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +03001546 acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
1548 /*
1549 * Process the Multiple APIC Description Table (MADT), if present
1550 */
1551 acpi_process_madt();
1552
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001553 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
Thomas Gleixnerb72d0db2009-08-29 16:24:51 +02001555 if (!acpi_noirq)
1556 x86_init.pci.init = pci_acpi_init;
1557
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 return 0;
1559}
Rusty Russell1a3f2392006-09-26 10:52:32 +02001560
1561static int __init parse_acpi(char *arg)
1562{
1563 if (!arg)
1564 return -EINVAL;
1565
1566 /* "acpi=off" disables both ACPI table parsing and interpreter */
1567 if (strcmp(arg, "off") == 0) {
1568 disable_acpi();
1569 }
1570 /* acpi=force to over-ride black-list */
1571 else if (strcmp(arg, "force") == 0) {
1572 acpi_force = 1;
1573 acpi_ht = 1;
1574 acpi_disabled = 0;
1575 }
1576 /* acpi=strict disables out-of-spec workarounds */
1577 else if (strcmp(arg, "strict") == 0) {
1578 acpi_strict = 1;
1579 }
1580 /* Limit ACPI just to boot-time to enable HT */
1581 else if (strcmp(arg, "ht") == 0) {
Len Brown4c81ba42010-03-14 16:28:46 -04001582 if (!acpi_force) {
1583 printk(KERN_WARNING "acpi=ht will be removed in Linux-2.6.35\n");
Rusty Russell1a3f2392006-09-26 10:52:32 +02001584 disable_acpi();
Len Brown4c81ba42010-03-14 16:28:46 -04001585 }
Rusty Russell1a3f2392006-09-26 10:52:32 +02001586 acpi_ht = 1;
1587 }
Zhao Yakui237889b2008-12-17 16:55:18 +08001588 /* acpi=rsdt use RSDT instead of XSDT */
1589 else if (strcmp(arg, "rsdt") == 0) {
1590 acpi_rsdt_forced = 1;
1591 }
Rusty Russell1a3f2392006-09-26 10:52:32 +02001592 /* "acpi=noirq" disables ACPI interrupt routing */
1593 else if (strcmp(arg, "noirq") == 0) {
1594 acpi_noirq_set();
1595 } else {
1596 /* Core will printk when we return error. */
1597 return -EINVAL;
1598 }
1599 return 0;
1600}
1601early_param("acpi", parse_acpi);
1602
1603/* FIXME: Using pci= for an ACPI parameter is a travesty. */
1604static int __init parse_pci(char *arg)
1605{
1606 if (arg && strcmp(arg, "noacpi") == 0)
1607 acpi_disable_pci();
1608 return 0;
1609}
1610early_param("pci", parse_pci);
1611
Yinghai Lu3c999f12008-06-20 16:11:20 -07001612int __init acpi_mps_check(void)
1613{
1614#if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
1615/* mptable code is not built-in*/
1616 if (acpi_disabled || acpi_noirq) {
1617 printk(KERN_WARNING "MPS support code is not built-in.\n"
1618 "Using acpi=off or acpi=noirq or pci=noacpi "
1619 "may have problem\n");
1620 return 1;
1621 }
1622#endif
1623 return 0;
1624}
1625
Rusty Russell1a3f2392006-09-26 10:52:32 +02001626#ifdef CONFIG_X86_IO_APIC
1627static int __init parse_acpi_skip_timer_override(char *arg)
1628{
1629 acpi_skip_timer_override = 1;
1630 return 0;
1631}
1632early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
Andi Kleenfa18f472006-11-14 16:57:46 +01001633
1634static int __init parse_acpi_use_timer_override(char *arg)
1635{
1636 acpi_use_timer_override = 1;
1637 return 0;
1638}
1639early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001640#endif /* CONFIG_X86_IO_APIC */
1641
1642static int __init setup_acpi_sci(char *s)
1643{
1644 if (!s)
1645 return -EINVAL;
1646 if (!strcmp(s, "edge"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001647 acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
1648 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001649 else if (!strcmp(s, "level"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001650 acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
1651 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001652 else if (!strcmp(s, "high"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001653 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
1654 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001655 else if (!strcmp(s, "low"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001656 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
1657 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001658 else
1659 return -EINVAL;
1660 return 0;
1661}
1662early_param("acpi_sci", setup_acpi_sci);
Andrew Mortond0a90812006-10-20 14:30:27 -07001663
1664int __acpi_acquire_global_lock(unsigned int *lock)
1665{
1666 unsigned int old, new, val;
1667 do {
1668 old = *lock;
1669 new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
1670 val = cmpxchg(lock, old, new);
1671 } while (unlikely (val != old));
1672 return (new < 3) ? -1 : 0;
1673}
1674
1675int __acpi_release_global_lock(unsigned int *lock)
1676{
1677 unsigned int old, new, val;
1678 do {
1679 old = *lock;
1680 new = old & ~0x3;
1681 val = cmpxchg(lock, old, new);
1682 } while (unlikely (val != old));
1683 return old & 0x1;
1684}