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