blob: 314fe0dddef42afa1df22b4e6108457c2c926d63 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * boot.c - Architecture-Specific Low-Level ACPI Boot Support
3 *
4 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
5 * Copyright (C) 2001 Jun Nakajima <jun.nakajima@intel.com>
6 *
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 */
25
26#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/acpi.h>
Thomas Gleixnerd66bea52007-02-16 01:27:57 -080028#include <linux/acpi_pmtmr.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/efi.h>
Ashok Raj73fea172006-09-26 10:52:35 +020030#include <linux/cpumask.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/module.h>
Andrey Paninaea00142005-06-25 14:54:42 -070032#include <linux/dmi.h>
Nick Pigginb33fa1f2005-10-01 02:34:42 +100033#include <linux/irq.h>
adurbin@google.comf0f4c342006-09-26 10:52:39 +020034#include <linux/bootmem.h>
35#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#include <asm/pgtable.h>
38#include <asm/io_apic.h>
39#include <asm/apic.h>
Ingo Molnar183fe062008-07-09 11:32:10 +020040#include <asm/genapic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/mpspec.h>
Alexey Starikovskiydfac2182008-04-04 23:41:50 +040043#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Glauber de Oliveira Costaf6bc4022008-03-19 14:25:53 -030045#ifdef CONFIG_X86_LOCAL_APIC
46# include <mach_apic.h>
47#endif
48
Adrian Bunke8924ac2006-09-26 10:52:35 +020049static int __initdata acpi_force = 0;
Zhao Yakui237889b2008-12-17 16:55:18 +080050u32 acpi_rsdt_forced;
Andi Kleendf3bb572006-09-26 10:52:33 +020051#ifdef CONFIG_ACPI
52int acpi_disabled = 0;
53#else
54int acpi_disabled = 1;
55#endif
56EXPORT_SYMBOL(acpi_disabled);
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#ifdef CONFIG_X86_64
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#include <asm/proto.h>
Linus Torvalds637029c2006-02-27 20:41:56 -080061
Len Brown4be44fc2005-08-05 00:44:28 -040062#else /* X86 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64#ifdef CONFIG_X86_LOCAL_APIC
65#include <mach_apic.h>
66#include <mach_mpparse.h>
Len Brown4be44fc2005-08-05 00:44:28 -040067#endif /* CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Len Brown4be44fc2005-08-05 00:44:28 -040069#endif /* X86 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71#define BAD_MADT_ENTRY(entry, end) ( \
72 (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +030073 ((struct acpi_subtable_header *)entry)->length < sizeof(*entry))
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75#define PREFIX "ACPI: "
76
Andrew Morton90d53902006-11-02 22:07:18 -080077int acpi_noirq; /* skip ACPI IRQ initialization */
Yinghai Lu6e4be1ff2008-02-05 00:01:48 -080078int acpi_pci_disabled; /* skip ACPI PCI scan and IRQ initialization */
79EXPORT_SYMBOL(acpi_pci_disabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080int acpi_ht __initdata = 1; /* enable HT */
81
82int acpi_lapic;
83int acpi_ioapic;
84int acpi_strict;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +030086u8 acpi_sci_flags __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087int acpi_sci_override_gsi __initdata;
88int acpi_skip_timer_override __initdata;
Andi Kleenfa18f472006-11-14 16:57:46 +010089int acpi_use_timer_override __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91#ifdef CONFIG_X86_LOCAL_APIC
92static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
93#endif
94
95#ifndef __HAVE_ARCH_CMPXCHG
96#warning ACPI uses CMPXCHG, i486 and later hardware
97#endif
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/* --------------------------------------------------------------------------
100 Boot-time Configuration
101 -------------------------------------------------------------------------- */
102
103/*
104 * The default interrupt routing model is PIC (8259). This gets
Simon Arlott27b46d72007-10-20 01:13:56 +0200105 * overridden if IOAPICs are enumerated (below).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 */
Len Brown4be44fc2005-08-05 00:44:28 -0400107enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110/*
111 * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
112 * to map the target physical address. The problem is that set_fixmap()
113 * provides a single page, and it is possible that the page is not
114 * sufficient.
115 * By using this area, we can map up to MAX_IO_APICS pages temporarily,
116 * i.e. until the next __va_range() call.
117 *
118 * Important Safety Note: The fixed I/O APIC page numbers are *subtracted*
119 * from the fixed base. That's why we start at FIX_IO_APIC_BASE_END and
120 * count idx down while incrementing the phys address.
121 */
Jan Beulich2fdf0742007-12-13 08:33:59 +0000122char *__init __acpi_map_table(unsigned long phys, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
124 unsigned long base, offset, mapped_size;
125 int idx;
126
Yinghai Luf34fa822008-07-09 20:16:36 -0700127 if (!phys || !size)
128 return NULL;
129
Yinghai Luf361a452008-07-10 20:38:26 -0700130 if (phys+size <= (max_low_pfn_mapped << PAGE_SHIFT))
Len Brown4be44fc2005-08-05 00:44:28 -0400131 return __va(phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 offset = phys & (PAGE_SIZE - 1);
134 mapped_size = PAGE_SIZE - offset;
Yinghai Luf34fa822008-07-09 20:16:36 -0700135 clear_fixmap(FIX_ACPI_END);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 set_fixmap(FIX_ACPI_END, phys);
137 base = fix_to_virt(FIX_ACPI_END);
138
139 /*
140 * Most cases can be covered by the below.
141 */
142 idx = FIX_ACPI_END;
143 while (mapped_size < size) {
144 if (--idx < FIX_ACPI_BEGIN)
145 return NULL; /* cannot handle this */
146 phys += PAGE_SIZE;
Yinghai Luf34fa822008-07-09 20:16:36 -0700147 clear_fixmap(idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 set_fixmap(idx, phys);
149 mapped_size += PAGE_SIZE;
150 }
151
Len Brown4be44fc2005-08-05 00:44:28 -0400152 return ((unsigned char *)base + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155#ifdef CONFIG_PCI_MMCONFIG
Pavel Vasilyev1339c362008-10-15 17:33:48 -0400156
157static int acpi_mcfg_64bit_base_addr __initdata = FALSE;
158
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700159/* The physical address of the MMCONFIG aperture. Set from ACPI tables. */
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300160struct acpi_mcfg_allocation *pci_mmcfg_config;
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700161int pci_mmcfg_config_num;
162
John Kellera726c602008-07-29 14:34:16 -0500163static int __init acpi_mcfg_oem_check(struct acpi_table_mcfg *mcfg)
164{
165 if (!strcmp(mcfg->header.oem_id, "SGI"))
166 acpi_mcfg_64bit_base_addr = TRUE;
167
168 return 0;
169}
170
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300171int __init acpi_parse_mcfg(struct acpi_table_header *header)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172{
173 struct acpi_table_mcfg *mcfg;
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700174 unsigned long i;
175 int config_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300177 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 return -EINVAL;
179
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300180 mcfg = (struct acpi_table_mcfg *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700182 /* how many config structures do we have */
183 pci_mmcfg_config_num = 0;
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300184 i = header->length - sizeof(struct acpi_table_mcfg);
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300185 while (i >= sizeof(struct acpi_mcfg_allocation)) {
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700186 ++pci_mmcfg_config_num;
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300187 i -= sizeof(struct acpi_mcfg_allocation);
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700188 };
189 if (pci_mmcfg_config_num == 0) {
190 printk(KERN_ERR PREFIX "MMCONFIG has no entries\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 return -ENODEV;
192 }
193
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700194 config_size = pci_mmcfg_config_num * sizeof(*pci_mmcfg_config);
195 pci_mmcfg_config = kmalloc(config_size, GFP_KERNEL);
196 if (!pci_mmcfg_config) {
197 printk(KERN_WARNING PREFIX
198 "No memory for MCFG config tables\n");
199 return -ENOMEM;
200 }
201
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300202 memcpy(pci_mmcfg_config, &mcfg[1], config_size);
John Kellera726c602008-07-29 14:34:16 -0500203
204 acpi_mcfg_oem_check(mcfg);
205
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700206 for (i = 0; i < pci_mmcfg_config_num; ++i) {
John Kellera726c602008-07-29 14:34:16 -0500207 if ((pci_mmcfg_config[i].address > 0xFFFFFFFF) &&
208 !acpi_mcfg_64bit_base_addr) {
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700209 printk(KERN_ERR PREFIX
210 "MMCONFIG not in low 4GB of memory\n");
Konrad Rzeszutekacc7c2e2006-06-15 12:08:30 -0400211 kfree(pci_mmcfg_config);
212 pci_mmcfg_config_num = 0;
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700213 return -ENODEV;
214 }
215 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 return 0;
218}
Len Brown4be44fc2005-08-05 00:44:28 -0400219#endif /* CONFIG_PCI_MMCONFIG */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221#ifdef CONFIG_X86_LOCAL_APIC
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300222static int __init acpi_parse_madt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
Len Brown4be44fc2005-08-05 00:44:28 -0400224 struct acpi_table_madt *madt = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300226 if (!cpu_has_apic)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 return -EINVAL;
228
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300229 madt = (struct acpi_table_madt *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 if (!madt) {
231 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
232 return -ENODEV;
233 }
234
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300235 if (madt->address) {
236 acpi_lapic_addr = (u64) madt->address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
238 printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300239 madt->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 }
241
Ingo Molnar306db032009-01-28 03:43:47 +0100242 default_acpi_madt_oem_check(madt->header.oem_id,
243 madt->header.oem_table_id);
Len Brown4be44fc2005-08-05 00:44:28 -0400244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 return 0;
246}
247
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400248static void __cpuinit acpi_register_lapic(int id, u8 enabled)
249{
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700250 unsigned int ver = 0;
251
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400252 if (!enabled) {
253 ++disabled_cpus;
254 return;
255 }
256
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700257 if (boot_cpu_physical_apicid != -1U)
258 ver = apic_version[boot_cpu_physical_apicid];
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700259
260 generic_processor_info(id, ver);
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400261}
262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300264acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300266 struct acpi_madt_local_apic *processor = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300268 processor = (struct acpi_madt_local_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 if (BAD_MADT_ENTRY(processor, end))
271 return -EINVAL;
272
273 acpi_table_print_madt_entry(header);
274
Ashok Raj7f66ae42006-02-03 21:51:50 +0100275 /*
276 * We need to register disabled CPU as well to permit
277 * counting disabled CPUs. This allows us to size
278 * cpus_possible_map more accurately, to permit
279 * to not preallocating memory for all NR_CPUS
280 * when we use CPU hotplug.
281 */
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400282 acpi_register_lapic(processor->id, /* APIC ID */
283 processor->lapic_flags & ACPI_MADT_ENABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285 return 0;
286}
287
288static int __init
Jack Steinerac049c12008-03-28 14:12:09 -0500289acpi_parse_sapic(struct acpi_subtable_header *header, const unsigned long end)
290{
291 struct acpi_madt_local_sapic *processor = NULL;
292
293 processor = (struct acpi_madt_local_sapic *)header;
294
295 if (BAD_MADT_ENTRY(processor, end))
296 return -EINVAL;
297
298 acpi_table_print_madt_entry(header);
299
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400300 acpi_register_lapic((processor->id << 8) | processor->eid,/* APIC ID */
301 processor->lapic_flags & ACPI_MADT_ENABLED);
Jack Steinerac049c12008-03-28 14:12:09 -0500302
303 return 0;
304}
305
306static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300307acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400308 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300310 struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300312 lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
314 if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
315 return -EINVAL;
316
317 acpi_lapic_addr = lapic_addr_ovr->address;
318
319 return 0;
320}
321
322static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300323acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300325 struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300327 lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 if (BAD_MADT_ENTRY(lapic_nmi, end))
330 return -EINVAL;
331
332 acpi_table_print_madt_entry(header);
333
334 if (lapic_nmi->lint != 1)
335 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
336
337 return 0;
338}
339
Len Brown4be44fc2005-08-05 00:44:28 -0400340#endif /*CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Len Brown84663612005-08-24 12:09:07 -0400342#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
344static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300345acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300347 struct acpi_madt_io_apic *ioapic = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300349 ioapic = (struct acpi_madt_io_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
351 if (BAD_MADT_ENTRY(ioapic, end))
352 return -EINVAL;
Len Brown4be44fc2005-08-05 00:44:28 -0400353
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 acpi_table_print_madt_entry(header);
355
Len Brown4be44fc2005-08-05 00:44:28 -0400356 mp_register_ioapic(ioapic->id,
357 ioapic->address, ioapic->global_irq_base);
358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 return 0;
360}
361
362/*
363 * Parse Interrupt Source Override for the ACPI SCI
364 */
Len Browne82c3542006-12-21 01:29:59 -0500365static void __init acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
367 if (trigger == 0) /* compatible SCI trigger is level */
368 trigger = 3;
369
370 if (polarity == 0) /* compatible SCI polarity is low */
371 polarity = 3;
372
373 /* Command-line over-ride via acpi_sci= */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300374 if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
375 trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300377 if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
378 polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
380 /*
Len Brown4be44fc2005-08-05 00:44:28 -0400381 * mp_config_acpi_legacy_irqs() already setup IRQs < 16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 * If GSI is < 16, this will update its flags,
383 * else it will create a new mp_irqs[] entry.
384 */
Len Brown7bdd21c2006-12-02 02:27:46 -0500385 mp_override_legacy_irq(gsi, polarity, trigger, gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
387 /*
388 * stash over-ride to indicate we've been here
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300389 * and for later update of acpi_gbl_FADT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 */
Len Brown7bdd21c2006-12-02 02:27:46 -0500391 acpi_sci_override_gsi = gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 return;
393}
394
395static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300396acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400397 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300399 struct acpi_madt_interrupt_override *intsrc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300401 intsrc = (struct acpi_madt_interrupt_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
403 if (BAD_MADT_ENTRY(intsrc, end))
404 return -EINVAL;
405
406 acpi_table_print_madt_entry(header);
407
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300408 if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
Len Brown7bdd21c2006-12-02 02:27:46 -0500409 acpi_sci_ioapic_setup(intsrc->global_irq,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300410 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
411 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 return 0;
413 }
414
415 if (acpi_skip_timer_override &&
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300416 intsrc->source_irq == 0 && intsrc->global_irq == 2) {
Len Brown4be44fc2005-08-05 00:44:28 -0400417 printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
418 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 }
420
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300421 mp_override_legacy_irq(intsrc->source_irq,
422 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
423 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
424 intsrc->global_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426 return 0;
427}
428
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300430acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300432 struct acpi_madt_nmi_source *nmi_src = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300434 nmi_src = (struct acpi_madt_nmi_source *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
436 if (BAD_MADT_ENTRY(nmi_src, end))
437 return -EINVAL;
438
439 acpi_table_print_madt_entry(header);
440
441 /* TBD: Support nimsrc entries? */
442
443 return 0;
444}
445
Len Brown4be44fc2005-08-05 00:44:28 -0400446#endif /* CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448/*
449 * acpi_pic_sci_set_trigger()
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300450 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 * use ELCR to set PIC-mode trigger type for SCI
452 *
453 * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
454 * it may require Edge Trigger -- use "acpi_sci=edge"
455 *
456 * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
457 * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
Simon Arlott27b46d72007-10-20 01:13:56 +0200458 * ECLR1 is IRQs 0-7 (IRQ 0, 1, 2 must be 0)
459 * ECLR2 is IRQs 8-15 (IRQ 8, 13 must be 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 */
461
Len Brown4be44fc2005-08-05 00:44:28 -0400462void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463{
464 unsigned int mask = 1 << irq;
465 unsigned int old, new;
466
467 /* Real old ELCR mask */
468 old = inb(0x4d0) | (inb(0x4d1) << 8);
469
470 /*
Simon Arlott27b46d72007-10-20 01:13:56 +0200471 * If we use ACPI to set PCI IRQs, then we should clear ELCR
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 * since we will set it correctly as we enable the PCI irq
473 * routing.
474 */
475 new = acpi_noirq ? old : 0;
476
477 /*
478 * Update SCI information in the ELCR, it isn't in the PCI
479 * routing tables..
480 */
481 switch (trigger) {
Len Brown4be44fc2005-08-05 00:44:28 -0400482 case 1: /* Edge - clear */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 new &= ~mask;
484 break;
Len Brown4be44fc2005-08-05 00:44:28 -0400485 case 3: /* Level - set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 new |= mask;
487 break;
488 }
489
490 if (old == new)
491 return;
492
493 printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
494 outb(new, 0x4d0);
495 outb(new >> 8, 0x4d1);
496}
497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
499{
Eric W. Biedermanf023d762006-10-04 02:16:52 -0700500 *irq = gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 return 0;
502}
503
Kenji Kaneshige1f3a6a12005-07-28 14:42:00 -0400504/*
505 * success: return IRQ number (>=0)
506 * failure: return < 0
507 */
Len Browncb654692005-12-28 02:43:51 -0500508int acpi_register_gsi(u32 gsi, int triggering, int polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509{
510 unsigned int irq;
511 unsigned int plat_gsi = gsi;
512
513#ifdef CONFIG_PCI
514 /*
515 * Make sure all (legacy) PCI IRQs are set as level-triggered.
516 */
517 if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
Len Browncb654692005-12-28 02:43:51 -0500518 if (triggering == ACPI_LEVEL_SENSITIVE)
Len Brown4be44fc2005-08-05 00:44:28 -0400519 eisa_set_level_irq(gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 }
521#endif
522
523#ifdef CONFIG_X86_IO_APIC
524 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) {
Len Browncb654692005-12-28 02:43:51 -0500525 plat_gsi = mp_register_gsi(gsi, triggering, polarity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 }
527#endif
528 acpi_gsi_to_irq(plat_gsi, &irq);
529 return irq;
530}
Len Brown4be44fc2005-08-05 00:44:28 -0400531
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532/*
533 * ACPI based hotplug support for CPU
534 */
535#ifdef CONFIG_ACPI_HOTPLUG_CPU
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100536
537static int __cpuinit _acpi_map_lsapic(acpi_handle handle, int *pcpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538{
Ashok Raj73fea172006-09-26 10:52:35 +0200539 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
540 union acpi_object *obj;
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300541 struct acpi_madt_local_apic *lapic;
Rusty Russellee943a82008-12-31 18:08:47 -0800542 cpumask_var_t tmp_map, new_map;
Ashok Raj73fea172006-09-26 10:52:35 +0200543 u8 physid;
544 int cpu;
Rusty Russellee943a82008-12-31 18:08:47 -0800545 int retval = -ENOMEM;
Ashok Raj73fea172006-09-26 10:52:35 +0200546
547 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
548 return -EINVAL;
549
550 if (!buffer.length || !buffer.pointer)
551 return -EINVAL;
552
553 obj = buffer.pointer;
554 if (obj->type != ACPI_TYPE_BUFFER ||
555 obj->buffer.length < sizeof(*lapic)) {
556 kfree(buffer.pointer);
557 return -EINVAL;
558 }
559
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300560 lapic = (struct acpi_madt_local_apic *)obj->buffer.pointer;
Ashok Raj73fea172006-09-26 10:52:35 +0200561
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300562 if (lapic->header.type != ACPI_MADT_TYPE_LOCAL_APIC ||
563 !(lapic->lapic_flags & ACPI_MADT_ENABLED)) {
Ashok Raj73fea172006-09-26 10:52:35 +0200564 kfree(buffer.pointer);
565 return -EINVAL;
566 }
567
568 physid = lapic->id;
569
570 kfree(buffer.pointer);
571 buffer.length = ACPI_ALLOCATE_BUFFER;
572 buffer.pointer = NULL;
573
Rusty Russellee943a82008-12-31 18:08:47 -0800574 if (!alloc_cpumask_var(&tmp_map, GFP_KERNEL))
575 goto out;
576
577 if (!alloc_cpumask_var(&new_map, GFP_KERNEL))
578 goto free_tmp_map;
579
580 cpumask_copy(tmp_map, cpu_present_mask);
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400581 acpi_register_lapic(physid, lapic->lapic_flags & ACPI_MADT_ENABLED);
Ashok Raj73fea172006-09-26 10:52:35 +0200582
583 /*
584 * If mp_register_lapic successfully generates a new logical cpu
585 * number, then the following will get us exactly what was mapped
586 */
Rusty Russellee943a82008-12-31 18:08:47 -0800587 cpumask_andnot(new_map, cpu_present_mask, tmp_map);
588 if (cpumask_empty(new_map)) {
Ashok Raj73fea172006-09-26 10:52:35 +0200589 printk ("Unable to map lapic to logical cpu number\n");
Rusty Russellee943a82008-12-31 18:08:47 -0800590 retval = -EINVAL;
591 goto free_new_map;
Ashok Raj73fea172006-09-26 10:52:35 +0200592 }
593
Rusty Russellee943a82008-12-31 18:08:47 -0800594 cpu = cpumask_first(new_map);
Ashok Raj73fea172006-09-26 10:52:35 +0200595
596 *pcpu = cpu;
Rusty Russellee943a82008-12-31 18:08:47 -0800597 retval = 0;
598
599free_new_map:
600 free_cpumask_var(new_map);
601free_tmp_map:
602 free_cpumask_var(tmp_map);
603out:
604 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605}
Len Brown4be44fc2005-08-05 00:44:28 -0400606
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100607/* wrapper to silence section mismatch warning */
608int __ref acpi_map_lsapic(acpi_handle handle, int *pcpu)
609{
610 return _acpi_map_lsapic(handle, pcpu);
611}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612EXPORT_SYMBOL(acpi_map_lsapic);
613
Len Brown4be44fc2005-08-05 00:44:28 -0400614int acpi_unmap_lsapic(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615{
Mike Travis71fff5e2007-10-19 20:35:03 +0200616 per_cpu(x86_cpu_to_apicid, cpu) = -1;
Mike Travis96289372008-12-31 18:08:46 -0800617 set_cpu_present(cpu, false);
Ashok Raj73fea172006-09-26 10:52:35 +0200618 num_processors--;
619
620 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621}
Len Brown4be44fc2005-08-05 00:44:28 -0400622
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623EXPORT_SYMBOL(acpi_unmap_lsapic);
Len Brown4be44fc2005-08-05 00:44:28 -0400624#endif /* CONFIG_ACPI_HOTPLUG_CPU */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Len Brown4be44fc2005-08-05 00:44:28 -0400626int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700627{
628 /* TBD */
629 return -EINVAL;
630}
Len Brown4be44fc2005-08-05 00:44:28 -0400631
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700632EXPORT_SYMBOL(acpi_register_ioapic);
633
Len Brown4be44fc2005-08-05 00:44:28 -0400634int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700635{
636 /* TBD */
637 return -EINVAL;
638}
Len Brown4be44fc2005-08-05 00:44:28 -0400639
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700640EXPORT_SYMBOL(acpi_unregister_ioapic);
641
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300642static int __init acpi_parse_sbf(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300644 struct acpi_table_boot *sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300646 sb = (struct acpi_table_boot *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 if (!sb) {
648 printk(KERN_WARNING PREFIX "Unable to map SBF\n");
649 return -ENODEV;
650 }
651
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300652 sbf_port = sb->cmos_index; /* Save CMOS port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
654 return 0;
655}
656
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657#ifdef CONFIG_HPET_TIMER
john stultz2d0c87c2007-02-16 01:28:18 -0800658#include <asm/hpet.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Aaron Durbina1dfd852007-07-21 17:11:39 +0200660static struct __initdata resource *hpet_res;
661
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300662static int __init acpi_parse_hpet(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663{
664 struct acpi_table_hpet *hpet_tbl;
665
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300666 hpet_tbl = (struct acpi_table_hpet *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 if (!hpet_tbl) {
668 printk(KERN_WARNING PREFIX "Unable to map HPET\n");
669 return -ENODEV;
670 }
671
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300672 if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 printk(KERN_WARNING PREFIX "HPET timers must be located in "
674 "memory.\n");
675 return -1;
676 }
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200677
john stultz2d0c87c2007-02-16 01:28:18 -0800678 hpet_address = hpet_tbl->address.address;
Thomas Gleixnerf4df73c2007-11-15 21:41:50 -0500679
680 /*
681 * Some broken BIOSes advertise HPET at 0x0. We really do not
682 * want to allocate a resource there.
683 */
684 if (!hpet_address) {
685 printk(KERN_WARNING PREFIX
686 "HPET id: %#x base: %#lx is invalid\n",
687 hpet_tbl->id, hpet_address);
688 return 0;
689 }
690#ifdef CONFIG_X86_64
691 /*
692 * Some even more broken BIOSes advertise HPET at
693 * 0xfed0000000000000 instead of 0xfed00000. Fix it up and add
694 * some noise:
695 */
696 if (hpet_address == 0xfed0000000000000UL) {
697 if (!hpet_force_user) {
698 printk(KERN_WARNING PREFIX "HPET id: %#x "
699 "base: 0xfed0000000000000 is bogus\n "
700 "try hpet=force on the kernel command line to "
701 "fix it up to 0xfed00000.\n", hpet_tbl->id);
702 hpet_address = 0;
703 return 0;
704 }
705 printk(KERN_WARNING PREFIX
706 "HPET id: %#x base: 0xfed0000000000000 fixed up "
707 "to 0xfed00000.\n", hpet_tbl->id);
708 hpet_address >>= 32;
709 }
710#endif
Len Brown4be44fc2005-08-05 00:44:28 -0400711 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
john stultz2d0c87c2007-02-16 01:28:18 -0800712 hpet_tbl->id, hpet_address);
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200713
Aaron Durbina1dfd852007-07-21 17:11:39 +0200714 /*
715 * Allocate and initialize the HPET firmware resource for adding into
716 * the resource tree during the lateinit timeframe.
717 */
718#define HPET_RESOURCE_NAME_SIZE 9
719 hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
720
Aaron Durbina1dfd852007-07-21 17:11:39 +0200721 hpet_res->name = (void *)&hpet_res[1];
722 hpet_res->flags = IORESOURCE_MEM;
723 snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE, "HPET %u",
724 hpet_tbl->sequence);
725
726 hpet_res->start = hpet_address;
727 hpet_res->end = hpet_address + (1 * 1024) - 1;
728
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 return 0;
730}
Aaron Durbina1dfd852007-07-21 17:11:39 +0200731
732/*
733 * hpet_insert_resource inserts the HPET resources used into the resource
734 * tree.
735 */
736static __init int hpet_insert_resource(void)
737{
738 if (!hpet_res)
739 return 1;
740
741 return insert_resource(&iomem_resource, hpet_res);
742}
743
744late_initcall(hpet_insert_resource);
745
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746#else
747#define acpi_parse_hpet NULL
748#endif
749
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300750static int __init acpi_parse_fadt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751{
Jason Davis90660ec2005-04-16 15:24:53 -0700752
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753#ifdef CONFIG_X86_PM_TIMER
754 /* detect the location of the ACPI PM Timer */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300755 if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 /* FADT rev. 2 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300757 if (acpi_gbl_FADT.xpm_timer_block.space_id !=
Len Brown4be44fc2005-08-05 00:44:28 -0400758 ACPI_ADR_SPACE_SYSTEM_IO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 return 0;
760
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300761 pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
David Shaohua Lie6e87b42005-09-21 01:35:00 -0400762 /*
763 * "X" fields are optional extensions to the original V1.0
764 * fields, so we must selectively expand V1.0 fields if the
765 * corresponding X field is zero.
766 */
767 if (!pmtmr_ioport)
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300768 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 } else {
770 /* FADT rev. 1 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300771 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 }
773 if (pmtmr_ioport)
Len Brown4be44fc2005-08-05 00:44:28 -0400774 printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
775 pmtmr_ioport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776#endif
777 return 0;
778}
779
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780#ifdef CONFIG_X86_LOCAL_APIC
781/*
782 * Parse LAPIC entries in MADT
783 * returns 0 on success, < 0 on error
784 */
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400785
786static void __init acpi_register_lapic_address(unsigned long address)
787{
788 mp_lapic_addr = address;
789
790 set_fixmap_nocache(FIX_APIC_BASE, address);
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700791 if (boot_cpu_physical_apicid == -1U) {
Yinghai Lu4c9961d2008-07-11 18:44:16 -0700792 boot_cpu_physical_apicid = read_apic_id();
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700793 apic_version[boot_cpu_physical_apicid] =
794 GET_APIC_VERSION(apic_read(APIC_LVR));
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700795 }
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400796}
797
Yinghai Lucbf9bd62008-02-19 03:21:06 -0800798static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
799{
800 int count;
801
802 if (!cpu_has_apic)
803 return -ENODEV;
804
805 /*
806 * Note that the LAPIC address is obtained from the MADT (32-bit value)
807 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
808 */
809
810 count =
811 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
812 acpi_parse_lapic_addr_ovr, 0);
813 if (count < 0) {
814 printk(KERN_ERR PREFIX
815 "Error parsing LAPIC address override entry\n");
816 return count;
817 }
818
819 acpi_register_lapic_address(acpi_lapic_addr);
820
821 return count;
822}
823
Len Brown4be44fc2005-08-05 00:44:28 -0400824static int __init acpi_parse_madt_lapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825{
826 int count;
827
Andi Kleen0fcd2702006-04-11 12:54:36 +0200828 if (!cpu_has_apic)
829 return -ENODEV;
830
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300831 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 * Note that the LAPIC address is obtained from the MADT (32-bit value)
833 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
834 */
835
Len Brown4be44fc2005-08-05 00:44:28 -0400836 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300837 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
Len Brown4be44fc2005-08-05 00:44:28 -0400838 acpi_parse_lapic_addr_ovr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 if (count < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400840 printk(KERN_ERR PREFIX
841 "Error parsing LAPIC address override entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 return count;
843 }
844
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400845 acpi_register_lapic_address(acpi_lapic_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
Jack Steinerac049c12008-03-28 14:12:09 -0500847 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
848 acpi_parse_sapic, MAX_APICS);
849
850 if (!count)
851 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
852 acpi_parse_lapic, MAX_APICS);
Len Brown4be44fc2005-08-05 00:44:28 -0400853 if (!count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
855 /* TBD: Cleanup to allow fallback to MPS */
856 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400857 } else if (count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
859 /* TBD: Cleanup to allow fallback to MPS */
860 return count;
861 }
862
Len Brown4be44fc2005-08-05 00:44:28 -0400863 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300864 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 if (count < 0) {
866 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
867 /* TBD: Cleanup to allow fallback to MPS */
868 return count;
869 }
870 return 0;
871}
Len Brown4be44fc2005-08-05 00:44:28 -0400872#endif /* CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
Len Brown84663612005-08-24 12:09:07 -0400874#ifdef CONFIG_X86_IO_APIC
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400875#define MP_ISA_BUS 0
876
Yinghai Lud49c4282008-06-08 18:31:54 -0700877#ifdef CONFIG_X86_ES7000
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400878extern int es7000_plat;
879#endif
880
Alexey Starikovskiy5f895142008-05-14 19:03:04 +0400881static struct {
882 int apic_id;
883 int gsi_base;
884 int gsi_end;
885 DECLARE_BITMAP(pin_programmed, MP_MAX_IOAPIC_PIN + 1);
886} mp_ioapic_routing[MAX_IO_APICS];
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400887
888static int mp_find_ioapic(int gsi)
889{
890 int i = 0;
891
892 /* Find the IOAPIC that manages this GSI. */
893 for (i = 0; i < nr_ioapics; i++) {
894 if ((gsi >= mp_ioapic_routing[i].gsi_base)
895 && (gsi <= mp_ioapic_routing[i].gsi_end))
896 return i;
897 }
898
899 printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
900 return -1;
901}
902
903static u8 __init uniq_ioapic_id(u8 id)
904{
905#ifdef CONFIG_X86_32
906 if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
907 !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
908 return io_apic_get_unique_id(nr_ioapics, id);
909 else
910 return id;
911#else
912 int i;
913 DECLARE_BITMAP(used, 256);
914 bitmap_zero(used, 256);
915 for (i = 0; i < nr_ioapics; i++) {
Jaswinder Singh Rajputb5ba7e6d2009-01-12 17:46:17 +0530916 struct mpc_ioapic *ia = &mp_ioapics[i];
917 __set_bit(ia->apicid, used);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400918 }
919 if (!test_bit(id, used))
920 return id;
921 return find_first_zero_bit(used, 256);
922#endif
923}
924
925static int bad_ioapic(unsigned long address)
926{
927 if (nr_ioapics >= MAX_IO_APICS) {
928 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
929 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
930 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
931 }
932 if (!address) {
933 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
934 " found in table, skipping!\n");
935 return 1;
936 }
937 return 0;
938}
939
940void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
941{
942 int idx = 0;
943
944 if (bad_ioapic(address))
945 return;
946
947 idx = nr_ioapics;
948
Jaswinder Singh Rajputb5ba7e6d2009-01-12 17:46:17 +0530949 mp_ioapics[idx].type = MP_IOAPIC;
950 mp_ioapics[idx].flags = MPC_APIC_USABLE;
951 mp_ioapics[idx].apicaddr = address;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400952
953 set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
Jaswinder Singh Rajputb5ba7e6d2009-01-12 17:46:17 +0530954 mp_ioapics[idx].apicid = uniq_ioapic_id(id);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400955#ifdef CONFIG_X86_32
Jaswinder Singh Rajputb5ba7e6d2009-01-12 17:46:17 +0530956 mp_ioapics[idx].apicver = io_apic_get_version(idx);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400957#else
Jaswinder Singh Rajputb5ba7e6d2009-01-12 17:46:17 +0530958 mp_ioapics[idx].apicver = 0;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400959#endif
960 /*
961 * Build basic GSI lookup table to facilitate gsi->io_apic lookups
962 * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
963 */
Jaswinder Singh Rajputb5ba7e6d2009-01-12 17:46:17 +0530964 mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].apicid;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400965 mp_ioapic_routing[idx].gsi_base = gsi_base;
966 mp_ioapic_routing[idx].gsi_end = gsi_base +
967 io_apic_get_redir_entries(idx);
968
Jaswinder Singh Rajputb5ba7e6d2009-01-12 17:46:17 +0530969 printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
970 "GSI %d-%d\n", idx, mp_ioapics[idx].apicid,
971 mp_ioapics[idx].apicver, mp_ioapics[idx].apicaddr,
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400972 mp_ioapic_routing[idx].gsi_base, mp_ioapic_routing[idx].gsi_end);
973
974 nr_ioapics++;
975}
976
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530977static void assign_to_mp_irq(struct mpc_intsrc *m,
978 struct mpc_intsrc *mp_irq)
Yinghai Lufcfa1462008-06-18 17:29:31 -0700979{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530980 memcpy(mp_irq, m, sizeof(struct mpc_intsrc));
Yinghai Lufcfa1462008-06-18 17:29:31 -0700981}
982
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530983static int mp_irq_cmp(struct mpc_intsrc *mp_irq,
984 struct mpc_intsrc *m)
Yinghai Lufcfa1462008-06-18 17:29:31 -0700985{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530986 return memcmp(mp_irq, m, sizeof(struct mpc_intsrc));
Yinghai Lufcfa1462008-06-18 17:29:31 -0700987}
988
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530989static void save_mp_irq(struct mpc_intsrc *m)
Yinghai Lufcfa1462008-06-18 17:29:31 -0700990{
991 int i;
992
993 for (i = 0; i < mp_irq_entries; i++) {
994 if (!mp_irq_cmp(&mp_irqs[i], m))
995 return;
996 }
997
998 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
999 if (++mp_irq_entries == MAX_IRQ_SOURCES)
1000 panic("Max # of irq sources exceeded!!\n");
1001}
1002
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001003void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
1004{
Yinghai Lu6df88092008-06-15 18:19:46 -07001005 int ioapic;
1006 int pin;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301007 struct mpc_intsrc mp_irq;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001008
1009 /*
1010 * Convert 'gsi' to 'ioapic.pin'.
1011 */
1012 ioapic = mp_find_ioapic(gsi);
1013 if (ioapic < 0)
1014 return;
1015 pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
1016
1017 /*
1018 * TBD: This check is for faulty timer entries, where the override
1019 * erroneously sets the trigger to level, resulting in a HUGE
1020 * increase of timer interrupts!
1021 */
1022 if ((bus_irq == 0) && (trigger == 3))
1023 trigger = 1;
1024
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301025 mp_irq.type = MP_INTSRC;
1026 mp_irq.irqtype = mp_INT;
1027 mp_irq.irqflag = (trigger << 2) | polarity;
1028 mp_irq.srcbus = MP_ISA_BUS;
1029 mp_irq.srcbusirq = bus_irq; /* IRQ */
1030 mp_irq.dstapic = mp_ioapics[ioapic].apicid; /* APIC ID */
1031 mp_irq.dstirq = pin; /* INTIN# */
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001032
Yinghai Lufcfa1462008-06-18 17:29:31 -07001033 save_mp_irq(&mp_irq);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001034}
1035
1036void __init mp_config_acpi_legacy_irqs(void)
1037{
Yinghai Lu6df88092008-06-15 18:19:46 -07001038 int i;
1039 int ioapic;
1040 unsigned int dstapic;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301041 struct mpc_intsrc mp_irq;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001042
1043#if defined (CONFIG_MCA) || defined (CONFIG_EISA)
1044 /*
1045 * Fabricate the legacy ISA bus (bus #31).
1046 */
1047 mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
1048#endif
1049 set_bit(MP_ISA_BUS, mp_bus_not_pci);
Thomas Gleixnercfc1b9a2008-07-21 21:35:38 +02001050 pr_debug("Bus #%d is ISA\n", MP_ISA_BUS);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001051
Yinghai Lud49c4282008-06-08 18:31:54 -07001052#ifdef CONFIG_X86_ES7000
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001053 /*
1054 * Older generations of ES7000 have no legacy identity mappings
1055 */
1056 if (es7000_plat == 1)
1057 return;
1058#endif
1059
1060 /*
1061 * Locate the IOAPIC that manages the ISA IRQs (0-15).
1062 */
1063 ioapic = mp_find_ioapic(0);
1064 if (ioapic < 0)
1065 return;
Jaswinder Singh Rajputb5ba7e6d2009-01-12 17:46:17 +05301066 dstapic = mp_ioapics[ioapic].apicid;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001067
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001068 /*
1069 * Use the default configuration for the IRQs 0-15. Unless
1070 * overridden by (MADT) interrupt source override entries.
1071 */
1072 for (i = 0; i < 16; i++) {
1073 int idx;
1074
1075 for (idx = 0; idx < mp_irq_entries; idx++) {
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301076 struct mpc_intsrc *irq = mp_irqs + idx;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001077
1078 /* Do we already have a mapping for this ISA IRQ? */
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301079 if (irq->srcbus == MP_ISA_BUS && irq->srcbusirq == i)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001080 break;
1081
1082 /* Do we already have a mapping for this IOAPIC pin */
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301083 if (irq->dstapic == dstapic && irq->dstirq == i)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001084 break;
1085 }
1086
1087 if (idx != mp_irq_entries) {
1088 printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
1089 continue; /* IRQ already used */
1090 }
1091
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301092 mp_irq.type = MP_INTSRC;
1093 mp_irq.irqflag = 0; /* Conforming */
1094 mp_irq.srcbus = MP_ISA_BUS;
1095 mp_irq.dstapic = dstapic;
1096 mp_irq.irqtype = mp_INT;
1097 mp_irq.srcbusirq = i; /* Identity mapped */
1098 mp_irq.dstirq = i;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001099
Yinghai Lufcfa1462008-06-18 17:29:31 -07001100 save_mp_irq(&mp_irq);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001101 }
1102}
1103
1104int mp_register_gsi(u32 gsi, int triggering, int polarity)
1105{
1106 int ioapic;
1107 int ioapic_pin;
1108#ifdef CONFIG_X86_32
1109#define MAX_GSI_NUM 4096
1110#define IRQ_COMPRESSION_START 64
1111
1112 static int pci_irq = IRQ_COMPRESSION_START;
1113 /*
1114 * Mapping between Global System Interrupts, which
1115 * represent all possible interrupts, and IRQs
1116 * assigned to actual devices.
1117 */
1118 static int gsi_to_irq[MAX_GSI_NUM];
1119#else
1120
1121 if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
1122 return gsi;
1123#endif
1124
1125 /* Don't set up the ACPI SCI because it's already set up */
1126 if (acpi_gbl_FADT.sci_interrupt == gsi)
1127 return gsi;
1128
1129 ioapic = mp_find_ioapic(gsi);
1130 if (ioapic < 0) {
1131 printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
1132 return gsi;
1133 }
1134
1135 ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
1136
1137#ifdef CONFIG_X86_32
1138 if (ioapic_renumber_irq)
1139 gsi = ioapic_renumber_irq(ioapic, gsi);
1140#endif
1141
1142 /*
1143 * Avoid pin reprogramming. PRTs typically include entries
1144 * with redundant pin->gsi mappings (but unique PCI devices);
1145 * we only program the IOAPIC on the first.
1146 */
1147 if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
1148 printk(KERN_ERR "Invalid reference to IOAPIC pin "
1149 "%d-%d\n", mp_ioapic_routing[ioapic].apic_id,
1150 ioapic_pin);
1151 return gsi;
1152 }
1153 if (test_bit(ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed)) {
Gustavo F. Padovan55410792008-10-15 10:37:04 -03001154 pr_debug("Pin %d-%d already programmed\n",
Thomas Gleixnercfc1b9a2008-07-21 21:35:38 +02001155 mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001156#ifdef CONFIG_X86_32
1157 return (gsi < IRQ_COMPRESSION_START ? gsi : gsi_to_irq[gsi]);
1158#else
1159 return gsi;
1160#endif
1161 }
1162
1163 set_bit(ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed);
1164#ifdef CONFIG_X86_32
1165 /*
1166 * For GSI >= 64, use IRQ compression
1167 */
1168 if ((gsi >= IRQ_COMPRESSION_START)
1169 && (triggering == ACPI_LEVEL_SENSITIVE)) {
1170 /*
1171 * For PCI devices assign IRQs in order, avoiding gaps
1172 * due to unused I/O APIC pins.
1173 */
1174 int irq = gsi;
1175 if (gsi < MAX_GSI_NUM) {
1176 /*
1177 * Retain the VIA chipset work-around (gsi > 15), but
1178 * avoid a problem where the 8254 timer (IRQ0) is setup
1179 * via an override (so it's not on pin 0 of the ioapic),
1180 * and at the same time, the pin 0 interrupt is a PCI
1181 * type. The gsi > 15 test could cause these two pins
1182 * to be shared as IRQ0, and they are not shareable.
1183 * So test for this condition, and if necessary, avoid
1184 * the pin collision.
1185 */
1186 gsi = pci_irq++;
1187 /*
1188 * Don't assign IRQ used by ACPI SCI
1189 */
1190 if (gsi == acpi_gbl_FADT.sci_interrupt)
1191 gsi = pci_irq++;
1192 gsi_to_irq[irq] = gsi;
1193 } else {
1194 printk(KERN_ERR "GSI %u is too high\n", gsi);
1195 return gsi;
1196 }
1197 }
1198#endif
1199 io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
1200 triggering == ACPI_EDGE_SENSITIVE ? 0 : 1,
1201 polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
1202 return gsi;
1203}
1204
Yinghai Lu2944e162008-06-01 13:17:38 -07001205int mp_config_acpi_gsi(unsigned char number, unsigned int devfn, u8 pin,
1206 u32 gsi, int triggering, int polarity)
1207{
Yinghai Lufcfa1462008-06-18 17:29:31 -07001208#ifdef CONFIG_X86_MPPARSE
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301209 struct mpc_intsrc mp_irq;
Yinghai Lu2944e162008-06-01 13:17:38 -07001210 int ioapic;
1211
Yinghai Lufcfa1462008-06-18 17:29:31 -07001212 if (!acpi_ioapic)
Yinghai Lud867e532008-06-14 01:26:41 -07001213 return 0;
1214
Yinghai Lu2944e162008-06-01 13:17:38 -07001215 /* print the entry should happen on mptable identically */
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301216 mp_irq.type = MP_INTSRC;
1217 mp_irq.irqtype = mp_INT;
1218 mp_irq.irqflag = (triggering == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
Yinghai Lu2944e162008-06-01 13:17:38 -07001219 (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301220 mp_irq.srcbus = number;
1221 mp_irq.srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
Yinghai Lu2944e162008-06-01 13:17:38 -07001222 ioapic = mp_find_ioapic(gsi);
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301223 mp_irq.dstapic = mp_ioapic_routing[ioapic].apic_id;
1224 mp_irq.dstirq = gsi - mp_ioapic_routing[ioapic].gsi_base;
Yinghai Lu2944e162008-06-01 13:17:38 -07001225
Yinghai Lufcfa1462008-06-18 17:29:31 -07001226 save_mp_irq(&mp_irq);
1227#endif
Yinghai Lu2944e162008-06-01 13:17:38 -07001228 return 0;
1229}
1230
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231/*
1232 * Parse IOAPIC related entries in MADT
1233 * returns 0 on success, < 0 on error
1234 */
Len Brown4be44fc2005-08-05 00:44:28 -04001235static int __init acpi_parse_madt_ioapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236{
1237 int count;
1238
1239 /*
1240 * ACPI interpreter is required to complete interrupt setup,
1241 * so if it is off, don't enumerate the io-apics with ACPI.
1242 * If MPS is present, it will handle them,
1243 * otherwise the system will stay in PIC mode
1244 */
1245 if (acpi_disabled || acpi_noirq) {
1246 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -04001247 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001249 if (!cpu_has_apic)
Andi Kleend3b6a342006-04-07 19:49:39 +02001250 return -ENODEV;
1251
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001253 * if "noapic" boot option, don't look for IO-APICs
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 */
1255 if (skip_ioapic_setup) {
1256 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
Len Brown4be44fc2005-08-05 00:44:28 -04001257 "due to 'noapic' option.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 return -ENODEV;
1259 }
1260
Len Brown4be44fc2005-08-05 00:44:28 -04001261 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001262 acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
Len Brown4be44fc2005-08-05 00:44:28 -04001263 MAX_IO_APICS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 if (!count) {
1265 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
1266 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -04001267 } else if (count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
1269 return count;
1270 }
1271
Len Brown4be44fc2005-08-05 00:44:28 -04001272 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001273 acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr,
Yinghai Lu71f521b2008-08-19 20:50:03 -07001274 nr_irqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 if (count < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -04001276 printk(KERN_ERR PREFIX
1277 "Error parsing interrupt source overrides entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 /* TBD: Cleanup to allow fallback to MPS */
1279 return count;
1280 }
1281
1282 /*
1283 * If BIOS did not supply an INT_SRC_OVR for the SCI
1284 * pretend we got one so we can set the SCI flags.
1285 */
1286 if (!acpi_sci_override_gsi)
Alexey Starikovskiycee324b2007-02-02 19:48:22 +03001287 acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
1289 /* Fill in identity legacy mapings where no override */
1290 mp_config_acpi_legacy_irqs();
1291
Len Brown4be44fc2005-08-05 00:44:28 -04001292 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001293 acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src,
Yinghai Lu71f521b2008-08-19 20:50:03 -07001294 nr_irqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 if (count < 0) {
1296 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
1297 /* TBD: Cleanup to allow fallback to MPS */
1298 return count;
1299 }
1300
1301 return 0;
1302}
1303#else
1304static inline int acpi_parse_madt_ioapic_entries(void)
1305{
1306 return -1;
1307}
Len Brown84663612005-08-24 12:09:07 -04001308#endif /* !CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001310static void __init early_acpi_process_madt(void)
1311{
1312#ifdef CONFIG_X86_LOCAL_APIC
1313 int error;
1314
1315 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1316
1317 /*
1318 * Parse MADT LAPIC entries
1319 */
1320 error = early_acpi_parse_madt_lapic_addr_ovr();
1321 if (!error) {
1322 acpi_lapic = 1;
1323 smp_found_config = 1;
1324 }
1325 if (error == -EINVAL) {
1326 /*
1327 * Dell Precision Workstation 410, 610 come here.
1328 */
1329 printk(KERN_ERR PREFIX
1330 "Invalid BIOS MADT, disabling ACPI\n");
1331 disable_acpi();
1332 }
1333 }
1334#endif
1335}
1336
Len Brown4be44fc2005-08-05 00:44:28 -04001337static void __init acpi_process_madt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338{
1339#ifdef CONFIG_X86_LOCAL_APIC
Len Brown7f8f97c2007-02-10 21:28:03 -05001340 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341
Len Brown7f8f97c2007-02-10 21:28:03 -05001342 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
1344 /*
1345 * Parse MADT LAPIC entries
1346 */
1347 error = acpi_parse_madt_lapic_entries();
1348 if (!error) {
1349 acpi_lapic = 1;
1350
Venkatesh Pallipadi911a62d2005-09-03 15:56:31 -07001351#ifdef CONFIG_X86_GENERICARCH
1352 generic_bigsmp_probe();
1353#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 /*
1355 * Parse MADT IO-APIC entries
1356 */
1357 error = acpi_parse_madt_ioapic_entries();
1358 if (!error) {
1359 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 acpi_ioapic = 1;
1361
1362 smp_found_config = 1;
Suresh Siddha6e1cb382008-07-10 11:16:58 -07001363#ifdef CONFIG_X86_32
Ingo Molnar3c43f032007-05-02 19:27:04 +02001364 setup_apic_routing();
Suresh Siddha6e1cb382008-07-10 11:16:58 -07001365#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 }
1367 }
1368 if (error == -EINVAL) {
1369 /*
1370 * Dell Precision Workstation 410, 610 come here.
1371 */
Len Brown4be44fc2005-08-05 00:44:28 -04001372 printk(KERN_ERR PREFIX
1373 "Invalid BIOS MADT, disabling ACPI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 disable_acpi();
1375 }
Len Brown7b37b5f2008-12-23 01:47:42 -05001376 } else {
1377 /*
1378 * ACPI found no MADT, and so ACPI wants UP PIC mode.
1379 * In the event an MPS table was found, forget it.
1380 * Boot with "acpi=off" to use MPS on such a system.
1381 */
1382 if (smp_found_config) {
1383 printk(KERN_WARNING PREFIX
1384 "No APIC-table, disabling MPS\n");
1385 smp_found_config = 0;
1386 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 }
Yinghai Lu69b88af2008-12-05 22:45:50 -08001388
1389 /*
1390 * ACPI supports both logical (e.g. Hyper-Threading) and physical
1391 * processors, where MPS only supports physical.
1392 */
1393 if (acpi_lapic && acpi_ioapic)
1394 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
1395 "information\n");
1396 else if (acpi_lapic)
1397 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
1398 "configuration information\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399#endif
1400 return;
1401}
1402
Jeff Garzik18552562007-10-03 15:15:40 -04001403static int __init disable_acpi_irq(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001404{
1405 if (!acpi_force) {
1406 printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
1407 d->ident);
1408 acpi_noirq_set();
1409 }
1410 return 0;
1411}
1412
Jeff Garzik18552562007-10-03 15:15:40 -04001413static int __init disable_acpi_pci(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001414{
1415 if (!acpi_force) {
1416 printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
1417 d->ident);
1418 acpi_disable_pci();
1419 }
1420 return 0;
1421}
Andrey Paninaea00142005-06-25 14:54:42 -07001422
Jeff Garzik18552562007-10-03 15:15:40 -04001423static int __init dmi_disable_acpi(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001424{
1425 if (!acpi_force) {
Len Brown4be44fc2005-08-05 00:44:28 -04001426 printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
Andrey Paninaea00142005-06-25 14:54:42 -07001427 disable_acpi();
1428 } else {
1429 printk(KERN_NOTICE
1430 "Warning: DMI blacklist says broken, but acpi forced\n");
1431 }
1432 return 0;
1433}
1434
1435/*
1436 * Limit ACPI to CPU enumeration for HT
1437 */
Jeff Garzik18552562007-10-03 15:15:40 -04001438static int __init force_acpi_ht(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001439{
1440 if (!acpi_force) {
Len Brown4be44fc2005-08-05 00:44:28 -04001441 printk(KERN_NOTICE "%s detected: force use of acpi=ht\n",
1442 d->ident);
Andrey Paninaea00142005-06-25 14:54:42 -07001443 disable_acpi();
1444 acpi_ht = 1;
1445 } else {
1446 printk(KERN_NOTICE
1447 "Warning: acpi=force overrules DMI blacklist: acpi=ht\n");
1448 }
1449 return 0;
1450}
1451
1452/*
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001453 * Force ignoring BIOS IRQ0 pin2 override
1454 */
1455static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
1456{
Ingo Molnar8d89adf2008-10-07 06:47:52 +02001457 /*
1458 * The ati_ixp4x0_rev() early PCI quirk should have set
1459 * the acpi_skip_timer_override flag already:
1460 */
1461 if (!acpi_skip_timer_override) {
1462 WARN(1, KERN_ERR "ati_ixp4x0 quirk not complete.\n");
1463 pr_notice("%s detected: Ignoring BIOS IRQ0 pin2 override\n",
1464 d->ident);
1465 acpi_skip_timer_override = 1;
1466 }
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001467 return 0;
1468}
1469
1470/*
Andrey Paninaea00142005-06-25 14:54:42 -07001471 * If your system is blacklisted here, but you find that acpi=force
1472 * works for you, please contact acpi-devel@sourceforge.net
1473 */
1474static struct dmi_system_id __initdata acpi_dmi_table[] = {
1475 /*
1476 * Boxes that need ACPI disabled
1477 */
1478 {
Len Brown4be44fc2005-08-05 00:44:28 -04001479 .callback = dmi_disable_acpi,
1480 .ident = "IBM Thinkpad",
1481 .matches = {
1482 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1483 DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
1484 },
1485 },
Andrey Paninaea00142005-06-25 14:54:42 -07001486
1487 /*
1488 * Boxes that need acpi=ht
1489 */
1490 {
Len Brown4be44fc2005-08-05 00:44:28 -04001491 .callback = force_acpi_ht,
1492 .ident = "FSC Primergy T850",
1493 .matches = {
1494 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
1495 DMI_MATCH(DMI_PRODUCT_NAME, "PRIMERGY T850"),
1496 },
1497 },
Andrey Paninaea00142005-06-25 14:54:42 -07001498 {
Len Brown4be44fc2005-08-05 00:44:28 -04001499 .callback = force_acpi_ht,
Len Brown4be44fc2005-08-05 00:44:28 -04001500 .ident = "HP VISUALIZE NT Workstation",
1501 .matches = {
1502 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
1503 DMI_MATCH(DMI_PRODUCT_NAME, "HP VISUALIZE NT Workstation"),
1504 },
1505 },
Andrey Paninaea00142005-06-25 14:54:42 -07001506 {
Len Brown4be44fc2005-08-05 00:44:28 -04001507 .callback = force_acpi_ht,
1508 .ident = "Compaq Workstation W8000",
1509 .matches = {
1510 DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
1511 DMI_MATCH(DMI_PRODUCT_NAME, "Workstation W8000"),
1512 },
1513 },
Andrey Paninaea00142005-06-25 14:54:42 -07001514 {
Len Brown4be44fc2005-08-05 00:44:28 -04001515 .callback = force_acpi_ht,
1516 .ident = "ASUS P4B266",
1517 .matches = {
1518 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1519 DMI_MATCH(DMI_BOARD_NAME, "P4B266"),
1520 },
1521 },
Andrey Paninaea00142005-06-25 14:54:42 -07001522 {
Len Brown4be44fc2005-08-05 00:44:28 -04001523 .callback = force_acpi_ht,
1524 .ident = "ASUS P2B-DS",
1525 .matches = {
1526 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1527 DMI_MATCH(DMI_BOARD_NAME, "P2B-DS"),
1528 },
1529 },
Andrey Paninaea00142005-06-25 14:54:42 -07001530 {
Len Brown4be44fc2005-08-05 00:44:28 -04001531 .callback = force_acpi_ht,
1532 .ident = "ASUS CUR-DLS",
1533 .matches = {
1534 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1535 DMI_MATCH(DMI_BOARD_NAME, "CUR-DLS"),
1536 },
1537 },
Andrey Paninaea00142005-06-25 14:54:42 -07001538 {
Len Brown4be44fc2005-08-05 00:44:28 -04001539 .callback = force_acpi_ht,
1540 .ident = "ABIT i440BX-W83977",
1541 .matches = {
1542 DMI_MATCH(DMI_BOARD_VENDOR, "ABIT <http://www.abit.com>"),
1543 DMI_MATCH(DMI_BOARD_NAME, "i440BX-W83977 (BP6)"),
1544 },
1545 },
Andrey Paninaea00142005-06-25 14:54:42 -07001546 {
Len Brown4be44fc2005-08-05 00:44:28 -04001547 .callback = force_acpi_ht,
1548 .ident = "IBM Bladecenter",
1549 .matches = {
1550 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1551 DMI_MATCH(DMI_BOARD_NAME, "IBM eServer BladeCenter HS20"),
1552 },
1553 },
Andrey Paninaea00142005-06-25 14:54:42 -07001554 {
Len Brown4be44fc2005-08-05 00:44:28 -04001555 .callback = force_acpi_ht,
1556 .ident = "IBM eServer xSeries 360",
1557 .matches = {
1558 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1559 DMI_MATCH(DMI_BOARD_NAME, "eServer xSeries 360"),
1560 },
1561 },
Andrey Paninaea00142005-06-25 14:54:42 -07001562 {
Len Brown4be44fc2005-08-05 00:44:28 -04001563 .callback = force_acpi_ht,
1564 .ident = "IBM eserver xSeries 330",
1565 .matches = {
1566 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1567 DMI_MATCH(DMI_BOARD_NAME, "eserver xSeries 330"),
1568 },
1569 },
Andrey Paninaea00142005-06-25 14:54:42 -07001570 {
Len Brown4be44fc2005-08-05 00:44:28 -04001571 .callback = force_acpi_ht,
1572 .ident = "IBM eserver xSeries 440",
1573 .matches = {
1574 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1575 DMI_MATCH(DMI_PRODUCT_NAME, "eserver xSeries 440"),
1576 },
1577 },
Andrey Paninaea00142005-06-25 14:54:42 -07001578
Andrey Paninaea00142005-06-25 14:54:42 -07001579 /*
1580 * Boxes that need ACPI PCI IRQ routing disabled
1581 */
1582 {
Len Brown4be44fc2005-08-05 00:44:28 -04001583 .callback = disable_acpi_irq,
1584 .ident = "ASUS A7V",
1585 .matches = {
1586 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
1587 DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
1588 /* newer BIOS, Revision 1011, does work */
1589 DMI_MATCH(DMI_BIOS_VERSION,
1590 "ASUS A7V ACPI BIOS Revision 1007"),
1591 },
1592 },
Len Brown74586fc2007-03-08 02:48:30 -05001593 {
1594 /*
1595 * Latest BIOS for IBM 600E (1.16) has bad pcinum
1596 * for LPC bridge, which is needed for the PCI
1597 * interrupt links to work. DSDT fix is in bug 5966.
1598 * 2645, 2646 model numbers are shared with 600/600E/600X
1599 */
1600 .callback = disable_acpi_irq,
1601 .ident = "IBM Thinkpad 600 Series 2645",
1602 .matches = {
1603 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1604 DMI_MATCH(DMI_BOARD_NAME, "2645"),
1605 },
1606 },
1607 {
1608 .callback = disable_acpi_irq,
1609 .ident = "IBM Thinkpad 600 Series 2646",
1610 .matches = {
1611 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1612 DMI_MATCH(DMI_BOARD_NAME, "2646"),
1613 },
1614 },
Andrey Paninaea00142005-06-25 14:54:42 -07001615 /*
1616 * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
1617 */
Len Brown4be44fc2005-08-05 00:44:28 -04001618 { /* _BBN 0 bug */
1619 .callback = disable_acpi_pci,
1620 .ident = "ASUS PR-DLS",
1621 .matches = {
1622 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1623 DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
1624 DMI_MATCH(DMI_BIOS_VERSION,
1625 "ASUS PR-DLS ACPI BIOS Revision 1010"),
1626 DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
1627 },
1628 },
Andrey Paninaea00142005-06-25 14:54:42 -07001629 {
Len Brown4be44fc2005-08-05 00:44:28 -04001630 .callback = disable_acpi_pci,
1631 .ident = "Acer TravelMate 36x Laptop",
1632 .matches = {
1633 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
1634 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
1635 },
1636 },
Andreas Herrmann35af2822008-10-22 13:08:31 +02001637 {}
1638};
1639
1640/* second table for DMI checks that should run after early-quirks */
1641static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
Matthew Garrett9340e1c2008-07-01 01:12:06 +01001642 /*
1643 * HP laptops which use a DSDT reporting as HP/SB400/10000,
1644 * which includes some code which overrides all temperature
1645 * trip points to 16C if the INTIN2 input of the I/O APIC
1646 * is enabled. This input is incorrectly designated the
1647 * ISA IRQ 0 via an interrupt source override even though
1648 * it is wired to the output of the master 8259A and INTIN0
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001649 * is not connected at all. Force ignoring BIOS IRQ0 pin2
1650 * override in that cases.
1651 */
1652 {
1653 .callback = dmi_ignore_irq0_timer_override,
Rafael J. Wysockie84956f2008-10-06 11:59:29 +02001654 .ident = "HP nx6115 laptop",
1655 .matches = {
1656 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1657 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6115"),
1658 },
1659 },
1660 {
1661 .callback = dmi_ignore_irq0_timer_override,
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001662 .ident = "HP NX6125 laptop",
1663 .matches = {
1664 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1665 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
1666 },
1667 },
1668 {
1669 .callback = dmi_ignore_irq0_timer_override,
1670 .ident = "HP NX6325 laptop",
1671 .matches = {
1672 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1673 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
1674 },
1675 },
Rafael J. Wysockie84956f2008-10-06 11:59:29 +02001676 {
1677 .callback = dmi_ignore_irq0_timer_override,
1678 .ident = "HP 6715b laptop",
1679 .matches = {
1680 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1681 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
1682 },
1683 },
Len Brown4be44fc2005-08-05 00:44:28 -04001684 {}
Andrey Paninaea00142005-06-25 14:54:42 -07001685};
1686
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687/*
1688 * acpi_boot_table_init() and acpi_boot_init()
1689 * called from setup_arch(), always.
1690 * 1. checksums all tables
1691 * 2. enumerates lapics
1692 * 3. enumerates io-apics
1693 *
1694 * acpi_table_init() is separate to allow reading SRAT without
1695 * other side effects.
1696 *
1697 * side effects of acpi_boot_init:
1698 * acpi_lapic = 1 if LAPIC found
1699 * acpi_ioapic = 1 if IOAPIC found
1700 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
1701 * if acpi_blacklisted() acpi_disabled = 1;
1702 * acpi_irq_model=...
1703 * ...
1704 *
1705 * return value: (currently ignored)
1706 * 0: success
1707 * !0: failure
1708 */
1709
Len Brown4be44fc2005-08-05 00:44:28 -04001710int __init acpi_boot_table_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711{
1712 int error;
1713
Andrey Paninaea00142005-06-25 14:54:42 -07001714 dmi_check_system(acpi_dmi_table);
Andrey Paninaea00142005-06-25 14:54:42 -07001715
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 /*
1717 * If acpi_disabled, bail out
1718 * One exception: acpi=ht continues far enough to enumerate LAPICs
1719 */
1720 if (acpi_disabled && !acpi_ht)
Len Brown4be44fc2005-08-05 00:44:28 -04001721 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001723 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 * Initialize the ACPI boot-time table parser.
1725 */
1726 error = acpi_table_init();
1727 if (error) {
1728 disable_acpi();
1729 return error;
1730 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001732 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
1734 /*
1735 * blacklist may disable ACPI entirely
1736 */
1737 error = acpi_blacklisted();
1738 if (error) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 if (acpi_force) {
1740 printk(KERN_WARNING PREFIX "acpi=force override\n");
1741 } else {
1742 printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
1743 disable_acpi();
1744 return error;
1745 }
1746 }
1747
1748 return 0;
1749}
1750
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001751int __init early_acpi_boot_init(void)
1752{
1753 /*
1754 * If acpi_disabled, bail out
1755 * One exception: acpi=ht continues far enough to enumerate LAPICs
1756 */
1757 if (acpi_disabled && !acpi_ht)
1758 return 1;
1759
1760 /*
1761 * Process the Multiple APIC Description Table (MADT), if present
1762 */
1763 early_acpi_process_madt();
1764
1765 return 0;
1766}
1767
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768int __init acpi_boot_init(void)
1769{
Andreas Herrmann35af2822008-10-22 13:08:31 +02001770 /* those are executed after early-quirks are executed */
1771 dmi_check_system(acpi_dmi_table_late);
1772
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 /*
1774 * If acpi_disabled, bail out
1775 * One exception: acpi=ht continues far enough to enumerate LAPICs
1776 */
1777 if (acpi_disabled && !acpi_ht)
Len Brown4be44fc2005-08-05 00:44:28 -04001778 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001780 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
1782 /*
1783 * set sci_int and PM timer address
1784 */
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +03001785 acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786
1787 /*
1788 * Process the Multiple APIC Description Table (MADT), if present
1789 */
1790 acpi_process_madt();
1791
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001792 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
1794 return 0;
1795}
Rusty Russell1a3f2392006-09-26 10:52:32 +02001796
1797static int __init parse_acpi(char *arg)
1798{
1799 if (!arg)
1800 return -EINVAL;
1801
1802 /* "acpi=off" disables both ACPI table parsing and interpreter */
1803 if (strcmp(arg, "off") == 0) {
1804 disable_acpi();
1805 }
1806 /* acpi=force to over-ride black-list */
1807 else if (strcmp(arg, "force") == 0) {
1808 acpi_force = 1;
1809 acpi_ht = 1;
1810 acpi_disabled = 0;
1811 }
1812 /* acpi=strict disables out-of-spec workarounds */
1813 else if (strcmp(arg, "strict") == 0) {
1814 acpi_strict = 1;
1815 }
1816 /* Limit ACPI just to boot-time to enable HT */
1817 else if (strcmp(arg, "ht") == 0) {
1818 if (!acpi_force)
1819 disable_acpi();
1820 acpi_ht = 1;
1821 }
Zhao Yakui237889b2008-12-17 16:55:18 +08001822 /* acpi=rsdt use RSDT instead of XSDT */
1823 else if (strcmp(arg, "rsdt") == 0) {
1824 acpi_rsdt_forced = 1;
1825 }
Rusty Russell1a3f2392006-09-26 10:52:32 +02001826 /* "acpi=noirq" disables ACPI interrupt routing */
1827 else if (strcmp(arg, "noirq") == 0) {
1828 acpi_noirq_set();
1829 } else {
1830 /* Core will printk when we return error. */
1831 return -EINVAL;
1832 }
1833 return 0;
1834}
1835early_param("acpi", parse_acpi);
1836
1837/* FIXME: Using pci= for an ACPI parameter is a travesty. */
1838static int __init parse_pci(char *arg)
1839{
1840 if (arg && strcmp(arg, "noacpi") == 0)
1841 acpi_disable_pci();
1842 return 0;
1843}
1844early_param("pci", parse_pci);
1845
Yinghai Lu3c999f12008-06-20 16:11:20 -07001846int __init acpi_mps_check(void)
1847{
1848#if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
1849/* mptable code is not built-in*/
1850 if (acpi_disabled || acpi_noirq) {
1851 printk(KERN_WARNING "MPS support code is not built-in.\n"
1852 "Using acpi=off or acpi=noirq or pci=noacpi "
1853 "may have problem\n");
1854 return 1;
1855 }
1856#endif
1857 return 0;
1858}
1859
Rusty Russell1a3f2392006-09-26 10:52:32 +02001860#ifdef CONFIG_X86_IO_APIC
1861static int __init parse_acpi_skip_timer_override(char *arg)
1862{
1863 acpi_skip_timer_override = 1;
1864 return 0;
1865}
1866early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
Andi Kleenfa18f472006-11-14 16:57:46 +01001867
1868static int __init parse_acpi_use_timer_override(char *arg)
1869{
1870 acpi_use_timer_override = 1;
1871 return 0;
1872}
1873early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001874#endif /* CONFIG_X86_IO_APIC */
1875
1876static int __init setup_acpi_sci(char *s)
1877{
1878 if (!s)
1879 return -EINVAL;
1880 if (!strcmp(s, "edge"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001881 acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
1882 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001883 else if (!strcmp(s, "level"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001884 acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
1885 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001886 else if (!strcmp(s, "high"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001887 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
1888 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001889 else if (!strcmp(s, "low"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001890 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
1891 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001892 else
1893 return -EINVAL;
1894 return 0;
1895}
1896early_param("acpi_sci", setup_acpi_sci);
Andrew Mortond0a90812006-10-20 14:30:27 -07001897
1898int __acpi_acquire_global_lock(unsigned int *lock)
1899{
1900 unsigned int old, new, val;
1901 do {
1902 old = *lock;
1903 new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
1904 val = cmpxchg(lock, old, new);
1905 } while (unlikely (val != old));
1906 return (new < 3) ? -1 : 0;
1907}
1908
1909int __acpi_release_global_lock(unsigned int *lock)
1910{
1911 unsigned int old, new, val;
1912 do {
1913 old = *lock;
1914 new = old & ~0x3;
1915 val = cmpxchg(lock, old, new);
1916 } while (unlikely (val != old));
1917 return old & 0x1;
1918}