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