blob: c597ab5275b8ef268f50dfbe20e7f4bdeff75317 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * acpi.c - Architecture-Specific Low-Level ACPI Support
4 *
5 * Copyright (C) 1999 VA Linux Systems
6 * Copyright (C) 1999,2000 Walt Drummond <drummond@valinux.com>
7 * Copyright (C) 2000, 2002-2003 Hewlett-Packard Co.
8 * David Mosberger-Tang <davidm@hpl.hp.com>
9 * Copyright (C) 2000 Intel Corp.
10 * Copyright (C) 2000,2001 J.I. Lee <jung-ik.lee@intel.com>
11 * Copyright (C) 2001 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
12 * Copyright (C) 2001 Jenna Hall <jenna.s.hall@intel.com>
13 * Copyright (C) 2001 Takayoshi Kochi <t-kochi@bq.jp.nec.com>
14 * Copyright (C) 2002 Erich Focht <efocht@ess.nec.de>
Ashok Raj55e59c52005-03-31 22:51:10 -050015 * Copyright (C) 2004 Ashok Raj <ashok.raj@intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 */
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/kernel.h>
21#include <linux/sched.h>
22#include <linux/smp.h>
23#include <linux/string.h>
24#include <linux/types.h>
25#include <linux/irq.h>
26#include <linux/acpi.h>
27#include <linux/efi.h>
28#include <linux/mmzone.h>
29#include <linux/nodemask.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
Alex Chiangd8191fa2010-02-22 12:11:39 -070031#include <acpi/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/io.h>
33#include <asm/iosapic.h>
34#include <asm/machvec.h>
35#include <asm/page.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/numa.h>
37#include <asm/sal.h>
38#include <asm/cyclone.h>
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#define PREFIX "ACPI: "
41
Baoquan He247dba52014-05-05 12:48:25 +080042int acpi_lapic;
Ashok Raj55e59c52005-03-31 22:51:10 -050043unsigned int acpi_cpei_override;
44unsigned int acpi_cpei_phys_cpuid;
45
Len Browne8b2fd02007-07-24 22:26:33 -040046unsigned long acpi_wakeup_address = 0;
47
Len Brown239665a2007-11-23 20:08:02 -050048#ifdef CONFIG_IA64_GENERIC
49static unsigned long __init acpi_find_rsdp(void)
50{
51 unsigned long rsdp_phys = 0;
52
53 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
54 rsdp_phys = efi.acpi20;
55 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
56 printk(KERN_WARNING PREFIX
57 "v1.0/r0.71 tables no longer supported\n");
58 return rsdp_phys;
59}
Len Brown239665a2007-11-23 20:08:02 -050060
Tony Luckd57c4a32007-05-24 10:59:44 -070061const char __init *
62acpi_get_sysname(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 unsigned long rsdp_phys;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +030065 struct acpi_table_rsdp *rsdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 struct acpi_table_xsdt *xsdt;
67 struct acpi_table_header *hdr;
Suresh Siddhad3f13812011-08-23 17:05:25 -070068#ifdef CONFIG_INTEL_IOMMU
Fenghua Yu62fdd762008-10-17 12:14:13 -070069 u64 i, nentries;
70#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72 rsdp_phys = acpi_find_rsdp();
73 if (!rsdp_phys) {
Len Brown4be44fc2005-08-05 00:44:28 -040074 printk(KERN_ERR
75 "ACPI 2.0 RSDP not found, default to \"dig\"\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 return "dig";
77 }
78
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +030079 rsdp = (struct acpi_table_rsdp *)__va(rsdp_phys);
80 if (strncmp(rsdp->signature, ACPI_SIG_RSDP, sizeof(ACPI_SIG_RSDP) - 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -040081 printk(KERN_ERR
82 "ACPI 2.0 RSDP signature incorrect, default to \"dig\"\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 return "dig";
84 }
85
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +030086 xsdt = (struct acpi_table_xsdt *)__va(rsdp->xsdt_physical_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 hdr = &xsdt->header;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +030088 if (strncmp(hdr->signature, ACPI_SIG_XSDT, sizeof(ACPI_SIG_XSDT) - 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -040089 printk(KERN_ERR
90 "ACPI 2.0 XSDT signature incorrect, default to \"dig\"\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 return "dig";
92 }
93
94 if (!strcmp(hdr->oem_id, "HP")) {
95 return "hpzx1";
Len Brown4be44fc2005-08-05 00:44:28 -040096 } else if (!strcmp(hdr->oem_id, "SGI")) {
Jack Steiner22246612008-05-06 15:18:57 -050097 if (!strcmp(hdr->oem_table_id + 4, "UV"))
98 return "uv";
99 else
100 return "sn2";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 }
102
Suresh Siddhad3f13812011-08-23 17:05:25 -0700103#ifdef CONFIG_INTEL_IOMMU
Fenghua Yu62fdd762008-10-17 12:14:13 -0700104 /* Look for Intel IOMMU */
105 nentries = (hdr->length - sizeof(*hdr)) /
106 sizeof(xsdt->table_offset_entry[0]);
107 for (i = 0; i < nentries; i++) {
108 hdr = __va(xsdt->table_offset_entry[i]);
109 if (strncmp(hdr->signature, ACPI_SIG_DMAR,
110 sizeof(ACPI_SIG_DMAR) - 1) == 0)
111 return "dig_vtd";
112 }
113#endif
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 return "dig";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116}
Alex Chiangd8680802010-02-25 14:09:52 -0700117#endif /* CONFIG_IA64_GENERIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119#define ACPI_MAX_PLATFORM_INTERRUPTS 256
120
121/* Array to record platform interrupt vectors for generic interrupt routing. */
122int platform_intr_list[ACPI_MAX_PLATFORM_INTERRUPTS] = {
123 [0 ... ACPI_MAX_PLATFORM_INTERRUPTS - 1] = -1
124};
125
126enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_IOSAPIC;
127
128/*
129 * Interrupt routing API for device drivers. Provides interrupt vector for
130 * a generic platform event. Currently only CPEI is implemented.
131 */
Len Brown4be44fc2005-08-05 00:44:28 -0400132int acpi_request_vector(u32 int_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
134 int vector = -1;
135
136 if (int_type < ACPI_MAX_PLATFORM_INTERRUPTS) {
137 /* corrected platform error interrupt */
138 vector = platform_intr_list[int_type];
139 } else
Len Brown4be44fc2005-08-05 00:44:28 -0400140 printk(KERN_ERR
141 "acpi_request_vector(): invalid interrupt type\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 return vector;
143}
144
Andy Shevchenko6c9a58e2017-07-18 18:04:17 +0300145void __init __iomem *__acpi_map_table(unsigned long phys, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
Andy Shevchenko6c9a58e2017-07-18 18:04:17 +0300147 return __va(phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148}
149
Andy Shevchenko6c9a58e2017-07-18 18:04:17 +0300150void __init __acpi_unmap_table(void __iomem *map, unsigned long size)
Yinghai Lu7d972772009-02-07 15:39:41 -0800151{
152}
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154/* --------------------------------------------------------------------------
155 Boot-time Table Parsing
156 -------------------------------------------------------------------------- */
157
Len Brown4be44fc2005-08-05 00:44:28 -0400158static int available_cpus __initdata;
159struct acpi_table_madt *acpi_madt __initdata;
160static u8 has_8259;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162static int __init
Keith Busch60574d12019-03-11 14:55:57 -0600163acpi_parse_lapic_addr_ovr(union acpi_subtable_headers * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400164 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300166 struct acpi_madt_local_apic_override *lapic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300168 lapic = (struct acpi_madt_local_apic_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 if (BAD_MADT_ENTRY(lapic, end))
171 return -EINVAL;
172
173 if (lapic->address) {
174 iounmap(ipi_base_addr);
175 ipi_base_addr = ioremap(lapic->address, 0);
176 }
177 return 0;
178}
179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180static int __init
Keith Busch60574d12019-03-11 14:55:57 -0600181acpi_parse_lsapic(union acpi_subtable_headers *header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300183 struct acpi_madt_local_sapic *lsapic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300185 lsapic = (struct acpi_madt_local_sapic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300187 /*Skip BAD_MADT_ENTRY check, as lsapic size could vary */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300189 if (lsapic->lapic_flags & ACPI_MADT_ENABLED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190#ifdef CONFIG_SMP
Len Brown4be44fc2005-08-05 00:44:28 -0400191 smp_boot_data.cpu_phys_id[available_cpus] =
192 (lsapic->id << 8) | lsapic->eid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 ++available_cpus;
195 }
196
197 total_cpus++;
198 return 0;
199}
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201static int __init
Keith Busch60574d12019-03-11 14:55:57 -0600202acpi_parse_lapic_nmi(union acpi_subtable_headers * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300204 struct acpi_madt_local_apic_nmi *lacpi_nmi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300206 lacpi_nmi = (struct acpi_madt_local_apic_nmi *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208 if (BAD_MADT_ENTRY(lacpi_nmi, end))
209 return -EINVAL;
210
211 /* TBD: Support lapic_nmi entries */
212 return 0;
213}
214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215static int __init
Keith Busch60574d12019-03-11 14:55:57 -0600216acpi_parse_iosapic(union acpi_subtable_headers * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300218 struct acpi_madt_io_sapic *iosapic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300220 iosapic = (struct acpi_madt_io_sapic *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222 if (BAD_MADT_ENTRY(iosapic, end))
223 return -EINVAL;
224
Kenji Kaneshige0e888ad2005-04-28 00:25:58 -0700225 return iosapic_init(iosapic->address, iosapic->global_irq_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226}
227
Len Brown58104522006-05-13 01:12:15 -0400228static unsigned int __initdata acpi_madt_rev;
229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230static int __init
Keith Busch60574d12019-03-11 14:55:57 -0600231acpi_parse_plat_int_src(union acpi_subtable_headers * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400232 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300234 struct acpi_madt_interrupt_source *plintsrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 int vector;
236
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300237 plintsrc = (struct acpi_madt_interrupt_source *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
239 if (BAD_MADT_ENTRY(plintsrc, end))
240 return -EINVAL;
241
242 /*
243 * Get vector assignment for this interrupt, set attributes,
244 * and program the IOSAPIC routing table.
245 */
246 vector = iosapic_register_platform_intr(plintsrc->type,
247 plintsrc->global_irq,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300248 plintsrc->io_sapic_vector,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 plintsrc->eid,
250 plintsrc->id,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300251 ((plintsrc->inti_flags & ACPI_MADT_POLARITY_MASK) ==
252 ACPI_MADT_POLARITY_ACTIVE_HIGH) ?
253 IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
254 ((plintsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) ==
255 ACPI_MADT_TRIGGER_EDGE) ?
256 IOSAPIC_EDGE : IOSAPIC_LEVEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
258 platform_intr_list[plintsrc->type] = vector;
Ashok Raj55e59c52005-03-31 22:51:10 -0500259 if (acpi_madt_rev > 1) {
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300260 acpi_cpei_override = plintsrc->flags & ACPI_MADT_CPEI_OVERRIDE;
Ashok Raj55e59c52005-03-31 22:51:10 -0500261 }
262
263 /*
264 * Save the physical id, so we can check when its being removed
265 */
266 acpi_cpei_phys_cpuid = ((plintsrc->id << 8) | (plintsrc->eid)) & 0xffff;
267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 return 0;
269}
270
Ashok Rajb88e9262006-01-19 16:18:47 -0800271#ifdef CONFIG_HOTPLUG_CPU
Ashok Raj55e59c52005-03-31 22:51:10 -0500272unsigned int can_cpei_retarget(void)
273{
274 extern int cpe_vector;
Ashok Rajff741902005-11-11 14:32:40 -0800275 extern unsigned int force_cpei_retarget;
Ashok Raj55e59c52005-03-31 22:51:10 -0500276
277 /*
278 * Only if CPEI is supported and the override flag
279 * is present, otherwise return that its re-targettable
280 * if we are in polling mode.
281 */
Ashok Rajff741902005-11-11 14:32:40 -0800282 if (cpe_vector > 0) {
283 if (acpi_cpei_override || force_cpei_retarget)
284 return 1;
285 else
286 return 0;
287 }
288 return 1;
Ashok Raj55e59c52005-03-31 22:51:10 -0500289}
290
291unsigned int is_cpu_cpei_target(unsigned int cpu)
292{
293 unsigned int logical_id;
294
295 logical_id = cpu_logical_id(acpi_cpei_phys_cpuid);
296
297 if (logical_id == cpu)
298 return 1;
299 else
300 return 0;
301}
302
303void set_cpei_target_cpu(unsigned int cpu)
304{
305 acpi_cpei_phys_cpuid = cpu_physical_id(cpu);
306}
Ashok Rajb88e9262006-01-19 16:18:47 -0800307#endif
Ashok Raj55e59c52005-03-31 22:51:10 -0500308
309unsigned int get_cpei_target_cpu(void)
310{
311 return acpi_cpei_phys_cpuid;
312}
313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314static int __init
Keith Busch60574d12019-03-11 14:55:57 -0600315acpi_parse_int_src_ovr(union acpi_subtable_headers * header,
Len Brown4be44fc2005-08-05 00:44:28 -0400316 const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300318 struct acpi_madt_interrupt_override *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300320 p = (struct acpi_madt_interrupt_override *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322 if (BAD_MADT_ENTRY(p, end))
323 return -EINVAL;
324
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300325 iosapic_override_isa_irq(p->source_irq, p->global_irq,
326 ((p->inti_flags & ACPI_MADT_POLARITY_MASK) ==
Liu Jiang0577bb62012-03-13 22:07:09 +0800327 ACPI_MADT_POLARITY_ACTIVE_LOW) ?
328 IOSAPIC_POL_LOW : IOSAPIC_POL_HIGH,
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300329 ((p->inti_flags & ACPI_MADT_TRIGGER_MASK) ==
Liu Jiang0577bb62012-03-13 22:07:09 +0800330 ACPI_MADT_TRIGGER_LEVEL) ?
331 IOSAPIC_LEVEL : IOSAPIC_EDGE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 return 0;
333}
334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335static int __init
Keith Busch60574d12019-03-11 14:55:57 -0600336acpi_parse_nmi_src(union acpi_subtable_headers * header, const unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300338 struct acpi_madt_nmi_source *nmi_src;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300340 nmi_src = (struct acpi_madt_nmi_source *)header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342 if (BAD_MADT_ENTRY(nmi_src, end))
343 return -EINVAL;
344
345 /* TBD: Support nimsrc entries */
346 return 0;
347}
348
Len Brown4be44fc2005-08-05 00:44:28 -0400349static void __init acpi_madt_oem_check(char *oem_id, char *oem_table_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350{
Len Brown4be44fc2005-08-05 00:44:28 -0400351 if (!strncmp(oem_id, "IBM", 3) && (!strncmp(oem_table_id, "SERMOW", 6))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353 /*
354 * Unfortunately ITC_DRIFT is not yet part of the
355 * official SAL spec, so the ITC_DRIFT bit is not
356 * set by the BIOS on this hardware.
357 */
358 sal_platform_features |= IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT;
359
360 cyclone_setup();
361 }
362}
363
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300364static int __init acpi_parse_madt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365{
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300366 acpi_madt = (struct acpi_table_madt *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Ashok Raj55e59c52005-03-31 22:51:10 -0500368 acpi_madt_rev = acpi_madt->header.revision;
369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 /* remember the value for reference after free_initmem() */
371#ifdef CONFIG_ITANIUM
Len Brown4be44fc2005-08-05 00:44:28 -0400372 has_8259 = 1; /* Firmware on old Itanium systems is broken */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373#else
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300374 has_8259 = acpi_madt->flags & ACPI_MADT_PCAT_COMPAT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375#endif
376 iosapic_system_init(has_8259);
377
378 /* Get base address of IPI Message Block */
379
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300380 if (acpi_madt->address)
381 ipi_base_addr = ioremap(acpi_madt->address, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
383 printk(KERN_INFO PREFIX "Local APIC address %p\n", ipi_base_addr);
384
385 acpi_madt_oem_check(acpi_madt->header.oem_id,
Len Brown4be44fc2005-08-05 00:44:28 -0400386 acpi_madt->header.oem_table_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388 return 0;
389}
390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391#ifdef CONFIG_ACPI_NUMA
392
393#undef SLIT_DEBUG
394
395#define PXM_FLAG_LEN ((MAX_PXM_DOMAINS + 1)/32)
396
Len Brown4be44fc2005-08-05 00:44:28 -0400397static int __initdata srat_num_cpus; /* number of cpus */
Greg Kroah-Hartman5b5e76e2012-12-21 14:05:13 -0800398static u32 pxm_flag[PXM_FLAG_LEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399#define pxm_bit_set(bit) (set_bit(bit,(void *)pxm_flag))
400#define pxm_bit_test(bit) (test_bit(bit,(void *)pxm_flag))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401static struct acpi_table_slit __initdata *slit_table;
holt@sgi.com2c6e6db2008-04-03 15:17:13 -0500402cpumask_t early_cpu_possible_map = CPU_MASK_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Kurt Garloff9f10f6a2012-01-17 04:21:49 -0500404static int __init
405get_processor_proximity_domain(struct acpi_srat_cpu_affinity *pa)
Jack Steiner3ad5ef82006-03-02 16:02:25 -0600406{
407 int pxm;
408
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300409 pxm = pa->proximity_domain_lo;
Kurt Garloff9f10f6a2012-01-17 04:21:49 -0500410 if (ia64_platform_is("sn2") || acpi_srat_revision >= 2)
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300411 pxm += pa->proximity_domain_hi[0] << 8;
Jack Steiner3ad5ef82006-03-02 16:02:25 -0600412 return pxm;
413}
414
Kurt Garloff9f10f6a2012-01-17 04:21:49 -0500415static int __init
416get_memory_proximity_domain(struct acpi_srat_mem_affinity *ma)
Jack Steiner3ad5ef82006-03-02 16:02:25 -0600417{
418 int pxm;
419
420 pxm = ma->proximity_domain;
Kurt Garloff9f10f6a2012-01-17 04:21:49 -0500421 if (!ia64_platform_is("sn2") && acpi_srat_revision <= 1)
Alexey Starikovskiydefad232007-02-02 22:02:55 -0500422 pxm &= 0xff;
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300423
Jack Steiner3ad5ef82006-03-02 16:02:25 -0600424 return pxm;
425}
426
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427/*
428 * ACPI 2.0 SLIT (System Locality Information Table)
429 * http://devresource.hp.com/devresource/Docs/TechPapers/IA64/slit.pdf
430 */
Len Brown4be44fc2005-08-05 00:44:28 -0400431void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
433 u32 len;
434
435 len = sizeof(struct acpi_table_header) + 8
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300436 + slit->locality_count * slit->locality_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 if (slit->header.length != len) {
Len Brown4be44fc2005-08-05 00:44:28 -0400438 printk(KERN_ERR
439 "ACPI 2.0 SLIT: size mismatch: %d expected, %d actual\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 len, slit->header.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 return;
442 }
443 slit_table = slit;
444}
445
446void __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300447acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448{
Jack Steiner3ad5ef82006-03-02 16:02:25 -0600449 int pxm;
450
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300451 if (!(pa->flags & ACPI_SRAT_CPU_ENABLED))
Kenji Kaneshiged903cea2006-03-15 14:45:11 +0900452 return;
453
Tony Luck05f2f272011-01-07 09:11:55 -0800454 if (srat_num_cpus >= ARRAY_SIZE(node_cpuid)) {
455 printk_once(KERN_WARNING
Tony Luckdff00922011-01-12 11:02:43 -0800456 "node_cpuid[%ld] is too small, may not be able to use all cpus\n",
Tony Luck05f2f272011-01-07 09:11:55 -0800457 ARRAY_SIZE(node_cpuid));
458 return;
459 }
Jack Steiner3ad5ef82006-03-02 16:02:25 -0600460 pxm = get_processor_proximity_domain(pa);
461
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 /* record this node in proximity bitmap */
Jack Steiner3ad5ef82006-03-02 16:02:25 -0600463 pxm_bit_set(pxm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Len Brown4be44fc2005-08-05 00:44:28 -0400465 node_cpuid[srat_num_cpus].phys_id =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300466 (pa->apic_id << 8) | (pa->local_sapic_eid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 /* nid should be overridden as logical node id later */
Jack Steiner3ad5ef82006-03-02 16:02:25 -0600468 node_cpuid[srat_num_cpus].nid = pxm;
Rusty Russell5d2068d2015-03-05 10:49:16 +1030469 cpumask_set_cpu(srat_num_cpus, &early_cpu_possible_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 srat_num_cpus++;
471}
472
Thomas Renninger095adbb2012-07-31 17:41:09 +0200473int __init
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300474acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475{
476 unsigned long paddr, size;
Jack Steiner3ad5ef82006-03-02 16:02:25 -0600477 int pxm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 struct node_memblk_s *p, *q, *pend;
479
Jack Steiner3ad5ef82006-03-02 16:02:25 -0600480 pxm = get_memory_proximity_domain(ma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482 /* fill node memory chunk structure */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300483 paddr = ma->base_address;
484 size = ma->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
486 /* Ignore disabled entries */
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300487 if (!(ma->flags & ACPI_SRAT_MEM_ENABLED))
Thomas Renninger095adbb2012-07-31 17:41:09 +0200488 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
Ganapatrao Kulkarnifd3e4542017-11-15 22:59:02 +0530490 if (num_node_memblks >= NR_NODE_MEMBLKS) {
491 pr_err("NUMA: too many memblk ranges\n");
492 return -EINVAL;
493 }
494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 /* record this node in proximity bitmap */
496 pxm_bit_set(pxm);
497
498 /* Insertion sort based on base address */
499 pend = &node_memblk[num_node_memblks];
500 for (p = &node_memblk[0]; p < pend; p++) {
501 if (paddr < p->start_paddr)
502 break;
503 }
504 if (p < pend) {
505 for (q = pend - 1; q >= p; q--)
506 *(q + 1) = *q;
507 }
508 p->start_paddr = paddr;
509 p->size = size;
510 p->nid = pxm;
511 num_node_memblks++;
Thomas Renninger095adbb2012-07-31 17:41:09 +0200512 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513}
514
Robert Richter312521d2016-05-24 15:35:34 -0700515void __init acpi_numa_fixup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516{
517 int i, j, node_from, node_to;
518
519 /* If there's no SRAT, fix the phys_id and mark node 0 online */
520 if (srat_num_cpus == 0) {
521 node_set_online(0);
522 node_cpuid[0].phys_id = hard_smp_processor_id();
523 return;
524 }
525
526 /*
527 * MCD - This can probably be dropped now. No need for pxm ID to node ID
528 * mapping with sparse node numbering iff MAX_PXM_DOMAINS <= MAX_NUMNODES.
529 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 nodes_clear(node_online_map);
531 for (i = 0; i < MAX_PXM_DOMAINS; i++) {
532 if (pxm_bit_test(i)) {
Yasunori Goto762834e2006-06-23 02:03:19 -0700533 int nid = acpi_map_pxm_to_node(i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 node_set_online(nid);
535 }
536 }
537
538 /* set logical node id in memory chunk structure */
539 for (i = 0; i < num_node_memblks; i++)
Yasunori Goto762834e2006-06-23 02:03:19 -0700540 node_memblk[i].nid = pxm_to_node(node_memblk[i].nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
542 /* assign memory bank numbers for each chunk on each node */
543 for_each_online_node(i) {
544 int bank;
545
546 bank = 0;
547 for (j = 0; j < num_node_memblks; j++)
548 if (node_memblk[j].nid == i)
549 node_memblk[j].bank = bank++;
550 }
551
552 /* set logical node id in cpu structure */
holt@sgi.com2c6e6db2008-04-03 15:17:13 -0500553 for_each_possible_early_cpu(i)
Yasunori Goto762834e2006-06-23 02:03:19 -0700554 node_cpuid[i].nid = pxm_to_node(node_cpuid[i].nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Len Brown4be44fc2005-08-05 00:44:28 -0400556 printk(KERN_INFO "Number of logical nodes in system = %d\n",
557 num_online_nodes());
558 printk(KERN_INFO "Number of memory chunks in system = %d\n",
559 num_node_memblks);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Fenghua Yu39b89312008-06-09 16:48:18 -0700561 if (!slit_table) {
562 for (i = 0; i < MAX_NUMNODES; i++)
563 for (j = 0; j < MAX_NUMNODES; j++)
Matias Bjørlingef78e5e2018-11-26 11:27:03 -0800564 slit_distance(i, j) = i == j ?
565 LOCAL_DISTANCE : REMOTE_DISTANCE;
Len Brown4be44fc2005-08-05 00:44:28 -0400566 return;
Fenghua Yu39b89312008-06-09 16:48:18 -0700567 }
568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 memset(numa_slit, -1, sizeof(numa_slit));
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300570 for (i = 0; i < slit_table->locality_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 if (!pxm_bit_test(i))
572 continue;
Yasunori Goto762834e2006-06-23 02:03:19 -0700573 node_from = pxm_to_node(i);
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300574 for (j = 0; j < slit_table->locality_count; j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 if (!pxm_bit_test(j))
576 continue;
Yasunori Goto762834e2006-06-23 02:03:19 -0700577 node_to = pxm_to_node(j);
Matias Bjørlingef78e5e2018-11-26 11:27:03 -0800578 slit_distance(node_from, node_to) =
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300579 slit_table->entry[i * slit_table->locality_count + j];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 }
581 }
582
583#ifdef SLIT_DEBUG
584 printk("ACPI 2.0 SLIT locality table:\n");
585 for_each_online_node(i) {
586 for_each_online_node(j)
Len Brown4be44fc2005-08-05 00:44:28 -0400587 printk("%03d ", node_distance(i, j));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 printk("\n");
589 }
590#endif
591}
Len Brown4be44fc2005-08-05 00:44:28 -0400592#endif /* CONFIG_ACPI_NUMA */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
Kenji Kaneshige1f3a6a12005-07-28 14:42:00 -0400594/*
595 * success: return IRQ number (>=0)
596 * failure: return < 0
597 */
Yinghai Lua2f809b2009-04-27 18:01:20 -0700598int acpi_register_gsi(struct device *dev, u32 gsi, int triggering, int polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599{
John Keller3948ec92006-12-22 11:50:04 -0600600 if (acpi_irq_model == ACPI_IRQ_MODEL_PLATFORM)
601 return gsi;
602
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 if (has_8259 && gsi < 16)
604 return isa_irq_to_vector(gsi);
605
606 return iosapic_register_intr(gsi,
Len Browncb654692005-12-28 02:43:51 -0500607 (polarity ==
Len Brown4be44fc2005-08-05 00:44:28 -0400608 ACPI_ACTIVE_HIGH) ? IOSAPIC_POL_HIGH :
609 IOSAPIC_POL_LOW,
Len Browncb654692005-12-28 02:43:51 -0500610 (triggering ==
Len Brown4be44fc2005-08-05 00:44:28 -0400611 ACPI_EDGE_SENSITIVE) ? IOSAPIC_EDGE :
612 IOSAPIC_LEVEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613}
Mika Westerberga42b9bf2012-10-31 22:44:55 +0100614EXPORT_SYMBOL_GPL(acpi_register_gsi);
Len Brown4be44fc2005-08-05 00:44:28 -0400615
Len Brown4be44fc2005-08-05 00:44:28 -0400616void acpi_unregister_gsi(u32 gsi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617{
John Keller72253942007-02-03 01:14:02 -0800618 if (acpi_irq_model == ACPI_IRQ_MODEL_PLATFORM)
619 return;
620
Prarit Bhargava3fb2c742008-05-14 12:00:24 -0400621 if (has_8259 && gsi < 16)
622 return;
623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 iosapic_unregister_intr(gsi);
625}
Mika Westerberga42b9bf2012-10-31 22:44:55 +0100626EXPORT_SYMBOL_GPL(acpi_unregister_gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300628static int __init acpi_parse_fadt(struct acpi_table_header *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629{
630 struct acpi_table_header *fadt_header;
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300631 struct acpi_table_fadt *fadt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300633 fadt_header = (struct acpi_table_header *)table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 if (fadt_header->revision != 3)
Len Brown4be44fc2005-08-05 00:44:28 -0400635 return -ENODEV; /* Only deal with ACPI 2.0 FADT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300637 fadt = (struct acpi_table_fadt *)fadt_header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Yinghai Lua2f809b2009-04-27 18:01:20 -0700639 acpi_register_gsi(NULL, fadt->sci_interrupt, ACPI_LEVEL_SENSITIVE,
640 ACPI_ACTIVE_LOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 return 0;
642}
643
Doug Chapman62ee0542008-11-05 17:57:52 -0500644int __init early_acpi_boot_init(void)
645{
646 int ret;
647
648 /*
649 * do a partial walk of MADT to determine how many CPUs
650 * we have including offline CPUs
651 */
652 if (acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
653 printk(KERN_ERR PREFIX "Can't find MADT\n");
654 return 0;
655 }
656
657 ret = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
658 acpi_parse_lsapic, NR_CPUS);
659 if (ret < 1)
660 printk(KERN_ERR PREFIX
661 "Error parsing MADT - no LAPIC entries\n");
Baoquan He247dba52014-05-05 12:48:25 +0800662 else
663 acpi_lapic = 1;
Doug Chapman62ee0542008-11-05 17:57:52 -0500664
Tejun Heo12cda812009-10-02 13:28:56 +0900665#ifdef CONFIG_SMP
666 if (available_cpus == 0) {
667 printk(KERN_INFO "ACPI: Found 0 CPUS; assuming 1\n");
668 printk(KERN_INFO "CPU 0 (0x%04x)", hard_smp_processor_id());
669 smp_boot_data.cpu_phys_id[available_cpus] =
670 hard_smp_processor_id();
671 available_cpus = 1; /* We've got at least one of these, no? */
672 }
673 smp_boot_data.cpu_count = available_cpus;
674#endif
675 /* Make boot-up look pretty */
676 printk(KERN_INFO "%d CPUs available, %d CPUs total\n", available_cpus,
677 total_cpus);
678
Doug Chapman62ee0542008-11-05 17:57:52 -0500679 return 0;
680}
681
Len Brown4be44fc2005-08-05 00:44:28 -0400682int __init acpi_boot_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683{
684
685 /*
686 * MADT
687 * ----
688 * Parse the Multiple APIC Description Table (MADT), if exists.
689 * Note that this table provides platform SMP configuration
690 * information -- the successor to MPS tables.
691 */
692
John Kellerdb2d4cc2007-02-16 15:07:27 -0600693 if (acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 printk(KERN_ERR PREFIX "Can't find MADT\n");
695 goto skip_madt;
696 }
697
698 /* Local APIC */
699
Len Brown4be44fc2005-08-05 00:44:28 -0400700 if (acpi_table_parse_madt
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300701 (ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE, acpi_parse_lapic_addr_ovr, 0) < 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400702 printk(KERN_ERR PREFIX
703 "Error parsing LAPIC address override entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300705 if (acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400706 < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
708
709 /* I/O APIC */
710
Len Brown4be44fc2005-08-05 00:44:28 -0400711 if (acpi_table_parse_madt
George Beshers7f6ff622007-10-11 15:33:55 -0400712 (ACPI_MADT_TYPE_IO_SAPIC, acpi_parse_iosapic, NR_IOSAPICS) < 1) {
713 if (!ia64_platform_is("sn2"))
714 printk(KERN_ERR PREFIX
715 "Error parsing MADT - no IOSAPIC entries\n");
716 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
718 /* System-Level Interrupt Routing */
719
Len Brown4be44fc2005-08-05 00:44:28 -0400720 if (acpi_table_parse_madt
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300721 (ACPI_MADT_TYPE_INTERRUPT_SOURCE, acpi_parse_plat_int_src,
Len Brown4be44fc2005-08-05 00:44:28 -0400722 ACPI_MAX_PLATFORM_INTERRUPTS) < 0)
723 printk(KERN_ERR PREFIX
724 "Error parsing platform interrupt source entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Len Brown4be44fc2005-08-05 00:44:28 -0400726 if (acpi_table_parse_madt
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300727 (ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr, 0) < 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400728 printk(KERN_ERR PREFIX
729 "Error parsing interrupt source overrides entry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300731 if (acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src, 0) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
Len Brown4be44fc2005-08-05 00:44:28 -0400733 skip_madt:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
735 /*
736 * FADT says whether a legacy keyboard controller is present.
737 * The FADT also contains an SCI_INT line, by which the system
738 * gets interrupts such as power and sleep buttons. If it's not
739 * on a Legacy interrupt, it needs to be setup.
740 */
John Kellerdb2d4cc2007-02-16 15:07:27 -0600741 if (acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 printk(KERN_ERR PREFIX "Can't find FADT\n");
743
Tejun Heo12cda812009-10-02 13:28:56 +0900744#ifdef CONFIG_ACPI_NUMA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745#ifdef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 if (srat_num_cpus == 0) {
747 int cpu, i = 1;
748 for (cpu = 0; cpu < smp_boot_data.cpu_count; cpu++)
Len Brown4be44fc2005-08-05 00:44:28 -0400749 if (smp_boot_data.cpu_phys_id[cpu] !=
750 hard_smp_processor_id())
751 node_cpuid[i++].phys_id =
752 smp_boot_data.cpu_phys_id[cpu];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754#endif
Tony Luck8d7e3512005-07-06 18:18:10 -0700755 build_cpu_to_node_map();
756#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 return 0;
758}
759
Len Brown4be44fc2005-08-05 00:44:28 -0400760int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761{
Kenji Kaneshige3c3738c2007-07-26 15:31:34 +0900762 int tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
764 if (has_8259 && gsi < 16)
765 *irq = isa_irq_to_vector(gsi);
766 else {
Kenji Kaneshige3c3738c2007-07-26 15:31:34 +0900767 tmp = gsi_to_irq(gsi);
768 if (tmp == -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 return -1;
Kenji Kaneshige3c3738c2007-07-26 15:31:34 +0900770 *irq = tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 }
772 return 0;
773}
774
Eric W. Biederman2c2df842010-03-30 01:07:02 -0700775int acpi_isa_irq_to_gsi(unsigned isa_irq, u32 *gsi)
776{
777 if (isa_irq >= 16)
778 return -1;
779 *gsi = isa_irq;
780 return 0;
781}
782
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783/*
784 * ACPI based hotplug CPU support
785 */
786#ifdef CONFIG_ACPI_HOTPLUG_CPU
Gu Zhengdc6db242016-08-25 16:35:18 +0800787int acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788{
789#ifdef CONFIG_ACPI_NUMA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 /*
KAMEZAWA Hiroyuki08992982006-09-25 16:25:21 -0700791 * We don't have cpu-only-node hotadd. But if the system equips
792 * SRAT table, pxm is already found and node is ready.
793 * So, just pxm_to_nid(pxm) is OK.
794 * This code here is for the system which doesn't have full SRAT
795 * table for possible cpus.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 */
Len Brown4be44fc2005-08-05 00:44:28 -0400797 node_cpuid[cpu].phys_id = physid;
Bjorn Helgaasb1e9cee2014-01-24 15:28:42 -0700798 node_cpuid[cpu].nid = acpi_get_node(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799#endif
Bjorn Helgaasb1e9cee2014-01-24 15:28:42 -0700800 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801}
802
Ashok Raja6b14fa2006-02-14 15:01:12 -0800803int additional_cpus __initdata = -1;
804
805static __init int setup_additional_cpus(char *s)
806{
807 if (s)
808 additional_cpus = simple_strtol(s, NULL, 0);
809
810 return 0;
811}
812
813early_param("additional_cpus", setup_additional_cpus);
814
815/*
Rusty Russell5f054e32012-03-29 15:38:31 +1030816 * cpu_possible_mask should be static, it cannot change as CPUs
Ashok Raja6b14fa2006-02-14 15:01:12 -0800817 * are onlined, or offlined. The reason is per-cpu data-structures
818 * are allocated by some modules at init time, and dont expect to
819 * do this dynamically on cpu arrival/departure.
Srivatsa S. Bhat7d7f9842012-03-28 14:42:46 -0700820 * cpu_present_mask on the other hand can change dynamically.
Ashok Raja6b14fa2006-02-14 15:01:12 -0800821 * In case when cpu_hotplug is not compiled, then we resort to current
822 * behaviour, which is cpu_possible == cpu_present.
823 * - Ashok Raj
824 *
825 * Three ways to find out the number of additional hotplug CPUs:
826 * - If the BIOS specified disabled CPUs in ACPI/mptables use that.
827 * - The user can overwrite it with additional_cpus=NUM
828 * - Otherwise don't reserve additional CPUs.
829 */
830__init void prefill_possible_map(void)
831{
832 int i;
833 int possible, disabled_cpus;
834
835 disabled_cpus = total_cpus - available_cpus;
Ashok Raj8f8b11382006-02-16 14:01:48 -0800836
Ashok Raja6b14fa2006-02-14 15:01:12 -0800837 if (additional_cpus == -1) {
Ashok Raj8f8b11382006-02-16 14:01:48 -0800838 if (disabled_cpus > 0)
Ashok Raja6b14fa2006-02-14 15:01:12 -0800839 additional_cpus = disabled_cpus;
Ashok Raj8f8b11382006-02-16 14:01:48 -0800840 else
Ashok Raja6b14fa2006-02-14 15:01:12 -0800841 additional_cpus = 0;
Ashok Raj8f8b11382006-02-16 14:01:48 -0800842 }
843
844 possible = available_cpus + additional_cpus;
845
Yinghai Lu2b633e32010-02-10 01:20:37 -0800846 if (possible > nr_cpu_ids)
847 possible = nr_cpu_ids;
Ashok Raja6b14fa2006-02-14 15:01:12 -0800848
849 printk(KERN_INFO "SMP: Allowing %d CPUs, %d hotplug CPUs\n",
Ashok Raj8f8b11382006-02-16 14:01:48 -0800850 possible, max((possible - available_cpus), 0));
Ashok Raja6b14fa2006-02-14 15:01:12 -0800851
852 for (i = 0; i < possible; i++)
Rusty Russell2af51a32009-03-16 14:12:43 +1030853 set_cpu_possible(i, true);
Ashok Raja6b14fa2006-02-14 15:01:12 -0800854}
855
Jiang Liud536bf32013-09-02 11:57:35 +0800856static int _acpi_map_lsapic(acpi_handle handle, int physid, int *pcpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 cpumask_t tmp_map;
Jiang Liud536bf32013-09-02 11:57:35 +0800859 int cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Rusty Russell5dd3c992009-03-16 14:12:42 +1030861 cpumask_complement(&tmp_map, cpu_present_mask);
862 cpu = cpumask_first(&tmp_map);
863 if (cpu >= nr_cpu_ids)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 return -EINVAL;
865
866 acpi_map_cpu2node(handle, cpu, physid);
867
Srivatsa S. Bhat7d7f9842012-03-28 14:42:46 -0700868 set_cpu_present(cpu, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 ia64_cpu_to_sapicid[cpu] = physid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
Alex Chiangd8191fa2010-02-22 12:11:39 -0700871 acpi_processor_set_pdc(handle);
872
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 *pcpu = cpu;
Len Brown4be44fc2005-08-05 00:44:28 -0400874 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875}
Len Brown4be44fc2005-08-05 00:44:28 -0400876
Jan Beulichaf10f942011-02-17 16:36:24 +0000877/* wrapper to silence section mismatch warning */
Vitaly Kuznetsovfebf2402017-02-06 18:01:51 +0100878int __ref acpi_map_cpu(acpi_handle handle, phys_cpuid_t physid, u32 acpi_id,
879 int *pcpu)
Jan Beulichaf10f942011-02-17 16:36:24 +0000880{
Jiang Liud536bf32013-09-02 11:57:35 +0800881 return _acpi_map_lsapic(handle, physid, pcpu);
Jan Beulichaf10f942011-02-17 16:36:24 +0000882}
Hanjun Guod02dc272015-01-04 18:55:03 +0800883EXPORT_SYMBOL(acpi_map_cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884
Hanjun Guod02dc272015-01-04 18:55:03 +0800885int acpi_unmap_cpu(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 ia64_cpu_to_sapicid[cpu] = -1;
Srivatsa S. Bhat7d7f9842012-03-28 14:42:46 -0700888 set_cpu_present(cpu, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
890#ifdef CONFIG_ACPI_NUMA
891 /* NUMA specific cleanup's */
892#endif
893
Len Brown4be44fc2005-08-05 00:44:28 -0400894 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895}
Hanjun Guod02dc272015-01-04 18:55:03 +0800896EXPORT_SYMBOL(acpi_unmap_cpu);
Len Brown4be44fc2005-08-05 00:44:28 -0400897#endif /* CONFIG_ACPI_HOTPLUG_CPU */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
899#ifdef CONFIG_ACPI_NUMA
Greg Kroah-Hartman5b5e76e2012-12-21 14:05:13 -0800900static acpi_status acpi_map_iosapic(acpi_handle handle, u32 depth,
901 void *context, void **ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902{
Len Brown4be44fc2005-08-05 00:44:28 -0400903 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 union acpi_object *obj;
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300905 struct acpi_madt_io_sapic *iosapic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 unsigned int gsi_base;
Bjorn Helgaasb1e9cee2014-01-24 15:28:42 -0700907 int node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
909 /* Only care about objects w/ a method that returns the MADT */
910 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
911 return AE_OK;
912
913 if (!buffer.length || !buffer.pointer)
914 return AE_OK;
915
916 obj = buffer.pointer;
917 if (obj->type != ACPI_TYPE_BUFFER ||
918 obj->buffer.length < sizeof(*iosapic)) {
Len Brown02438d82006-06-30 03:19:10 -0400919 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 return AE_OK;
921 }
922
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300923 iosapic = (struct acpi_madt_io_sapic *)obj->buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Alexey Starikovskiy5f3b1a82007-02-02 19:48:22 +0300925 if (iosapic->header.type != ACPI_MADT_TYPE_IO_SAPIC) {
Len Brown02438d82006-06-30 03:19:10 -0400926 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 return AE_OK;
928 }
929
930 gsi_base = iosapic->global_irq_base;
931
Len Brown02438d82006-06-30 03:19:10 -0400932 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
Bjorn Helgaasb1e9cee2014-01-24 15:28:42 -0700934 /* OK, it's an IOSAPIC MADT entry; associate it with a node */
935 node = acpi_get_node(handle);
936 if (node == NUMA_NO_NODE || !node_online(node) ||
Rusty Russellfbb776c2008-12-26 22:23:40 +1030937 cpumask_empty(cpumask_of_node(node)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 return AE_OK;
939
940 /* We know a gsi to node mapping! */
941 map_iosapic_to_node(gsi_base, node);
942 return AE_OK;
943}
Bjorn Helgaas650316f2005-09-16 11:43:45 -0600944
945static int __init
946acpi_map_iosapics (void)
947{
948 acpi_get_devices(NULL, acpi_map_iosapic, NULL, NULL);
949 return 0;
950}
951
952fs_initcall(acpi_map_iosapics);
953#endif /* CONFIG_ACPI_NUMA */
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700954
Hidetoshi Setoc5b5a592008-04-30 16:51:06 +0900955int __ref acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700956{
Kenji Kaneshige0e888ad2005-04-28 00:25:58 -0700957 int err;
958
959 if ((err = iosapic_init(phys_addr, gsi_base)))
960 return err;
961
Peter Chubb24b8e0c2005-09-15 15:36:35 +1000962#ifdef CONFIG_ACPI_NUMA
Kenji Kaneshige0e888ad2005-04-28 00:25:58 -0700963 acpi_map_iosapic(handle, 0, NULL, NULL);
Len Brown4be44fc2005-08-05 00:44:28 -0400964#endif /* CONFIG_ACPI_NUMA */
Kenji Kaneshige0e888ad2005-04-28 00:25:58 -0700965
966 return 0;
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700967}
Len Brown4be44fc2005-08-05 00:44:28 -0400968
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700969EXPORT_SYMBOL(acpi_register_ioapic);
970
Len Brown4be44fc2005-08-05 00:44:28 -0400971int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700972{
Kenji Kaneshige0e888ad2005-04-28 00:25:58 -0700973 return iosapic_remove(gsi_base);
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700974}
Len Brown4be44fc2005-08-05 00:44:28 -0400975
Kenji Kaneshigeb1bb2482005-04-28 00:25:58 -0700976EXPORT_SYMBOL(acpi_unregister_ioapic);
977
Len Browne8b2fd02007-07-24 22:26:33 -0400978/*
Rafael J. Wysockif1a20032011-02-08 23:42:22 +0100979 * acpi_suspend_lowlevel() - save kernel state and suspend.
Len Browne8b2fd02007-07-24 22:26:33 -0400980 *
981 * TBD when when IA64 starts to support suspend...
982 */
Rafael J. Wysockif1a20032011-02-08 23:42:22 +0100983int acpi_suspend_lowlevel(void) { return 0; }