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

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

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

~ [ 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