]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/x86/kernel/acpi/boot.c
x86, irq: Simplify arch_early_irq_init()
[mirror_ubuntu-artful-kernel.git] / arch / x86 / kernel / acpi / boot.c
CommitLineData
1da177e4
LT
1/*
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>
1da177e4 27#include <linux/acpi.h>
d66bea57 28#include <linux/acpi_pmtmr.h>
1da177e4 29#include <linux/efi.h>
73fea175 30#include <linux/cpumask.h>
1da177e4 31#include <linux/module.h>
aea00143 32#include <linux/dmi.h>
b33fa1f3 33#include <linux/irq.h>
5a0e3ad6 34#include <linux/slab.h>
f0f4c343
AD
35#include <linux/bootmem.h>
36#include <linux/ioport.h>
a31f8205 37#include <linux/pci.h>
1da177e4 38
b72d0db9 39#include <asm/pci_x86.h>
1da177e4
LT
40#include <asm/pgtable.h>
41#include <asm/io_apic.h>
42#include <asm/apic.h>
43#include <asm/io.h>
1da177e4 44#include <asm/mpspec.h>
dfac2189 45#include <asm/smp.h>
95d76acc 46#include <asm/i8259.h>
1da177e4 47
d6a77ead 48#include "sleep.h" /* To include x86_acpi_suspend_lowlevel */
e8924acb 49static int __initdata acpi_force = 0;
c636f753 50int acpi_disabled;
df3bb57d
AK
51EXPORT_SYMBOL(acpi_disabled);
52
1da177e4 53#ifdef CONFIG_X86_64
1dcdd3d1 54# include <asm/proto.h>
4be44fcd 55#endif /* X86 */
1da177e4 56
1da177e4
LT
57#define PREFIX "ACPI: "
58
90d53909 59int acpi_noirq; /* skip ACPI IRQ initialization */
6e4be1ff
YL
60int acpi_pci_disabled; /* skip ACPI PCI scan and IRQ initialization */
61EXPORT_SYMBOL(acpi_pci_disabled);
1da177e4
LT
62
63int acpi_lapic;
64int acpi_ioapic;
65int acpi_strict;
9ad95879 66int acpi_disable_cmcff;
1da177e4 67
5f3b1a8b 68u8 acpi_sci_flags __initdata;
1da177e4
LT
69int acpi_sci_override_gsi __initdata;
70int acpi_skip_timer_override __initdata;
fa18f477 71int acpi_use_timer_override __initdata;
7f74f8f2 72int acpi_fix_pin2_polarity __initdata;
1da177e4
LT
73
74#ifdef CONFIG_X86_LOCAL_APIC
75static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
76#endif
77
78#ifndef __HAVE_ARCH_CMPXCHG
79#warning ACPI uses CMPXCHG, i486 and later hardware
80#endif
81
1da177e4
LT
82/* --------------------------------------------------------------------------
83 Boot-time Configuration
84 -------------------------------------------------------------------------- */
85
86/*
87 * The default interrupt routing model is PIC (8259). This gets
27b46d76 88 * overridden if IOAPICs are enumerated (below).
1da177e4 89 */
4be44fcd 90enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
1da177e4 91
1da177e4 92
988856ee
EB
93/*
94 * ISA irqs by default are the first 16 gsis but can be
95 * any gsi as specified by an interrupt source override.
96 */
97static u32 isa_irq_to_gsi[NR_IRQS_LEGACY] __read_mostly = {
98 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
99};
100
2c0a6894
JL
101#define ACPI_INVALID_GSI INT_MIN
102
988856ee
EB
103static unsigned int gsi_to_irq(unsigned int gsi)
104{
95d76acc 105 unsigned int irq = gsi + nr_legacy_irqs();
988856ee
EB
106 unsigned int i;
107
95d76acc 108 for (i = 0; i < nr_legacy_irqs(); i++) {
988856ee
EB
109 if (isa_irq_to_gsi[i] == gsi) {
110 return i;
111 }
112 }
113
114 /* Provide an identity mapping of gsi == irq
115 * except on truly weird platforms that have
116 * non isa irqs in the first 16 gsis.
117 */
95d76acc 118 if (gsi >= nr_legacy_irqs())
988856ee
EB
119 irq = gsi;
120 else
a4384df3 121 irq = gsi_top + gsi;
988856ee
EB
122
123 return irq;
124}
125
1da177e4 126/*
45f1330a
ZY
127 * This is just a simple wrapper around early_ioremap(),
128 * with sanity checks for phys == 0 and size == 0.
1da177e4 129 */
2fdf0741 130char *__init __acpi_map_table(unsigned long phys, unsigned long size)
1da177e4 131{
1da177e4 132
f34fa82b
YL
133 if (!phys || !size)
134 return NULL;
135
7d97277b
YL
136 return early_ioremap(phys, size);
137}
45f1330a 138
7d97277b
YL
139void __init __acpi_unmap_table(char *map, unsigned long size)
140{
141 if (!map || !size)
142 return;
1da177e4 143
7d97277b 144 early_iounmap(map, size);
1da177e4 145}
1da177e4 146
1da177e4 147#ifdef CONFIG_X86_LOCAL_APIC
15a58ed1 148static int __init acpi_parse_madt(struct acpi_table_header *table)
1da177e4 149{
4be44fcd 150 struct acpi_table_madt *madt = NULL;
1da177e4 151
15a58ed1 152 if (!cpu_has_apic)
1da177e4
LT
153 return -EINVAL;
154
15a58ed1 155 madt = (struct acpi_table_madt *)table;
1da177e4
LT
156 if (!madt) {
157 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
158 return -ENODEV;
159 }
160
ad363f80
AS
161 if (madt->address) {
162 acpi_lapic_addr = (u64) madt->address;
1da177e4
LT
163
164 printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
ad363f80 165 madt->address);
1da177e4
LT
166 }
167
306db03b
IM
168 default_acpi_madt_oem_check(madt->header.oem_id,
169 madt->header.oem_table_id);
4be44fcd 170
1da177e4
LT
171 return 0;
172}
173
7e1f85f9
JL
174/**
175 * acpi_register_lapic - register a local apic and generates a logic cpu number
176 * @id: local apic id to register
177 * @enabled: this cpu is enabled or not
178 *
179 * Returns the logic cpu number which maps to the local apic
180 */
181static int acpi_register_lapic(int id, u8 enabled)
dfac2189 182{
fb3bbd6a
YL
183 unsigned int ver = 0;
184
82982d72 185 if (id >= MAX_LOCAL_APIC) {
d3bd0588 186 printk(KERN_INFO PREFIX "skipped apicid that is too big\n");
7e1f85f9 187 return -EINVAL;
d3bd0588
YL
188 }
189
dfac2189
AS
190 if (!enabled) {
191 ++disabled_cpus;
7e1f85f9 192 return -EINVAL;
dfac2189
AS
193 }
194
fb3bbd6a
YL
195 if (boot_cpu_physical_apicid != -1U)
196 ver = apic_version[boot_cpu_physical_apicid];
fb3bbd6a 197
7e1f85f9 198 return generic_processor_info(id, ver);
dfac2189
AS
199}
200
7237d3de
SS
201static int __init
202acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
203{
204 struct acpi_madt_local_x2apic *processor = NULL;
a35fd282
YL
205 int apic_id;
206 u8 enabled;
7237d3de
SS
207
208 processor = (struct acpi_madt_local_x2apic *)header;
209
210 if (BAD_MADT_ENTRY(processor, end))
211 return -EINVAL;
212
213 acpi_table_print_madt_entry(header);
214
a35fd282
YL
215 apic_id = processor->local_apic_id;
216 enabled = processor->lapic_flags & ACPI_MADT_ENABLED;
7237d3de
SS
217#ifdef CONFIG_X86_X2APIC
218 /*
219 * We need to register disabled CPU as well to permit
220 * counting disabled CPUs. This allows us to size
221 * cpus_possible_map more accurately, to permit
222 * to not preallocating memory for all NR_CPUS
223 * when we use CPU hotplug.
224 */
b7157acf 225 if (!apic->apic_id_valid(apic_id) && enabled)
a35fd282
YL
226 printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
227 else
228 acpi_register_lapic(apic_id, enabled);
7237d3de
SS
229#else
230 printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
231#endif
232
233 return 0;
234}
235
1da177e4 236static int __init
5f3b1a8b 237acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
1da177e4 238{
5f3b1a8b 239 struct acpi_madt_local_apic *processor = NULL;
1da177e4 240
5f3b1a8b 241 processor = (struct acpi_madt_local_apic *)header;
1da177e4
LT
242
243 if (BAD_MADT_ENTRY(processor, end))
244 return -EINVAL;
245
246 acpi_table_print_madt_entry(header);
247
7f66ae48
AR
248 /*
249 * We need to register disabled CPU as well to permit
250 * counting disabled CPUs. This allows us to size
251 * cpus_possible_map more accurately, to permit
252 * to not preallocating memory for all NR_CPUS
253 * when we use CPU hotplug.
254 */
dfac2189
AS
255 acpi_register_lapic(processor->id, /* APIC ID */
256 processor->lapic_flags & ACPI_MADT_ENABLED);
1da177e4
LT
257
258 return 0;
259}
260
ac049c1d
JS
261static int __init
262acpi_parse_sapic(struct acpi_subtable_header *header, const unsigned long end)
263{
264 struct acpi_madt_local_sapic *processor = NULL;
265
266 processor = (struct acpi_madt_local_sapic *)header;
267
268 if (BAD_MADT_ENTRY(processor, end))
269 return -EINVAL;
270
271 acpi_table_print_madt_entry(header);
272
dfac2189
AS
273 acpi_register_lapic((processor->id << 8) | processor->eid,/* APIC ID */
274 processor->lapic_flags & ACPI_MADT_ENABLED);
ac049c1d
JS
275
276 return 0;
277}
278
1da177e4 279static int __init
5f3b1a8b 280acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
4be44fcd 281 const unsigned long end)
1da177e4 282{
5f3b1a8b 283 struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
1da177e4 284
5f3b1a8b 285 lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
1da177e4
LT
286
287 if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
288 return -EINVAL;
289
290 acpi_lapic_addr = lapic_addr_ovr->address;
291
292 return 0;
293}
294
7237d3de
SS
295static int __init
296acpi_parse_x2apic_nmi(struct acpi_subtable_header *header,
297 const unsigned long end)
298{
299 struct acpi_madt_local_x2apic_nmi *x2apic_nmi = NULL;
300
301 x2apic_nmi = (struct acpi_madt_local_x2apic_nmi *)header;
302
303 if (BAD_MADT_ENTRY(x2apic_nmi, end))
304 return -EINVAL;
305
306 acpi_table_print_madt_entry(header);
307
308 if (x2apic_nmi->lint != 1)
309 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
310
311 return 0;
312}
313
1da177e4 314static int __init
5f3b1a8b 315acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
1da177e4 316{
5f3b1a8b 317 struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
1da177e4 318
5f3b1a8b 319 lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
1da177e4
LT
320
321 if (BAD_MADT_ENTRY(lapic_nmi, end))
322 return -EINVAL;
323
324 acpi_table_print_madt_entry(header);
325
326 if (lapic_nmi->lint != 1)
327 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
328
329 return 0;
330}
331
4be44fcd 332#endif /*CONFIG_X86_LOCAL_APIC */
1da177e4 333
8466361a 334#ifdef CONFIG_X86_IO_APIC
8d7cdcb9
JL
335#define MP_ISA_BUS 0
336
337static void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger,
338 u32 gsi)
339{
340 int ioapic;
341 int pin;
342 struct mpc_intsrc mp_irq;
343
344 /*
345 * Convert 'gsi' to 'ioapic.pin'.
346 */
347 ioapic = mp_find_ioapic(gsi);
348 if (ioapic < 0)
349 return;
350 pin = mp_find_ioapic_pin(ioapic, gsi);
351
352 /*
353 * TBD: This check is for faulty timer entries, where the override
354 * erroneously sets the trigger to level, resulting in a HUGE
355 * increase of timer interrupts!
356 */
357 if ((bus_irq == 0) && (trigger == 3))
358 trigger = 1;
359
360 mp_irq.type = MP_INTSRC;
361 mp_irq.irqtype = mp_INT;
362 mp_irq.irqflag = (trigger << 2) | polarity;
363 mp_irq.srcbus = MP_ISA_BUS;
364 mp_irq.srcbusirq = bus_irq; /* IRQ */
365 mp_irq.dstapic = mpc_ioapic_id(ioapic); /* APIC ID */
366 mp_irq.dstirq = pin; /* INTIN# */
367
368 mp_save_irq(&mp_irq);
369
2e0ad0e2
JL
370 /*
371 * Reset default identity mapping if gsi is also an legacy IRQ,
372 * otherwise there will be more than one entry with the same GSI
373 * and acpi_isa_irq_to_gsi() may give wrong result.
374 */
95d76acc 375 if (gsi < nr_legacy_irqs() && isa_irq_to_gsi[gsi] == gsi)
2e0ad0e2 376 isa_irq_to_gsi[gsi] = ACPI_INVALID_GSI;
8d7cdcb9
JL
377 isa_irq_to_gsi[bus_irq] = gsi;
378}
379
380static int mp_config_acpi_gsi(struct device *dev, u32 gsi, int trigger,
381 int polarity)
382{
383#ifdef CONFIG_X86_MPPARSE
384 struct mpc_intsrc mp_irq;
385 struct pci_dev *pdev;
386 unsigned char number;
387 unsigned int devfn;
388 int ioapic;
389 u8 pin;
390
391 if (!acpi_ioapic)
392 return 0;
393 if (!dev || !dev_is_pci(dev))
394 return 0;
395
396 pdev = to_pci_dev(dev);
397 number = pdev->bus->number;
398 devfn = pdev->devfn;
399 pin = pdev->pin;
400 /* print the entry should happen on mptable identically */
401 mp_irq.type = MP_INTSRC;
402 mp_irq.irqtype = mp_INT;
403 mp_irq.irqflag = (trigger == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
404 (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
405 mp_irq.srcbus = number;
406 mp_irq.srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
407 ioapic = mp_find_ioapic(gsi);
408 mp_irq.dstapic = mpc_ioapic_id(ioapic);
409 mp_irq.dstirq = mp_find_ioapic_pin(ioapic, gsi);
410
411 mp_save_irq(&mp_irq);
412#endif
413 return 0;
414}
415
a491cc90 416static int mp_register_gsi(struct device *dev, u32 gsi, int trigger,
8d7cdcb9
JL
417 int polarity)
418{
419 int ioapic;
420 int ioapic_pin;
421 struct io_apic_irq_attr irq_attr;
422 int ret;
423
424 if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
425 return gsi;
426
427 /* Don't set up the ACPI SCI because it's already set up */
428 if (acpi_gbl_FADT.sci_interrupt == gsi)
429 return gsi;
430
431 ioapic = mp_find_ioapic(gsi);
432 if (ioapic < 0) {
433 printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
434 return gsi;
435 }
436
437 ioapic_pin = mp_find_ioapic_pin(ioapic, gsi);
438
439 if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
440 printk(KERN_ERR "Invalid reference to IOAPIC pin "
441 "%d-%d\n", mpc_ioapic_id(ioapic),
442 ioapic_pin);
443 return gsi;
444 }
445
446 if (enable_update_mptable)
447 mp_config_acpi_gsi(dev, gsi, trigger, polarity);
448
449 set_io_apic_irq_attr(&irq_attr, ioapic, ioapic_pin,
450 trigger == ACPI_EDGE_SENSITIVE ? 0 : 1,
451 polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
452 ret = io_apic_set_pci_routing(dev, gsi_to_irq(gsi), &irq_attr);
453 if (ret < 0)
2c0a6894 454 gsi = ACPI_INVALID_GSI;
8d7cdcb9
JL
455
456 return gsi;
457}
458
1da177e4
LT
459
460static int __init
5f3b1a8b 461acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
1da177e4 462{
5f3b1a8b 463 struct acpi_madt_io_apic *ioapic = NULL;
1da177e4 464
5f3b1a8b 465 ioapic = (struct acpi_madt_io_apic *)header;
1da177e4
LT
466
467 if (BAD_MADT_ENTRY(ioapic, end))
468 return -EINVAL;
4be44fcd 469
1da177e4
LT
470 acpi_table_print_madt_entry(header);
471
4be44fcd
LB
472 mp_register_ioapic(ioapic->id,
473 ioapic->address, ioapic->global_irq_base);
474
1da177e4
LT
475 return 0;
476}
477
478/*
479 * Parse Interrupt Source Override for the ACPI SCI
480 */
9d2062b8 481static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger, u32 gsi)
1da177e4
LT
482{
483 if (trigger == 0) /* compatible SCI trigger is level */
484 trigger = 3;
485
486 if (polarity == 0) /* compatible SCI polarity is low */
487 polarity = 3;
488
489 /* Command-line over-ride via acpi_sci= */
5f3b1a8b
AS
490 if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
491 trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
1da177e4 492
5f3b1a8b
AS
493 if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
494 polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
1da177e4 495
9d2062b8 496 mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
1da177e4
LT
497
498 /*
499 * stash over-ride to indicate we've been here
cee324b1 500 * and for later update of acpi_gbl_FADT
1da177e4 501 */
7bdd21ce 502 acpi_sci_override_gsi = gsi;
1da177e4
LT
503 return;
504}
505
506static int __init
5f3b1a8b 507acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
4be44fcd 508 const unsigned long end)
1da177e4 509{
5f3b1a8b 510 struct acpi_madt_interrupt_override *intsrc = NULL;
1da177e4 511
5f3b1a8b 512 intsrc = (struct acpi_madt_interrupt_override *)header;
1da177e4
LT
513
514 if (BAD_MADT_ENTRY(intsrc, end))
515 return -EINVAL;
516
517 acpi_table_print_madt_entry(header);
518
5f3b1a8b 519 if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
9d2062b8 520 acpi_sci_ioapic_setup(intsrc->source_irq,
5f3b1a8b 521 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
9d2062b8
EB
522 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
523 intsrc->global_irq);
1da177e4
LT
524 return 0;
525 }
526
ae10ccdc 527 if (intsrc->source_irq == 0) {
7f74f8f2 528 if (acpi_skip_timer_override) {
ae10ccdc 529 printk(PREFIX "BIOS IRQ0 override ignored.\n");
7f74f8f2
AH
530 return 0;
531 }
ae10ccdc
FT
532
533 if ((intsrc->global_irq == 2) && acpi_fix_pin2_polarity
534 && (intsrc->inti_flags & ACPI_MADT_POLARITY_MASK)) {
7f74f8f2
AH
535 intsrc->inti_flags &= ~ACPI_MADT_POLARITY_MASK;
536 printk(PREFIX "BIOS IRQ0 pin2 override: forcing polarity to high active.\n");
537 }
1da177e4
LT
538 }
539
5f3b1a8b
AS
540 mp_override_legacy_irq(intsrc->source_irq,
541 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
542 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
543 intsrc->global_irq);
1da177e4
LT
544
545 return 0;
546}
547
1da177e4 548static int __init
5f3b1a8b 549acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
1da177e4 550{
5f3b1a8b 551 struct acpi_madt_nmi_source *nmi_src = NULL;
1da177e4 552
5f3b1a8b 553 nmi_src = (struct acpi_madt_nmi_source *)header;
1da177e4
LT
554
555 if (BAD_MADT_ENTRY(nmi_src, end))
556 return -EINVAL;
557
558 acpi_table_print_madt_entry(header);
559
560 /* TBD: Support nimsrc entries? */
561
562 return 0;
563}
564
4be44fcd 565#endif /* CONFIG_X86_IO_APIC */
1da177e4 566
1da177e4
LT
567/*
568 * acpi_pic_sci_set_trigger()
5f3b1a8b 569 *
1da177e4
LT
570 * use ELCR to set PIC-mode trigger type for SCI
571 *
572 * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
573 * it may require Edge Trigger -- use "acpi_sci=edge"
574 *
575 * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
576 * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
27b46d76
SA
577 * ECLR1 is IRQs 0-7 (IRQ 0, 1, 2 must be 0)
578 * ECLR2 is IRQs 8-15 (IRQ 8, 13 must be 0)
1da177e4
LT
579 */
580
4be44fcd 581void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
1da177e4
LT
582{
583 unsigned int mask = 1 << irq;
584 unsigned int old, new;
585
586 /* Real old ELCR mask */
587 old = inb(0x4d0) | (inb(0x4d1) << 8);
588
589 /*
27b46d76 590 * If we use ACPI to set PCI IRQs, then we should clear ELCR
1da177e4
LT
591 * since we will set it correctly as we enable the PCI irq
592 * routing.
593 */
594 new = acpi_noirq ? old : 0;
595
596 /*
597 * Update SCI information in the ELCR, it isn't in the PCI
598 * routing tables..
599 */
600 switch (trigger) {
4be44fcd 601 case 1: /* Edge - clear */
1da177e4
LT
602 new &= ~mask;
603 break;
4be44fcd 604 case 3: /* Level - set */
1da177e4
LT
605 new |= mask;
606 break;
607 }
608
609 if (old == new)
610 return;
611
612 printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
613 outb(new, 0x4d0);
614 outb(new >> 8, 0x4d1);
615}
616
1da177e4
LT
617int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
618{
988856ee 619 *irq = gsi_to_irq(gsi);
18dce6ba
YL
620
621#ifdef CONFIG_X86_IO_APIC
622 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
623 setup_IO_APIC_irq_extra(gsi);
624#endif
625
1da177e4
LT
626 return 0;
627}
81e88fdc 628EXPORT_SYMBOL_GPL(acpi_gsi_to_irq);
1da177e4 629
2c2df841
EB
630int acpi_isa_irq_to_gsi(unsigned isa_irq, u32 *gsi)
631{
95d76acc 632 if (isa_irq < nr_legacy_irqs() &&
2e0ad0e2 633 isa_irq_to_gsi[isa_irq] != ACPI_INVALID_GSI) {
032329ee
JL
634 *gsi = isa_irq_to_gsi[isa_irq];
635 return 0;
636 }
637
638 return -1;
2c2df841
EB
639}
640
2f065aef
JF
641static int acpi_register_gsi_pic(struct device *dev, u32 gsi,
642 int trigger, int polarity)
1da177e4 643{
1da177e4
LT
644#ifdef CONFIG_PCI
645 /*
646 * Make sure all (legacy) PCI IRQs are set as level-triggered.
647 */
2f065aef
JF
648 if (trigger == ACPI_LEVEL_SENSITIVE)
649 eisa_set_level_irq(gsi);
1da177e4
LT
650#endif
651
2f065aef
JF
652 return gsi;
653}
654
655static int acpi_register_gsi_ioapic(struct device *dev, u32 gsi,
656 int trigger, int polarity)
657{
1da177e4 658#ifdef CONFIG_X86_IO_APIC
2f065aef 659 gsi = mp_register_gsi(dev, gsi, trigger, polarity);
1da177e4 660#endif
2f065aef
JF
661
662 return gsi;
663}
664
90f6881e
JF
665int (*__acpi_register_gsi)(struct device *dev, u32 gsi,
666 int trigger, int polarity) = acpi_register_gsi_pic;
2f065aef 667
d6a77ead
KRW
668#ifdef CONFIG_ACPI_SLEEP
669int (*acpi_suspend_lowlevel)(void) = x86_acpi_suspend_lowlevel;
670#else
671int (*acpi_suspend_lowlevel)(void);
672#endif
673
2f065aef
JF
674/*
675 * success: return IRQ number (>=0)
676 * failure: return < 0
677 */
678int acpi_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
679{
2c0a6894 680 unsigned int plat_gsi;
2f065aef 681
2c0a6894
JL
682 plat_gsi = __acpi_register_gsi(dev, gsi, trigger, polarity);
683 if (plat_gsi != ACPI_INVALID_GSI)
684 return gsi_to_irq(plat_gsi);
18dce6ba 685
2c0a6894 686 return -1;
1da177e4 687}
35e92b78
AS
688EXPORT_SYMBOL_GPL(acpi_register_gsi);
689
690void acpi_unregister_gsi(u32 gsi)
691{
692}
693EXPORT_SYMBOL_GPL(acpi_unregister_gsi);
4be44fcd 694
e819813f 695static void __init acpi_set_irq_model_ioapic(void)
2f065aef
JF
696{
697 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
698 __acpi_register_gsi = acpi_register_gsi_ioapic;
699 acpi_ioapic = 1;
700}
701
1da177e4
LT
702/*
703 * ACPI based hotplug support for CPU
704 */
705#ifdef CONFIG_ACPI_HOTPLUG_CPU
d8191fa4 706#include <acpi/processor.h>
009cbadb 707
148f9bb8 708static void acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
0271f910
HL
709{
710#ifdef CONFIG_ACPI_NUMA
711 int nid;
712
713 nid = acpi_get_node(handle);
896dc506
JL
714 if (nid != -1) {
715 set_apicid_to_node(physid, nid);
716 numa_set_node(cpu, nid);
717 }
0271f910
HL
718#endif
719}
009cbadb 720
d536bf3d 721static int _acpi_map_lsapic(acpi_handle handle, int physid, int *pcpu)
1da177e4 722{
73fea175 723 int cpu;
ee943a82 724
7e1f85f9
JL
725 cpu = acpi_register_lapic(physid, ACPI_MADT_ENABLED);
726 if (cpu < 0) {
727 pr_info(PREFIX "Unable to map lapic to logical cpu number\n");
728 return cpu;
73fea175
AR
729 }
730
d8191fa4 731 acpi_processor_set_pdc(handle);
0271f910 732 acpi_map_cpu2node(handle, cpu, physid);
73fea175
AR
733
734 *pcpu = cpu;
7e1f85f9 735 return 0;
1da177e4 736}
1da177e4 737
009cbadb 738/* wrapper to silence section mismatch warning */
d536bf3d 739int __ref acpi_map_lsapic(acpi_handle handle, int physid, int *pcpu)
009cbadb 740{
d536bf3d 741 return _acpi_map_lsapic(handle, physid, pcpu);
009cbadb 742}
4be44fcd 743EXPORT_SYMBOL(acpi_map_lsapic);
1da177e4 744
4be44fcd 745int acpi_unmap_lsapic(int cpu)
1da177e4 746{
c4c60524
WC
747#ifdef CONFIG_ACPI_NUMA
748 set_apicid_to_node(per_cpu(x86_cpu_to_apicid, cpu), NUMA_NO_NODE);
749#endif
750
71fff5e6 751 per_cpu(x86_cpu_to_apicid, cpu) = -1;
9628937d 752 set_cpu_present(cpu, false);
73fea175
AR
753 num_processors--;
754
755 return (0);
1da177e4 756}
4be44fcd 757
1da177e4 758EXPORT_SYMBOL(acpi_unmap_lsapic);
4be44fcd 759#endif /* CONFIG_ACPI_HOTPLUG_CPU */
1da177e4 760
4be44fcd 761int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
b1bb248a
KK
762{
763 /* TBD */
764 return -EINVAL;
765}
4be44fcd 766
b1bb248a
KK
767EXPORT_SYMBOL(acpi_register_ioapic);
768
4be44fcd 769int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
b1bb248a
KK
770{
771 /* TBD */
772 return -EINVAL;
773}
4be44fcd 774
b1bb248a
KK
775EXPORT_SYMBOL(acpi_unregister_ioapic);
776
5f3b1a8b 777static int __init acpi_parse_sbf(struct acpi_table_header *table)
1da177e4 778{
5f3b1a8b 779 struct acpi_table_boot *sb;
1da177e4 780
5f3b1a8b 781 sb = (struct acpi_table_boot *)table;
1da177e4
LT
782 if (!sb) {
783 printk(KERN_WARNING PREFIX "Unable to map SBF\n");
784 return -ENODEV;
785 }
786
5f3b1a8b 787 sbf_port = sb->cmos_index; /* Save CMOS port */
1da177e4
LT
788
789 return 0;
790}
791
1da177e4 792#ifdef CONFIG_HPET_TIMER
2d0c87c3 793#include <asm/hpet.h>
1da177e4 794
dd96dc32 795static struct resource *hpet_res __initdata;
a1dfd851 796
5f3b1a8b 797static int __init acpi_parse_hpet(struct acpi_table_header *table)
1da177e4
LT
798{
799 struct acpi_table_hpet *hpet_tbl;
800
5f3b1a8b 801 hpet_tbl = (struct acpi_table_hpet *)table;
1da177e4
LT
802 if (!hpet_tbl) {
803 printk(KERN_WARNING PREFIX "Unable to map HPET\n");
804 return -ENODEV;
805 }
806
ad363f80 807 if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
1da177e4
LT
808 printk(KERN_WARNING PREFIX "HPET timers must be located in "
809 "memory.\n");
810 return -1;
811 }
f0f4c343 812
2d0c87c3 813 hpet_address = hpet_tbl->address.address;
c8bc6f3c 814 hpet_blockid = hpet_tbl->sequence;
f4df73c2
TG
815
816 /*
817 * Some broken BIOSes advertise HPET at 0x0. We really do not
818 * want to allocate a resource there.
819 */
820 if (!hpet_address) {
821 printk(KERN_WARNING PREFIX
822 "HPET id: %#x base: %#lx is invalid\n",
823 hpet_tbl->id, hpet_address);
824 return 0;
825 }
826#ifdef CONFIG_X86_64
827 /*
828 * Some even more broken BIOSes advertise HPET at
829 * 0xfed0000000000000 instead of 0xfed00000. Fix it up and add
830 * some noise:
831 */
832 if (hpet_address == 0xfed0000000000000UL) {
833 if (!hpet_force_user) {
834 printk(KERN_WARNING PREFIX "HPET id: %#x "
835 "base: 0xfed0000000000000 is bogus\n "
836 "try hpet=force on the kernel command line to "
837 "fix it up to 0xfed00000.\n", hpet_tbl->id);
838 hpet_address = 0;
839 return 0;
840 }
841 printk(KERN_WARNING PREFIX
842 "HPET id: %#x base: 0xfed0000000000000 fixed up "
843 "to 0xfed00000.\n", hpet_tbl->id);
844 hpet_address >>= 32;
845 }
846#endif
4be44fcd 847 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
2d0c87c3 848 hpet_tbl->id, hpet_address);
1da177e4 849
a1dfd851
AD
850 /*
851 * Allocate and initialize the HPET firmware resource for adding into
852 * the resource tree during the lateinit timeframe.
853 */
854#define HPET_RESOURCE_NAME_SIZE 9
855 hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
856
a1dfd851
AD
857 hpet_res->name = (void *)&hpet_res[1];
858 hpet_res->flags = IORESOURCE_MEM;
859 snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE, "HPET %u",
860 hpet_tbl->sequence);
861
862 hpet_res->start = hpet_address;
863 hpet_res->end = hpet_address + (1 * 1024) - 1;
864
1da177e4
LT
865 return 0;
866}
a1dfd851
AD
867
868/*
869 * hpet_insert_resource inserts the HPET resources used into the resource
870 * tree.
871 */
872static __init int hpet_insert_resource(void)
873{
874 if (!hpet_res)
875 return 1;
876
877 return insert_resource(&iomem_resource, hpet_res);
878}
879
880late_initcall(hpet_insert_resource);
881
1da177e4
LT
882#else
883#define acpi_parse_hpet NULL
884#endif
885
5f3b1a8b 886static int __init acpi_parse_fadt(struct acpi_table_header *table)
1da177e4 887{
90660ec3 888
1da177e4
LT
889#ifdef CONFIG_X86_PM_TIMER
890 /* detect the location of the ACPI PM Timer */
5f3b1a8b 891 if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
1da177e4 892 /* FADT rev. 2 */
5f3b1a8b 893 if (acpi_gbl_FADT.xpm_timer_block.space_id !=
4be44fcd 894 ACPI_ADR_SPACE_SYSTEM_IO)
1da177e4
LT
895 return 0;
896
5f3b1a8b 897 pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
e6e87b4b
DSL
898 /*
899 * "X" fields are optional extensions to the original V1.0
900 * fields, so we must selectively expand V1.0 fields if the
901 * corresponding X field is zero.
902 */
903 if (!pmtmr_ioport)
5f3b1a8b 904 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
1da177e4
LT
905 } else {
906 /* FADT rev. 1 */
5f3b1a8b 907 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
1da177e4
LT
908 }
909 if (pmtmr_ioport)
4be44fcd
LB
910 printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
911 pmtmr_ioport);
1da177e4
LT
912#endif
913 return 0;
914}
915
1da177e4
LT
916#ifdef CONFIG_X86_LOCAL_APIC
917/*
918 * Parse LAPIC entries in MADT
919 * returns 0 on success, < 0 on error
920 */
31d2092e 921
cbf9bd60
YL
922static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
923{
924 int count;
925
926 if (!cpu_has_apic)
927 return -ENODEV;
928
929 /*
930 * Note that the LAPIC address is obtained from the MADT (32-bit value)
931 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
932 */
933
e819813f
JL
934 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
935 acpi_parse_lapic_addr_ovr, 0);
cbf9bd60
YL
936 if (count < 0) {
937 printk(KERN_ERR PREFIX
938 "Error parsing LAPIC address override entry\n");
939 return count;
940 }
941
c0104d38 942 register_lapic_address(acpi_lapic_addr);
cbf9bd60
YL
943
944 return count;
945}
946
4be44fcd 947static int __init acpi_parse_madt_lapic_entries(void)
1da177e4
LT
948{
949 int count;
7237d3de 950 int x2count = 0;
1da177e4 951
0fcd2709
AK
952 if (!cpu_has_apic)
953 return -ENODEV;
954
5f3b1a8b 955 /*
1da177e4
LT
956 * Note that the LAPIC address is obtained from the MADT (32-bit value)
957 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
958 */
959
e819813f
JL
960 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
961 acpi_parse_lapic_addr_ovr, 0);
1da177e4 962 if (count < 0) {
4be44fcd
LB
963 printk(KERN_ERR PREFIX
964 "Error parsing LAPIC address override entry\n");
1da177e4
LT
965 return count;
966 }
967
c0104d38 968 register_lapic_address(acpi_lapic_addr);
1da177e4 969
ac049c1d 970 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
cb2ded37 971 acpi_parse_sapic, MAX_LOCAL_APIC);
ac049c1d 972
7237d3de
SS
973 if (!count) {
974 x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
cb2ded37 975 acpi_parse_x2apic, MAX_LOCAL_APIC);
ac049c1d 976 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
cb2ded37 977 acpi_parse_lapic, MAX_LOCAL_APIC);
7237d3de
SS
978 }
979 if (!count && !x2count) {
1da177e4
LT
980 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
981 /* TBD: Cleanup to allow fallback to MPS */
982 return -ENODEV;
7237d3de 983 } else if (count < 0 || x2count < 0) {
1da177e4
LT
984 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
985 /* TBD: Cleanup to allow fallback to MPS */
986 return count;
987 }
988
e819813f
JL
989 x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI,
990 acpi_parse_x2apic_nmi, 0);
991 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI,
992 acpi_parse_lapic_nmi, 0);
7237d3de 993 if (count < 0 || x2count < 0) {
1da177e4
LT
994 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
995 /* TBD: Cleanup to allow fallback to MPS */
996 return count;
997 }
998 return 0;
999}
4be44fcd 1000#endif /* CONFIG_X86_LOCAL_APIC */
1da177e4 1001
8466361a 1002#ifdef CONFIG_X86_IO_APIC
a491cc90 1003static void __init mp_config_acpi_legacy_irqs(void)
11113f84 1004{
6df8809b 1005 int i;
c2c21745 1006 struct mpc_intsrc mp_irq;
11113f84 1007
bb8187d3 1008#ifdef CONFIG_EISA
11113f84
AS
1009 /*
1010 * Fabricate the legacy ISA bus (bus #31).
1011 */
1012 mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
1013#endif
1014 set_bit(MP_ISA_BUS, mp_bus_not_pci);
cfc1b9a6 1015 pr_debug("Bus #%d is ISA\n", MP_ISA_BUS);
11113f84 1016
11113f84
AS
1017 /*
1018 * Use the default configuration for the IRQs 0-15. Unless
1019 * overridden by (MADT) interrupt source override entries.
1020 */
95d76acc 1021 for (i = 0; i < nr_legacy_irqs(); i++) {
0fd52670
EB
1022 int ioapic, pin;
1023 unsigned int dstapic;
11113f84 1024 int idx;
0fd52670
EB
1025 u32 gsi;
1026
1027 /* Locate the gsi that irq i maps to. */
1028 if (acpi_isa_irq_to_gsi(i, &gsi))
1029 continue;
1030
1031 /*
1032 * Locate the IOAPIC that manages the ISA IRQ.
1033 */
1034 ioapic = mp_find_ioapic(gsi);
1035 if (ioapic < 0)
1036 continue;
1037 pin = mp_find_ioapic_pin(ioapic, gsi);
d5371430 1038 dstapic = mpc_ioapic_id(ioapic);
11113f84
AS
1039
1040 for (idx = 0; idx < mp_irq_entries; idx++) {
c2c21745 1041 struct mpc_intsrc *irq = mp_irqs + idx;
11113f84
AS
1042
1043 /* Do we already have a mapping for this ISA IRQ? */
c2c21745 1044 if (irq->srcbus == MP_ISA_BUS && irq->srcbusirq == i)
11113f84
AS
1045 break;
1046
1047 /* Do we already have a mapping for this IOAPIC pin */
0fd52670 1048 if (irq->dstapic == dstapic && irq->dstirq == pin)
11113f84
AS
1049 break;
1050 }
1051
1052 if (idx != mp_irq_entries) {
1053 printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
1054 continue; /* IRQ already used */
1055 }
1056
c2c21745
JSR
1057 mp_irq.type = MP_INTSRC;
1058 mp_irq.irqflag = 0; /* Conforming */
1059 mp_irq.srcbus = MP_ISA_BUS;
1060 mp_irq.dstapic = dstapic;
1061 mp_irq.irqtype = mp_INT;
1062 mp_irq.srcbusirq = i; /* Identity mapped */
0fd52670 1063 mp_irq.dstirq = pin;
11113f84 1064
2d8009ba 1065 mp_save_irq(&mp_irq);
11113f84
AS
1066 }
1067}
1068
1da177e4
LT
1069/*
1070 * Parse IOAPIC related entries in MADT
1071 * returns 0 on success, < 0 on error
1072 */
4be44fcd 1073static int __init acpi_parse_madt_ioapic_entries(void)
1da177e4
LT
1074{
1075 int count;
1076
1077 /*
1078 * ACPI interpreter is required to complete interrupt setup,
1079 * so if it is off, don't enumerate the io-apics with ACPI.
1080 * If MPS is present, it will handle them,
1081 * otherwise the system will stay in PIC mode
1082 */
6b2b171a 1083 if (acpi_disabled || acpi_noirq)
1da177e4 1084 return -ENODEV;
1da177e4 1085
5f3b1a8b 1086 if (!cpu_has_apic)
d3b6a349
AK
1087 return -ENODEV;
1088
1da177e4 1089 /*
4be44fcd 1090 * if "noapic" boot option, don't look for IO-APICs
1da177e4
LT
1091 */
1092 if (skip_ioapic_setup) {
1093 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
4be44fcd 1094 "due to 'noapic' option.\n");
1da177e4
LT
1095 return -ENODEV;
1096 }
1097
e819813f
JL
1098 count = acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
1099 MAX_IO_APICS);
1da177e4
LT
1100 if (!count) {
1101 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
1102 return -ENODEV;
4be44fcd 1103 } else if (count < 0) {
1da177e4
LT
1104 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
1105 return count;
1106 }
1107
e819813f
JL
1108 count = acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE,
1109 acpi_parse_int_src_ovr, nr_irqs);
1da177e4 1110 if (count < 0) {
4be44fcd
LB
1111 printk(KERN_ERR PREFIX
1112 "Error parsing interrupt source overrides entry\n");
1da177e4
LT
1113 /* TBD: Cleanup to allow fallback to MPS */
1114 return count;
1115 }
1116
1117 /*
1118 * If BIOS did not supply an INT_SRC_OVR for the SCI
1119 * pretend we got one so we can set the SCI flags.
1120 */
1121 if (!acpi_sci_override_gsi)
9d2062b8
EB
1122 acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0,
1123 acpi_gbl_FADT.sci_interrupt);
1da177e4 1124
af901ca1 1125 /* Fill in identity legacy mappings where no override */
1da177e4
LT
1126 mp_config_acpi_legacy_irqs();
1127
e819813f
JL
1128 count = acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE,
1129 acpi_parse_nmi_src, nr_irqs);
1da177e4
LT
1130 if (count < 0) {
1131 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
1132 /* TBD: Cleanup to allow fallback to MPS */
1133 return count;
1134 }
1135
1136 return 0;
1137}
1138#else
1139static inline int acpi_parse_madt_ioapic_entries(void)
1140{
1141 return -1;
1142}
8466361a 1143#endif /* !CONFIG_X86_IO_APIC */
1da177e4 1144
cbf9bd60
YL
1145static void __init early_acpi_process_madt(void)
1146{
1147#ifdef CONFIG_X86_LOCAL_APIC
1148 int error;
1149
1150 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1151
1152 /*
1153 * Parse MADT LAPIC entries
1154 */
1155 error = early_acpi_parse_madt_lapic_addr_ovr();
1156 if (!error) {
1157 acpi_lapic = 1;
1158 smp_found_config = 1;
1159 }
1160 if (error == -EINVAL) {
1161 /*
1162 * Dell Precision Workstation 410, 610 come here.
1163 */
1164 printk(KERN_ERR PREFIX
1165 "Invalid BIOS MADT, disabling ACPI\n");
1166 disable_acpi();
1167 }
1168 }
1169#endif
1170}
1171
4be44fcd 1172static void __init acpi_process_madt(void)
1da177e4
LT
1173{
1174#ifdef CONFIG_X86_LOCAL_APIC
7f8f97c3 1175 int error;
1da177e4 1176
7f8f97c3 1177 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1da177e4
LT
1178
1179 /*
1180 * Parse MADT LAPIC entries
1181 */
1182 error = acpi_parse_madt_lapic_entries();
1183 if (!error) {
1184 acpi_lapic = 1;
1185
1186 /*
1187 * Parse MADT IO-APIC entries
1188 */
1189 error = acpi_parse_madt_ioapic_entries();
1190 if (!error) {
2f065aef 1191 acpi_set_irq_model_ioapic();
1da177e4
LT
1192
1193 smp_found_config = 1;
1da177e4
LT
1194 }
1195 }
1196 if (error == -EINVAL) {
1197 /*
1198 * Dell Precision Workstation 410, 610 come here.
1199 */
4be44fcd
LB
1200 printk(KERN_ERR PREFIX
1201 "Invalid BIOS MADT, disabling ACPI\n");
1da177e4
LT
1202 disable_acpi();
1203 }
7b37b5fd
LB
1204 } else {
1205 /*
1206 * ACPI found no MADT, and so ACPI wants UP PIC mode.
1207 * In the event an MPS table was found, forget it.
1208 * Boot with "acpi=off" to use MPS on such a system.
1209 */
1210 if (smp_found_config) {
1211 printk(KERN_WARNING PREFIX
1212 "No APIC-table, disabling MPS\n");
1213 smp_found_config = 0;
1214 }
1da177e4 1215 }
69b88afa
YL
1216
1217 /*
1218 * ACPI supports both logical (e.g. Hyper-Threading) and physical
1219 * processors, where MPS only supports physical.
1220 */
1221 if (acpi_lapic && acpi_ioapic)
1222 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
1223 "information\n");
1224 else if (acpi_lapic)
1225 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
1226 "configuration information\n");
1da177e4
LT
1227#endif
1228 return;
1229}
1230
1855256c 1231static int __init disable_acpi_irq(const struct dmi_system_id *d)
aea00143
AP
1232{
1233 if (!acpi_force) {
1234 printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
1235 d->ident);
1236 acpi_noirq_set();
1237 }
1238 return 0;
1239}
1240
1855256c 1241static int __init disable_acpi_pci(const struct dmi_system_id *d)
aea00143
AP
1242{
1243 if (!acpi_force) {
1244 printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
1245 d->ident);
1246 acpi_disable_pci();
1247 }
1248 return 0;
1249}
aea00143 1250
1855256c 1251static int __init dmi_disable_acpi(const struct dmi_system_id *d)
aea00143
AP
1252{
1253 if (!acpi_force) {
4be44fcd 1254 printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
aea00143
AP
1255 disable_acpi();
1256 } else {
1257 printk(KERN_NOTICE
1258 "Warning: DMI blacklist says broken, but acpi forced\n");
1259 }
1260 return 0;
1261}
1262
e2079c43 1263/*
ae10ccdc 1264 * Force ignoring BIOS IRQ0 override
e2079c43
RW
1265 */
1266static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
1267{
8d89adf4 1268 if (!acpi_skip_timer_override) {
ae10ccdc 1269 pr_notice("%s detected: Ignoring BIOS IRQ0 override\n",
8d89adf4
IM
1270 d->ident);
1271 acpi_skip_timer_override = 1;
1272 }
e2079c43
RW
1273 return 0;
1274}
1275
aea00143
AP
1276/*
1277 * If your system is blacklisted here, but you find that acpi=force
5b4c0b6f 1278 * works for you, please contact linux-acpi@vger.kernel.org
aea00143
AP
1279 */
1280static struct dmi_system_id __initdata acpi_dmi_table[] = {
1281 /*
1282 * Boxes that need ACPI disabled
1283 */
1284 {
4be44fcd
LB
1285 .callback = dmi_disable_acpi,
1286 .ident = "IBM Thinkpad",
1287 .matches = {
1288 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1289 DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
1290 },
1291 },
aea00143 1292
aea00143
AP
1293 /*
1294 * Boxes that need ACPI PCI IRQ routing disabled
1295 */
1296 {
4be44fcd
LB
1297 .callback = disable_acpi_irq,
1298 .ident = "ASUS A7V",
1299 .matches = {
1300 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
1301 DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
1302 /* newer BIOS, Revision 1011, does work */
1303 DMI_MATCH(DMI_BIOS_VERSION,
1304 "ASUS A7V ACPI BIOS Revision 1007"),
1305 },
1306 },
74586fca
LB
1307 {
1308 /*
1309 * Latest BIOS for IBM 600E (1.16) has bad pcinum
1310 * for LPC bridge, which is needed for the PCI
1311 * interrupt links to work. DSDT fix is in bug 5966.
1312 * 2645, 2646 model numbers are shared with 600/600E/600X
1313 */
1314 .callback = disable_acpi_irq,
1315 .ident = "IBM Thinkpad 600 Series 2645",
1316 .matches = {
1317 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1318 DMI_MATCH(DMI_BOARD_NAME, "2645"),
1319 },
1320 },
1321 {
1322 .callback = disable_acpi_irq,
1323 .ident = "IBM Thinkpad 600 Series 2646",
1324 .matches = {
1325 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1326 DMI_MATCH(DMI_BOARD_NAME, "2646"),
1327 },
1328 },
aea00143
AP
1329 /*
1330 * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
1331 */
4be44fcd
LB
1332 { /* _BBN 0 bug */
1333 .callback = disable_acpi_pci,
1334 .ident = "ASUS PR-DLS",
1335 .matches = {
1336 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1337 DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
1338 DMI_MATCH(DMI_BIOS_VERSION,
1339 "ASUS PR-DLS ACPI BIOS Revision 1010"),
1340 DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
1341 },
1342 },
aea00143 1343 {
4be44fcd
LB
1344 .callback = disable_acpi_pci,
1345 .ident = "Acer TravelMate 36x Laptop",
1346 .matches = {
1347 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
1348 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
1349 },
1350 },
35af2821
AH
1351 {}
1352};
1353
1354/* second table for DMI checks that should run after early-quirks */
1355static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
e2079c43
RW
1356 /*
1357 * HP laptops which use a DSDT reporting as HP/SB400/10000,
1358 * which includes some code which overrides all temperature
1359 * trip points to 16C if the INTIN2 input of the I/O APIC
1360 * is enabled. This input is incorrectly designated the
1361 * ISA IRQ 0 via an interrupt source override even though
1362 * it is wired to the output of the master 8259A and INTIN0
ae10ccdc 1363 * is not connected at all. Force ignoring BIOS IRQ0
e2079c43
RW
1364 * override in that cases.
1365 */
e84956f9
RW
1366 {
1367 .callback = dmi_ignore_irq0_timer_override,
1368 .ident = "HP nx6115 laptop",
1369 .matches = {
1370 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1371 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6115"),
1372 },
1373 },
e2079c43
RW
1374 {
1375 .callback = dmi_ignore_irq0_timer_override,
1376 .ident = "HP NX6125 laptop",
1377 .matches = {
1378 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1379 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
1380 },
1381 },
1382 {
1383 .callback = dmi_ignore_irq0_timer_override,
1384 .ident = "HP NX6325 laptop",
1385 .matches = {
1386 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1387 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
1388 },
1389 },
e84956f9
RW
1390 {
1391 .callback = dmi_ignore_irq0_timer_override,
1392 .ident = "HP 6715b laptop",
1393 .matches = {
1394 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1395 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
1396 },
1397 },
f6b54f08
FT
1398 {
1399 .callback = dmi_ignore_irq0_timer_override,
1400 .ident = "FUJITSU SIEMENS",
1401 .matches = {
1402 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
1403 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO PRO V2030"),
1404 },
1405 },
4be44fcd 1406 {}
aea00143
AP
1407};
1408
1da177e4
LT
1409/*
1410 * acpi_boot_table_init() and acpi_boot_init()
1411 * called from setup_arch(), always.
1412 * 1. checksums all tables
1413 * 2. enumerates lapics
1414 * 3. enumerates io-apics
1415 *
1416 * acpi_table_init() is separate to allow reading SRAT without
1417 * other side effects.
1418 *
1419 * side effects of acpi_boot_init:
1420 * acpi_lapic = 1 if LAPIC found
1421 * acpi_ioapic = 1 if IOAPIC found
1422 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
1423 * if acpi_blacklisted() acpi_disabled = 1;
1424 * acpi_irq_model=...
1425 * ...
1da177e4
LT
1426 */
1427
8558e394 1428void __init acpi_boot_table_init(void)
1da177e4 1429{
aea00143 1430 dmi_check_system(acpi_dmi_table);
aea00143 1431
1da177e4
LT
1432 /*
1433 * If acpi_disabled, bail out
1da177e4 1434 */
68ca4069 1435 if (acpi_disabled)
8558e394 1436 return;
1da177e4 1437
5f3b1a8b 1438 /*
1da177e4
LT
1439 * Initialize the ACPI boot-time table parser.
1440 */
8558e394 1441 if (acpi_table_init()) {
1da177e4 1442 disable_acpi();
8558e394 1443 return;
1da177e4 1444 }
1da177e4 1445
5f3b1a8b 1446 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
1da177e4
LT
1447
1448 /*
1449 * blacklist may disable ACPI entirely
1450 */
8558e394 1451 if (acpi_blacklisted()) {
1da177e4
LT
1452 if (acpi_force) {
1453 printk(KERN_WARNING PREFIX "acpi=force override\n");
1454 } else {
1455 printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
1456 disable_acpi();
8558e394 1457 return;
1da177e4
LT
1458 }
1459 }
cbf9bd60
YL
1460}
1461
1462int __init early_acpi_boot_init(void)
1463{
1464 /*
1465 * If acpi_disabled, bail out
cbf9bd60 1466 */
68ca4069 1467 if (acpi_disabled)
cbf9bd60
YL
1468 return 1;
1469
1470 /*
1471 * Process the Multiple APIC Description Table (MADT), if present
1472 */
1473 early_acpi_process_madt();
1da177e4
LT
1474
1475 return 0;
1476}
1477
1da177e4
LT
1478int __init acpi_boot_init(void)
1479{
35af2821
AH
1480 /* those are executed after early-quirks are executed */
1481 dmi_check_system(acpi_dmi_table_late);
1482
1da177e4
LT
1483 /*
1484 * If acpi_disabled, bail out
1da177e4 1485 */
68ca4069 1486 if (acpi_disabled)
4be44fcd 1487 return 1;
1da177e4 1488
5f3b1a8b 1489 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
1da177e4
LT
1490
1491 /*
1492 * set sci_int and PM timer address
1493 */
ceb6c468 1494 acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
1da177e4
LT
1495
1496 /*
1497 * Process the Multiple APIC Description Table (MADT), if present
1498 */
1499 acpi_process_madt();
1500
5f3b1a8b 1501 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
1da177e4 1502
b72d0db9
TG
1503 if (!acpi_noirq)
1504 x86_init.pci.init = pci_acpi_init;
1505
1da177e4
LT
1506 return 0;
1507}
1a3f239d
RR
1508
1509static int __init parse_acpi(char *arg)
1510{
1511 if (!arg)
1512 return -EINVAL;
1513
1514 /* "acpi=off" disables both ACPI table parsing and interpreter */
1515 if (strcmp(arg, "off") == 0) {
1516 disable_acpi();
1517 }
1518 /* acpi=force to over-ride black-list */
1519 else if (strcmp(arg, "force") == 0) {
1520 acpi_force = 1;
1a3f239d
RR
1521 acpi_disabled = 0;
1522 }
1523 /* acpi=strict disables out-of-spec workarounds */
1524 else if (strcmp(arg, "strict") == 0) {
1525 acpi_strict = 1;
1526 }
237889bf
ZY
1527 /* acpi=rsdt use RSDT instead of XSDT */
1528 else if (strcmp(arg, "rsdt") == 0) {
fab46105 1529 acpi_gbl_do_not_use_xsdt = TRUE;
237889bf 1530 }
1a3f239d
RR
1531 /* "acpi=noirq" disables ACPI interrupt routing */
1532 else if (strcmp(arg, "noirq") == 0) {
1533 acpi_noirq_set();
aa2110cb
LM
1534 }
1535 /* "acpi=copy_dsdt" copys DSDT */
1536 else if (strcmp(arg, "copy_dsdt") == 0) {
1537 acpi_gbl_copy_dsdt_locally = 1;
9ad95879
NR
1538 }
1539 /* "acpi=nocmcff" disables FF mode for corrected errors */
1540 else if (strcmp(arg, "nocmcff") == 0) {
1541 acpi_disable_cmcff = 1;
1a3f239d
RR
1542 } else {
1543 /* Core will printk when we return error. */
1544 return -EINVAL;
1545 }
1546 return 0;
1547}
1548early_param("acpi", parse_acpi);
1549
1550/* FIXME: Using pci= for an ACPI parameter is a travesty. */
1551static int __init parse_pci(char *arg)
1552{
1553 if (arg && strcmp(arg, "noacpi") == 0)
1554 acpi_disable_pci();
1555 return 0;
1556}
1557early_param("pci", parse_pci);
1558
3c999f14
YL
1559int __init acpi_mps_check(void)
1560{
1561#if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
1562/* mptable code is not built-in*/
1563 if (acpi_disabled || acpi_noirq) {
1564 printk(KERN_WARNING "MPS support code is not built-in.\n"
1565 "Using acpi=off or acpi=noirq or pci=noacpi "
1566 "may have problem\n");
1567 return 1;
1568 }
1569#endif
1570 return 0;
1571}
1572
1a3f239d
RR
1573#ifdef CONFIG_X86_IO_APIC
1574static int __init parse_acpi_skip_timer_override(char *arg)
1575{
1576 acpi_skip_timer_override = 1;
1577 return 0;
1578}
1579early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
fa18f477
AK
1580
1581static int __init parse_acpi_use_timer_override(char *arg)
1582{
1583 acpi_use_timer_override = 1;
1584 return 0;
1585}
1586early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
1a3f239d
RR
1587#endif /* CONFIG_X86_IO_APIC */
1588
1589static int __init setup_acpi_sci(char *s)
1590{
1591 if (!s)
1592 return -EINVAL;
1593 if (!strcmp(s, "edge"))
5f3b1a8b
AS
1594 acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
1595 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
1a3f239d 1596 else if (!strcmp(s, "level"))
5f3b1a8b
AS
1597 acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
1598 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
1a3f239d 1599 else if (!strcmp(s, "high"))
5f3b1a8b
AS
1600 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
1601 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
1a3f239d 1602 else if (!strcmp(s, "low"))
5f3b1a8b
AS
1603 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
1604 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
1a3f239d
RR
1605 else
1606 return -EINVAL;
1607 return 0;
1608}
1609early_param("acpi_sci", setup_acpi_sci);
d0a9081b
AM
1610
1611int __acpi_acquire_global_lock(unsigned int *lock)
1612{
1613 unsigned int old, new, val;
1614 do {
1615 old = *lock;
1616 new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
1617 val = cmpxchg(lock, old, new);
1618 } while (unlikely (val != old));
1619 return (new < 3) ? -1 : 0;
1620}
1621
1622int __acpi_release_global_lock(unsigned int *lock)
1623{
1624 unsigned int old, new, val;
1625 do {
1626 old = *lock;
1627 new = old & ~0x3;
1628 val = cmpxchg(lock, old, new);
1629 } while (unlikely (val != old));
1630 return old & 0x1;
1631}
8e30524d
TR
1632
1633void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
1634{
1635 e820_add_region(addr, size, E820_ACPI);
1636 update_e820();
1637}