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 bool acpi_int_src_ovr[NR_IRQS_LEGACY];
56
57 /* ACPI SCI override configuration */
58 u8 acpi_sci_flags __initdata;
59 u32 acpi_sci_override_gsi __initdata = INVALID_ACPI_IRQ;
60 int acpi_skip_timer_override __initdata;
61 int acpi_use_timer_override __initdata;
62 int acpi_fix_pin2_polarity __initdata;
63
64 #ifdef CONFIG_X86_LOCAL_APIC
65 static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
66 static bool has_lapic_cpus __initdata;
67 static bool acpi_support_online_capable;
68 #endif
69
70 #ifdef CONFIG_X86_IO_APIC
71 /*
72 * Locks related to IOAPIC hotplug
73 * Hotplug side:
74 * ->device_hotplug_lock
75 * ->acpi_ioapic_lock
76 * ->ioapic_lock
77 * Interrupt mapping side:
78 * ->acpi_ioapic_lock
79 * ->ioapic_mutex
80 * ->ioapic_lock
81 */
82 static DEFINE_MUTEX(acpi_ioapic_lock);
83 #endif
84
85 /* --------------------------------------------------------------------------
86 Boot-time Configuration
87 -------------------------------------------------------------------------- */
88
89 /*
90 * The default interrupt routing model is PIC (8259). This gets
91 * overridden if IOAPICs are enumerated (below).
92 */
93 enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
94
95
96 /*
97 * ISA irqs by default are the first 16 gsis but can be
98 * any gsi as specified by an interrupt source override.
99 */
100 static u32 isa_irq_to_gsi[NR_IRQS_LEGACY] __read_mostly = {
101 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
102 };
103
104 /*
105 * This is just a simple wrapper around early_memremap(),
106 * with sanity checks for phys == 0 and size == 0.
107 */
__acpi_map_table(unsigned long phys,unsigned long size)108 void __init __iomem *__acpi_map_table(unsigned long phys, unsigned long size)
109 {
110
111 if (!phys || !size)
112 return NULL;
113
114 return early_memremap(phys, size);
115 }
116
__acpi_unmap_table(void __iomem * map,unsigned long size)117 void __init __acpi_unmap_table(void __iomem *map, unsigned long size)
118 {
119 if (!map || !size)
120 return;
121
122 early_memunmap(map, size);
123 }
124
125 #ifdef CONFIG_X86_LOCAL_APIC
acpi_parse_madt(struct acpi_table_header * table)126 static int __init acpi_parse_madt(struct acpi_table_header *table)
127 {
128 struct acpi_table_madt *madt = NULL;
129
130 if (!boot_cpu_has(X86_FEATURE_APIC))
131 return -EINVAL;
132
133 madt = (struct acpi_table_madt *)table;
134 if (!madt) {
135 pr_warn("Unable to map MADT\n");
136 return -ENODEV;
137 }
138
139 if (madt->address) {
140 acpi_lapic_addr = (u64) madt->address;
141
142 pr_debug("Local APIC address 0x%08x\n", madt->address);
143 }
144
145 if (madt->flags & ACPI_MADT_PCAT_COMPAT)
146 legacy_pic_pcat_compat();
147
148 /* ACPI 6.3 and newer support the online capable bit. */
149 if (acpi_gbl_FADT.header.revision > 6 ||
150 (acpi_gbl_FADT.header.revision == 6 &&
151 acpi_gbl_FADT.minor_revision >= 3))
152 acpi_support_online_capable = true;
153
154 default_acpi_madt_oem_check(madt->header.oem_id,
155 madt->header.oem_table_id);
156
157 return 0;
158 }
159
acpi_is_processor_usable(u32 lapic_flags)160 static bool __init acpi_is_processor_usable(u32 lapic_flags)
161 {
162 if (lapic_flags & ACPI_MADT_ENABLED)
163 return true;
164
165 if (!acpi_support_online_capable ||
166 (lapic_flags & ACPI_MADT_ONLINE_CAPABLE))
167 return true;
168
169 return false;
170 }
171
172 static int __init
acpi_parse_x2apic(union acpi_subtable_headers * header,const unsigned long end)173 acpi_parse_x2apic(union acpi_subtable_headers *header, const unsigned long end)
174 {
175 struct acpi_madt_local_x2apic *processor = NULL;
176 #ifdef CONFIG_X86_X2APIC
177 u32 apic_id;
178 u8 enabled;
179 #endif
180
181 processor = (struct acpi_madt_local_x2apic *)header;
182
183 if (BAD_MADT_ENTRY(processor, end))
184 return -EINVAL;
185
186 acpi_table_print_madt_entry(&header->common);
187
188 #ifdef CONFIG_X86_X2APIC
189 apic_id = processor->local_apic_id;
190 enabled = processor->lapic_flags & ACPI_MADT_ENABLED;
191
192 /* Ignore invalid ID */
193 if (apic_id == 0xffffffff)
194 return 0;
195
196 /* don't register processors that cannot be onlined */
197 if (!acpi_is_processor_usable(processor->lapic_flags))
198 return 0;
199
200 /*
201 * According to https://uefi.org/specs/ACPI/6.5/05_ACPI_Software_Programming_Model.html#processor-local-x2apic-structure
202 * when MADT provides both valid LAPIC and x2APIC entries, the APIC ID
203 * in x2APIC must be equal or greater than 0xff.
204 */
205 if (has_lapic_cpus && apic_id < 0xff)
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_id_valid(apic_id)) {
216 if (enabled)
217 pr_warn("x2apic entry ignored\n");
218 return 0;
219 }
220
221 topology_register_apic(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 /* don't register processors that can not be onlined */
246 if (!acpi_is_processor_usable(processor->lapic_flags))
247 return 0;
248
249 /*
250 * We need to register disabled CPU as well to permit
251 * counting disabled CPUs. This allows us to size
252 * cpus_possible_map more accurately, to permit
253 * to not preallocating memory for all NR_CPUS
254 * when we use CPU hotplug.
255 */
256 topology_register_apic(processor->id, /* APIC ID */
257 processor->processor_id, /* ACPI ID */
258 processor->lapic_flags & ACPI_MADT_ENABLED);
259
260 has_lapic_cpus = true;
261 return 0;
262 }
263
264 static int __init
acpi_parse_sapic(union acpi_subtable_headers * header,const unsigned long end)265 acpi_parse_sapic(union acpi_subtable_headers *header, const unsigned long end)
266 {
267 struct acpi_madt_local_sapic *processor = NULL;
268
269 processor = (struct acpi_madt_local_sapic *)header;
270
271 if (BAD_MADT_ENTRY(processor, end))
272 return -EINVAL;
273
274 acpi_table_print_madt_entry(&header->common);
275
276 topology_register_apic((processor->id << 8) | processor->eid,/* APIC ID */
277 processor->processor_id, /* ACPI ID */
278 processor->lapic_flags & ACPI_MADT_ENABLED);
279
280 return 0;
281 }
282
283 static int __init
acpi_parse_lapic_addr_ovr(union acpi_subtable_headers * header,const unsigned long end)284 acpi_parse_lapic_addr_ovr(union acpi_subtable_headers * header,
285 const unsigned long end)
286 {
287 struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
288
289 lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
290
291 if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
292 return -EINVAL;
293
294 acpi_table_print_madt_entry(&header->common);
295
296 acpi_lapic_addr = lapic_addr_ovr->address;
297
298 return 0;
299 }
300
301 static int __init
acpi_parse_x2apic_nmi(union acpi_subtable_headers * header,const unsigned long end)302 acpi_parse_x2apic_nmi(union acpi_subtable_headers *header,
303 const unsigned long end)
304 {
305 struct acpi_madt_local_x2apic_nmi *x2apic_nmi = NULL;
306
307 x2apic_nmi = (struct acpi_madt_local_x2apic_nmi *)header;
308
309 if (BAD_MADT_ENTRY(x2apic_nmi, end))
310 return -EINVAL;
311
312 acpi_table_print_madt_entry(&header->common);
313
314 if (x2apic_nmi->lint != 1)
315 pr_warn("NMI not connected to LINT 1!\n");
316
317 return 0;
318 }
319
320 static int __init
acpi_parse_lapic_nmi(union acpi_subtable_headers * header,const unsigned long end)321 acpi_parse_lapic_nmi(union acpi_subtable_headers * header, const unsigned long end)
322 {
323 struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
324
325 lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
326
327 if (BAD_MADT_ENTRY(lapic_nmi, end))
328 return -EINVAL;
329
330 acpi_table_print_madt_entry(&header->common);
331
332 if (lapic_nmi->lint != 1)
333 pr_warn("NMI not connected to LINT 1!\n");
334
335 return 0;
336 }
337 #endif /* CONFIG_X86_LOCAL_APIC */
338
339 #ifdef CONFIG_X86_IO_APIC
340 #define MP_ISA_BUS 0
341
342 static int __init mp_register_ioapic_irq(u8 bus_irq, u8 polarity,
343 u8 trigger, u32 gsi);
344
mp_override_legacy_irq(u8 bus_irq,u8 polarity,u8 trigger,u32 gsi)345 static void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger,
346 u32 gsi)
347 {
348 /*
349 * Check bus_irq boundary.
350 */
351 if (bus_irq >= NR_IRQS_LEGACY) {
352 pr_warn("Invalid bus_irq %u for legacy override\n", bus_irq);
353 return;
354 }
355
356 /*
357 * TBD: This check is for faulty timer entries, where the override
358 * erroneously sets the trigger to level, resulting in a HUGE
359 * increase of timer interrupts!
360 */
361 if ((bus_irq == 0) && (trigger == 3))
362 trigger = 1;
363
364 if (mp_register_ioapic_irq(bus_irq, polarity, trigger, gsi) < 0)
365 return;
366 /*
367 * Reset default identity mapping if gsi is also an legacy IRQ,
368 * otherwise there will be more than one entry with the same GSI
369 * and acpi_isa_irq_to_gsi() may give wrong result.
370 */
371 if (gsi < nr_legacy_irqs() && isa_irq_to_gsi[gsi] == gsi)
372 isa_irq_to_gsi[gsi] = INVALID_ACPI_IRQ;
373 isa_irq_to_gsi[bus_irq] = gsi;
374 }
375
mp_config_acpi_gsi(struct device * dev,u32 gsi,int trigger,int polarity)376 static void mp_config_acpi_gsi(struct device *dev, u32 gsi, int trigger,
377 int polarity)
378 {
379 #ifdef CONFIG_X86_MPPARSE
380 struct mpc_intsrc mp_irq;
381 struct pci_dev *pdev;
382 unsigned char number;
383 unsigned int devfn;
384 int ioapic;
385 u8 pin;
386
387 if (!acpi_ioapic)
388 return;
389 if (!dev || !dev_is_pci(dev))
390 return;
391
392 pdev = to_pci_dev(dev);
393 number = pdev->bus->number;
394 devfn = pdev->devfn;
395 pin = pdev->pin;
396 /* print the entry should happen on mptable identically */
397 mp_irq.type = MP_INTSRC;
398 mp_irq.irqtype = mp_INT;
399 mp_irq.irqflag = (trigger == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
400 (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
401 mp_irq.srcbus = number;
402 mp_irq.srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
403 ioapic = mp_find_ioapic(gsi);
404 mp_irq.dstapic = mpc_ioapic_id(ioapic);
405 mp_irq.dstirq = mp_find_ioapic_pin(ioapic, gsi);
406
407 mp_save_irq(&mp_irq);
408 #endif
409 }
410
mp_register_ioapic_irq(u8 bus_irq,u8 polarity,u8 trigger,u32 gsi)411 static int __init mp_register_ioapic_irq(u8 bus_irq, u8 polarity,
412 u8 trigger, u32 gsi)
413 {
414 struct mpc_intsrc mp_irq;
415 int ioapic, pin;
416
417 /* Convert 'gsi' to 'ioapic.pin'(INTIN#) */
418 ioapic = mp_find_ioapic(gsi);
419 if (ioapic < 0) {
420 pr_warn("Failed to find ioapic for gsi : %u\n", gsi);
421 return ioapic;
422 }
423
424 pin = mp_find_ioapic_pin(ioapic, gsi);
425
426 mp_irq.type = MP_INTSRC;
427 mp_irq.irqtype = mp_INT;
428 mp_irq.irqflag = (trigger << 2) | polarity;
429 mp_irq.srcbus = MP_ISA_BUS;
430 mp_irq.srcbusirq = bus_irq;
431 mp_irq.dstapic = mpc_ioapic_id(ioapic);
432 mp_irq.dstirq = pin;
433
434 mp_save_irq(&mp_irq);
435
436 return 0;
437 }
438
439 static int __init
acpi_parse_ioapic(union acpi_subtable_headers * header,const unsigned long end)440 acpi_parse_ioapic(union acpi_subtable_headers * header, const unsigned long end)
441 {
442 struct acpi_madt_io_apic *ioapic = NULL;
443 struct ioapic_domain_cfg cfg = {
444 .type = IOAPIC_DOMAIN_DYNAMIC,
445 .ops = &mp_ioapic_irqdomain_ops,
446 };
447
448 ioapic = (struct acpi_madt_io_apic *)header;
449
450 if (BAD_MADT_ENTRY(ioapic, end))
451 return -EINVAL;
452
453 acpi_table_print_madt_entry(&header->common);
454
455 /* Statically assign IRQ numbers for IOAPICs hosting legacy IRQs */
456 if (ioapic->global_irq_base < nr_legacy_irqs())
457 cfg.type = IOAPIC_DOMAIN_LEGACY;
458
459 mp_register_ioapic(ioapic->id, ioapic->address, ioapic->global_irq_base,
460 &cfg);
461
462 return 0;
463 }
464
465 /*
466 * Parse Interrupt Source Override for the ACPI SCI
467 */
acpi_sci_ioapic_setup(u8 bus_irq,u16 polarity,u16 trigger,u32 gsi)468 static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger, u32 gsi)
469 {
470 if (trigger == 0) /* compatible SCI trigger is level */
471 trigger = 3;
472
473 if (polarity == 0) /* compatible SCI polarity is low */
474 polarity = 3;
475
476 /* Command-line over-ride via acpi_sci= */
477 if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
478 trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
479
480 if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
481 polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
482
483 if (bus_irq < NR_IRQS_LEGACY)
484 mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
485 else
486 mp_register_ioapic_irq(bus_irq, polarity, trigger, gsi);
487
488 acpi_penalize_sci_irq(bus_irq, trigger, polarity);
489
490 /*
491 * stash over-ride to indicate we've been here
492 * and for later update of acpi_gbl_FADT
493 */
494 acpi_sci_override_gsi = gsi;
495 return;
496 }
497
498 static int __init
acpi_parse_int_src_ovr(union acpi_subtable_headers * header,const unsigned long end)499 acpi_parse_int_src_ovr(union acpi_subtable_headers * header,
500 const unsigned long end)
501 {
502 struct acpi_madt_interrupt_override *intsrc = NULL;
503
504 intsrc = (struct acpi_madt_interrupt_override *)header;
505
506 if (BAD_MADT_ENTRY(intsrc, end))
507 return -EINVAL;
508
509 acpi_table_print_madt_entry(&header->common);
510
511 if (intsrc->source_irq < NR_IRQS_LEGACY)
512 acpi_int_src_ovr[intsrc->source_irq] = true;
513
514 if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
515 acpi_sci_ioapic_setup(intsrc->source_irq,
516 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
517 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
518 intsrc->global_irq);
519 return 0;
520 }
521
522 if (intsrc->source_irq == 0) {
523 if (acpi_skip_timer_override) {
524 pr_warn("BIOS IRQ0 override ignored.\n");
525 return 0;
526 }
527
528 if ((intsrc->global_irq == 2) && acpi_fix_pin2_polarity
529 && (intsrc->inti_flags & ACPI_MADT_POLARITY_MASK)) {
530 intsrc->inti_flags &= ~ACPI_MADT_POLARITY_MASK;
531 pr_warn("BIOS IRQ0 pin2 override: forcing polarity to high active.\n");
532 }
533 }
534
535 mp_override_legacy_irq(intsrc->source_irq,
536 intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
537 (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
538 intsrc->global_irq);
539
540 return 0;
541 }
542
543 static int __init
acpi_parse_nmi_src(union acpi_subtable_headers * header,const unsigned long end)544 acpi_parse_nmi_src(union acpi_subtable_headers * header, const unsigned long end)
545 {
546 struct acpi_madt_nmi_source *nmi_src = NULL;
547
548 nmi_src = (struct acpi_madt_nmi_source *)header;
549
550 if (BAD_MADT_ENTRY(nmi_src, end))
551 return -EINVAL;
552
553 acpi_table_print_madt_entry(&header->common);
554
555 /* TBD: Support nimsrc entries? */
556
557 return 0;
558 }
559
560 #endif /* CONFIG_X86_IO_APIC */
561
562 /*
563 * acpi_pic_sci_set_trigger()
564 *
565 * use ELCR to set PIC-mode trigger type for SCI
566 *
567 * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
568 * it may require Edge Trigger -- use "acpi_sci=edge"
569 *
570 * Port 0x4d0-4d1 are ELCR1 and ELCR2, the Edge/Level Control Registers
571 * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
572 * ELCR1 is IRQs 0-7 (IRQ 0, 1, 2 must be 0)
573 * ELCR2 is IRQs 8-15 (IRQ 8, 13 must be 0)
574 */
575
acpi_pic_sci_set_trigger(unsigned int irq,u16 trigger)576 void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
577 {
578 unsigned int mask = 1 << irq;
579 unsigned int old, new;
580
581 /* Real old ELCR mask */
582 old = inb(PIC_ELCR1) | (inb(PIC_ELCR2) << 8);
583
584 /*
585 * If we use ACPI to set PCI IRQs, then we should clear ELCR
586 * since we will set it correctly as we enable the PCI irq
587 * routing.
588 */
589 new = acpi_noirq ? old : 0;
590
591 /*
592 * Update SCI information in the ELCR, it isn't in the PCI
593 * routing tables..
594 */
595 switch (trigger) {
596 case 1: /* Edge - clear */
597 new &= ~mask;
598 break;
599 case 3: /* Level - set */
600 new |= mask;
601 break;
602 }
603
604 if (old == new)
605 return;
606
607 pr_warn("setting ELCR to %04x (from %04x)\n", new, old);
608 outb(new, PIC_ELCR1);
609 outb(new >> 8, PIC_ELCR2);
610 }
611
acpi_gsi_to_irq(u32 gsi,unsigned int * irqp)612 int acpi_gsi_to_irq(u32 gsi, unsigned int *irqp)
613 {
614 int rc, irq, trigger, polarity;
615
616 if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
617 *irqp = gsi;
618 return 0;
619 }
620
621 rc = acpi_get_override_irq(gsi, &trigger, &polarity);
622 if (rc)
623 return rc;
624
625 trigger = trigger ? ACPI_LEVEL_SENSITIVE : ACPI_EDGE_SENSITIVE;
626 polarity = polarity ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH;
627 irq = acpi_register_gsi(NULL, gsi, trigger, polarity);
628 if (irq < 0)
629 return irq;
630
631 *irqp = irq;
632 return 0;
633 }
634 EXPORT_SYMBOL_GPL(acpi_gsi_to_irq);
635
acpi_isa_irq_to_gsi(unsigned isa_irq,u32 * gsi)636 int acpi_isa_irq_to_gsi(unsigned isa_irq, u32 *gsi)
637 {
638 if (isa_irq < nr_legacy_irqs() &&
639 isa_irq_to_gsi[isa_irq] != INVALID_ACPI_IRQ) {
640 *gsi = isa_irq_to_gsi[isa_irq];
641 return 0;
642 }
643
644 return -1;
645 }
646
acpi_register_gsi_pic(struct device * dev,u32 gsi,int trigger,int polarity)647 static int acpi_register_gsi_pic(struct device *dev, u32 gsi,
648 int trigger, int polarity)
649 {
650 #ifdef CONFIG_PCI
651 /*
652 * Make sure all (legacy) PCI IRQs are set as level-triggered.
653 */
654 if (trigger == ACPI_LEVEL_SENSITIVE)
655 elcr_set_level_irq(gsi);
656 #endif
657
658 return gsi;
659 }
660
661 #ifdef CONFIG_X86_LOCAL_APIC
acpi_register_gsi_ioapic(struct device * dev,u32 gsi,int trigger,int polarity)662 static int acpi_register_gsi_ioapic(struct device *dev, u32 gsi,
663 int trigger, int polarity)
664 {
665 int irq = gsi;
666 #ifdef CONFIG_X86_IO_APIC
667 int node;
668 struct irq_alloc_info info;
669
670 node = dev ? dev_to_node(dev) : NUMA_NO_NODE;
671 trigger = trigger == ACPI_EDGE_SENSITIVE ? 0 : 1;
672 polarity = polarity == ACPI_ACTIVE_HIGH ? 0 : 1;
673 ioapic_set_alloc_attr(&info, node, trigger, polarity);
674
675 mutex_lock(&acpi_ioapic_lock);
676 irq = mp_map_gsi_to_irq(gsi, IOAPIC_MAP_ALLOC, &info);
677 /* Don't set up the ACPI SCI because it's already set up */
678 if (irq >= 0 && enable_update_mptable && gsi != acpi_gbl_FADT.sci_interrupt)
679 mp_config_acpi_gsi(dev, gsi, trigger, polarity);
680 mutex_unlock(&acpi_ioapic_lock);
681 #endif
682
683 return irq;
684 }
685
acpi_unregister_gsi_ioapic(u32 gsi)686 static void acpi_unregister_gsi_ioapic(u32 gsi)
687 {
688 #ifdef CONFIG_X86_IO_APIC
689 int irq;
690
691 mutex_lock(&acpi_ioapic_lock);
692 irq = mp_map_gsi_to_irq(gsi, 0, NULL);
693 if (irq > 0)
694 mp_unmap_irq(irq);
695 mutex_unlock(&acpi_ioapic_lock);
696 #endif
697 }
698 #endif
699
700 int (*__acpi_register_gsi)(struct device *dev, u32 gsi,
701 int trigger, int polarity) = acpi_register_gsi_pic;
702 void (*__acpi_unregister_gsi)(u32 gsi) = NULL;
703
704 #ifdef CONFIG_ACPI_SLEEP
705 int (*acpi_suspend_lowlevel)(void) = x86_acpi_suspend_lowlevel;
706 #else
707 int (*acpi_suspend_lowlevel)(void);
708 #endif
709
710 /*
711 * success: return IRQ number (>=0)
712 * failure: return < 0
713 */
acpi_register_gsi(struct device * dev,u32 gsi,int trigger,int polarity)714 int acpi_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
715 {
716 return __acpi_register_gsi(dev, gsi, trigger, polarity);
717 }
718 EXPORT_SYMBOL_GPL(acpi_register_gsi);
719
acpi_unregister_gsi(u32 gsi)720 void acpi_unregister_gsi(u32 gsi)
721 {
722 if (__acpi_unregister_gsi)
723 __acpi_unregister_gsi(gsi);
724 }
725 EXPORT_SYMBOL_GPL(acpi_unregister_gsi);
726
727 #ifdef CONFIG_X86_LOCAL_APIC
acpi_set_irq_model_ioapic(void)728 static void __init acpi_set_irq_model_ioapic(void)
729 {
730 acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
731 __acpi_register_gsi = acpi_register_gsi_ioapic;
732 __acpi_unregister_gsi = acpi_unregister_gsi_ioapic;
733 acpi_ioapic = 1;
734 }
735 #endif
736
737 /*
738 * ACPI based hotplug support for CPU
739 */
740 #ifdef CONFIG_ACPI_HOTPLUG_CPU
741 #include <acpi/processor.h>
742
acpi_map_cpu2node(acpi_handle handle,int cpu,int physid)743 static int acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
744 {
745 #ifdef CONFIG_ACPI_NUMA
746 int nid;
747
748 nid = acpi_get_node(handle);
749 if (nid != NUMA_NO_NODE) {
750 set_apicid_to_node(physid, nid);
751 numa_set_node(cpu, nid);
752 }
753 #endif
754 return 0;
755 }
756
acpi_map_cpu(acpi_handle handle,phys_cpuid_t physid,u32 acpi_id,int * pcpu)757 int acpi_map_cpu(acpi_handle handle, phys_cpuid_t physid, u32 acpi_id, int *pcpu)
758 {
759 int cpu = topology_hotplug_apic(physid, acpi_id);
760
761 if (cpu < 0) {
762 pr_info("Unable to map lapic to logical cpu number\n");
763 return cpu;
764 }
765
766 acpi_processor_set_pdc(handle);
767 acpi_map_cpu2node(handle, cpu, physid);
768
769 *pcpu = cpu;
770 return 0;
771 }
772 EXPORT_SYMBOL(acpi_map_cpu);
773
acpi_unmap_cpu(int cpu)774 int acpi_unmap_cpu(int cpu)
775 {
776 #ifdef CONFIG_ACPI_NUMA
777 set_apicid_to_node(per_cpu(x86_cpu_to_apicid, cpu), NUMA_NO_NODE);
778 #endif
779 topology_hotunplug_apic(cpu);
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, x2count = 0;
1032
1033 if (!boot_cpu_has(X86_FEATURE_APIC))
1034 return -ENODEV;
1035
1036 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
1037 acpi_parse_sapic, MAX_LOCAL_APIC);
1038
1039 if (!count) {
1040 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
1041 acpi_parse_lapic, MAX_LOCAL_APIC);
1042 x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
1043 acpi_parse_x2apic, MAX_LOCAL_APIC);
1044 }
1045 if (!count && !x2count) {
1046 pr_err("No LAPIC entries present\n");
1047 /* TBD: Cleanup to allow fallback to MPS */
1048 return -ENODEV;
1049 } else if (count < 0 || x2count < 0) {
1050 pr_err("Error parsing LAPIC entry\n");
1051 /* TBD: Cleanup to allow fallback to MPS */
1052 return count;
1053 }
1054
1055 x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI,
1056 acpi_parse_x2apic_nmi, 0);
1057 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI,
1058 acpi_parse_lapic_nmi, 0);
1059 if (count < 0 || x2count < 0) {
1060 pr_err("Error parsing LAPIC NMI entry\n");
1061 /* TBD: Cleanup to allow fallback to MPS */
1062 return count;
1063 }
1064 return 0;
1065 }
1066 #endif /* CONFIG_X86_LOCAL_APIC */
1067
1068 #ifdef CONFIG_X86_IO_APIC
mp_config_acpi_legacy_irqs(void)1069 static void __init mp_config_acpi_legacy_irqs(void)
1070 {
1071 int i;
1072 struct mpc_intsrc mp_irq;
1073
1074 #ifdef CONFIG_EISA
1075 /*
1076 * Fabricate the legacy ISA bus (bus #31).
1077 */
1078 mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
1079 #endif
1080 set_bit(MP_ISA_BUS, mp_bus_not_pci);
1081 pr_debug("Bus #%d is ISA (nIRQs: %d)\n", MP_ISA_BUS, nr_legacy_irqs());
1082
1083 /*
1084 * Use the default configuration for the IRQs 0-15. Unless
1085 * overridden by (MADT) interrupt source override entries.
1086 */
1087 for (i = 0; i < nr_legacy_irqs(); i++) {
1088 int ioapic, pin;
1089 unsigned int dstapic;
1090 int idx;
1091 u32 gsi;
1092
1093 /* Locate the gsi that irq i maps to. */
1094 if (acpi_isa_irq_to_gsi(i, &gsi))
1095 continue;
1096
1097 /*
1098 * Locate the IOAPIC that manages the ISA IRQ.
1099 */
1100 ioapic = mp_find_ioapic(gsi);
1101 if (ioapic < 0)
1102 continue;
1103 pin = mp_find_ioapic_pin(ioapic, gsi);
1104 dstapic = mpc_ioapic_id(ioapic);
1105
1106 for (idx = 0; idx < mp_irq_entries; idx++) {
1107 struct mpc_intsrc *irq = mp_irqs + idx;
1108
1109 /* Do we already have a mapping for this ISA IRQ? */
1110 if (irq->srcbus == MP_ISA_BUS && irq->srcbusirq == i)
1111 break;
1112
1113 /* Do we already have a mapping for this IOAPIC pin */
1114 if (irq->dstapic == dstapic && irq->dstirq == pin)
1115 break;
1116 }
1117
1118 if (idx != mp_irq_entries) {
1119 pr_debug("ACPI: IRQ%d used by override.\n", i);
1120 continue; /* IRQ already used */
1121 }
1122
1123 mp_irq.type = MP_INTSRC;
1124 mp_irq.irqflag = 0; /* Conforming */
1125 mp_irq.srcbus = MP_ISA_BUS;
1126 mp_irq.dstapic = dstapic;
1127 mp_irq.irqtype = mp_INT;
1128 mp_irq.srcbusirq = i; /* Identity mapped */
1129 mp_irq.dstirq = pin;
1130
1131 mp_save_irq(&mp_irq);
1132 }
1133 }
1134
1135 /*
1136 * Parse IOAPIC related entries in MADT
1137 * returns 0 on success, < 0 on error
1138 */
acpi_parse_madt_ioapic_entries(void)1139 static int __init acpi_parse_madt_ioapic_entries(void)
1140 {
1141 int count;
1142
1143 /*
1144 * ACPI interpreter is required to complete interrupt setup,
1145 * so if it is off, don't enumerate the io-apics with ACPI.
1146 * If MPS is present, it will handle them,
1147 * otherwise the system will stay in PIC mode
1148 */
1149 if (acpi_disabled || acpi_noirq)
1150 return -ENODEV;
1151
1152 if (!boot_cpu_has(X86_FEATURE_APIC))
1153 return -ENODEV;
1154
1155 /*
1156 * if "noapic" boot option, don't look for IO-APICs
1157 */
1158 if (ioapic_is_disabled) {
1159 pr_info("Skipping IOAPIC probe due to 'noapic' option.\n");
1160 return -ENODEV;
1161 }
1162
1163 count = acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
1164 MAX_IO_APICS);
1165 if (!count) {
1166 pr_err("No IOAPIC entries present\n");
1167 return -ENODEV;
1168 } else if (count < 0) {
1169 pr_err("Error parsing IOAPIC entry\n");
1170 return count;
1171 }
1172
1173 count = acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE,
1174 acpi_parse_int_src_ovr,
1175 irq_get_nr_irqs());
1176 if (count < 0) {
1177 pr_err("Error parsing interrupt source overrides entry\n");
1178 /* TBD: Cleanup to allow fallback to MPS */
1179 return count;
1180 }
1181
1182 /*
1183 * If BIOS did not supply an INT_SRC_OVR for the SCI
1184 * pretend we got one so we can set the SCI flags.
1185 * But ignore setting up SCI on hardware reduced platforms.
1186 */
1187 if (acpi_sci_override_gsi == INVALID_ACPI_IRQ && !acpi_gbl_reduced_hardware)
1188 acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0,
1189 acpi_gbl_FADT.sci_interrupt);
1190
1191 /* Fill in identity legacy mappings where no override */
1192 mp_config_acpi_legacy_irqs();
1193
1194 count = acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE,
1195 acpi_parse_nmi_src,
1196 irq_get_nr_irqs());
1197 if (count < 0) {
1198 pr_err("Error parsing NMI SRC entry\n");
1199 /* TBD: Cleanup to allow fallback to MPS */
1200 return count;
1201 }
1202
1203 return 0;
1204 }
1205 #else
acpi_parse_madt_ioapic_entries(void)1206 static inline int acpi_parse_madt_ioapic_entries(void)
1207 {
1208 return -1;
1209 }
1210 #endif /* !CONFIG_X86_IO_APIC */
1211
early_acpi_process_madt(void)1212 static void __init early_acpi_process_madt(void)
1213 {
1214 #ifdef CONFIG_X86_LOCAL_APIC
1215 int error;
1216
1217 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1218
1219 /*
1220 * Parse MADT LAPIC entries
1221 */
1222 error = early_acpi_parse_madt_lapic_addr_ovr();
1223 if (!error) {
1224 acpi_lapic = 1;
1225 smp_found_config = 1;
1226 }
1227 if (error == -EINVAL) {
1228 /*
1229 * Dell Precision Workstation 410, 610 come here.
1230 */
1231 pr_err("Invalid BIOS MADT, disabling ACPI\n");
1232 disable_acpi();
1233 }
1234 }
1235 #endif
1236 }
1237
acpi_process_madt(void)1238 static void __init acpi_process_madt(void)
1239 {
1240 #ifdef CONFIG_X86_LOCAL_APIC
1241 int error;
1242
1243 if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
1244
1245 /*
1246 * Parse MADT LAPIC entries
1247 */
1248 error = acpi_parse_madt_lapic_entries();
1249 if (!error) {
1250 acpi_lapic = 1;
1251
1252 /*
1253 * Parse MADT IO-APIC entries
1254 */
1255 mutex_lock(&acpi_ioapic_lock);
1256 error = acpi_parse_madt_ioapic_entries();
1257 mutex_unlock(&acpi_ioapic_lock);
1258 if (!error) {
1259 acpi_set_irq_model_ioapic();
1260
1261 smp_found_config = 1;
1262 }
1263
1264 #ifdef CONFIG_ACPI_MADT_WAKEUP
1265 /*
1266 * Parse MADT MP Wake entry.
1267 */
1268 acpi_table_parse_madt(ACPI_MADT_TYPE_MULTIPROC_WAKEUP,
1269 acpi_parse_mp_wake, 1);
1270 #endif
1271 }
1272 if (error == -EINVAL) {
1273 /*
1274 * Dell Precision Workstation 410, 610 come here.
1275 */
1276 pr_err("Invalid BIOS MADT, disabling ACPI\n");
1277 disable_acpi();
1278 }
1279 } else {
1280 /*
1281 * ACPI found no MADT, and so ACPI wants UP PIC mode.
1282 * In the event an MPS table was found, forget it.
1283 * Boot with "acpi=off" to use MPS on such a system.
1284 */
1285 if (smp_found_config) {
1286 pr_warn("No APIC-table, disabling MPS\n");
1287 smp_found_config = 0;
1288 }
1289 }
1290
1291 /*
1292 * ACPI supports both logical (e.g. Hyper-Threading) and physical
1293 * processors, where MPS only supports physical.
1294 */
1295 if (acpi_lapic && acpi_ioapic)
1296 pr_info("Using ACPI (MADT) for SMP configuration information\n");
1297 else if (acpi_lapic)
1298 pr_info("Using ACPI for processor (LAPIC) configuration information\n");
1299 #endif
1300 return;
1301 }
1302
disable_acpi_irq(const struct dmi_system_id * d)1303 static int __init disable_acpi_irq(const struct dmi_system_id *d)
1304 {
1305 if (!acpi_force) {
1306 pr_notice("%s detected: force use of acpi=noirq\n", d->ident);
1307 acpi_noirq_set();
1308 }
1309 return 0;
1310 }
1311
disable_acpi_pci(const struct dmi_system_id * d)1312 static int __init disable_acpi_pci(const struct dmi_system_id *d)
1313 {
1314 if (!acpi_force) {
1315 pr_notice("%s detected: force use of pci=noacpi\n", d->ident);
1316 acpi_disable_pci();
1317 }
1318 return 0;
1319 }
1320
disable_acpi_xsdt(const struct dmi_system_id * d)1321 static int __init disable_acpi_xsdt(const struct dmi_system_id *d)
1322 {
1323 if (!acpi_force) {
1324 pr_notice("%s detected: force use of acpi=rsdt\n", d->ident);
1325 acpi_gbl_do_not_use_xsdt = TRUE;
1326 } else {
1327 pr_notice("Warning: DMI blacklist says broken, but acpi XSDT forced\n");
1328 }
1329 return 0;
1330 }
1331
dmi_disable_acpi(const struct dmi_system_id * d)1332 static int __init dmi_disable_acpi(const struct dmi_system_id *d)
1333 {
1334 if (!acpi_force) {
1335 pr_notice("%s detected: acpi off\n", d->ident);
1336 disable_acpi();
1337 } else {
1338 pr_notice("Warning: DMI blacklist says broken, but acpi forced\n");
1339 }
1340 return 0;
1341 }
1342
1343 /*
1344 * Force ignoring BIOS IRQ0 override
1345 */
dmi_ignore_irq0_timer_override(const struct dmi_system_id * d)1346 static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
1347 {
1348 if (!acpi_skip_timer_override) {
1349 pr_notice("%s detected: Ignoring BIOS IRQ0 override\n",
1350 d->ident);
1351 acpi_skip_timer_override = 1;
1352 }
1353 return 0;
1354 }
1355
1356 /*
1357 * ACPI offers an alternative platform interface model that removes
1358 * ACPI hardware requirements for platforms that do not implement
1359 * the PC Architecture.
1360 *
1361 * We initialize the Hardware-reduced ACPI model here:
1362 */
acpi_generic_reduced_hw_init(void)1363 void __init acpi_generic_reduced_hw_init(void)
1364 {
1365 /*
1366 * Override x86_init functions and bypass legacy PIC in
1367 * hardware reduced ACPI mode.
1368 */
1369 x86_init.timers.timer_init = x86_init_noop;
1370 x86_init.irqs.pre_vector_init = x86_init_noop;
1371 legacy_pic = &null_legacy_pic;
1372 }
1373
acpi_reduced_hw_init(void)1374 static void __init acpi_reduced_hw_init(void)
1375 {
1376 if (acpi_gbl_reduced_hardware)
1377 x86_init.acpi.reduced_hw_early_init();
1378 }
1379
1380 /*
1381 * If your system is blacklisted here, but you find that acpi=force
1382 * works for you, please contact linux-acpi@vger.kernel.org
1383 */
1384 static const struct dmi_system_id acpi_dmi_table[] __initconst = {
1385 /*
1386 * Boxes that need ACPI disabled
1387 */
1388 {
1389 .callback = dmi_disable_acpi,
1390 .ident = "IBM Thinkpad",
1391 .matches = {
1392 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1393 DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
1394 },
1395 },
1396
1397 /*
1398 * Boxes that need ACPI PCI IRQ routing disabled
1399 */
1400 {
1401 .callback = disable_acpi_irq,
1402 .ident = "ASUS A7V",
1403 .matches = {
1404 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
1405 DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
1406 /* newer BIOS, Revision 1011, does work */
1407 DMI_MATCH(DMI_BIOS_VERSION,
1408 "ASUS A7V ACPI BIOS Revision 1007"),
1409 },
1410 },
1411 {
1412 /*
1413 * Latest BIOS for IBM 600E (1.16) has bad pcinum
1414 * for LPC bridge, which is needed for the PCI
1415 * interrupt links to work. DSDT fix is in bug 5966.
1416 * 2645, 2646 model numbers are shared with 600/600E/600X
1417 */
1418 .callback = disable_acpi_irq,
1419 .ident = "IBM Thinkpad 600 Series 2645",
1420 .matches = {
1421 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1422 DMI_MATCH(DMI_BOARD_NAME, "2645"),
1423 },
1424 },
1425 {
1426 .callback = disable_acpi_irq,
1427 .ident = "IBM Thinkpad 600 Series 2646",
1428 .matches = {
1429 DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
1430 DMI_MATCH(DMI_BOARD_NAME, "2646"),
1431 },
1432 },
1433 /*
1434 * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
1435 */
1436 { /* _BBN 0 bug */
1437 .callback = disable_acpi_pci,
1438 .ident = "ASUS PR-DLS",
1439 .matches = {
1440 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1441 DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
1442 DMI_MATCH(DMI_BIOS_VERSION,
1443 "ASUS PR-DLS ACPI BIOS Revision 1010"),
1444 DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
1445 },
1446 },
1447 {
1448 .callback = disable_acpi_pci,
1449 .ident = "Acer TravelMate 36x Laptop",
1450 .matches = {
1451 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
1452 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
1453 },
1454 },
1455 /*
1456 * Boxes that need ACPI XSDT use disabled due to corrupted tables
1457 */
1458 {
1459 .callback = disable_acpi_xsdt,
1460 .ident = "Advantech DAC-BJ01",
1461 .matches = {
1462 DMI_MATCH(DMI_SYS_VENDOR, "NEC"),
1463 DMI_MATCH(DMI_PRODUCT_NAME, "Bearlake CRB Board"),
1464 DMI_MATCH(DMI_BIOS_VERSION, "V1.12"),
1465 DMI_MATCH(DMI_BIOS_DATE, "02/01/2011"),
1466 },
1467 },
1468 {}
1469 };
1470
1471 /* second table for DMI checks that should run after early-quirks */
1472 static const struct dmi_system_id acpi_dmi_table_late[] __initconst = {
1473 /*
1474 * HP laptops which use a DSDT reporting as HP/SB400/10000,
1475 * which includes some code which overrides all temperature
1476 * trip points to 16C if the INTIN2 input of the I/O APIC
1477 * is enabled. This input is incorrectly designated the
1478 * ISA IRQ 0 via an interrupt source override even though
1479 * it is wired to the output of the master 8259A and INTIN0
1480 * is not connected at all. Force ignoring BIOS IRQ0
1481 * override in that cases.
1482 */
1483 {
1484 .callback = dmi_ignore_irq0_timer_override,
1485 .ident = "HP nx6115 laptop",
1486 .matches = {
1487 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1488 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6115"),
1489 },
1490 },
1491 {
1492 .callback = dmi_ignore_irq0_timer_override,
1493 .ident = "HP NX6125 laptop",
1494 .matches = {
1495 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1496 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
1497 },
1498 },
1499 {
1500 .callback = dmi_ignore_irq0_timer_override,
1501 .ident = "HP NX6325 laptop",
1502 .matches = {
1503 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1504 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
1505 },
1506 },
1507 {
1508 .callback = dmi_ignore_irq0_timer_override,
1509 .ident = "HP 6715b laptop",
1510 .matches = {
1511 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1512 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
1513 },
1514 },
1515 {
1516 .callback = dmi_ignore_irq0_timer_override,
1517 .ident = "FUJITSU SIEMENS",
1518 .matches = {
1519 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
1520 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO PRO V2030"),
1521 },
1522 },
1523 {}
1524 };
1525
1526 /*
1527 * acpi_boot_table_init() and acpi_boot_init()
1528 * called from setup_arch(), always.
1529 * 1. checksums all tables
1530 * 2. enumerates lapics
1531 * 3. enumerates io-apics
1532 *
1533 * acpi_table_init() is separate to allow reading SRAT without
1534 * other side effects.
1535 *
1536 * side effects of acpi_boot_init:
1537 * acpi_lapic = 1 if LAPIC found
1538 * acpi_ioapic = 1 if IOAPIC found
1539 * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
1540 * if acpi_blacklisted() acpi_disabled = 1;
1541 * acpi_irq_model=...
1542 * ...
1543 */
1544
acpi_boot_table_init(void)1545 void __init acpi_boot_table_init(void)
1546 {
1547 dmi_check_system(acpi_dmi_table);
1548
1549 /*
1550 * If acpi_disabled, bail out
1551 */
1552 if (acpi_disabled)
1553 return;
1554
1555 /*
1556 * Initialize the ACPI boot-time table parser.
1557 */
1558 if (acpi_locate_initial_tables())
1559 disable_acpi();
1560 else
1561 acpi_reserve_initial_tables();
1562 }
1563
early_acpi_boot_init(void)1564 int __init early_acpi_boot_init(void)
1565 {
1566 if (acpi_disabled)
1567 return 1;
1568
1569 acpi_table_init_complete();
1570
1571 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
1572
1573 /*
1574 * blacklist may disable ACPI entirely
1575 */
1576 if (acpi_blacklisted()) {
1577 if (acpi_force) {
1578 pr_warn("acpi=force override\n");
1579 } else {
1580 pr_warn("Disabling ACPI support\n");
1581 disable_acpi();
1582 return 1;
1583 }
1584 }
1585
1586 /*
1587 * Process the Multiple APIC Description Table (MADT), if present
1588 */
1589 early_acpi_process_madt();
1590
1591 /*
1592 * Hardware-reduced ACPI mode initialization:
1593 */
1594 acpi_reduced_hw_init();
1595
1596 return 0;
1597 }
1598
acpi_boot_init(void)1599 int __init acpi_boot_init(void)
1600 {
1601 /* those are executed after early-quirks are executed */
1602 dmi_check_system(acpi_dmi_table_late);
1603
1604 /*
1605 * If acpi_disabled, bail out
1606 */
1607 if (acpi_disabled)
1608 return 1;
1609
1610 acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
1611
1612 /*
1613 * set sci_int and PM timer address
1614 */
1615 acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
1616
1617 /*
1618 * Process the Multiple APIC Description Table (MADT), if present
1619 */
1620 acpi_process_madt();
1621
1622 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
1623 if (IS_ENABLED(CONFIG_ACPI_BGRT) && !acpi_nobgrt)
1624 acpi_table_parse(ACPI_SIG_BGRT, acpi_parse_bgrt);
1625
1626 if (!acpi_noirq)
1627 x86_init.pci.init = pci_acpi_init;
1628
1629 /* Do not enable ACPI SPCR console by default */
1630 acpi_parse_spcr(earlycon_acpi_spcr_enable, false);
1631 return 0;
1632 }
1633
parse_acpi(char * arg)1634 static int __init parse_acpi(char *arg)
1635 {
1636 if (!arg)
1637 return -EINVAL;
1638
1639 /* "acpi=off" disables both ACPI table parsing and interpreter */
1640 if (strcmp(arg, "off") == 0) {
1641 disable_acpi();
1642 }
1643 /* acpi=force to over-ride black-list */
1644 else if (strcmp(arg, "force") == 0) {
1645 acpi_force = 1;
1646 acpi_disabled = 0;
1647 }
1648 /* acpi=strict disables out-of-spec workarounds */
1649 else if (strcmp(arg, "strict") == 0) {
1650 acpi_strict = 1;
1651 }
1652 /* acpi=rsdt use RSDT instead of XSDT */
1653 else if (strcmp(arg, "rsdt") == 0) {
1654 acpi_gbl_do_not_use_xsdt = TRUE;
1655 }
1656 /* "acpi=noirq" disables ACPI interrupt routing */
1657 else if (strcmp(arg, "noirq") == 0) {
1658 acpi_noirq_set();
1659 }
1660 /* "acpi=copy_dsdt" copies DSDT */
1661 else if (strcmp(arg, "copy_dsdt") == 0) {
1662 acpi_gbl_copy_dsdt_locally = 1;
1663 }
1664 /* "acpi=nocmcff" disables FF mode for corrected errors */
1665 else if (strcmp(arg, "nocmcff") == 0) {
1666 acpi_disable_cmcff = 1;
1667 } else {
1668 /* Core will printk when we return error. */
1669 return -EINVAL;
1670 }
1671 return 0;
1672 }
1673 early_param("acpi", parse_acpi);
1674
parse_acpi_bgrt(char * arg)1675 static int __init parse_acpi_bgrt(char *arg)
1676 {
1677 acpi_nobgrt = true;
1678 return 0;
1679 }
1680 early_param("bgrt_disable", parse_acpi_bgrt);
1681
1682 /* FIXME: Using pci= for an ACPI parameter is a travesty. */
parse_pci(char * arg)1683 static int __init parse_pci(char *arg)
1684 {
1685 if (arg && strcmp(arg, "noacpi") == 0)
1686 acpi_disable_pci();
1687 return 0;
1688 }
1689 early_param("pci", parse_pci);
1690
acpi_mps_check(void)1691 int __init acpi_mps_check(void)
1692 {
1693 #if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
1694 /* mptable code is not built-in*/
1695 if (acpi_disabled || acpi_noirq) {
1696 pr_warn("MPS support code is not built-in, using acpi=off or acpi=noirq or pci=noacpi may have problem\n");
1697 return 1;
1698 }
1699 #endif
1700 return 0;
1701 }
1702
1703 #ifdef CONFIG_X86_IO_APIC
parse_acpi_skip_timer_override(char * arg)1704 static int __init parse_acpi_skip_timer_override(char *arg)
1705 {
1706 acpi_skip_timer_override = 1;
1707 return 0;
1708 }
1709 early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
1710
parse_acpi_use_timer_override(char * arg)1711 static int __init parse_acpi_use_timer_override(char *arg)
1712 {
1713 acpi_use_timer_override = 1;
1714 return 0;
1715 }
1716 early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
1717 #endif /* CONFIG_X86_IO_APIC */
1718
setup_acpi_sci(char * s)1719 static int __init setup_acpi_sci(char *s)
1720 {
1721 if (!s)
1722 return -EINVAL;
1723 if (!strcmp(s, "edge"))
1724 acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
1725 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
1726 else if (!strcmp(s, "level"))
1727 acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
1728 (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
1729 else if (!strcmp(s, "high"))
1730 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
1731 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
1732 else if (!strcmp(s, "low"))
1733 acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
1734 (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
1735 else
1736 return -EINVAL;
1737 return 0;
1738 }
1739 early_param("acpi_sci", setup_acpi_sci);
1740
__acpi_acquire_global_lock(unsigned int * lock)1741 int __acpi_acquire_global_lock(unsigned int *lock)
1742 {
1743 unsigned int old, new, val;
1744
1745 old = READ_ONCE(*lock);
1746 do {
1747 val = (old >> 1) & 0x1;
1748 new = (old & ~0x3) + 2 + val;
1749 } while (!try_cmpxchg(lock, &old, new));
1750
1751 if (val)
1752 return 0;
1753
1754 return -1;
1755 }
1756
__acpi_release_global_lock(unsigned int * lock)1757 int __acpi_release_global_lock(unsigned int *lock)
1758 {
1759 unsigned int old, new;
1760
1761 old = READ_ONCE(*lock);
1762 do {
1763 new = old & ~0x3;
1764 } while (!try_cmpxchg(lock, &old, new));
1765 return old & 0x1;
1766 }
1767
arch_reserve_mem_area(acpi_physical_address addr,size_t size)1768 void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
1769 {
1770 e820__range_add(addr, size, E820_TYPE_NVS);
1771 e820__update_table_print();
1772 }
1773
x86_default_set_root_pointer(u64 addr)1774 void x86_default_set_root_pointer(u64 addr)
1775 {
1776 boot_params.acpi_rsdp_addr = addr;
1777 }
1778
x86_default_get_root_pointer(void)1779 u64 x86_default_get_root_pointer(void)
1780 {
1781 return boot_params.acpi_rsdp_addr;
1782 }
1783
1784 #ifdef CONFIG_XEN_PV
x86_acpi_os_ioremap(acpi_physical_address phys,acpi_size size)1785 void __iomem *x86_acpi_os_ioremap(acpi_physical_address phys, acpi_size size)
1786 {
1787 return ioremap_cache(phys, size);
1788 }
1789
1790 void __iomem * (*acpi_os_ioremap)(acpi_physical_address phys, acpi_size size) =
1791 x86_acpi_os_ioremap;
1792 EXPORT_SYMBOL_GPL(acpi_os_ioremap);
1793 #endif
1794