ACPI: delete dead acpi_disabled setting code
[linux-2.6] / arch / x86 / 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/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/bootmem.h>
35 #include <linux/ioport.h>
36
37 #include <asm/pgtable.h>
38 #include <asm/io_apic.h>
39 #include <asm/apic.h>
40 #include <asm/io.h>
41 #include <asm/mpspec.h>
42 #include <asm/smp.h>
43
44 static int __initdata acpi_force = 0;
45 u32 acpi_rsdt_forced;
46 int acpi_disabled;
47 EXPORT_SYMBOL(acpi_disabled);
48
49 #ifdef  CONFIG_X86_64
50 # include <asm/proto.h>
51 #endif                          /* X86 */
52
53 #define BAD_MADT_ENTRY(entry, end) (                                        \
54                 (!entry) || (unsigned long)entry + sizeof(*entry) > end ||  \
55                 ((struct acpi_subtable_header *)entry)->length < sizeof(*entry))
56
57 #define PREFIX                  "ACPI: "
58
59 int acpi_noirq;                         /* skip ACPI IRQ initialization */
60 int acpi_pci_disabled;          /* skip ACPI PCI scan and IRQ initialization */
61 EXPORT_SYMBOL(acpi_pci_disabled);
62 int acpi_ht __initdata = 1;     /* enable HT */
63
64 int acpi_lapic;
65 int acpi_ioapic;
66 int acpi_strict;
67
68 u8 acpi_sci_flags __initdata;
69 int acpi_sci_override_gsi __initdata;
70 int acpi_skip_timer_override __initdata;
71 int acpi_use_timer_override __initdata;
72
73 #ifdef CONFIG_X86_LOCAL_APIC
74 static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
75 #endif
76
77 #ifndef __HAVE_ARCH_CMPXCHG
78 #warning ACPI uses CMPXCHG, i486 and later hardware
79 #endif
80
81 /* --------------------------------------------------------------------------
82                               Boot-time Configuration
83    -------------------------------------------------------------------------- */
84
85 /*
86  * The default interrupt routing model is PIC (8259).  This gets
87  * overridden if IOAPICs are enumerated (below).
88  */
89 enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
90
91
92 /*
93  * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
94  * to map the target physical address. The problem is that set_fixmap()
95  * provides a single page, and it is possible that the page is not
96  * sufficient.
97  * By using this area, we can map up to MAX_IO_APICS pages temporarily,
98  * i.e. until the next __va_range() call.
99  *
100  * Important Safety Note:  The fixed I/O APIC page numbers are *subtracted*
101  * from the fixed base.  That's why we start at FIX_IO_APIC_BASE_END and
102  * count idx down while incrementing the phys address.
103  */
104 char *__init __acpi_map_table(unsigned long phys, unsigned long size)
105 {
106
107         if (!phys || !size)
108                 return NULL;
109
110         return early_ioremap(phys, size);
111 }
112 void __init __acpi_unmap_table(char *map, unsigned long size)
113 {
114         if (!map || !size)
115                 return;
116
117         early_iounmap(map, size);
118 }
119
120 #ifdef CONFIG_PCI_MMCONFIG
121
122 static int acpi_mcfg_64bit_base_addr __initdata = FALSE;
123
124 /* The physical address of the MMCONFIG aperture.  Set from ACPI tables. */
125 struct acpi_mcfg_allocation *pci_mmcfg_config;
126 int pci_mmcfg_config_num;
127
128 static int __init acpi_mcfg_oem_check(struct acpi_table_mcfg *mcfg)
129 {
130         if (!strcmp(mcfg->header.oem_id, "SGI"))
131                 acpi_mcfg_64bit_base_addr = TRUE;
132
133         return 0;
134 }
135
136 int __init acpi_parse_mcfg(struct acpi_table_header *header)
137 {
138         struct acpi_table_mcfg *mcfg;
139         unsigned long i;
140         int config_size;
141
142         if (!header)
143                 return -EINVAL;
144
145         mcfg = (struct acpi_table_mcfg *)header;
146
147         /* how many config structures do we have */
148         pci_mmcfg_config_num = 0;
149         i = header->length - sizeof(struct acpi_table_mcfg);
150         while (i >= sizeof(struct acpi_mcfg_allocation)) {
151                 ++pci_mmcfg_config_num;
152                 i -= sizeof(struct acpi_mcfg_allocation);
153         };
154         if (pci_mmcfg_config_num == 0) {
155                 printk(KERN_ERR PREFIX "MMCONFIG has no entries\n");
156                 return -ENODEV;
157         }
158
159         config_size = pci_mmcfg_config_num * sizeof(*pci_mmcfg_config);
160         pci_mmcfg_config = kmalloc(config_size, GFP_KERNEL);
161         if (!pci_mmcfg_config) {
162                 printk(KERN_WARNING PREFIX
163                        "No memory for MCFG config tables\n");
164                 return -ENOMEM;
165         }
166
167         memcpy(pci_mmcfg_config, &mcfg[1], config_size);
168
169         acpi_mcfg_oem_check(mcfg);
170
171         for (i = 0; i < pci_mmcfg_config_num; ++i) {
172                 if ((pci_mmcfg_config[i].address > 0xFFFFFFFF) &&
173                     !acpi_mcfg_64bit_base_addr) {
174                         printk(KERN_ERR PREFIX
175                                "MMCONFIG not in low 4GB of memory\n");
176                         kfree(pci_mmcfg_config);
177                         pci_mmcfg_config_num = 0;
178                         return -ENODEV;
179                 }
180         }
181
182         return 0;
183 }
184 #endif                          /* CONFIG_PCI_MMCONFIG */
185
186 #ifdef CONFIG_X86_LOCAL_APIC
187 static int __init acpi_parse_madt(struct acpi_table_header *table)
188 {
189         struct acpi_table_madt *madt = NULL;
190
191         if (!cpu_has_apic)
192                 return -EINVAL;
193
194         madt = (struct acpi_table_madt *)table;
195         if (!madt) {
196                 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
197                 return -ENODEV;
198         }
199
200         if (madt->address) {
201                 acpi_lapic_addr = (u64) madt->address;
202
203                 printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
204                        madt->address);
205         }
206
207         default_acpi_madt_oem_check(madt->header.oem_id,
208                                     madt->header.oem_table_id);
209
210         return 0;
211 }
212
213 static void __cpuinit acpi_register_lapic(int id, u8 enabled)
214 {
215         unsigned int ver = 0;
216
217         if (!enabled) {
218                 ++disabled_cpus;
219                 return;
220         }
221
222         if (boot_cpu_physical_apicid != -1U)
223                 ver = apic_version[boot_cpu_physical_apicid];
224
225         generic_processor_info(id, ver);
226 }
227
228 static int __init
229 acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
230 {
231         struct acpi_madt_local_x2apic *processor = NULL;
232
233         processor = (struct acpi_madt_local_x2apic *)header;
234
235         if (BAD_MADT_ENTRY(processor, end))
236                 return -EINVAL;
237
238         acpi_table_print_madt_entry(header);
239
240 #ifdef CONFIG_X86_X2APIC
241         /*
242          * We need to register disabled CPU as well to permit
243          * counting disabled CPUs. This allows us to size
244          * cpus_possible_map more accurately, to permit
245          * to not preallocating memory for all NR_CPUS
246          * when we use CPU hotplug.
247          */
248         acpi_register_lapic(processor->local_apic_id,   /* APIC ID */
249                             processor->lapic_flags & ACPI_MADT_ENABLED);
250 #else
251         printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
252 #endif
253
254         return 0;
255 }
256
257 static int __init
258 acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
259 {
260         struct acpi_madt_local_apic *processor = NULL;
261
262         processor = (struct acpi_madt_local_apic *)header;
263
264         if (BAD_MADT_ENTRY(processor, end))
265                 return -EINVAL;
266
267         acpi_table_print_madt_entry(header);
268
269         /*
270          * We need to register disabled CPU as well to permit
271          * counting disabled CPUs. This allows us to size
272          * cpus_possible_map more accurately, to permit
273          * to not preallocating memory for all NR_CPUS
274          * when we use CPU hotplug.
275          */
276         acpi_register_lapic(processor->id,      /* APIC ID */
277                             processor->lapic_flags & ACPI_MADT_ENABLED);
278
279         return 0;
280 }
281
282 static int __init
283 acpi_parse_sapic(struct acpi_subtable_header *header, const unsigned long end)
284 {
285         struct acpi_madt_local_sapic *processor = NULL;
286
287         processor = (struct acpi_madt_local_sapic *)header;
288
289         if (BAD_MADT_ENTRY(processor, end))
290                 return -EINVAL;
291
292         acpi_table_print_madt_entry(header);
293
294         acpi_register_lapic((processor->id << 8) | processor->eid,/* APIC ID */
295                             processor->lapic_flags & ACPI_MADT_ENABLED);
296
297         return 0;
298 }
299
300 static int __init
301 acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
302                           const unsigned long end)
303 {
304         struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
305
306         lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
307
308         if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
309                 return -EINVAL;
310
311         acpi_lapic_addr = lapic_addr_ovr->address;
312
313         return 0;
314 }
315
316 static int __init
317 acpi_parse_x2apic_nmi(struct acpi_subtable_header *header,
318                       const unsigned long end)
319 {
320         struct acpi_madt_local_x2apic_nmi *x2apic_nmi = NULL;
321
322         x2apic_nmi = (struct acpi_madt_local_x2apic_nmi *)header;
323
324         if (BAD_MADT_ENTRY(x2apic_nmi, end))
325                 return -EINVAL;
326
327         acpi_table_print_madt_entry(header);
328
329         if (x2apic_nmi->lint != 1)
330                 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
331
332         return 0;
333 }
334
335 static int __init
336 acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
337 {
338         struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
339
340         lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
341
342         if (BAD_MADT_ENTRY(lapic_nmi, end))
343                 return -EINVAL;
344
345         acpi_table_print_madt_entry(header);
346
347         if (lapic_nmi->lint != 1)
348                 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
349
350         return 0;
351 }
352
353 #endif                          /*CONFIG_X86_LOCAL_APIC */
354
355 #ifdef CONFIG_X86_IO_APIC
356
357 static int __init
358 acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
359 {
360         struct acpi_madt_io_apic *ioapic = NULL;
361
362         ioapic = (struct acpi_madt_io_apic *)header;
363
364         if (BAD_MADT_ENTRY(ioapic, end))
365                 return -EINVAL;
366
367         acpi_table_print_madt_entry(header);
368
369         mp_register_ioapic(ioapic->id,
370                            ioapic->address, ioapic->global_irq_base);
371
372         return 0;
373 }
374
375 /*
376  * Parse Interrupt Source Override for the ACPI SCI
377  */
378 static void __init acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
379 {
380         if (trigger == 0)       /* compatible SCI trigger is level */
381                 trigger = 3;
382
383         if (polarity == 0)      /* compatible SCI polarity is low */
384                 polarity = 3;
385
386         /* Command-line over-ride via acpi_sci= */
387         if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
388                 trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
389
390         if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
391                 polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
392
393         /*
394          * mp_config_acpi_legacy_irqs() already setup IRQs < 16
395          * If GSI is < 16, this will update its flags,
396          * else it will create a new mp_irqs[] entry.
397          */
398         mp_override_legacy_irq(gsi, polarity, trigger, gsi);
399
400         /*
401          * stash over-ride to indicate we've been here
402          * and for later update of acpi_gbl_FADT
403          */
404         acpi_sci_override_gsi = gsi;
405         return;
406 }
407
408 static int __init
409 acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
410                        const unsigned long end)
411 {
412         struct acpi_madt_interrupt_override *intsrc = NULL;
413
414         intsrc = (struct acpi_madt_interrupt_override *)header;
415
416         if (BAD_MADT_ENTRY(intsrc, end))
417                 return -EINVAL;
418
419         acpi_table_print_madt_entry(header);
420
421         if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
422                 acpi_sci_ioapic_setup(intsrc->global_irq,
423                                       intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
424                                       (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
425                 return 0;
426         }
427
428         if (acpi_skip_timer_override &&
429             intsrc->source_irq == 0 && intsrc->global_irq == 2) {
430                 printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
431                 return 0;
432         }
433
434         mp_override_legacy_irq(intsrc->source_irq,
435                                 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
436                                 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
437                                 intsrc->global_irq);
438
439         return 0;
440 }
441
442 static int __init
443 acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
444 {
445         struct acpi_madt_nmi_source *nmi_src = NULL;
446
447         nmi_src = (struct acpi_madt_nmi_source *)header;
448
449         if (BAD_MADT_ENTRY(nmi_src, end))
450                 return -EINVAL;
451
452         acpi_table_print_madt_entry(header);
453
454         /* TBD: Support nimsrc entries? */
455
456         return 0;
457 }
458
459 #endif                          /* CONFIG_X86_IO_APIC */
460
461 /*
462  * acpi_pic_sci_set_trigger()
463  *
464  * use ELCR to set PIC-mode trigger type for SCI
465  *
466  * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
467  * it may require Edge Trigger -- use "acpi_sci=edge"
468  *
469  * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
470  * for the 8259 PIC.  bit[n] = 1 means irq[n] is Level, otherwise Edge.
471  * ECLR1 is IRQs 0-7 (IRQ 0, 1, 2 must be 0)
472  * ECLR2 is IRQs 8-15 (IRQ 8, 13 must be 0)
473  */
474
475 void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
476 {
477         unsigned int mask = 1 << irq;
478         unsigned int old, new;
479
480         /* Real old ELCR mask */
481         old = inb(0x4d0) | (inb(0x4d1) << 8);
482
483         /*
484          * If we use ACPI to set PCI IRQs, then we should clear ELCR
485          * since we will set it correctly as we enable the PCI irq
486          * routing.
487          */
488         new = acpi_noirq ? old : 0;
489
490         /*
491          * Update SCI information in the ELCR, it isn't in the PCI
492          * routing tables..
493          */
494         switch (trigger) {
495         case 1:         /* Edge - clear */
496                 new &= ~mask;
497                 break;
498         case 3:         /* Level - set */
499                 new |= mask;
500                 break;
501         }
502
503         if (old == new)
504                 return;
505
506         printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
507         outb(new, 0x4d0);
508         outb(new >> 8, 0x4d1);
509 }
510
511 int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
512 {
513         *irq = gsi;
514         return 0;
515 }
516
517 /*
518  * success: return IRQ number (>=0)
519  * failure: return < 0
520  */
521 int acpi_register_gsi(u32 gsi, int triggering, int polarity)
522 {
523         unsigned int irq;
524         unsigned int plat_gsi = gsi;
525
526 #ifdef CONFIG_PCI
527         /*
528          * Make sure all (legacy) PCI IRQs are set as level-triggered.
529          */
530         if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
531                 if (triggering == ACPI_LEVEL_SENSITIVE)
532                         eisa_set_level_irq(gsi);
533         }
534 #endif
535
536 #ifdef CONFIG_X86_IO_APIC
537         if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) {
538                 plat_gsi = mp_register_gsi(gsi, triggering, polarity);
539         }
540 #endif
541         acpi_gsi_to_irq(plat_gsi, &irq);
542         return irq;
543 }
544
545 /*
546  *  ACPI based hotplug support for CPU
547  */
548 #ifdef CONFIG_ACPI_HOTPLUG_CPU
549
550 static int __cpuinit _acpi_map_lsapic(acpi_handle handle, int *pcpu)
551 {
552         struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
553         union acpi_object *obj;
554         struct acpi_madt_local_apic *lapic;
555         cpumask_var_t tmp_map, new_map;
556         u8 physid;
557         int cpu;
558         int retval = -ENOMEM;
559
560         if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
561                 return -EINVAL;
562
563         if (!buffer.length || !buffer.pointer)
564                 return -EINVAL;
565
566         obj = buffer.pointer;
567         if (obj->type != ACPI_TYPE_BUFFER ||
568             obj->buffer.length < sizeof(*lapic)) {
569                 kfree(buffer.pointer);
570                 return -EINVAL;
571         }
572
573         lapic = (struct acpi_madt_local_apic *)obj->buffer.pointer;
574
575         if (lapic->header.type != ACPI_MADT_TYPE_LOCAL_APIC ||
576             !(lapic->lapic_flags & ACPI_MADT_ENABLED)) {
577                 kfree(buffer.pointer);
578                 return -EINVAL;
579         }
580
581         physid = lapic->id;
582
583         kfree(buffer.pointer);
584         buffer.length = ACPI_ALLOCATE_BUFFER;
585         buffer.pointer = NULL;
586
587         if (!alloc_cpumask_var(&tmp_map, GFP_KERNEL))
588                 goto out;
589
590         if (!alloc_cpumask_var(&new_map, GFP_KERNEL))
591                 goto free_tmp_map;
592
593         cpumask_copy(tmp_map, cpu_present_mask);
594         acpi_register_lapic(physid, lapic->lapic_flags & ACPI_MADT_ENABLED);
595
596         /*
597          * If mp_register_lapic successfully generates a new logical cpu
598          * number, then the following will get us exactly what was mapped
599          */
600         cpumask_andnot(new_map, cpu_present_mask, tmp_map);
601         if (cpumask_empty(new_map)) {
602                 printk ("Unable to map lapic to logical cpu number\n");
603                 retval = -EINVAL;
604                 goto free_new_map;
605         }
606
607         cpu = cpumask_first(new_map);
608
609         *pcpu = cpu;
610         retval = 0;
611
612 free_new_map:
613         free_cpumask_var(new_map);
614 free_tmp_map:
615         free_cpumask_var(tmp_map);
616 out:
617         return retval;
618 }
619
620 /* wrapper to silence section mismatch warning */
621 int __ref acpi_map_lsapic(acpi_handle handle, int *pcpu)
622 {
623         return _acpi_map_lsapic(handle, pcpu);
624 }
625 EXPORT_SYMBOL(acpi_map_lsapic);
626
627 int acpi_unmap_lsapic(int cpu)
628 {
629         per_cpu(x86_cpu_to_apicid, cpu) = -1;
630         set_cpu_present(cpu, false);
631         num_processors--;
632
633         return (0);
634 }
635
636 EXPORT_SYMBOL(acpi_unmap_lsapic);
637 #endif                          /* CONFIG_ACPI_HOTPLUG_CPU */
638
639 int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
640 {
641         /* TBD */
642         return -EINVAL;
643 }
644
645 EXPORT_SYMBOL(acpi_register_ioapic);
646
647 int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
648 {
649         /* TBD */
650         return -EINVAL;
651 }
652
653 EXPORT_SYMBOL(acpi_unregister_ioapic);
654
655 static int __init acpi_parse_sbf(struct acpi_table_header *table)
656 {
657         struct acpi_table_boot *sb;
658
659         sb = (struct acpi_table_boot *)table;
660         if (!sb) {
661                 printk(KERN_WARNING PREFIX "Unable to map SBF\n");
662                 return -ENODEV;
663         }
664
665         sbf_port = sb->cmos_index;      /* Save CMOS port */
666
667         return 0;
668 }
669
670 #ifdef CONFIG_HPET_TIMER
671 #include <asm/hpet.h>
672
673 static struct __initdata resource *hpet_res;
674
675 static int __init acpi_parse_hpet(struct acpi_table_header *table)
676 {
677         struct acpi_table_hpet *hpet_tbl;
678
679         hpet_tbl = (struct acpi_table_hpet *)table;
680         if (!hpet_tbl) {
681                 printk(KERN_WARNING PREFIX "Unable to map HPET\n");
682                 return -ENODEV;
683         }
684
685         if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
686                 printk(KERN_WARNING PREFIX "HPET timers must be located in "
687                        "memory.\n");
688                 return -1;
689         }
690
691         hpet_address = hpet_tbl->address.address;
692
693         /*
694          * Some broken BIOSes advertise HPET at 0x0. We really do not
695          * want to allocate a resource there.
696          */
697         if (!hpet_address) {
698                 printk(KERN_WARNING PREFIX
699                        "HPET id: %#x base: %#lx is invalid\n",
700                        hpet_tbl->id, hpet_address);
701                 return 0;
702         }
703 #ifdef CONFIG_X86_64
704         /*
705          * Some even more broken BIOSes advertise HPET at
706          * 0xfed0000000000000 instead of 0xfed00000. Fix it up and add
707          * some noise:
708          */
709         if (hpet_address == 0xfed0000000000000UL) {
710                 if (!hpet_force_user) {
711                         printk(KERN_WARNING PREFIX "HPET id: %#x "
712                                "base: 0xfed0000000000000 is bogus\n "
713                                "try hpet=force on the kernel command line to "
714                                "fix it up to 0xfed00000.\n", hpet_tbl->id);
715                         hpet_address = 0;
716                         return 0;
717                 }
718                 printk(KERN_WARNING PREFIX
719                        "HPET id: %#x base: 0xfed0000000000000 fixed up "
720                        "to 0xfed00000.\n", hpet_tbl->id);
721                 hpet_address >>= 32;
722         }
723 #endif
724         printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
725                hpet_tbl->id, hpet_address);
726
727         /*
728          * Allocate and initialize the HPET firmware resource for adding into
729          * the resource tree during the lateinit timeframe.
730          */
731 #define HPET_RESOURCE_NAME_SIZE 9
732         hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
733
734         hpet_res->name = (void *)&hpet_res[1];
735         hpet_res->flags = IORESOURCE_MEM;
736         snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE, "HPET %u",
737                  hpet_tbl->sequence);
738
739         hpet_res->start = hpet_address;
740         hpet_res->end = hpet_address + (1 * 1024) - 1;
741
742         return 0;
743 }
744
745 /*
746  * hpet_insert_resource inserts the HPET resources used into the resource
747  * tree.
748  */
749 static __init int hpet_insert_resource(void)
750 {
751         if (!hpet_res)
752                 return 1;
753
754         return insert_resource(&iomem_resource, hpet_res);
755 }
756
757 late_initcall(hpet_insert_resource);
758
759 #else
760 #define acpi_parse_hpet NULL
761 #endif
762
763 static int __init acpi_parse_fadt(struct acpi_table_header *table)
764 {
765
766 #ifdef CONFIG_X86_PM_TIMER
767         /* detect the location of the ACPI PM Timer */
768         if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
769                 /* FADT rev. 2 */
770                 if (acpi_gbl_FADT.xpm_timer_block.space_id !=
771                     ACPI_ADR_SPACE_SYSTEM_IO)
772                         return 0;
773
774                 pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
775                 /*
776                  * "X" fields are optional extensions to the original V1.0
777                  * fields, so we must selectively expand V1.0 fields if the
778                  * corresponding X field is zero.
779                  */
780                 if (!pmtmr_ioport)
781                         pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
782         } else {
783                 /* FADT rev. 1 */
784                 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
785         }
786         if (pmtmr_ioport)
787                 printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
788                        pmtmr_ioport);
789 #endif
790         return 0;
791 }
792
793 #ifdef  CONFIG_X86_LOCAL_APIC
794 /*
795  * Parse LAPIC entries in MADT
796  * returns 0 on success, < 0 on error
797  */
798
799 static void __init acpi_register_lapic_address(unsigned long address)
800 {
801         mp_lapic_addr = address;
802
803         set_fixmap_nocache(FIX_APIC_BASE, address);
804         if (boot_cpu_physical_apicid == -1U) {
805                 boot_cpu_physical_apicid  = read_apic_id();
806                 apic_version[boot_cpu_physical_apicid] =
807                          GET_APIC_VERSION(apic_read(APIC_LVR));
808         }
809 }
810
811 static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
812 {
813         int count;
814
815         if (!cpu_has_apic)
816                 return -ENODEV;
817
818         /*
819          * Note that the LAPIC address is obtained from the MADT (32-bit value)
820          * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
821          */
822
823         count =
824             acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
825                                   acpi_parse_lapic_addr_ovr, 0);
826         if (count < 0) {
827                 printk(KERN_ERR PREFIX
828                        "Error parsing LAPIC address override entry\n");
829                 return count;
830         }
831
832         acpi_register_lapic_address(acpi_lapic_addr);
833
834         return count;
835 }
836
837 static int __init acpi_parse_madt_lapic_entries(void)
838 {
839         int count;
840         int x2count = 0;
841
842         if (!cpu_has_apic)
843                 return -ENODEV;
844
845         /*
846          * Note that the LAPIC address is obtained from the MADT (32-bit value)
847          * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
848          */
849
850         count =
851             acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
852                                   acpi_parse_lapic_addr_ovr, 0);
853         if (count < 0) {
854                 printk(KERN_ERR PREFIX
855                        "Error parsing LAPIC address override entry\n");
856                 return count;
857         }
858
859         acpi_register_lapic_address(acpi_lapic_addr);
860
861         count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
862                                       acpi_parse_sapic, MAX_APICS);
863
864         if (!count) {
865                 x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
866                                                 acpi_parse_x2apic, MAX_APICS);
867                 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
868                                               acpi_parse_lapic, MAX_APICS);
869         }
870         if (!count && !x2count) {
871                 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
872                 /* TBD: Cleanup to allow fallback to MPS */
873                 return -ENODEV;
874         } else if (count < 0 || x2count < 0) {
875                 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
876                 /* TBD: Cleanup to allow fallback to MPS */
877                 return count;
878         }
879
880         x2count =
881             acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI,
882                                   acpi_parse_x2apic_nmi, 0);
883         count =
884             acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0);
885         if (count < 0 || x2count < 0) {
886                 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
887                 /* TBD: Cleanup to allow fallback to MPS */
888                 return count;
889         }
890         return 0;
891 }
892 #endif                          /* CONFIG_X86_LOCAL_APIC */
893
894 #ifdef  CONFIG_X86_IO_APIC
895 #define MP_ISA_BUS              0
896
897 #ifdef CONFIG_X86_ES7000
898 extern int es7000_plat;
899 #endif
900
901 static struct {
902         int apic_id;
903         int gsi_base;
904         int gsi_end;
905         DECLARE_BITMAP(pin_programmed, MP_MAX_IOAPIC_PIN + 1);
906 } mp_ioapic_routing[MAX_IO_APICS];
907
908 int mp_find_ioapic(int gsi)
909 {
910         int i = 0;
911
912         /* Find the IOAPIC that manages this GSI. */
913         for (i = 0; i < nr_ioapics; i++) {
914                 if ((gsi >= mp_ioapic_routing[i].gsi_base)
915                     && (gsi <= mp_ioapic_routing[i].gsi_end))
916                         return i;
917         }
918
919         printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
920         return -1;
921 }
922
923 int mp_find_ioapic_pin(int ioapic, int gsi)
924 {
925         if (WARN_ON(ioapic == -1))
926                 return -1;
927         if (WARN_ON(gsi > mp_ioapic_routing[ioapic].gsi_end))
928                 return -1;
929
930         return gsi - mp_ioapic_routing[ioapic].gsi_base;
931 }
932
933 static u8 __init uniq_ioapic_id(u8 id)
934 {
935 #ifdef CONFIG_X86_32
936         if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
937             !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
938                 return io_apic_get_unique_id(nr_ioapics, id);
939         else
940                 return id;
941 #else
942         int i;
943         DECLARE_BITMAP(used, 256);
944         bitmap_zero(used, 256);
945         for (i = 0; i < nr_ioapics; i++) {
946                 struct mpc_ioapic *ia = &mp_ioapics[i];
947                 __set_bit(ia->apicid, used);
948         }
949         if (!test_bit(id, used))
950                 return id;
951         return find_first_zero_bit(used, 256);
952 #endif
953 }
954
955 static int bad_ioapic(unsigned long address)
956 {
957         if (nr_ioapics >= MAX_IO_APICS) {
958                 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
959                        "(found %d)\n", MAX_IO_APICS, nr_ioapics);
960                 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
961         }
962         if (!address) {
963                 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
964                        " found in table, skipping!\n");
965                 return 1;
966         }
967         return 0;
968 }
969
970 void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
971 {
972         int idx = 0;
973
974         if (bad_ioapic(address))
975                 return;
976
977         idx = nr_ioapics;
978
979         mp_ioapics[idx].type = MP_IOAPIC;
980         mp_ioapics[idx].flags = MPC_APIC_USABLE;
981         mp_ioapics[idx].apicaddr = address;
982
983         set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
984         mp_ioapics[idx].apicid = uniq_ioapic_id(id);
985 #ifdef CONFIG_X86_32
986         mp_ioapics[idx].apicver = io_apic_get_version(idx);
987 #else
988         mp_ioapics[idx].apicver = 0;
989 #endif
990         /*
991          * Build basic GSI lookup table to facilitate gsi->io_apic lookups
992          * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
993          */
994         mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].apicid;
995         mp_ioapic_routing[idx].gsi_base = gsi_base;
996         mp_ioapic_routing[idx].gsi_end = gsi_base +
997             io_apic_get_redir_entries(idx);
998
999         printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
1000                "GSI %d-%d\n", idx, mp_ioapics[idx].apicid,
1001                mp_ioapics[idx].apicver, mp_ioapics[idx].apicaddr,
1002                mp_ioapic_routing[idx].gsi_base, mp_ioapic_routing[idx].gsi_end);
1003
1004         nr_ioapics++;
1005 }
1006
1007 int __init acpi_probe_gsi(void)
1008 {
1009         int idx;
1010         int gsi;
1011         int max_gsi = 0;
1012
1013         if (acpi_disabled)
1014                 return 0;
1015
1016         if (!acpi_ioapic)
1017                 return 0;
1018
1019         max_gsi = 0;
1020         for (idx = 0; idx < nr_ioapics; idx++) {
1021                 gsi = mp_ioapic_routing[idx].gsi_end;
1022
1023                 if (gsi > max_gsi)
1024                         max_gsi = gsi;
1025         }
1026
1027         return max_gsi + 1;
1028 }
1029
1030 static void assign_to_mp_irq(struct mpc_intsrc *m,
1031                                     struct mpc_intsrc *mp_irq)
1032 {
1033         memcpy(mp_irq, m, sizeof(struct mpc_intsrc));
1034 }
1035
1036 static int mp_irq_cmp(struct mpc_intsrc *mp_irq,
1037                                 struct mpc_intsrc *m)
1038 {
1039         return memcmp(mp_irq, m, sizeof(struct mpc_intsrc));
1040 }
1041
1042 static void save_mp_irq(struct mpc_intsrc *m)
1043 {
1044         int i;
1045
1046         for (i = 0; i < mp_irq_entries; i++) {
1047                 if (!mp_irq_cmp(&mp_irqs[i], m))
1048                         return;
1049         }
1050
1051         assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
1052         if (++mp_irq_entries == MAX_IRQ_SOURCES)
1053                 panic("Max # of irq sources exceeded!!\n");
1054 }
1055
1056 void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
1057 {
1058         int ioapic;
1059         int pin;
1060         struct mpc_intsrc mp_irq;
1061
1062         /*
1063          * Convert 'gsi' to 'ioapic.pin'.
1064          */
1065         ioapic = mp_find_ioapic(gsi);
1066         if (ioapic < 0)
1067                 return;
1068         pin = mp_find_ioapic_pin(ioapic, gsi);
1069
1070         /*
1071          * TBD: This check is for faulty timer entries, where the override
1072          *      erroneously sets the trigger to level, resulting in a HUGE
1073          *      increase of timer interrupts!
1074          */
1075         if ((bus_irq == 0) && (trigger == 3))
1076                 trigger = 1;
1077
1078         mp_irq.type = MP_INTSRC;
1079         mp_irq.irqtype = mp_INT;
1080         mp_irq.irqflag = (trigger << 2) | polarity;
1081         mp_irq.srcbus = MP_ISA_BUS;
1082         mp_irq.srcbusirq = bus_irq;     /* IRQ */
1083         mp_irq.dstapic = mp_ioapics[ioapic].apicid; /* APIC ID */
1084         mp_irq.dstirq = pin;    /* INTIN# */
1085
1086         save_mp_irq(&mp_irq);
1087 }
1088
1089 void __init mp_config_acpi_legacy_irqs(void)
1090 {
1091         int i;
1092         int ioapic;
1093         unsigned int dstapic;
1094         struct mpc_intsrc mp_irq;
1095
1096 #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
1097         /*
1098          * Fabricate the legacy ISA bus (bus #31).
1099          */
1100         mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
1101 #endif
1102         set_bit(MP_ISA_BUS, mp_bus_not_pci);
1103         pr_debug("Bus #%d is ISA\n", MP_ISA_BUS);
1104
1105 #ifdef CONFIG_X86_ES7000
1106         /*
1107          * Older generations of ES7000 have no legacy identity mappings
1108          */
1109         if (es7000_plat == 1)
1110                 return;
1111 #endif
1112
1113         /*
1114          * Locate the IOAPIC that manages the ISA IRQs (0-15).
1115          */
1116         ioapic = mp_find_ioapic(0);
1117         if (ioapic < 0)
1118                 return;
1119         dstapic = mp_ioapics[ioapic].apicid;
1120
1121         /*
1122          * Use the default configuration for the IRQs 0-15.  Unless
1123          * overridden by (MADT) interrupt source override entries.
1124          */
1125         for (i = 0; i < 16; i++) {
1126                 int idx;
1127
1128                 for (idx = 0; idx < mp_irq_entries; idx++) {
1129                         struct mpc_intsrc *irq = mp_irqs + idx;
1130
1131                         /* Do we already have a mapping for this ISA IRQ? */
1132                         if (irq->srcbus == MP_ISA_BUS && irq->srcbusirq == i)
1133                                 break;
1134
1135                         /* Do we already have a mapping for this IOAPIC pin */
1136                         if (irq->dstapic == dstapic && irq->dstirq == i)
1137                                 break;
1138                 }
1139
1140                 if (idx != mp_irq_entries) {
1141                         printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
1142                         continue;       /* IRQ already used */
1143                 }
1144
1145                 mp_irq.type = MP_INTSRC;
1146                 mp_irq.irqflag = 0;     /* Conforming */
1147                 mp_irq.srcbus = MP_ISA_BUS;
1148                 mp_irq.dstapic = dstapic;
1149                 mp_irq.irqtype = mp_INT;
1150                 mp_irq.srcbusirq = i; /* Identity mapped */
1151                 mp_irq.dstirq = i;
1152
1153                 save_mp_irq(&mp_irq);
1154         }
1155 }
1156
1157 int mp_register_gsi(u32 gsi, int triggering, int polarity)
1158 {
1159         int ioapic;
1160         int ioapic_pin;
1161 #ifdef CONFIG_X86_32
1162 #define MAX_GSI_NUM     4096
1163 #define IRQ_COMPRESSION_START   64
1164
1165         static int pci_irq = IRQ_COMPRESSION_START;
1166         /*
1167          * Mapping between Global System Interrupts, which
1168          * represent all possible interrupts, and IRQs
1169          * assigned to actual devices.
1170          */
1171         static int gsi_to_irq[MAX_GSI_NUM];
1172 #else
1173
1174         if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
1175                 return gsi;
1176 #endif
1177
1178         /* Don't set up the ACPI SCI because it's already set up */
1179         if (acpi_gbl_FADT.sci_interrupt == gsi)
1180                 return gsi;
1181
1182         ioapic = mp_find_ioapic(gsi);
1183         if (ioapic < 0) {
1184                 printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
1185                 return gsi;
1186         }
1187
1188         ioapic_pin = mp_find_ioapic_pin(ioapic, gsi);
1189
1190 #ifdef CONFIG_X86_32
1191         if (ioapic_renumber_irq)
1192                 gsi = ioapic_renumber_irq(ioapic, gsi);
1193 #endif
1194
1195         /*
1196          * Avoid pin reprogramming.  PRTs typically include entries
1197          * with redundant pin->gsi mappings (but unique PCI devices);
1198          * we only program the IOAPIC on the first.
1199          */
1200         if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
1201                 printk(KERN_ERR "Invalid reference to IOAPIC pin "
1202                        "%d-%d\n", mp_ioapic_routing[ioapic].apic_id,
1203                        ioapic_pin);
1204                 return gsi;
1205         }
1206         if (test_bit(ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed)) {
1207                 pr_debug("Pin %d-%d already programmed\n",
1208                          mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
1209 #ifdef CONFIG_X86_32
1210                 return (gsi < IRQ_COMPRESSION_START ? gsi : gsi_to_irq[gsi]);
1211 #else
1212                 return gsi;
1213 #endif
1214         }
1215
1216         set_bit(ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed);
1217 #ifdef CONFIG_X86_32
1218         /*
1219          * For GSI >= 64, use IRQ compression
1220          */
1221         if ((gsi >= IRQ_COMPRESSION_START)
1222             && (triggering == ACPI_LEVEL_SENSITIVE)) {
1223                 /*
1224                  * For PCI devices assign IRQs in order, avoiding gaps
1225                  * due to unused I/O APIC pins.
1226                  */
1227                 int irq = gsi;
1228                 if (gsi < MAX_GSI_NUM) {
1229                         /*
1230                          * Retain the VIA chipset work-around (gsi > 15), but
1231                          * avoid a problem where the 8254 timer (IRQ0) is setup
1232                          * via an override (so it's not on pin 0 of the ioapic),
1233                          * and at the same time, the pin 0 interrupt is a PCI
1234                          * type.  The gsi > 15 test could cause these two pins
1235                          * to be shared as IRQ0, and they are not shareable.
1236                          * So test for this condition, and if necessary, avoid
1237                          * the pin collision.
1238                          */
1239                         gsi = pci_irq++;
1240                         /*
1241                          * Don't assign IRQ used by ACPI SCI
1242                          */
1243                         if (gsi == acpi_gbl_FADT.sci_interrupt)
1244                                 gsi = pci_irq++;
1245                         gsi_to_irq[irq] = gsi;
1246                 } else {
1247                         printk(KERN_ERR "GSI %u is too high\n", gsi);
1248                         return gsi;
1249                 }
1250         }
1251 #endif
1252         io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
1253                                 triggering == ACPI_EDGE_SENSITIVE ? 0 : 1,
1254                                 polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
1255         return gsi;
1256 }
1257
1258 int mp_config_acpi_gsi(unsigned char number, unsigned int devfn, u8 pin,
1259                         u32 gsi, int triggering, int polarity)
1260 {
1261 #ifdef CONFIG_X86_MPPARSE
1262         struct mpc_intsrc mp_irq;
1263         int ioapic;
1264
1265         if (!acpi_ioapic)
1266                 return 0;
1267
1268         /* print the entry should happen on mptable identically */
1269         mp_irq.type = MP_INTSRC;
1270         mp_irq.irqtype = mp_INT;
1271         mp_irq.irqflag = (triggering == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
1272                                 (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
1273         mp_irq.srcbus = number;
1274         mp_irq.srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
1275         ioapic = mp_find_ioapic(gsi);
1276         mp_irq.dstapic = mp_ioapic_routing[ioapic].apic_id;
1277         mp_irq.dstirq = mp_find_ioapic_pin(ioapic, gsi);
1278
1279         save_mp_irq(&mp_irq);
1280 #endif
1281         return 0;
1282 }
1283
1284 /*
1285  * Parse IOAPIC related entries in MADT
1286  * returns 0 on success, < 0 on error
1287  */
1288 static int __init acpi_parse_madt_ioapic_entries(void)
1289 {
1290         int count;
1291
1292         /*
1293          * ACPI interpreter is required to complete interrupt setup,
1294          * so if it is off, don't enumerate the io-apics with ACPI.
1295          * If MPS is present, it will handle them,
1296          * otherwise the system will stay in PIC mode
1297          */
1298         if (acpi_disabled || acpi_noirq) {
1299                 return -ENODEV;
1300         }
1301
1302         if (!cpu_has_apic)
1303                 return -ENODEV;
1304
1305         /*
1306          * if "noapic" boot option, don't look for IO-APICs
1307          */
1308         if (skip_ioapic_setup) {
1309                 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
1310                        "due to 'noapic' option.\n");
1311                 return -ENODEV;
1312         }
1313
1314         count =
1315             acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
1316                                   MAX_IO_APICS);
1317         if (!count) {
1318                 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
1319                 return -ENODEV;
1320         } else if (count < 0) {
1321                 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
1322                 return count;
1323         }
1324
1325         count =
1326             acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr,
1327                                   nr_irqs);
1328         if (count < 0) {
1329                 printk(KERN_ERR PREFIX
1330                        "Error parsing interrupt source overrides entry\n");
1331                 /* TBD: Cleanup to allow fallback to MPS */
1332                 return count;
1333         }
1334
1335         /*
1336          * If BIOS did not supply an INT_SRC_OVR for the SCI
1337          * pretend we got one so we can set the SCI flags.
1338          */
1339         if (!acpi_sci_override_gsi)
1340                 acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0);
1341
1342         /* Fill in identity legacy mapings where no override */
1343         mp_config_acpi_legacy_irqs();
1344
1345         count =
1346             acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src,
1347                                   nr_irqs);
1348         if (count < 0) {
1349                 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
1350                 /* TBD: Cleanup to allow fallback to MPS */
1351                 return count;
1352         }
1353
1354         return 0;
1355 }
1356 #else
1357 static inline int acpi_parse_madt_ioapic_entries(void)
1358 {
1359         return -1;
1360 }
1361 #endif  /* !CONFIG_X86_IO_APIC */
1362
1363 static void __init early_acpi_process_madt(void)
1364 {
1365 #ifdef CONFIG_X86_LOCAL_APIC
1366         int error;
1367
1368         if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1369
1370                 /*
1371                  * Parse MADT LAPIC entries
1372                  */
1373                 error = early_acpi_parse_madt_lapic_addr_ovr();
1374                 if (!error) {
1375                         acpi_lapic = 1;
1376                         smp_found_config = 1;
1377                 }
1378                 if (error == -EINVAL) {
1379                         /*
1380                          * Dell Precision Workstation 410, 610 come here.
1381                          */
1382                         printk(KERN_ERR PREFIX
1383                                "Invalid BIOS MADT, disabling ACPI\n");
1384                         disable_acpi();
1385                 }
1386         }
1387 #endif
1388 }
1389
1390 static void __init acpi_process_madt(void)
1391 {
1392 #ifdef CONFIG_X86_LOCAL_APIC
1393         int error;
1394
1395         if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1396
1397                 /*
1398                  * Parse MADT LAPIC entries
1399                  */
1400                 error = acpi_parse_madt_lapic_entries();
1401                 if (!error) {
1402                         acpi_lapic = 1;
1403
1404 #ifdef CONFIG_X86_BIGSMP
1405                         generic_bigsmp_probe();
1406 #endif
1407                         /*
1408                          * Parse MADT IO-APIC entries
1409                          */
1410                         error = acpi_parse_madt_ioapic_entries();
1411                         if (!error) {
1412                                 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
1413                                 acpi_ioapic = 1;
1414
1415                                 smp_found_config = 1;
1416                                 if (apic->setup_apic_routing)
1417                                         apic->setup_apic_routing();
1418                         }
1419                 }
1420                 if (error == -EINVAL) {
1421                         /*
1422                          * Dell Precision Workstation 410, 610 come here.
1423                          */
1424                         printk(KERN_ERR PREFIX
1425                                "Invalid BIOS MADT, disabling ACPI\n");
1426                         disable_acpi();
1427                 }
1428         } else {
1429                 /*
1430                  * ACPI found no MADT, and so ACPI wants UP PIC mode.
1431                  * In the event an MPS table was found, forget it.
1432                  * Boot with "acpi=off" to use MPS on such a system.
1433                  */
1434                 if (smp_found_config) {
1435                         printk(KERN_WARNING PREFIX
1436                                 "No APIC-table, disabling MPS\n");
1437                         smp_found_config = 0;
1438                 }
1439         }
1440
1441         /*
1442          * ACPI supports both logical (e.g. Hyper-Threading) and physical
1443          * processors, where MPS only supports physical.
1444          */
1445         if (acpi_lapic && acpi_ioapic)
1446                 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
1447                        "information\n");
1448         else if (acpi_lapic)
1449                 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
1450                        "configuration information\n");
1451 #endif
1452         return;
1453 }
1454
1455 static int __init disable_acpi_irq(const struct dmi_system_id *d)
1456 {
1457         if (!acpi_force) {
1458                 printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
1459                        d->ident);
1460                 acpi_noirq_set();
1461         }
1462         return 0;
1463 }
1464
1465 static int __init disable_acpi_pci(const struct dmi_system_id *d)
1466 {
1467         if (!acpi_force) {
1468                 printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
1469                        d->ident);
1470                 acpi_disable_pci();
1471         }
1472         return 0;
1473 }
1474
1475 static int __init dmi_disable_acpi(const struct dmi_system_id *d)
1476 {
1477         if (!acpi_force) {
1478                 printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
1479                 disable_acpi();
1480         } else {
1481                 printk(KERN_NOTICE
1482                        "Warning: DMI blacklist says broken, but acpi forced\n");
1483         }
1484         return 0;
1485 }
1486
1487 /*
1488  * Limit ACPI to CPU enumeration for HT
1489  */
1490 static int __init force_acpi_ht(const struct dmi_system_id *d)
1491 {
1492         if (!acpi_force) {
1493                 printk(KERN_NOTICE "%s detected: force use of acpi=ht\n",
1494                        d->ident);
1495                 disable_acpi();
1496                 acpi_ht = 1;
1497         } else {
1498                 printk(KERN_NOTICE
1499                        "Warning: acpi=force overrules DMI blacklist: acpi=ht\n");
1500         }
1501         return 0;
1502 }
1503
1504 /*
1505  * Force ignoring BIOS IRQ0 pin2 override
1506  */
1507 static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
1508 {
1509         /*
1510          * The ati_ixp4x0_rev() early PCI quirk should have set
1511          * the acpi_skip_timer_override flag already:
1512          */
1513         if (!acpi_skip_timer_override) {
1514                 WARN(1, KERN_ERR "ati_ixp4x0 quirk not complete.\n");
1515                 pr_notice("%s detected: Ignoring BIOS IRQ0 pin2 override\n",
1516                         d->ident);
1517                 acpi_skip_timer_override = 1;
1518         }
1519         return 0;
1520 }
1521
1522 /*
1523  * If your system is blacklisted here, but you find that acpi=force
1524  * works for you, please contact linux-acpi@vger.kernel.org
1525  */
1526 static struct dmi_system_id __initdata acpi_dmi_table[] = {
1527         /*
1528          * Boxes that need ACPI disabled
1529          */
1530         {
1531          .callback = dmi_disable_acpi,
1532          .ident = "IBM Thinkpad",
1533          .matches = {
1534                      DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1535                      DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
1536                      },
1537          },
1538
1539         /*
1540          * Boxes that need acpi=ht
1541          */
1542         {
1543          .callback = force_acpi_ht,
1544          .ident = "FSC Primergy T850",
1545          .matches = {
1546                      DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
1547                      DMI_MATCH(DMI_PRODUCT_NAME, "PRIMERGY T850"),
1548                      },
1549          },
1550         {
1551          .callback = force_acpi_ht,
1552          .ident = "HP VISUALIZE NT Workstation",
1553          .matches = {
1554                      DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
1555                      DMI_MATCH(DMI_PRODUCT_NAME, "HP VISUALIZE NT Workstation"),
1556                      },
1557          },
1558         {
1559          .callback = force_acpi_ht,
1560          .ident = "Compaq Workstation W8000",
1561          .matches = {
1562                      DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
1563                      DMI_MATCH(DMI_PRODUCT_NAME, "Workstation W8000"),
1564                      },
1565          },
1566         {
1567          .callback = force_acpi_ht,
1568          .ident = "ASUS P4B266",
1569          .matches = {
1570                      DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1571                      DMI_MATCH(DMI_BOARD_NAME, "P4B266"),
1572                      },
1573          },
1574         {
1575          .callback = force_acpi_ht,
1576          .ident = "ASUS P2B-DS",
1577          .matches = {
1578                      DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1579                      DMI_MATCH(DMI_BOARD_NAME, "P2B-DS"),
1580                      },
1581          },
1582         {
1583          .callback = force_acpi_ht,
1584          .ident = "ASUS CUR-DLS",
1585          .matches = {
1586                      DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1587                      DMI_MATCH(DMI_BOARD_NAME, "CUR-DLS"),
1588                      },
1589          },
1590         {
1591          .callback = force_acpi_ht,
1592          .ident = "ABIT i440BX-W83977",
1593          .matches = {
1594                      DMI_MATCH(DMI_BOARD_VENDOR, "ABIT <http://www.abit.com>"),
1595                      DMI_MATCH(DMI_BOARD_NAME, "i440BX-W83977 (BP6)"),
1596                      },
1597          },
1598         {
1599          .callback = force_acpi_ht,
1600          .ident = "IBM Bladecenter",
1601          .matches = {
1602                      DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1603                      DMI_MATCH(DMI_BOARD_NAME, "IBM eServer BladeCenter HS20"),
1604                      },
1605          },
1606         {
1607          .callback = force_acpi_ht,
1608          .ident = "IBM eServer xSeries 360",
1609          .matches = {
1610                      DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1611                      DMI_MATCH(DMI_BOARD_NAME, "eServer xSeries 360"),
1612                      },
1613          },
1614         {
1615          .callback = force_acpi_ht,
1616          .ident = "IBM eserver xSeries 330",
1617          .matches = {
1618                      DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1619                      DMI_MATCH(DMI_BOARD_NAME, "eserver xSeries 330"),
1620                      },
1621          },
1622         {
1623          .callback = force_acpi_ht,
1624          .ident = "IBM eserver xSeries 440",
1625          .matches = {
1626                      DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1627                      DMI_MATCH(DMI_PRODUCT_NAME, "eserver xSeries 440"),
1628                      },
1629          },
1630
1631         /*
1632          * Boxes that need ACPI PCI IRQ routing disabled
1633          */
1634         {
1635          .callback = disable_acpi_irq,
1636          .ident = "ASUS A7V",
1637          .matches = {
1638                      DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
1639                      DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
1640                      /* newer BIOS, Revision 1011, does work */
1641                      DMI_MATCH(DMI_BIOS_VERSION,
1642                                "ASUS A7V ACPI BIOS Revision 1007"),
1643                      },
1644          },
1645         {
1646                 /*
1647                  * Latest BIOS for IBM 600E (1.16) has bad pcinum
1648                  * for LPC bridge, which is needed for the PCI
1649                  * interrupt links to work. DSDT fix is in bug 5966.
1650                  * 2645, 2646 model numbers are shared with 600/600E/600X
1651                  */
1652          .callback = disable_acpi_irq,
1653          .ident = "IBM Thinkpad 600 Series 2645",
1654          .matches = {
1655                      DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1656                      DMI_MATCH(DMI_BOARD_NAME, "2645"),
1657                      },
1658          },
1659         {
1660          .callback = disable_acpi_irq,
1661          .ident = "IBM Thinkpad 600 Series 2646",
1662          .matches = {
1663                      DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1664                      DMI_MATCH(DMI_BOARD_NAME, "2646"),
1665                      },
1666          },
1667         /*
1668          * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
1669          */
1670         {                       /* _BBN 0 bug */
1671          .callback = disable_acpi_pci,
1672          .ident = "ASUS PR-DLS",
1673          .matches = {
1674                      DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1675                      DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
1676                      DMI_MATCH(DMI_BIOS_VERSION,
1677                                "ASUS PR-DLS ACPI BIOS Revision 1010"),
1678                      DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
1679                      },
1680          },
1681         {
1682          .callback = disable_acpi_pci,
1683          .ident = "Acer TravelMate 36x Laptop",
1684          .matches = {
1685                      DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
1686                      DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
1687                      },
1688          },
1689         {}
1690 };
1691
1692 /* second table for DMI checks that should run after early-quirks */
1693 static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
1694         /*
1695          * HP laptops which use a DSDT reporting as HP/SB400/10000,
1696          * which includes some code which overrides all temperature
1697          * trip points to 16C if the INTIN2 input of the I/O APIC
1698          * is enabled.  This input is incorrectly designated the
1699          * ISA IRQ 0 via an interrupt source override even though
1700          * it is wired to the output of the master 8259A and INTIN0
1701          * is not connected at all.  Force ignoring BIOS IRQ0 pin2
1702          * override in that cases.
1703          */
1704         {
1705          .callback = dmi_ignore_irq0_timer_override,
1706          .ident = "HP nx6115 laptop",
1707          .matches = {
1708                      DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1709                      DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6115"),
1710                      },
1711          },
1712         {
1713          .callback = dmi_ignore_irq0_timer_override,
1714          .ident = "HP NX6125 laptop",
1715          .matches = {
1716                      DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1717                      DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
1718                      },
1719          },
1720         {
1721          .callback = dmi_ignore_irq0_timer_override,
1722          .ident = "HP NX6325 laptop",
1723          .matches = {
1724                      DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1725                      DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
1726                      },
1727          },
1728         {
1729          .callback = dmi_ignore_irq0_timer_override,
1730          .ident = "HP 6715b laptop",
1731          .matches = {
1732                      DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1733                      DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
1734                      },
1735          },
1736         {}
1737 };
1738
1739 /*
1740  * acpi_boot_table_init() and acpi_boot_init()
1741  *  called from setup_arch(), always.
1742  *      1. checksums all tables
1743  *      2. enumerates lapics
1744  *      3. enumerates io-apics
1745  *
1746  * acpi_table_init() is separate to allow reading SRAT without
1747  * other side effects.
1748  *
1749  * side effects of acpi_boot_init:
1750  *      acpi_lapic = 1 if LAPIC found
1751  *      acpi_ioapic = 1 if IOAPIC found
1752  *      if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
1753  *      if acpi_blacklisted() acpi_disabled = 1;
1754  *      acpi_irq_model=...
1755  *      ...
1756  *
1757  * return value: (currently ignored)
1758  *      0: success
1759  *      !0: failure
1760  */
1761
1762 int __init acpi_boot_table_init(void)
1763 {
1764         int error;
1765
1766         dmi_check_system(acpi_dmi_table);
1767
1768         /*
1769          * If acpi_disabled, bail out
1770          * One exception: acpi=ht continues far enough to enumerate LAPICs
1771          */
1772         if (acpi_disabled && !acpi_ht)
1773                 return 1;
1774
1775         /*
1776          * Initialize the ACPI boot-time table parser.
1777          */
1778         error = acpi_table_init();
1779         if (error) {
1780                 disable_acpi();
1781                 return error;
1782         }
1783
1784         acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
1785
1786         /*
1787          * blacklist may disable ACPI entirely
1788          */
1789         error = acpi_blacklisted();
1790         if (error) {
1791                 if (acpi_force) {
1792                         printk(KERN_WARNING PREFIX "acpi=force override\n");
1793                 } else {
1794                         printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
1795                         disable_acpi();
1796                         return error;
1797                 }
1798         }
1799
1800         return 0;
1801 }
1802
1803 int __init early_acpi_boot_init(void)
1804 {
1805         /*
1806          * If acpi_disabled, bail out
1807          * One exception: acpi=ht continues far enough to enumerate LAPICs
1808          */
1809         if (acpi_disabled && !acpi_ht)
1810                 return 1;
1811
1812         /*
1813          * Process the Multiple APIC Description Table (MADT), if present
1814          */
1815         early_acpi_process_madt();
1816
1817         return 0;
1818 }
1819
1820 int __init acpi_boot_init(void)
1821 {
1822         /* those are executed after early-quirks are executed */
1823         dmi_check_system(acpi_dmi_table_late);
1824
1825         /*
1826          * If acpi_disabled, bail out
1827          * One exception: acpi=ht continues far enough to enumerate LAPICs
1828          */
1829         if (acpi_disabled && !acpi_ht)
1830                 return 1;
1831
1832         acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
1833
1834         /*
1835          * set sci_int and PM timer address
1836          */
1837         acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
1838
1839         /*
1840          * Process the Multiple APIC Description Table (MADT), if present
1841          */
1842         acpi_process_madt();
1843
1844         acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
1845
1846         return 0;
1847 }
1848
1849 static int __init parse_acpi(char *arg)
1850 {
1851         if (!arg)
1852                 return -EINVAL;
1853
1854         /* "acpi=off" disables both ACPI table parsing and interpreter */
1855         if (strcmp(arg, "off") == 0) {
1856                 disable_acpi();
1857         }
1858         /* acpi=force to over-ride black-list */
1859         else if (strcmp(arg, "force") == 0) {
1860                 acpi_force = 1;
1861                 acpi_ht = 1;
1862                 acpi_disabled = 0;
1863         }
1864         /* acpi=strict disables out-of-spec workarounds */
1865         else if (strcmp(arg, "strict") == 0) {
1866                 acpi_strict = 1;
1867         }
1868         /* Limit ACPI just to boot-time to enable HT */
1869         else if (strcmp(arg, "ht") == 0) {
1870                 if (!acpi_force)
1871                         disable_acpi();
1872                 acpi_ht = 1;
1873         }
1874         /* acpi=rsdt use RSDT instead of XSDT */
1875         else if (strcmp(arg, "rsdt") == 0) {
1876                 acpi_rsdt_forced = 1;
1877         }
1878         /* "acpi=noirq" disables ACPI interrupt routing */
1879         else if (strcmp(arg, "noirq") == 0) {
1880                 acpi_noirq_set();
1881         } else {
1882                 /* Core will printk when we return error. */
1883                 return -EINVAL;
1884         }
1885         return 0;
1886 }
1887 early_param("acpi", parse_acpi);
1888
1889 /* FIXME: Using pci= for an ACPI parameter is a travesty. */
1890 static int __init parse_pci(char *arg)
1891 {
1892         if (arg && strcmp(arg, "noacpi") == 0)
1893                 acpi_disable_pci();
1894         return 0;
1895 }
1896 early_param("pci", parse_pci);
1897
1898 int __init acpi_mps_check(void)
1899 {
1900 #if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
1901 /* mptable code is not built-in*/
1902         if (acpi_disabled || acpi_noirq) {
1903                 printk(KERN_WARNING "MPS support code is not built-in.\n"
1904                        "Using acpi=off or acpi=noirq or pci=noacpi "
1905                        "may have problem\n");
1906                 return 1;
1907         }
1908 #endif
1909         return 0;
1910 }
1911
1912 #ifdef CONFIG_X86_IO_APIC
1913 static int __init parse_acpi_skip_timer_override(char *arg)
1914 {
1915         acpi_skip_timer_override = 1;
1916         return 0;
1917 }
1918 early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
1919
1920 static int __init parse_acpi_use_timer_override(char *arg)
1921 {
1922         acpi_use_timer_override = 1;
1923         return 0;
1924 }
1925 early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
1926 #endif /* CONFIG_X86_IO_APIC */
1927
1928 static int __init setup_acpi_sci(char *s)
1929 {
1930         if (!s)
1931                 return -EINVAL;
1932         if (!strcmp(s, "edge"))
1933                 acpi_sci_flags =  ACPI_MADT_TRIGGER_EDGE |
1934                         (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
1935         else if (!strcmp(s, "level"))
1936                 acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
1937                         (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
1938         else if (!strcmp(s, "high"))
1939                 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
1940                         (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
1941         else if (!strcmp(s, "low"))
1942                 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
1943                         (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
1944         else
1945                 return -EINVAL;
1946         return 0;
1947 }
1948 early_param("acpi_sci", setup_acpi_sci);
1949
1950 int __acpi_acquire_global_lock(unsigned int *lock)
1951 {
1952         unsigned int old, new, val;
1953         do {
1954                 old = *lock;
1955                 new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
1956                 val = cmpxchg(lock, old, new);
1957         } while (unlikely (val != old));
1958         return (new < 3) ? -1 : 0;
1959 }
1960
1961 int __acpi_release_global_lock(unsigned int *lock)
1962 {
1963         unsigned int old, new, val;
1964         do {
1965                 old = *lock;
1966                 new = old & ~0x3;
1967                 val = cmpxchg(lock, old, new);
1968         } while (unlikely (val != old));
1969         return old & 0x1;
1970 }