blob: 7ff007ed899d1731c97eba25fc40ccac38a90309 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * boot.c - Architecture-Specific Low-Level ACPI Boot Support
3 *
4 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
5 * Copyright (C) 2001 Jun Nakajima <jun.nakajima@intel.com>
6 *
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 */
25
26#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/acpi.h>
Thomas Gleixnerd66bea52007-02-16 01:27:57 -080028#include <linux/acpi_pmtmr.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/efi.h>
Ashok Raj73fea172006-09-26 10:52:35 +020030#include <linux/cpumask.h>
Paul Gortmaker186f4362016-07-13 20:18:56 -040031#include <linux/export.h>
Andrey Paninaea00142005-06-25 14:54:42 -070032#include <linux/dmi.h>
Nick Pigginb33fa1f2005-10-01 02:34:42 +100033#include <linux/irq.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/slab.h>
adurbin@google.comf0f4c342006-09-26 10:52:39 +020035#include <linux/bootmem.h>
36#include <linux/ioport.h>
Yinghai Lua31f8202009-05-06 10:06:15 -070037#include <linux/pci.h>
Dave Young7b0a9112017-01-31 13:21:40 +000038#include <linux/efi-bgrt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Thomas Gleixnerf7a0c782015-04-14 10:30:08 +080040#include <asm/irqdomain.h>
Thomas Gleixnerb72d0db2009-08-29 16:24:51 +020041#include <asm/pci_x86.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/pgtable.h>
43#include <asm/io_apic.h>
44#include <asm/apic.h>
45#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <asm/mpspec.h>
Alexey Starikovskiydfac2182008-04-04 23:41:50 +040047#include <asm/smp.h>
Jiang Liu95d76ac2014-06-09 16:19:48 +080048#include <asm/i8259.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Konrad Rzeszutek Wilkd6a77ea2013-05-14 17:09:16 +000050#include "sleep.h" /* To include x86_acpi_suspend_lowlevel */
Adrian Bunke8924ac2006-09-26 10:52:35 +020051static int __initdata acpi_force = 0;
Len Brownc636f752009-05-19 23:47:38 -040052int acpi_disabled;
Andi Kleendf3bb572006-09-26 10:52:33 +020053EXPORT_SYMBOL(acpi_disabled);
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#ifdef CONFIG_X86_64
Ingo Molnar1dcdd3d2009-01-28 17:55:37 +010056# include <asm/proto.h>
Len Brown4be44fc2005-08-05 00:44:28 -040057#endif /* X86 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#define PREFIX "ACPI: "
60
Andrew Morton90d53902006-11-02 22:07:18 -080061int acpi_noirq; /* skip ACPI IRQ initialization */
Yinghai Lu6e4be1ff2008-02-05 00:01:48 -080062int acpi_pci_disabled; /* skip ACPI PCI scan and IRQ initialization */
63EXPORT_SYMBOL(acpi_pci_disabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65int acpi_lapic;
66int acpi_ioapic;
67int acpi_strict;
Naveen N. Rao9ad95872013-07-01 21:08:54 +053068int acpi_disable_cmcff;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +030070u8 acpi_sci_flags __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071int acpi_sci_override_gsi __initdata;
72int acpi_skip_timer_override __initdata;
Andi Kleenfa18f472006-11-14 16:57:46 +010073int acpi_use_timer_override __initdata;
Andreas Herrmann7f74f8f2011-02-24 15:53:46 +010074int acpi_fix_pin2_polarity __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76#ifdef CONFIG_X86_LOCAL_APIC
77static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
78#endif
79
Sebastian Andrzej Siewiord2d9c4a2016-10-21 10:44:49 +020080#ifdef CONFIG_X86_IO_APIC
Jiang Liu5da2fd22014-11-02 14:04:29 +080081/*
82 * Locks related to IOAPIC hotplug
83 * Hotplug side:
84 * ->device_hotplug_lock
85 * ->acpi_ioapic_lock
86 * ->ioapic_lock
87 * Interrupt mapping side:
88 * ->acpi_ioapic_lock
89 * ->ioapic_mutex
90 * ->ioapic_lock
91 */
92static DEFINE_MUTEX(acpi_ioapic_lock);
Sebastian Andrzej Siewiord2d9c4a2016-10-21 10:44:49 +020093#endif
Jiang Liu5da2fd22014-11-02 14:04:29 +080094
Linus Torvalds1da177e2005-04-16 15:20:36 -070095/* --------------------------------------------------------------------------
96 Boot-time Configuration
97 -------------------------------------------------------------------------- */
98
99/*
100 * The default interrupt routing model is PIC (8259). This gets
Simon Arlott27b46d72007-10-20 01:13:56 +0200101 * overridden if IOAPICs are enumerated (below).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 */
Len Brown4be44fc2005-08-05 00:44:28 -0400103enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106/*
Eric W. Biederman988856e2010-03-30 01:07:15 -0700107 * ISA irqs by default are the first 16 gsis but can be
108 * any gsi as specified by an interrupt source override.
109 */
110static u32 isa_irq_to_gsi[NR_IRQS_LEGACY] __read_mostly = {
111 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
112};
113
Jiang Liu2c0a6892014-06-10 14:11:23 +0800114#define ACPI_INVALID_GSI INT_MIN
Eric W. Biederman988856e2010-03-30 01:07:15 -0700115
116/*
Zhang Yanfei45f13302013-07-23 21:03:24 +0800117 * This is just a simple wrapper around early_ioremap(),
118 * with sanity checks for phys == 0 and size == 0.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 */
Jan Beulich2fdf0742007-12-13 08:33:59 +0000120char *__init __acpi_map_table(unsigned long phys, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Yinghai Luf34fa822008-07-09 20:16:36 -0700123 if (!phys || !size)
124 return NULL;
125
Yinghai Lu7d972772009-02-07 15:39:41 -0800126 return early_ioremap(phys, size);
127}
Zhang Yanfei45f13302013-07-23 21:03:24 +0800128
Yinghai Lu7d972772009-02-07 15:39:41 -0800129void __init __acpi_unmap_table(char *map, unsigned long size)
130{
131 if (!map || !size)
132 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Yinghai Lu7d972772009-02-07 15:39:41 -0800134 early_iounmap(map, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#ifdef CONFIG_X86_LOCAL_APIC
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300138static int __init acpi_parse_madt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
Len Brown4be44fc2005-08-05 00:44:28 -0400140 struct acpi_table_madt *madt = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Borislav Petkov93984fb2016-04-04 22:25:00 +0200142 if (!boot_cpu_has(X86_FEATURE_APIC))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 return -EINVAL;
144
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300145 madt = (struct acpi_table_madt *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 if (!madt) {
147 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
148 return -ENODEV;
149 }
150
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300151 if (madt->address) {
152 acpi_lapic_addr = (u64) madt->address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154 printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300155 madt->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 }
157
Ingo Molnar306db032009-01-28 03:43:47 +0100158 default_acpi_madt_oem_check(madt->header.oem_id,
159 madt->header.oem_table_id);
Len Brown4be44fc2005-08-05 00:44:28 -0400160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 return 0;
162}
163
Jiang Liu7e1f85f2013-09-02 11:57:36 +0800164/**
165 * acpi_register_lapic - register a local apic and generates a logic cpu number
166 * @id: local apic id to register
Vitaly Kuznetsov3e9e57f2016-06-30 17:56:36 +0200167 * @acpiid: ACPI id to register
Jiang Liu7e1f85f2013-09-02 11:57:36 +0800168 * @enabled: this cpu is enabled or not
169 *
170 * Returns the logic cpu number which maps to the local apic
171 */
Vitaly Kuznetsov3e9e57f2016-06-30 17:56:36 +0200172static int acpi_register_lapic(int id, u32 acpiid, u8 enabled)
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400173{
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700174 unsigned int ver = 0;
Vitaly Kuznetsov3e9e57f2016-06-30 17:56:36 +0200175 int cpu;
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700176
Tang Chen82982d72013-07-23 16:00:19 +0800177 if (id >= MAX_LOCAL_APIC) {
Yinghai Lud3bd0582010-12-16 19:09:58 -0800178 printk(KERN_INFO PREFIX "skipped apicid that is too big\n");
Jiang Liu7e1f85f2013-09-02 11:57:36 +0800179 return -EINVAL;
Yinghai Lud3bd0582010-12-16 19:09:58 -0800180 }
181
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700182 if (boot_cpu_physical_apicid != -1U)
Denys Vlasenkocff9ab22016-09-13 20:12:32 +0200183 ver = boot_cpu_apic_version;
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700184
Gu Zheng8f549692016-08-25 16:35:16 +0800185 cpu = __generic_processor_info(id, ver, enabled);
Vitaly Kuznetsov3e9e57f2016-06-30 17:56:36 +0200186 if (cpu >= 0)
187 early_per_cpu(x86_cpu_to_acpiid, cpu) = acpiid;
188
189 return cpu;
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400190}
191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192static int __init
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800193acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
194{
195 struct acpi_madt_local_x2apic *processor = NULL;
Yinghai Lua35fd282011-12-21 17:45:16 -0800196 int apic_id;
197 u8 enabled;
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800198
199 processor = (struct acpi_madt_local_x2apic *)header;
200
201 if (BAD_MADT_ENTRY(processor, end))
202 return -EINVAL;
203
204 acpi_table_print_madt_entry(header);
205
Yinghai Lua35fd282011-12-21 17:45:16 -0800206 apic_id = processor->local_apic_id;
207 enabled = processor->lapic_flags & ACPI_MADT_ENABLED;
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800208#ifdef CONFIG_X86_X2APIC
209 /*
210 * We need to register disabled CPU as well to permit
211 * counting disabled CPUs. This allows us to size
212 * cpus_possible_map more accurately, to permit
213 * to not preallocating memory for all NR_CPUS
214 * when we use CPU hotplug.
215 */
Steffen Persvoldb7157ac2012-03-16 20:25:35 +0100216 if (!apic->apic_id_valid(apic_id) && enabled)
Yinghai Lua35fd282011-12-21 17:45:16 -0800217 printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
218 else
Vitaly Kuznetsov3e9e57f2016-06-30 17:56:36 +0200219 acpi_register_lapic(apic_id, processor->uid, enabled);
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800220#else
221 printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
222#endif
223
224 return 0;
225}
226
227static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300228acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300230 struct acpi_madt_local_apic *processor = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300232 processor = (struct acpi_madt_local_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
234 if (BAD_MADT_ENTRY(processor, end))
235 return -EINVAL;
236
237 acpi_table_print_madt_entry(header);
238
Thomas Gleixnerf3bf1db2016-10-07 14:02:12 +0200239 /* Ignore invalid ID */
240 if (processor->id == 0xff)
241 return 0;
242
Ashok Raj7f66ae42006-02-03 21:51:50 +0100243 /*
244 * We need to register disabled CPU as well to permit
245 * counting disabled CPUs. This allows us to size
246 * cpus_possible_map more accurately, to permit
247 * to not preallocating memory for all NR_CPUS
248 * when we use CPU hotplug.
249 */
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400250 acpi_register_lapic(processor->id, /* APIC ID */
Vitaly Kuznetsov3e9e57f2016-06-30 17:56:36 +0200251 processor->processor_id, /* ACPI ID */
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400252 processor->lapic_flags & ACPI_MADT_ENABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254 return 0;
255}
256
257static int __init
Jack Steinerac049c12008-03-28 14:12:09 -0500258acpi_parse_sapic(struct acpi_subtable_header *header, const unsigned long end)
259{
260 struct acpi_madt_local_sapic *processor = NULL;
261
262 processor = (struct acpi_madt_local_sapic *)header;
263
264 if (BAD_MADT_ENTRY(processor, end))
265 return -EINVAL;
266
267 acpi_table_print_madt_entry(header);
268
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400269 acpi_register_lapic((processor->id << 8) | processor->eid,/* APIC ID */
Vitaly Kuznetsov3e9e57f2016-06-30 17:56:36 +0200270 processor->processor_id, /* ACPI ID */
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400271 processor->lapic_flags & ACPI_MADT_ENABLED);
Jack Steinerac049c12008-03-28 14:12:09 -0500272
273 return 0;
274}
275
276static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300277acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400278 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300280 struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300282 lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
285 return -EINVAL;
286
Baoquan He6de42112016-08-12 14:57:13 +0800287 acpi_table_print_madt_entry(header);
288
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 acpi_lapic_addr = lapic_addr_ovr->address;
290
291 return 0;
292}
293
294static int __init
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800295acpi_parse_x2apic_nmi(struct acpi_subtable_header *header,
296 const unsigned long end)
297{
298 struct acpi_madt_local_x2apic_nmi *x2apic_nmi = NULL;
299
300 x2apic_nmi = (struct acpi_madt_local_x2apic_nmi *)header;
301
302 if (BAD_MADT_ENTRY(x2apic_nmi, end))
303 return -EINVAL;
304
305 acpi_table_print_madt_entry(header);
306
307 if (x2apic_nmi->lint != 1)
308 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
309
310 return 0;
311}
312
313static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300314acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300316 struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300318 lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320 if (BAD_MADT_ENTRY(lapic_nmi, end))
321 return -EINVAL;
322
323 acpi_table_print_madt_entry(header);
324
325 if (lapic_nmi->lint != 1)
326 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
327
328 return 0;
329}
330
Len Brown4be44fc2005-08-05 00:44:28 -0400331#endif /*CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Len Brown84663612005-08-24 12:09:07 -0400333#ifdef CONFIG_X86_IO_APIC
Jiang Liu8d7cdcb2014-06-09 16:19:33 +0800334#define MP_ISA_BUS 0
335
336static void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger,
337 u32 gsi)
338{
339 int ioapic;
340 int pin;
341 struct mpc_intsrc mp_irq;
342
343 /*
344 * Convert 'gsi' to 'ioapic.pin'.
345 */
346 ioapic = mp_find_ioapic(gsi);
347 if (ioapic < 0)
348 return;
349 pin = mp_find_ioapic_pin(ioapic, gsi);
350
351 /*
352 * TBD: This check is for faulty timer entries, where the override
353 * erroneously sets the trigger to level, resulting in a HUGE
354 * increase of timer interrupts!
355 */
356 if ((bus_irq == 0) && (trigger == 3))
357 trigger = 1;
358
359 mp_irq.type = MP_INTSRC;
360 mp_irq.irqtype = mp_INT;
361 mp_irq.irqflag = (trigger << 2) | polarity;
362 mp_irq.srcbus = MP_ISA_BUS;
363 mp_irq.srcbusirq = bus_irq; /* IRQ */
364 mp_irq.dstapic = mpc_ioapic_id(ioapic); /* APIC ID */
365 mp_irq.dstirq = pin; /* INTIN# */
366
367 mp_save_irq(&mp_irq);
368
Jiang Liu2e0ad0e2014-06-09 16:19:38 +0800369 /*
370 * Reset default identity mapping if gsi is also an legacy IRQ,
371 * otherwise there will be more than one entry with the same GSI
372 * and acpi_isa_irq_to_gsi() may give wrong result.
373 */
Jiang Liu95d76ac2014-06-09 16:19:48 +0800374 if (gsi < nr_legacy_irqs() && isa_irq_to_gsi[gsi] == gsi)
Jiang Liu2e0ad0e2014-06-09 16:19:38 +0800375 isa_irq_to_gsi[gsi] = ACPI_INVALID_GSI;
Jiang Liu8d7cdcb2014-06-09 16:19:33 +0800376 isa_irq_to_gsi[bus_irq] = gsi;
377}
378
379static int mp_config_acpi_gsi(struct device *dev, u32 gsi, int trigger,
380 int polarity)
381{
382#ifdef CONFIG_X86_MPPARSE
383 struct mpc_intsrc mp_irq;
384 struct pci_dev *pdev;
385 unsigned char number;
386 unsigned int devfn;
387 int ioapic;
388 u8 pin;
389
390 if (!acpi_ioapic)
391 return 0;
392 if (!dev || !dev_is_pci(dev))
393 return 0;
394
395 pdev = to_pci_dev(dev);
396 number = pdev->bus->number;
397 devfn = pdev->devfn;
398 pin = pdev->pin;
399 /* print the entry should happen on mptable identically */
400 mp_irq.type = MP_INTSRC;
401 mp_irq.irqtype = mp_INT;
402 mp_irq.irqflag = (trigger == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
403 (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
404 mp_irq.srcbus = number;
405 mp_irq.srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
406 ioapic = mp_find_ioapic(gsi);
407 mp_irq.dstapic = mpc_ioapic_id(ioapic);
408 mp_irq.dstirq = mp_find_ioapic_pin(ioapic, gsi);
409
410 mp_save_irq(&mp_irq);
411#endif
412 return 0;
413}
414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300416acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300418 struct acpi_madt_io_apic *ioapic = NULL;
Jiang Liuca7e28aa2014-06-09 16:19:54 +0800419 struct ioapic_domain_cfg cfg = {
420 .type = IOAPIC_DOMAIN_DYNAMIC,
Thomas Gleixnerf7a0c782015-04-14 10:30:08 +0800421 .ops = &mp_ioapic_irqdomain_ops,
Jiang Liuca7e28aa2014-06-09 16:19:54 +0800422 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300424 ioapic = (struct acpi_madt_io_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426 if (BAD_MADT_ENTRY(ioapic, end))
427 return -EINVAL;
Len Brown4be44fc2005-08-05 00:44:28 -0400428
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 acpi_table_print_madt_entry(header);
430
Jiang Liuca7e28aa2014-06-09 16:19:54 +0800431 /* Statically assign IRQ numbers for IOAPICs hosting legacy IRQs */
432 if (ioapic->global_irq_base < nr_legacy_irqs())
433 cfg.type = IOAPIC_DOMAIN_LEGACY;
434
435 mp_register_ioapic(ioapic->id, ioapic->address, ioapic->global_irq_base,
436 &cfg);
Len Brown4be44fc2005-08-05 00:44:28 -0400437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 return 0;
439}
440
441/*
442 * Parse Interrupt Source Override for the ACPI SCI
443 */
Eric W. Biederman9d2062b2010-03-30 01:07:05 -0700444static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger, u32 gsi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
446 if (trigger == 0) /* compatible SCI trigger is level */
447 trigger = 3;
448
449 if (polarity == 0) /* compatible SCI polarity is low */
450 polarity = 3;
451
452 /* Command-line over-ride via acpi_sci= */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300453 if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
454 trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300456 if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
457 polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Eric W. Biederman9d2062b2010-03-30 01:07:05 -0700459 mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
Sinan Kayaf1caa612016-10-24 00:31:31 -0400460 acpi_penalize_sci_irq(bus_irq, trigger, polarity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
462 /*
463 * stash over-ride to indicate we've been here
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300464 * and for later update of acpi_gbl_FADT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 */
Len Brown7bdd21c2006-12-02 02:27:46 -0500466 acpi_sci_override_gsi = gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 return;
468}
469
470static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300471acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400472 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300474 struct acpi_madt_interrupt_override *intsrc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300476 intsrc = (struct acpi_madt_interrupt_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
478 if (BAD_MADT_ENTRY(intsrc, end))
479 return -EINVAL;
480
481 acpi_table_print_madt_entry(header);
482
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300483 if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
Eric W. Biederman9d2062b2010-03-30 01:07:05 -0700484 acpi_sci_ioapic_setup(intsrc->source_irq,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300485 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
Eric W. Biederman9d2062b2010-03-30 01:07:05 -0700486 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
487 intsrc->global_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 return 0;
489 }
490
Feng Tangae10ccd2012-06-04 15:00:04 +0800491 if (intsrc->source_irq == 0) {
Andreas Herrmann7f74f8f2011-02-24 15:53:46 +0100492 if (acpi_skip_timer_override) {
Feng Tangae10ccd2012-06-04 15:00:04 +0800493 printk(PREFIX "BIOS IRQ0 override ignored.\n");
Andreas Herrmann7f74f8f2011-02-24 15:53:46 +0100494 return 0;
495 }
Feng Tangae10ccd2012-06-04 15:00:04 +0800496
497 if ((intsrc->global_irq == 2) && acpi_fix_pin2_polarity
498 && (intsrc->inti_flags & ACPI_MADT_POLARITY_MASK)) {
Andreas Herrmann7f74f8f2011-02-24 15:53:46 +0100499 intsrc->inti_flags &= ~ACPI_MADT_POLARITY_MASK;
500 printk(PREFIX "BIOS IRQ0 pin2 override: forcing polarity to high active.\n");
501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 }
503
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300504 mp_override_legacy_irq(intsrc->source_irq,
505 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
506 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
507 intsrc->global_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
509 return 0;
510}
511
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300513acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300515 struct acpi_madt_nmi_source *nmi_src = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300517 nmi_src = (struct acpi_madt_nmi_source *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
519 if (BAD_MADT_ENTRY(nmi_src, end))
520 return -EINVAL;
521
522 acpi_table_print_madt_entry(header);
523
524 /* TBD: Support nimsrc entries? */
525
526 return 0;
527}
528
Len Brown4be44fc2005-08-05 00:44:28 -0400529#endif /* CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531/*
532 * acpi_pic_sci_set_trigger()
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300533 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 * use ELCR to set PIC-mode trigger type for SCI
535 *
536 * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
537 * it may require Edge Trigger -- use "acpi_sci=edge"
538 *
539 * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
540 * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
Simon Arlott27b46d72007-10-20 01:13:56 +0200541 * ECLR1 is IRQs 0-7 (IRQ 0, 1, 2 must be 0)
542 * ECLR2 is IRQs 8-15 (IRQ 8, 13 must be 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 */
544
Len Brown4be44fc2005-08-05 00:44:28 -0400545void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546{
547 unsigned int mask = 1 << irq;
548 unsigned int old, new;
549
550 /* Real old ELCR mask */
551 old = inb(0x4d0) | (inb(0x4d1) << 8);
552
553 /*
Simon Arlott27b46d72007-10-20 01:13:56 +0200554 * If we use ACPI to set PCI IRQs, then we should clear ELCR
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 * since we will set it correctly as we enable the PCI irq
556 * routing.
557 */
558 new = acpi_noirq ? old : 0;
559
560 /*
561 * Update SCI information in the ELCR, it isn't in the PCI
562 * routing tables..
563 */
564 switch (trigger) {
Len Brown4be44fc2005-08-05 00:44:28 -0400565 case 1: /* Edge - clear */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 new &= ~mask;
567 break;
Len Brown4be44fc2005-08-05 00:44:28 -0400568 case 3: /* Level - set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 new |= mask;
570 break;
571 }
572
573 if (old == new)
574 return;
575
576 printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
577 outb(new, 0x4d0);
578 outb(new >> 8, 0x4d1);
579}
580
Jiang Liu6b9fb702014-06-10 14:13:25 +0800581int acpi_gsi_to_irq(u32 gsi, unsigned int *irqp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582{
Jiang Liub568b862015-01-20 10:21:05 +0800583 int rc, irq, trigger, polarity;
Yinghai Lu18dce6b2010-02-10 01:20:05 -0800584
Jiang Liu1ea76fb2015-02-16 10:11:13 +0800585 if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
586 *irqp = gsi;
587 return 0;
588 }
589
Jiang Liub568b862015-01-20 10:21:05 +0800590 rc = acpi_get_override_irq(gsi, &trigger, &polarity);
591 if (rc == 0) {
592 trigger = trigger ? ACPI_LEVEL_SENSITIVE : ACPI_EDGE_SENSITIVE;
593 polarity = polarity ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH;
594 irq = acpi_register_gsi(NULL, gsi, trigger, polarity);
595 if (irq >= 0) {
596 *irqp = irq;
597 return 0;
598 }
Jiang Liu6b9fb702014-06-10 14:13:25 +0800599 }
Jiang Liub568b862015-01-20 10:21:05 +0800600
601 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602}
Huang Ying81e88fd2011-01-12 14:44:55 +0800603EXPORT_SYMBOL_GPL(acpi_gsi_to_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Eric W. Biederman2c2df842010-03-30 01:07:02 -0700605int acpi_isa_irq_to_gsi(unsigned isa_irq, u32 *gsi)
606{
Jiang Liu95d76ac2014-06-09 16:19:48 +0800607 if (isa_irq < nr_legacy_irqs() &&
Jiang Liu2e0ad0e2014-06-09 16:19:38 +0800608 isa_irq_to_gsi[isa_irq] != ACPI_INVALID_GSI) {
Jiang Liu032329e2014-06-09 16:19:35 +0800609 *gsi = isa_irq_to_gsi[isa_irq];
610 return 0;
611 }
612
613 return -1;
Eric W. Biederman2c2df842010-03-30 01:07:02 -0700614}
615
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100616static int acpi_register_gsi_pic(struct device *dev, u32 gsi,
617 int trigger, int polarity)
618{
619#ifdef CONFIG_PCI
620 /*
621 * Make sure all (legacy) PCI IRQs are set as level-triggered.
622 */
623 if (trigger == ACPI_LEVEL_SENSITIVE)
Paul Gortmakerea6cd252015-05-09 20:27:37 -0400624 elcr_set_level_irq(gsi);
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100625#endif
626
627 return gsi;
628}
629
Thomas Gleixner2f82c9d2015-01-22 15:13:36 +0100630#ifdef CONFIG_X86_LOCAL_APIC
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100631static int acpi_register_gsi_ioapic(struct device *dev, u32 gsi,
632 int trigger, int polarity)
633{
Jiang Liu84245af2014-06-10 14:14:47 +0800634 int irq = gsi;
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100635#ifdef CONFIG_X86_IO_APIC
Jiang Liu46176f32015-04-14 10:30:05 +0800636 int node;
637 struct irq_alloc_info info;
638
639 node = dev ? dev_to_node(dev) : NUMA_NO_NODE;
640 trigger = trigger == ACPI_EDGE_SENSITIVE ? 0 : 1;
641 polarity = polarity == ACPI_ACTIVE_HIGH ? 0 : 1;
642 ioapic_set_alloc_attr(&info, node, trigger, polarity);
643
Jiang Liu5da2fd22014-11-02 14:04:29 +0800644 mutex_lock(&acpi_ioapic_lock);
Jiang Liu46176f32015-04-14 10:30:05 +0800645 irq = mp_map_gsi_to_irq(gsi, IOAPIC_MAP_ALLOC, &info);
646 /* Don't set up the ACPI SCI because it's already set up */
647 if (irq >= 0 && enable_update_mptable &&
648 acpi_gbl_FADT.sci_interrupt != gsi)
649 mp_config_acpi_gsi(dev, gsi, trigger, polarity);
Jiang Liu5da2fd22014-11-02 14:04:29 +0800650 mutex_unlock(&acpi_ioapic_lock);
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100651#endif
652
Jiang Liu84245af2014-06-10 14:14:47 +0800653 return irq;
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100654}
655
Jiang Liu6a38fa02014-06-10 14:16:27 +0800656static void acpi_unregister_gsi_ioapic(u32 gsi)
657{
658#ifdef CONFIG_X86_IO_APIC
Jiang Liu46176f32015-04-14 10:30:05 +0800659 int irq;
660
Jiang Liu5da2fd22014-11-02 14:04:29 +0800661 mutex_lock(&acpi_ioapic_lock);
Jiang Liu46176f32015-04-14 10:30:05 +0800662 irq = mp_map_gsi_to_irq(gsi, 0, NULL);
663 if (irq > 0)
664 mp_unmap_irq(irq);
Jiang Liu5da2fd22014-11-02 14:04:29 +0800665 mutex_unlock(&acpi_ioapic_lock);
Jiang Liu6a38fa02014-06-10 14:16:27 +0800666#endif
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100667}
Thomas Gleixner2f82c9d2015-01-22 15:13:36 +0100668#endif
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100669
Jeremy Fitzhardinge90f68812010-06-24 17:05:41 +0100670int (*__acpi_register_gsi)(struct device *dev, u32 gsi,
671 int trigger, int polarity) = acpi_register_gsi_pic;
Jiang Liu6a38fa02014-06-10 14:16:27 +0800672void (*__acpi_unregister_gsi)(u32 gsi) = NULL;
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100673
Konrad Rzeszutek Wilkd6a77ea2013-05-14 17:09:16 +0000674#ifdef CONFIG_ACPI_SLEEP
675int (*acpi_suspend_lowlevel)(void) = x86_acpi_suspend_lowlevel;
676#else
677int (*acpi_suspend_lowlevel)(void);
678#endif
679
Kenji Kaneshige1f3a6a12005-07-28 14:42:00 -0400680/*
681 * success: return IRQ number (>=0)
682 * failure: return < 0
683 */
Yinghai Lue5198072009-05-15 13:05:16 -0700684int acpi_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685{
Jiang Liu84245af2014-06-10 14:14:47 +0800686 return __acpi_register_gsi(dev, gsi, trigger, polarity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687}
Andy Shevchenko35e92b72012-10-31 22:44:48 +0100688EXPORT_SYMBOL_GPL(acpi_register_gsi);
689
690void acpi_unregister_gsi(u32 gsi)
691{
Jiang Liu6a38fa02014-06-10 14:16:27 +0800692 if (__acpi_unregister_gsi)
693 __acpi_unregister_gsi(gsi);
Andy Shevchenko35e92b72012-10-31 22:44:48 +0100694}
695EXPORT_SYMBOL_GPL(acpi_unregister_gsi);
Len Brown4be44fc2005-08-05 00:44:28 -0400696
Jiang Liu9f50c6e2014-10-27 16:11:53 +0800697#ifdef CONFIG_X86_LOCAL_APIC
Jiang Liue8198132014-06-09 16:19:36 +0800698static void __init acpi_set_irq_model_ioapic(void)
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100699{
700 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
701 __acpi_register_gsi = acpi_register_gsi_ioapic;
Jiang Liu6a38fa02014-06-10 14:16:27 +0800702 __acpi_unregister_gsi = acpi_unregister_gsi_ioapic;
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100703 acpi_ioapic = 1;
704}
Jiang Liu9f50c6e2014-10-27 16:11:53 +0800705#endif
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100706
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707/*
708 * ACPI based hotplug support for CPU
709 */
710#ifdef CONFIG_ACPI_HOTPLUG_CPU
Alex Chiangd8191fa2010-02-22 12:11:39 -0700711#include <acpi/processor.h>
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100712
Gu Zhengdc6db242016-08-25 16:35:18 +0800713int acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
Haicheng Li0271f912010-02-04 19:06:33 +0800714{
715#ifdef CONFIG_ACPI_NUMA
716 int nid;
717
718 nid = acpi_get_node(handle);
Boris Ostrovsky4370a3e2016-12-12 14:29:52 -0500719 if (nid != NUMA_NO_NODE) {
Jiang Liu896dc502014-01-20 10:31:54 +0800720 set_apicid_to_node(physid, nid);
721 numa_set_node(cpu, nid);
722 }
Haicheng Li0271f912010-02-04 19:06:33 +0800723#endif
Gu Zhengdc6db242016-08-25 16:35:18 +0800724 return 0;
Haicheng Li0271f912010-02-04 19:06:33 +0800725}
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100726
Mathias Krause4daa8322015-07-20 18:32:53 +0200727int acpi_map_cpu(acpi_handle handle, phys_cpuid_t physid, int *pcpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728{
Ashok Raj73fea172006-09-26 10:52:35 +0200729 int cpu;
730
Vitaly Kuznetsov3e9e57f2016-06-30 17:56:36 +0200731 cpu = acpi_register_lapic(physid, U32_MAX, ACPI_MADT_ENABLED);
Jiang Liu7e1f85f2013-09-02 11:57:36 +0800732 if (cpu < 0) {
733 pr_info(PREFIX "Unable to map lapic to logical cpu number\n");
734 return cpu;
Ashok Raj73fea172006-09-26 10:52:35 +0200735 }
736
Alex Chiangd8191fa2010-02-22 12:11:39 -0700737 acpi_processor_set_pdc(handle);
Haicheng Li0271f912010-02-04 19:06:33 +0800738 acpi_map_cpu2node(handle, cpu, physid);
Ashok Raj73fea172006-09-26 10:52:35 +0200739
740 *pcpu = cpu;
Jiang Liu7e1f85f2013-09-02 11:57:36 +0800741 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742}
Hanjun Guod02dc272015-01-04 18:55:03 +0800743EXPORT_SYMBOL(acpi_map_cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Hanjun Guod02dc272015-01-04 18:55:03 +0800745int acpi_unmap_cpu(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746{
Wen Congyangc4c60522013-02-22 16:33:24 -0800747#ifdef CONFIG_ACPI_NUMA
748 set_apicid_to_node(per_cpu(x86_cpu_to_apicid, cpu), NUMA_NO_NODE);
749#endif
750
Mike Travis71fff5e2007-10-19 20:35:03 +0200751 per_cpu(x86_cpu_to_apicid, cpu) = -1;
Mike Travis96289372008-12-31 18:08:46 -0800752 set_cpu_present(cpu, false);
Ashok Raj73fea172006-09-26 10:52:35 +0200753 num_processors--;
754
755 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756}
Hanjun Guod02dc272015-01-04 18:55:03 +0800757EXPORT_SYMBOL(acpi_unmap_cpu);
Len Brown4be44fc2005-08-05 00:44:28 -0400758#endif /* CONFIG_ACPI_HOTPLUG_CPU */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
Len Brown4be44fc2005-08-05 00:44:28 -0400760int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700761{
Jiang Liu7db298c2014-10-27 13:21:45 +0800762 int ret = -ENOSYS;
763#ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
764 int ioapic_id;
765 u64 addr;
766 struct ioapic_domain_cfg cfg = {
767 .type = IOAPIC_DOMAIN_DYNAMIC,
Thomas Gleixnerf7a0c782015-04-14 10:30:08 +0800768 .ops = &mp_ioapic_irqdomain_ops,
Jiang Liu7db298c2014-10-27 13:21:45 +0800769 };
770
771 ioapic_id = acpi_get_ioapic_id(handle, gsi_base, &addr);
772 if (ioapic_id < 0) {
773 unsigned long long uid;
774 acpi_status status;
775
776 status = acpi_evaluate_integer(handle, METHOD_NAME__UID,
777 NULL, &uid);
778 if (ACPI_FAILURE(status)) {
779 acpi_handle_warn(handle, "failed to get IOAPIC ID.\n");
780 return -EINVAL;
781 }
782 ioapic_id = (int)uid;
783 }
784
785 mutex_lock(&acpi_ioapic_lock);
786 ret = mp_register_ioapic(ioapic_id, phys_addr, gsi_base, &cfg);
787 mutex_unlock(&acpi_ioapic_lock);
788#endif
789
790 return ret;
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700791}
792EXPORT_SYMBOL(acpi_register_ioapic);
793
Len Brown4be44fc2005-08-05 00:44:28 -0400794int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700795{
Jiang Liu15516a32014-10-27 13:21:46 +0800796 int ret = -ENOSYS;
Len Brown4be44fc2005-08-05 00:44:28 -0400797
Jiang Liu15516a32014-10-27 13:21:46 +0800798#ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
799 mutex_lock(&acpi_ioapic_lock);
800 ret = mp_unregister_ioapic(gsi_base);
801 mutex_unlock(&acpi_ioapic_lock);
802#endif
803
804 return ret;
805}
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700806EXPORT_SYMBOL(acpi_unregister_ioapic);
807
Jiang Liue89900c2014-10-27 13:21:47 +0800808/**
809 * acpi_ioapic_registered - Check whether IOAPIC assoicatied with @gsi_base
810 * has been registered
811 * @handle: ACPI handle of the IOAPIC deivce
812 * @gsi_base: GSI base associated with the IOAPIC
813 *
814 * Assume caller holds some type of lock to serialize acpi_ioapic_registered()
815 * with acpi_register_ioapic()/acpi_unregister_ioapic().
816 */
817int acpi_ioapic_registered(acpi_handle handle, u32 gsi_base)
818{
819 int ret = 0;
820
821#ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
822 mutex_lock(&acpi_ioapic_lock);
823 ret = mp_ioapic_registered(gsi_base);
824 mutex_unlock(&acpi_ioapic_lock);
825#endif
826
827 return ret;
828}
829
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300830static int __init acpi_parse_sbf(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831{
Hanjun Guo2fad9302015-02-05 17:33:14 +0800832 struct acpi_table_boot *sb = (struct acpi_table_boot *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300834 sbf_port = sb->cmos_index; /* Save CMOS port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
836 return 0;
837}
838
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839#ifdef CONFIG_HPET_TIMER
john stultz2d0c87c2007-02-16 01:28:18 -0800840#include <asm/hpet.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
Bartlomiej Zolnierkiewiczdd96dc322013-09-30 17:29:43 +0200842static struct resource *hpet_res __initdata;
Aaron Durbina1dfd852007-07-21 17:11:39 +0200843
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300844static int __init acpi_parse_hpet(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845{
Hanjun Guo2fad9302015-02-05 17:33:14 +0800846 struct acpi_table_hpet *hpet_tbl = (struct acpi_table_hpet *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300848 if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 printk(KERN_WARNING PREFIX "HPET timers must be located in "
850 "memory.\n");
851 return -1;
852 }
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200853
john stultz2d0c87c2007-02-16 01:28:18 -0800854 hpet_address = hpet_tbl->address.address;
Suresh Siddhac8bc6f32009-08-04 12:07:09 -0700855 hpet_blockid = hpet_tbl->sequence;
Thomas Gleixnerf4df73c2007-11-15 21:41:50 -0500856
857 /*
858 * Some broken BIOSes advertise HPET at 0x0. We really do not
859 * want to allocate a resource there.
860 */
861 if (!hpet_address) {
862 printk(KERN_WARNING PREFIX
863 "HPET id: %#x base: %#lx is invalid\n",
864 hpet_tbl->id, hpet_address);
865 return 0;
866 }
867#ifdef CONFIG_X86_64
868 /*
869 * Some even more broken BIOSes advertise HPET at
870 * 0xfed0000000000000 instead of 0xfed00000. Fix it up and add
871 * some noise:
872 */
873 if (hpet_address == 0xfed0000000000000UL) {
874 if (!hpet_force_user) {
875 printk(KERN_WARNING PREFIX "HPET id: %#x "
876 "base: 0xfed0000000000000 is bogus\n "
877 "try hpet=force on the kernel command line to "
878 "fix it up to 0xfed00000.\n", hpet_tbl->id);
879 hpet_address = 0;
880 return 0;
881 }
882 printk(KERN_WARNING PREFIX
883 "HPET id: %#x base: 0xfed0000000000000 fixed up "
884 "to 0xfed00000.\n", hpet_tbl->id);
885 hpet_address >>= 32;
886 }
887#endif
Len Brown4be44fc2005-08-05 00:44:28 -0400888 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
john stultz2d0c87c2007-02-16 01:28:18 -0800889 hpet_tbl->id, hpet_address);
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200890
Aaron Durbina1dfd852007-07-21 17:11:39 +0200891 /*
892 * Allocate and initialize the HPET firmware resource for adding into
893 * the resource tree during the lateinit timeframe.
894 */
895#define HPET_RESOURCE_NAME_SIZE 9
896 hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
897
Aaron Durbina1dfd852007-07-21 17:11:39 +0200898 hpet_res->name = (void *)&hpet_res[1];
899 hpet_res->flags = IORESOURCE_MEM;
900 snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE, "HPET %u",
901 hpet_tbl->sequence);
902
903 hpet_res->start = hpet_address;
904 hpet_res->end = hpet_address + (1 * 1024) - 1;
905
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 return 0;
907}
Aaron Durbina1dfd852007-07-21 17:11:39 +0200908
909/*
910 * hpet_insert_resource inserts the HPET resources used into the resource
911 * tree.
912 */
913static __init int hpet_insert_resource(void)
914{
915 if (!hpet_res)
916 return 1;
917
918 return insert_resource(&iomem_resource, hpet_res);
919}
920
921late_initcall(hpet_insert_resource);
922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923#else
924#define acpi_parse_hpet NULL
925#endif
926
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300927static int __init acpi_parse_fadt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928{
Luis R. Rodriguez7a17b822016-04-13 17:04:42 -0700929 if (!(acpi_gbl_FADT.boot_flags & ACPI_FADT_LEGACY_DEVICES)) {
930 pr_debug("ACPI: no legacy devices present\n");
931 x86_platform.legacy.devices.pnpbios = 0;
932 }
933
Dmitry Torokhov93ffa9a2016-12-09 12:57:38 -0800934 if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID &&
935 !(acpi_gbl_FADT.boot_flags & ACPI_FADT_8042) &&
936 x86_platform.legacy.i8042 != X86_LEGACY_I8042_PLATFORM_ABSENT) {
937 pr_debug("ACPI: i8042 controller is absent\n");
938 x86_platform.legacy.i8042 = X86_LEGACY_I8042_FIRMWARE_ABSENT;
939 }
940
Luis R. Rodriguez088a8ef2016-04-13 17:04:35 -0700941 if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_CMOS_RTC) {
942 pr_debug("ACPI: not registering RTC platform device\n");
943 x86_platform.legacy.rtc = 0;
944 }
Jason Davis90660ec2005-04-16 15:24:53 -0700945
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946#ifdef CONFIG_X86_PM_TIMER
947 /* detect the location of the ACPI PM Timer */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300948 if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 /* FADT rev. 2 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300950 if (acpi_gbl_FADT.xpm_timer_block.space_id !=
Len Brown4be44fc2005-08-05 00:44:28 -0400951 ACPI_ADR_SPACE_SYSTEM_IO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 return 0;
953
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300954 pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
David Shaohua Lie6e87b42005-09-21 01:35:00 -0400955 /*
956 * "X" fields are optional extensions to the original V1.0
957 * fields, so we must selectively expand V1.0 fields if the
958 * corresponding X field is zero.
959 */
960 if (!pmtmr_ioport)
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300961 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 } else {
963 /* FADT rev. 1 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300964 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 }
966 if (pmtmr_ioport)
Len Brown4be44fc2005-08-05 00:44:28 -0400967 printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
968 pmtmr_ioport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969#endif
970 return 0;
971}
972
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973#ifdef CONFIG_X86_LOCAL_APIC
974/*
975 * Parse LAPIC entries in MADT
976 * returns 0 on success, < 0 on error
977 */
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400978
Yinghai Lucbf9bd62008-02-19 03:21:06 -0800979static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
980{
981 int count;
982
Borislav Petkov93984fb2016-04-04 22:25:00 +0200983 if (!boot_cpu_has(X86_FEATURE_APIC))
Yinghai Lucbf9bd62008-02-19 03:21:06 -0800984 return -ENODEV;
985
986 /*
987 * Note that the LAPIC address is obtained from the MADT (32-bit value)
Adam Buchbinder6a6256f2016-02-23 15:34:30 -0800988 * and (optionally) overridden by a LAPIC_ADDR_OVR entry (64-bit value).
Yinghai Lucbf9bd62008-02-19 03:21:06 -0800989 */
990
Jiang Liue8198132014-06-09 16:19:36 +0800991 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
992 acpi_parse_lapic_addr_ovr, 0);
Yinghai Lucbf9bd62008-02-19 03:21:06 -0800993 if (count < 0) {
994 printk(KERN_ERR PREFIX
995 "Error parsing LAPIC address override entry\n");
996 return count;
997 }
998
Yinghai Luc0104d32010-12-07 00:55:17 -0800999 register_lapic_address(acpi_lapic_addr);
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001000
1001 return count;
1002}
1003
Len Brown4be44fc2005-08-05 00:44:28 -04001004static int __init acpi_parse_madt_lapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005{
1006 int count;
Suresh Siddha7237d3d2009-03-30 13:55:30 -08001007 int x2count = 0;
Lukasz Anaczkowskid81056b2015-09-09 15:47:29 +02001008 int ret;
1009 struct acpi_subtable_proc madt_proc[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
Borislav Petkov93984fb2016-04-04 22:25:00 +02001011 if (!boot_cpu_has(X86_FEATURE_APIC))
Andi Kleen0fcd2702006-04-11 12:54:36 +02001012 return -ENODEV;
1013
Jack Steinerac049c12008-03-28 14:12:09 -05001014 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
Yinghai Lucb2ded32011-01-04 16:38:52 -08001015 acpi_parse_sapic, MAX_LOCAL_APIC);
Jack Steinerac049c12008-03-28 14:12:09 -05001016
Suresh Siddha7237d3d2009-03-30 13:55:30 -08001017 if (!count) {
Lukasz Anaczkowskid81056b2015-09-09 15:47:29 +02001018 memset(madt_proc, 0, sizeof(madt_proc));
1019 madt_proc[0].id = ACPI_MADT_TYPE_LOCAL_APIC;
1020 madt_proc[0].handler = acpi_parse_lapic;
1021 madt_proc[1].id = ACPI_MADT_TYPE_LOCAL_X2APIC;
1022 madt_proc[1].handler = acpi_parse_x2apic;
1023 ret = acpi_table_parse_entries_array(ACPI_SIG_MADT,
1024 sizeof(struct acpi_table_madt),
1025 madt_proc, ARRAY_SIZE(madt_proc), MAX_LOCAL_APIC);
1026 if (ret < 0) {
1027 printk(KERN_ERR PREFIX
1028 "Error parsing LAPIC/X2APIC entries\n");
1029 return ret;
1030 }
1031
Al Stonec12f29a2016-08-19 17:24:02 -06001032 count = madt_proc[0].count;
1033 x2count = madt_proc[1].count;
Suresh Siddha7237d3d2009-03-30 13:55:30 -08001034 }
1035 if (!count && !x2count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
1037 /* TBD: Cleanup to allow fallback to MPS */
1038 return -ENODEV;
Suresh Siddha7237d3d2009-03-30 13:55:30 -08001039 } else if (count < 0 || x2count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
1041 /* TBD: Cleanup to allow fallback to MPS */
1042 return count;
1043 }
1044
Jiang Liue8198132014-06-09 16:19:36 +08001045 x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI,
1046 acpi_parse_x2apic_nmi, 0);
1047 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI,
1048 acpi_parse_lapic_nmi, 0);
Suresh Siddha7237d3d2009-03-30 13:55:30 -08001049 if (count < 0 || x2count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
1051 /* TBD: Cleanup to allow fallback to MPS */
1052 return count;
1053 }
1054 return 0;
1055}
Len Brown4be44fc2005-08-05 00:44:28 -04001056#endif /* CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Len Brown84663612005-08-24 12:09:07 -04001058#ifdef CONFIG_X86_IO_APIC
Jiang Liua491cc9022014-06-09 16:19:32 +08001059static void __init mp_config_acpi_legacy_irqs(void)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001060{
Yinghai Lu6df88092008-06-15 18:19:46 -07001061 int i;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301062 struct mpc_intsrc mp_irq;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001063
Paul Gortmakerbb8187d2012-05-17 19:06:13 -04001064#ifdef CONFIG_EISA
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001065 /*
1066 * Fabricate the legacy ISA bus (bus #31).
1067 */
1068 mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
1069#endif
1070 set_bit(MP_ISA_BUS, mp_bus_not_pci);
Thomas Gleixnercfc1b9a2008-07-21 21:35:38 +02001071 pr_debug("Bus #%d is ISA\n", MP_ISA_BUS);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001072
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001073 /*
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001074 * Use the default configuration for the IRQs 0-15. Unless
1075 * overridden by (MADT) interrupt source override entries.
1076 */
Jiang Liu95d76ac2014-06-09 16:19:48 +08001077 for (i = 0; i < nr_legacy_irqs(); i++) {
Eric W. Biederman0fd52672010-03-30 01:07:06 -07001078 int ioapic, pin;
1079 unsigned int dstapic;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001080 int idx;
Eric W. Biederman0fd52672010-03-30 01:07:06 -07001081 u32 gsi;
1082
1083 /* Locate the gsi that irq i maps to. */
1084 if (acpi_isa_irq_to_gsi(i, &gsi))
1085 continue;
1086
1087 /*
1088 * Locate the IOAPIC that manages the ISA IRQ.
1089 */
1090 ioapic = mp_find_ioapic(gsi);
1091 if (ioapic < 0)
1092 continue;
1093 pin = mp_find_ioapic_pin(ioapic, gsi);
Suresh Siddhad5371432011-05-18 16:31:37 -07001094 dstapic = mpc_ioapic_id(ioapic);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001095
1096 for (idx = 0; idx < mp_irq_entries; idx++) {
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301097 struct mpc_intsrc *irq = mp_irqs + idx;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001098
1099 /* Do we already have a mapping for this ISA IRQ? */
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301100 if (irq->srcbus == MP_ISA_BUS && irq->srcbusirq == i)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001101 break;
1102
1103 /* Do we already have a mapping for this IOAPIC pin */
Eric W. Biederman0fd52672010-03-30 01:07:06 -07001104 if (irq->dstapic == dstapic && irq->dstirq == pin)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001105 break;
1106 }
1107
1108 if (idx != mp_irq_entries) {
1109 printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
1110 continue; /* IRQ already used */
1111 }
1112
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301113 mp_irq.type = MP_INTSRC;
1114 mp_irq.irqflag = 0; /* Conforming */
1115 mp_irq.srcbus = MP_ISA_BUS;
1116 mp_irq.dstapic = dstapic;
1117 mp_irq.irqtype = mp_INT;
1118 mp_irq.srcbusirq = i; /* Identity mapped */
Eric W. Biederman0fd52672010-03-30 01:07:06 -07001119 mp_irq.dstirq = pin;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001120
Feng Tang2d8009b2010-11-19 11:33:35 +08001121 mp_save_irq(&mp_irq);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001122 }
1123}
1124
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125/*
1126 * Parse IOAPIC related entries in MADT
1127 * returns 0 on success, < 0 on error
1128 */
Len Brown4be44fc2005-08-05 00:44:28 -04001129static int __init acpi_parse_madt_ioapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130{
1131 int count;
1132
1133 /*
1134 * ACPI interpreter is required to complete interrupt setup,
1135 * so if it is off, don't enumerate the io-apics with ACPI.
1136 * If MPS is present, it will handle them,
1137 * otherwise the system will stay in PIC mode
1138 */
Jeremy Fitzhardinge6b2b1712009-06-08 02:53:50 -07001139 if (acpi_disabled || acpi_noirq)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
Borislav Petkov93984fb2016-04-04 22:25:00 +02001142 if (!boot_cpu_has(X86_FEATURE_APIC))
Andi Kleend3b6a342006-04-07 19:49:39 +02001143 return -ENODEV;
1144
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001146 * if "noapic" boot option, don't look for IO-APICs
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 */
1148 if (skip_ioapic_setup) {
1149 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
Len Brown4be44fc2005-08-05 00:44:28 -04001150 "due to 'noapic' option.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 return -ENODEV;
1152 }
1153
Jiang Liue8198132014-06-09 16:19:36 +08001154 count = acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
1155 MAX_IO_APICS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 if (!count) {
1157 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
1158 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -04001159 } else if (count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
1161 return count;
1162 }
1163
Jiang Liue8198132014-06-09 16:19:36 +08001164 count = acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE,
1165 acpi_parse_int_src_ovr, nr_irqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 if (count < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -04001167 printk(KERN_ERR PREFIX
1168 "Error parsing interrupt source overrides entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 /* TBD: Cleanup to allow fallback to MPS */
1170 return count;
1171 }
1172
1173 /*
1174 * If BIOS did not supply an INT_SRC_OVR for the SCI
1175 * pretend we got one so we can set the SCI flags.
1176 */
1177 if (!acpi_sci_override_gsi)
Eric W. Biederman9d2062b2010-03-30 01:07:05 -07001178 acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0,
1179 acpi_gbl_FADT.sci_interrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001181 /* Fill in identity legacy mappings where no override */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 mp_config_acpi_legacy_irqs();
1183
Jiang Liue8198132014-06-09 16:19:36 +08001184 count = acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE,
1185 acpi_parse_nmi_src, nr_irqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 if (count < 0) {
1187 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
1188 /* TBD: Cleanup to allow fallback to MPS */
1189 return count;
1190 }
1191
1192 return 0;
1193}
1194#else
1195static inline int acpi_parse_madt_ioapic_entries(void)
1196{
1197 return -1;
1198}
Len Brown84663612005-08-24 12:09:07 -04001199#endif /* !CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001201static void __init early_acpi_process_madt(void)
1202{
1203#ifdef CONFIG_X86_LOCAL_APIC
1204 int error;
1205
1206 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1207
1208 /*
1209 * Parse MADT LAPIC entries
1210 */
1211 error = early_acpi_parse_madt_lapic_addr_ovr();
1212 if (!error) {
1213 acpi_lapic = 1;
1214 smp_found_config = 1;
1215 }
1216 if (error == -EINVAL) {
1217 /*
1218 * Dell Precision Workstation 410, 610 come here.
1219 */
1220 printk(KERN_ERR PREFIX
1221 "Invalid BIOS MADT, disabling ACPI\n");
1222 disable_acpi();
1223 }
1224 }
1225#endif
1226}
1227
Len Brown4be44fc2005-08-05 00:44:28 -04001228static void __init acpi_process_madt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229{
1230#ifdef CONFIG_X86_LOCAL_APIC
Len Brown7f8f97c2007-02-10 21:28:03 -05001231 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
Len Brown7f8f97c2007-02-10 21:28:03 -05001233 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
1235 /*
1236 * Parse MADT LAPIC entries
1237 */
1238 error = acpi_parse_madt_lapic_entries();
1239 if (!error) {
1240 acpi_lapic = 1;
1241
1242 /*
1243 * Parse MADT IO-APIC entries
1244 */
Jiang Liu5da2fd22014-11-02 14:04:29 +08001245 mutex_lock(&acpi_ioapic_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 error = acpi_parse_madt_ioapic_entries();
Jiang Liu5da2fd22014-11-02 14:04:29 +08001247 mutex_unlock(&acpi_ioapic_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 if (!error) {
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +01001249 acpi_set_irq_model_ioapic();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
1251 smp_found_config = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 }
1253 }
1254 if (error == -EINVAL) {
1255 /*
1256 * Dell Precision Workstation 410, 610 come here.
1257 */
Len Brown4be44fc2005-08-05 00:44:28 -04001258 printk(KERN_ERR PREFIX
1259 "Invalid BIOS MADT, disabling ACPI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 disable_acpi();
1261 }
Len Brown7b37b5f2008-12-23 01:47:42 -05001262 } else {
1263 /*
1264 * ACPI found no MADT, and so ACPI wants UP PIC mode.
1265 * In the event an MPS table was found, forget it.
1266 * Boot with "acpi=off" to use MPS on such a system.
1267 */
1268 if (smp_found_config) {
1269 printk(KERN_WARNING PREFIX
1270 "No APIC-table, disabling MPS\n");
1271 smp_found_config = 0;
1272 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 }
Yinghai Lu69b88af2008-12-05 22:45:50 -08001274
1275 /*
1276 * ACPI supports both logical (e.g. Hyper-Threading) and physical
1277 * processors, where MPS only supports physical.
1278 */
1279 if (acpi_lapic && acpi_ioapic)
1280 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
1281 "information\n");
1282 else if (acpi_lapic)
1283 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
1284 "configuration information\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285#endif
1286 return;
1287}
1288
Jeff Garzik18552562007-10-03 15:15:40 -04001289static int __init disable_acpi_irq(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001290{
1291 if (!acpi_force) {
1292 printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
1293 d->ident);
1294 acpi_noirq_set();
1295 }
1296 return 0;
1297}
1298
Jeff Garzik18552562007-10-03 15:15:40 -04001299static int __init disable_acpi_pci(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001300{
1301 if (!acpi_force) {
1302 printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
1303 d->ident);
1304 acpi_disable_pci();
1305 }
1306 return 0;
1307}
Andrey Paninaea00142005-06-25 14:54:42 -07001308
Jeff Garzik18552562007-10-03 15:15:40 -04001309static int __init dmi_disable_acpi(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001310{
1311 if (!acpi_force) {
Len Brown4be44fc2005-08-05 00:44:28 -04001312 printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
Andrey Paninaea00142005-06-25 14:54:42 -07001313 disable_acpi();
1314 } else {
1315 printk(KERN_NOTICE
1316 "Warning: DMI blacklist says broken, but acpi forced\n");
1317 }
1318 return 0;
1319}
1320
1321/*
Feng Tangae10ccd2012-06-04 15:00:04 +08001322 * Force ignoring BIOS IRQ0 override
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001323 */
1324static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
1325{
Ingo Molnar8d89adf2008-10-07 06:47:52 +02001326 if (!acpi_skip_timer_override) {
Feng Tangae10ccd2012-06-04 15:00:04 +08001327 pr_notice("%s detected: Ignoring BIOS IRQ0 override\n",
Ingo Molnar8d89adf2008-10-07 06:47:52 +02001328 d->ident);
1329 acpi_skip_timer_override = 1;
1330 }
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001331 return 0;
1332}
1333
1334/*
Li, Aubrey74863412015-03-11 16:09:00 +08001335 * ACPI offers an alternative platform interface model that removes
1336 * ACPI hardware requirements for platforms that do not implement
1337 * the PC Architecture.
1338 *
1339 * We initialize the Hardware-reduced ACPI model here:
1340 */
1341static void __init acpi_reduced_hw_init(void)
1342{
1343 if (acpi_gbl_reduced_hardware) {
1344 /*
1345 * Override x86_init functions and bypass legacy pic
1346 * in Hardware-reduced ACPI mode
1347 */
1348 x86_init.timers.timer_init = x86_init_noop;
1349 x86_init.irqs.pre_vector_init = x86_init_noop;
1350 legacy_pic = &null_legacy_pic;
1351 }
1352}
1353
1354/*
Andrey Paninaea00142005-06-25 14:54:42 -07001355 * If your system is blacklisted here, but you find that acpi=force
Zhang Rui5b4c0b62009-04-01 01:49:42 -04001356 * works for you, please contact linux-acpi@vger.kernel.org
Andrey Paninaea00142005-06-25 14:54:42 -07001357 */
1358static struct dmi_system_id __initdata acpi_dmi_table[] = {
1359 /*
1360 * Boxes that need ACPI disabled
1361 */
1362 {
Len Brown4be44fc2005-08-05 00:44:28 -04001363 .callback = dmi_disable_acpi,
1364 .ident = "IBM Thinkpad",
1365 .matches = {
1366 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1367 DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
1368 },
1369 },
Andrey Paninaea00142005-06-25 14:54:42 -07001370
1371 /*
Andrey Paninaea00142005-06-25 14:54:42 -07001372 * Boxes that need ACPI PCI IRQ routing disabled
1373 */
1374 {
Len Brown4be44fc2005-08-05 00:44:28 -04001375 .callback = disable_acpi_irq,
1376 .ident = "ASUS A7V",
1377 .matches = {
1378 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
1379 DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
1380 /* newer BIOS, Revision 1011, does work */
1381 DMI_MATCH(DMI_BIOS_VERSION,
1382 "ASUS A7V ACPI BIOS Revision 1007"),
1383 },
1384 },
Len Brown74586fc2007-03-08 02:48:30 -05001385 {
1386 /*
1387 * Latest BIOS for IBM 600E (1.16) has bad pcinum
1388 * for LPC bridge, which is needed for the PCI
1389 * interrupt links to work. DSDT fix is in bug 5966.
1390 * 2645, 2646 model numbers are shared with 600/600E/600X
1391 */
1392 .callback = disable_acpi_irq,
1393 .ident = "IBM Thinkpad 600 Series 2645",
1394 .matches = {
1395 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1396 DMI_MATCH(DMI_BOARD_NAME, "2645"),
1397 },
1398 },
1399 {
1400 .callback = disable_acpi_irq,
1401 .ident = "IBM Thinkpad 600 Series 2646",
1402 .matches = {
1403 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1404 DMI_MATCH(DMI_BOARD_NAME, "2646"),
1405 },
1406 },
Andrey Paninaea00142005-06-25 14:54:42 -07001407 /*
1408 * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
1409 */
Len Brown4be44fc2005-08-05 00:44:28 -04001410 { /* _BBN 0 bug */
1411 .callback = disable_acpi_pci,
1412 .ident = "ASUS PR-DLS",
1413 .matches = {
1414 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1415 DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
1416 DMI_MATCH(DMI_BIOS_VERSION,
1417 "ASUS PR-DLS ACPI BIOS Revision 1010"),
1418 DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
1419 },
1420 },
Andrey Paninaea00142005-06-25 14:54:42 -07001421 {
Len Brown4be44fc2005-08-05 00:44:28 -04001422 .callback = disable_acpi_pci,
1423 .ident = "Acer TravelMate 36x Laptop",
1424 .matches = {
1425 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
1426 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
1427 },
1428 },
Andreas Herrmann35af2822008-10-22 13:08:31 +02001429 {}
1430};
1431
1432/* second table for DMI checks that should run after early-quirks */
1433static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
Matthew Garrett9340e1c2008-07-01 01:12:06 +01001434 /*
1435 * HP laptops which use a DSDT reporting as HP/SB400/10000,
1436 * which includes some code which overrides all temperature
1437 * trip points to 16C if the INTIN2 input of the I/O APIC
1438 * is enabled. This input is incorrectly designated the
1439 * ISA IRQ 0 via an interrupt source override even though
1440 * it is wired to the output of the master 8259A and INTIN0
Feng Tangae10ccd2012-06-04 15:00:04 +08001441 * is not connected at all. Force ignoring BIOS IRQ0
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001442 * override in that cases.
1443 */
1444 {
1445 .callback = dmi_ignore_irq0_timer_override,
Rafael J. Wysockie84956f2008-10-06 11:59:29 +02001446 .ident = "HP nx6115 laptop",
1447 .matches = {
1448 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1449 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6115"),
1450 },
1451 },
1452 {
1453 .callback = dmi_ignore_irq0_timer_override,
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001454 .ident = "HP NX6125 laptop",
1455 .matches = {
1456 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1457 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
1458 },
1459 },
1460 {
1461 .callback = dmi_ignore_irq0_timer_override,
1462 .ident = "HP NX6325 laptop",
1463 .matches = {
1464 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1465 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
1466 },
1467 },
Rafael J. Wysockie84956f2008-10-06 11:59:29 +02001468 {
1469 .callback = dmi_ignore_irq0_timer_override,
1470 .ident = "HP 6715b laptop",
1471 .matches = {
1472 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1473 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
1474 },
1475 },
Feng Tangf6b54f02012-06-04 15:00:06 +08001476 {
1477 .callback = dmi_ignore_irq0_timer_override,
1478 .ident = "FUJITSU SIEMENS",
1479 .matches = {
1480 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
1481 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO PRO V2030"),
1482 },
1483 },
Len Brown4be44fc2005-08-05 00:44:28 -04001484 {}
Andrey Paninaea00142005-06-25 14:54:42 -07001485};
1486
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487/*
1488 * acpi_boot_table_init() and acpi_boot_init()
1489 * called from setup_arch(), always.
1490 * 1. checksums all tables
1491 * 2. enumerates lapics
1492 * 3. enumerates io-apics
1493 *
1494 * acpi_table_init() is separate to allow reading SRAT without
1495 * other side effects.
1496 *
1497 * side effects of acpi_boot_init:
1498 * acpi_lapic = 1 if LAPIC found
1499 * acpi_ioapic = 1 if IOAPIC found
1500 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
1501 * if acpi_blacklisted() acpi_disabled = 1;
1502 * acpi_irq_model=...
1503 * ...
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 */
1505
Len Brown8558e392010-01-06 16:11:06 -05001506void __init acpi_boot_table_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507{
Andrey Paninaea00142005-06-25 14:54:42 -07001508 dmi_check_system(acpi_dmi_table);
Andrey Paninaea00142005-06-25 14:54:42 -07001509
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 /*
1511 * If acpi_disabled, bail out
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 */
Len Brown68ca4062010-02-19 00:09:22 -05001513 if (acpi_disabled)
Al Stone0f61aaa2016-08-19 17:24:01 -06001514 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001516 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 * Initialize the ACPI boot-time table parser.
1518 */
Len Brown8558e392010-01-06 16:11:06 -05001519 if (acpi_table_init()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 disable_acpi();
Len Brown8558e392010-01-06 16:11:06 -05001521 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001524 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
1526 /*
1527 * blacklist may disable ACPI entirely
1528 */
Len Brown8558e392010-01-06 16:11:06 -05001529 if (acpi_blacklisted()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 if (acpi_force) {
1531 printk(KERN_WARNING PREFIX "acpi=force override\n");
1532 } else {
1533 printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
1534 disable_acpi();
Len Brown8558e392010-01-06 16:11:06 -05001535 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 }
1537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538}
1539
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001540int __init early_acpi_boot_init(void)
1541{
1542 /*
1543 * If acpi_disabled, bail out
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001544 */
Len Brown68ca4062010-02-19 00:09:22 -05001545 if (acpi_disabled)
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001546 return 1;
1547
1548 /*
1549 * Process the Multiple APIC Description Table (MADT), if present
1550 */
1551 early_acpi_process_madt();
1552
Li, Aubrey74863412015-03-11 16:09:00 +08001553 /*
1554 * Hardware-reduced ACPI mode initialization:
1555 */
1556 acpi_reduced_hw_init();
1557
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001558 return 0;
1559}
1560
Dave Young7b0a9112017-01-31 13:21:40 +00001561static int __init acpi_parse_bgrt(struct acpi_table_header *table)
1562{
1563 efi_bgrt_init(table);
1564 return 0;
1565}
1566
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567int __init acpi_boot_init(void)
1568{
Andreas Herrmann35af2822008-10-22 13:08:31 +02001569 /* those are executed after early-quirks are executed */
1570 dmi_check_system(acpi_dmi_table_late);
1571
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 /*
1573 * If acpi_disabled, bail out
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 */
Len Brown68ca4062010-02-19 00:09:22 -05001575 if (acpi_disabled)
Len Brown4be44fc2005-08-05 00:44:28 -04001576 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001578 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579
1580 /*
1581 * set sci_int and PM timer address
1582 */
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +03001583 acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
1585 /*
1586 * Process the Multiple APIC Description Table (MADT), if present
1587 */
1588 acpi_process_madt();
1589
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001590 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
Dave Young7b0a9112017-01-31 13:21:40 +00001591 if (IS_ENABLED(CONFIG_ACPI_BGRT))
1592 acpi_table_parse(ACPI_SIG_BGRT, acpi_parse_bgrt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
Thomas Gleixnerb72d0db2009-08-29 16:24:51 +02001594 if (!acpi_noirq)
1595 x86_init.pci.init = pci_acpi_init;
1596
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 return 0;
1598}
Rusty Russell1a3f2392006-09-26 10:52:32 +02001599
1600static int __init parse_acpi(char *arg)
1601{
1602 if (!arg)
1603 return -EINVAL;
1604
1605 /* "acpi=off" disables both ACPI table parsing and interpreter */
1606 if (strcmp(arg, "off") == 0) {
1607 disable_acpi();
1608 }
1609 /* acpi=force to over-ride black-list */
1610 else if (strcmp(arg, "force") == 0) {
1611 acpi_force = 1;
Rusty Russell1a3f2392006-09-26 10:52:32 +02001612 acpi_disabled = 0;
1613 }
1614 /* acpi=strict disables out-of-spec workarounds */
1615 else if (strcmp(arg, "strict") == 0) {
1616 acpi_strict = 1;
1617 }
Zhao Yakui237889b2008-12-17 16:55:18 +08001618 /* acpi=rsdt use RSDT instead of XSDT */
1619 else if (strcmp(arg, "rsdt") == 0) {
Lv Zhengfab46102014-01-08 13:43:40 +08001620 acpi_gbl_do_not_use_xsdt = TRUE;
Zhao Yakui237889b2008-12-17 16:55:18 +08001621 }
Rusty Russell1a3f2392006-09-26 10:52:32 +02001622 /* "acpi=noirq" disables ACPI interrupt routing */
1623 else if (strcmp(arg, "noirq") == 0) {
1624 acpi_noirq_set();
Lin Mingaa2110c2010-04-08 14:34:27 +08001625 }
1626 /* "acpi=copy_dsdt" copys DSDT */
1627 else if (strcmp(arg, "copy_dsdt") == 0) {
1628 acpi_gbl_copy_dsdt_locally = 1;
Naveen N. Rao9ad95872013-07-01 21:08:54 +05301629 }
1630 /* "acpi=nocmcff" disables FF mode for corrected errors */
1631 else if (strcmp(arg, "nocmcff") == 0) {
1632 acpi_disable_cmcff = 1;
Rusty Russell1a3f2392006-09-26 10:52:32 +02001633 } else {
1634 /* Core will printk when we return error. */
1635 return -EINVAL;
1636 }
1637 return 0;
1638}
1639early_param("acpi", parse_acpi);
1640
1641/* FIXME: Using pci= for an ACPI parameter is a travesty. */
1642static int __init parse_pci(char *arg)
1643{
1644 if (arg && strcmp(arg, "noacpi") == 0)
1645 acpi_disable_pci();
1646 return 0;
1647}
1648early_param("pci", parse_pci);
1649
Yinghai Lu3c999f12008-06-20 16:11:20 -07001650int __init acpi_mps_check(void)
1651{
1652#if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
1653/* mptable code is not built-in*/
1654 if (acpi_disabled || acpi_noirq) {
1655 printk(KERN_WARNING "MPS support code is not built-in.\n"
1656 "Using acpi=off or acpi=noirq or pci=noacpi "
1657 "may have problem\n");
1658 return 1;
1659 }
1660#endif
1661 return 0;
1662}
1663
Rusty Russell1a3f2392006-09-26 10:52:32 +02001664#ifdef CONFIG_X86_IO_APIC
1665static int __init parse_acpi_skip_timer_override(char *arg)
1666{
1667 acpi_skip_timer_override = 1;
1668 return 0;
1669}
1670early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
Andi Kleenfa18f472006-11-14 16:57:46 +01001671
1672static int __init parse_acpi_use_timer_override(char *arg)
1673{
1674 acpi_use_timer_override = 1;
1675 return 0;
1676}
1677early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001678#endif /* CONFIG_X86_IO_APIC */
1679
1680static int __init setup_acpi_sci(char *s)
1681{
1682 if (!s)
1683 return -EINVAL;
1684 if (!strcmp(s, "edge"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001685 acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
1686 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001687 else if (!strcmp(s, "level"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001688 acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
1689 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001690 else if (!strcmp(s, "high"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001691 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
1692 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001693 else if (!strcmp(s, "low"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001694 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
1695 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001696 else
1697 return -EINVAL;
1698 return 0;
1699}
1700early_param("acpi_sci", setup_acpi_sci);
Andrew Mortond0a90812006-10-20 14:30:27 -07001701
1702int __acpi_acquire_global_lock(unsigned int *lock)
1703{
1704 unsigned int old, new, val;
1705 do {
1706 old = *lock;
1707 new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
1708 val = cmpxchg(lock, old, new);
1709 } while (unlikely (val != old));
1710 return (new < 3) ? -1 : 0;
1711}
1712
1713int __acpi_release_global_lock(unsigned int *lock)
1714{
1715 unsigned int old, new, val;
1716 do {
1717 old = *lock;
1718 new = old & ~0x3;
1719 val = cmpxchg(lock, old, new);
1720 } while (unlikely (val != old));
1721 return old & 0x1;
1722}
Thomas Renninger8e305242012-10-01 00:23:53 +02001723
1724void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
1725{
1726 e820_add_region(addr, size, E820_ACPI);
1727 update_e820();
1728}