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