blob: 7d668d172fce065afb3cfe97d5488f27a3ed3ef5 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Thomas Gleixnerf7a0c782015-04-14 10:30:08 +080039#include <asm/irqdomain.h>
Thomas Gleixnerb72d0db2009-08-29 16:24:51 +020040#include <asm/pci_x86.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <asm/pgtable.h>
42#include <asm/io_apic.h>
43#include <asm/apic.h>
44#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <asm/mpspec.h>
Alexey Starikovskiydfac2182008-04-04 23:41:50 +040046#include <asm/smp.h>
Jiang Liu95d76ac2014-06-09 16:19:48 +080047#include <asm/i8259.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Konrad Rzeszutek Wilkd6a77ea2013-05-14 17:09:16 +000049#include "sleep.h" /* To include x86_acpi_suspend_lowlevel */
Adrian Bunke8924ac2006-09-26 10:52:35 +020050static int __initdata acpi_force = 0;
Len Brownc636f752009-05-19 23:47:38 -040051int acpi_disabled;
Andi Kleendf3bb572006-09-26 10:52:33 +020052EXPORT_SYMBOL(acpi_disabled);
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#ifdef CONFIG_X86_64
Ingo Molnar1dcdd3d2009-01-28 17:55:37 +010055# include <asm/proto.h>
Len Brown4be44fc2005-08-05 00:44:28 -040056#endif /* X86 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#define PREFIX "ACPI: "
59
Andrew Morton90d53902006-11-02 22:07:18 -080060int acpi_noirq; /* skip ACPI IRQ initialization */
Yinghai Lu6e4be1ff2008-02-05 00:01:48 -080061int acpi_pci_disabled; /* skip ACPI PCI scan and IRQ initialization */
62EXPORT_SYMBOL(acpi_pci_disabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64int acpi_lapic;
65int acpi_ioapic;
66int acpi_strict;
Naveen N. Rao9ad95872013-07-01 21:08:54 +053067int acpi_disable_cmcff;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +030069u8 acpi_sci_flags __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070int acpi_sci_override_gsi __initdata;
71int acpi_skip_timer_override __initdata;
Andi Kleenfa18f472006-11-14 16:57:46 +010072int acpi_use_timer_override __initdata;
Andreas Herrmann7f74f8f2011-02-24 15:53:46 +010073int acpi_fix_pin2_polarity __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75#ifdef CONFIG_X86_LOCAL_APIC
76static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
77#endif
78
Jiang Liu5da2fd22014-11-02 14:04:29 +080079/*
80 * Locks related to IOAPIC hotplug
81 * Hotplug side:
82 * ->device_hotplug_lock
83 * ->acpi_ioapic_lock
84 * ->ioapic_lock
85 * Interrupt mapping side:
86 * ->acpi_ioapic_lock
87 * ->ioapic_mutex
88 * ->ioapic_lock
89 */
90static DEFINE_MUTEX(acpi_ioapic_lock);
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092/* --------------------------------------------------------------------------
93 Boot-time Configuration
94 -------------------------------------------------------------------------- */
95
96/*
97 * The default interrupt routing model is PIC (8259). This gets
Simon Arlott27b46d72007-10-20 01:13:56 +020098 * overridden if IOAPICs are enumerated (below).
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 */
Len Brown4be44fc2005-08-05 00:44:28 -0400100enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103/*
Eric W. Biederman988856e2010-03-30 01:07:15 -0700104 * ISA irqs by default are the first 16 gsis but can be
105 * any gsi as specified by an interrupt source override.
106 */
107static u32 isa_irq_to_gsi[NR_IRQS_LEGACY] __read_mostly = {
108 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
109};
110
Jiang Liu2c0a6892014-06-10 14:11:23 +0800111#define ACPI_INVALID_GSI INT_MIN
Eric W. Biederman988856e2010-03-30 01:07:15 -0700112
113/*
Zhang Yanfei45f13302013-07-23 21:03:24 +0800114 * This is just a simple wrapper around early_ioremap(),
115 * with sanity checks for phys == 0 and size == 0.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 */
Jan Beulich2fdf0742007-12-13 08:33:59 +0000117char *__init __acpi_map_table(unsigned long phys, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Yinghai Luf34fa822008-07-09 20:16:36 -0700120 if (!phys || !size)
121 return NULL;
122
Yinghai Lu7d972772009-02-07 15:39:41 -0800123 return early_ioremap(phys, size);
124}
Zhang Yanfei45f13302013-07-23 21:03:24 +0800125
Yinghai Lu7d972772009-02-07 15:39:41 -0800126void __init __acpi_unmap_table(char *map, unsigned long size)
127{
128 if (!map || !size)
129 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Yinghai Lu7d972772009-02-07 15:39:41 -0800131 early_iounmap(map, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#ifdef CONFIG_X86_LOCAL_APIC
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300135static int __init acpi_parse_madt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
Len Brown4be44fc2005-08-05 00:44:28 -0400137 struct acpi_table_madt *madt = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Borislav Petkov93984fb2016-04-04 22:25:00 +0200139 if (!boot_cpu_has(X86_FEATURE_APIC))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 return -EINVAL;
141
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300142 madt = (struct acpi_table_madt *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 if (!madt) {
144 printk(KERN_WARNING PREFIX "Unable to map MADT\n");
145 return -ENODEV;
146 }
147
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300148 if (madt->address) {
149 acpi_lapic_addr = (u64) madt->address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151 printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300152 madt->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 }
154
Ingo Molnar306db032009-01-28 03:43:47 +0100155 default_acpi_madt_oem_check(madt->header.oem_id,
156 madt->header.oem_table_id);
Len Brown4be44fc2005-08-05 00:44:28 -0400157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 return 0;
159}
160
Jiang Liu7e1f85f2013-09-02 11:57:36 +0800161/**
162 * acpi_register_lapic - register a local apic and generates a logic cpu number
163 * @id: local apic id to register
Vitaly Kuznetsov3e9e57f2016-06-30 17:56:36 +0200164 * @acpiid: ACPI id to register
Jiang Liu7e1f85f2013-09-02 11:57:36 +0800165 * @enabled: this cpu is enabled or not
166 *
167 * Returns the logic cpu number which maps to the local apic
168 */
Vitaly Kuznetsov3e9e57f2016-06-30 17:56:36 +0200169static int acpi_register_lapic(int id, u32 acpiid, u8 enabled)
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400170{
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700171 unsigned int ver = 0;
Vitaly Kuznetsov3e9e57f2016-06-30 17:56:36 +0200172 int cpu;
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700173
Tang Chen82982d72013-07-23 16:00:19 +0800174 if (id >= MAX_LOCAL_APIC) {
Yinghai Lud3bd0582010-12-16 19:09:58 -0800175 printk(KERN_INFO PREFIX "skipped apicid that is too big\n");
Jiang Liu7e1f85f2013-09-02 11:57:36 +0800176 return -EINVAL;
Yinghai Lud3bd0582010-12-16 19:09:58 -0800177 }
178
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700179 if (boot_cpu_physical_apicid != -1U)
Denys Vlasenkocff9ab22016-09-13 20:12:32 +0200180 ver = boot_cpu_apic_version;
Yinghai Lufb3bbd62008-05-22 18:22:30 -0700181
Gu Zheng8f549692016-08-25 16:35:16 +0800182 cpu = __generic_processor_info(id, ver, enabled);
Vitaly Kuznetsov3e9e57f2016-06-30 17:56:36 +0200183 if (cpu >= 0)
184 early_per_cpu(x86_cpu_to_acpiid, cpu) = acpiid;
185
186 return cpu;
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400187}
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189static int __init
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800190acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
191{
192 struct acpi_madt_local_x2apic *processor = NULL;
Yinghai Lua35fd282011-12-21 17:45:16 -0800193 int apic_id;
194 u8 enabled;
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800195
196 processor = (struct acpi_madt_local_x2apic *)header;
197
198 if (BAD_MADT_ENTRY(processor, end))
199 return -EINVAL;
200
201 acpi_table_print_madt_entry(header);
202
Yinghai Lua35fd282011-12-21 17:45:16 -0800203 apic_id = processor->local_apic_id;
204 enabled = processor->lapic_flags & ACPI_MADT_ENABLED;
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800205#ifdef CONFIG_X86_X2APIC
206 /*
207 * We need to register disabled CPU as well to permit
208 * counting disabled CPUs. This allows us to size
209 * cpus_possible_map more accurately, to permit
210 * to not preallocating memory for all NR_CPUS
211 * when we use CPU hotplug.
212 */
Steffen Persvoldb7157ac2012-03-16 20:25:35 +0100213 if (!apic->apic_id_valid(apic_id) && enabled)
Yinghai Lua35fd282011-12-21 17:45:16 -0800214 printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
215 else
Vitaly Kuznetsov3e9e57f2016-06-30 17:56:36 +0200216 acpi_register_lapic(apic_id, processor->uid, enabled);
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800217#else
218 printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
219#endif
220
221 return 0;
222}
223
224static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300225acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300227 struct acpi_madt_local_apic *processor = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300229 processor = (struct acpi_madt_local_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231 if (BAD_MADT_ENTRY(processor, end))
232 return -EINVAL;
233
234 acpi_table_print_madt_entry(header);
235
Ashok Raj7f66ae42006-02-03 21:51:50 +0100236 /*
237 * We need to register disabled CPU as well to permit
238 * counting disabled CPUs. This allows us to size
239 * cpus_possible_map more accurately, to permit
240 * to not preallocating memory for all NR_CPUS
241 * when we use CPU hotplug.
242 */
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400243 acpi_register_lapic(processor->id, /* APIC ID */
Vitaly Kuznetsov3e9e57f2016-06-30 17:56:36 +0200244 processor->processor_id, /* ACPI ID */
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400245 processor->lapic_flags & ACPI_MADT_ENABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
247 return 0;
248}
249
250static int __init
Jack Steinerac049c12008-03-28 14:12:09 -0500251acpi_parse_sapic(struct acpi_subtable_header *header, const unsigned long end)
252{
253 struct acpi_madt_local_sapic *processor = NULL;
254
255 processor = (struct acpi_madt_local_sapic *)header;
256
257 if (BAD_MADT_ENTRY(processor, end))
258 return -EINVAL;
259
260 acpi_table_print_madt_entry(header);
261
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400262 acpi_register_lapic((processor->id << 8) | processor->eid,/* APIC ID */
Vitaly Kuznetsov3e9e57f2016-06-30 17:56:36 +0200263 processor->processor_id, /* ACPI ID */
Alexey Starikovskiydfac2182008-04-04 23:41:50 +0400264 processor->lapic_flags & ACPI_MADT_ENABLED);
Jack Steinerac049c12008-03-28 14:12:09 -0500265
266 return 0;
267}
268
269static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300270acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400271 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300273 struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300275 lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277 if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
278 return -EINVAL;
279
Baoquan He6de42112016-08-12 14:57:13 +0800280 acpi_table_print_madt_entry(header);
281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 acpi_lapic_addr = lapic_addr_ovr->address;
283
284 return 0;
285}
286
287static int __init
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800288acpi_parse_x2apic_nmi(struct acpi_subtable_header *header,
289 const unsigned long end)
290{
291 struct acpi_madt_local_x2apic_nmi *x2apic_nmi = NULL;
292
293 x2apic_nmi = (struct acpi_madt_local_x2apic_nmi *)header;
294
295 if (BAD_MADT_ENTRY(x2apic_nmi, end))
296 return -EINVAL;
297
298 acpi_table_print_madt_entry(header);
299
300 if (x2apic_nmi->lint != 1)
301 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
302
303 return 0;
304}
305
306static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300307acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300309 struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300311 lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
313 if (BAD_MADT_ENTRY(lapic_nmi, end))
314 return -EINVAL;
315
316 acpi_table_print_madt_entry(header);
317
318 if (lapic_nmi->lint != 1)
319 printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
320
321 return 0;
322}
323
Len Brown4be44fc2005-08-05 00:44:28 -0400324#endif /*CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
Len Brown84663612005-08-24 12:09:07 -0400326#ifdef CONFIG_X86_IO_APIC
Jiang Liu8d7cdcb2014-06-09 16:19:33 +0800327#define MP_ISA_BUS 0
328
329static void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger,
330 u32 gsi)
331{
332 int ioapic;
333 int pin;
334 struct mpc_intsrc mp_irq;
335
336 /*
337 * Convert 'gsi' to 'ioapic.pin'.
338 */
339 ioapic = mp_find_ioapic(gsi);
340 if (ioapic < 0)
341 return;
342 pin = mp_find_ioapic_pin(ioapic, gsi);
343
344 /*
345 * TBD: This check is for faulty timer entries, where the override
346 * erroneously sets the trigger to level, resulting in a HUGE
347 * increase of timer interrupts!
348 */
349 if ((bus_irq == 0) && (trigger == 3))
350 trigger = 1;
351
352 mp_irq.type = MP_INTSRC;
353 mp_irq.irqtype = mp_INT;
354 mp_irq.irqflag = (trigger << 2) | polarity;
355 mp_irq.srcbus = MP_ISA_BUS;
356 mp_irq.srcbusirq = bus_irq; /* IRQ */
357 mp_irq.dstapic = mpc_ioapic_id(ioapic); /* APIC ID */
358 mp_irq.dstirq = pin; /* INTIN# */
359
360 mp_save_irq(&mp_irq);
361
Jiang Liu2e0ad0e2014-06-09 16:19:38 +0800362 /*
363 * Reset default identity mapping if gsi is also an legacy IRQ,
364 * otherwise there will be more than one entry with the same GSI
365 * and acpi_isa_irq_to_gsi() may give wrong result.
366 */
Jiang Liu95d76ac2014-06-09 16:19:48 +0800367 if (gsi < nr_legacy_irqs() && isa_irq_to_gsi[gsi] == gsi)
Jiang Liu2e0ad0e2014-06-09 16:19:38 +0800368 isa_irq_to_gsi[gsi] = ACPI_INVALID_GSI;
Jiang Liu8d7cdcb2014-06-09 16:19:33 +0800369 isa_irq_to_gsi[bus_irq] = gsi;
370}
371
372static int mp_config_acpi_gsi(struct device *dev, u32 gsi, int trigger,
373 int polarity)
374{
375#ifdef CONFIG_X86_MPPARSE
376 struct mpc_intsrc mp_irq;
377 struct pci_dev *pdev;
378 unsigned char number;
379 unsigned int devfn;
380 int ioapic;
381 u8 pin;
382
383 if (!acpi_ioapic)
384 return 0;
385 if (!dev || !dev_is_pci(dev))
386 return 0;
387
388 pdev = to_pci_dev(dev);
389 number = pdev->bus->number;
390 devfn = pdev->devfn;
391 pin = pdev->pin;
392 /* print the entry should happen on mptable identically */
393 mp_irq.type = MP_INTSRC;
394 mp_irq.irqtype = mp_INT;
395 mp_irq.irqflag = (trigger == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
396 (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
397 mp_irq.srcbus = number;
398 mp_irq.srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
399 ioapic = mp_find_ioapic(gsi);
400 mp_irq.dstapic = mpc_ioapic_id(ioapic);
401 mp_irq.dstirq = mp_find_ioapic_pin(ioapic, gsi);
402
403 mp_save_irq(&mp_irq);
404#endif
405 return 0;
406}
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300409acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300411 struct acpi_madt_io_apic *ioapic = NULL;
Jiang Liuca7e28aa2014-06-09 16:19:54 +0800412 struct ioapic_domain_cfg cfg = {
413 .type = IOAPIC_DOMAIN_DYNAMIC,
Thomas Gleixnerf7a0c782015-04-14 10:30:08 +0800414 .ops = &mp_ioapic_irqdomain_ops,
Jiang Liuca7e28aa2014-06-09 16:19:54 +0800415 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300417 ioapic = (struct acpi_madt_io_apic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
419 if (BAD_MADT_ENTRY(ioapic, end))
420 return -EINVAL;
Len Brown4be44fc2005-08-05 00:44:28 -0400421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 acpi_table_print_madt_entry(header);
423
Jiang Liuca7e28aa2014-06-09 16:19:54 +0800424 /* Statically assign IRQ numbers for IOAPICs hosting legacy IRQs */
425 if (ioapic->global_irq_base < nr_legacy_irqs())
426 cfg.type = IOAPIC_DOMAIN_LEGACY;
427
428 mp_register_ioapic(ioapic->id, ioapic->address, ioapic->global_irq_base,
429 &cfg);
Len Brown4be44fc2005-08-05 00:44:28 -0400430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 return 0;
432}
433
434/*
435 * Parse Interrupt Source Override for the ACPI SCI
436 */
Eric W. Biederman9d2062b2010-03-30 01:07:05 -0700437static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger, u32 gsi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
439 if (trigger == 0) /* compatible SCI trigger is level */
440 trigger = 3;
441
442 if (polarity == 0) /* compatible SCI polarity is low */
443 polarity = 3;
444
445 /* Command-line over-ride via acpi_sci= */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300446 if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
447 trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300449 if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
450 polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Eric W. Biederman9d2062b2010-03-30 01:07:05 -0700452 mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
454 /*
455 * stash over-ride to indicate we've been here
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300456 * and for later update of acpi_gbl_FADT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 */
Len Brown7bdd21c2006-12-02 02:27:46 -0500458 acpi_sci_override_gsi = gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 return;
460}
461
462static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300463acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400464 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300466 struct acpi_madt_interrupt_override *intsrc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300468 intsrc = (struct acpi_madt_interrupt_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
470 if (BAD_MADT_ENTRY(intsrc, end))
471 return -EINVAL;
472
473 acpi_table_print_madt_entry(header);
474
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300475 if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
Eric W. Biederman9d2062b2010-03-30 01:07:05 -0700476 acpi_sci_ioapic_setup(intsrc->source_irq,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300477 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
Eric W. Biederman9d2062b2010-03-30 01:07:05 -0700478 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
479 intsrc->global_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 return 0;
481 }
482
Feng Tangae10ccd2012-06-04 15:00:04 +0800483 if (intsrc->source_irq == 0) {
Andreas Herrmann7f74f8f2011-02-24 15:53:46 +0100484 if (acpi_skip_timer_override) {
Feng Tangae10ccd2012-06-04 15:00:04 +0800485 printk(PREFIX "BIOS IRQ0 override ignored.\n");
Andreas Herrmann7f74f8f2011-02-24 15:53:46 +0100486 return 0;
487 }
Feng Tangae10ccd2012-06-04 15:00:04 +0800488
489 if ((intsrc->global_irq == 2) && acpi_fix_pin2_polarity
490 && (intsrc->inti_flags & ACPI_MADT_POLARITY_MASK)) {
Andreas Herrmann7f74f8f2011-02-24 15:53:46 +0100491 intsrc->inti_flags &= ~ACPI_MADT_POLARITY_MASK;
492 printk(PREFIX "BIOS IRQ0 pin2 override: forcing polarity to high active.\n");
493 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 }
495
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300496 mp_override_legacy_irq(intsrc->source_irq,
497 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
498 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
499 intsrc->global_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
501 return 0;
502}
503
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504static int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300505acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300507 struct acpi_madt_nmi_source *nmi_src = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300509 nmi_src = (struct acpi_madt_nmi_source *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
511 if (BAD_MADT_ENTRY(nmi_src, end))
512 return -EINVAL;
513
514 acpi_table_print_madt_entry(header);
515
516 /* TBD: Support nimsrc entries? */
517
518 return 0;
519}
520
Len Brown4be44fc2005-08-05 00:44:28 -0400521#endif /* CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523/*
524 * acpi_pic_sci_set_trigger()
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300525 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 * use ELCR to set PIC-mode trigger type for SCI
527 *
528 * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
529 * it may require Edge Trigger -- use "acpi_sci=edge"
530 *
531 * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
532 * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
Simon Arlott27b46d72007-10-20 01:13:56 +0200533 * ECLR1 is IRQs 0-7 (IRQ 0, 1, 2 must be 0)
534 * ECLR2 is IRQs 8-15 (IRQ 8, 13 must be 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 */
536
Len Brown4be44fc2005-08-05 00:44:28 -0400537void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538{
539 unsigned int mask = 1 << irq;
540 unsigned int old, new;
541
542 /* Real old ELCR mask */
543 old = inb(0x4d0) | (inb(0x4d1) << 8);
544
545 /*
Simon Arlott27b46d72007-10-20 01:13:56 +0200546 * If we use ACPI to set PCI IRQs, then we should clear ELCR
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 * since we will set it correctly as we enable the PCI irq
548 * routing.
549 */
550 new = acpi_noirq ? old : 0;
551
552 /*
553 * Update SCI information in the ELCR, it isn't in the PCI
554 * routing tables..
555 */
556 switch (trigger) {
Len Brown4be44fc2005-08-05 00:44:28 -0400557 case 1: /* Edge - clear */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 new &= ~mask;
559 break;
Len Brown4be44fc2005-08-05 00:44:28 -0400560 case 3: /* Level - set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 new |= mask;
562 break;
563 }
564
565 if (old == new)
566 return;
567
568 printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
569 outb(new, 0x4d0);
570 outb(new >> 8, 0x4d1);
571}
572
Jiang Liu6b9fb702014-06-10 14:13:25 +0800573int acpi_gsi_to_irq(u32 gsi, unsigned int *irqp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574{
Jiang Liub568b862015-01-20 10:21:05 +0800575 int rc, irq, trigger, polarity;
Yinghai Lu18dce6b2010-02-10 01:20:05 -0800576
Jiang Liu1ea76fb2015-02-16 10:11:13 +0800577 if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
578 *irqp = gsi;
579 return 0;
580 }
581
Jiang Liub568b862015-01-20 10:21:05 +0800582 rc = acpi_get_override_irq(gsi, &trigger, &polarity);
583 if (rc == 0) {
584 trigger = trigger ? ACPI_LEVEL_SENSITIVE : ACPI_EDGE_SENSITIVE;
585 polarity = polarity ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH;
586 irq = acpi_register_gsi(NULL, gsi, trigger, polarity);
587 if (irq >= 0) {
588 *irqp = irq;
589 return 0;
590 }
Jiang Liu6b9fb702014-06-10 14:13:25 +0800591 }
Jiang Liub568b862015-01-20 10:21:05 +0800592
593 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594}
Huang Ying81e88fd2011-01-12 14:44:55 +0800595EXPORT_SYMBOL_GPL(acpi_gsi_to_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Eric W. Biederman2c2df842010-03-30 01:07:02 -0700597int acpi_isa_irq_to_gsi(unsigned isa_irq, u32 *gsi)
598{
Jiang Liu95d76ac2014-06-09 16:19:48 +0800599 if (isa_irq < nr_legacy_irqs() &&
Jiang Liu2e0ad0e2014-06-09 16:19:38 +0800600 isa_irq_to_gsi[isa_irq] != ACPI_INVALID_GSI) {
Jiang Liu032329e2014-06-09 16:19:35 +0800601 *gsi = isa_irq_to_gsi[isa_irq];
602 return 0;
603 }
604
605 return -1;
Eric W. Biederman2c2df842010-03-30 01:07:02 -0700606}
607
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100608static int acpi_register_gsi_pic(struct device *dev, u32 gsi,
609 int trigger, int polarity)
610{
611#ifdef CONFIG_PCI
612 /*
613 * Make sure all (legacy) PCI IRQs are set as level-triggered.
614 */
615 if (trigger == ACPI_LEVEL_SENSITIVE)
Paul Gortmakerea6cd252015-05-09 20:27:37 -0400616 elcr_set_level_irq(gsi);
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100617#endif
618
619 return gsi;
620}
621
Thomas Gleixner2f82c9d2015-01-22 15:13:36 +0100622#ifdef CONFIG_X86_LOCAL_APIC
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100623static int acpi_register_gsi_ioapic(struct device *dev, u32 gsi,
624 int trigger, int polarity)
625{
Jiang Liu84245af2014-06-10 14:14:47 +0800626 int irq = gsi;
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100627#ifdef CONFIG_X86_IO_APIC
Jiang Liu46176f32015-04-14 10:30:05 +0800628 int node;
629 struct irq_alloc_info info;
630
631 node = dev ? dev_to_node(dev) : NUMA_NO_NODE;
632 trigger = trigger == ACPI_EDGE_SENSITIVE ? 0 : 1;
633 polarity = polarity == ACPI_ACTIVE_HIGH ? 0 : 1;
634 ioapic_set_alloc_attr(&info, node, trigger, polarity);
635
Jiang Liu5da2fd22014-11-02 14:04:29 +0800636 mutex_lock(&acpi_ioapic_lock);
Jiang Liu46176f32015-04-14 10:30:05 +0800637 irq = mp_map_gsi_to_irq(gsi, IOAPIC_MAP_ALLOC, &info);
638 /* Don't set up the ACPI SCI because it's already set up */
639 if (irq >= 0 && enable_update_mptable &&
640 acpi_gbl_FADT.sci_interrupt != gsi)
641 mp_config_acpi_gsi(dev, gsi, trigger, polarity);
Jiang Liu5da2fd22014-11-02 14:04:29 +0800642 mutex_unlock(&acpi_ioapic_lock);
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100643#endif
644
Jiang Liu84245af2014-06-10 14:14:47 +0800645 return irq;
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100646}
647
Jiang Liu6a38fa02014-06-10 14:16:27 +0800648static void acpi_unregister_gsi_ioapic(u32 gsi)
649{
650#ifdef CONFIG_X86_IO_APIC
Jiang Liu46176f32015-04-14 10:30:05 +0800651 int irq;
652
Jiang Liu5da2fd22014-11-02 14:04:29 +0800653 mutex_lock(&acpi_ioapic_lock);
Jiang Liu46176f32015-04-14 10:30:05 +0800654 irq = mp_map_gsi_to_irq(gsi, 0, NULL);
655 if (irq > 0)
656 mp_unmap_irq(irq);
Jiang Liu5da2fd22014-11-02 14:04:29 +0800657 mutex_unlock(&acpi_ioapic_lock);
Jiang Liu6a38fa02014-06-10 14:16:27 +0800658#endif
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100659}
Thomas Gleixner2f82c9d2015-01-22 15:13:36 +0100660#endif
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100661
Jeremy Fitzhardinge90f68812010-06-24 17:05:41 +0100662int (*__acpi_register_gsi)(struct device *dev, u32 gsi,
663 int trigger, int polarity) = acpi_register_gsi_pic;
Jiang Liu6a38fa02014-06-10 14:16:27 +0800664void (*__acpi_unregister_gsi)(u32 gsi) = NULL;
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100665
Konrad Rzeszutek Wilkd6a77ea2013-05-14 17:09:16 +0000666#ifdef CONFIG_ACPI_SLEEP
667int (*acpi_suspend_lowlevel)(void) = x86_acpi_suspend_lowlevel;
668#else
669int (*acpi_suspend_lowlevel)(void);
670#endif
671
Kenji Kaneshige1f3a6a12005-07-28 14:42:00 -0400672/*
673 * success: return IRQ number (>=0)
674 * failure: return < 0
675 */
Yinghai Lue5198072009-05-15 13:05:16 -0700676int acpi_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677{
Jiang Liu84245af2014-06-10 14:14:47 +0800678 return __acpi_register_gsi(dev, gsi, trigger, polarity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679}
Andy Shevchenko35e92b72012-10-31 22:44:48 +0100680EXPORT_SYMBOL_GPL(acpi_register_gsi);
681
682void acpi_unregister_gsi(u32 gsi)
683{
Jiang Liu6a38fa02014-06-10 14:16:27 +0800684 if (__acpi_unregister_gsi)
685 __acpi_unregister_gsi(gsi);
Andy Shevchenko35e92b72012-10-31 22:44:48 +0100686}
687EXPORT_SYMBOL_GPL(acpi_unregister_gsi);
Len Brown4be44fc2005-08-05 00:44:28 -0400688
Jiang Liu9f50c6e2014-10-27 16:11:53 +0800689#ifdef CONFIG_X86_LOCAL_APIC
Jiang Liue8198132014-06-09 16:19:36 +0800690static void __init acpi_set_irq_model_ioapic(void)
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100691{
692 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
693 __acpi_register_gsi = acpi_register_gsi_ioapic;
Jiang Liu6a38fa02014-06-10 14:16:27 +0800694 __acpi_unregister_gsi = acpi_unregister_gsi_ioapic;
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100695 acpi_ioapic = 1;
696}
Jiang Liu9f50c6e2014-10-27 16:11:53 +0800697#endif
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +0100698
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699/*
700 * ACPI based hotplug support for CPU
701 */
702#ifdef CONFIG_ACPI_HOTPLUG_CPU
Alex Chiangd8191fa2010-02-22 12:11:39 -0700703#include <acpi/processor.h>
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100704
Paul Gortmaker148f9bb2013-06-18 18:23:59 -0400705static void acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
Haicheng Li0271f912010-02-04 19:06:33 +0800706{
707#ifdef CONFIG_ACPI_NUMA
708 int nid;
709
710 nid = acpi_get_node(handle);
Jiang Liu896dc502014-01-20 10:31:54 +0800711 if (nid != -1) {
712 set_apicid_to_node(physid, nid);
713 numa_set_node(cpu, nid);
714 }
Haicheng Li0271f912010-02-04 19:06:33 +0800715#endif
716}
Sam Ravnborg009cbad2008-02-01 17:49:42 +0100717
Mathias Krause4daa8322015-07-20 18:32:53 +0200718int acpi_map_cpu(acpi_handle handle, phys_cpuid_t physid, int *pcpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719{
Ashok Raj73fea172006-09-26 10:52:35 +0200720 int cpu;
721
Vitaly Kuznetsov3e9e57f2016-06-30 17:56:36 +0200722 cpu = acpi_register_lapic(physid, U32_MAX, ACPI_MADT_ENABLED);
Jiang Liu7e1f85f2013-09-02 11:57:36 +0800723 if (cpu < 0) {
724 pr_info(PREFIX "Unable to map lapic to logical cpu number\n");
725 return cpu;
Ashok Raj73fea172006-09-26 10:52:35 +0200726 }
727
Alex Chiangd8191fa2010-02-22 12:11:39 -0700728 acpi_processor_set_pdc(handle);
Haicheng Li0271f912010-02-04 19:06:33 +0800729 acpi_map_cpu2node(handle, cpu, physid);
Ashok Raj73fea172006-09-26 10:52:35 +0200730
731 *pcpu = cpu;
Jiang Liu7e1f85f2013-09-02 11:57:36 +0800732 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733}
Hanjun Guod02dc272015-01-04 18:55:03 +0800734EXPORT_SYMBOL(acpi_map_cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
Hanjun Guod02dc272015-01-04 18:55:03 +0800736int acpi_unmap_cpu(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737{
Wen Congyangc4c60522013-02-22 16:33:24 -0800738#ifdef CONFIG_ACPI_NUMA
739 set_apicid_to_node(per_cpu(x86_cpu_to_apicid, cpu), NUMA_NO_NODE);
740#endif
741
Mike Travis71fff5e2007-10-19 20:35:03 +0200742 per_cpu(x86_cpu_to_apicid, cpu) = -1;
Mike Travis96289372008-12-31 18:08:46 -0800743 set_cpu_present(cpu, false);
Ashok Raj73fea172006-09-26 10:52:35 +0200744 num_processors--;
745
746 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747}
Hanjun Guod02dc272015-01-04 18:55:03 +0800748EXPORT_SYMBOL(acpi_unmap_cpu);
Len Brown4be44fc2005-08-05 00:44:28 -0400749#endif /* CONFIG_ACPI_HOTPLUG_CPU */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
Len Brown4be44fc2005-08-05 00:44:28 -0400751int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700752{
Jiang Liu7db298c2014-10-27 13:21:45 +0800753 int ret = -ENOSYS;
754#ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
755 int ioapic_id;
756 u64 addr;
757 struct ioapic_domain_cfg cfg = {
758 .type = IOAPIC_DOMAIN_DYNAMIC,
Thomas Gleixnerf7a0c782015-04-14 10:30:08 +0800759 .ops = &mp_ioapic_irqdomain_ops,
Jiang Liu7db298c2014-10-27 13:21:45 +0800760 };
761
762 ioapic_id = acpi_get_ioapic_id(handle, gsi_base, &addr);
763 if (ioapic_id < 0) {
764 unsigned long long uid;
765 acpi_status status;
766
767 status = acpi_evaluate_integer(handle, METHOD_NAME__UID,
768 NULL, &uid);
769 if (ACPI_FAILURE(status)) {
770 acpi_handle_warn(handle, "failed to get IOAPIC ID.\n");
771 return -EINVAL;
772 }
773 ioapic_id = (int)uid;
774 }
775
776 mutex_lock(&acpi_ioapic_lock);
777 ret = mp_register_ioapic(ioapic_id, phys_addr, gsi_base, &cfg);
778 mutex_unlock(&acpi_ioapic_lock);
779#endif
780
781 return ret;
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700782}
783EXPORT_SYMBOL(acpi_register_ioapic);
784
Len Brown4be44fc2005-08-05 00:44:28 -0400785int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700786{
Jiang Liu15516a32014-10-27 13:21:46 +0800787 int ret = -ENOSYS;
Len Brown4be44fc2005-08-05 00:44:28 -0400788
Jiang Liu15516a32014-10-27 13:21:46 +0800789#ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
790 mutex_lock(&acpi_ioapic_lock);
791 ret = mp_unregister_ioapic(gsi_base);
792 mutex_unlock(&acpi_ioapic_lock);
793#endif
794
795 return ret;
796}
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700797EXPORT_SYMBOL(acpi_unregister_ioapic);
798
Jiang Liue89900c2014-10-27 13:21:47 +0800799/**
800 * acpi_ioapic_registered - Check whether IOAPIC assoicatied with @gsi_base
801 * has been registered
802 * @handle: ACPI handle of the IOAPIC deivce
803 * @gsi_base: GSI base associated with the IOAPIC
804 *
805 * Assume caller holds some type of lock to serialize acpi_ioapic_registered()
806 * with acpi_register_ioapic()/acpi_unregister_ioapic().
807 */
808int acpi_ioapic_registered(acpi_handle handle, u32 gsi_base)
809{
810 int ret = 0;
811
812#ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
813 mutex_lock(&acpi_ioapic_lock);
814 ret = mp_ioapic_registered(gsi_base);
815 mutex_unlock(&acpi_ioapic_lock);
816#endif
817
818 return ret;
819}
820
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300821static int __init acpi_parse_sbf(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822{
Hanjun Guo2fad9302015-02-05 17:33:14 +0800823 struct acpi_table_boot *sb = (struct acpi_table_boot *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300825 sbf_port = sb->cmos_index; /* Save CMOS port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
827 return 0;
828}
829
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830#ifdef CONFIG_HPET_TIMER
john stultz2d0c87c2007-02-16 01:28:18 -0800831#include <asm/hpet.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
Bartlomiej Zolnierkiewiczdd96dc322013-09-30 17:29:43 +0200833static struct resource *hpet_res __initdata;
Aaron Durbina1dfd852007-07-21 17:11:39 +0200834
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300835static int __init acpi_parse_hpet(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836{
Hanjun Guo2fad9302015-02-05 17:33:14 +0800837 struct acpi_table_hpet *hpet_tbl = (struct acpi_table_hpet *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300839 if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 printk(KERN_WARNING PREFIX "HPET timers must be located in "
841 "memory.\n");
842 return -1;
843 }
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200844
john stultz2d0c87c2007-02-16 01:28:18 -0800845 hpet_address = hpet_tbl->address.address;
Suresh Siddhac8bc6f32009-08-04 12:07:09 -0700846 hpet_blockid = hpet_tbl->sequence;
Thomas Gleixnerf4df73c2007-11-15 21:41:50 -0500847
848 /*
849 * Some broken BIOSes advertise HPET at 0x0. We really do not
850 * want to allocate a resource there.
851 */
852 if (!hpet_address) {
853 printk(KERN_WARNING PREFIX
854 "HPET id: %#x base: %#lx is invalid\n",
855 hpet_tbl->id, hpet_address);
856 return 0;
857 }
858#ifdef CONFIG_X86_64
859 /*
860 * Some even more broken BIOSes advertise HPET at
861 * 0xfed0000000000000 instead of 0xfed00000. Fix it up and add
862 * some noise:
863 */
864 if (hpet_address == 0xfed0000000000000UL) {
865 if (!hpet_force_user) {
866 printk(KERN_WARNING PREFIX "HPET id: %#x "
867 "base: 0xfed0000000000000 is bogus\n "
868 "try hpet=force on the kernel command line to "
869 "fix it up to 0xfed00000.\n", hpet_tbl->id);
870 hpet_address = 0;
871 return 0;
872 }
873 printk(KERN_WARNING PREFIX
874 "HPET id: %#x base: 0xfed0000000000000 fixed up "
875 "to 0xfed00000.\n", hpet_tbl->id);
876 hpet_address >>= 32;
877 }
878#endif
Len Brown4be44fc2005-08-05 00:44:28 -0400879 printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
john stultz2d0c87c2007-02-16 01:28:18 -0800880 hpet_tbl->id, hpet_address);
adurbin@google.comf0f4c342006-09-26 10:52:39 +0200881
Aaron Durbina1dfd852007-07-21 17:11:39 +0200882 /*
883 * Allocate and initialize the HPET firmware resource for adding into
884 * the resource tree during the lateinit timeframe.
885 */
886#define HPET_RESOURCE_NAME_SIZE 9
887 hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
888
Aaron Durbina1dfd852007-07-21 17:11:39 +0200889 hpet_res->name = (void *)&hpet_res[1];
890 hpet_res->flags = IORESOURCE_MEM;
891 snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE, "HPET %u",
892 hpet_tbl->sequence);
893
894 hpet_res->start = hpet_address;
895 hpet_res->end = hpet_address + (1 * 1024) - 1;
896
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 return 0;
898}
Aaron Durbina1dfd852007-07-21 17:11:39 +0200899
900/*
901 * hpet_insert_resource inserts the HPET resources used into the resource
902 * tree.
903 */
904static __init int hpet_insert_resource(void)
905{
906 if (!hpet_res)
907 return 1;
908
909 return insert_resource(&iomem_resource, hpet_res);
910}
911
912late_initcall(hpet_insert_resource);
913
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914#else
915#define acpi_parse_hpet NULL
916#endif
917
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300918static int __init acpi_parse_fadt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919{
Luis R. Rodriguez7a17b822016-04-13 17:04:42 -0700920 if (!(acpi_gbl_FADT.boot_flags & ACPI_FADT_LEGACY_DEVICES)) {
921 pr_debug("ACPI: no legacy devices present\n");
922 x86_platform.legacy.devices.pnpbios = 0;
923 }
924
Luis R. Rodriguez088a8ef2016-04-13 17:04:35 -0700925 if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_CMOS_RTC) {
926 pr_debug("ACPI: not registering RTC platform device\n");
927 x86_platform.legacy.rtc = 0;
928 }
Jason Davis90660ec2005-04-16 15:24:53 -0700929
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930#ifdef CONFIG_X86_PM_TIMER
931 /* detect the location of the ACPI PM Timer */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300932 if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 /* FADT rev. 2 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300934 if (acpi_gbl_FADT.xpm_timer_block.space_id !=
Len Brown4be44fc2005-08-05 00:44:28 -0400935 ACPI_ADR_SPACE_SYSTEM_IO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 return 0;
937
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300938 pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
David Shaohua Lie6e87b42005-09-21 01:35:00 -0400939 /*
940 * "X" fields are optional extensions to the original V1.0
941 * fields, so we must selectively expand V1.0 fields if the
942 * corresponding X field is zero.
943 */
944 if (!pmtmr_ioport)
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300945 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 } else {
947 /* FADT rev. 1 */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300948 pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 }
950 if (pmtmr_ioport)
Len Brown4be44fc2005-08-05 00:44:28 -0400951 printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
952 pmtmr_ioport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953#endif
954 return 0;
955}
956
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957#ifdef CONFIG_X86_LOCAL_APIC
958/*
959 * Parse LAPIC entries in MADT
960 * returns 0 on success, < 0 on error
961 */
Alexey Starikovskiy31d20922008-04-04 23:41:57 +0400962
Yinghai Lucbf9bd62008-02-19 03:21:06 -0800963static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
964{
965 int count;
966
Borislav Petkov93984fb2016-04-04 22:25:00 +0200967 if (!boot_cpu_has(X86_FEATURE_APIC))
Yinghai Lucbf9bd62008-02-19 03:21:06 -0800968 return -ENODEV;
969
970 /*
971 * Note that the LAPIC address is obtained from the MADT (32-bit value)
Adam Buchbinder6a6256f2016-02-23 15:34:30 -0800972 * and (optionally) overridden by a LAPIC_ADDR_OVR entry (64-bit value).
Yinghai Lucbf9bd62008-02-19 03:21:06 -0800973 */
974
Jiang Liue8198132014-06-09 16:19:36 +0800975 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
976 acpi_parse_lapic_addr_ovr, 0);
Yinghai Lucbf9bd62008-02-19 03:21:06 -0800977 if (count < 0) {
978 printk(KERN_ERR PREFIX
979 "Error parsing LAPIC address override entry\n");
980 return count;
981 }
982
Yinghai Luc0104d32010-12-07 00:55:17 -0800983 register_lapic_address(acpi_lapic_addr);
Yinghai Lucbf9bd62008-02-19 03:21:06 -0800984
985 return count;
986}
987
Len Brown4be44fc2005-08-05 00:44:28 -0400988static int __init acpi_parse_madt_lapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989{
990 int count;
Suresh Siddha7237d3d2009-03-30 13:55:30 -0800991 int x2count = 0;
Lukasz Anaczkowskid81056b2015-09-09 15:47:29 +0200992 int ret;
993 struct acpi_subtable_proc madt_proc[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
Borislav Petkov93984fb2016-04-04 22:25:00 +0200995 if (!boot_cpu_has(X86_FEATURE_APIC))
Andi Kleen0fcd2702006-04-11 12:54:36 +0200996 return -ENODEV;
997
Jack Steinerac049c12008-03-28 14:12:09 -0500998 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
Yinghai Lucb2ded32011-01-04 16:38:52 -0800999 acpi_parse_sapic, MAX_LOCAL_APIC);
Jack Steinerac049c12008-03-28 14:12:09 -05001000
Suresh Siddha7237d3d2009-03-30 13:55:30 -08001001 if (!count) {
Lukasz Anaczkowskid81056b2015-09-09 15:47:29 +02001002 memset(madt_proc, 0, sizeof(madt_proc));
1003 madt_proc[0].id = ACPI_MADT_TYPE_LOCAL_APIC;
1004 madt_proc[0].handler = acpi_parse_lapic;
1005 madt_proc[1].id = ACPI_MADT_TYPE_LOCAL_X2APIC;
1006 madt_proc[1].handler = acpi_parse_x2apic;
1007 ret = acpi_table_parse_entries_array(ACPI_SIG_MADT,
1008 sizeof(struct acpi_table_madt),
1009 madt_proc, ARRAY_SIZE(madt_proc), MAX_LOCAL_APIC);
1010 if (ret < 0) {
1011 printk(KERN_ERR PREFIX
1012 "Error parsing LAPIC/X2APIC entries\n");
1013 return ret;
1014 }
1015
Baoquan He31b02dd2016-08-12 15:21:47 +08001016 count = madt_proc[0].count;
1017 x2count = madt_proc[1].count;
Suresh Siddha7237d3d2009-03-30 13:55:30 -08001018 }
1019 if (!count && !x2count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 printk(KERN_ERR PREFIX "No LAPIC entries present\n");
1021 /* TBD: Cleanup to allow fallback to MPS */
1022 return -ENODEV;
Suresh Siddha7237d3d2009-03-30 13:55:30 -08001023 } else if (count < 0 || x2count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
1025 /* TBD: Cleanup to allow fallback to MPS */
1026 return count;
1027 }
1028
Jiang Liue8198132014-06-09 16:19:36 +08001029 x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI,
1030 acpi_parse_x2apic_nmi, 0);
1031 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI,
1032 acpi_parse_lapic_nmi, 0);
Suresh Siddha7237d3d2009-03-30 13:55:30 -08001033 if (count < 0 || x2count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
1035 /* TBD: Cleanup to allow fallback to MPS */
1036 return count;
1037 }
1038 return 0;
1039}
Len Brown4be44fc2005-08-05 00:44:28 -04001040#endif /* CONFIG_X86_LOCAL_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
Len Brown84663612005-08-24 12:09:07 -04001042#ifdef CONFIG_X86_IO_APIC
Jiang Liua491cc9022014-06-09 16:19:32 +08001043static void __init mp_config_acpi_legacy_irqs(void)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001044{
Yinghai Lu6df88092008-06-15 18:19:46 -07001045 int i;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301046 struct mpc_intsrc mp_irq;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001047
Paul Gortmakerbb8187d2012-05-17 19:06:13 -04001048#ifdef CONFIG_EISA
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001049 /*
1050 * Fabricate the legacy ISA bus (bus #31).
1051 */
1052 mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
1053#endif
1054 set_bit(MP_ISA_BUS, mp_bus_not_pci);
Thomas Gleixnercfc1b9a2008-07-21 21:35:38 +02001055 pr_debug("Bus #%d is ISA\n", MP_ISA_BUS);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001056
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001057 /*
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001058 * Use the default configuration for the IRQs 0-15. Unless
1059 * overridden by (MADT) interrupt source override entries.
1060 */
Jiang Liu95d76ac2014-06-09 16:19:48 +08001061 for (i = 0; i < nr_legacy_irqs(); i++) {
Eric W. Biederman0fd52672010-03-30 01:07:06 -07001062 int ioapic, pin;
1063 unsigned int dstapic;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001064 int idx;
Eric W. Biederman0fd52672010-03-30 01:07:06 -07001065 u32 gsi;
1066
1067 /* Locate the gsi that irq i maps to. */
1068 if (acpi_isa_irq_to_gsi(i, &gsi))
1069 continue;
1070
1071 /*
1072 * Locate the IOAPIC that manages the ISA IRQ.
1073 */
1074 ioapic = mp_find_ioapic(gsi);
1075 if (ioapic < 0)
1076 continue;
1077 pin = mp_find_ioapic_pin(ioapic, gsi);
Suresh Siddhad5371432011-05-18 16:31:37 -07001078 dstapic = mpc_ioapic_id(ioapic);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001079
1080 for (idx = 0; idx < mp_irq_entries; idx++) {
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301081 struct mpc_intsrc *irq = mp_irqs + idx;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001082
1083 /* Do we already have a mapping for this ISA IRQ? */
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301084 if (irq->srcbus == MP_ISA_BUS && irq->srcbusirq == i)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001085 break;
1086
1087 /* Do we already have a mapping for this IOAPIC pin */
Eric W. Biederman0fd52672010-03-30 01:07:06 -07001088 if (irq->dstapic == dstapic && irq->dstirq == pin)
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001089 break;
1090 }
1091
1092 if (idx != mp_irq_entries) {
1093 printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
1094 continue; /* IRQ already used */
1095 }
1096
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05301097 mp_irq.type = MP_INTSRC;
1098 mp_irq.irqflag = 0; /* Conforming */
1099 mp_irq.srcbus = MP_ISA_BUS;
1100 mp_irq.dstapic = dstapic;
1101 mp_irq.irqtype = mp_INT;
1102 mp_irq.srcbusirq = i; /* Identity mapped */
Eric W. Biederman0fd52672010-03-30 01:07:06 -07001103 mp_irq.dstirq = pin;
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001104
Feng Tang2d8009b2010-11-19 11:33:35 +08001105 mp_save_irq(&mp_irq);
Alexey Starikovskiy11113f82008-05-14 19:02:57 +04001106 }
1107}
1108
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109/*
1110 * Parse IOAPIC related entries in MADT
1111 * returns 0 on success, < 0 on error
1112 */
Len Brown4be44fc2005-08-05 00:44:28 -04001113static int __init acpi_parse_madt_ioapic_entries(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114{
1115 int count;
1116
1117 /*
1118 * ACPI interpreter is required to complete interrupt setup,
1119 * so if it is off, don't enumerate the io-apics with ACPI.
1120 * If MPS is present, it will handle them,
1121 * otherwise the system will stay in PIC mode
1122 */
Jeremy Fitzhardinge6b2b1712009-06-08 02:53:50 -07001123 if (acpi_disabled || acpi_noirq)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Borislav Petkov93984fb2016-04-04 22:25:00 +02001126 if (!boot_cpu_has(X86_FEATURE_APIC))
Andi Kleend3b6a342006-04-07 19:49:39 +02001127 return -ENODEV;
1128
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001130 * if "noapic" boot option, don't look for IO-APICs
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 */
1132 if (skip_ioapic_setup) {
1133 printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
Len Brown4be44fc2005-08-05 00:44:28 -04001134 "due to 'noapic' option.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 return -ENODEV;
1136 }
1137
Jiang Liue8198132014-06-09 16:19:36 +08001138 count = acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
1139 MAX_IO_APICS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 if (!count) {
1141 printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
1142 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -04001143 } else if (count < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
1145 return count;
1146 }
1147
Jiang Liue8198132014-06-09 16:19:36 +08001148 count = acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE,
1149 acpi_parse_int_src_ovr, nr_irqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 if (count < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -04001151 printk(KERN_ERR PREFIX
1152 "Error parsing interrupt source overrides entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 /* TBD: Cleanup to allow fallback to MPS */
1154 return count;
1155 }
1156
1157 /*
1158 * If BIOS did not supply an INT_SRC_OVR for the SCI
1159 * pretend we got one so we can set the SCI flags.
1160 */
1161 if (!acpi_sci_override_gsi)
Eric W. Biederman9d2062b2010-03-30 01:07:05 -07001162 acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0,
1163 acpi_gbl_FADT.sci_interrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001165 /* Fill in identity legacy mappings where no override */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 mp_config_acpi_legacy_irqs();
1167
Jiang Liue8198132014-06-09 16:19:36 +08001168 count = acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE,
1169 acpi_parse_nmi_src, nr_irqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 if (count < 0) {
1171 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
1172 /* TBD: Cleanup to allow fallback to MPS */
1173 return count;
1174 }
1175
1176 return 0;
1177}
1178#else
1179static inline int acpi_parse_madt_ioapic_entries(void)
1180{
1181 return -1;
1182}
Len Brown84663612005-08-24 12:09:07 -04001183#endif /* !CONFIG_X86_IO_APIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001185static void __init early_acpi_process_madt(void)
1186{
1187#ifdef CONFIG_X86_LOCAL_APIC
1188 int error;
1189
1190 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1191
1192 /*
1193 * Parse MADT LAPIC entries
1194 */
1195 error = early_acpi_parse_madt_lapic_addr_ovr();
1196 if (!error) {
1197 acpi_lapic = 1;
1198 smp_found_config = 1;
1199 }
1200 if (error == -EINVAL) {
1201 /*
1202 * Dell Precision Workstation 410, 610 come here.
1203 */
1204 printk(KERN_ERR PREFIX
1205 "Invalid BIOS MADT, disabling ACPI\n");
1206 disable_acpi();
1207 }
1208 }
1209#endif
1210}
1211
Len Brown4be44fc2005-08-05 00:44:28 -04001212static void __init acpi_process_madt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213{
1214#ifdef CONFIG_X86_LOCAL_APIC
Len Brown7f8f97c2007-02-10 21:28:03 -05001215 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
Len Brown7f8f97c2007-02-10 21:28:03 -05001217 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
1219 /*
1220 * Parse MADT LAPIC entries
1221 */
1222 error = acpi_parse_madt_lapic_entries();
1223 if (!error) {
1224 acpi_lapic = 1;
1225
1226 /*
1227 * Parse MADT IO-APIC entries
1228 */
Jiang Liu5da2fd22014-11-02 14:04:29 +08001229 mutex_lock(&acpi_ioapic_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 error = acpi_parse_madt_ioapic_entries();
Jiang Liu5da2fd22014-11-02 14:04:29 +08001231 mutex_unlock(&acpi_ioapic_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 if (!error) {
Jeremy Fitzhardinge2f065ae2010-06-24 16:59:16 +01001233 acpi_set_irq_model_ioapic();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
1235 smp_found_config = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 }
1237 }
1238 if (error == -EINVAL) {
1239 /*
1240 * Dell Precision Workstation 410, 610 come here.
1241 */
Len Brown4be44fc2005-08-05 00:44:28 -04001242 printk(KERN_ERR PREFIX
1243 "Invalid BIOS MADT, disabling ACPI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 disable_acpi();
1245 }
Len Brown7b37b5f2008-12-23 01:47:42 -05001246 } else {
1247 /*
1248 * ACPI found no MADT, and so ACPI wants UP PIC mode.
1249 * In the event an MPS table was found, forget it.
1250 * Boot with "acpi=off" to use MPS on such a system.
1251 */
1252 if (smp_found_config) {
1253 printk(KERN_WARNING PREFIX
1254 "No APIC-table, disabling MPS\n");
1255 smp_found_config = 0;
1256 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 }
Yinghai Lu69b88af2008-12-05 22:45:50 -08001258
1259 /*
1260 * ACPI supports both logical (e.g. Hyper-Threading) and physical
1261 * processors, where MPS only supports physical.
1262 */
1263 if (acpi_lapic && acpi_ioapic)
1264 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
1265 "information\n");
1266 else if (acpi_lapic)
1267 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
1268 "configuration information\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269#endif
1270 return;
1271}
1272
Jeff Garzik18552562007-10-03 15:15:40 -04001273static int __init disable_acpi_irq(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001274{
1275 if (!acpi_force) {
1276 printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
1277 d->ident);
1278 acpi_noirq_set();
1279 }
1280 return 0;
1281}
1282
Jeff Garzik18552562007-10-03 15:15:40 -04001283static int __init disable_acpi_pci(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001284{
1285 if (!acpi_force) {
1286 printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
1287 d->ident);
1288 acpi_disable_pci();
1289 }
1290 return 0;
1291}
Andrey Paninaea00142005-06-25 14:54:42 -07001292
Jeff Garzik18552562007-10-03 15:15:40 -04001293static int __init dmi_disable_acpi(const struct dmi_system_id *d)
Andrey Paninaea00142005-06-25 14:54:42 -07001294{
1295 if (!acpi_force) {
Len Brown4be44fc2005-08-05 00:44:28 -04001296 printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
Andrey Paninaea00142005-06-25 14:54:42 -07001297 disable_acpi();
1298 } else {
1299 printk(KERN_NOTICE
1300 "Warning: DMI blacklist says broken, but acpi forced\n");
1301 }
1302 return 0;
1303}
1304
1305/*
Feng Tangae10ccd2012-06-04 15:00:04 +08001306 * Force ignoring BIOS IRQ0 override
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001307 */
1308static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
1309{
Ingo Molnar8d89adf2008-10-07 06:47:52 +02001310 if (!acpi_skip_timer_override) {
Feng Tangae10ccd2012-06-04 15:00:04 +08001311 pr_notice("%s detected: Ignoring BIOS IRQ0 override\n",
Ingo Molnar8d89adf2008-10-07 06:47:52 +02001312 d->ident);
1313 acpi_skip_timer_override = 1;
1314 }
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001315 return 0;
1316}
1317
1318/*
Li, Aubrey74863412015-03-11 16:09:00 +08001319 * ACPI offers an alternative platform interface model that removes
1320 * ACPI hardware requirements for platforms that do not implement
1321 * the PC Architecture.
1322 *
1323 * We initialize the Hardware-reduced ACPI model here:
1324 */
1325static void __init acpi_reduced_hw_init(void)
1326{
1327 if (acpi_gbl_reduced_hardware) {
1328 /*
1329 * Override x86_init functions and bypass legacy pic
1330 * in Hardware-reduced ACPI mode
1331 */
1332 x86_init.timers.timer_init = x86_init_noop;
1333 x86_init.irqs.pre_vector_init = x86_init_noop;
1334 legacy_pic = &null_legacy_pic;
1335 }
1336}
1337
1338/*
Andrey Paninaea00142005-06-25 14:54:42 -07001339 * If your system is blacklisted here, but you find that acpi=force
Zhang Rui5b4c0b62009-04-01 01:49:42 -04001340 * works for you, please contact linux-acpi@vger.kernel.org
Andrey Paninaea00142005-06-25 14:54:42 -07001341 */
1342static struct dmi_system_id __initdata acpi_dmi_table[] = {
1343 /*
1344 * Boxes that need ACPI disabled
1345 */
1346 {
Len Brown4be44fc2005-08-05 00:44:28 -04001347 .callback = dmi_disable_acpi,
1348 .ident = "IBM Thinkpad",
1349 .matches = {
1350 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1351 DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
1352 },
1353 },
Andrey Paninaea00142005-06-25 14:54:42 -07001354
1355 /*
Andrey Paninaea00142005-06-25 14:54:42 -07001356 * Boxes that need ACPI PCI IRQ routing disabled
1357 */
1358 {
Len Brown4be44fc2005-08-05 00:44:28 -04001359 .callback = disable_acpi_irq,
1360 .ident = "ASUS A7V",
1361 .matches = {
1362 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
1363 DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
1364 /* newer BIOS, Revision 1011, does work */
1365 DMI_MATCH(DMI_BIOS_VERSION,
1366 "ASUS A7V ACPI BIOS Revision 1007"),
1367 },
1368 },
Len Brown74586fc2007-03-08 02:48:30 -05001369 {
1370 /*
1371 * Latest BIOS for IBM 600E (1.16) has bad pcinum
1372 * for LPC bridge, which is needed for the PCI
1373 * interrupt links to work. DSDT fix is in bug 5966.
1374 * 2645, 2646 model numbers are shared with 600/600E/600X
1375 */
1376 .callback = disable_acpi_irq,
1377 .ident = "IBM Thinkpad 600 Series 2645",
1378 .matches = {
1379 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1380 DMI_MATCH(DMI_BOARD_NAME, "2645"),
1381 },
1382 },
1383 {
1384 .callback = disable_acpi_irq,
1385 .ident = "IBM Thinkpad 600 Series 2646",
1386 .matches = {
1387 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1388 DMI_MATCH(DMI_BOARD_NAME, "2646"),
1389 },
1390 },
Andrey Paninaea00142005-06-25 14:54:42 -07001391 /*
1392 * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
1393 */
Len Brown4be44fc2005-08-05 00:44:28 -04001394 { /* _BBN 0 bug */
1395 .callback = disable_acpi_pci,
1396 .ident = "ASUS PR-DLS",
1397 .matches = {
1398 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1399 DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
1400 DMI_MATCH(DMI_BIOS_VERSION,
1401 "ASUS PR-DLS ACPI BIOS Revision 1010"),
1402 DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
1403 },
1404 },
Andrey Paninaea00142005-06-25 14:54:42 -07001405 {
Len Brown4be44fc2005-08-05 00:44:28 -04001406 .callback = disable_acpi_pci,
1407 .ident = "Acer TravelMate 36x Laptop",
1408 .matches = {
1409 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
1410 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
1411 },
1412 },
Andreas Herrmann35af2822008-10-22 13:08:31 +02001413 {}
1414};
1415
1416/* second table for DMI checks that should run after early-quirks */
1417static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
Matthew Garrett9340e1c2008-07-01 01:12:06 +01001418 /*
1419 * HP laptops which use a DSDT reporting as HP/SB400/10000,
1420 * which includes some code which overrides all temperature
1421 * trip points to 16C if the INTIN2 input of the I/O APIC
1422 * is enabled. This input is incorrectly designated the
1423 * ISA IRQ 0 via an interrupt source override even though
1424 * it is wired to the output of the master 8259A and INTIN0
Feng Tangae10ccd2012-06-04 15:00:04 +08001425 * is not connected at all. Force ignoring BIOS IRQ0
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001426 * override in that cases.
1427 */
1428 {
1429 .callback = dmi_ignore_irq0_timer_override,
Rafael J. Wysockie84956f2008-10-06 11:59:29 +02001430 .ident = "HP nx6115 laptop",
1431 .matches = {
1432 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1433 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6115"),
1434 },
1435 },
1436 {
1437 .callback = dmi_ignore_irq0_timer_override,
Rafael J. Wysockie2079c42008-07-08 16:12:26 +02001438 .ident = "HP NX6125 laptop",
1439 .matches = {
1440 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1441 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
1442 },
1443 },
1444 {
1445 .callback = dmi_ignore_irq0_timer_override,
1446 .ident = "HP NX6325 laptop",
1447 .matches = {
1448 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1449 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
1450 },
1451 },
Rafael J. Wysockie84956f2008-10-06 11:59:29 +02001452 {
1453 .callback = dmi_ignore_irq0_timer_override,
1454 .ident = "HP 6715b laptop",
1455 .matches = {
1456 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1457 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
1458 },
1459 },
Feng Tangf6b54f02012-06-04 15:00:06 +08001460 {
1461 .callback = dmi_ignore_irq0_timer_override,
1462 .ident = "FUJITSU SIEMENS",
1463 .matches = {
1464 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
1465 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO PRO V2030"),
1466 },
1467 },
Len Brown4be44fc2005-08-05 00:44:28 -04001468 {}
Andrey Paninaea00142005-06-25 14:54:42 -07001469};
1470
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471/*
1472 * acpi_boot_table_init() and acpi_boot_init()
1473 * called from setup_arch(), always.
1474 * 1. checksums all tables
1475 * 2. enumerates lapics
1476 * 3. enumerates io-apics
1477 *
1478 * acpi_table_init() is separate to allow reading SRAT without
1479 * other side effects.
1480 *
1481 * side effects of acpi_boot_init:
1482 * acpi_lapic = 1 if LAPIC found
1483 * acpi_ioapic = 1 if IOAPIC found
1484 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
1485 * if acpi_blacklisted() acpi_disabled = 1;
1486 * acpi_irq_model=...
1487 * ...
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 */
1489
Len Brown8558e392010-01-06 16:11:06 -05001490void __init acpi_boot_table_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491{
Andrey Paninaea00142005-06-25 14:54:42 -07001492 dmi_check_system(acpi_dmi_table);
Andrey Paninaea00142005-06-25 14:54:42 -07001493
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 /*
1495 * If acpi_disabled, bail out
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 */
Len Brown68ca4062010-02-19 00:09:22 -05001497 if (acpi_disabled)
Len Brown8558e392010-01-06 16:11:06 -05001498 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001500 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 * Initialize the ACPI boot-time table parser.
1502 */
Len Brown8558e392010-01-06 16:11:06 -05001503 if (acpi_table_init()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 disable_acpi();
Len Brown8558e392010-01-06 16:11:06 -05001505 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001508 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
1510 /*
1511 * blacklist may disable ACPI entirely
1512 */
Len Brown8558e392010-01-06 16:11:06 -05001513 if (acpi_blacklisted()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 if (acpi_force) {
1515 printk(KERN_WARNING PREFIX "acpi=force override\n");
1516 } else {
1517 printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
1518 disable_acpi();
Len Brown8558e392010-01-06 16:11:06 -05001519 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 }
1521 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522}
1523
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001524int __init early_acpi_boot_init(void)
1525{
1526 /*
1527 * If acpi_disabled, bail out
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001528 */
Len Brown68ca4062010-02-19 00:09:22 -05001529 if (acpi_disabled)
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001530 return 1;
1531
1532 /*
1533 * Process the Multiple APIC Description Table (MADT), if present
1534 */
1535 early_acpi_process_madt();
1536
Li, Aubrey74863412015-03-11 16:09:00 +08001537 /*
1538 * Hardware-reduced ACPI mode initialization:
1539 */
1540 acpi_reduced_hw_init();
1541
Yinghai Lucbf9bd62008-02-19 03:21:06 -08001542 return 0;
1543}
1544
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545int __init acpi_boot_init(void)
1546{
Andreas Herrmann35af2822008-10-22 13:08:31 +02001547 /* those are executed after early-quirks are executed */
1548 dmi_check_system(acpi_dmi_table_late);
1549
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 /*
1551 * If acpi_disabled, bail out
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 */
Len Brown68ca4062010-02-19 00:09:22 -05001553 if (acpi_disabled)
Len Brown4be44fc2005-08-05 00:44:28 -04001554 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001556 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
1558 /*
1559 * set sci_int and PM timer address
1560 */
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +03001561 acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
1563 /*
1564 * Process the Multiple APIC Description Table (MADT), if present
1565 */
1566 acpi_process_madt();
1567
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001568 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
Thomas Gleixnerb72d0db2009-08-29 16:24:51 +02001570 if (!acpi_noirq)
1571 x86_init.pci.init = pci_acpi_init;
1572
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 return 0;
1574}
Rusty Russell1a3f2392006-09-26 10:52:32 +02001575
1576static int __init parse_acpi(char *arg)
1577{
1578 if (!arg)
1579 return -EINVAL;
1580
1581 /* "acpi=off" disables both ACPI table parsing and interpreter */
1582 if (strcmp(arg, "off") == 0) {
1583 disable_acpi();
1584 }
1585 /* acpi=force to over-ride black-list */
1586 else if (strcmp(arg, "force") == 0) {
1587 acpi_force = 1;
Rusty Russell1a3f2392006-09-26 10:52:32 +02001588 acpi_disabled = 0;
1589 }
1590 /* acpi=strict disables out-of-spec workarounds */
1591 else if (strcmp(arg, "strict") == 0) {
1592 acpi_strict = 1;
1593 }
Zhao Yakui237889b2008-12-17 16:55:18 +08001594 /* acpi=rsdt use RSDT instead of XSDT */
1595 else if (strcmp(arg, "rsdt") == 0) {
Lv Zhengfab46102014-01-08 13:43:40 +08001596 acpi_gbl_do_not_use_xsdt = TRUE;
Zhao Yakui237889b2008-12-17 16:55:18 +08001597 }
Rusty Russell1a3f2392006-09-26 10:52:32 +02001598 /* "acpi=noirq" disables ACPI interrupt routing */
1599 else if (strcmp(arg, "noirq") == 0) {
1600 acpi_noirq_set();
Lin Mingaa2110c2010-04-08 14:34:27 +08001601 }
1602 /* "acpi=copy_dsdt" copys DSDT */
1603 else if (strcmp(arg, "copy_dsdt") == 0) {
1604 acpi_gbl_copy_dsdt_locally = 1;
Naveen N. Rao9ad95872013-07-01 21:08:54 +05301605 }
1606 /* "acpi=nocmcff" disables FF mode for corrected errors */
1607 else if (strcmp(arg, "nocmcff") == 0) {
1608 acpi_disable_cmcff = 1;
Rusty Russell1a3f2392006-09-26 10:52:32 +02001609 } else {
1610 /* Core will printk when we return error. */
1611 return -EINVAL;
1612 }
1613 return 0;
1614}
1615early_param("acpi", parse_acpi);
1616
1617/* FIXME: Using pci= for an ACPI parameter is a travesty. */
1618static int __init parse_pci(char *arg)
1619{
1620 if (arg && strcmp(arg, "noacpi") == 0)
1621 acpi_disable_pci();
1622 return 0;
1623}
1624early_param("pci", parse_pci);
1625
Yinghai Lu3c999f12008-06-20 16:11:20 -07001626int __init acpi_mps_check(void)
1627{
1628#if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
1629/* mptable code is not built-in*/
1630 if (acpi_disabled || acpi_noirq) {
1631 printk(KERN_WARNING "MPS support code is not built-in.\n"
1632 "Using acpi=off or acpi=noirq or pci=noacpi "
1633 "may have problem\n");
1634 return 1;
1635 }
1636#endif
1637 return 0;
1638}
1639
Rusty Russell1a3f2392006-09-26 10:52:32 +02001640#ifdef CONFIG_X86_IO_APIC
1641static int __init parse_acpi_skip_timer_override(char *arg)
1642{
1643 acpi_skip_timer_override = 1;
1644 return 0;
1645}
1646early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
Andi Kleenfa18f472006-11-14 16:57:46 +01001647
1648static int __init parse_acpi_use_timer_override(char *arg)
1649{
1650 acpi_use_timer_override = 1;
1651 return 0;
1652}
1653early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001654#endif /* CONFIG_X86_IO_APIC */
1655
1656static int __init setup_acpi_sci(char *s)
1657{
1658 if (!s)
1659 return -EINVAL;
1660 if (!strcmp(s, "edge"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001661 acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
1662 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001663 else if (!strcmp(s, "level"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001664 acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
1665 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001666 else if (!strcmp(s, "high"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001667 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
1668 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001669 else if (!strcmp(s, "low"))
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +03001670 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
1671 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001672 else
1673 return -EINVAL;
1674 return 0;
1675}
1676early_param("acpi_sci", setup_acpi_sci);
Andrew Mortond0a90812006-10-20 14:30:27 -07001677
1678int __acpi_acquire_global_lock(unsigned int *lock)
1679{
1680 unsigned int old, new, val;
1681 do {
1682 old = *lock;
1683 new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
1684 val = cmpxchg(lock, old, new);
1685 } while (unlikely (val != old));
1686 return (new < 3) ? -1 : 0;
1687}
1688
1689int __acpi_release_global_lock(unsigned int *lock)
1690{
1691 unsigned int old, new, val;
1692 do {
1693 old = *lock;
1694 new = old & ~0x3;
1695 val = cmpxchg(lock, old, new);
1696 } while (unlikely (val != old));
1697 return old & 0x1;
1698}
Thomas Renninger8e305242012-10-01 00:23:53 +02001699
1700void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
1701{
1702 e820_add_region(addr, size, E820_ACPI);
1703 update_e820();
1704}