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