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