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