1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * boot.c - Architecture-Specific Low-Level ACPI Boot Support
8 #define pr_fmt(fmt) "ACPI: " fmt
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>
26 #include <asm/e820/api.h>
27 #include <asm/irqdomain.h>
28 #include <asm/pci_x86.h>
29 #include <asm/io_apic.h>
32 #include <asm/mpspec.h>
34 #include <asm/i8259.h>
35 #include <asm/setup.h>
37 #include "sleep.h" /* To include x86_acpi_suspend_lowlevel */
38 static int __initdata acpi_force = 0;
40 EXPORT_SYMBOL(acpi_disabled);
43 # include <asm/proto.h>
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);
54 int acpi_disable_cmcff;
55 bool acpi_int_src_ovr[NR_IRQS_LEGACY];
57 /* ACPI SCI override configuration */
58 u8 acpi_sci_flags __initdata;
59 u32 acpi_sci_override_gsi __initdata = INVALID_ACPI_IRQ;
60 int acpi_skip_timer_override __initdata;
61 int acpi_use_timer_override __initdata;
62 int acpi_fix_pin2_polarity __initdata;
64 #ifdef CONFIG_X86_LOCAL_APIC
65 static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
66 static bool has_lapic_cpus __initdata;
67 static bool acpi_support_online_capable;
71 /* Physical address of the Multiprocessor Wakeup Structure mailbox */
72 static u64 acpi_mp_wake_mailbox_paddr;
73 /* Virtual address of the Multiprocessor Wakeup Structure mailbox */
74 static struct acpi_madt_multiproc_wakeup_mailbox *acpi_mp_wake_mailbox;
77 #ifdef CONFIG_X86_IO_APIC
79 * Locks related to IOAPIC hotplug
81 * ->device_hotplug_lock
84 * Interrupt mapping side:
89 static DEFINE_MUTEX(acpi_ioapic_lock);
92 /* --------------------------------------------------------------------------
93 Boot-time Configuration
94 -------------------------------------------------------------------------- */
97 * The default interrupt routing model is PIC (8259). This gets
98 * overridden if IOAPICs are enumerated (below).
100 enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
104 * ISA irqs by default are the first 16 gsis but can be
105 * any gsi as specified by an interrupt source override.
107 static u32 isa_irq_to_gsi[NR_IRQS_LEGACY] __read_mostly = {
108 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
112 * This is just a simple wrapper around early_memremap(),
113 * with sanity checks for phys == 0 and size == 0.
115 void __init __iomem *__acpi_map_table(unsigned long phys, unsigned long size)
121 return early_memremap(phys, size);
124 void __init __acpi_unmap_table(void __iomem *map, unsigned long size)
129 early_memunmap(map, size);
132 #ifdef CONFIG_X86_LOCAL_APIC
133 static int __init acpi_parse_madt(struct acpi_table_header *table)
135 struct acpi_table_madt *madt = NULL;
137 if (!boot_cpu_has(X86_FEATURE_APIC))
140 madt = (struct acpi_table_madt *)table;
142 pr_warn("Unable to map MADT\n");
147 acpi_lapic_addr = (u64) madt->address;
149 pr_debug("Local APIC address 0x%08x\n", madt->address);
152 if (madt->flags & ACPI_MADT_PCAT_COMPAT)
153 legacy_pic_pcat_compat();
155 /* ACPI 6.3 and newer support the online capable bit. */
156 if (acpi_gbl_FADT.header.revision > 6 ||
157 (acpi_gbl_FADT.header.revision == 6 &&
158 acpi_gbl_FADT.minor_revision >= 3))
159 acpi_support_online_capable = true;
161 default_acpi_madt_oem_check(madt->header.oem_id,
162 madt->header.oem_table_id);
167 static bool __init acpi_is_processor_usable(u32 lapic_flags)
169 if (lapic_flags & ACPI_MADT_ENABLED)
172 if (!acpi_support_online_capable ||
173 (lapic_flags & ACPI_MADT_ONLINE_CAPABLE))
180 acpi_parse_x2apic(union acpi_subtable_headers *header, const unsigned long end)
182 struct acpi_madt_local_x2apic *processor = NULL;
183 #ifdef CONFIG_X86_X2APIC
188 processor = (struct acpi_madt_local_x2apic *)header;
190 if (BAD_MADT_ENTRY(processor, end))
193 acpi_table_print_madt_entry(&header->common);
195 #ifdef CONFIG_X86_X2APIC
196 apic_id = processor->local_apic_id;
197 enabled = processor->lapic_flags & ACPI_MADT_ENABLED;
199 /* Ignore invalid ID */
200 if (apic_id == 0xffffffff)
203 /* don't register processors that cannot be onlined */
204 if (!acpi_is_processor_usable(processor->lapic_flags))
208 * According to https://uefi.org/specs/ACPI/6.5/05_ACPI_Software_Programming_Model.html#processor-local-x2apic-structure
209 * when MADT provides both valid LAPIC and x2APIC entries, the APIC ID
210 * in x2APIC must be equal or greater than 0xff.
212 if (has_lapic_cpus && apic_id < 0xff)
216 * We need to register disabled CPU as well to permit
217 * counting disabled CPUs. This allows us to size
218 * cpus_possible_map more accurately, to permit
219 * to not preallocating memory for all NR_CPUS
220 * when we use CPU hotplug.
222 if (!apic_id_valid(apic_id)) {
224 pr_warn("x2apic entry ignored\n");
228 topology_register_apic(apic_id, processor->uid, enabled);
230 pr_warn("x2apic entry ignored\n");
237 acpi_parse_lapic(union acpi_subtable_headers * header, const unsigned long end)
239 struct acpi_madt_local_apic *processor = NULL;
241 processor = (struct acpi_madt_local_apic *)header;
243 if (BAD_MADT_ENTRY(processor, end))
246 acpi_table_print_madt_entry(&header->common);
248 /* Ignore invalid ID */
249 if (processor->id == 0xff)
252 /* don't register processors that can not be onlined */
253 if (!acpi_is_processor_usable(processor->lapic_flags))
257 * We need to register disabled CPU as well to permit
258 * counting disabled CPUs. This allows us to size
259 * cpus_possible_map more accurately, to permit
260 * to not preallocating memory for all NR_CPUS
261 * when we use CPU hotplug.
263 topology_register_apic(processor->id, /* APIC ID */
264 processor->processor_id, /* ACPI ID */
265 processor->lapic_flags & ACPI_MADT_ENABLED);
267 has_lapic_cpus = true;
272 acpi_parse_sapic(union acpi_subtable_headers *header, const unsigned long end)
274 struct acpi_madt_local_sapic *processor = NULL;
276 processor = (struct acpi_madt_local_sapic *)header;
278 if (BAD_MADT_ENTRY(processor, end))
281 acpi_table_print_madt_entry(&header->common);
283 topology_register_apic((processor->id << 8) | processor->eid,/* APIC ID */
284 processor->processor_id, /* ACPI ID */
285 processor->lapic_flags & ACPI_MADT_ENABLED);
291 acpi_parse_lapic_addr_ovr(union acpi_subtable_headers * header,
292 const unsigned long end)
294 struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
296 lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
298 if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
301 acpi_table_print_madt_entry(&header->common);
303 acpi_lapic_addr = lapic_addr_ovr->address;
309 acpi_parse_x2apic_nmi(union acpi_subtable_headers *header,
310 const unsigned long end)
312 struct acpi_madt_local_x2apic_nmi *x2apic_nmi = NULL;
314 x2apic_nmi = (struct acpi_madt_local_x2apic_nmi *)header;
316 if (BAD_MADT_ENTRY(x2apic_nmi, end))
319 acpi_table_print_madt_entry(&header->common);
321 if (x2apic_nmi->lint != 1)
322 pr_warn("NMI not connected to LINT 1!\n");
328 acpi_parse_lapic_nmi(union acpi_subtable_headers * header, const unsigned long end)
330 struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
332 lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
334 if (BAD_MADT_ENTRY(lapic_nmi, end))
337 acpi_table_print_madt_entry(&header->common);
339 if (lapic_nmi->lint != 1)
340 pr_warn("NMI not connected to LINT 1!\n");
346 static int acpi_wakeup_cpu(u32 apicid, unsigned long start_ip)
349 * Remap mailbox memory only for the first call to acpi_wakeup_cpu().
351 * Wakeup of secondary CPUs is fully serialized in the core code.
352 * No need to protect acpi_mp_wake_mailbox from concurrent accesses.
354 if (!acpi_mp_wake_mailbox) {
355 acpi_mp_wake_mailbox = memremap(acpi_mp_wake_mailbox_paddr,
356 sizeof(*acpi_mp_wake_mailbox),
361 * Mailbox memory is shared between the firmware and OS. Firmware will
362 * listen on mailbox command address, and once it receives the wakeup
363 * command, the CPU associated with the given apicid will be booted.
365 * The value of 'apic_id' and 'wakeup_vector' must be visible to the
366 * firmware before the wakeup command is visible. smp_store_release()
367 * ensures ordering and visibility.
369 acpi_mp_wake_mailbox->apic_id = apicid;
370 acpi_mp_wake_mailbox->wakeup_vector = start_ip;
371 smp_store_release(&acpi_mp_wake_mailbox->command,
372 ACPI_MP_WAKE_COMMAND_WAKEUP);
375 * Wait for the CPU to wake up.
377 * The CPU being woken up is essentially in a spin loop waiting to be
378 * woken up. It should not take long for it wake up and acknowledge by
379 * zeroing out ->command.
381 * ACPI specification doesn't provide any guidance on how long kernel
382 * has to wait for a wake up acknowledgement. It also doesn't provide
383 * a way to cancel a wake up request if it takes too long.
385 * In TDX environment, the VMM has control over how long it takes to
386 * wake up secondary. It can postpone scheduling secondary vCPU
387 * indefinitely. Giving up on wake up request and reporting error opens
388 * possible attack vector for VMM: it can wake up a secondary CPU when
389 * kernel doesn't expect it. Wait until positive result of the wake up
392 while (READ_ONCE(acpi_mp_wake_mailbox->command))
397 #endif /* CONFIG_X86_64 */
398 #endif /* CONFIG_X86_LOCAL_APIC */
400 #ifdef CONFIG_X86_IO_APIC
403 static int __init mp_register_ioapic_irq(u8 bus_irq, u8 polarity,
404 u8 trigger, u32 gsi);
406 static void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger,
410 * Check bus_irq boundary.
412 if (bus_irq >= NR_IRQS_LEGACY) {
413 pr_warn("Invalid bus_irq %u for legacy override\n", bus_irq);
418 * TBD: This check is for faulty timer entries, where the override
419 * erroneously sets the trigger to level, resulting in a HUGE
420 * increase of timer interrupts!
422 if ((bus_irq == 0) && (trigger == 3))
425 if (mp_register_ioapic_irq(bus_irq, polarity, trigger, gsi) < 0)
428 * Reset default identity mapping if gsi is also an legacy IRQ,
429 * otherwise there will be more than one entry with the same GSI
430 * and acpi_isa_irq_to_gsi() may give wrong result.
432 if (gsi < nr_legacy_irqs() && isa_irq_to_gsi[gsi] == gsi)
433 isa_irq_to_gsi[gsi] = INVALID_ACPI_IRQ;
434 isa_irq_to_gsi[bus_irq] = gsi;
437 static void mp_config_acpi_gsi(struct device *dev, u32 gsi, int trigger,
440 #ifdef CONFIG_X86_MPPARSE
441 struct mpc_intsrc mp_irq;
442 struct pci_dev *pdev;
443 unsigned char number;
450 if (!dev || !dev_is_pci(dev))
453 pdev = to_pci_dev(dev);
454 number = pdev->bus->number;
457 /* print the entry should happen on mptable identically */
458 mp_irq.type = MP_INTSRC;
459 mp_irq.irqtype = mp_INT;
460 mp_irq.irqflag = (trigger == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
461 (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
462 mp_irq.srcbus = number;
463 mp_irq.srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
464 ioapic = mp_find_ioapic(gsi);
465 mp_irq.dstapic = mpc_ioapic_id(ioapic);
466 mp_irq.dstirq = mp_find_ioapic_pin(ioapic, gsi);
468 mp_save_irq(&mp_irq);
472 static int __init mp_register_ioapic_irq(u8 bus_irq, u8 polarity,
475 struct mpc_intsrc mp_irq;
478 /* Convert 'gsi' to 'ioapic.pin'(INTIN#) */
479 ioapic = mp_find_ioapic(gsi);
481 pr_warn("Failed to find ioapic for gsi : %u\n", gsi);
485 pin = mp_find_ioapic_pin(ioapic, gsi);
487 mp_irq.type = MP_INTSRC;
488 mp_irq.irqtype = mp_INT;
489 mp_irq.irqflag = (trigger << 2) | polarity;
490 mp_irq.srcbus = MP_ISA_BUS;
491 mp_irq.srcbusirq = bus_irq;
492 mp_irq.dstapic = mpc_ioapic_id(ioapic);
495 mp_save_irq(&mp_irq);
501 acpi_parse_ioapic(union acpi_subtable_headers * header, const unsigned long end)
503 struct acpi_madt_io_apic *ioapic = NULL;
504 struct ioapic_domain_cfg cfg = {
505 .type = IOAPIC_DOMAIN_DYNAMIC,
506 .ops = &mp_ioapic_irqdomain_ops,
509 ioapic = (struct acpi_madt_io_apic *)header;
511 if (BAD_MADT_ENTRY(ioapic, end))
514 acpi_table_print_madt_entry(&header->common);
516 /* Statically assign IRQ numbers for IOAPICs hosting legacy IRQs */
517 if (ioapic->global_irq_base < nr_legacy_irqs())
518 cfg.type = IOAPIC_DOMAIN_LEGACY;
520 mp_register_ioapic(ioapic->id, ioapic->address, ioapic->global_irq_base,
527 * Parse Interrupt Source Override for the ACPI SCI
529 static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger, u32 gsi)
531 if (trigger == 0) /* compatible SCI trigger is level */
534 if (polarity == 0) /* compatible SCI polarity is low */
537 /* Command-line over-ride via acpi_sci= */
538 if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
539 trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
541 if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
542 polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
544 if (bus_irq < NR_IRQS_LEGACY)
545 mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
547 mp_register_ioapic_irq(bus_irq, polarity, trigger, gsi);
549 acpi_penalize_sci_irq(bus_irq, trigger, polarity);
552 * stash over-ride to indicate we've been here
553 * and for later update of acpi_gbl_FADT
555 acpi_sci_override_gsi = gsi;
560 acpi_parse_int_src_ovr(union acpi_subtable_headers * header,
561 const unsigned long end)
563 struct acpi_madt_interrupt_override *intsrc = NULL;
565 intsrc = (struct acpi_madt_interrupt_override *)header;
567 if (BAD_MADT_ENTRY(intsrc, end))
570 acpi_table_print_madt_entry(&header->common);
572 if (intsrc->source_irq < NR_IRQS_LEGACY)
573 acpi_int_src_ovr[intsrc->source_irq] = true;
575 if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
576 acpi_sci_ioapic_setup(intsrc->source_irq,
577 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
578 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
583 if (intsrc->source_irq == 0) {
584 if (acpi_skip_timer_override) {
585 pr_warn("BIOS IRQ0 override ignored.\n");
589 if ((intsrc->global_irq == 2) && acpi_fix_pin2_polarity
590 && (intsrc->inti_flags & ACPI_MADT_POLARITY_MASK)) {
591 intsrc->inti_flags &= ~ACPI_MADT_POLARITY_MASK;
592 pr_warn("BIOS IRQ0 pin2 override: forcing polarity to high active.\n");
596 mp_override_legacy_irq(intsrc->source_irq,
597 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
598 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
605 acpi_parse_nmi_src(union acpi_subtable_headers * header, const unsigned long end)
607 struct acpi_madt_nmi_source *nmi_src = NULL;
609 nmi_src = (struct acpi_madt_nmi_source *)header;
611 if (BAD_MADT_ENTRY(nmi_src, end))
614 acpi_table_print_madt_entry(&header->common);
616 /* TBD: Support nimsrc entries? */
621 #endif /* CONFIG_X86_IO_APIC */
624 * acpi_pic_sci_set_trigger()
626 * use ELCR to set PIC-mode trigger type for SCI
628 * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
629 * it may require Edge Trigger -- use "acpi_sci=edge"
631 * Port 0x4d0-4d1 are ELCR1 and ELCR2, the Edge/Level Control Registers
632 * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
633 * ELCR1 is IRQs 0-7 (IRQ 0, 1, 2 must be 0)
634 * ELCR2 is IRQs 8-15 (IRQ 8, 13 must be 0)
637 void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
639 unsigned int mask = 1 << irq;
640 unsigned int old, new;
642 /* Real old ELCR mask */
643 old = inb(PIC_ELCR1) | (inb(PIC_ELCR2) << 8);
646 * If we use ACPI to set PCI IRQs, then we should clear ELCR
647 * since we will set it correctly as we enable the PCI irq
650 new = acpi_noirq ? old : 0;
653 * Update SCI information in the ELCR, it isn't in the PCI
657 case 1: /* Edge - clear */
660 case 3: /* Level - set */
668 pr_warn("setting ELCR to %04x (from %04x)\n", new, old);
669 outb(new, PIC_ELCR1);
670 outb(new >> 8, PIC_ELCR2);
673 int acpi_gsi_to_irq(u32 gsi, unsigned int *irqp)
675 int rc, irq, trigger, polarity;
677 if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
682 rc = acpi_get_override_irq(gsi, &trigger, &polarity);
686 trigger = trigger ? ACPI_LEVEL_SENSITIVE : ACPI_EDGE_SENSITIVE;
687 polarity = polarity ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH;
688 irq = acpi_register_gsi(NULL, gsi, trigger, polarity);
695 EXPORT_SYMBOL_GPL(acpi_gsi_to_irq);
697 int acpi_isa_irq_to_gsi(unsigned isa_irq, u32 *gsi)
699 if (isa_irq < nr_legacy_irqs() &&
700 isa_irq_to_gsi[isa_irq] != INVALID_ACPI_IRQ) {
701 *gsi = isa_irq_to_gsi[isa_irq];
708 static int acpi_register_gsi_pic(struct device *dev, u32 gsi,
709 int trigger, int polarity)
713 * Make sure all (legacy) PCI IRQs are set as level-triggered.
715 if (trigger == ACPI_LEVEL_SENSITIVE)
716 elcr_set_level_irq(gsi);
722 #ifdef CONFIG_X86_LOCAL_APIC
723 static int acpi_register_gsi_ioapic(struct device *dev, u32 gsi,
724 int trigger, int polarity)
727 #ifdef CONFIG_X86_IO_APIC
729 struct irq_alloc_info info;
731 node = dev ? dev_to_node(dev) : NUMA_NO_NODE;
732 trigger = trigger == ACPI_EDGE_SENSITIVE ? 0 : 1;
733 polarity = polarity == ACPI_ACTIVE_HIGH ? 0 : 1;
734 ioapic_set_alloc_attr(&info, node, trigger, polarity);
736 mutex_lock(&acpi_ioapic_lock);
737 irq = mp_map_gsi_to_irq(gsi, IOAPIC_MAP_ALLOC, &info);
738 /* Don't set up the ACPI SCI because it's already set up */
739 if (irq >= 0 && enable_update_mptable && gsi != acpi_gbl_FADT.sci_interrupt)
740 mp_config_acpi_gsi(dev, gsi, trigger, polarity);
741 mutex_unlock(&acpi_ioapic_lock);
747 static void acpi_unregister_gsi_ioapic(u32 gsi)
749 #ifdef CONFIG_X86_IO_APIC
752 mutex_lock(&acpi_ioapic_lock);
753 irq = mp_map_gsi_to_irq(gsi, 0, NULL);
756 mutex_unlock(&acpi_ioapic_lock);
761 int (*__acpi_register_gsi)(struct device *dev, u32 gsi,
762 int trigger, int polarity) = acpi_register_gsi_pic;
763 void (*__acpi_unregister_gsi)(u32 gsi) = NULL;
765 #ifdef CONFIG_ACPI_SLEEP
766 int (*acpi_suspend_lowlevel)(void) = x86_acpi_suspend_lowlevel;
768 int (*acpi_suspend_lowlevel)(void);
772 * success: return IRQ number (>=0)
773 * failure: return < 0
775 int acpi_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
777 return __acpi_register_gsi(dev, gsi, trigger, polarity);
779 EXPORT_SYMBOL_GPL(acpi_register_gsi);
781 void acpi_unregister_gsi(u32 gsi)
783 if (__acpi_unregister_gsi)
784 __acpi_unregister_gsi(gsi);
786 EXPORT_SYMBOL_GPL(acpi_unregister_gsi);
788 #ifdef CONFIG_X86_LOCAL_APIC
789 static void __init acpi_set_irq_model_ioapic(void)
791 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
792 __acpi_register_gsi = acpi_register_gsi_ioapic;
793 __acpi_unregister_gsi = acpi_unregister_gsi_ioapic;
799 * ACPI based hotplug support for CPU
801 #ifdef CONFIG_ACPI_HOTPLUG_CPU
802 #include <acpi/processor.h>
804 static int acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
806 #ifdef CONFIG_ACPI_NUMA
809 nid = acpi_get_node(handle);
810 if (nid != NUMA_NO_NODE) {
811 set_apicid_to_node(physid, nid);
812 numa_set_node(cpu, nid);
818 int acpi_map_cpu(acpi_handle handle, phys_cpuid_t physid, u32 acpi_id, int *pcpu)
820 int cpu = topology_hotplug_apic(physid, acpi_id);
823 pr_info("Unable to map lapic to logical cpu number\n");
827 acpi_processor_set_pdc(handle);
828 acpi_map_cpu2node(handle, cpu, physid);
833 EXPORT_SYMBOL(acpi_map_cpu);
835 int acpi_unmap_cpu(int cpu)
837 #ifdef CONFIG_ACPI_NUMA
838 set_apicid_to_node(per_cpu(x86_cpu_to_apicid, cpu), NUMA_NO_NODE);
840 topology_hotunplug_apic(cpu);
843 EXPORT_SYMBOL(acpi_unmap_cpu);
844 #endif /* CONFIG_ACPI_HOTPLUG_CPU */
846 int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
849 #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
852 struct ioapic_domain_cfg cfg = {
853 .type = IOAPIC_DOMAIN_DYNAMIC,
854 .ops = &mp_ioapic_irqdomain_ops,
857 ioapic_id = acpi_get_ioapic_id(handle, gsi_base, &addr);
859 unsigned long long uid;
862 status = acpi_evaluate_integer(handle, METHOD_NAME__UID,
864 if (ACPI_FAILURE(status)) {
865 acpi_handle_warn(handle, "failed to get IOAPIC ID.\n");
868 ioapic_id = (int)uid;
871 mutex_lock(&acpi_ioapic_lock);
872 ret = mp_register_ioapic(ioapic_id, phys_addr, gsi_base, &cfg);
873 mutex_unlock(&acpi_ioapic_lock);
878 EXPORT_SYMBOL(acpi_register_ioapic);
880 int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
884 #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
885 mutex_lock(&acpi_ioapic_lock);
886 ret = mp_unregister_ioapic(gsi_base);
887 mutex_unlock(&acpi_ioapic_lock);
892 EXPORT_SYMBOL(acpi_unregister_ioapic);
895 * acpi_ioapic_registered - Check whether IOAPIC associated with @gsi_base
896 * has been registered
897 * @handle: ACPI handle of the IOAPIC device
898 * @gsi_base: GSI base associated with the IOAPIC
900 * Assume caller holds some type of lock to serialize acpi_ioapic_registered()
901 * with acpi_register_ioapic()/acpi_unregister_ioapic().
903 int acpi_ioapic_registered(acpi_handle handle, u32 gsi_base)
907 #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
908 mutex_lock(&acpi_ioapic_lock);
909 ret = mp_ioapic_registered(gsi_base);
910 mutex_unlock(&acpi_ioapic_lock);
916 static int __init acpi_parse_sbf(struct acpi_table_header *table)
918 struct acpi_table_boot *sb = (struct acpi_table_boot *)table;
920 sbf_port = sb->cmos_index; /* Save CMOS port */
925 #ifdef CONFIG_HPET_TIMER
926 #include <asm/hpet.h>
928 static struct resource *hpet_res __initdata;
930 static int __init acpi_parse_hpet(struct acpi_table_header *table)
932 struct acpi_table_hpet *hpet_tbl = (struct acpi_table_hpet *)table;
934 if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
935 pr_warn("HPET timers must be located in memory.\n");
939 hpet_address = hpet_tbl->address.address;
940 hpet_blockid = hpet_tbl->sequence;
943 * Some broken BIOSes advertise HPET at 0x0. We really do not
944 * want to allocate a resource there.
947 pr_warn("HPET id: %#x base: %#lx is invalid\n", hpet_tbl->id, hpet_address);
952 * Some even more broken BIOSes advertise HPET at
953 * 0xfed0000000000000 instead of 0xfed00000. Fix it up and add
956 if (hpet_address == 0xfed0000000000000UL) {
957 if (!hpet_force_user) {
958 pr_warn("HPET id: %#x base: 0xfed0000000000000 is bogus, try hpet=force on the kernel command line to fix it up to 0xfed00000.\n",
963 pr_warn("HPET id: %#x base: 0xfed0000000000000 fixed up to 0xfed00000.\n",
968 pr_info("HPET id: %#x base: %#lx\n", hpet_tbl->id, hpet_address);
971 * Allocate and initialize the HPET firmware resource for adding into
972 * the resource tree during the lateinit timeframe.
974 #define HPET_RESOURCE_NAME_SIZE 9
975 hpet_res = memblock_alloc(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE,
978 panic("%s: Failed to allocate %zu bytes\n", __func__,
979 sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
981 hpet_res->name = (void *)&hpet_res[1];
982 hpet_res->flags = IORESOURCE_MEM;
983 snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE, "HPET %u",
986 hpet_res->start = hpet_address;
987 hpet_res->end = hpet_address + (1 * 1024) - 1;
993 * hpet_insert_resource inserts the HPET resources used into the resource
996 static __init int hpet_insert_resource(void)
1001 return insert_resource(&iomem_resource, hpet_res);
1004 late_initcall(hpet_insert_resource);
1007 #define acpi_parse_hpet NULL
1010 static int __init acpi_parse_fadt(struct acpi_table_header *table)
1012 if (!(acpi_gbl_FADT.boot_flags & ACPI_FADT_LEGACY_DEVICES)) {
1013 pr_debug("no legacy devices present\n");
1014 x86_platform.legacy.devices.pnpbios = 0;
1017 if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID &&
1018 !(acpi_gbl_FADT.boot_flags & ACPI_FADT_8042) &&
1019 x86_platform.legacy.i8042 != X86_LEGACY_I8042_PLATFORM_ABSENT) {
1020 pr_debug("i8042 controller is absent\n");
1021 x86_platform.legacy.i8042 = X86_LEGACY_I8042_FIRMWARE_ABSENT;
1024 if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_CMOS_RTC) {
1025 pr_debug("not registering RTC platform device\n");
1026 x86_platform.legacy.rtc = 0;
1029 if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_VGA) {
1030 pr_debug("probing for VGA not safe\n");
1031 x86_platform.legacy.no_vga = 1;
1034 #ifdef CONFIG_X86_PM_TIMER
1035 /* detect the location of the ACPI PM Timer */
1036 if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
1038 if (acpi_gbl_FADT.xpm_timer_block.space_id !=
1039 ACPI_ADR_SPACE_SYSTEM_IO)
1042 pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
1044 * "X" fields are optional extensions to the original V1.0
1045 * fields, so we must selectively expand V1.0 fields if the
1046 * corresponding X field is zero.
1049 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
1052 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
1055 pr_info("PM-Timer IO Port: %#x\n", pmtmr_ioport);
1060 #ifdef CONFIG_X86_LOCAL_APIC
1062 * Parse LAPIC entries in MADT
1063 * returns 0 on success, < 0 on error
1066 static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
1070 if (!boot_cpu_has(X86_FEATURE_APIC))
1074 * Note that the LAPIC address is obtained from the MADT (32-bit value)
1075 * and (optionally) overridden by a LAPIC_ADDR_OVR entry (64-bit value).
1078 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
1079 acpi_parse_lapic_addr_ovr, 0);
1081 pr_err("Error parsing LAPIC address override entry\n");
1085 register_lapic_address(acpi_lapic_addr);
1090 static int __init acpi_parse_madt_lapic_entries(void)
1092 int count, x2count = 0;
1094 if (!boot_cpu_has(X86_FEATURE_APIC))
1097 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
1098 acpi_parse_sapic, MAX_LOCAL_APIC);
1101 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
1102 acpi_parse_lapic, MAX_LOCAL_APIC);
1103 x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
1104 acpi_parse_x2apic, MAX_LOCAL_APIC);
1106 if (!count && !x2count) {
1107 pr_err("No LAPIC entries present\n");
1108 /* TBD: Cleanup to allow fallback to MPS */
1110 } else if (count < 0 || x2count < 0) {
1111 pr_err("Error parsing LAPIC entry\n");
1112 /* TBD: Cleanup to allow fallback to MPS */
1116 x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI,
1117 acpi_parse_x2apic_nmi, 0);
1118 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI,
1119 acpi_parse_lapic_nmi, 0);
1120 if (count < 0 || x2count < 0) {
1121 pr_err("Error parsing LAPIC NMI entry\n");
1122 /* TBD: Cleanup to allow fallback to MPS */
1128 #ifdef CONFIG_X86_64
1129 static int __init acpi_parse_mp_wake(union acpi_subtable_headers *header,
1130 const unsigned long end)
1132 struct acpi_madt_multiproc_wakeup *mp_wake;
1134 if (!IS_ENABLED(CONFIG_SMP))
1137 mp_wake = (struct acpi_madt_multiproc_wakeup *)header;
1138 if (BAD_MADT_ENTRY(mp_wake, end))
1141 acpi_table_print_madt_entry(&header->common);
1143 acpi_mp_wake_mailbox_paddr = mp_wake->base_address;
1145 apic_update_callback(wakeup_secondary_cpu_64, acpi_wakeup_cpu);
1149 #endif /* CONFIG_X86_64 */
1150 #endif /* CONFIG_X86_LOCAL_APIC */
1152 #ifdef CONFIG_X86_IO_APIC
1153 static void __init mp_config_acpi_legacy_irqs(void)
1156 struct mpc_intsrc mp_irq;
1160 * Fabricate the legacy ISA bus (bus #31).
1162 mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
1164 set_bit(MP_ISA_BUS, mp_bus_not_pci);
1165 pr_debug("Bus #%d is ISA (nIRQs: %d)\n", MP_ISA_BUS, nr_legacy_irqs());
1168 * Use the default configuration for the IRQs 0-15. Unless
1169 * overridden by (MADT) interrupt source override entries.
1171 for (i = 0; i < nr_legacy_irqs(); i++) {
1173 unsigned int dstapic;
1177 /* Locate the gsi that irq i maps to. */
1178 if (acpi_isa_irq_to_gsi(i, &gsi))
1182 * Locate the IOAPIC that manages the ISA IRQ.
1184 ioapic = mp_find_ioapic(gsi);
1187 pin = mp_find_ioapic_pin(ioapic, gsi);
1188 dstapic = mpc_ioapic_id(ioapic);
1190 for (idx = 0; idx < mp_irq_entries; idx++) {
1191 struct mpc_intsrc *irq = mp_irqs + idx;
1193 /* Do we already have a mapping for this ISA IRQ? */
1194 if (irq->srcbus == MP_ISA_BUS && irq->srcbusirq == i)
1197 /* Do we already have a mapping for this IOAPIC pin */
1198 if (irq->dstapic == dstapic && irq->dstirq == pin)
1202 if (idx != mp_irq_entries) {
1203 pr_debug("ACPI: IRQ%d used by override.\n", i);
1204 continue; /* IRQ already used */
1207 mp_irq.type = MP_INTSRC;
1208 mp_irq.irqflag = 0; /* Conforming */
1209 mp_irq.srcbus = MP_ISA_BUS;
1210 mp_irq.dstapic = dstapic;
1211 mp_irq.irqtype = mp_INT;
1212 mp_irq.srcbusirq = i; /* Identity mapped */
1213 mp_irq.dstirq = pin;
1215 mp_save_irq(&mp_irq);
1220 * Parse IOAPIC related entries in MADT
1221 * returns 0 on success, < 0 on error
1223 static int __init acpi_parse_madt_ioapic_entries(void)
1228 * ACPI interpreter is required to complete interrupt setup,
1229 * so if it is off, don't enumerate the io-apics with ACPI.
1230 * If MPS is present, it will handle them,
1231 * otherwise the system will stay in PIC mode
1233 if (acpi_disabled || acpi_noirq)
1236 if (!boot_cpu_has(X86_FEATURE_APIC))
1240 * if "noapic" boot option, don't look for IO-APICs
1242 if (ioapic_is_disabled) {
1243 pr_info("Skipping IOAPIC probe due to 'noapic' option.\n");
1247 count = acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
1250 pr_err("No IOAPIC entries present\n");
1252 } else if (count < 0) {
1253 pr_err("Error parsing IOAPIC entry\n");
1257 count = acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE,
1258 acpi_parse_int_src_ovr, nr_irqs);
1260 pr_err("Error parsing interrupt source overrides entry\n");
1261 /* TBD: Cleanup to allow fallback to MPS */
1266 * If BIOS did not supply an INT_SRC_OVR for the SCI
1267 * pretend we got one so we can set the SCI flags.
1268 * But ignore setting up SCI on hardware reduced platforms.
1270 if (acpi_sci_override_gsi == INVALID_ACPI_IRQ && !acpi_gbl_reduced_hardware)
1271 acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0,
1272 acpi_gbl_FADT.sci_interrupt);
1274 /* Fill in identity legacy mappings where no override */
1275 mp_config_acpi_legacy_irqs();
1277 count = acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE,
1278 acpi_parse_nmi_src, nr_irqs);
1280 pr_err("Error parsing NMI SRC entry\n");
1281 /* TBD: Cleanup to allow fallback to MPS */
1288 static inline int acpi_parse_madt_ioapic_entries(void)
1292 #endif /* !CONFIG_X86_IO_APIC */
1294 static void __init early_acpi_process_madt(void)
1296 #ifdef CONFIG_X86_LOCAL_APIC
1299 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1302 * Parse MADT LAPIC entries
1304 error = early_acpi_parse_madt_lapic_addr_ovr();
1307 smp_found_config = 1;
1309 if (error == -EINVAL) {
1311 * Dell Precision Workstation 410, 610 come here.
1313 pr_err("Invalid BIOS MADT, disabling ACPI\n");
1320 static void __init acpi_process_madt(void)
1322 #ifdef CONFIG_X86_LOCAL_APIC
1325 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1328 * Parse MADT LAPIC entries
1330 error = acpi_parse_madt_lapic_entries();
1335 * Parse MADT IO-APIC entries
1337 mutex_lock(&acpi_ioapic_lock);
1338 error = acpi_parse_madt_ioapic_entries();
1339 mutex_unlock(&acpi_ioapic_lock);
1341 acpi_set_irq_model_ioapic();
1343 smp_found_config = 1;
1346 #ifdef CONFIG_X86_64
1348 * Parse MADT MP Wake entry.
1350 acpi_table_parse_madt(ACPI_MADT_TYPE_MULTIPROC_WAKEUP,
1351 acpi_parse_mp_wake, 1);
1354 if (error == -EINVAL) {
1356 * Dell Precision Workstation 410, 610 come here.
1358 pr_err("Invalid BIOS MADT, disabling ACPI\n");
1363 * ACPI found no MADT, and so ACPI wants UP PIC mode.
1364 * In the event an MPS table was found, forget it.
1365 * Boot with "acpi=off" to use MPS on such a system.
1367 if (smp_found_config) {
1368 pr_warn("No APIC-table, disabling MPS\n");
1369 smp_found_config = 0;
1374 * ACPI supports both logical (e.g. Hyper-Threading) and physical
1375 * processors, where MPS only supports physical.
1377 if (acpi_lapic && acpi_ioapic)
1378 pr_info("Using ACPI (MADT) for SMP configuration information\n");
1379 else if (acpi_lapic)
1380 pr_info("Using ACPI for processor (LAPIC) configuration information\n");
1385 static int __init disable_acpi_irq(const struct dmi_system_id *d)
1388 pr_notice("%s detected: force use of acpi=noirq\n", d->ident);
1394 static int __init disable_acpi_pci(const struct dmi_system_id *d)
1397 pr_notice("%s detected: force use of pci=noacpi\n", d->ident);
1403 static int __init disable_acpi_xsdt(const struct dmi_system_id *d)
1406 pr_notice("%s detected: force use of acpi=rsdt\n", d->ident);
1407 acpi_gbl_do_not_use_xsdt = TRUE;
1409 pr_notice("Warning: DMI blacklist says broken, but acpi XSDT forced\n");
1414 static int __init dmi_disable_acpi(const struct dmi_system_id *d)
1417 pr_notice("%s detected: acpi off\n", d->ident);
1420 pr_notice("Warning: DMI blacklist says broken, but acpi forced\n");
1426 * Force ignoring BIOS IRQ0 override
1428 static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
1430 if (!acpi_skip_timer_override) {
1431 pr_notice("%s detected: Ignoring BIOS IRQ0 override\n",
1433 acpi_skip_timer_override = 1;
1439 * ACPI offers an alternative platform interface model that removes
1440 * ACPI hardware requirements for platforms that do not implement
1441 * the PC Architecture.
1443 * We initialize the Hardware-reduced ACPI model here:
1445 void __init acpi_generic_reduced_hw_init(void)
1448 * Override x86_init functions and bypass legacy PIC in
1449 * hardware reduced ACPI mode.
1451 x86_init.timers.timer_init = x86_init_noop;
1452 x86_init.irqs.pre_vector_init = x86_init_noop;
1453 legacy_pic = &null_legacy_pic;
1456 static void __init acpi_reduced_hw_init(void)
1458 if (acpi_gbl_reduced_hardware)
1459 x86_init.acpi.reduced_hw_early_init();
1463 * If your system is blacklisted here, but you find that acpi=force
1466 static const struct dmi_system_id acpi_dmi_table[] __initconst = {
1468 * Boxes that need ACPI disabled
1471 .callback = dmi_disable_acpi,
1472 .ident = "IBM Thinkpad",
1474 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1475 DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
1480 * Boxes that need ACPI PCI IRQ routing disabled
1483 .callback = disable_acpi_irq,
1484 .ident = "ASUS A7V",
1486 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
1487 DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
1488 /* newer BIOS, Revision 1011, does work */
1489 DMI_MATCH(DMI_BIOS_VERSION,
1490 "ASUS A7V ACPI BIOS Revision 1007"),
1495 * Latest BIOS for IBM 600E (1.16) has bad pcinum
1496 * for LPC bridge, which is needed for the PCI
1497 * interrupt links to work. DSDT fix is in bug 5966.
1498 * 2645, 2646 model numbers are shared with 600/600E/600X
1500 .callback = disable_acpi_irq,
1501 .ident = "IBM Thinkpad 600 Series 2645",
1503 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1504 DMI_MATCH(DMI_BOARD_NAME, "2645"),
1508 .callback = disable_acpi_irq,
1509 .ident = "IBM Thinkpad 600 Series 2646",
1511 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1512 DMI_MATCH(DMI_BOARD_NAME, "2646"),
1516 * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
1519 .callback = disable_acpi_pci,
1520 .ident = "ASUS PR-DLS",
1522 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1523 DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
1524 DMI_MATCH(DMI_BIOS_VERSION,
1525 "ASUS PR-DLS ACPI BIOS Revision 1010"),
1526 DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
1530 .callback = disable_acpi_pci,
1531 .ident = "Acer TravelMate 36x Laptop",
1533 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
1534 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
1538 * Boxes that need ACPI XSDT use disabled due to corrupted tables
1541 .callback = disable_acpi_xsdt,
1542 .ident = "Advantech DAC-BJ01",
1544 DMI_MATCH(DMI_SYS_VENDOR, "NEC"),
1545 DMI_MATCH(DMI_PRODUCT_NAME, "Bearlake CRB Board"),
1546 DMI_MATCH(DMI_BIOS_VERSION, "V1.12"),
1547 DMI_MATCH(DMI_BIOS_DATE, "02/01/2011"),
1553 /* second table for DMI checks that should run after early-quirks */
1554 static const struct dmi_system_id acpi_dmi_table_late[] __initconst = {
1556 * HP laptops which use a DSDT reporting as HP/SB400/10000,
1557 * which includes some code which overrides all temperature
1558 * trip points to 16C if the INTIN2 input of the I/O APIC
1559 * is enabled. This input is incorrectly designated the
1560 * ISA IRQ 0 via an interrupt source override even though
1561 * it is wired to the output of the master 8259A and INTIN0
1562 * is not connected at all. Force ignoring BIOS IRQ0
1563 * override in that cases.
1566 .callback = dmi_ignore_irq0_timer_override,
1567 .ident = "HP nx6115 laptop",
1569 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1570 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6115"),
1574 .callback = dmi_ignore_irq0_timer_override,
1575 .ident = "HP NX6125 laptop",
1577 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1578 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
1582 .callback = dmi_ignore_irq0_timer_override,
1583 .ident = "HP NX6325 laptop",
1585 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1586 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
1590 .callback = dmi_ignore_irq0_timer_override,
1591 .ident = "HP 6715b laptop",
1593 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1594 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
1598 .callback = dmi_ignore_irq0_timer_override,
1599 .ident = "FUJITSU SIEMENS",
1601 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
1602 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO PRO V2030"),
1609 * acpi_boot_table_init() and acpi_boot_init()
1610 * called from setup_arch(), always.
1611 * 1. checksums all tables
1612 * 2. enumerates lapics
1613 * 3. enumerates io-apics
1615 * acpi_table_init() is separate to allow reading SRAT without
1616 * other side effects.
1618 * side effects of acpi_boot_init:
1619 * acpi_lapic = 1 if LAPIC found
1620 * acpi_ioapic = 1 if IOAPIC found
1621 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
1622 * if acpi_blacklisted() acpi_disabled = 1;
1623 * acpi_irq_model=...
1627 void __init acpi_boot_table_init(void)
1629 dmi_check_system(acpi_dmi_table);
1632 * If acpi_disabled, bail out
1638 * Initialize the ACPI boot-time table parser.
1640 if (acpi_locate_initial_tables())
1643 acpi_reserve_initial_tables();
1646 int __init early_acpi_boot_init(void)
1651 acpi_table_init_complete();
1653 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
1656 * blacklist may disable ACPI entirely
1658 if (acpi_blacklisted()) {
1660 pr_warn("acpi=force override\n");
1662 pr_warn("Disabling ACPI support\n");
1669 * Process the Multiple APIC Description Table (MADT), if present
1671 early_acpi_process_madt();
1674 * Hardware-reduced ACPI mode initialization:
1676 acpi_reduced_hw_init();
1681 int __init acpi_boot_init(void)
1683 /* those are executed after early-quirks are executed */
1684 dmi_check_system(acpi_dmi_table_late);
1687 * If acpi_disabled, bail out
1692 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
1695 * set sci_int and PM timer address
1697 acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
1700 * Process the Multiple APIC Description Table (MADT), if present
1702 acpi_process_madt();
1704 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
1705 if (IS_ENABLED(CONFIG_ACPI_BGRT) && !acpi_nobgrt)
1706 acpi_table_parse(ACPI_SIG_BGRT, acpi_parse_bgrt);
1709 x86_init.pci.init = pci_acpi_init;
1711 /* Do not enable ACPI SPCR console by default */
1712 acpi_parse_spcr(earlycon_acpi_spcr_enable, false);
1716 static int __init parse_acpi(char *arg)
1721 /* "acpi=off" disables both ACPI table parsing and interpreter */
1722 if (strcmp(arg, "off") == 0) {
1725 /* acpi=force to over-ride black-list */
1726 else if (strcmp(arg, "force") == 0) {
1730 /* acpi=strict disables out-of-spec workarounds */
1731 else if (strcmp(arg, "strict") == 0) {
1734 /* acpi=rsdt use RSDT instead of XSDT */
1735 else if (strcmp(arg, "rsdt") == 0) {
1736 acpi_gbl_do_not_use_xsdt = TRUE;
1738 /* "acpi=noirq" disables ACPI interrupt routing */
1739 else if (strcmp(arg, "noirq") == 0) {
1742 /* "acpi=copy_dsdt" copies DSDT */
1743 else if (strcmp(arg, "copy_dsdt") == 0) {
1744 acpi_gbl_copy_dsdt_locally = 1;
1746 /* "acpi=nocmcff" disables FF mode for corrected errors */
1747 else if (strcmp(arg, "nocmcff") == 0) {
1748 acpi_disable_cmcff = 1;
1750 /* Core will printk when we return error. */
1755 early_param("acpi", parse_acpi);
1757 static int __init parse_acpi_bgrt(char *arg)
1762 early_param("bgrt_disable", parse_acpi_bgrt);
1764 /* FIXME: Using pci= for an ACPI parameter is a travesty. */
1765 static int __init parse_pci(char *arg)
1767 if (arg && strcmp(arg, "noacpi") == 0)
1771 early_param("pci", parse_pci);
1773 int __init acpi_mps_check(void)
1775 #if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
1776 /* mptable code is not built-in*/
1777 if (acpi_disabled || acpi_noirq) {
1778 pr_warn("MPS support code is not built-in, using acpi=off or acpi=noirq or pci=noacpi may have problem\n");
1785 #ifdef CONFIG_X86_IO_APIC
1786 static int __init parse_acpi_skip_timer_override(char *arg)
1788 acpi_skip_timer_override = 1;
1791 early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
1793 static int __init parse_acpi_use_timer_override(char *arg)
1795 acpi_use_timer_override = 1;
1798 early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
1799 #endif /* CONFIG_X86_IO_APIC */
1801 static int __init setup_acpi_sci(char *s)
1805 if (!strcmp(s, "edge"))
1806 acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
1807 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
1808 else if (!strcmp(s, "level"))
1809 acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
1810 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
1811 else if (!strcmp(s, "high"))
1812 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
1813 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
1814 else if (!strcmp(s, "low"))
1815 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
1816 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
1821 early_param("acpi_sci", setup_acpi_sci);
1823 int __acpi_acquire_global_lock(unsigned int *lock)
1825 unsigned int old, new, val;
1827 old = READ_ONCE(*lock);
1829 val = (old >> 1) & 0x1;
1830 new = (old & ~0x3) + 2 + val;
1831 } while (!try_cmpxchg(lock, &old, new));
1839 int __acpi_release_global_lock(unsigned int *lock)
1841 unsigned int old, new;
1843 old = READ_ONCE(*lock);
1846 } while (!try_cmpxchg(lock, &old, new));
1850 void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
1852 e820__range_add(addr, size, E820_TYPE_NVS);
1853 e820__update_table_print();
1856 void x86_default_set_root_pointer(u64 addr)
1858 boot_params.acpi_rsdp_addr = addr;
1861 u64 x86_default_get_root_pointer(void)
1863 return boot_params.acpi_rsdp_addr;