~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/x86/kernel/acpi/boot.c

Version: ~ [ linux-5.4-rc7 ] ~ [ linux-5.3.10 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.83 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.153 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.200 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.200 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.76 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp