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 <asm/pgalloc.h>
32 #include <asm/io_apic.h>
36 #include <asm/mpspec.h>
40 static inline void acpi_madt_oem_check(char *oem_id, char *oem_table_id) { }
41 static inline void clustered_apic_check(void) { }
42 static inline int ioapic_setup_disabled(void) { return 0; }
43 #include <asm/proto.h>
47 #ifdef CONFIG_X86_LOCAL_APIC
48 #include <mach_apic.h>
49 #include <mach_mpparse.h>
50 #endif /* CONFIG_X86_LOCAL_APIC */
54 #define BAD_MADT_ENTRY(entry, end) ( \
55 (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
56 ((acpi_table_entry_header *)entry)->length != sizeof(*entry))
58 #define PREFIX "ACPI: "
60 #ifdef CONFIG_ACPI_PCI
61 int acpi_noirq __initdata; /* skip ACPI IRQ initialization */
62 int acpi_pci_disabled __initdata; /* skip ACPI PCI scan and IRQ initialization */
64 int acpi_noirq __initdata = 1;
65 int acpi_pci_disabled __initdata = 1;
67 int acpi_ht __initdata = 1; /* enable HT */
73 acpi_interrupt_flags acpi_sci_flags __initdata;
74 int acpi_sci_override_gsi __initdata;
75 int acpi_skip_timer_override __initdata;
77 #ifdef CONFIG_X86_LOCAL_APIC
78 static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
81 #ifndef __HAVE_ARCH_CMPXCHG
82 #warning ACPI uses CMPXCHG, i486 and later hardware
85 /* --------------------------------------------------------------------------
86 Boot-time Configuration
87 -------------------------------------------------------------------------- */
90 * The default interrupt routing model is PIC (8259). This gets
91 * overriden if IOAPICs are enumerated (below).
93 enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
97 /* rely on all ACPI tables being in the direct mapping */
98 char *__acpi_map_table(unsigned long phys_addr, unsigned long size)
100 if (!phys_addr || !size)
103 if (phys_addr < (end_pfn_map << PAGE_SHIFT))
104 return __va(phys_addr);
112 * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
113 * to map the target physical address. The problem is that set_fixmap()
114 * provides a single page, and it is possible that the page is not
116 * By using this area, we can map up to MAX_IO_APICS pages temporarily,
117 * i.e. until the next __va_range() call.
119 * Important Safety Note: The fixed I/O APIC page numbers are *subtracted*
120 * from the fixed base. That's why we start at FIX_IO_APIC_BASE_END and
121 * count idx down while incrementing the phys address.
123 char *__acpi_map_table(unsigned long phys, unsigned long size)
125 unsigned long base, offset, mapped_size;
128 if (phys + size < 8*1024*1024)
131 offset = phys & (PAGE_SIZE - 1);
132 mapped_size = PAGE_SIZE - offset;
133 set_fixmap(FIX_ACPI_END, phys);
134 base = fix_to_virt(FIX_ACPI_END);
137 * Most cases can be covered by the below.
140 while (mapped_size < size) {
141 if (--idx < FIX_ACPI_BEGIN)
142 return 0; /* cannot handle this */
144 set_fixmap(idx, phys);
145 mapped_size += PAGE_SIZE;
148 return ((unsigned char *) base + offset);
152 #ifdef CONFIG_PCI_MMCONFIG
153 static int __init acpi_parse_mcfg(unsigned long phys_addr, unsigned long size)
155 struct acpi_table_mcfg *mcfg;
157 if (!phys_addr || !size)
160 mcfg = (struct acpi_table_mcfg *) __acpi_map_table(phys_addr, size);
162 printk(KERN_WARNING PREFIX "Unable to map MCFG\n");
166 if (mcfg->base_reserved) {
167 printk(KERN_ERR PREFIX "MMCONFIG not in low 4GB of memory\n");
171 pci_mmcfg_base_addr = mcfg->base_address;
176 #define acpi_parse_mcfg NULL
177 #endif /* !CONFIG_PCI_MMCONFIG */
179 #ifdef CONFIG_X86_LOCAL_APIC
182 unsigned long phys_addr,
185 struct acpi_table_madt *madt = NULL;
187 if (!phys_addr || !size)
190 madt = (struct acpi_table_madt *) __acpi_map_table(phys_addr, size);
192 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
196 if (madt->lapic_address) {
197 acpi_lapic_addr = (u64) madt->lapic_address;
199 printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
200 madt->lapic_address);
203 acpi_madt_oem_check(madt->header.oem_id, madt->header.oem_table_id);
211 acpi_table_entry_header *header, const unsigned long end)
213 struct acpi_table_lapic *processor = NULL;
215 processor = (struct acpi_table_lapic*) header;
217 if (BAD_MADT_ENTRY(processor, end))
220 acpi_table_print_madt_entry(header);
222 /* no utility in registering a disabled processor */
223 if (processor->flags.enabled == 0)
227 processor->id, /* APIC ID */
228 processor->flags.enabled); /* Enabled? */
234 acpi_parse_lapic_addr_ovr (
235 acpi_table_entry_header *header, const unsigned long end)
237 struct acpi_table_lapic_addr_ovr *lapic_addr_ovr = NULL;
239 lapic_addr_ovr = (struct acpi_table_lapic_addr_ovr*) header;
241 if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
244 acpi_lapic_addr = lapic_addr_ovr->address;
250 acpi_parse_lapic_nmi (
251 acpi_table_entry_header *header, const unsigned long end)
253 struct acpi_table_lapic_nmi *lapic_nmi = NULL;
255 lapic_nmi = (struct acpi_table_lapic_nmi*) header;
257 if (BAD_MADT_ENTRY(lapic_nmi, end))
260 acpi_table_print_madt_entry(header);
262 if (lapic_nmi->lint != 1)
263 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
269 #endif /*CONFIG_X86_LOCAL_APIC*/
271 #if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_ACPI_INTERPRETER)
275 acpi_table_entry_header *header, const unsigned long end)
277 struct acpi_table_ioapic *ioapic = NULL;
279 ioapic = (struct acpi_table_ioapic*) header;
281 if (BAD_MADT_ENTRY(ioapic, end))
284 acpi_table_print_madt_entry(header);
289 ioapic->global_irq_base);
295 * Parse Interrupt Source Override for the ACPI SCI
298 acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
300 if (trigger == 0) /* compatible SCI trigger is level */
303 if (polarity == 0) /* compatible SCI polarity is low */
306 /* Command-line over-ride via acpi_sci= */
307 if (acpi_sci_flags.trigger)
308 trigger = acpi_sci_flags.trigger;
310 if (acpi_sci_flags.polarity)
311 polarity = acpi_sci_flags.polarity;
314 * mp_config_acpi_legacy_irqs() already setup IRQs < 16
315 * If GSI is < 16, this will update its flags,
316 * else it will create a new mp_irqs[] entry.
318 mp_override_legacy_irq(gsi, polarity, trigger, gsi);
321 * stash over-ride to indicate we've been here
322 * and for later update of acpi_fadt
324 acpi_sci_override_gsi = gsi;
329 acpi_parse_int_src_ovr (
330 acpi_table_entry_header *header, const unsigned long end)
332 struct acpi_table_int_src_ovr *intsrc = NULL;
334 intsrc = (struct acpi_table_int_src_ovr*) header;
336 if (BAD_MADT_ENTRY(intsrc, end))
339 acpi_table_print_madt_entry(header);
341 if (intsrc->bus_irq == acpi_fadt.sci_int) {
342 acpi_sci_ioapic_setup(intsrc->global_irq,
343 intsrc->flags.polarity, intsrc->flags.trigger);
347 if (acpi_skip_timer_override &&
348 intsrc->bus_irq == 0 && intsrc->global_irq == 2) {
349 printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
353 mp_override_legacy_irq (
355 intsrc->flags.polarity,
356 intsrc->flags.trigger,
365 acpi_table_entry_header *header, const unsigned long end)
367 struct acpi_table_nmi_src *nmi_src = NULL;
369 nmi_src = (struct acpi_table_nmi_src*) header;
371 if (BAD_MADT_ENTRY(nmi_src, end))
374 acpi_table_print_madt_entry(header);
376 /* TBD: Support nimsrc entries? */
381 #endif /* CONFIG_X86_IO_APIC */
383 #ifdef CONFIG_ACPI_BUS
386 * acpi_pic_sci_set_trigger()
388 * use ELCR to set PIC-mode trigger type for SCI
390 * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
391 * it may require Edge Trigger -- use "acpi_sci=edge"
393 * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
394 * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
395 * ECLR1 is IRQ's 0-7 (IRQ 0, 1, 2 must be 0)
396 * ECLR2 is IRQ's 8-15 (IRQ 8, 13 must be 0)
400 acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
402 unsigned char mask = 1 << (irq & 7);
403 unsigned int port = 0x4d0 + (irq >> 3);
404 unsigned char val = inb(port);
407 printk(PREFIX "IRQ%d SCI:", irq);
412 printk(" set to Level");
413 outb(val | mask, port);
419 printk(" set to Edge");
420 outb(val & ~mask, port);
423 printk(" Trigger.\n");
427 #endif /* CONFIG_ACPI_BUS */
429 int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
431 #ifdef CONFIG_X86_IO_APIC
432 if (use_pci_vector() && !platform_legacy_irq(gsi))
433 *irq = IO_APIC_VECTOR(gsi);
440 static unsigned long __init
443 unsigned long length)
445 unsigned long offset = 0;
446 unsigned long sig_len = sizeof("RSD PTR ") - 1;
449 * Scan all 16-byte boundaries of the physical memory region for the
452 for (offset = 0; offset < length; offset += 16) {
453 if (strncmp((char *) (start + offset), "RSD PTR ", sig_len))
455 return (start + offset);
461 static int __init acpi_parse_sbf(unsigned long phys_addr, unsigned long size)
463 struct acpi_table_sbf *sb;
465 if (!phys_addr || !size)
468 sb = (struct acpi_table_sbf *) __acpi_map_table(phys_addr, size);
470 printk(KERN_WARNING PREFIX "Unable to map SBF\n");
474 sbf_port = sb->sbf_cmos; /* Save CMOS port */
480 #ifdef CONFIG_HPET_TIMER
482 static int __init acpi_parse_hpet(unsigned long phys, unsigned long size)
484 struct acpi_table_hpet *hpet_tbl;
489 hpet_tbl = (struct acpi_table_hpet *) __acpi_map_table(phys, size);
491 printk(KERN_WARNING PREFIX "Unable to map HPET\n");
495 if (hpet_tbl->addr.space_id != ACPI_SPACE_MEM) {
496 printk(KERN_WARNING PREFIX "HPET timers must be located in "
502 vxtime.hpet_address = hpet_tbl->addr.addrl |
503 ((long) hpet_tbl->addr.addrh << 32);
505 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
506 hpet_tbl->id, vxtime.hpet_address);
509 extern unsigned long hpet_address;
511 hpet_address = hpet_tbl->addr.addrl;
512 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
513 hpet_tbl->id, hpet_address);
520 #define acpi_parse_hpet NULL
523 #ifdef CONFIG_X86_PM_TIMER
524 extern u32 pmtmr_ioport;
527 static int __init acpi_parse_fadt(unsigned long phys, unsigned long size)
529 struct fadt_descriptor_rev2 *fadt =0;
531 fadt = (struct fadt_descriptor_rev2*) __acpi_map_table(phys,size);
533 printk(KERN_WARNING PREFIX "Unable to map FADT\n");
537 #ifdef CONFIG_ACPI_INTERPRETER
538 /* initialize sci_int early for INT_SRC_OVR MADT parsing */
539 acpi_fadt.sci_int = fadt->sci_int;
542 #ifdef CONFIG_X86_PM_TIMER
543 /* detect the location of the ACPI PM Timer */
544 if (fadt->revision >= FADT2_REVISION_ID) {
546 if (fadt->xpm_tmr_blk.address_space_id != ACPI_ADR_SPACE_SYSTEM_IO)
549 pmtmr_ioport = fadt->xpm_tmr_blk.address;
552 pmtmr_ioport = fadt->V1_pm_tmr_blk;
555 printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n", pmtmr_ioport);
562 acpi_find_rsdp (void)
564 unsigned long rsdp_phys = 0;
568 return __pa(efi.acpi20);
570 return __pa(efi.acpi);
573 * Scan memory looking for the RSDP signature. First search EBDA (low
574 * memory) paragraphs and then search upper memory (E0000-FFFFF).
576 rsdp_phys = acpi_scan_rsdp (0, 0x400);
578 rsdp_phys = acpi_scan_rsdp (0xE0000, 0xFFFFF);
583 #ifdef CONFIG_X86_LOCAL_APIC
585 * Parse LAPIC entries in MADT
586 * returns 0 on success, < 0 on error
589 acpi_parse_madt_lapic_entries(void)
594 * Note that the LAPIC address is obtained from the MADT (32-bit value)
595 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
598 count = acpi_table_parse_madt(ACPI_MADT_LAPIC_ADDR_OVR, acpi_parse_lapic_addr_ovr, 0);
600 printk(KERN_ERR PREFIX "Error parsing LAPIC address override entry\n");
604 mp_register_lapic_address(acpi_lapic_addr);
606 count = acpi_table_parse_madt(ACPI_MADT_LAPIC, acpi_parse_lapic,
609 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
610 /* TBD: Cleanup to allow fallback to MPS */
613 else if (count < 0) {
614 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
615 /* TBD: Cleanup to allow fallback to MPS */
619 count = acpi_table_parse_madt(ACPI_MADT_LAPIC_NMI, acpi_parse_lapic_nmi, 0);
621 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
622 /* TBD: Cleanup to allow fallback to MPS */
627 #endif /* CONFIG_X86_LOCAL_APIC */
629 #if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_ACPI_INTERPRETER)
631 * Parse IOAPIC related entries in MADT
632 * returns 0 on success, < 0 on error
635 acpi_parse_madt_ioapic_entries(void)
640 * ACPI interpreter is required to complete interrupt setup,
641 * so if it is off, don't enumerate the io-apics with ACPI.
642 * If MPS is present, it will handle them,
643 * otherwise the system will stay in PIC mode
645 if (acpi_disabled || acpi_noirq) {
650 * if "noapic" boot option, don't look for IO-APICs
652 if (skip_ioapic_setup) {
653 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
654 "due to 'noapic' option.\n");
658 count = acpi_table_parse_madt(ACPI_MADT_IOAPIC, acpi_parse_ioapic, MAX_IO_APICS);
660 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
663 else if (count < 0) {
664 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
668 count = acpi_table_parse_madt(ACPI_MADT_INT_SRC_OVR, acpi_parse_int_src_ovr, NR_IRQ_VECTORS);
670 printk(KERN_ERR PREFIX "Error parsing interrupt source overrides entry\n");
671 /* TBD: Cleanup to allow fallback to MPS */
676 * If BIOS did not supply an INT_SRC_OVR for the SCI
677 * pretend we got one so we can set the SCI flags.
679 if (!acpi_sci_override_gsi)
680 acpi_sci_ioapic_setup(acpi_fadt.sci_int, 0, 0);
682 /* Fill in identity legacy mapings where no override */
683 mp_config_acpi_legacy_irqs();
685 count = acpi_table_parse_madt(ACPI_MADT_NMI_SRC, acpi_parse_nmi_src, NR_IRQ_VECTORS);
687 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
688 /* TBD: Cleanup to allow fallback to MPS */
695 static inline int acpi_parse_madt_ioapic_entries(void)
699 #endif /* !(CONFIG_X86_IO_APIC && CONFIG_ACPI_INTERPRETER) */
703 acpi_process_madt(void)
705 #ifdef CONFIG_X86_LOCAL_APIC
708 count = acpi_table_parse(ACPI_APIC, acpi_parse_madt);
712 * Parse MADT LAPIC entries
714 error = acpi_parse_madt_lapic_entries();
719 * Parse MADT IO-APIC entries
721 error = acpi_parse_madt_ioapic_entries();
723 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
724 acpi_irq_balance_set(NULL);
727 smp_found_config = 1;
728 clustered_apic_check();
731 if (error == -EINVAL) {
733 * Dell Precision Workstation 410, 610 come here.
735 printk(KERN_ERR PREFIX "Invalid BIOS MADT, disabling ACPI\n");
745 * called from setup_arch(), always.
746 * 1. checksums all tables
747 * 2. enumerates lapics
748 * 3. enumerates io-apics
751 * acpi_lapic = 1 if LAPIC found
752 * acpi_ioapic = 1 if IOAPIC found
753 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
754 * if acpi_blacklisted() acpi_disabled = 1;
758 * return value: (currently ignored)
764 acpi_boot_init (void)
769 * If acpi_disabled, bail out
770 * One exception: acpi=ht continues far enough to enumerate LAPICs
772 if (acpi_disabled && !acpi_ht)
776 * Initialize the ACPI boot-time table parser.
778 error = acpi_table_init();
784 acpi_table_parse(ACPI_BOOT, acpi_parse_sbf);
787 * blacklist may disable ACPI entirely
789 error = acpi_blacklisted();
791 printk(KERN_WARNING PREFIX "BIOS listed in blacklist, disabling ACPI support\n");
797 * set sci_int and PM timer address
799 acpi_table_parse(ACPI_FADT, acpi_parse_fadt);
802 * Process the Multiple APIC Description Table (MADT), if present
806 acpi_table_parse(ACPI_HPET, acpi_parse_hpet);
807 acpi_table_parse(ACPI_MCFG, acpi_parse_mcfg);