ia64/xen-unstable

view xen/arch/x86/acpi/boot.c @ 6552:a9873d384da4

Merge.
author adsharma@los-vmm.sc.intel.com
date Thu Aug 25 12:24:48 2005 -0700 (2005-08-25)
parents 112d44270733 fa0754a9f64f
children dfaf788ab18c
line source
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 */
26 #include <xen/config.h>
27 #include <xen/errno.h>
28 #include <xen/init.h>
29 #include <xen/acpi.h>
30 #include <xen/irq.h>
31 #include <asm/fixmap.h>
32 #include <asm/page.h>
33 #include <asm/apic.h>
34 #include <asm/io_apic.h>
35 #include <asm/apic.h>
36 #include <asm/io.h>
37 #include <asm/mpspec.h>
38 #include <mach_apic.h>
39 #include <mach_mpparse.h>
41 int sbf_port;
42 #define CONFIG_ACPI_PCI
44 #define BAD_MADT_ENTRY(entry, end) ( \
45 (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
46 ((acpi_table_entry_header *)entry)->length != sizeof(*entry))
48 #define PREFIX "ACPI: "
50 #ifdef CONFIG_ACPI_PCI
51 int acpi_noirq __initdata; /* skip ACPI IRQ initialization */
52 int acpi_pci_disabled __initdata; /* skip ACPI PCI scan and IRQ initialization */
53 #else
54 int acpi_noirq __initdata = 1;
55 int acpi_pci_disabled __initdata = 1;
56 #endif
57 int acpi_ht __initdata = 1; /* enable HT */
59 int acpi_lapic;
60 int acpi_ioapic;
61 int acpi_strict;
62 EXPORT_SYMBOL(acpi_strict);
64 acpi_interrupt_flags acpi_sci_flags __initdata;
65 int acpi_sci_override_gsi __initdata;
66 int acpi_skip_timer_override __initdata;
68 #ifdef CONFIG_X86_LOCAL_APIC
69 static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
70 #endif
72 #ifndef __HAVE_ARCH_CMPXCHG
73 #warning ACPI uses CMPXCHG, i486 and later hardware
74 #endif
76 #define MAX_MADT_ENTRIES 256
77 u8 x86_acpiid_to_apicid[MAX_MADT_ENTRIES] =
78 { [0 ... MAX_MADT_ENTRIES-1] = 0xff };
79 EXPORT_SYMBOL(x86_acpiid_to_apicid);
81 /* --------------------------------------------------------------------------
82 Boot-time Configuration
83 -------------------------------------------------------------------------- */
85 /*
86 * The default interrupt routing model is PIC (8259). This gets
87 * overriden if IOAPICs are enumerated (below).
88 */
89 enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
91 /*
92 * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
93 * to map the target physical address. The problem is that set_fixmap()
94 * provides a single page, and it is possible that the page is not
95 * sufficient.
96 * By using this area, we can map up to MAX_IO_APICS pages temporarily,
97 * i.e. until the next __va_range() call.
98 *
99 * Important Safety Note: The fixed I/O APIC page numbers are *subtracted*
100 * from the fixed base. That's why we start at FIX_IO_APIC_BASE_END and
101 * count idx down while incrementing the phys address.
102 */
103 char *__acpi_map_table(unsigned long phys, unsigned long size)
104 {
105 unsigned long base, offset, mapped_size;
106 int idx;
108 if (phys + size < 8*1024*1024)
109 return __va(phys);
111 offset = phys & (PAGE_SIZE - 1);
112 mapped_size = PAGE_SIZE - offset;
113 set_fixmap(FIX_ACPI_END, phys);
114 base = fix_to_virt(FIX_ACPI_END);
116 /*
117 * Most cases can be covered by the below.
118 */
119 idx = FIX_ACPI_END;
120 while (mapped_size < size) {
121 if (--idx < FIX_ACPI_BEGIN)
122 return NULL; /* cannot handle this */
123 phys += PAGE_SIZE;
124 set_fixmap(idx, phys);
125 mapped_size += PAGE_SIZE;
126 }
128 return ((char *) base + offset);
129 }
131 #ifdef CONFIG_PCI_MMCONFIG
132 static int __init acpi_parse_mcfg(unsigned long phys_addr, unsigned long size)
133 {
134 struct acpi_table_mcfg *mcfg;
136 if (!phys_addr || !size)
137 return -EINVAL;
139 mcfg = (struct acpi_table_mcfg *) __acpi_map_table(phys_addr, size);
140 if (!mcfg) {
141 printk(KERN_WARNING PREFIX "Unable to map MCFG\n");
142 return -ENODEV;
143 }
145 if (mcfg->base_reserved) {
146 printk(KERN_ERR PREFIX "MMCONFIG not in low 4GB of memory\n");
147 return -ENODEV;
148 }
150 pci_mmcfg_base_addr = mcfg->base_address;
152 return 0;
153 }
154 #else
155 #define acpi_parse_mcfg NULL
156 #endif /* !CONFIG_PCI_MMCONFIG */
158 #ifdef CONFIG_X86_LOCAL_APIC
159 static int __init
160 acpi_parse_madt (
161 unsigned long phys_addr,
162 unsigned long size)
163 {
164 struct acpi_table_madt *madt = NULL;
166 if (!phys_addr || !size)
167 return -EINVAL;
169 madt = (struct acpi_table_madt *) __acpi_map_table(phys_addr, size);
170 if (!madt) {
171 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
172 return -ENODEV;
173 }
175 if (madt->lapic_address) {
176 acpi_lapic_addr = (u64) madt->lapic_address;
178 printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
179 madt->lapic_address);
180 }
182 acpi_madt_oem_check(madt->header.oem_id, madt->header.oem_table_id);
184 return 0;
185 }
188 static int __init
189 acpi_parse_lapic (
190 acpi_table_entry_header *header, const unsigned long end)
191 {
192 struct acpi_table_lapic *processor = NULL;
194 processor = (struct acpi_table_lapic*) header;
196 if (BAD_MADT_ENTRY(processor, end))
197 return -EINVAL;
199 acpi_table_print_madt_entry(header);
201 /* no utility in registering a disabled processor */
202 if (processor->flags.enabled == 0)
203 return 0;
205 x86_acpiid_to_apicid[processor->acpi_id] = processor->id;
207 mp_register_lapic (
208 processor->id, /* APIC ID */
209 processor->flags.enabled); /* Enabled? */
211 return 0;
212 }
214 static int __init
215 acpi_parse_lapic_addr_ovr (
216 acpi_table_entry_header *header, const unsigned long end)
217 {
218 struct acpi_table_lapic_addr_ovr *lapic_addr_ovr = NULL;
220 lapic_addr_ovr = (struct acpi_table_lapic_addr_ovr*) header;
222 if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
223 return -EINVAL;
225 acpi_lapic_addr = lapic_addr_ovr->address;
227 return 0;
228 }
230 static int __init
231 acpi_parse_lapic_nmi (
232 acpi_table_entry_header *header, const unsigned long end)
233 {
234 struct acpi_table_lapic_nmi *lapic_nmi = NULL;
236 lapic_nmi = (struct acpi_table_lapic_nmi*) header;
238 if (BAD_MADT_ENTRY(lapic_nmi, end))
239 return -EINVAL;
241 acpi_table_print_madt_entry(header);
243 if (lapic_nmi->lint != 1)
244 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
246 return 0;
247 }
250 #endif /*CONFIG_X86_LOCAL_APIC*/
252 #if defined(CONFIG_X86_IO_APIC) /*&& defined(CONFIG_ACPI_INTERPRETER)*/
254 static int __init
255 acpi_parse_ioapic (
256 acpi_table_entry_header *header, const unsigned long end)
257 {
258 struct acpi_table_ioapic *ioapic = NULL;
260 ioapic = (struct acpi_table_ioapic*) header;
262 if (BAD_MADT_ENTRY(ioapic, end))
263 return -EINVAL;
265 acpi_table_print_madt_entry(header);
267 mp_register_ioapic (
268 ioapic->id,
269 ioapic->address,
270 ioapic->global_irq_base);
272 return 0;
273 }
275 static int __init
276 acpi_parse_int_src_ovr (
277 acpi_table_entry_header *header, const unsigned long end)
278 {
279 struct acpi_table_int_src_ovr *intsrc = NULL;
281 intsrc = (struct acpi_table_int_src_ovr*) header;
283 if (BAD_MADT_ENTRY(intsrc, end))
284 return -EINVAL;
286 acpi_table_print_madt_entry(header);
288 if (acpi_skip_timer_override &&
289 intsrc->bus_irq == 0 && intsrc->global_irq == 2) {
290 printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
291 return 0;
292 }
294 mp_override_legacy_irq (
295 intsrc->bus_irq,
296 intsrc->flags.polarity,
297 intsrc->flags.trigger,
298 intsrc->global_irq);
300 return 0;
301 }
304 static int __init
305 acpi_parse_nmi_src (
306 acpi_table_entry_header *header, const unsigned long end)
307 {
308 struct acpi_table_nmi_src *nmi_src = NULL;
310 nmi_src = (struct acpi_table_nmi_src*) header;
312 if (BAD_MADT_ENTRY(nmi_src, end))
313 return -EINVAL;
315 acpi_table_print_madt_entry(header);
317 /* TBD: Support nimsrc entries? */
319 return 0;
320 }
322 #endif /* CONFIG_X86_IO_APIC */
324 static unsigned long __init
325 acpi_scan_rsdp (
326 unsigned long start,
327 unsigned long length)
328 {
329 unsigned long offset = 0;
330 unsigned long sig_len = sizeof("RSD PTR ") - 1;
332 /*
333 * Scan all 16-byte boundaries of the physical memory region for the
334 * RSDP signature.
335 */
336 for (offset = 0; offset < length; offset += 16) {
337 if (strncmp((char *) (start + offset), "RSD PTR ", sig_len))
338 continue;
339 return (start + offset);
340 }
342 return 0;
343 }
345 static int __init acpi_parse_sbf(unsigned long phys_addr, unsigned long size)
346 {
347 struct acpi_table_sbf *sb;
349 if (!phys_addr || !size)
350 return -EINVAL;
352 sb = (struct acpi_table_sbf *) __acpi_map_table(phys_addr, size);
353 if (!sb) {
354 printk(KERN_WARNING PREFIX "Unable to map SBF\n");
355 return -ENODEV;
356 }
358 sbf_port = sb->sbf_cmos; /* Save CMOS port */
360 return 0;
361 }
364 #ifdef CONFIG_HPET_TIMER
366 static int __init acpi_parse_hpet(unsigned long phys, unsigned long size)
367 {
368 struct acpi_table_hpet *hpet_tbl;
370 if (!phys || !size)
371 return -EINVAL;
373 hpet_tbl = (struct acpi_table_hpet *) __acpi_map_table(phys, size);
374 if (!hpet_tbl) {
375 printk(KERN_WARNING PREFIX "Unable to map HPET\n");
376 return -ENODEV;
377 }
379 if (hpet_tbl->addr.space_id != ACPI_SPACE_MEM) {
380 printk(KERN_WARNING PREFIX "HPET timers must be located in "
381 "memory.\n");
382 return -1;
383 }
385 #if 0/*def CONFIG_X86_64*/
386 vxtime.hpet_address = hpet_tbl->addr.addrl |
387 ((long) hpet_tbl->addr.addrh << 32);
389 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
390 hpet_tbl->id, vxtime.hpet_address);
391 #else /* X86 */
392 {
393 extern unsigned long hpet_address;
395 hpet_address = hpet_tbl->addr.addrl;
396 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
397 hpet_tbl->id, hpet_address);
398 }
399 #endif /* X86 */
401 return 0;
402 }
403 #else
404 #define acpi_parse_hpet NULL
405 #endif
407 #ifdef CONFIG_X86_PM_TIMER
408 extern u32 pmtmr_ioport;
409 #endif
411 static int __init acpi_parse_fadt(unsigned long phys, unsigned long size)
412 {
413 struct fadt_descriptor_rev2 *fadt = NULL;
415 fadt = (struct fadt_descriptor_rev2*) __acpi_map_table(phys,size);
416 if(!fadt) {
417 printk(KERN_WARNING PREFIX "Unable to map FADT\n");
418 return 0;
419 }
421 #ifdef CONFIG_ACPI_INTERPRETER
422 /* initialize sci_int early for INT_SRC_OVR MADT parsing */
423 acpi_fadt.sci_int = fadt->sci_int;
424 #endif
426 #ifdef CONFIG_X86_PM_TIMER
427 /* detect the location of the ACPI PM Timer */
428 if (fadt->revision >= FADT2_REVISION_ID) {
429 /* FADT rev. 2 */
430 if (fadt->xpm_tmr_blk.address_space_id != ACPI_ADR_SPACE_SYSTEM_IO)
431 return 0;
433 pmtmr_ioport = fadt->xpm_tmr_blk.address;
434 } else {
435 /* FADT rev. 1 */
436 pmtmr_ioport = fadt->V1_pm_tmr_blk;
437 }
438 if (pmtmr_ioport)
439 printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n", pmtmr_ioport);
440 #endif
441 return 0;
442 }
445 unsigned long __init
446 acpi_find_rsdp (void)
447 {
448 unsigned long rsdp_phys = 0;
450 #if 0
451 if (efi_enabled) {
452 if (efi.acpi20)
453 return __pa(efi.acpi20);
454 else if (efi.acpi)
455 return __pa(efi.acpi);
456 }
457 #endif
458 /*
459 * Scan memory looking for the RSDP signature. First search EBDA (low
460 * memory) paragraphs and then search upper memory (E0000-FFFFF).
461 */
462 rsdp_phys = acpi_scan_rsdp (0, 0x400);
463 if (!rsdp_phys)
464 rsdp_phys = acpi_scan_rsdp (0xE0000, 0x20000);
466 return rsdp_phys;
467 }
469 #ifdef CONFIG_X86_LOCAL_APIC
470 /*
471 * Parse LAPIC entries in MADT
472 * returns 0 on success, < 0 on error
473 */
474 static int __init
475 acpi_parse_madt_lapic_entries(void)
476 {
477 int count;
479 /*
480 * Note that the LAPIC address is obtained from the MADT (32-bit value)
481 * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
482 */
484 count = acpi_table_parse_madt(ACPI_MADT_LAPIC_ADDR_OVR, acpi_parse_lapic_addr_ovr, 0);
485 if (count < 0) {
486 printk(KERN_ERR PREFIX "Error parsing LAPIC address override entry\n");
487 return count;
488 }
490 mp_register_lapic_address(acpi_lapic_addr);
492 count = acpi_table_parse_madt(ACPI_MADT_LAPIC, acpi_parse_lapic,
493 MAX_APICS);
494 if (!count) {
495 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
496 /* TBD: Cleanup to allow fallback to MPS */
497 return -ENODEV;
498 }
499 else if (count < 0) {
500 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
501 /* TBD: Cleanup to allow fallback to MPS */
502 return count;
503 }
505 count = acpi_table_parse_madt(ACPI_MADT_LAPIC_NMI, acpi_parse_lapic_nmi, 0);
506 if (count < 0) {
507 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
508 /* TBD: Cleanup to allow fallback to MPS */
509 return count;
510 }
511 return 0;
512 }
513 #endif /* CONFIG_X86_LOCAL_APIC */
515 #if defined(CONFIG_X86_IO_APIC) /*&& defined(CONFIG_ACPI_INTERPRETER)*/
516 /*
517 * Parse IOAPIC related entries in MADT
518 * returns 0 on success, < 0 on error
519 */
520 static int __init
521 acpi_parse_madt_ioapic_entries(void)
522 {
523 int count;
525 /*
526 * ACPI interpreter is required to complete interrupt setup,
527 * so if it is off, don't enumerate the io-apics with ACPI.
528 * If MPS is present, it will handle them,
529 * otherwise the system will stay in PIC mode
530 */
531 if (acpi_disabled || acpi_noirq) {
532 return -ENODEV;
533 }
535 /*
536 * if "noapic" boot option, don't look for IO-APICs
537 */
538 if (skip_ioapic_setup) {
539 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
540 "due to 'noapic' option.\n");
541 return -ENODEV;
542 }
544 count = acpi_table_parse_madt(ACPI_MADT_IOAPIC, acpi_parse_ioapic, MAX_IO_APICS);
545 if (!count) {
546 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
547 return -ENODEV;
548 }
549 else if (count < 0) {
550 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
551 return count;
552 }
554 count = acpi_table_parse_madt(ACPI_MADT_INT_SRC_OVR, acpi_parse_int_src_ovr, NR_IRQ_VECTORS);
555 if (count < 0) {
556 printk(KERN_ERR PREFIX "Error parsing interrupt source overrides entry\n");
557 /* TBD: Cleanup to allow fallback to MPS */
558 return count;
559 }
561 #ifdef CONFIG_ACPI_INTERPRETER
562 /*
563 * If BIOS did not supply an INT_SRC_OVR for the SCI
564 * pretend we got one so we can set the SCI flags.
565 */
566 if (!acpi_sci_override_gsi)
567 acpi_sci_ioapic_setup(acpi_fadt.sci_int, 0, 0);
568 #endif
570 /* Fill in identity legacy mapings where no override */
571 mp_config_acpi_legacy_irqs();
573 count = acpi_table_parse_madt(ACPI_MADT_NMI_SRC, acpi_parse_nmi_src, NR_IRQ_VECTORS);
574 if (count < 0) {
575 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
576 /* TBD: Cleanup to allow fallback to MPS */
577 return count;
578 }
580 return 0;
581 }
582 #else
583 static inline int acpi_parse_madt_ioapic_entries(void)
584 {
585 return -1;
586 }
587 #endif /* !(CONFIG_X86_IO_APIC && CONFIG_ACPI_INTERPRETER) */
590 static void __init
591 acpi_process_madt(void)
592 {
593 #ifdef CONFIG_X86_LOCAL_APIC
594 int count, error;
596 count = acpi_table_parse(ACPI_APIC, acpi_parse_madt);
597 if (count >= 1) {
599 /*
600 * Parse MADT LAPIC entries
601 */
602 error = acpi_parse_madt_lapic_entries();
603 if (!error) {
604 acpi_lapic = 1;
606 /*
607 * Parse MADT IO-APIC entries
608 */
609 error = acpi_parse_madt_ioapic_entries();
610 if (!error) {
611 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
612 acpi_irq_balance_set(NULL);
613 acpi_ioapic = 1;
615 smp_found_config = 1;
616 clustered_apic_check();
617 }
618 }
619 if (error == -EINVAL) {
620 /*
621 * Dell Precision Workstation 410, 610 come here.
622 */
623 printk(KERN_ERR PREFIX "Invalid BIOS MADT, disabling ACPI\n");
624 disable_acpi();
625 }
626 }
627 #endif
628 return;
629 }
631 /*
632 * acpi_boot_table_init() and acpi_boot_init()
633 * called from setup_arch(), always.
634 * 1. checksums all tables
635 * 2. enumerates lapics
636 * 3. enumerates io-apics
637 *
638 * acpi_table_init() is separate to allow reading SRAT without
639 * other side effects.
640 *
641 * side effects of acpi_boot_init:
642 * acpi_lapic = 1 if LAPIC found
643 * acpi_ioapic = 1 if IOAPIC found
644 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
645 * if acpi_blacklisted() acpi_disabled = 1;
646 * acpi_irq_model=...
647 * ...
648 *
649 * return value: (currently ignored)
650 * 0: success
651 * !0: failure
652 */
654 int __init
655 acpi_boot_table_init(void)
656 {
657 int error;
659 /*
660 * If acpi_disabled, bail out
661 * One exception: acpi=ht continues far enough to enumerate LAPICs
662 */
663 if (acpi_disabled && !acpi_ht)
664 return 1;
666 /*
667 * Initialize the ACPI boot-time table parser.
668 */
669 error = acpi_table_init();
670 if (error) {
671 disable_acpi();
672 return error;
673 }
675 acpi_table_parse(ACPI_BOOT, acpi_parse_sbf);
677 /*
678 * blacklist may disable ACPI entirely
679 */
680 error = acpi_blacklisted();
681 if (error) {
682 extern int acpi_force;
684 if (acpi_force) {
685 printk(KERN_WARNING PREFIX "acpi=force override\n");
686 } else {
687 printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
688 disable_acpi();
689 return error;
690 }
691 }
693 return 0;
694 }
697 int __init acpi_boot_init(void)
698 {
699 /*
700 * If acpi_disabled, bail out
701 * One exception: acpi=ht continues far enough to enumerate LAPICs
702 */
703 if (acpi_disabled && !acpi_ht)
704 return 1;
706 acpi_table_parse(ACPI_BOOT, acpi_parse_sbf);
708 /*
709 * set sci_int and PM timer address
710 */
711 acpi_table_parse(ACPI_FADT, acpi_parse_fadt);
713 /*
714 * Process the Multiple APIC Description Table (MADT), if present
715 */
716 acpi_process_madt();
718 acpi_table_parse(ACPI_HPET, acpi_parse_hpet);
719 acpi_table_parse(ACPI_MCFG, acpi_parse_mcfg);
721 return 0;
722 }