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