blob: fa88a1d7129094fcc85b1b2425234a80e2418581 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * boot.c - Architecture-Specific Low-Level ACPI Boot Support
3 *
4 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
5 * Copyright (C) 2001 Jun Nakajima <jun.nakajima@intel.com>
6 *
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 */
25
26#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/acpi.h>
Thomas Gleixnerd66bea52007-02-16 01:27:57 -080028#include <linux/acpi_pmtmr.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/efi.h>
Ashok Raj73fea172006-09-26 10:52:35 +020030#include <linux/cpumask.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/module.h>
Andrey Paninaea00142005-06-25 14:54:42 -070032#include <linux/dmi.h>
Nick Pigginb33fa1f2005-10-01 02:34:42 +100033#include <linux/irq.h>
adurbin@google.comf0f4c342006-09-26 10:52:39 +020034#include <linux/bootmem.h>
35#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#include <asm/pgtable.h>
38#include <asm/io_apic.h>
39#include <asm/apic.h>
Ingo Molnar183fe062008-07-09 11:32:10 +020040#include <asm/genapic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/mpspec.h>
Alexey Starikovskiydfac2182008-04-04 23:41:50 +040043#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Glauber de Oliveira Costaf6bc4022008-03-19 14:25:53 -030045#ifdef CONFIG_X86_LOCAL_APIC
46# include <mach_apic.h>
47#endif
48
Adrian Bunke8924ac2006-09-26 10:52:35 +020049static int __initdata acpi_force = 0;
Rusty Russell1a3f2392006-09-26 10:52:32 +020050
Andi Kleendf3bb572006-09-26 10:52:33 +020051#ifdef CONFIG_ACPI
52int acpi_disabled = 0;
53#else
54int acpi_disabled = 1;
55#endif
56EXPORT_SYMBOL(acpi_disabled);
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#ifdef CONFIG_X86_64
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#include <asm/proto.h>
Jack Steinerae261862008-03-28 14:12:06 -050061#include <asm/genapic.h>
Linus Torvalds637029c2006-02-27 20:41:56 -080062
Len Brown4be44fc2005-08-05 00:44:28 -040063#else /* X86 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65#ifdef CONFIG_X86_LOCAL_APIC
66#include <mach_apic.h>
67#include <mach_mpparse.h>
Len Brown4be44fc2005-08-05 00:44:28 -040068#endif /* CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Len Brown4be44fc2005-08-05 00:44:28 -040070#endif /* X86 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72#define BAD_MADT_ENTRY(entry, end) ( \
73 (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +030074 ((struct acpi_subtable_header *)entry)->length < sizeof(*entry))
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76#define PREFIX "ACPI: "
77
Andrew Morton90d53902006-11-02 22:07:18 -080078int acpi_noirq; /* skip ACPI IRQ initialization */
Yinghai Lu6e4be1f2008-02-05 00:01:48 -080079int acpi_pci_disabled; /* skip ACPI PCI scan and IRQ initialization */
80EXPORT_SYMBOL(acpi_pci_disabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081int acpi_ht __initdata = 1; /* enable HT */
82
83int acpi_lapic;
84int acpi_ioapic;
85int acpi_strict;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +030087u8 acpi_sci_flags __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088int acpi_sci_override_gsi __initdata;
89int acpi_skip_timer_override __initdata;
Andi Kleenfa18f472006-11-14 16:57:46 +010090int acpi_use_timer_override __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92#ifdef CONFIG_X86_LOCAL_APIC
93static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
94#endif
95
96#ifndef __HAVE_ARCH_CMPXCHG
97#warning ACPI uses CMPXCHG, i486 and later hardware
98#endif
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100/* --------------------------------------------------------------------------
101 Boot-time Configuration
102 -------------------------------------------------------------------------- */
103
104/*
105 * The default interrupt routing model is PIC (8259). This gets
Simon Arlott27b46d72007-10-20 01:13:56 +0200106 * overridden if IOAPICs are enumerated (below).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 */
Len Brown4be44fc2005-08-05 00:44:28 -0400108enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111/*
112 * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
113 * to map the target physical address. The problem is that set_fixmap()
114 * provides a single page, and it is possible that the page is not
115 * sufficient.
116 * By using this area, we can map up to MAX_IO_APICS pages temporarily,
117 * i.e. until the next __va_range() call.
118 *
119 * Important Safety Note: The fixed I/O APIC page numbers are *subtracted*
120 * from the fixed base. That's why we start at FIX_IO_APIC_BASE_END and
121 * count idx down while incrementing the phys address.
122 */
Jan Beulich2fdf0742007-12-13 08:33:59 +0000123char *__init __acpi_map_table(unsigned long phys, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
125 unsigned long base, offset, mapped_size;
126 int idx;
127
Yinghai Luf34fa822008-07-09 20:16:36 -0700128 if (!phys || !size)
129 return NULL;
130
Yinghai Luf361a452008-07-10 20:38:26 -0700131 if (phys+size <= (max_low_pfn_mapped << PAGE_SHIFT))
Len Brown4be44fc2005-08-05 00:44:28 -0400132 return __va(phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134 offset = phys & (PAGE_SIZE - 1);
135 mapped_size = PAGE_SIZE - offset;
Yinghai Luf34fa822008-07-09 20:16:36 -0700136 clear_fixmap(FIX_ACPI_END);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 set_fixmap(FIX_ACPI_END, phys);
138 base = fix_to_virt(FIX_ACPI_END);
139
140 /*
141 * Most cases can be covered by the below.
142 */
143 idx = FIX_ACPI_END;
144 while (mapped_size < size) {
145 if (--idx < FIX_ACPI_BEGIN)
146 return NULL; /* cannot handle this */
147 phys += PAGE_SIZE;
Yinghai Luf34fa822008-07-09 20:16:36 -0700148 clear_fixmap(idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 set_fixmap(idx, phys);
150 mapped_size += PAGE_SIZE;
151 }
152
Len Brown4be44fc2005-08-05 00:44:28 -0400153 return ((unsigned char *)base + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156#ifdef CONFIG_PCI_MMCONFIG
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700157/* The physical address of the MMCONFIG aperture. Set from ACPI tables. */
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300158struct acpi_mcfg_allocation *pci_mmcfg_config;
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700159int pci_mmcfg_config_num;
160
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300161int __init acpi_parse_mcfg(struct acpi_table_header *header)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162{
163 struct acpi_table_mcfg *mcfg;
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700164 unsigned long i;
165 int config_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300167 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 return -EINVAL;
169
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300170 mcfg = (struct acpi_table_mcfg *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700172 /* how many config structures do we have */
173 pci_mmcfg_config_num = 0;
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300174 i = header->length - sizeof(struct acpi_table_mcfg);
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300175 while (i >= sizeof(struct acpi_mcfg_allocation)) {
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700176 ++pci_mmcfg_config_num;
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300177 i -= sizeof(struct acpi_mcfg_allocation);
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700178 };
179 if (pci_mmcfg_config_num == 0) {
180 printk(KERN_ERR PREFIX "MMCONFIG has no entries\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 return -ENODEV;
182 }
183
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700184 config_size = pci_mmcfg_config_num * sizeof(*pci_mmcfg_config);
185 pci_mmcfg_config = kmalloc(config_size, GFP_KERNEL);
186 if (!pci_mmcfg_config) {
187 printk(KERN_WARNING PREFIX
188 "No memory for MCFG config tables\n");
189 return -ENOMEM;
190 }
191
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300192 memcpy(pci_mmcfg_config, &mcfg[1], config_size);
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700193 for (i = 0; i < pci_mmcfg_config_num; ++i) {
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300194 if (pci_mmcfg_config[i].address > 0xFFFFFFFF) {
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700195 printk(KERN_ERR PREFIX
196 "MMCONFIG not in low 4GB of memory\n");
Konrad Rzeszutekacc7c2e2006-06-15 12:08:30 -0400197 kfree(pci_mmcfg_config);
198 pci_mmcfg_config_num = 0;
Greg Kroah-Hartman54549392005-06-23 17:35:56 -0700199 return -ENODEV;
200 }
201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203 return 0;
204}
Len Brown4be44fc2005-08-05 00:44:28 -0400205#endif /* CONFIG_PCI_MMCONFIG */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
207#ifdef CONFIG_X86_LOCAL_APIC
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300208static int __init acpi_parse_madt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
Len Brown4be44fc2005-08-05 00:44:28 -0400210 struct acpi_table_madt *madt = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300212 if (!cpu_has_apic)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 return -EINVAL;
214
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300215 madt = (struct acpi_table_madt *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 if (!madt) {
217 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
218 return -ENODEV;
219 }
220
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300221 if (madt->address) {
222 acpi_lapic_addr = (u64) madt->address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
224 printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300225 madt->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 }
227
228 acpi_madt_oem_check(madt->header.oem_id, madt->header.oem_table_id);
Len Brown4be44fc2005-08-05 00:44:28 -0400229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 return 0;
231}
232
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400233static void __cpuinit acpi_register_lapic(int id, u8 enabled)
234{
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700235 unsigned int ver = 0;
236
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400237 if (!enabled) {
238 ++disabled_cpus;
239 return;
240 }
241
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700242#ifdef CONFIG_X86_32
243 if (boot_cpu_physical_apicid != -1U)
244 ver = apic_version[boot_cpu_physical_apicid];
245#endif
246
247 generic_processor_info(id, ver);
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400248}
249
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300251acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300253 struct acpi_madt_local_apic *processor = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300255 processor = (struct acpi_madt_local_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257 if (BAD_MADT_ENTRY(processor, end))
258 return -EINVAL;
259
260 acpi_table_print_madt_entry(header);
261
Ashok Raj7f66ae42006-02-03 21:51:50 +0100262 /*
263 * We need to register disabled CPU as well to permit
264 * counting disabled CPUs. This allows us to size
265 * cpus_possible_map more accurately, to permit
266 * to not preallocating memory for all NR_CPUS
267 * when we use CPU hotplug.
268 */
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400269 acpi_register_lapic(processor->id, /* APIC ID */
270 processor->lapic_flags & ACPI_MADT_ENABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
272 return 0;
273}
274
275static int __init
Jack Steinerac049c12008-03-28 14:12:09 -0500276acpi_parse_sapic(struct acpi_subtable_header *header, const unsigned long end)
277{
278 struct acpi_madt_local_sapic *processor = NULL;
279
280 processor = (struct acpi_madt_local_sapic *)header;
281
282 if (BAD_MADT_ENTRY(processor, end))
283 return -EINVAL;
284
285 acpi_table_print_madt_entry(header);
286
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400287 acpi_register_lapic((processor->id << 8) | processor->eid,/* APIC ID */
288 processor->lapic_flags & ACPI_MADT_ENABLED);
Jack Steinerac049c12008-03-28 14:12:09 -0500289
290 return 0;
291}
292
293static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300294acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400295 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300297 struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300299 lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301 if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
302 return -EINVAL;
303
304 acpi_lapic_addr = lapic_addr_ovr->address;
305
306 return 0;
307}
308
309static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300310acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300312 struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300314 lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316 if (BAD_MADT_ENTRY(lapic_nmi, end))
317 return -EINVAL;
318
319 acpi_table_print_madt_entry(header);
320
321 if (lapic_nmi->lint != 1)
322 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
323
324 return 0;
325}
326
Len Brown4be44fc2005-08-05 00:44:28 -0400327#endif /*CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Len Brown84663612005-08-24 12:09:07 -0400329#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
331static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300332acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300334 struct acpi_madt_io_apic *ioapic = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300336 ioapic = (struct acpi_madt_io_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
338 if (BAD_MADT_ENTRY(ioapic, end))
339 return -EINVAL;
Len Brown4be44fc2005-08-05 00:44:28 -0400340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 acpi_table_print_madt_entry(header);
342
Len Brown4be44fc2005-08-05 00:44:28 -0400343 mp_register_ioapic(ioapic->id,
344 ioapic->address, ioapic->global_irq_base);
345
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 return 0;
347}
348
349/*
350 * Parse Interrupt Source Override for the ACPI SCI
351 */
Len Browne82c3542006-12-21 01:29:59 -0500352static void __init acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353{
354 if (trigger == 0) /* compatible SCI trigger is level */
355 trigger = 3;
356
357 if (polarity == 0) /* compatible SCI polarity is low */
358 polarity = 3;
359
360 /* Command-line over-ride via acpi_sci= */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300361 if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
362 trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300364 if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
365 polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367 /*
Len Brown4be44fc2005-08-05 00:44:28 -0400368 * mp_config_acpi_legacy_irqs() already setup IRQs < 16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 * If GSI is < 16, this will update its flags,
370 * else it will create a new mp_irqs[] entry.
371 */
Len Brown7bdd21c2006-12-02 02:27:46 -0500372 mp_override_legacy_irq(gsi, polarity, trigger, gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374 /*
375 * stash over-ride to indicate we've been here
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300376 * and for later update of acpi_gbl_FADT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 */
Len Brown7bdd21c2006-12-02 02:27:46 -0500378 acpi_sci_override_gsi = gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 return;
380}
381
382static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300383acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400384 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300386 struct acpi_madt_interrupt_override *intsrc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300388 intsrc = (struct acpi_madt_interrupt_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
390 if (BAD_MADT_ENTRY(intsrc, end))
391 return -EINVAL;
392
393 acpi_table_print_madt_entry(header);
394
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300395 if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
Len Brown7bdd21c2006-12-02 02:27:46 -0500396 acpi_sci_ioapic_setup(intsrc->global_irq,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300397 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
398 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 return 0;
400 }
401
402 if (acpi_skip_timer_override &&
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300403 intsrc->source_irq == 0 && intsrc->global_irq == 2) {
Len Brown4be44fc2005-08-05 00:44:28 -0400404 printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
405 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 }
407
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300408 mp_override_legacy_irq(intsrc->source_irq,
409 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
410 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
411 intsrc->global_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 return 0;
414}
415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300417acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300419 struct acpi_madt_nmi_source *nmi_src = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300421 nmi_src = (struct acpi_madt_nmi_source *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423 if (BAD_MADT_ENTRY(nmi_src, end))
424 return -EINVAL;
425
426 acpi_table_print_madt_entry(header);
427
428 /* TBD: Support nimsrc entries? */
429
430 return 0;
431}
432
Len Brown4be44fc2005-08-05 00:44:28 -0400433#endif /* CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435/*
436 * acpi_pic_sci_set_trigger()
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300437 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 * use ELCR to set PIC-mode trigger type for SCI
439 *
440 * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
441 * it may require Edge Trigger -- use "acpi_sci=edge"
442 *
443 * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
444 * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
Simon Arlott27b46d72007-10-20 01:13:56 +0200445 * ECLR1 is IRQs 0-7 (IRQ 0, 1, 2 must be 0)
446 * ECLR2 is IRQs 8-15 (IRQ 8, 13 must be 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 */
448
Len Brown4be44fc2005-08-05 00:44:28 -0400449void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450{
451 unsigned int mask = 1 << irq;
452 unsigned int old, new;
453
454 /* Real old ELCR mask */
455 old = inb(0x4d0) | (inb(0x4d1) << 8);
456
457 /*
Simon Arlott27b46d72007-10-20 01:13:56 +0200458 * If we use ACPI to set PCI IRQs, then we should clear ELCR
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 * since we will set it correctly as we enable the PCI irq
460 * routing.
461 */
462 new = acpi_noirq ? old : 0;
463
464 /*
465 * Update SCI information in the ELCR, it isn't in the PCI
466 * routing tables..
467 */
468 switch (trigger) {
Len Brown4be44fc2005-08-05 00:44:28 -0400469 case 1: /* Edge - clear */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 new &= ~mask;
471 break;
Len Brown4be44fc2005-08-05 00:44:28 -0400472 case 3: /* Level - set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 new |= mask;
474 break;
475 }
476
477 if (old == new)
478 return;
479
480 printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
481 outb(new, 0x4d0);
482 outb(new >> 8, 0x4d1);
483}
484
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
486{
Eric W. Biedermanf023d762006-10-04 02:16:52 -0700487 *irq = gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 return 0;
489}
490
Kenji Kaneshige1f3a6a12005-07-28 14:42:00 -0400491/*
492 * success: return IRQ number (>=0)
493 * failure: return < 0
494 */
Len Browncb654692005-12-28 02:43:51 -0500495int acpi_register_gsi(u32 gsi, int triggering, int polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
497 unsigned int irq;
498 unsigned int plat_gsi = gsi;
499
500#ifdef CONFIG_PCI
501 /*
502 * Make sure all (legacy) PCI IRQs are set as level-triggered.
503 */
504 if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
Len Browncb654692005-12-28 02:43:51 -0500505 if (triggering == ACPI_LEVEL_SENSITIVE)
Len Brown4be44fc2005-08-05 00:44:28 -0400506 eisa_set_level_irq(gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 }
508#endif
509
510#ifdef CONFIG_X86_IO_APIC
511 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) {
Len Browncb654692005-12-28 02:43:51 -0500512 plat_gsi = mp_register_gsi(gsi, triggering, polarity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 }
514#endif
515 acpi_gsi_to_irq(plat_gsi, &irq);
516 return irq;
517}
Len Brown4be44fc2005-08-05 00:44:28 -0400518
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519/*
520 * ACPI based hotplug support for CPU
521 */
522#ifdef CONFIG_ACPI_HOTPLUG_CPU
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;
Ashok Raj73fea172006-09-26 10:52:35 +0200529 cpumask_t tmp_map, new_map;
530 u8 physid;
531 int cpu;
532
533 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
534 return -EINVAL;
535
536 if (!buffer.length || !buffer.pointer)
537 return -EINVAL;
538
539 obj = buffer.pointer;
540 if (obj->type != ACPI_TYPE_BUFFER ||
541 obj->buffer.length < sizeof(*lapic)) {
542 kfree(buffer.pointer);
543 return -EINVAL;
544 }
545
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300546 lapic = (struct acpi_madt_local_apic *)obj->buffer.pointer;
Ashok Raj73fea172006-09-26 10:52:35 +0200547
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300548 if (lapic->header.type != ACPI_MADT_TYPE_LOCAL_APIC ||
549 !(lapic->lapic_flags & ACPI_MADT_ENABLED)) {
Ashok Raj73fea172006-09-26 10:52:35 +0200550 kfree(buffer.pointer);
551 return -EINVAL;
552 }
553
554 physid = lapic->id;
555
556 kfree(buffer.pointer);
557 buffer.length = ACPI_ALLOCATE_BUFFER;
558 buffer.pointer = NULL;
559
560 tmp_map = cpu_present_map;
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400561 acpi_register_lapic(physid, lapic->lapic_flags & ACPI_MADT_ENABLED);
Ashok Raj73fea172006-09-26 10:52:35 +0200562
563 /*
564 * If mp_register_lapic successfully generates a new logical cpu
565 * number, then the following will get us exactly what was mapped
566 */
567 cpus_andnot(new_map, cpu_present_map, tmp_map);
568 if (cpus_empty(new_map)) {
569 printk ("Unable to map lapic to logical cpu number\n");
570 return -EINVAL;
571 }
572
573 cpu = first_cpu(new_map);
574
575 *pcpu = cpu;
576 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577}
Len Brown4be44fc2005-08-05 00:44:28 -0400578
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100579/* wrapper to silence section mismatch warning */
580int __ref acpi_map_lsapic(acpi_handle handle, int *pcpu)
581{
582 return _acpi_map_lsapic(handle, pcpu);
583}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584EXPORT_SYMBOL(acpi_map_lsapic);
585
Len Brown4be44fc2005-08-05 00:44:28 -0400586int acpi_unmap_lsapic(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587{
Mike Travis71fff5e2007-10-19 20:35:03 +0200588 per_cpu(x86_cpu_to_apicid, cpu) = -1;
Ashok Raj73fea172006-09-26 10:52:35 +0200589 cpu_clear(cpu, cpu_present_map);
590 num_processors--;
591
592 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593}
Len Brown4be44fc2005-08-05 00:44:28 -0400594
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595EXPORT_SYMBOL(acpi_unmap_lsapic);
Len Brown4be44fc2005-08-05 00:44:28 -0400596#endif /* CONFIG_ACPI_HOTPLUG_CPU */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Len Brown4be44fc2005-08-05 00:44:28 -0400598int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700599{
600 /* TBD */
601 return -EINVAL;
602}
Len Brown4be44fc2005-08-05 00:44:28 -0400603
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700604EXPORT_SYMBOL(acpi_register_ioapic);
605
Len Brown4be44fc2005-08-05 00:44:28 -0400606int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700607{
608 /* TBD */
609 return -EINVAL;
610}
Len Brown4be44fc2005-08-05 00:44:28 -0400611
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700612EXPORT_SYMBOL(acpi_unregister_ioapic);
613
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300614static int __init acpi_parse_sbf(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300616 struct acpi_table_boot *sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300618 sb = (struct acpi_table_boot *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 if (!sb) {
620 printk(KERN_WARNING PREFIX "Unable to map SBF\n");
621 return -ENODEV;
622 }
623
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300624 sbf_port = sb->cmos_index; /* Save CMOS port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
626 return 0;
627}
628
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629#ifdef CONFIG_HPET_TIMER
john stultz2d0c87c2007-02-16 01:28:18 -0800630#include <asm/hpet.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
Aaron Durbina1dfd852007-07-21 17:11:39 +0200632static struct __initdata resource *hpet_res;
633
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300634static int __init acpi_parse_hpet(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635{
636 struct acpi_table_hpet *hpet_tbl;
637
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300638 hpet_tbl = (struct acpi_table_hpet *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 if (!hpet_tbl) {
640 printk(KERN_WARNING PREFIX "Unable to map HPET\n");
641 return -ENODEV;
642 }
643
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300644 if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 printk(KERN_WARNING PREFIX "HPET timers must be located in "
646 "memory.\n");
647 return -1;
648 }
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200649
john stultz2d0c87c2007-02-16 01:28:18 -0800650 hpet_address = hpet_tbl->address.address;
Thomas Gleixnerf4df73c2007-11-15 21:41:50 -0500651
652 /*
653 * Some broken BIOSes advertise HPET at 0x0. We really do not
654 * want to allocate a resource there.
655 */
656 if (!hpet_address) {
657 printk(KERN_WARNING PREFIX
658 "HPET id: %#x base: %#lx is invalid\n",
659 hpet_tbl->id, hpet_address);
660 return 0;
661 }
662#ifdef CONFIG_X86_64
663 /*
664 * Some even more broken BIOSes advertise HPET at
665 * 0xfed0000000000000 instead of 0xfed00000. Fix it up and add
666 * some noise:
667 */
668 if (hpet_address == 0xfed0000000000000UL) {
669 if (!hpet_force_user) {
670 printk(KERN_WARNING PREFIX "HPET id: %#x "
671 "base: 0xfed0000000000000 is bogus\n "
672 "try hpet=force on the kernel command line to "
673 "fix it up to 0xfed00000.\n", hpet_tbl->id);
674 hpet_address = 0;
675 return 0;
676 }
677 printk(KERN_WARNING PREFIX
678 "HPET id: %#x base: 0xfed0000000000000 fixed up "
679 "to 0xfed00000.\n", hpet_tbl->id);
680 hpet_address >>= 32;
681 }
682#endif
Len Brown4be44fc2005-08-05 00:44:28 -0400683 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
john stultz2d0c87c2007-02-16 01:28:18 -0800684 hpet_tbl->id, hpet_address);
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200685
Aaron Durbina1dfd852007-07-21 17:11:39 +0200686 /*
687 * Allocate and initialize the HPET firmware resource for adding into
688 * the resource tree during the lateinit timeframe.
689 */
690#define HPET_RESOURCE_NAME_SIZE 9
691 hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
692
Aaron Durbina1dfd852007-07-21 17:11:39 +0200693 hpet_res->name = (void *)&hpet_res[1];
694 hpet_res->flags = IORESOURCE_MEM;
695 snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE, "HPET %u",
696 hpet_tbl->sequence);
697
698 hpet_res->start = hpet_address;
699 hpet_res->end = hpet_address + (1 * 1024) - 1;
700
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 return 0;
702}
Aaron Durbina1dfd852007-07-21 17:11:39 +0200703
704/*
705 * hpet_insert_resource inserts the HPET resources used into the resource
706 * tree.
707 */
708static __init int hpet_insert_resource(void)
709{
710 if (!hpet_res)
711 return 1;
712
713 return insert_resource(&iomem_resource, hpet_res);
714}
715
716late_initcall(hpet_insert_resource);
717
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718#else
719#define acpi_parse_hpet NULL
720#endif
721
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300722static int __init acpi_parse_fadt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723{
Jason Davis90660ec2005-04-16 15:24:53 -0700724
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725#ifdef CONFIG_X86_PM_TIMER
726 /* detect the location of the ACPI PM Timer */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300727 if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 /* FADT rev. 2 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300729 if (acpi_gbl_FADT.xpm_timer_block.space_id !=
Len Brown4be44fc2005-08-05 00:44:28 -0400730 ACPI_ADR_SPACE_SYSTEM_IO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 return 0;
732
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300733 pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
David Shaohua Lie6e87b42005-09-21 01:35:00 -0400734 /*
735 * "X" fields are optional extensions to the original V1.0
736 * fields, so we must selectively expand V1.0 fields if the
737 * corresponding X field is zero.
738 */
739 if (!pmtmr_ioport)
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300740 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 } else {
742 /* FADT rev. 1 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300743 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 }
745 if (pmtmr_ioport)
Len Brown4be44fc2005-08-05 00:44:28 -0400746 printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
747 pmtmr_ioport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748#endif
749 return 0;
750}
751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752#ifdef CONFIG_X86_LOCAL_APIC
753/*
754 * Parse LAPIC entries in MADT
755 * returns 0 on success, < 0 on error
756 */
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400757
758static void __init acpi_register_lapic_address(unsigned long address)
759{
760 mp_lapic_addr = address;
761
762 set_fixmap_nocache(FIX_APIC_BASE, address);
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700763 if (boot_cpu_physical_apicid == -1U) {
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400764 boot_cpu_physical_apicid = GET_APIC_ID(read_apic_id());
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700765#ifdef CONFIG_X86_32
766 apic_version[boot_cpu_physical_apicid] =
767 GET_APIC_VERSION(apic_read(APIC_LVR));
768#endif
769 }
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400770}
771
Yinghai Lucbf9bd62008-02-19 03:21:06 -0800772static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
773{
774 int count;
775
776 if (!cpu_has_apic)
777 return -ENODEV;
778
779 /*
780 * Note that the LAPIC address is obtained from the MADT (32-bit value)
781 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
782 */
783
784 count =
785 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
786 acpi_parse_lapic_addr_ovr, 0);
787 if (count < 0) {
788 printk(KERN_ERR PREFIX
789 "Error parsing LAPIC address override entry\n");
790 return count;
791 }
792
793 acpi_register_lapic_address(acpi_lapic_addr);
794
795 return count;
796}
797
Len Brown4be44fc2005-08-05 00:44:28 -0400798static int __init acpi_parse_madt_lapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799{
800 int count;
801
Andi Kleen0fcd2702006-04-11 12:54:36 +0200802 if (!cpu_has_apic)
803 return -ENODEV;
804
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300805 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 * 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
Len Brown4be44fc2005-08-05 00:44:28 -0400810 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300811 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
Len Brown4be44fc2005-08-05 00:44:28 -0400812 acpi_parse_lapic_addr_ovr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 if (count < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400814 printk(KERN_ERR PREFIX
815 "Error parsing LAPIC address override entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 return count;
817 }
818
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400819 acpi_register_lapic_address(acpi_lapic_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
Jack Steinerac049c12008-03-28 14:12:09 -0500821 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
822 acpi_parse_sapic, MAX_APICS);
823
824 if (!count)
825 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
826 acpi_parse_lapic, MAX_APICS);
Len Brown4be44fc2005-08-05 00:44:28 -0400827 if (!count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
829 /* TBD: Cleanup to allow fallback to MPS */
830 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400831 } else if (count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
833 /* TBD: Cleanup to allow fallback to MPS */
834 return count;
835 }
836
Len Brown4be44fc2005-08-05 00:44:28 -0400837 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300838 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 if (count < 0) {
840 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
841 /* TBD: Cleanup to allow fallback to MPS */
842 return count;
843 }
844 return 0;
845}
Len Brown4be44fc2005-08-05 00:44:28 -0400846#endif /* CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
Len Brown84663612005-08-24 12:09:07 -0400848#ifdef CONFIG_X86_IO_APIC
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400849#define MP_ISA_BUS 0
850
Yinghai Lud49c4282008-06-08 18:31:54 -0700851#ifdef CONFIG_X86_ES7000
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400852extern int es7000_plat;
853#endif
854
Alexey Starikovskiy5f895142008-05-14 19:03:04 +0400855static struct {
856 int apic_id;
857 int gsi_base;
858 int gsi_end;
859 DECLARE_BITMAP(pin_programmed, MP_MAX_IOAPIC_PIN + 1);
860} mp_ioapic_routing[MAX_IO_APICS];
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400861
862static int mp_find_ioapic(int gsi)
863{
864 int i = 0;
865
866 /* Find the IOAPIC that manages this GSI. */
867 for (i = 0; i < nr_ioapics; i++) {
868 if ((gsi >= mp_ioapic_routing[i].gsi_base)
869 && (gsi <= mp_ioapic_routing[i].gsi_end))
870 return i;
871 }
872
873 printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
874 return -1;
875}
876
877static u8 __init uniq_ioapic_id(u8 id)
878{
879#ifdef CONFIG_X86_32
880 if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
881 !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
882 return io_apic_get_unique_id(nr_ioapics, id);
883 else
884 return id;
885#else
886 int i;
887 DECLARE_BITMAP(used, 256);
888 bitmap_zero(used, 256);
889 for (i = 0; i < nr_ioapics; i++) {
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400890 struct mp_config_ioapic *ia = &mp_ioapics[i];
891 __set_bit(ia->mp_apicid, used);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400892 }
893 if (!test_bit(id, used))
894 return id;
895 return find_first_zero_bit(used, 256);
896#endif
897}
898
899static int bad_ioapic(unsigned long address)
900{
901 if (nr_ioapics >= MAX_IO_APICS) {
902 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
903 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
904 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
905 }
906 if (!address) {
907 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
908 " found in table, skipping!\n");
909 return 1;
910 }
911 return 0;
912}
913
914void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
915{
916 int idx = 0;
917
918 if (bad_ioapic(address))
919 return;
920
921 idx = nr_ioapics;
922
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400923 mp_ioapics[idx].mp_type = MP_IOAPIC;
924 mp_ioapics[idx].mp_flags = MPC_APIC_USABLE;
925 mp_ioapics[idx].mp_apicaddr = address;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400926
927 set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400928 mp_ioapics[idx].mp_apicid = uniq_ioapic_id(id);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400929#ifdef CONFIG_X86_32
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400930 mp_ioapics[idx].mp_apicver = io_apic_get_version(idx);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400931#else
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400932 mp_ioapics[idx].mp_apicver = 0;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400933#endif
934 /*
935 * Build basic GSI lookup table to facilitate gsi->io_apic lookups
936 * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
937 */
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400938 mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].mp_apicid;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400939 mp_ioapic_routing[idx].gsi_base = gsi_base;
940 mp_ioapic_routing[idx].gsi_end = gsi_base +
941 io_apic_get_redir_entries(idx);
942
Alexey Starikovskiyec2cd0a2008-05-14 19:03:10 +0400943 printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%lx, "
944 "GSI %d-%d\n", idx, mp_ioapics[idx].mp_apicid,
945 mp_ioapics[idx].mp_apicver, mp_ioapics[idx].mp_apicaddr,
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400946 mp_ioapic_routing[idx].gsi_base, mp_ioapic_routing[idx].gsi_end);
947
948 nr_ioapics++;
949}
950
Yinghai Lufcfa1462008-06-18 17:29:31 -0700951static void assign_to_mp_irq(struct mp_config_intsrc *m,
952 struct mp_config_intsrc *mp_irq)
953{
954 memcpy(mp_irq, m, sizeof(struct mp_config_intsrc));
955}
956
957static int mp_irq_cmp(struct mp_config_intsrc *mp_irq,
958 struct mp_config_intsrc *m)
959{
960 return memcmp(mp_irq, m, sizeof(struct mp_config_intsrc));
961}
962
963static void save_mp_irq(struct mp_config_intsrc *m)
964{
965 int i;
966
967 for (i = 0; i < mp_irq_entries; i++) {
968 if (!mp_irq_cmp(&mp_irqs[i], m))
969 return;
970 }
971
972 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
973 if (++mp_irq_entries == MAX_IRQ_SOURCES)
974 panic("Max # of irq sources exceeded!!\n");
975}
976
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400977void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
978{
Yinghai Lu6df88092008-06-15 18:19:46 -0700979 int ioapic;
980 int pin;
Yinghai Lufcfa1462008-06-18 17:29:31 -0700981 struct mp_config_intsrc mp_irq;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +0400982
983 /*
984 * Convert 'gsi' to 'ioapic.pin'.
985 */
986 ioapic = mp_find_ioapic(gsi);
987 if (ioapic < 0)
988 return;
989 pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
990
991 /*
992 * TBD: This check is for faulty timer entries, where the override
993 * erroneously sets the trigger to level, resulting in a HUGE
994 * increase of timer interrupts!
995 */
996 if ((bus_irq == 0) && (trigger == 3))
997 trigger = 1;
998
Yinghai Lufcfa1462008-06-18 17:29:31 -0700999 mp_irq.mp_type = MP_INTSRC;
1000 mp_irq.mp_irqtype = mp_INT;
1001 mp_irq.mp_irqflag = (trigger << 2) | polarity;
1002 mp_irq.mp_srcbus = MP_ISA_BUS;
1003 mp_irq.mp_srcbusirq = bus_irq; /* IRQ */
1004 mp_irq.mp_dstapic = mp_ioapics[ioapic].mp_apicid; /* APIC ID */
1005 mp_irq.mp_dstirq = pin; /* INTIN# */
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001006
Yinghai Lufcfa1462008-06-18 17:29:31 -07001007 save_mp_irq(&mp_irq);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001008}
1009
1010void __init mp_config_acpi_legacy_irqs(void)
1011{
Yinghai Lu6df88092008-06-15 18:19:46 -07001012 int i;
1013 int ioapic;
1014 unsigned int dstapic;
Yinghai Lufcfa1462008-06-18 17:29:31 -07001015 struct mp_config_intsrc mp_irq;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001016
1017#if defined (CONFIG_MCA) || defined (CONFIG_EISA)
1018 /*
1019 * Fabricate the legacy ISA bus (bus #31).
1020 */
1021 mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
1022#endif
1023 set_bit(MP_ISA_BUS, mp_bus_not_pci);
Thomas Gleixnercfc1b9a2008-07-21 21:35:38 +02001024 pr_debug("Bus #%d is ISA\n", MP_ISA_BUS);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001025
Yinghai Lud49c4282008-06-08 18:31:54 -07001026#ifdef CONFIG_X86_ES7000
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001027 /*
1028 * Older generations of ES7000 have no legacy identity mappings
1029 */
1030 if (es7000_plat == 1)
1031 return;
1032#endif
1033
1034 /*
1035 * Locate the IOAPIC that manages the ISA IRQs (0-15).
1036 */
1037 ioapic = mp_find_ioapic(0);
1038 if (ioapic < 0)
1039 return;
Yinghai Lu6df88092008-06-15 18:19:46 -07001040 dstapic = mp_ioapics[ioapic].mp_apicid;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001041
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001042 /*
1043 * Use the default configuration for the IRQs 0-15. Unless
1044 * overridden by (MADT) interrupt source override entries.
1045 */
1046 for (i = 0; i < 16; i++) {
1047 int idx;
1048
1049 for (idx = 0; idx < mp_irq_entries; idx++) {
Alexey Starikovskiy2fddb6e282008-05-14 19:03:17 +04001050 struct mp_config_intsrc *irq = mp_irqs + idx;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001051
1052 /* Do we already have a mapping for this ISA IRQ? */
Alexey Starikovskiy2fddb6e282008-05-14 19:03:17 +04001053 if (irq->mp_srcbus == MP_ISA_BUS
1054 && irq->mp_srcbusirq == i)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001055 break;
1056
1057 /* Do we already have a mapping for this IOAPIC pin */
Yinghai Lu6df88092008-06-15 18:19:46 -07001058 if (irq->mp_dstapic == dstapic &&
1059 irq->mp_dstirq == i)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001060 break;
1061 }
1062
1063 if (idx != mp_irq_entries) {
1064 printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
1065 continue; /* IRQ already used */
1066 }
1067
Yinghai Lufcfa1462008-06-18 17:29:31 -07001068 mp_irq.mp_type = MP_INTSRC;
1069 mp_irq.mp_irqflag = 0; /* Conforming */
1070 mp_irq.mp_srcbus = MP_ISA_BUS;
1071 mp_irq.mp_dstapic = dstapic;
1072 mp_irq.mp_irqtype = mp_INT;
1073 mp_irq.mp_srcbusirq = i; /* Identity mapped */
1074 mp_irq.mp_dstirq = i;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001075
Yinghai Lufcfa1462008-06-18 17:29:31 -07001076 save_mp_irq(&mp_irq);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001077 }
1078}
1079
1080int mp_register_gsi(u32 gsi, int triggering, int polarity)
1081{
1082 int ioapic;
1083 int ioapic_pin;
1084#ifdef CONFIG_X86_32
1085#define MAX_GSI_NUM 4096
1086#define IRQ_COMPRESSION_START 64
1087
1088 static int pci_irq = IRQ_COMPRESSION_START;
1089 /*
1090 * Mapping between Global System Interrupts, which
1091 * represent all possible interrupts, and IRQs
1092 * assigned to actual devices.
1093 */
1094 static int gsi_to_irq[MAX_GSI_NUM];
1095#else
1096
1097 if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
1098 return gsi;
1099#endif
1100
1101 /* Don't set up the ACPI SCI because it's already set up */
1102 if (acpi_gbl_FADT.sci_interrupt == gsi)
1103 return gsi;
1104
1105 ioapic = mp_find_ioapic(gsi);
1106 if (ioapic < 0) {
1107 printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
1108 return gsi;
1109 }
1110
1111 ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
1112
1113#ifdef CONFIG_X86_32
1114 if (ioapic_renumber_irq)
1115 gsi = ioapic_renumber_irq(ioapic, gsi);
1116#endif
1117
1118 /*
1119 * Avoid pin reprogramming. PRTs typically include entries
1120 * with redundant pin->gsi mappings (but unique PCI devices);
1121 * we only program the IOAPIC on the first.
1122 */
1123 if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
1124 printk(KERN_ERR "Invalid reference to IOAPIC pin "
1125 "%d-%d\n", mp_ioapic_routing[ioapic].apic_id,
1126 ioapic_pin);
1127 return gsi;
1128 }
1129 if (test_bit(ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed)) {
Thomas Gleixnercfc1b9a2008-07-21 21:35:38 +02001130 pr_debug(KERN_DEBUG "Pin %d-%d already programmed\n",
1131 mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001132#ifdef CONFIG_X86_32
1133 return (gsi < IRQ_COMPRESSION_START ? gsi : gsi_to_irq[gsi]);
1134#else
1135 return gsi;
1136#endif
1137 }
1138
1139 set_bit(ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed);
1140#ifdef CONFIG_X86_32
1141 /*
1142 * For GSI >= 64, use IRQ compression
1143 */
1144 if ((gsi >= IRQ_COMPRESSION_START)
1145 && (triggering == ACPI_LEVEL_SENSITIVE)) {
1146 /*
1147 * For PCI devices assign IRQs in order, avoiding gaps
1148 * due to unused I/O APIC pins.
1149 */
1150 int irq = gsi;
1151 if (gsi < MAX_GSI_NUM) {
1152 /*
1153 * Retain the VIA chipset work-around (gsi > 15), but
1154 * avoid a problem where the 8254 timer (IRQ0) is setup
1155 * via an override (so it's not on pin 0 of the ioapic),
1156 * and at the same time, the pin 0 interrupt is a PCI
1157 * type. The gsi > 15 test could cause these two pins
1158 * to be shared as IRQ0, and they are not shareable.
1159 * So test for this condition, and if necessary, avoid
1160 * the pin collision.
1161 */
1162 gsi = pci_irq++;
1163 /*
1164 * Don't assign IRQ used by ACPI SCI
1165 */
1166 if (gsi == acpi_gbl_FADT.sci_interrupt)
1167 gsi = pci_irq++;
1168 gsi_to_irq[irq] = gsi;
1169 } else {
1170 printk(KERN_ERR "GSI %u is too high\n", gsi);
1171 return gsi;
1172 }
1173 }
1174#endif
1175 io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
1176 triggering == ACPI_EDGE_SENSITIVE ? 0 : 1,
1177 polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
1178 return gsi;
1179}
1180
Yinghai Lu2944e162008-06-01 13:17:38 -07001181int mp_config_acpi_gsi(unsigned char number, unsigned int devfn, u8 pin,
1182 u32 gsi, int triggering, int polarity)
1183{
Yinghai Lufcfa1462008-06-18 17:29:31 -07001184#ifdef CONFIG_X86_MPPARSE
1185 struct mp_config_intsrc mp_irq;
Yinghai Lu2944e162008-06-01 13:17:38 -07001186 int ioapic;
1187
Yinghai Lufcfa1462008-06-18 17:29:31 -07001188 if (!acpi_ioapic)
Yinghai Lud867e532008-06-14 01:26:41 -07001189 return 0;
1190
Yinghai Lu2944e162008-06-01 13:17:38 -07001191 /* print the entry should happen on mptable identically */
Yinghai Lufcfa1462008-06-18 17:29:31 -07001192 mp_irq.mp_type = MP_INTSRC;
1193 mp_irq.mp_irqtype = mp_INT;
1194 mp_irq.mp_irqflag = (triggering == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
Yinghai Lu2944e162008-06-01 13:17:38 -07001195 (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
Yinghai Lufcfa1462008-06-18 17:29:31 -07001196 mp_irq.mp_srcbus = number;
1197 mp_irq.mp_srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
Yinghai Lu2944e162008-06-01 13:17:38 -07001198 ioapic = mp_find_ioapic(gsi);
Yinghai Lufcfa1462008-06-18 17:29:31 -07001199 mp_irq.mp_dstapic = mp_ioapic_routing[ioapic].apic_id;
1200 mp_irq.mp_dstirq = gsi - mp_ioapic_routing[ioapic].gsi_base;
Yinghai Lu2944e162008-06-01 13:17:38 -07001201
Yinghai Lufcfa1462008-06-18 17:29:31 -07001202 save_mp_irq(&mp_irq);
1203#endif
Yinghai Lu2944e162008-06-01 13:17:38 -07001204 return 0;
1205}
1206
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207/*
1208 * Parse IOAPIC related entries in MADT
1209 * returns 0 on success, < 0 on error
1210 */
Len Brown4be44fc2005-08-05 00:44:28 -04001211static int __init acpi_parse_madt_ioapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212{
1213 int count;
1214
1215 /*
1216 * ACPI interpreter is required to complete interrupt setup,
1217 * so if it is off, don't enumerate the io-apics with ACPI.
1218 * If MPS is present, it will handle them,
1219 * otherwise the system will stay in PIC mode
1220 */
1221 if (acpi_disabled || acpi_noirq) {
1222 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -04001223 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001225 if (!cpu_has_apic)
Andi Kleend3b6a342006-04-07 19:49:39 +02001226 return -ENODEV;
1227
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001229 * if "noapic" boot option, don't look for IO-APICs
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 */
1231 if (skip_ioapic_setup) {
1232 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
Len Brown4be44fc2005-08-05 00:44:28 -04001233 "due to 'noapic' option.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 return -ENODEV;
1235 }
1236
Len Brown4be44fc2005-08-05 00:44:28 -04001237 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001238 acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
Len Brown4be44fc2005-08-05 00:44:28 -04001239 MAX_IO_APICS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 if (!count) {
1241 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
1242 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -04001243 } else if (count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
1245 return count;
1246 }
1247
Len Brown4be44fc2005-08-05 00:44:28 -04001248 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001249 acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr,
Len Brown4be44fc2005-08-05 00:44:28 -04001250 NR_IRQ_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 if (count < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -04001252 printk(KERN_ERR PREFIX
1253 "Error parsing interrupt source overrides entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 /* TBD: Cleanup to allow fallback to MPS */
1255 return count;
1256 }
1257
1258 /*
1259 * If BIOS did not supply an INT_SRC_OVR for the SCI
1260 * pretend we got one so we can set the SCI flags.
1261 */
1262 if (!acpi_sci_override_gsi)
Alexey Starikovskiycee324b2007-02-02 19:48:22 +03001263 acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
1265 /* Fill in identity legacy mapings where no override */
1266 mp_config_acpi_legacy_irqs();
1267
Len Brown4be44fc2005-08-05 00:44:28 -04001268 count =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001269 acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src,
Len Brown4be44fc2005-08-05 00:44:28 -04001270 NR_IRQ_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 if (count < 0) {
1272 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
1273 /* TBD: Cleanup to allow fallback to MPS */
1274 return count;
1275 }
1276
1277 return 0;
1278}
1279#else
1280static inline int acpi_parse_madt_ioapic_entries(void)
1281{
1282 return -1;
1283}
Len Brown84663612005-08-24 12:09:07 -04001284#endif /* !CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001286static void __init early_acpi_process_madt(void)
1287{
1288#ifdef CONFIG_X86_LOCAL_APIC
1289 int error;
1290
1291 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1292
1293 /*
1294 * Parse MADT LAPIC entries
1295 */
1296 error = early_acpi_parse_madt_lapic_addr_ovr();
1297 if (!error) {
1298 acpi_lapic = 1;
1299 smp_found_config = 1;
1300 }
1301 if (error == -EINVAL) {
1302 /*
1303 * Dell Precision Workstation 410, 610 come here.
1304 */
1305 printk(KERN_ERR PREFIX
1306 "Invalid BIOS MADT, disabling ACPI\n");
1307 disable_acpi();
1308 }
1309 }
1310#endif
1311}
1312
Len Brown4be44fc2005-08-05 00:44:28 -04001313static void __init acpi_process_madt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314{
1315#ifdef CONFIG_X86_LOCAL_APIC
Len Brown7f8f97c2007-02-10 21:28:03 -05001316 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Len Brown7f8f97c2007-02-10 21:28:03 -05001318 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
1320 /*
1321 * Parse MADT LAPIC entries
1322 */
1323 error = acpi_parse_madt_lapic_entries();
1324 if (!error) {
1325 acpi_lapic = 1;
1326
Venkatesh Pallipadi911a62d2005-09-03 15:56:31 -07001327#ifdef CONFIG_X86_GENERICARCH
1328 generic_bigsmp_probe();
1329#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 /*
1331 * Parse MADT IO-APIC entries
1332 */
1333 error = acpi_parse_madt_ioapic_entries();
1334 if (!error) {
1335 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
1336 acpi_irq_balance_set(NULL);
1337 acpi_ioapic = 1;
1338
1339 smp_found_config = 1;
Ingo Molnar3c43f032007-05-02 19:27:04 +02001340 setup_apic_routing();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 }
1342 }
1343 if (error == -EINVAL) {
1344 /*
1345 * Dell Precision Workstation 410, 610 come here.
1346 */
Len Brown4be44fc2005-08-05 00:44:28 -04001347 printk(KERN_ERR PREFIX
1348 "Invalid BIOS MADT, disabling ACPI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 disable_acpi();
1350 }
1351 }
1352#endif
1353 return;
1354}
1355
Jeff Garzik18552562007-10-03 15:15:40 -04001356static int __init disable_acpi_irq(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001357{
1358 if (!acpi_force) {
1359 printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
1360 d->ident);
1361 acpi_noirq_set();
1362 }
1363 return 0;
1364}
1365
Jeff Garzik18552562007-10-03 15:15:40 -04001366static int __init disable_acpi_pci(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001367{
1368 if (!acpi_force) {
1369 printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
1370 d->ident);
1371 acpi_disable_pci();
1372 }
1373 return 0;
1374}
Andrey Paninaea00142005-06-25 14:54:42 -07001375
Jeff Garzik18552562007-10-03 15:15:40 -04001376static int __init dmi_disable_acpi(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001377{
1378 if (!acpi_force) {
Len Brown4be44fc2005-08-05 00:44:28 -04001379 printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
Andrey Paninaea00142005-06-25 14:54:42 -07001380 disable_acpi();
1381 } else {
1382 printk(KERN_NOTICE
1383 "Warning: DMI blacklist says broken, but acpi forced\n");
1384 }
1385 return 0;
1386}
1387
1388/*
1389 * Limit ACPI to CPU enumeration for HT
1390 */
Jeff Garzik18552562007-10-03 15:15:40 -04001391static int __init force_acpi_ht(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001392{
1393 if (!acpi_force) {
Len Brown4be44fc2005-08-05 00:44:28 -04001394 printk(KERN_NOTICE "%s detected: force use of acpi=ht\n",
1395 d->ident);
Andrey Paninaea00142005-06-25 14:54:42 -07001396 disable_acpi();
1397 acpi_ht = 1;
1398 } else {
1399 printk(KERN_NOTICE
1400 "Warning: acpi=force overrules DMI blacklist: acpi=ht\n");
1401 }
1402 return 0;
1403}
1404
1405/*
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001406 * Force ignoring BIOS IRQ0 pin2 override
1407 */
1408static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
1409{
1410 pr_notice("%s detected: Ignoring BIOS IRQ0 pin2 override\n", d->ident);
1411 acpi_skip_timer_override = 1;
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001412 return 0;
1413}
1414
1415/*
Andrey Paninaea00142005-06-25 14:54:42 -07001416 * If your system is blacklisted here, but you find that acpi=force
1417 * works for you, please contact acpi-devel@sourceforge.net
1418 */
1419static struct dmi_system_id __initdata acpi_dmi_table[] = {
1420 /*
1421 * Boxes that need ACPI disabled
1422 */
1423 {
Len Brown4be44fc2005-08-05 00:44:28 -04001424 .callback = dmi_disable_acpi,
1425 .ident = "IBM Thinkpad",
1426 .matches = {
1427 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1428 DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
1429 },
1430 },
Andrey Paninaea00142005-06-25 14:54:42 -07001431
1432 /*
1433 * Boxes that need acpi=ht
1434 */
1435 {
Len Brown4be44fc2005-08-05 00:44:28 -04001436 .callback = force_acpi_ht,
1437 .ident = "FSC Primergy T850",
1438 .matches = {
1439 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
1440 DMI_MATCH(DMI_PRODUCT_NAME, "PRIMERGY T850"),
1441 },
1442 },
Andrey Paninaea00142005-06-25 14:54:42 -07001443 {
Len Brown4be44fc2005-08-05 00:44:28 -04001444 .callback = force_acpi_ht,
Len Brown4be44fc2005-08-05 00:44:28 -04001445 .ident = "HP VISUALIZE NT Workstation",
1446 .matches = {
1447 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
1448 DMI_MATCH(DMI_PRODUCT_NAME, "HP VISUALIZE NT Workstation"),
1449 },
1450 },
Andrey Paninaea00142005-06-25 14:54:42 -07001451 {
Len Brown4be44fc2005-08-05 00:44:28 -04001452 .callback = force_acpi_ht,
1453 .ident = "Compaq Workstation W8000",
1454 .matches = {
1455 DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
1456 DMI_MATCH(DMI_PRODUCT_NAME, "Workstation W8000"),
1457 },
1458 },
Andrey Paninaea00142005-06-25 14:54:42 -07001459 {
Len Brown4be44fc2005-08-05 00:44:28 -04001460 .callback = force_acpi_ht,
1461 .ident = "ASUS P4B266",
1462 .matches = {
1463 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1464 DMI_MATCH(DMI_BOARD_NAME, "P4B266"),
1465 },
1466 },
Andrey Paninaea00142005-06-25 14:54:42 -07001467 {
Len Brown4be44fc2005-08-05 00:44:28 -04001468 .callback = force_acpi_ht,
1469 .ident = "ASUS P2B-DS",
1470 .matches = {
1471 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1472 DMI_MATCH(DMI_BOARD_NAME, "P2B-DS"),
1473 },
1474 },
Andrey Paninaea00142005-06-25 14:54:42 -07001475 {
Len Brown4be44fc2005-08-05 00:44:28 -04001476 .callback = force_acpi_ht,
1477 .ident = "ASUS CUR-DLS",
1478 .matches = {
1479 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1480 DMI_MATCH(DMI_BOARD_NAME, "CUR-DLS"),
1481 },
1482 },
Andrey Paninaea00142005-06-25 14:54:42 -07001483 {
Len Brown4be44fc2005-08-05 00:44:28 -04001484 .callback = force_acpi_ht,
1485 .ident = "ABIT i440BX-W83977",
1486 .matches = {
1487 DMI_MATCH(DMI_BOARD_VENDOR, "ABIT <http://www.abit.com>"),
1488 DMI_MATCH(DMI_BOARD_NAME, "i440BX-W83977 (BP6)"),
1489 },
1490 },
Andrey Paninaea00142005-06-25 14:54:42 -07001491 {
Len Brown4be44fc2005-08-05 00:44:28 -04001492 .callback = force_acpi_ht,
1493 .ident = "IBM Bladecenter",
1494 .matches = {
1495 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1496 DMI_MATCH(DMI_BOARD_NAME, "IBM eServer BladeCenter HS20"),
1497 },
1498 },
Andrey Paninaea00142005-06-25 14:54:42 -07001499 {
Len Brown4be44fc2005-08-05 00:44:28 -04001500 .callback = force_acpi_ht,
1501 .ident = "IBM eServer xSeries 360",
1502 .matches = {
1503 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1504 DMI_MATCH(DMI_BOARD_NAME, "eServer xSeries 360"),
1505 },
1506 },
Andrey Paninaea00142005-06-25 14:54:42 -07001507 {
Len Brown4be44fc2005-08-05 00:44:28 -04001508 .callback = force_acpi_ht,
1509 .ident = "IBM eserver xSeries 330",
1510 .matches = {
1511 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1512 DMI_MATCH(DMI_BOARD_NAME, "eserver xSeries 330"),
1513 },
1514 },
Andrey Paninaea00142005-06-25 14:54:42 -07001515 {
Len Brown4be44fc2005-08-05 00:44:28 -04001516 .callback = force_acpi_ht,
1517 .ident = "IBM eserver xSeries 440",
1518 .matches = {
1519 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1520 DMI_MATCH(DMI_PRODUCT_NAME, "eserver xSeries 440"),
1521 },
1522 },
Andrey Paninaea00142005-06-25 14:54:42 -07001523
Andrey Paninaea00142005-06-25 14:54:42 -07001524 /*
1525 * Boxes that need ACPI PCI IRQ routing disabled
1526 */
1527 {
Len Brown4be44fc2005-08-05 00:44:28 -04001528 .callback = disable_acpi_irq,
1529 .ident = "ASUS A7V",
1530 .matches = {
1531 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
1532 DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
1533 /* newer BIOS, Revision 1011, does work */
1534 DMI_MATCH(DMI_BIOS_VERSION,
1535 "ASUS A7V ACPI BIOS Revision 1007"),
1536 },
1537 },
Len Brown74586fc2007-03-08 02:48:30 -05001538 {
1539 /*
1540 * Latest BIOS for IBM 600E (1.16) has bad pcinum
1541 * for LPC bridge, which is needed for the PCI
1542 * interrupt links to work. DSDT fix is in bug 5966.
1543 * 2645, 2646 model numbers are shared with 600/600E/600X
1544 */
1545 .callback = disable_acpi_irq,
1546 .ident = "IBM Thinkpad 600 Series 2645",
1547 .matches = {
1548 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1549 DMI_MATCH(DMI_BOARD_NAME, "2645"),
1550 },
1551 },
1552 {
1553 .callback = disable_acpi_irq,
1554 .ident = "IBM Thinkpad 600 Series 2646",
1555 .matches = {
1556 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1557 DMI_MATCH(DMI_BOARD_NAME, "2646"),
1558 },
1559 },
Andrey Paninaea00142005-06-25 14:54:42 -07001560 /*
1561 * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
1562 */
Len Brown4be44fc2005-08-05 00:44:28 -04001563 { /* _BBN 0 bug */
1564 .callback = disable_acpi_pci,
1565 .ident = "ASUS PR-DLS",
1566 .matches = {
1567 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1568 DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
1569 DMI_MATCH(DMI_BIOS_VERSION,
1570 "ASUS PR-DLS ACPI BIOS Revision 1010"),
1571 DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
1572 },
1573 },
Andrey Paninaea00142005-06-25 14:54:42 -07001574 {
Len Brown4be44fc2005-08-05 00:44:28 -04001575 .callback = disable_acpi_pci,
1576 .ident = "Acer TravelMate 36x Laptop",
1577 .matches = {
1578 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
1579 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
1580 },
1581 },
Matthew Garrett9340e1c2008-07-01 01:12:06 +01001582 /*
1583 * HP laptops which use a DSDT reporting as HP/SB400/10000,
1584 * which includes some code which overrides all temperature
1585 * trip points to 16C if the INTIN2 input of the I/O APIC
1586 * is enabled. This input is incorrectly designated the
1587 * ISA IRQ 0 via an interrupt source override even though
1588 * it is wired to the output of the master 8259A and INTIN0
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001589 * is not connected at all. Force ignoring BIOS IRQ0 pin2
1590 * override in that cases.
1591 */
1592 {
1593 .callback = dmi_ignore_irq0_timer_override,
1594 .ident = "HP NX6125 laptop",
1595 .matches = {
1596 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1597 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
1598 },
1599 },
1600 {
1601 .callback = dmi_ignore_irq0_timer_override,
1602 .ident = "HP NX6325 laptop",
1603 .matches = {
1604 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1605 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
1606 },
1607 },
Len Brown4be44fc2005-08-05 00:44:28 -04001608 {}
Andrey Paninaea00142005-06-25 14:54:42 -07001609};
1610
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611/*
1612 * acpi_boot_table_init() and acpi_boot_init()
1613 * called from setup_arch(), always.
1614 * 1. checksums all tables
1615 * 2. enumerates lapics
1616 * 3. enumerates io-apics
1617 *
1618 * acpi_table_init() is separate to allow reading SRAT without
1619 * other side effects.
1620 *
1621 * side effects of acpi_boot_init:
1622 * acpi_lapic = 1 if LAPIC found
1623 * acpi_ioapic = 1 if IOAPIC found
1624 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
1625 * if acpi_blacklisted() acpi_disabled = 1;
1626 * acpi_irq_model=...
1627 * ...
1628 *
1629 * return value: (currently ignored)
1630 * 0: success
1631 * !0: failure
1632 */
1633
Len Brown4be44fc2005-08-05 00:44:28 -04001634int __init acpi_boot_table_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635{
1636 int error;
1637
Andrey Paninaea00142005-06-25 14:54:42 -07001638 dmi_check_system(acpi_dmi_table);
Andrey Paninaea00142005-06-25 14:54:42 -07001639
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 /*
1641 * If acpi_disabled, bail out
1642 * One exception: acpi=ht continues far enough to enumerate LAPICs
1643 */
1644 if (acpi_disabled && !acpi_ht)
Len Brown4be44fc2005-08-05 00:44:28 -04001645 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001647 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 * Initialize the ACPI boot-time table parser.
1649 */
1650 error = acpi_table_init();
1651 if (error) {
1652 disable_acpi();
1653 return error;
1654 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001656 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657
1658 /*
1659 * blacklist may disable ACPI entirely
1660 */
1661 error = acpi_blacklisted();
1662 if (error) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 if (acpi_force) {
1664 printk(KERN_WARNING PREFIX "acpi=force override\n");
1665 } else {
1666 printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
1667 disable_acpi();
1668 return error;
1669 }
1670 }
1671
1672 return 0;
1673}
1674
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001675int __init early_acpi_boot_init(void)
1676{
1677 /*
1678 * If acpi_disabled, bail out
1679 * One exception: acpi=ht continues far enough to enumerate LAPICs
1680 */
1681 if (acpi_disabled && !acpi_ht)
1682 return 1;
1683
1684 /*
1685 * Process the Multiple APIC Description Table (MADT), if present
1686 */
1687 early_acpi_process_madt();
1688
1689 return 0;
1690}
1691
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692int __init acpi_boot_init(void)
1693{
1694 /*
1695 * If acpi_disabled, bail out
1696 * One exception: acpi=ht continues far enough to enumerate LAPICs
1697 */
1698 if (acpi_disabled && !acpi_ht)
Len Brown4be44fc2005-08-05 00:44:28 -04001699 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001701 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702
1703 /*
1704 * set sci_int and PM timer address
1705 */
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +03001706 acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
1708 /*
1709 * Process the Multiple APIC Description Table (MADT), if present
1710 */
1711 acpi_process_madt();
1712
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001713 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714
1715 return 0;
1716}
Rusty Russell1a3f2392006-09-26 10:52:32 +02001717
1718static int __init parse_acpi(char *arg)
1719{
1720 if (!arg)
1721 return -EINVAL;
1722
1723 /* "acpi=off" disables both ACPI table parsing and interpreter */
1724 if (strcmp(arg, "off") == 0) {
1725 disable_acpi();
1726 }
1727 /* acpi=force to over-ride black-list */
1728 else if (strcmp(arg, "force") == 0) {
1729 acpi_force = 1;
1730 acpi_ht = 1;
1731 acpi_disabled = 0;
1732 }
1733 /* acpi=strict disables out-of-spec workarounds */
1734 else if (strcmp(arg, "strict") == 0) {
1735 acpi_strict = 1;
1736 }
1737 /* Limit ACPI just to boot-time to enable HT */
1738 else if (strcmp(arg, "ht") == 0) {
1739 if (!acpi_force)
1740 disable_acpi();
1741 acpi_ht = 1;
1742 }
1743 /* "acpi=noirq" disables ACPI interrupt routing */
1744 else if (strcmp(arg, "noirq") == 0) {
1745 acpi_noirq_set();
1746 } else {
1747 /* Core will printk when we return error. */
1748 return -EINVAL;
1749 }
1750 return 0;
1751}
1752early_param("acpi", parse_acpi);
1753
1754/* FIXME: Using pci= for an ACPI parameter is a travesty. */
1755static int __init parse_pci(char *arg)
1756{
1757 if (arg && strcmp(arg, "noacpi") == 0)
1758 acpi_disable_pci();
1759 return 0;
1760}
1761early_param("pci", parse_pci);
1762
Yinghai Lu3c999f12008-06-20 16:11:20 -07001763int __init acpi_mps_check(void)
1764{
1765#if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
1766/* mptable code is not built-in*/
1767 if (acpi_disabled || acpi_noirq) {
1768 printk(KERN_WARNING "MPS support code is not built-in.\n"
1769 "Using acpi=off or acpi=noirq or pci=noacpi "
1770 "may have problem\n");
1771 return 1;
1772 }
1773#endif
1774 return 0;
1775}
1776
Rusty Russell1a3f2392006-09-26 10:52:32 +02001777#ifdef CONFIG_X86_IO_APIC
1778static int __init parse_acpi_skip_timer_override(char *arg)
1779{
1780 acpi_skip_timer_override = 1;
1781 return 0;
1782}
1783early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
Andi Kleenfa18f472006-11-14 16:57:46 +01001784
1785static int __init parse_acpi_use_timer_override(char *arg)
1786{
1787 acpi_use_timer_override = 1;
1788 return 0;
1789}
1790early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001791#endif /* CONFIG_X86_IO_APIC */
1792
1793static int __init setup_acpi_sci(char *s)
1794{
1795 if (!s)
1796 return -EINVAL;
1797 if (!strcmp(s, "edge"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001798 acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
1799 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001800 else if (!strcmp(s, "level"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001801 acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
1802 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001803 else if (!strcmp(s, "high"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001804 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
1805 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001806 else if (!strcmp(s, "low"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001807 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
1808 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001809 else
1810 return -EINVAL;
1811 return 0;
1812}
1813early_param("acpi_sci", setup_acpi_sci);
Andrew Mortond0a90812006-10-20 14:30:27 -07001814
1815int __acpi_acquire_global_lock(unsigned int *lock)
1816{
1817 unsigned int old, new, val;
1818 do {
1819 old = *lock;
1820 new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
1821 val = cmpxchg(lock, old, new);
1822 } while (unlikely (val != old));
1823 return (new < 3) ? -1 : 0;
1824}
1825
1826int __acpi_release_global_lock(unsigned int *lock)
1827{
1828 unsigned int old, new, val;
1829 do {
1830 old = *lock;
1831 new = old & ~0x3;
1832 val = cmpxchg(lock, old, new);
1833 } while (unlikely (val != old));
1834 return old & 0x1;
1835}