Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[linux-2.6/libata-dev.git] / arch / x86 / kernel / acpi / boot.c
blob230c8ea878e5f41ce3f63d2be6a4490759e46b49
1 /*
2 * boot.c - Architecture-Specific Low-Level ACPI Boot Support
4 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
5 * Copyright (C) 2001 Jun Nakajima <jun.nakajima@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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.
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
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26 #include <linux/init.h>
27 #include <linux/acpi.h>
28 #include <linux/acpi_pmtmr.h>
29 #include <linux/efi.h>
30 #include <linux/cpumask.h>
31 #include <linux/module.h>
32 #include <linux/dmi.h>
33 #include <linux/irq.h>
34 #include <linux/slab.h>
35 #include <linux/bootmem.h>
36 #include <linux/ioport.h>
37 #include <linux/pci.h>
39 #include <asm/pci_x86.h>
40 #include <asm/pgtable.h>
41 #include <asm/io_apic.h>
42 #include <asm/apic.h>
43 #include <asm/io.h>
44 #include <asm/mpspec.h>
45 #include <asm/smp.h>
47 static int __initdata acpi_force = 0;
48 u32 acpi_rsdt_forced;
49 int acpi_disabled;
50 EXPORT_SYMBOL(acpi_disabled);
52 #ifdef CONFIG_X86_64
53 # include <asm/proto.h>
54 #endif /* X86 */
56 #define BAD_MADT_ENTRY(entry, end) ( \
57 (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
58 ((struct acpi_subtable_header *)entry)->length < sizeof(*entry))
60 #define PREFIX "ACPI: "
62 int acpi_noirq; /* skip ACPI IRQ initialization */
63 int acpi_pci_disabled; /* skip ACPI PCI scan and IRQ initialization */
64 EXPORT_SYMBOL(acpi_pci_disabled);
66 int acpi_lapic;
67 int acpi_ioapic;
68 int acpi_strict;
70 u8 acpi_sci_flags __initdata;
71 int acpi_sci_override_gsi __initdata;
72 int acpi_skip_timer_override __initdata;
73 int acpi_use_timer_override __initdata;
74 int acpi_fix_pin2_polarity __initdata;
76 #ifdef CONFIG_X86_LOCAL_APIC
77 static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
78 #endif
80 #ifndef __HAVE_ARCH_CMPXCHG
81 #warning ACPI uses CMPXCHG, i486 and later hardware
82 #endif
84 /* --------------------------------------------------------------------------
85 Boot-time Configuration
86 -------------------------------------------------------------------------- */
89 * The default interrupt routing model is PIC (8259). This gets
90 * overridden if IOAPICs are enumerated (below).
92 enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
96 * ISA irqs by default are the first 16 gsis but can be
97 * any gsi as specified by an interrupt source override.
99 static 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
103 static unsigned int gsi_to_irq(unsigned int gsi)
105 unsigned int irq = gsi + NR_IRQS_LEGACY;
106 unsigned int i;
108 for (i = 0; i < NR_IRQS_LEGACY; i++) {
109 if (isa_irq_to_gsi[i] == gsi) {
110 return i;
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.
118 if (gsi >= NR_IRQS_LEGACY)
119 irq = gsi;
120 else
121 irq = gsi_top + gsi;
123 return irq;
126 static u32 irq_to_gsi(int irq)
128 unsigned int gsi;
130 if (irq < NR_IRQS_LEGACY)
131 gsi = isa_irq_to_gsi[irq];
132 else if (irq < gsi_top)
133 gsi = irq;
134 else if (irq < (gsi_top + NR_IRQS_LEGACY))
135 gsi = irq - gsi_top;
136 else
137 gsi = 0xffffffff;
139 return gsi;
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.
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.
154 char *__init __acpi_map_table(unsigned long phys, unsigned long size)
157 if (!phys || !size)
158 return NULL;
160 return early_ioremap(phys, size);
162 void __init __acpi_unmap_table(char *map, unsigned long size)
164 if (!map || !size)
165 return;
167 early_iounmap(map, size);
170 #ifdef CONFIG_X86_LOCAL_APIC
171 static int __init acpi_parse_madt(struct acpi_table_header *table)
173 struct acpi_table_madt *madt = NULL;
175 if (!cpu_has_apic)
176 return -EINVAL;
178 madt = (struct acpi_table_madt *)table;
179 if (!madt) {
180 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
181 return -ENODEV;
184 if (madt->address) {
185 acpi_lapic_addr = (u64) madt->address;
187 printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
188 madt->address);
191 default_acpi_madt_oem_check(madt->header.oem_id,
192 madt->header.oem_table_id);
194 return 0;
197 static void __cpuinit acpi_register_lapic(int id, u8 enabled)
199 unsigned int ver = 0;
201 if (id >= (MAX_LOCAL_APIC-1)) {
202 printk(KERN_INFO PREFIX "skipped apicid that is too big\n");
203 return;
206 if (!enabled) {
207 ++disabled_cpus;
208 return;
211 if (boot_cpu_physical_apicid != -1U)
212 ver = apic_version[boot_cpu_physical_apicid];
214 generic_processor_info(id, ver);
217 static int __init
218 acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
220 struct acpi_madt_local_x2apic *processor = NULL;
221 int apic_id;
222 u8 enabled;
224 processor = (struct acpi_madt_local_x2apic *)header;
226 if (BAD_MADT_ENTRY(processor, end))
227 return -EINVAL;
229 acpi_table_print_madt_entry(header);
231 apic_id = processor->local_apic_id;
232 enabled = processor->lapic_flags & ACPI_MADT_ENABLED;
233 #ifdef CONFIG_X86_X2APIC
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.
241 if (!apic->apic_id_valid(apic_id) && enabled)
242 printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
243 else
244 acpi_register_lapic(apic_id, enabled);
245 #else
246 printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
247 #endif
249 return 0;
252 static int __init
253 acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
255 struct acpi_madt_local_apic *processor = NULL;
257 processor = (struct acpi_madt_local_apic *)header;
259 if (BAD_MADT_ENTRY(processor, end))
260 return -EINVAL;
262 acpi_table_print_madt_entry(header);
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.
271 acpi_register_lapic(processor->id, /* APIC ID */
272 processor->lapic_flags & ACPI_MADT_ENABLED);
274 return 0;
277 static int __init
278 acpi_parse_sapic(struct acpi_subtable_header *header, const unsigned long end)
280 struct acpi_madt_local_sapic *processor = NULL;
282 processor = (struct acpi_madt_local_sapic *)header;
284 if (BAD_MADT_ENTRY(processor, end))
285 return -EINVAL;
287 acpi_table_print_madt_entry(header);
289 acpi_register_lapic((processor->id << 8) | processor->eid,/* APIC ID */
290 processor->lapic_flags & ACPI_MADT_ENABLED);
292 return 0;
295 static int __init
296 acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
297 const unsigned long end)
299 struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
301 lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
303 if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
304 return -EINVAL;
306 acpi_lapic_addr = lapic_addr_ovr->address;
308 return 0;
311 static int __init
312 acpi_parse_x2apic_nmi(struct acpi_subtable_header *header,
313 const unsigned long end)
315 struct acpi_madt_local_x2apic_nmi *x2apic_nmi = NULL;
317 x2apic_nmi = (struct acpi_madt_local_x2apic_nmi *)header;
319 if (BAD_MADT_ENTRY(x2apic_nmi, end))
320 return -EINVAL;
322 acpi_table_print_madt_entry(header);
324 if (x2apic_nmi->lint != 1)
325 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
327 return 0;
330 static int __init
331 acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
333 struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
335 lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
337 if (BAD_MADT_ENTRY(lapic_nmi, end))
338 return -EINVAL;
340 acpi_table_print_madt_entry(header);
342 if (lapic_nmi->lint != 1)
343 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
345 return 0;
348 #endif /*CONFIG_X86_LOCAL_APIC */
350 #ifdef CONFIG_X86_IO_APIC
352 static int __init
353 acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
355 struct acpi_madt_io_apic *ioapic = NULL;
357 ioapic = (struct acpi_madt_io_apic *)header;
359 if (BAD_MADT_ENTRY(ioapic, end))
360 return -EINVAL;
362 acpi_table_print_madt_entry(header);
364 mp_register_ioapic(ioapic->id,
365 ioapic->address, ioapic->global_irq_base);
367 return 0;
371 * Parse Interrupt Source Override for the ACPI SCI
373 static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger, u32 gsi)
375 if (trigger == 0) /* compatible SCI trigger is level */
376 trigger = 3;
378 if (polarity == 0) /* compatible SCI polarity is low */
379 polarity = 3;
381 /* Command-line over-ride via acpi_sci= */
382 if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
383 trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
385 if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
386 polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
389 * mp_config_acpi_legacy_irqs() already setup IRQs < 16
390 * If GSI is < 16, this will update its flags,
391 * else it will create a new mp_irqs[] entry.
393 mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
396 * stash over-ride to indicate we've been here
397 * and for later update of acpi_gbl_FADT
399 acpi_sci_override_gsi = gsi;
400 return;
403 static int __init
404 acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
405 const unsigned long end)
407 struct acpi_madt_interrupt_override *intsrc = NULL;
409 intsrc = (struct acpi_madt_interrupt_override *)header;
411 if (BAD_MADT_ENTRY(intsrc, end))
412 return -EINVAL;
414 acpi_table_print_madt_entry(header);
416 if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
417 acpi_sci_ioapic_setup(intsrc->source_irq,
418 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
419 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
420 intsrc->global_irq);
421 return 0;
424 if (intsrc->source_irq == 0) {
425 if (acpi_skip_timer_override) {
426 printk(PREFIX "BIOS IRQ0 override ignored.\n");
427 return 0;
430 if ((intsrc->global_irq == 2) && acpi_fix_pin2_polarity
431 && (intsrc->inti_flags & ACPI_MADT_POLARITY_MASK)) {
432 intsrc->inti_flags &= ~ACPI_MADT_POLARITY_MASK;
433 printk(PREFIX "BIOS IRQ0 pin2 override: forcing polarity to high active.\n");
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);
442 return 0;
445 static int __init
446 acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
448 struct acpi_madt_nmi_source *nmi_src = NULL;
450 nmi_src = (struct acpi_madt_nmi_source *)header;
452 if (BAD_MADT_ENTRY(nmi_src, end))
453 return -EINVAL;
455 acpi_table_print_madt_entry(header);
457 /* TBD: Support nimsrc entries? */
459 return 0;
462 #endif /* CONFIG_X86_IO_APIC */
465 * acpi_pic_sci_set_trigger()
467 * use ELCR to set PIC-mode trigger type for SCI
469 * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
470 * it may require Edge Trigger -- use "acpi_sci=edge"
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.
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)
478 void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
480 unsigned int mask = 1 << irq;
481 unsigned int old, new;
483 /* Real old ELCR mask */
484 old = inb(0x4d0) | (inb(0x4d1) << 8);
487 * If we use ACPI to set PCI IRQs, then we should clear ELCR
488 * since we will set it correctly as we enable the PCI irq
489 * routing.
491 new = acpi_noirq ? old : 0;
494 * Update SCI information in the ELCR, it isn't in the PCI
495 * routing tables..
497 switch (trigger) {
498 case 1: /* Edge - clear */
499 new &= ~mask;
500 break;
501 case 3: /* Level - set */
502 new |= mask;
503 break;
506 if (old == new)
507 return;
509 printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
510 outb(new, 0x4d0);
511 outb(new >> 8, 0x4d1);
514 int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
516 *irq = gsi_to_irq(gsi);
518 #ifdef CONFIG_X86_IO_APIC
519 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
520 setup_IO_APIC_irq_extra(gsi);
521 #endif
523 return 0;
525 EXPORT_SYMBOL_GPL(acpi_gsi_to_irq);
527 int acpi_isa_irq_to_gsi(unsigned isa_irq, u32 *gsi)
529 if (isa_irq >= 16)
530 return -1;
531 *gsi = irq_to_gsi(isa_irq);
532 return 0;
535 static int acpi_register_gsi_pic(struct device *dev, u32 gsi,
536 int trigger, int polarity)
538 #ifdef CONFIG_PCI
540 * Make sure all (legacy) PCI IRQs are set as level-triggered.
542 if (trigger == ACPI_LEVEL_SENSITIVE)
543 eisa_set_level_irq(gsi);
544 #endif
546 return gsi;
549 static int acpi_register_gsi_ioapic(struct device *dev, u32 gsi,
550 int trigger, int polarity)
552 #ifdef CONFIG_X86_IO_APIC
553 gsi = mp_register_gsi(dev, gsi, trigger, polarity);
554 #endif
556 return gsi;
559 int (*__acpi_register_gsi)(struct device *dev, u32 gsi,
560 int trigger, int polarity) = acpi_register_gsi_pic;
563 * success: return IRQ number (>=0)
564 * failure: return < 0
566 int acpi_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
568 unsigned int irq;
569 unsigned int plat_gsi = gsi;
571 plat_gsi = (*__acpi_register_gsi)(dev, gsi, trigger, polarity);
572 irq = gsi_to_irq(plat_gsi);
574 return irq;
576 EXPORT_SYMBOL_GPL(acpi_register_gsi);
578 void acpi_unregister_gsi(u32 gsi)
581 EXPORT_SYMBOL_GPL(acpi_unregister_gsi);
583 void __init acpi_set_irq_model_pic(void)
585 acpi_irq_model = ACPI_IRQ_MODEL_PIC;
586 __acpi_register_gsi = acpi_register_gsi_pic;
587 acpi_ioapic = 0;
590 void __init acpi_set_irq_model_ioapic(void)
592 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
593 __acpi_register_gsi = acpi_register_gsi_ioapic;
594 acpi_ioapic = 1;
598 * ACPI based hotplug support for CPU
600 #ifdef CONFIG_ACPI_HOTPLUG_CPU
601 #include <acpi/processor.h>
603 static void __cpuinit acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
605 #ifdef CONFIG_ACPI_NUMA
606 int nid;
608 nid = acpi_get_node(handle);
609 if (nid == -1 || !node_online(nid))
610 return;
611 set_apicid_to_node(physid, nid);
612 numa_set_node(cpu, nid);
613 #endif
616 static int __cpuinit _acpi_map_lsapic(acpi_handle handle, int *pcpu)
618 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
619 union acpi_object *obj;
620 struct acpi_madt_local_apic *lapic;
621 cpumask_var_t tmp_map, new_map;
622 u8 physid;
623 int cpu;
624 int retval = -ENOMEM;
626 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
627 return -EINVAL;
629 if (!buffer.length || !buffer.pointer)
630 return -EINVAL;
632 obj = buffer.pointer;
633 if (obj->type != ACPI_TYPE_BUFFER ||
634 obj->buffer.length < sizeof(*lapic)) {
635 kfree(buffer.pointer);
636 return -EINVAL;
639 lapic = (struct acpi_madt_local_apic *)obj->buffer.pointer;
641 if (lapic->header.type != ACPI_MADT_TYPE_LOCAL_APIC ||
642 !(lapic->lapic_flags & ACPI_MADT_ENABLED)) {
643 kfree(buffer.pointer);
644 return -EINVAL;
647 physid = lapic->id;
649 kfree(buffer.pointer);
650 buffer.length = ACPI_ALLOCATE_BUFFER;
651 buffer.pointer = NULL;
652 lapic = NULL;
654 if (!alloc_cpumask_var(&tmp_map, GFP_KERNEL))
655 goto out;
657 if (!alloc_cpumask_var(&new_map, GFP_KERNEL))
658 goto free_tmp_map;
660 cpumask_copy(tmp_map, cpu_present_mask);
661 acpi_register_lapic(physid, ACPI_MADT_ENABLED);
664 * If acpi_register_lapic successfully generates a new logical cpu
665 * number, then the following will get us exactly what was mapped
667 cpumask_andnot(new_map, cpu_present_mask, tmp_map);
668 if (cpumask_empty(new_map)) {
669 printk ("Unable to map lapic to logical cpu number\n");
670 retval = -EINVAL;
671 goto free_new_map;
674 acpi_processor_set_pdc(handle);
676 cpu = cpumask_first(new_map);
677 acpi_map_cpu2node(handle, cpu, physid);
679 *pcpu = cpu;
680 retval = 0;
682 free_new_map:
683 free_cpumask_var(new_map);
684 free_tmp_map:
685 free_cpumask_var(tmp_map);
686 out:
687 return retval;
690 /* wrapper to silence section mismatch warning */
691 int __ref acpi_map_lsapic(acpi_handle handle, int *pcpu)
693 return _acpi_map_lsapic(handle, pcpu);
695 EXPORT_SYMBOL(acpi_map_lsapic);
697 int acpi_unmap_lsapic(int cpu)
699 #ifdef CONFIG_ACPI_NUMA
700 set_apicid_to_node(per_cpu(x86_cpu_to_apicid, cpu), NUMA_NO_NODE);
701 #endif
703 per_cpu(x86_cpu_to_apicid, cpu) = -1;
704 set_cpu_present(cpu, false);
705 num_processors--;
707 return (0);
710 EXPORT_SYMBOL(acpi_unmap_lsapic);
711 #endif /* CONFIG_ACPI_HOTPLUG_CPU */
713 int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
715 /* TBD */
716 return -EINVAL;
719 EXPORT_SYMBOL(acpi_register_ioapic);
721 int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
723 /* TBD */
724 return -EINVAL;
727 EXPORT_SYMBOL(acpi_unregister_ioapic);
729 static int __init acpi_parse_sbf(struct acpi_table_header *table)
731 struct acpi_table_boot *sb;
733 sb = (struct acpi_table_boot *)table;
734 if (!sb) {
735 printk(KERN_WARNING PREFIX "Unable to map SBF\n");
736 return -ENODEV;
739 sbf_port = sb->cmos_index; /* Save CMOS port */
741 return 0;
744 #ifdef CONFIG_HPET_TIMER
745 #include <asm/hpet.h>
747 static struct __initdata resource *hpet_res;
749 static int __init acpi_parse_hpet(struct acpi_table_header *table)
751 struct acpi_table_hpet *hpet_tbl;
753 hpet_tbl = (struct acpi_table_hpet *)table;
754 if (!hpet_tbl) {
755 printk(KERN_WARNING PREFIX "Unable to map HPET\n");
756 return -ENODEV;
759 if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
760 printk(KERN_WARNING PREFIX "HPET timers must be located in "
761 "memory.\n");
762 return -1;
765 hpet_address = hpet_tbl->address.address;
766 hpet_blockid = hpet_tbl->sequence;
769 * Some broken BIOSes advertise HPET at 0x0. We really do not
770 * want to allocate a resource there.
772 if (!hpet_address) {
773 printk(KERN_WARNING PREFIX
774 "HPET id: %#x base: %#lx is invalid\n",
775 hpet_tbl->id, hpet_address);
776 return 0;
778 #ifdef CONFIG_X86_64
780 * Some even more broken BIOSes advertise HPET at
781 * 0xfed0000000000000 instead of 0xfed00000. Fix it up and add
782 * some noise:
784 if (hpet_address == 0xfed0000000000000UL) {
785 if (!hpet_force_user) {
786 printk(KERN_WARNING PREFIX "HPET id: %#x "
787 "base: 0xfed0000000000000 is bogus\n "
788 "try hpet=force on the kernel command line to "
789 "fix it up to 0xfed00000.\n", hpet_tbl->id);
790 hpet_address = 0;
791 return 0;
793 printk(KERN_WARNING PREFIX
794 "HPET id: %#x base: 0xfed0000000000000 fixed up "
795 "to 0xfed00000.\n", hpet_tbl->id);
796 hpet_address >>= 32;
798 #endif
799 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
800 hpet_tbl->id, hpet_address);
803 * Allocate and initialize the HPET firmware resource for adding into
804 * the resource tree during the lateinit timeframe.
806 #define HPET_RESOURCE_NAME_SIZE 9
807 hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
809 hpet_res->name = (void *)&hpet_res[1];
810 hpet_res->flags = IORESOURCE_MEM;
811 snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE, "HPET %u",
812 hpet_tbl->sequence);
814 hpet_res->start = hpet_address;
815 hpet_res->end = hpet_address + (1 * 1024) - 1;
817 return 0;
821 * hpet_insert_resource inserts the HPET resources used into the resource
822 * tree.
824 static __init int hpet_insert_resource(void)
826 if (!hpet_res)
827 return 1;
829 return insert_resource(&iomem_resource, hpet_res);
832 late_initcall(hpet_insert_resource);
834 #else
835 #define acpi_parse_hpet NULL
836 #endif
838 static int __init acpi_parse_fadt(struct acpi_table_header *table)
841 #ifdef CONFIG_X86_PM_TIMER
842 /* detect the location of the ACPI PM Timer */
843 if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
844 /* FADT rev. 2 */
845 if (acpi_gbl_FADT.xpm_timer_block.space_id !=
846 ACPI_ADR_SPACE_SYSTEM_IO)
847 return 0;
849 pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
851 * "X" fields are optional extensions to the original V1.0
852 * fields, so we must selectively expand V1.0 fields if the
853 * corresponding X field is zero.
855 if (!pmtmr_ioport)
856 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
857 } else {
858 /* FADT rev. 1 */
859 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
861 if (pmtmr_ioport)
862 printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
863 pmtmr_ioport);
864 #endif
865 return 0;
868 #ifdef CONFIG_X86_LOCAL_APIC
870 * Parse LAPIC entries in MADT
871 * returns 0 on success, < 0 on error
874 static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
876 int count;
878 if (!cpu_has_apic)
879 return -ENODEV;
882 * Note that the LAPIC address is obtained from the MADT (32-bit value)
883 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
886 count =
887 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
888 acpi_parse_lapic_addr_ovr, 0);
889 if (count < 0) {
890 printk(KERN_ERR PREFIX
891 "Error parsing LAPIC address override entry\n");
892 return count;
895 register_lapic_address(acpi_lapic_addr);
897 return count;
900 static int __init acpi_parse_madt_lapic_entries(void)
902 int count;
903 int x2count = 0;
905 if (!cpu_has_apic)
906 return -ENODEV;
909 * Note that the LAPIC address is obtained from the MADT (32-bit value)
910 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
913 count =
914 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
915 acpi_parse_lapic_addr_ovr, 0);
916 if (count < 0) {
917 printk(KERN_ERR PREFIX
918 "Error parsing LAPIC address override entry\n");
919 return count;
922 register_lapic_address(acpi_lapic_addr);
924 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
925 acpi_parse_sapic, MAX_LOCAL_APIC);
927 if (!count) {
928 x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
929 acpi_parse_x2apic, MAX_LOCAL_APIC);
930 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
931 acpi_parse_lapic, MAX_LOCAL_APIC);
933 if (!count && !x2count) {
934 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
935 /* TBD: Cleanup to allow fallback to MPS */
936 return -ENODEV;
937 } else if (count < 0 || x2count < 0) {
938 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
939 /* TBD: Cleanup to allow fallback to MPS */
940 return count;
943 x2count =
944 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI,
945 acpi_parse_x2apic_nmi, 0);
946 count =
947 acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0);
948 if (count < 0 || x2count < 0) {
949 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
950 /* TBD: Cleanup to allow fallback to MPS */
951 return count;
953 return 0;
955 #endif /* CONFIG_X86_LOCAL_APIC */
957 #ifdef CONFIG_X86_IO_APIC
958 #define MP_ISA_BUS 0
960 #ifdef CONFIG_X86_ES7000
961 extern int es7000_plat;
962 #endif
964 void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
966 int ioapic;
967 int pin;
968 struct mpc_intsrc mp_irq;
971 * Convert 'gsi' to 'ioapic.pin'.
973 ioapic = mp_find_ioapic(gsi);
974 if (ioapic < 0)
975 return;
976 pin = mp_find_ioapic_pin(ioapic, gsi);
979 * TBD: This check is for faulty timer entries, where the override
980 * erroneously sets the trigger to level, resulting in a HUGE
981 * increase of timer interrupts!
983 if ((bus_irq == 0) && (trigger == 3))
984 trigger = 1;
986 mp_irq.type = MP_INTSRC;
987 mp_irq.irqtype = mp_INT;
988 mp_irq.irqflag = (trigger << 2) | polarity;
989 mp_irq.srcbus = MP_ISA_BUS;
990 mp_irq.srcbusirq = bus_irq; /* IRQ */
991 mp_irq.dstapic = mpc_ioapic_id(ioapic); /* APIC ID */
992 mp_irq.dstirq = pin; /* INTIN# */
994 mp_save_irq(&mp_irq);
996 isa_irq_to_gsi[bus_irq] = gsi;
999 void __init mp_config_acpi_legacy_irqs(void)
1001 int i;
1002 struct mpc_intsrc mp_irq;
1004 #ifdef CONFIG_EISA
1006 * Fabricate the legacy ISA bus (bus #31).
1008 mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
1009 #endif
1010 set_bit(MP_ISA_BUS, mp_bus_not_pci);
1011 pr_debug("Bus #%d is ISA\n", MP_ISA_BUS);
1013 #ifdef CONFIG_X86_ES7000
1015 * Older generations of ES7000 have no legacy identity mappings
1017 if (es7000_plat == 1)
1018 return;
1019 #endif
1022 * Use the default configuration for the IRQs 0-15. Unless
1023 * overridden by (MADT) interrupt source override entries.
1025 for (i = 0; i < 16; i++) {
1026 int ioapic, pin;
1027 unsigned int dstapic;
1028 int idx;
1029 u32 gsi;
1031 /* Locate the gsi that irq i maps to. */
1032 if (acpi_isa_irq_to_gsi(i, &gsi))
1033 continue;
1036 * Locate the IOAPIC that manages the ISA IRQ.
1038 ioapic = mp_find_ioapic(gsi);
1039 if (ioapic < 0)
1040 continue;
1041 pin = mp_find_ioapic_pin(ioapic, gsi);
1042 dstapic = mpc_ioapic_id(ioapic);
1044 for (idx = 0; idx < mp_irq_entries; idx++) {
1045 struct mpc_intsrc *irq = mp_irqs + idx;
1047 /* Do we already have a mapping for this ISA IRQ? */
1048 if (irq->srcbus == MP_ISA_BUS && irq->srcbusirq == i)
1049 break;
1051 /* Do we already have a mapping for this IOAPIC pin */
1052 if (irq->dstapic == dstapic && irq->dstirq == pin)
1053 break;
1056 if (idx != mp_irq_entries) {
1057 printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
1058 continue; /* IRQ already used */
1061 mp_irq.type = MP_INTSRC;
1062 mp_irq.irqflag = 0; /* Conforming */
1063 mp_irq.srcbus = MP_ISA_BUS;
1064 mp_irq.dstapic = dstapic;
1065 mp_irq.irqtype = mp_INT;
1066 mp_irq.srcbusirq = i; /* Identity mapped */
1067 mp_irq.dstirq = pin;
1069 mp_save_irq(&mp_irq);
1073 static int mp_config_acpi_gsi(struct device *dev, u32 gsi, int trigger,
1074 int polarity)
1076 #ifdef CONFIG_X86_MPPARSE
1077 struct mpc_intsrc mp_irq;
1078 struct pci_dev *pdev;
1079 unsigned char number;
1080 unsigned int devfn;
1081 int ioapic;
1082 u8 pin;
1084 if (!acpi_ioapic)
1085 return 0;
1086 if (!dev)
1087 return 0;
1088 if (dev->bus != &pci_bus_type)
1089 return 0;
1091 pdev = to_pci_dev(dev);
1092 number = pdev->bus->number;
1093 devfn = pdev->devfn;
1094 pin = pdev->pin;
1095 /* print the entry should happen on mptable identically */
1096 mp_irq.type = MP_INTSRC;
1097 mp_irq.irqtype = mp_INT;
1098 mp_irq.irqflag = (trigger == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
1099 (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
1100 mp_irq.srcbus = number;
1101 mp_irq.srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
1102 ioapic = mp_find_ioapic(gsi);
1103 mp_irq.dstapic = mpc_ioapic_id(ioapic);
1104 mp_irq.dstirq = mp_find_ioapic_pin(ioapic, gsi);
1106 mp_save_irq(&mp_irq);
1107 #endif
1108 return 0;
1111 int mp_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
1113 int ioapic;
1114 int ioapic_pin;
1115 struct io_apic_irq_attr irq_attr;
1117 if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
1118 return gsi;
1120 /* Don't set up the ACPI SCI because it's already set up */
1121 if (acpi_gbl_FADT.sci_interrupt == gsi)
1122 return gsi;
1124 ioapic = mp_find_ioapic(gsi);
1125 if (ioapic < 0) {
1126 printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
1127 return gsi;
1130 ioapic_pin = mp_find_ioapic_pin(ioapic, gsi);
1132 if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
1133 printk(KERN_ERR "Invalid reference to IOAPIC pin "
1134 "%d-%d\n", mpc_ioapic_id(ioapic),
1135 ioapic_pin);
1136 return gsi;
1139 if (enable_update_mptable)
1140 mp_config_acpi_gsi(dev, gsi, trigger, polarity);
1142 set_io_apic_irq_attr(&irq_attr, ioapic, ioapic_pin,
1143 trigger == ACPI_EDGE_SENSITIVE ? 0 : 1,
1144 polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
1145 io_apic_set_pci_routing(dev, gsi_to_irq(gsi), &irq_attr);
1147 return gsi;
1151 * Parse IOAPIC related entries in MADT
1152 * returns 0 on success, < 0 on error
1154 static int __init acpi_parse_madt_ioapic_entries(void)
1156 int count;
1159 * ACPI interpreter is required to complete interrupt setup,
1160 * so if it is off, don't enumerate the io-apics with ACPI.
1161 * If MPS is present, it will handle them,
1162 * otherwise the system will stay in PIC mode
1164 if (acpi_disabled || acpi_noirq)
1165 return -ENODEV;
1167 if (!cpu_has_apic)
1168 return -ENODEV;
1171 * if "noapic" boot option, don't look for IO-APICs
1173 if (skip_ioapic_setup) {
1174 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
1175 "due to 'noapic' option.\n");
1176 return -ENODEV;
1179 count =
1180 acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
1181 MAX_IO_APICS);
1182 if (!count) {
1183 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
1184 return -ENODEV;
1185 } else if (count < 0) {
1186 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
1187 return count;
1190 count =
1191 acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr,
1192 nr_irqs);
1193 if (count < 0) {
1194 printk(KERN_ERR PREFIX
1195 "Error parsing interrupt source overrides entry\n");
1196 /* TBD: Cleanup to allow fallback to MPS */
1197 return count;
1201 * If BIOS did not supply an INT_SRC_OVR for the SCI
1202 * pretend we got one so we can set the SCI flags.
1204 if (!acpi_sci_override_gsi)
1205 acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0,
1206 acpi_gbl_FADT.sci_interrupt);
1208 /* Fill in identity legacy mappings where no override */
1209 mp_config_acpi_legacy_irqs();
1211 count =
1212 acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src,
1213 nr_irqs);
1214 if (count < 0) {
1215 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
1216 /* TBD: Cleanup to allow fallback to MPS */
1217 return count;
1220 return 0;
1222 #else
1223 static inline int acpi_parse_madt_ioapic_entries(void)
1225 return -1;
1227 #endif /* !CONFIG_X86_IO_APIC */
1229 static void __init early_acpi_process_madt(void)
1231 #ifdef CONFIG_X86_LOCAL_APIC
1232 int error;
1234 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1237 * Parse MADT LAPIC entries
1239 error = early_acpi_parse_madt_lapic_addr_ovr();
1240 if (!error) {
1241 acpi_lapic = 1;
1242 smp_found_config = 1;
1244 if (error == -EINVAL) {
1246 * Dell Precision Workstation 410, 610 come here.
1248 printk(KERN_ERR PREFIX
1249 "Invalid BIOS MADT, disabling ACPI\n");
1250 disable_acpi();
1253 #endif
1256 static void __init acpi_process_madt(void)
1258 #ifdef CONFIG_X86_LOCAL_APIC
1259 int error;
1261 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1264 * Parse MADT LAPIC entries
1266 error = acpi_parse_madt_lapic_entries();
1267 if (!error) {
1268 acpi_lapic = 1;
1271 * Parse MADT IO-APIC entries
1273 error = acpi_parse_madt_ioapic_entries();
1274 if (!error) {
1275 acpi_set_irq_model_ioapic();
1277 smp_found_config = 1;
1280 if (error == -EINVAL) {
1282 * Dell Precision Workstation 410, 610 come here.
1284 printk(KERN_ERR PREFIX
1285 "Invalid BIOS MADT, disabling ACPI\n");
1286 disable_acpi();
1288 } else {
1290 * ACPI found no MADT, and so ACPI wants UP PIC mode.
1291 * In the event an MPS table was found, forget it.
1292 * Boot with "acpi=off" to use MPS on such a system.
1294 if (smp_found_config) {
1295 printk(KERN_WARNING PREFIX
1296 "No APIC-table, disabling MPS\n");
1297 smp_found_config = 0;
1302 * ACPI supports both logical (e.g. Hyper-Threading) and physical
1303 * processors, where MPS only supports physical.
1305 if (acpi_lapic && acpi_ioapic)
1306 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
1307 "information\n");
1308 else if (acpi_lapic)
1309 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
1310 "configuration information\n");
1311 #endif
1312 return;
1315 static int __init disable_acpi_irq(const struct dmi_system_id *d)
1317 if (!acpi_force) {
1318 printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
1319 d->ident);
1320 acpi_noirq_set();
1322 return 0;
1325 static int __init disable_acpi_pci(const struct dmi_system_id *d)
1327 if (!acpi_force) {
1328 printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
1329 d->ident);
1330 acpi_disable_pci();
1332 return 0;
1335 static int __init dmi_disable_acpi(const struct dmi_system_id *d)
1337 if (!acpi_force) {
1338 printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
1339 disable_acpi();
1340 } else {
1341 printk(KERN_NOTICE
1342 "Warning: DMI blacklist says broken, but acpi forced\n");
1344 return 0;
1348 * Force ignoring BIOS IRQ0 override
1350 static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
1352 if (!acpi_skip_timer_override) {
1353 pr_notice("%s detected: Ignoring BIOS IRQ0 override\n",
1354 d->ident);
1355 acpi_skip_timer_override = 1;
1357 return 0;
1361 * If your system is blacklisted here, but you find that acpi=force
1362 * works for you, please contact linux-acpi@vger.kernel.org
1364 static struct dmi_system_id __initdata acpi_dmi_table[] = {
1366 * Boxes that need ACPI disabled
1369 .callback = dmi_disable_acpi,
1370 .ident = "IBM Thinkpad",
1371 .matches = {
1372 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1373 DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
1378 * Boxes that need ACPI PCI IRQ routing disabled
1381 .callback = disable_acpi_irq,
1382 .ident = "ASUS A7V",
1383 .matches = {
1384 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
1385 DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
1386 /* newer BIOS, Revision 1011, does work */
1387 DMI_MATCH(DMI_BIOS_VERSION,
1388 "ASUS A7V ACPI BIOS Revision 1007"),
1393 * Latest BIOS for IBM 600E (1.16) has bad pcinum
1394 * for LPC bridge, which is needed for the PCI
1395 * interrupt links to work. DSDT fix is in bug 5966.
1396 * 2645, 2646 model numbers are shared with 600/600E/600X
1398 .callback = disable_acpi_irq,
1399 .ident = "IBM Thinkpad 600 Series 2645",
1400 .matches = {
1401 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1402 DMI_MATCH(DMI_BOARD_NAME, "2645"),
1406 .callback = disable_acpi_irq,
1407 .ident = "IBM Thinkpad 600 Series 2646",
1408 .matches = {
1409 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1410 DMI_MATCH(DMI_BOARD_NAME, "2646"),
1414 * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
1416 { /* _BBN 0 bug */
1417 .callback = disable_acpi_pci,
1418 .ident = "ASUS PR-DLS",
1419 .matches = {
1420 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1421 DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
1422 DMI_MATCH(DMI_BIOS_VERSION,
1423 "ASUS PR-DLS ACPI BIOS Revision 1010"),
1424 DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
1428 .callback = disable_acpi_pci,
1429 .ident = "Acer TravelMate 36x Laptop",
1430 .matches = {
1431 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
1432 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
1438 /* second table for DMI checks that should run after early-quirks */
1439 static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
1441 * HP laptops which use a DSDT reporting as HP/SB400/10000,
1442 * which includes some code which overrides all temperature
1443 * trip points to 16C if the INTIN2 input of the I/O APIC
1444 * is enabled. This input is incorrectly designated the
1445 * ISA IRQ 0 via an interrupt source override even though
1446 * it is wired to the output of the master 8259A and INTIN0
1447 * is not connected at all. Force ignoring BIOS IRQ0
1448 * override in that cases.
1451 .callback = dmi_ignore_irq0_timer_override,
1452 .ident = "HP nx6115 laptop",
1453 .matches = {
1454 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1455 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6115"),
1459 .callback = dmi_ignore_irq0_timer_override,
1460 .ident = "HP NX6125 laptop",
1461 .matches = {
1462 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1463 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
1467 .callback = dmi_ignore_irq0_timer_override,
1468 .ident = "HP NX6325 laptop",
1469 .matches = {
1470 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1471 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
1475 .callback = dmi_ignore_irq0_timer_override,
1476 .ident = "HP 6715b laptop",
1477 .matches = {
1478 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1479 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
1483 .callback = dmi_ignore_irq0_timer_override,
1484 .ident = "FUJITSU SIEMENS",
1485 .matches = {
1486 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
1487 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO PRO V2030"),
1494 * acpi_boot_table_init() and acpi_boot_init()
1495 * called from setup_arch(), always.
1496 * 1. checksums all tables
1497 * 2. enumerates lapics
1498 * 3. enumerates io-apics
1500 * acpi_table_init() is separate to allow reading SRAT without
1501 * other side effects.
1503 * side effects of acpi_boot_init:
1504 * acpi_lapic = 1 if LAPIC found
1505 * acpi_ioapic = 1 if IOAPIC found
1506 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
1507 * if acpi_blacklisted() acpi_disabled = 1;
1508 * acpi_irq_model=...
1509 * ...
1512 void __init acpi_boot_table_init(void)
1514 dmi_check_system(acpi_dmi_table);
1517 * If acpi_disabled, bail out
1519 if (acpi_disabled)
1520 return;
1523 * Initialize the ACPI boot-time table parser.
1525 if (acpi_table_init()) {
1526 disable_acpi();
1527 return;
1530 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
1533 * blacklist may disable ACPI entirely
1535 if (acpi_blacklisted()) {
1536 if (acpi_force) {
1537 printk(KERN_WARNING PREFIX "acpi=force override\n");
1538 } else {
1539 printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
1540 disable_acpi();
1541 return;
1546 int __init early_acpi_boot_init(void)
1549 * If acpi_disabled, bail out
1551 if (acpi_disabled)
1552 return 1;
1555 * Process the Multiple APIC Description Table (MADT), if present
1557 early_acpi_process_madt();
1559 return 0;
1562 int __init acpi_boot_init(void)
1564 /* those are executed after early-quirks are executed */
1565 dmi_check_system(acpi_dmi_table_late);
1568 * If acpi_disabled, bail out
1570 if (acpi_disabled)
1571 return 1;
1573 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
1576 * set sci_int and PM timer address
1578 acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
1581 * Process the Multiple APIC Description Table (MADT), if present
1583 acpi_process_madt();
1585 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
1587 if (!acpi_noirq)
1588 x86_init.pci.init = pci_acpi_init;
1590 return 0;
1593 static int __init parse_acpi(char *arg)
1595 if (!arg)
1596 return -EINVAL;
1598 /* "acpi=off" disables both ACPI table parsing and interpreter */
1599 if (strcmp(arg, "off") == 0) {
1600 disable_acpi();
1602 /* acpi=force to over-ride black-list */
1603 else if (strcmp(arg, "force") == 0) {
1604 acpi_force = 1;
1605 acpi_disabled = 0;
1607 /* acpi=strict disables out-of-spec workarounds */
1608 else if (strcmp(arg, "strict") == 0) {
1609 acpi_strict = 1;
1611 /* acpi=rsdt use RSDT instead of XSDT */
1612 else if (strcmp(arg, "rsdt") == 0) {
1613 acpi_rsdt_forced = 1;
1615 /* "acpi=noirq" disables ACPI interrupt routing */
1616 else if (strcmp(arg, "noirq") == 0) {
1617 acpi_noirq_set();
1619 /* "acpi=copy_dsdt" copys DSDT */
1620 else if (strcmp(arg, "copy_dsdt") == 0) {
1621 acpi_gbl_copy_dsdt_locally = 1;
1622 } else {
1623 /* Core will printk when we return error. */
1624 return -EINVAL;
1626 return 0;
1628 early_param("acpi", parse_acpi);
1630 /* FIXME: Using pci= for an ACPI parameter is a travesty. */
1631 static int __init parse_pci(char *arg)
1633 if (arg && strcmp(arg, "noacpi") == 0)
1634 acpi_disable_pci();
1635 return 0;
1637 early_param("pci", parse_pci);
1639 int __init acpi_mps_check(void)
1641 #if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
1642 /* mptable code is not built-in*/
1643 if (acpi_disabled || acpi_noirq) {
1644 printk(KERN_WARNING "MPS support code is not built-in.\n"
1645 "Using acpi=off or acpi=noirq or pci=noacpi "
1646 "may have problem\n");
1647 return 1;
1649 #endif
1650 return 0;
1653 #ifdef CONFIG_X86_IO_APIC
1654 static int __init parse_acpi_skip_timer_override(char *arg)
1656 acpi_skip_timer_override = 1;
1657 return 0;
1659 early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
1661 static int __init parse_acpi_use_timer_override(char *arg)
1663 acpi_use_timer_override = 1;
1664 return 0;
1666 early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
1667 #endif /* CONFIG_X86_IO_APIC */
1669 static int __init setup_acpi_sci(char *s)
1671 if (!s)
1672 return -EINVAL;
1673 if (!strcmp(s, "edge"))
1674 acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
1675 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
1676 else if (!strcmp(s, "level"))
1677 acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
1678 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
1679 else if (!strcmp(s, "high"))
1680 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
1681 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
1682 else if (!strcmp(s, "low"))
1683 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
1684 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
1685 else
1686 return -EINVAL;
1687 return 0;
1689 early_param("acpi_sci", setup_acpi_sci);
1691 int __acpi_acquire_global_lock(unsigned int *lock)
1693 unsigned int old, new, val;
1694 do {
1695 old = *lock;
1696 new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
1697 val = cmpxchg(lock, old, new);
1698 } while (unlikely (val != old));
1699 return (new < 3) ? -1 : 0;
1702 int __acpi_release_global_lock(unsigned int *lock)
1704 unsigned int old, new, val;
1705 do {
1706 old = *lock;
1707 new = old & ~0x3;
1708 val = cmpxchg(lock, old, new);
1709 } while (unlikely (val != old));
1710 return old & 0x1;
1713 void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
1715 e820_add_region(addr, size, E820_ACPI);
1716 update_e820();