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