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