[ACPI] Merge acpi-2.6.12 branch into 2.6.13-rc3
[sfrench/cifs-2.6.git] / arch / i386 / kernel / acpi / boot.c
1 /*
2  *  boot.c - Architecture-Specific Low-Level ACPI Boot Support
3  *
4  *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
5  *  Copyright (C) 2001 Jun Nakajima <jun.nakajima@intel.com>
6  *
7  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  *
23  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24  */
25
26 #include <linux/init.h>
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>
32 #include <linux/dmi.h>
33
34 #include <asm/pgtable.h>
35 #include <asm/io_apic.h>
36 #include <asm/apic.h>
37 #include <asm/io.h>
38 #include <asm/irq.h>
39 #include <asm/mpspec.h>
40
41 #ifdef  CONFIG_X86_64
42
43 static inline void  acpi_madt_oem_check(char *oem_id, char *oem_table_id) { }
44 extern void __init clustered_apic_check(void);
45 static inline int ioapic_setup_disabled(void) { return 0; }
46 #include <asm/proto.h>
47
48 #else   /* X86 */
49
50 #ifdef  CONFIG_X86_LOCAL_APIC
51 #include <mach_apic.h>
52 #include <mach_mpparse.h>
53 #endif  /* CONFIG_X86_LOCAL_APIC */
54
55 #endif  /* X86 */
56
57 #define BAD_MADT_ENTRY(entry, end) (                                        \
58                 (!entry) || (unsigned long)entry + sizeof(*entry) > end ||  \
59                 ((acpi_table_entry_header *)entry)->length != sizeof(*entry))
60
61 #define PREFIX                  "ACPI: "
62
63 #ifdef CONFIG_ACPI_PCI
64 int acpi_noirq __initdata;      /* skip ACPI IRQ initialization */
65 int acpi_pci_disabled __initdata; /* skip ACPI PCI scan and IRQ initialization */
66 #else
67 int acpi_noirq __initdata = 1;
68 int acpi_pci_disabled __initdata = 1;
69 #endif
70 int acpi_ht __initdata = 1;     /* enable HT */
71
72 int acpi_lapic;
73 int acpi_ioapic;
74 int acpi_strict;
75 EXPORT_SYMBOL(acpi_strict);
76
77 acpi_interrupt_flags acpi_sci_flags __initdata;
78 int acpi_sci_override_gsi __initdata;
79 int acpi_skip_timer_override __initdata;
80
81 #ifdef CONFIG_X86_LOCAL_APIC
82 static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
83 #endif
84
85 #ifndef __HAVE_ARCH_CMPXCHG
86 #warning ACPI uses CMPXCHG, i486 and later hardware
87 #endif
88
89 #define MAX_MADT_ENTRIES        256
90 u8 x86_acpiid_to_apicid[MAX_MADT_ENTRIES] =
91                         { [0 ... MAX_MADT_ENTRIES-1] = 0xff };
92 EXPORT_SYMBOL(x86_acpiid_to_apicid);
93
94 /* --------------------------------------------------------------------------
95                               Boot-time Configuration
96    -------------------------------------------------------------------------- */
97
98 /*
99  * The default interrupt routing model is PIC (8259).  This gets
100  * overriden if IOAPICs are enumerated (below).
101  */
102 enum acpi_irq_model_id          acpi_irq_model = ACPI_IRQ_MODEL_PIC;
103
104 #ifdef  CONFIG_X86_64
105
106 /* rely on all ACPI tables being in the direct mapping */
107 char *__acpi_map_table(unsigned long phys_addr, unsigned long size)
108 {
109         if (!phys_addr || !size)
110         return NULL;
111
112         if (phys_addr < (end_pfn_map << PAGE_SHIFT))
113                 return __va(phys_addr);
114
115         return NULL;
116 }
117
118 #else
119
120 /*
121  * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
122  * to map the target physical address. The problem is that set_fixmap()
123  * provides a single page, and it is possible that the page is not
124  * sufficient.
125  * By using this area, we can map up to MAX_IO_APICS pages temporarily,
126  * i.e. until the next __va_range() call.
127  *
128  * Important Safety Note:  The fixed I/O APIC page numbers are *subtracted*
129  * from the fixed base.  That's why we start at FIX_IO_APIC_BASE_END and
130  * count idx down while incrementing the phys address.
131  */
132 char *__acpi_map_table(unsigned long phys, unsigned long size)
133 {
134         unsigned long base, offset, mapped_size;
135         int idx;
136
137         if (phys + size < 8*1024*1024) 
138                 return __va(phys); 
139
140         offset = phys & (PAGE_SIZE - 1);
141         mapped_size = PAGE_SIZE - offset;
142         set_fixmap(FIX_ACPI_END, phys);
143         base = fix_to_virt(FIX_ACPI_END);
144
145         /*
146          * Most cases can be covered by the below.
147          */
148         idx = FIX_ACPI_END;
149         while (mapped_size < size) {
150                 if (--idx < FIX_ACPI_BEGIN)
151                         return NULL;    /* cannot handle this */
152                 phys += PAGE_SIZE;
153                 set_fixmap(idx, phys);
154                 mapped_size += PAGE_SIZE;
155         }
156
157         return ((unsigned char *) base + offset);
158 }
159 #endif
160
161 #ifdef CONFIG_PCI_MMCONFIG
162 /* The physical address of the MMCONFIG aperture.  Set from ACPI tables. */
163 struct acpi_table_mcfg_config *pci_mmcfg_config;
164 int pci_mmcfg_config_num;
165
166 int __init acpi_parse_mcfg(unsigned long phys_addr, unsigned long size)
167 {
168         struct acpi_table_mcfg *mcfg;
169         unsigned long i;
170         int config_size;
171
172         if (!phys_addr || !size)
173                 return -EINVAL;
174
175         mcfg = (struct acpi_table_mcfg *) __acpi_map_table(phys_addr, size);
176         if (!mcfg) {
177                 printk(KERN_WARNING PREFIX "Unable to map MCFG\n");
178                 return -ENODEV;
179         }
180
181         /* how many config structures do we have */
182         pci_mmcfg_config_num = 0;
183         i = size - sizeof(struct acpi_table_mcfg);
184         while (i >= sizeof(struct acpi_table_mcfg_config)) {
185                 ++pci_mmcfg_config_num;
186                 i -= sizeof(struct acpi_table_mcfg_config);
187         };
188         if (pci_mmcfg_config_num == 0) {
189                 printk(KERN_ERR PREFIX "MMCONFIG has no entries\n");
190                 return -ENODEV;
191         }
192
193         config_size = pci_mmcfg_config_num * sizeof(*pci_mmcfg_config);
194         pci_mmcfg_config = kmalloc(config_size, GFP_KERNEL);
195         if (!pci_mmcfg_config) {
196                 printk(KERN_WARNING PREFIX
197                        "No memory for MCFG config tables\n");
198                 return -ENOMEM;
199         }
200
201         memcpy(pci_mmcfg_config, &mcfg->config, config_size);
202         for (i = 0; i < pci_mmcfg_config_num; ++i) {
203                 if (mcfg->config[i].base_reserved) {
204                         printk(KERN_ERR PREFIX
205                                "MMCONFIG not in low 4GB of memory\n");
206                         return -ENODEV;
207                 }
208         }
209
210         return 0;
211 }
212 #endif /* CONFIG_PCI_MMCONFIG */
213
214 #ifdef CONFIG_X86_LOCAL_APIC
215 static int __init
216 acpi_parse_madt (
217         unsigned long           phys_addr,
218         unsigned long           size)
219 {
220         struct acpi_table_madt  *madt = NULL;
221
222         if (!phys_addr || !size)
223                 return -EINVAL;
224
225         madt = (struct acpi_table_madt *) __acpi_map_table(phys_addr, size);
226         if (!madt) {
227                 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
228                 return -ENODEV;
229         }
230
231         if (madt->lapic_address) {
232                 acpi_lapic_addr = (u64) madt->lapic_address;
233
234                 printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
235                         madt->lapic_address);
236         }
237
238         acpi_madt_oem_check(madt->header.oem_id, madt->header.oem_table_id);
239         
240         return 0;
241 }
242
243
244 static int __init
245 acpi_parse_lapic (
246         acpi_table_entry_header *header, const unsigned long end)
247 {
248         struct acpi_table_lapic *processor = NULL;
249
250         processor = (struct acpi_table_lapic*) header;
251
252         if (BAD_MADT_ENTRY(processor, end))
253                 return -EINVAL;
254
255         acpi_table_print_madt_entry(header);
256
257         /* no utility in registering a disabled processor */
258         if (processor->flags.enabled == 0)
259                 return 0;
260
261         x86_acpiid_to_apicid[processor->acpi_id] = processor->id;
262
263         mp_register_lapic (
264                 processor->id,                                     /* APIC ID */
265                 processor->flags.enabled);                        /* Enabled? */
266
267         return 0;
268 }
269
270 static int __init
271 acpi_parse_lapic_addr_ovr (
272         acpi_table_entry_header *header, const unsigned long end)
273 {
274         struct acpi_table_lapic_addr_ovr *lapic_addr_ovr = NULL;
275
276         lapic_addr_ovr = (struct acpi_table_lapic_addr_ovr*) header;
277
278         if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
279                 return -EINVAL;
280
281         acpi_lapic_addr = lapic_addr_ovr->address;
282
283         return 0;
284 }
285
286 static int __init
287 acpi_parse_lapic_nmi (
288         acpi_table_entry_header *header, const unsigned long end)
289 {
290         struct acpi_table_lapic_nmi *lapic_nmi = NULL;
291
292         lapic_nmi = (struct acpi_table_lapic_nmi*) header;
293
294         if (BAD_MADT_ENTRY(lapic_nmi, end))
295                 return -EINVAL;
296
297         acpi_table_print_madt_entry(header);
298
299         if (lapic_nmi->lint != 1)
300                 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
301
302         return 0;
303 }
304
305
306 #endif /*CONFIG_X86_LOCAL_APIC*/
307
308 #if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_ACPI_INTERPRETER)
309
310 static int __init
311 acpi_parse_ioapic (
312         acpi_table_entry_header *header, const unsigned long end)
313 {
314         struct acpi_table_ioapic *ioapic = NULL;
315
316         ioapic = (struct acpi_table_ioapic*) header;
317
318         if (BAD_MADT_ENTRY(ioapic, end))
319                 return -EINVAL;
320  
321         acpi_table_print_madt_entry(header);
322
323         mp_register_ioapic (
324                 ioapic->id,
325                 ioapic->address,
326                 ioapic->global_irq_base);
327  
328         return 0;
329 }
330
331 /*
332  * Parse Interrupt Source Override for the ACPI SCI
333  */
334 static void
335 acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
336 {
337         if (trigger == 0)       /* compatible SCI trigger is level */
338                 trigger = 3;
339
340         if (polarity == 0)      /* compatible SCI polarity is low */
341                 polarity = 3;
342
343         /* Command-line over-ride via acpi_sci= */
344         if (acpi_sci_flags.trigger)
345                 trigger = acpi_sci_flags.trigger;
346
347         if (acpi_sci_flags.polarity)
348                 polarity = acpi_sci_flags.polarity;
349
350         /*
351          * mp_config_acpi_legacy_irqs() already setup IRQs < 16
352          * If GSI is < 16, this will update its flags,
353          * else it will create a new mp_irqs[] entry.
354          */
355         mp_override_legacy_irq(gsi, polarity, trigger, gsi);
356
357         /*
358          * stash over-ride to indicate we've been here
359          * and for later update of acpi_fadt
360          */
361         acpi_sci_override_gsi = gsi;
362         return;
363 }
364
365 static int __init
366 acpi_parse_int_src_ovr (
367         acpi_table_entry_header *header, const unsigned long end)
368 {
369         struct acpi_table_int_src_ovr *intsrc = NULL;
370
371         intsrc = (struct acpi_table_int_src_ovr*) header;
372
373         if (BAD_MADT_ENTRY(intsrc, end))
374                 return -EINVAL;
375
376         acpi_table_print_madt_entry(header);
377
378         if (intsrc->bus_irq == acpi_fadt.sci_int) {
379                 acpi_sci_ioapic_setup(intsrc->global_irq,
380                         intsrc->flags.polarity, intsrc->flags.trigger);
381                 return 0;
382         }
383
384         if (acpi_skip_timer_override &&
385                 intsrc->bus_irq == 0 && intsrc->global_irq == 2) {
386                         printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
387                         return 0;
388         }
389
390         mp_override_legacy_irq (
391                 intsrc->bus_irq,
392                 intsrc->flags.polarity,
393                 intsrc->flags.trigger,
394                 intsrc->global_irq);
395
396         return 0;
397 }
398
399
400 static int __init
401 acpi_parse_nmi_src (
402         acpi_table_entry_header *header, const unsigned long end)
403 {
404         struct acpi_table_nmi_src *nmi_src = NULL;
405
406         nmi_src = (struct acpi_table_nmi_src*) header;
407
408         if (BAD_MADT_ENTRY(nmi_src, end))
409                 return -EINVAL;
410
411         acpi_table_print_madt_entry(header);
412
413         /* TBD: Support nimsrc entries? */
414
415         return 0;
416 }
417
418 #endif /* CONFIG_X86_IO_APIC */
419
420 #ifdef  CONFIG_ACPI_BUS
421
422 /*
423  * acpi_pic_sci_set_trigger()
424  * 
425  * use ELCR to set PIC-mode trigger type for SCI
426  *
427  * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
428  * it may require Edge Trigger -- use "acpi_sci=edge"
429  *
430  * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
431  * for the 8259 PIC.  bit[n] = 1 means irq[n] is Level, otherwise Edge.
432  * ECLR1 is IRQ's 0-7 (IRQ 0, 1, 2 must be 0)
433  * ECLR2 is IRQ's 8-15 (IRQ 8, 13 must be 0)
434  */
435
436 void __init
437 acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
438 {
439         unsigned int mask = 1 << irq;
440         unsigned int old, new;
441
442         /* Real old ELCR mask */
443         old = inb(0x4d0) | (inb(0x4d1) << 8);
444
445         /*
446          * If we use ACPI to set PCI irq's, then we should clear ELCR
447          * since we will set it correctly as we enable the PCI irq
448          * routing.
449          */
450         new = acpi_noirq ? old : 0;
451
452         /*
453          * Update SCI information in the ELCR, it isn't in the PCI
454          * routing tables..
455          */
456         switch (trigger) {
457         case 1: /* Edge - clear */
458                 new &= ~mask;
459                 break;
460         case 3: /* Level - set */
461                 new |= mask;
462                 break;
463         }
464
465         if (old == new)
466                 return;
467
468         printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
469         outb(new, 0x4d0);
470         outb(new >> 8, 0x4d1);
471 }
472
473
474 #endif /* CONFIG_ACPI_BUS */
475
476 int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
477 {
478 #ifdef CONFIG_X86_IO_APIC
479         if (use_pci_vector() && !platform_legacy_irq(gsi))
480                 *irq = IO_APIC_VECTOR(gsi);
481         else
482 #endif
483                 *irq = gsi;
484         return 0;
485 }
486
487 /*
488  * success: return IRQ number (>=0)
489  * failure: return < 0
490  */
491 int acpi_register_gsi(u32 gsi, int edge_level, int active_high_low)
492 {
493         unsigned int irq;
494         unsigned int plat_gsi = gsi;
495
496 #ifdef CONFIG_PCI
497         /*
498          * Make sure all (legacy) PCI IRQs are set as level-triggered.
499          */
500         if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
501                 extern void eisa_set_level_irq(unsigned int irq);
502
503                 if (edge_level == ACPI_LEVEL_SENSITIVE)
504                                 eisa_set_level_irq(gsi);
505         }
506 #endif
507
508 #ifdef CONFIG_X86_IO_APIC
509         if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) {
510                 plat_gsi = mp_register_gsi(gsi, edge_level, active_high_low);
511         }
512 #endif
513         acpi_gsi_to_irq(plat_gsi, &irq);
514         return irq;
515 }
516 EXPORT_SYMBOL(acpi_register_gsi);
517
518 /*
519  *  ACPI based hotplug support for CPU
520  */
521 #ifdef CONFIG_ACPI_HOTPLUG_CPU
522 int
523 acpi_map_lsapic(acpi_handle handle, int *pcpu)
524 {
525         /* TBD */
526         return -EINVAL;
527 }
528 EXPORT_SYMBOL(acpi_map_lsapic);
529
530
531 int
532 acpi_unmap_lsapic(int cpu)
533 {
534         /* TBD */
535         return -EINVAL;
536 }
537 EXPORT_SYMBOL(acpi_unmap_lsapic);
538 #endif /* CONFIG_ACPI_HOTPLUG_CPU */
539
540 int
541 acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
542 {
543         /* TBD */
544         return -EINVAL;
545 }
546 EXPORT_SYMBOL(acpi_register_ioapic);
547
548 int
549 acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
550 {
551         /* TBD */
552         return -EINVAL;
553 }
554 EXPORT_SYMBOL(acpi_unregister_ioapic);
555
556 static unsigned long __init
557 acpi_scan_rsdp (
558         unsigned long           start,
559         unsigned long           length)
560 {
561         unsigned long           offset = 0;
562         unsigned long           sig_len = sizeof("RSD PTR ") - 1;
563
564         /*
565          * Scan all 16-byte boundaries of the physical memory region for the
566          * RSDP signature.
567          */
568         for (offset = 0; offset < length; offset += 16) {
569                 if (strncmp((char *) (start + offset), "RSD PTR ", sig_len))
570                         continue;
571                 return (start + offset);
572         }
573
574         return 0;
575 }
576
577 static int __init acpi_parse_sbf(unsigned long phys_addr, unsigned long size)
578 {
579         struct acpi_table_sbf *sb;
580
581         if (!phys_addr || !size)
582         return -EINVAL;
583
584         sb = (struct acpi_table_sbf *) __acpi_map_table(phys_addr, size);
585         if (!sb) {
586                 printk(KERN_WARNING PREFIX "Unable to map SBF\n");
587                 return -ENODEV;
588         }
589
590         sbf_port = sb->sbf_cmos; /* Save CMOS port */
591
592         return 0;
593 }
594
595
596 #ifdef CONFIG_HPET_TIMER
597
598 static int __init acpi_parse_hpet(unsigned long phys, unsigned long size)
599 {
600         struct acpi_table_hpet *hpet_tbl;
601
602         if (!phys || !size)
603                 return -EINVAL;
604
605         hpet_tbl = (struct acpi_table_hpet *) __acpi_map_table(phys, size);
606         if (!hpet_tbl) {
607                 printk(KERN_WARNING PREFIX "Unable to map HPET\n");
608                 return -ENODEV;
609         }
610
611         if (hpet_tbl->addr.space_id != ACPI_SPACE_MEM) {
612                 printk(KERN_WARNING PREFIX "HPET timers must be located in "
613                        "memory.\n");
614                 return -1;
615         }
616
617 #ifdef  CONFIG_X86_64
618         vxtime.hpet_address = hpet_tbl->addr.addrl |
619                 ((long) hpet_tbl->addr.addrh << 32);
620
621         printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
622                hpet_tbl->id, vxtime.hpet_address);
623 #else   /* X86 */
624         {
625                 extern unsigned long hpet_address;
626
627                 hpet_address = hpet_tbl->addr.addrl;
628                 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
629                         hpet_tbl->id, hpet_address);
630         }
631 #endif  /* X86 */
632
633         return 0;
634 }
635 #else
636 #define acpi_parse_hpet NULL
637 #endif
638
639 #ifdef CONFIG_X86_PM_TIMER
640 extern u32 pmtmr_ioport;
641 #endif
642
643 static int __init acpi_parse_fadt(unsigned long phys, unsigned long size)
644 {
645         struct fadt_descriptor_rev2 *fadt = NULL;
646
647         fadt = (struct fadt_descriptor_rev2*) __acpi_map_table(phys,size);
648         if(!fadt) {
649                 printk(KERN_WARNING PREFIX "Unable to map FADT\n");
650                 return 0;
651         }
652
653 #ifdef  CONFIG_ACPI_INTERPRETER
654         /* initialize sci_int early for INT_SRC_OVR MADT parsing */
655         acpi_fadt.sci_int = fadt->sci_int;
656 #endif
657
658 #ifdef CONFIG_ACPI_BUS
659         /* initialize rev and apic_phys_dest_mode for x86_64 genapic */
660         acpi_fadt.revision = fadt->revision;
661         acpi_fadt.force_apic_physical_destination_mode = fadt->force_apic_physical_destination_mode;
662 #endif
663
664 #ifdef CONFIG_X86_PM_TIMER
665         /* detect the location of the ACPI PM Timer */
666         if (fadt->revision >= FADT2_REVISION_ID) {
667                 /* FADT rev. 2 */
668                 if (fadt->xpm_tmr_blk.address_space_id != ACPI_ADR_SPACE_SYSTEM_IO)
669                         return 0;
670
671                 pmtmr_ioport = fadt->xpm_tmr_blk.address;
672         } else {
673                 /* FADT rev. 1 */
674                 pmtmr_ioport = fadt->V1_pm_tmr_blk;
675         }
676         if (pmtmr_ioport)
677                 printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n", pmtmr_ioport);
678 #endif
679         return 0;
680 }
681
682
683 unsigned long __init
684 acpi_find_rsdp (void)
685 {
686         unsigned long           rsdp_phys = 0;
687
688         if (efi_enabled) {
689                 if (efi.acpi20)
690                         return __pa(efi.acpi20);
691                 else if (efi.acpi)
692                         return __pa(efi.acpi);
693         }
694         /*
695          * Scan memory looking for the RSDP signature. First search EBDA (low
696          * memory) paragraphs and then search upper memory (E0000-FFFFF).
697          */
698         rsdp_phys = acpi_scan_rsdp (0, 0x400);
699         if (!rsdp_phys)
700                 rsdp_phys = acpi_scan_rsdp (0xE0000, 0x20000);
701
702         return rsdp_phys;
703 }
704
705 #ifdef  CONFIG_X86_LOCAL_APIC
706 /*
707  * Parse LAPIC entries in MADT
708  * returns 0 on success, < 0 on error
709  */
710 static int __init
711 acpi_parse_madt_lapic_entries(void)
712 {
713         int count;
714
715         /* 
716          * Note that the LAPIC address is obtained from the MADT (32-bit value)
717          * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
718          */
719
720         count = acpi_table_parse_madt(ACPI_MADT_LAPIC_ADDR_OVR, acpi_parse_lapic_addr_ovr, 0);
721         if (count < 0) {
722                 printk(KERN_ERR PREFIX "Error parsing LAPIC address override entry\n");
723                 return count;
724         }
725
726         mp_register_lapic_address(acpi_lapic_addr);
727
728         count = acpi_table_parse_madt(ACPI_MADT_LAPIC, acpi_parse_lapic,
729                                        MAX_APICS);
730         if (!count) { 
731                 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
732                 /* TBD: Cleanup to allow fallback to MPS */
733                 return -ENODEV;
734         }
735         else if (count < 0) {
736                 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
737                 /* TBD: Cleanup to allow fallback to MPS */
738                 return count;
739         }
740
741         count = acpi_table_parse_madt(ACPI_MADT_LAPIC_NMI, acpi_parse_lapic_nmi, 0);
742         if (count < 0) {
743                 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
744                 /* TBD: Cleanup to allow fallback to MPS */
745                 return count;
746         }
747         return 0;
748 }
749 #endif /* CONFIG_X86_LOCAL_APIC */
750
751 #if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_ACPI_INTERPRETER)
752 /*
753  * Parse IOAPIC related entries in MADT
754  * returns 0 on success, < 0 on error
755  */
756 static int __init
757 acpi_parse_madt_ioapic_entries(void)
758 {
759         int count;
760
761         /*
762          * ACPI interpreter is required to complete interrupt setup,
763          * so if it is off, don't enumerate the io-apics with ACPI.
764          * If MPS is present, it will handle them,
765          * otherwise the system will stay in PIC mode
766          */
767         if (acpi_disabled || acpi_noirq) {
768                 return -ENODEV;
769         }
770
771         /*
772          * if "noapic" boot option, don't look for IO-APICs
773          */
774         if (skip_ioapic_setup) {
775                 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
776                         "due to 'noapic' option.\n");
777                 return -ENODEV;
778         }
779
780         count = acpi_table_parse_madt(ACPI_MADT_IOAPIC, acpi_parse_ioapic, MAX_IO_APICS);
781         if (!count) {
782                 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
783                 return -ENODEV;
784         }
785         else if (count < 0) {
786                 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
787                 return count;
788         }
789
790         count = acpi_table_parse_madt(ACPI_MADT_INT_SRC_OVR, acpi_parse_int_src_ovr, NR_IRQ_VECTORS);
791         if (count < 0) {
792                 printk(KERN_ERR PREFIX "Error parsing interrupt source overrides entry\n");
793                 /* TBD: Cleanup to allow fallback to MPS */
794                 return count;
795         }
796
797         /*
798          * If BIOS did not supply an INT_SRC_OVR for the SCI
799          * pretend we got one so we can set the SCI flags.
800          */
801         if (!acpi_sci_override_gsi)
802                 acpi_sci_ioapic_setup(acpi_fadt.sci_int, 0, 0);
803
804         /* Fill in identity legacy mapings where no override */
805         mp_config_acpi_legacy_irqs();
806
807         count = acpi_table_parse_madt(ACPI_MADT_NMI_SRC, acpi_parse_nmi_src, NR_IRQ_VECTORS);
808         if (count < 0) {
809                 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
810                 /* TBD: Cleanup to allow fallback to MPS */
811                 return count;
812         }
813
814         return 0;
815 }
816 #else
817 static inline int acpi_parse_madt_ioapic_entries(void)
818 {
819         return -1;
820 }
821 #endif /* !(CONFIG_X86_IO_APIC && CONFIG_ACPI_INTERPRETER) */
822
823
824 static void __init
825 acpi_process_madt(void)
826 {
827 #ifdef CONFIG_X86_LOCAL_APIC
828         int count, error;
829
830         count = acpi_table_parse(ACPI_APIC, acpi_parse_madt);
831         if (count >= 1) {
832
833                 /*
834                  * Parse MADT LAPIC entries
835                  */
836                 error = acpi_parse_madt_lapic_entries();
837                 if (!error) {
838                         acpi_lapic = 1;
839
840                         /*
841                          * Parse MADT IO-APIC entries
842                          */
843                         error = acpi_parse_madt_ioapic_entries();
844                         if (!error) {
845                                 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
846                                 acpi_irq_balance_set(NULL);
847                                 acpi_ioapic = 1;
848
849                                 smp_found_config = 1;
850                                 clustered_apic_check();
851                         }
852                 }
853                 if (error == -EINVAL) {
854                         /*
855                          * Dell Precision Workstation 410, 610 come here.
856                          */
857                         printk(KERN_ERR PREFIX "Invalid BIOS MADT, disabling ACPI\n");
858                         disable_acpi();
859                 }
860         }
861 #endif
862         return;
863 }
864
865 extern int acpi_force;
866
867 #ifdef __i386__
868
869 #ifdef  CONFIG_ACPI_PCI
870 static int __init disable_acpi_irq(struct dmi_system_id *d)
871 {
872         if (!acpi_force) {
873                 printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
874                        d->ident);
875                 acpi_noirq_set();
876         }
877         return 0;
878 }
879
880 static int __init disable_acpi_pci(struct dmi_system_id *d)
881 {
882         if (!acpi_force) {
883                 printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
884                        d->ident);
885                 acpi_disable_pci();
886         }
887         return 0;
888 }
889 #endif
890
891 static int __init dmi_disable_acpi(struct dmi_system_id *d)
892 {
893         if (!acpi_force) {
894                 printk(KERN_NOTICE "%s detected: acpi off\n",d->ident);
895                 disable_acpi();
896         } else {
897                 printk(KERN_NOTICE
898                        "Warning: DMI blacklist says broken, but acpi forced\n");
899         }
900         return 0;
901 }
902
903 /*
904  * Limit ACPI to CPU enumeration for HT
905  */
906 static int __init force_acpi_ht(struct dmi_system_id *d)
907 {
908         if (!acpi_force) {
909                 printk(KERN_NOTICE "%s detected: force use of acpi=ht\n", d->ident);
910                 disable_acpi();
911                 acpi_ht = 1;
912         } else {
913                 printk(KERN_NOTICE
914                        "Warning: acpi=force overrules DMI blacklist: acpi=ht\n");
915         }
916         return 0;
917 }
918
919 /*
920  * If your system is blacklisted here, but you find that acpi=force
921  * works for you, please contact acpi-devel@sourceforge.net
922  */
923 static struct dmi_system_id __initdata acpi_dmi_table[] = {
924         /*
925          * Boxes that need ACPI disabled
926          */
927         {
928                 .callback = dmi_disable_acpi,
929                 .ident = "IBM Thinkpad",
930                 .matches = {
931                         DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
932                         DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
933                 },
934         },
935
936         /*
937          * Boxes that need acpi=ht
938          */
939         {
940                 .callback = force_acpi_ht,
941                 .ident = "FSC Primergy T850",
942                 .matches = {
943                         DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
944                         DMI_MATCH(DMI_PRODUCT_NAME, "PRIMERGY T850"),
945                 },
946         },
947         {
948                 .callback = force_acpi_ht,
949                 .ident = "DELL GX240",
950                 .matches = {
951                         DMI_MATCH(DMI_BOARD_VENDOR, "Dell Computer Corporation"),
952                         DMI_MATCH(DMI_BOARD_NAME, "OptiPlex GX240"),
953                 },
954         },
955         {
956                 .callback = force_acpi_ht,
957                 .ident = "HP VISUALIZE NT Workstation",
958                 .matches = {
959                         DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
960                         DMI_MATCH(DMI_PRODUCT_NAME, "HP VISUALIZE NT Workstation"),
961                 },
962         },
963         {
964                 .callback = force_acpi_ht,
965                 .ident = "Compaq Workstation W8000",
966                 .matches = {
967                         DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
968                         DMI_MATCH(DMI_PRODUCT_NAME, "Workstation W8000"),
969                 },
970         },
971         {
972                 .callback = force_acpi_ht,
973                 .ident = "ASUS P4B266",
974                 .matches = {
975                         DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
976                         DMI_MATCH(DMI_BOARD_NAME, "P4B266"),
977                 },
978         },
979         {
980                 .callback = force_acpi_ht,
981                 .ident = "ASUS P2B-DS",
982                 .matches = {
983                         DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
984                         DMI_MATCH(DMI_BOARD_NAME, "P2B-DS"),
985                 },
986         },
987         {
988                 .callback = force_acpi_ht,
989                 .ident = "ASUS CUR-DLS",
990                 .matches = {
991                         DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
992                         DMI_MATCH(DMI_BOARD_NAME, "CUR-DLS"),
993                 },
994         },
995         {
996                 .callback = force_acpi_ht,
997                 .ident = "ABIT i440BX-W83977",
998                 .matches = {
999                         DMI_MATCH(DMI_BOARD_VENDOR, "ABIT <http://www.abit.com>"),
1000                         DMI_MATCH(DMI_BOARD_NAME, "i440BX-W83977 (BP6)"),
1001                 },
1002         },
1003         {
1004                 .callback = force_acpi_ht,
1005                 .ident = "IBM Bladecenter",
1006                 .matches = {
1007                         DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1008                         DMI_MATCH(DMI_BOARD_NAME, "IBM eServer BladeCenter HS20"),
1009                 },
1010         },
1011         {
1012                 .callback = force_acpi_ht,
1013                 .ident = "IBM eServer xSeries 360",
1014                 .matches = {
1015                         DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1016                         DMI_MATCH(DMI_BOARD_NAME, "eServer xSeries 360"),
1017                 },
1018         },
1019         {
1020                 .callback = force_acpi_ht,
1021                 .ident = "IBM eserver xSeries 330",
1022                 .matches = {
1023                         DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1024                         DMI_MATCH(DMI_BOARD_NAME, "eserver xSeries 330"),
1025                 },
1026         },
1027         {
1028                 .callback = force_acpi_ht,
1029                 .ident = "IBM eserver xSeries 440",
1030                 .matches = {
1031                         DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1032                         DMI_MATCH(DMI_PRODUCT_NAME, "eserver xSeries 440"),
1033                 },
1034         },
1035
1036 #ifdef  CONFIG_ACPI_PCI
1037         /*
1038          * Boxes that need ACPI PCI IRQ routing disabled
1039          */
1040         {
1041                 .callback = disable_acpi_irq,
1042                 .ident = "ASUS A7V",
1043                 .matches = {
1044                         DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
1045                         DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
1046                         /* newer BIOS, Revision 1011, does work */
1047                         DMI_MATCH(DMI_BIOS_VERSION, "ASUS A7V ACPI BIOS Revision 1007"),
1048                 },
1049         },
1050
1051         /*
1052          * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
1053          */
1054         {       /* _BBN 0 bug */
1055                 .callback = disable_acpi_pci,
1056                 .ident = "ASUS PR-DLS",
1057                 .matches = {
1058                         DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1059                         DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
1060                         DMI_MATCH(DMI_BIOS_VERSION, "ASUS PR-DLS ACPI BIOS Revision 1010"),
1061                         DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
1062                 },
1063         },
1064         {
1065                 .callback = disable_acpi_pci,
1066                 .ident = "Acer TravelMate 36x Laptop",
1067                 .matches = {
1068                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
1069                         DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
1070                 },
1071         },
1072 #endif
1073         { }
1074 };
1075
1076 #endif  /* __i386__ */
1077
1078 /*
1079  * acpi_boot_table_init() and acpi_boot_init()
1080  *  called from setup_arch(), always.
1081  *      1. checksums all tables
1082  *      2. enumerates lapics
1083  *      3. enumerates io-apics
1084  *
1085  * acpi_table_init() is separate to allow reading SRAT without
1086  * other side effects.
1087  *
1088  * side effects of acpi_boot_init:
1089  *      acpi_lapic = 1 if LAPIC found
1090  *      acpi_ioapic = 1 if IOAPIC found
1091  *      if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
1092  *      if acpi_blacklisted() acpi_disabled = 1;
1093  *      acpi_irq_model=...
1094  *      ...
1095  *
1096  * return value: (currently ignored)
1097  *      0: success
1098  *      !0: failure
1099  */
1100
1101 int __init
1102 acpi_boot_table_init(void)
1103 {
1104         int error;
1105
1106 #ifdef __i386__
1107         dmi_check_system(acpi_dmi_table);
1108 #endif
1109
1110         /*
1111          * If acpi_disabled, bail out
1112          * One exception: acpi=ht continues far enough to enumerate LAPICs
1113          */
1114         if (acpi_disabled && !acpi_ht)
1115                  return 1;
1116
1117         /* 
1118          * Initialize the ACPI boot-time table parser.
1119          */
1120         error = acpi_table_init();
1121         if (error) {
1122                 disable_acpi();
1123                 return error;
1124         }
1125
1126 #ifdef __i386__
1127         check_acpi_pci();
1128 #endif
1129
1130         acpi_table_parse(ACPI_BOOT, acpi_parse_sbf);
1131
1132         /*
1133          * blacklist may disable ACPI entirely
1134          */
1135         error = acpi_blacklisted();
1136         if (error) {
1137                 if (acpi_force) {
1138                         printk(KERN_WARNING PREFIX "acpi=force override\n");
1139                 } else {
1140                         printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
1141                         disable_acpi();
1142                         return error;
1143                 }
1144         }
1145
1146         return 0;
1147 }
1148
1149
1150 int __init acpi_boot_init(void)
1151 {
1152         /*
1153          * If acpi_disabled, bail out
1154          * One exception: acpi=ht continues far enough to enumerate LAPICs
1155          */
1156         if (acpi_disabled && !acpi_ht)
1157                  return 1;
1158
1159         acpi_table_parse(ACPI_BOOT, acpi_parse_sbf);
1160
1161         /*
1162          * set sci_int and PM timer address
1163          */
1164         acpi_table_parse(ACPI_FADT, acpi_parse_fadt);
1165
1166         /*
1167          * Process the Multiple APIC Description Table (MADT), if present
1168          */
1169         acpi_process_madt();
1170
1171         acpi_table_parse(ACPI_HPET, acpi_parse_hpet);
1172
1173         return 0;
1174 }
1175