File Index
Files and directories
Sign in
FILE

boot.c

File preview with syntax highlighting.

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