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/config.h>
28 #include <linux/acpi.h>
29 #include <linux/efi.h>
30 #include <linux/irq.h>
31 #include <linux/module.h>
33 #include <asm/pgtable.h>
34 #include <asm/io_apic.h>
38 #include <asm/mpspec.h>
42 static inline void acpi_madt_oem_check(char *oem_id, char *oem_table_id) { }
43 static inline void clustered_apic_check(void) { }
44 static inline int ioapic_setup_disabled(void) { return 0; }
45 #include <asm/proto.h>
49 #ifdef CONFIG_X86_LOCAL_APIC
50 #include <mach_apic.h>
51 #include <mach_mpparse.h>
52 #endif /* CONFIG_X86_LOCAL_APIC */
56 #define BAD_MADT_ENTRY(entry, end) ( \
57 (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
58 ((acpi_table_entry_header *)entry)->length != sizeof(*entry))
60 #define PREFIX "ACPI: "
62 #ifdef CONFIG_ACPI_PCI
63 int acpi_noirq __initdata; /* skip ACPI IRQ initialization */
64 int acpi_pci_disabled __initdata; /* skip ACPI PCI scan and IRQ initialization */
66 int acpi_noirq __initdata = 1;
67 int acpi_pci_disabled __initdata = 1;
69 int acpi_ht __initdata = 1; /* enable HT */
75 acpi_interrupt_flags acpi_sci_flags __initdata;
76 int acpi_sci_override_gsi __initdata;
77 int acpi_skip_timer_override __initdata;
79 #ifdef CONFIG_X86_LOCAL_APIC
80 static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
83 #ifndef __HAVE_ARCH_CMPXCHG
84 #warning ACPI uses CMPXCHG, i486 and later hardware
87 /* --------------------------------------------------------------------------
88 Boot-time Configuration
89 -------------------------------------------------------------------------- */
92 * The default interrupt routing model is PIC (8259). This gets
93 * overriden if IOAPICs are enumerated (below).
95 enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
99 /* rely on all ACPI tables being in the direct mapping */
100 char *__acpi_map_table(unsigned long phys_addr, unsigned long size)
102 if (!phys_addr || !size)
105 if (phys_addr < (end_pfn_map << PAGE_SHIFT))
106 return __va(phys_addr);
114 * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
115 * to map the target physical address. The problem is that set_fixmap()
116 * provides a single page, and it is possible that the page is not
118 * By using this area, we can map up to MAX_IO_APICS pages temporarily,
119 * i.e. until the next __va_range() call.
121 * Important Safety Note: The fixed I/O APIC page numbers are *subtracted*
122 * from the fixed base. That's why we start at FIX_IO_APIC_BASE_END and
123 * count idx down while incrementing the phys address.
125 char *__acpi_map_table(unsigned long phys, unsigned long size)
127 unsigned long base, offset, mapped_size;
130 if (phys + size < 8*1024*1024)
133 offset = phys & (PAGE_SIZE - 1);
134 mapped_size = PAGE_SIZE - offset;
135 set_fixmap(FIX_ACPI_END, phys);
136 base = fix_to_virt(FIX_ACPI_END);
139 * Most cases can be covered by the below.
142 while (mapped_size < size) {
143 if (--idx < FIX_ACPI_BEGIN)
144 return 0; /* cannot handle this */
146 set_fixmap(idx, phys);
147 mapped_size += PAGE_SIZE;
150 return ((unsigned char *) base + offset);
154 #ifdef CONFIG_PCI_MMCONFIG
155 static int __init acpi_parse_mcfg(unsigned long phys_addr, unsigned long size)
157 struct acpi_table_mcfg *mcfg;
159 if (!phys_addr || !size)
162 mcfg = (struct acpi_table_mcfg *) __acpi_map_table(phys_addr, size);
164 printk(KERN_WARNING PREFIX "Unable to map MCFG\n");
168 if (mcfg->base_reserved) {
169 printk(KERN_ERR PREFIX "MMCONFIG not in low 4GB of memory\n");
173 pci_mmcfg_base_addr = mcfg->base_address;
178 #define acpi_parse_mcfg NULL
179 #endif /* !CONFIG_PCI_MMCONFIG */
181 #ifdef CONFIG_X86_LOCAL_APIC
184 unsigned long phys_addr,
187 struct acpi_table_madt *madt = NULL;
189 if (!phys_addr || !size)
192 madt = (struct acpi_table_madt *) __acpi_map_table(phys_addr, size);
194 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
198 if (madt->lapic_address) {
199 acpi_lapic_addr = (u64) madt->lapic_address;
201 printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
202 madt->lapic_address);
205 acpi_madt_oem_check(madt->header.oem_id, madt->header.oem_table_id);
213 acpi_table_entry_header *header, const unsigned long end)
215 struct acpi_table_lapic *processor = NULL;
217 processor = (struct acpi_table_lapic*) header;
219 if (BAD_MADT_ENTRY(processor, end))
222 acpi_table_print_madt_entry(header);
224 /* no utility in registering a disabled processor */
225 if (processor->flags.enabled == 0)
229 processor->id, /* APIC ID */
230 processor->flags.enabled); /* Enabled? */
236 acpi_parse_lapic_addr_ovr (
237 acpi_table_entry_header *header, const unsigned long end)
239 struct acpi_table_lapic_addr_ovr *lapic_addr_ovr = NULL;
241 lapic_addr_ovr = (struct acpi_table_lapic_addr_ovr*) header;
243 if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
246 acpi_lapic_addr = lapic_addr_ovr->address;
252 acpi_parse_lapic_nmi (
253 acpi_table_entry_header *header, const unsigned long end)
255 struct acpi_table_lapic_nmi *lapic_nmi = NULL;
257 lapic_nmi = (struct acpi_table_lapic_nmi*) header;
259 if (BAD_MADT_ENTRY(lapic_nmi, end))
262 acpi_table_print_madt_entry(header);
264 if (lapic_nmi->lint != 1)
265 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
271 #endif /*CONFIG_X86_LOCAL_APIC*/
273 #if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_ACPI_INTERPRETER)
277 acpi_table_entry_header *header, const unsigned long end)
279 struct acpi_table_ioapic *ioapic = NULL;
281 ioapic = (struct acpi_table_ioapic*) header;
283 if (BAD_MADT_ENTRY(ioapic, end))
286 acpi_table_print_madt_entry(header);
291 ioapic->global_irq_base);
297 * Parse Interrupt Source Override for the ACPI SCI
300 acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
302 if (trigger == 0) /* compatible SCI trigger is level */
305 if (polarity == 0) /* compatible SCI polarity is low */
308 /* Command-line over-ride via acpi_sci= */
309 if (acpi_sci_flags.trigger)
310 trigger = acpi_sci_flags.trigger;
312 if (acpi_sci_flags.polarity)
313 polarity = acpi_sci_flags.polarity;
316 * mp_config_acpi_legacy_irqs() already setup IRQs < 16
317 * If GSI is < 16, this will update its flags,
318 * else it will create a new mp_irqs[] entry.
320 mp_override_legacy_irq(gsi, polarity, trigger, gsi);
323 * stash over-ride to indicate we've been here
324 * and for later update of acpi_fadt
326 acpi_sci_override_gsi = gsi;
331 acpi_parse_int_src_ovr (
332 acpi_table_entry_header *header, const unsigned long end)
334 struct acpi_table_int_src_ovr *intsrc = NULL;
336 intsrc = (struct acpi_table_int_src_ovr*) header;
338 if (BAD_MADT_ENTRY(intsrc, end))
341 acpi_table_print_madt_entry(header);
343 if (intsrc->bus_irq == acpi_fadt.sci_int) {
344 acpi_sci_ioapic_setup(intsrc->global_irq,
345 intsrc->flags.polarity, intsrc->flags.trigger);
349 if (acpi_skip_timer_override &&
350 intsrc->bus_irq == 0 && intsrc->global_irq == 2) {
351 printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
355 mp_override_legacy_irq (
357 intsrc->flags.polarity,
358 intsrc->flags.trigger,
367 acpi_table_entry_header *header, const unsigned long end)
369 struct acpi_table_nmi_src *nmi_src = NULL;
371 nmi_src = (struct acpi_table_nmi_src*) header;
373 if (BAD_MADT_ENTRY(nmi_src, end))
376 acpi_table_print_madt_entry(header);
378 /* TBD: Support nimsrc entries? */
383 #endif /* CONFIG_X86_IO_APIC */
385 #ifdef CONFIG_ACPI_BUS
388 * acpi_pic_sci_set_trigger()
390 * use ELCR to set PIC-mode trigger type for SCI
392 * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
393 * it may require Edge Trigger -- use "acpi_sci=edge"
395 * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
396 * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
397 * ECLR1 is IRQ's 0-7 (IRQ 0, 1, 2 must be 0)
398 * ECLR2 is IRQ's 8-15 (IRQ 8, 13 must be 0)
402 acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
404 unsigned char mask = 1 << (irq & 7);
405 unsigned int port = 0x4d0 + (irq >> 3);
406 unsigned char val = inb(port);
409 printk(PREFIX "IRQ%d SCI:", irq);
414 printk(" set to Level");
415 outb(val | mask, port);
421 printk(" set to Edge");
422 outb(val & ~mask, port);
425 printk(" Trigger.\n");
429 #endif /* CONFIG_ACPI_BUS */
431 int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
433 #ifdef CONFIG_X86_IO_APIC
434 if (use_pci_vector() && !platform_legacy_irq(gsi))
435 *irq = IO_APIC_VECTOR(gsi);
442 unsigned int acpi_register_gsi(u32 gsi, int edge_level, int active_high_low)
448 * Make sure all (legacy) PCI IRQs are set as level-triggered.
450 if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
452 extern void eisa_set_level_irq(unsigned int irq);
454 if (edge_level == ACPI_LEVEL_SENSITIVE) {
455 if ((gsi < 16) && !((1 << gsi) & irq_mask)) {
456 Dprintk(KERN_DEBUG PREFIX "Setting GSI %u as level-triggered\n", gsi);
457 irq_mask |= (1 << gsi);
458 eisa_set_level_irq(gsi);
464 #ifdef CONFIG_X86_IO_APIC
465 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) {
466 mp_register_gsi(gsi, edge_level, active_high_low);
469 acpi_gsi_to_irq(gsi, &irq);
472 EXPORT_SYMBOL(acpi_register_gsi);
474 static unsigned long __init
477 unsigned long length)
479 unsigned long offset = 0;
480 unsigned long sig_len = sizeof("RSD PTR ") - 1;
483 * Scan all 16-byte boundaries of the physical memory region for the
486 for (offset = 0; offset < length; offset += 16) {
487 if (strncmp((char *) __va(start + offset), "RSD PTR ", sig_len))
489 return (start + offset);
495 static int __init acpi_parse_sbf(unsigned long phys_addr, unsigned long size)
497 struct acpi_table_sbf *sb;
499 if (!phys_addr || !size)
502 sb = (struct acpi_table_sbf *) __acpi_map_table(phys_addr, size);
504 printk(KERN_WARNING PREFIX "Unable to map SBF\n");
508 sbf_port = sb->sbf_cmos; /* Save CMOS port */
514 #ifdef CONFIG_HPET_TIMER
516 static int __init acpi_parse_hpet(unsigned long phys, unsigned long size)
518 struct acpi_table_hpet *hpet_tbl;
523 hpet_tbl = (struct acpi_table_hpet *) __acpi_map_table(phys, size);
525 printk(KERN_WARNING PREFIX "Unable to map HPET\n");
529 if (hpet_tbl->addr.space_id != ACPI_SPACE_MEM) {
530 printk(KERN_WARNING PREFIX "HPET timers must be located in "
536 vxtime.hpet_address = hpet_tbl->addr.addrl |
537 ((long) hpet_tbl->addr.addrh << 32);
539 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
540 hpet_tbl->id, vxtime.hpet_address);
543 extern unsigned long hpet_address;
545 hpet_address = hpet_tbl->addr.addrl;
546 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
547 hpet_tbl->id, hpet_address);
554 #define acpi_parse_hpet NULL
557 #ifdef CONFIG_X86_PM_TIMER
558 extern u32 pmtmr_ioport;
561 static int __init acpi_parse_fadt(unsigned long phys, unsigned long size)
563 struct fadt_descriptor_rev2 *fadt =0;
565 fadt = (struct fadt_descriptor_rev2*) __acpi_map_table(phys,size);
567 printk(KERN_WARNING PREFIX "Unable to map FADT\n");
571 #ifdef CONFIG_ACPI_INTERPRETER
572 /* initialize sci_int early for INT_SRC_OVR MADT parsing */
573 acpi_fadt.sci_int = fadt->sci_int;
576 #ifdef CONFIG_X86_PM_TIMER
577 /* detect the location of the ACPI PM Timer */
578 if (fadt->revision >= FADT2_REVISION_ID) {
580 if (fadt->xpm_tmr_blk.address_space_id != ACPI_ADR_SPACE_SYSTEM_IO)
583 pmtmr_ioport = fadt->xpm_tmr_blk.address;
586 pmtmr_ioport = fadt->V1_pm_tmr_blk;
589 printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n", pmtmr_ioport);
596 acpi_find_rsdp (void)
598 unsigned long rsdp_phys = 0;
602 return __pa(efi.acpi20);
604 return __pa(efi.acpi);
607 * Scan memory looking for the RSDP signature. First search EBDA (low
608 * memory) paragraphs and then search upper memory (E0000-FFFFF).
610 rsdp_phys = acpi_scan_rsdp (0, 0x400);
612 rsdp_phys = acpi_scan_rsdp (0xE0000, 0xFFFFF);
617 #ifdef CONFIG_X86_LOCAL_APIC
619 * Parse LAPIC entries in MADT
620 * returns 0 on success, < 0 on error
623 acpi_parse_madt_lapic_entries(void)
628 * Note that the LAPIC address is obtained from the MADT (32-bit value)
629 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
632 count = acpi_table_parse_madt(ACPI_MADT_LAPIC_ADDR_OVR, acpi_parse_lapic_addr_ovr, 0);
634 printk(KERN_ERR PREFIX "Error parsing LAPIC address override entry\n");
638 mp_register_lapic_address(acpi_lapic_addr);
640 count = acpi_table_parse_madt(ACPI_MADT_LAPIC, acpi_parse_lapic,
643 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
644 /* TBD: Cleanup to allow fallback to MPS */
647 else if (count < 0) {
648 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
649 /* TBD: Cleanup to allow fallback to MPS */
653 count = acpi_table_parse_madt(ACPI_MADT_LAPIC_NMI, acpi_parse_lapic_nmi, 0);
655 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
656 /* TBD: Cleanup to allow fallback to MPS */
661 #endif /* CONFIG_X86_LOCAL_APIC */
663 #if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_ACPI_INTERPRETER)
665 * Parse IOAPIC related entries in MADT
666 * returns 0 on success, < 0 on error
669 acpi_parse_madt_ioapic_entries(void)
674 * ACPI interpreter is required to complete interrupt setup,
675 * so if it is off, don't enumerate the io-apics with ACPI.
676 * If MPS is present, it will handle them,
677 * otherwise the system will stay in PIC mode
679 if (acpi_disabled || acpi_noirq) {
684 * if "noapic" boot option, don't look for IO-APICs
686 if (skip_ioapic_setup) {
687 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
688 "due to 'noapic' option.\n");
692 count = acpi_table_parse_madt(ACPI_MADT_IOAPIC, acpi_parse_ioapic, MAX_IO_APICS);
694 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
697 else if (count < 0) {
698 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
702 count = acpi_table_parse_madt(ACPI_MADT_INT_SRC_OVR, acpi_parse_int_src_ovr, NR_IRQ_VECTORS);
704 printk(KERN_ERR PREFIX "Error parsing interrupt source overrides entry\n");
705 /* TBD: Cleanup to allow fallback to MPS */
710 * If BIOS did not supply an INT_SRC_OVR for the SCI
711 * pretend we got one so we can set the SCI flags.
713 if (!acpi_sci_override_gsi)
714 acpi_sci_ioapic_setup(acpi_fadt.sci_int, 0, 0);
716 /* Fill in identity legacy mapings where no override */
717 mp_config_acpi_legacy_irqs();
719 count = acpi_table_parse_madt(ACPI_MADT_NMI_SRC, acpi_parse_nmi_src, NR_IRQ_VECTORS);
721 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
722 /* TBD: Cleanup to allow fallback to MPS */
729 static inline int acpi_parse_madt_ioapic_entries(void)
733 #endif /* !(CONFIG_X86_IO_APIC && CONFIG_ACPI_INTERPRETER) */
737 acpi_process_madt(void)
739 #ifdef CONFIG_X86_LOCAL_APIC
742 count = acpi_table_parse(ACPI_APIC, acpi_parse_madt);
746 * Parse MADT LAPIC entries
748 error = acpi_parse_madt_lapic_entries();
753 * Parse MADT IO-APIC entries
755 error = acpi_parse_madt_ioapic_entries();
757 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
758 acpi_irq_balance_set(NULL);
761 smp_found_config = 1;
762 clustered_apic_check();
765 if (error == -EINVAL) {
767 * Dell Precision Workstation 410, 610 come here.
769 printk(KERN_ERR PREFIX "Invalid BIOS MADT, disabling ACPI\n");
779 * called from setup_arch(), always.
780 * 1. checksums all tables
781 * 2. enumerates lapics
782 * 3. enumerates io-apics
785 * acpi_lapic = 1 if LAPIC found
786 * acpi_ioapic = 1 if IOAPIC found
787 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
788 * if acpi_blacklisted() acpi_disabled = 1;
792 * return value: (currently ignored)
798 acpi_boot_init (void)
803 * If acpi_disabled, bail out
804 * One exception: acpi=ht continues far enough to enumerate LAPICs
806 if (acpi_disabled && !acpi_ht)
810 * Initialize the ACPI boot-time table parser.
812 error = acpi_table_init();
818 acpi_table_parse(ACPI_BOOT, acpi_parse_sbf);
821 * blacklist may disable ACPI entirely
823 error = acpi_blacklisted();
825 printk(KERN_WARNING PREFIX "BIOS listed in blacklist, disabling ACPI support\n");
831 * set sci_int and PM timer address
833 acpi_table_parse(ACPI_FADT, acpi_parse_fadt);
836 * Process the Multiple APIC Description Table (MADT), if present
840 acpi_table_parse(ACPI_HPET, acpi_parse_hpet);
841 acpi_table_parse(ACPI_MCFG, acpi_parse_mcfg);