xref: /freebsd/sys/x86/acpica/madt.c (revision 4ce386ff25d77954b8cfa11534f632172e848244)
1 /*-
2  * Copyright (c) 2003 John Baldwin <jhb@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29 
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/bus.h>
33 #include <sys/kernel.h>
34 #include <sys/limits.h>
35 #include <sys/malloc.h>
36 #include <sys/smp.h>
37 #include <vm/vm.h>
38 #include <vm/pmap.h>
39 
40 #include <x86/apicreg.h>
41 #include <machine/intr_machdep.h>
42 #include <x86/apicvar.h>
43 #include <machine/md_var.h>
44 #include <x86/vmware.h>
45 
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/actables.h>
48 
49 #include <dev/acpica/acpivar.h>
50 #include <dev/pci/pcivar.h>
51 
52 /* These two arrays are indexed by APIC IDs. */
53 static struct {
54 	void *io_apic;
55 	UINT32 io_vector;
56 } *ioapics;
57 
58 static struct lapic_info {
59 	u_int la_enabled:1;
60 	u_int la_acpi_id:8;
61 } lapics[MAX_APIC_ID + 1];
62 
63 int madt_found_sci_override;
64 static ACPI_TABLE_MADT *madt;
65 static vm_paddr_t madt_physaddr;
66 static vm_offset_t madt_length;
67 
68 static MALLOC_DEFINE(M_MADT, "madt_table", "ACPI MADT Table Items");
69 
70 static enum intr_polarity interrupt_polarity(UINT16 IntiFlags, UINT8 Source);
71 static enum intr_trigger interrupt_trigger(UINT16 IntiFlags, UINT8 Source);
72 static int	madt_find_cpu(u_int acpi_id, u_int *apic_id);
73 static int	madt_find_interrupt(int intr, void **apic, u_int *pin);
74 static void	madt_parse_apics(ACPI_SUBTABLE_HEADER *entry, void *arg);
75 static void	madt_parse_interrupt_override(
76 		    ACPI_MADT_INTERRUPT_OVERRIDE *intr);
77 static void	madt_parse_ints(ACPI_SUBTABLE_HEADER *entry,
78 		    void *arg __unused);
79 static void	madt_parse_local_nmi(ACPI_MADT_LOCAL_APIC_NMI *nmi);
80 static void	madt_parse_nmi(ACPI_MADT_NMI_SOURCE *nmi);
81 static int	madt_probe(void);
82 static int	madt_probe_cpus(void);
83 static void	madt_probe_cpus_handler(ACPI_SUBTABLE_HEADER *entry,
84 		    void *arg __unused);
85 static void	madt_register(void *dummy);
86 static int	madt_setup_local(void);
87 static int	madt_setup_io(void);
88 static void	madt_walk_table(acpi_subtable_handler *handler, void *arg);
89 
90 static struct apic_enumerator madt_enumerator = {
91 	"MADT",
92 	madt_probe,
93 	madt_probe_cpus,
94 	madt_setup_local,
95 	madt_setup_io
96 };
97 
98 /*
99  * Look for an ACPI Multiple APIC Description Table ("APIC")
100  */
101 static int
102 madt_probe(void)
103 {
104 
105 	madt_physaddr = acpi_find_table(ACPI_SIG_MADT);
106 	if (madt_physaddr == 0)
107 		return (ENXIO);
108 	return (-50);
109 }
110 
111 /*
112  * Run through the MP table enumerating CPUs.
113  */
114 static int
115 madt_probe_cpus(void)
116 {
117 
118 	madt = acpi_map_table(madt_physaddr, ACPI_SIG_MADT);
119 	madt_length = madt->Header.Length;
120 	KASSERT(madt != NULL, ("Unable to re-map MADT"));
121 	madt_walk_table(madt_probe_cpus_handler, NULL);
122 	acpi_unmap_table(madt);
123 	madt = NULL;
124 	return (0);
125 }
126 
127 /*
128  * Initialize the local APIC on the BSP.
129  */
130 static int
131 madt_setup_local(void)
132 {
133 	ACPI_TABLE_DMAR *dmartbl;
134 	vm_paddr_t dmartbl_physaddr;
135 	u_int p[4];
136 
137 	madt = pmap_mapbios(madt_physaddr, madt_length);
138 	if ((cpu_feature2 & CPUID2_X2APIC) != 0) {
139 		x2apic_mode = 1;
140 		dmartbl_physaddr = acpi_find_table(ACPI_SIG_DMAR);
141 		if (dmartbl_physaddr != 0) {
142 			dmartbl = acpi_map_table(dmartbl_physaddr,
143 			    ACPI_SIG_DMAR);
144 			if ((dmartbl->Flags & ACPI_DMAR_X2APIC_OPT_OUT) != 0) {
145 				x2apic_mode = 0;
146 				if (bootverbose)
147 					printf(
148 		"x2APIC available but disabled by DMAR table\n");
149 			}
150 			acpi_unmap_table(dmartbl);
151 		}
152 		if (vm_guest == VM_GUEST_VMWARE) {
153 			vmware_hvcall(VMW_HVCMD_GETVCPU_INFO, p);
154 			if ((p[0] & VMW_VCPUINFO_VCPU_RESERVED) != 0 ||
155 			    (p[0] & VMW_VCPUINFO_LEGACY_X2APIC) == 0) {
156 				x2apic_mode = 0;
157 				if (bootverbose)
158 					printf(
159        "x2APIC available but disabled inside VMWare without intr redirection\n");
160 			}
161 		} else if (vm_guest == VM_GUEST_XEN) {
162 			x2apic_mode = 0;
163 		}
164 		TUNABLE_INT_FETCH("hw.x2apic_enable", &x2apic_mode);
165 	}
166 
167 	lapic_init(madt->Address);
168 	printf("ACPI APIC Table: <%.*s %.*s>\n",
169 	    (int)sizeof(madt->Header.OemId), madt->Header.OemId,
170 	    (int)sizeof(madt->Header.OemTableId), madt->Header.OemTableId);
171 
172 	/*
173 	 * We ignore 64-bit local APIC override entries.  Should we
174 	 * perhaps emit a warning here if we find one?
175 	 */
176 	return (0);
177 }
178 
179 /*
180  * Enumerate I/O APICs and setup interrupt sources.
181  */
182 static int
183 madt_setup_io(void)
184 {
185 	void *ioapic;
186 	u_int pin;
187 	int i;
188 
189 	/* Try to initialize ACPI so that we can access the FADT. */
190 	i = acpi_Startup();
191 	if (ACPI_FAILURE(i)) {
192 		printf("MADT: ACPI Startup failed with %s\n",
193 		    AcpiFormatException(i));
194 		printf("Try disabling either ACPI or apic support.\n");
195 		panic("Using MADT but ACPI doesn't work");
196 	}
197 
198 	ioapics = malloc(sizeof(*ioapics) * (MAX_APIC_ID + 1), M_MADT,
199 	    M_WAITOK | M_ZERO);
200 
201 	/* First, we run through adding I/O APIC's. */
202 	madt_walk_table(madt_parse_apics, NULL);
203 
204 	/* Second, we run through the table tweaking interrupt sources. */
205 	madt_walk_table(madt_parse_ints, NULL);
206 
207 	/*
208 	 * If there was not an explicit override entry for the SCI,
209 	 * force it to use level trigger and active-low polarity.
210 	 */
211 	if (!madt_found_sci_override) {
212 		if (madt_find_interrupt(AcpiGbl_FADT.SciInterrupt, &ioapic,
213 		    &pin) != 0)
214 			printf("MADT: Could not find APIC for SCI IRQ %u\n",
215 			    AcpiGbl_FADT.SciInterrupt);
216 		else {
217 			printf(
218 	"MADT: Forcing active-low polarity and level trigger for SCI\n");
219 			ioapic_set_polarity(ioapic, pin, INTR_POLARITY_LOW);
220 			ioapic_set_triggermode(ioapic, pin, INTR_TRIGGER_LEVEL);
221 		}
222 	}
223 
224 	/* Third, we register all the I/O APIC's. */
225 	for (i = 0; i <= MAX_APIC_ID; i++)
226 		if (ioapics[i].io_apic != NULL)
227 			ioapic_register(ioapics[i].io_apic);
228 
229 	/* Finally, we throw the switch to enable the I/O APIC's. */
230 	acpi_SetDefaultIntrModel(ACPI_INTR_APIC);
231 
232 	free(ioapics, M_MADT);
233 	ioapics = NULL;
234 
235 	return (0);
236 }
237 
238 static void
239 madt_register(void *dummy __unused)
240 {
241 
242 	apic_register_enumerator(&madt_enumerator);
243 }
244 SYSINIT(madt_register, SI_SUB_TUNABLES - 1, SI_ORDER_FIRST, madt_register, NULL);
245 
246 /*
247  * Call the handler routine for each entry in the MADT table.
248  */
249 static void
250 madt_walk_table(acpi_subtable_handler *handler, void *arg)
251 {
252 
253 	acpi_walk_subtables(madt + 1, (char *)madt + madt->Header.Length,
254 	    handler, arg);
255 }
256 
257 static void
258 madt_probe_cpus_handler(ACPI_SUBTABLE_HEADER *entry, void *arg)
259 {
260 	ACPI_MADT_LOCAL_APIC *proc;
261 	struct lapic_info *la;
262 
263 	switch (entry->Type) {
264 	case ACPI_MADT_TYPE_LOCAL_APIC:
265 		/*
266 		 * The MADT does not include a BSP flag, so we have to
267 		 * let the MP code figure out which CPU is the BSP on
268 		 * its own.
269 		 */
270 		proc = (ACPI_MADT_LOCAL_APIC *)entry;
271 		if (bootverbose)
272 			printf("MADT: Found CPU APIC ID %u ACPI ID %u: %s\n",
273 			    proc->Id, proc->ProcessorId,
274 			    (proc->LapicFlags & ACPI_MADT_ENABLED) ?
275 			    "enabled" : "disabled");
276 		if (!(proc->LapicFlags & ACPI_MADT_ENABLED))
277 			break;
278 		if (proc->Id > MAX_APIC_ID)
279 			panic("%s: CPU ID %u too high", __func__, proc->Id);
280 		la = &lapics[proc->Id];
281 		KASSERT(la->la_enabled == 0,
282 		    ("Duplicate local APIC ID %u", proc->Id));
283 		la->la_enabled = 1;
284 		la->la_acpi_id = proc->ProcessorId;
285 		lapic_create(proc->Id, 0);
286 		break;
287 	}
288 }
289 
290 
291 /*
292  * Add an I/O APIC from an entry in the table.
293  */
294 static void
295 madt_parse_apics(ACPI_SUBTABLE_HEADER *entry, void *arg __unused)
296 {
297 	ACPI_MADT_IO_APIC *apic;
298 
299 	switch (entry->Type) {
300 	case ACPI_MADT_TYPE_IO_APIC:
301 		apic = (ACPI_MADT_IO_APIC *)entry;
302 		if (bootverbose)
303 			printf(
304 			    "MADT: Found IO APIC ID %u, Interrupt %u at %p\n",
305 			    apic->Id, apic->GlobalIrqBase,
306 			    (void *)(uintptr_t)apic->Address);
307 		if (apic->Id > MAX_APIC_ID)
308 			panic("%s: I/O APIC ID %u too high", __func__,
309 			    apic->Id);
310 		if (ioapics[apic->Id].io_apic != NULL)
311 			panic("%s: Double APIC ID %u", __func__, apic->Id);
312 		if (apic->GlobalIrqBase >= FIRST_MSI_INT) {
313 			printf("MADT: Ignoring bogus I/O APIC ID %u", apic->Id);
314 			break;
315 		}
316 		ioapics[apic->Id].io_apic = ioapic_create(apic->Address,
317 		    apic->Id, apic->GlobalIrqBase);
318 		ioapics[apic->Id].io_vector = apic->GlobalIrqBase;
319 		break;
320 	default:
321 		break;
322 	}
323 }
324 
325 /*
326  * Determine properties of an interrupt source.  Note that for ACPI these
327  * functions are only used for ISA interrupts, so we assume ISA bus values
328  * (Active Hi, Edge Triggered) for conforming values except for the ACPI
329  * SCI for which we use Active Lo, Level Triggered.
330  */
331 static enum intr_polarity
332 interrupt_polarity(UINT16 IntiFlags, UINT8 Source)
333 {
334 
335 	switch (IntiFlags & ACPI_MADT_POLARITY_MASK) {
336 	default:
337 		printf("WARNING: Bogus Interrupt Polarity. Assume CONFORMS\n");
338 		/* FALLTHROUGH*/
339 	case ACPI_MADT_POLARITY_CONFORMS:
340 		if (Source == AcpiGbl_FADT.SciInterrupt)
341 			return (INTR_POLARITY_LOW);
342 		else
343 			return (INTR_POLARITY_HIGH);
344 	case ACPI_MADT_POLARITY_ACTIVE_HIGH:
345 		return (INTR_POLARITY_HIGH);
346 	case ACPI_MADT_POLARITY_ACTIVE_LOW:
347 		return (INTR_POLARITY_LOW);
348 	}
349 }
350 
351 static enum intr_trigger
352 interrupt_trigger(UINT16 IntiFlags, UINT8 Source)
353 {
354 
355 	switch (IntiFlags & ACPI_MADT_TRIGGER_MASK) {
356 	default:
357 		printf("WARNING: Bogus Interrupt Trigger Mode. Assume CONFORMS.\n");
358 		/*FALLTHROUGH*/
359 	case ACPI_MADT_TRIGGER_CONFORMS:
360 		if (Source == AcpiGbl_FADT.SciInterrupt)
361 			return (INTR_TRIGGER_LEVEL);
362 		else
363 			return (INTR_TRIGGER_EDGE);
364 	case ACPI_MADT_TRIGGER_EDGE:
365 		return (INTR_TRIGGER_EDGE);
366 	case ACPI_MADT_TRIGGER_LEVEL:
367 		return (INTR_TRIGGER_LEVEL);
368 	}
369 }
370 
371 /*
372  * Find the local APIC ID associated with a given ACPI Processor ID.
373  */
374 static int
375 madt_find_cpu(u_int acpi_id, u_int *apic_id)
376 {
377 	int i;
378 
379 	for (i = 0; i <= MAX_APIC_ID; i++) {
380 		if (!lapics[i].la_enabled)
381 			continue;
382 		if (lapics[i].la_acpi_id != acpi_id)
383 			continue;
384 		*apic_id = i;
385 		return (0);
386 	}
387 	return (ENOENT);
388 }
389 
390 /*
391  * Find the IO APIC and pin on that APIC associated with a given global
392  * interrupt.
393  */
394 static int
395 madt_find_interrupt(int intr, void **apic, u_int *pin)
396 {
397 	int i, best;
398 
399 	best = -1;
400 	for (i = 0; i <= MAX_APIC_ID; i++) {
401 		if (ioapics[i].io_apic == NULL ||
402 		    ioapics[i].io_vector > intr)
403 			continue;
404 		if (best == -1 ||
405 		    ioapics[best].io_vector < ioapics[i].io_vector)
406 			best = i;
407 	}
408 	if (best == -1)
409 		return (ENOENT);
410 	*apic = ioapics[best].io_apic;
411 	*pin = intr - ioapics[best].io_vector;
412 	if (*pin > 32)
413 		printf("WARNING: Found intpin of %u for vector %d\n", *pin,
414 		    intr);
415 	return (0);
416 }
417 
418 void
419 madt_parse_interrupt_values(void *entry,
420     enum intr_trigger *trig, enum intr_polarity *pol)
421 {
422 	ACPI_MADT_INTERRUPT_OVERRIDE *intr;
423 	char buf[64];
424 
425 	intr = entry;
426 
427 	if (bootverbose)
428 		printf("MADT: Interrupt override: source %u, irq %u\n",
429 		    intr->SourceIrq, intr->GlobalIrq);
430 	KASSERT(intr->Bus == 0, ("bus for interrupt overrides must be zero"));
431 
432 	/*
433 	 * Lookup the appropriate trigger and polarity modes for this
434 	 * entry.
435 	 */
436 	*trig = interrupt_trigger(intr->IntiFlags, intr->SourceIrq);
437 	*pol = interrupt_polarity(intr->IntiFlags, intr->SourceIrq);
438 
439 	/*
440 	 * If the SCI is identity mapped but has edge trigger and
441 	 * active-hi polarity or the force_sci_lo tunable is set,
442 	 * force it to use level/lo.
443 	 */
444 	if (intr->SourceIrq == AcpiGbl_FADT.SciInterrupt) {
445 		madt_found_sci_override = 1;
446 		if (getenv_string("hw.acpi.sci.trigger", buf, sizeof(buf))) {
447 			if (tolower(buf[0]) == 'e')
448 				*trig = INTR_TRIGGER_EDGE;
449 			else if (tolower(buf[0]) == 'l')
450 				*trig = INTR_TRIGGER_LEVEL;
451 			else
452 				panic(
453 				"Invalid trigger %s: must be 'edge' or 'level'",
454 				    buf);
455 			printf("MADT: Forcing SCI to %s trigger\n",
456 			    *trig == INTR_TRIGGER_EDGE ? "edge" : "level");
457 		}
458 		if (getenv_string("hw.acpi.sci.polarity", buf, sizeof(buf))) {
459 			if (tolower(buf[0]) == 'h')
460 				*pol = INTR_POLARITY_HIGH;
461 			else if (tolower(buf[0]) == 'l')
462 				*pol = INTR_POLARITY_LOW;
463 			else
464 				panic(
465 				"Invalid polarity %s: must be 'high' or 'low'",
466 				    buf);
467 			printf("MADT: Forcing SCI to active %s polarity\n",
468 			    *pol == INTR_POLARITY_HIGH ? "high" : "low");
469 		}
470 	}
471 }
472 
473 /*
474  * Parse an interrupt source override for an ISA interrupt.
475  */
476 static void
477 madt_parse_interrupt_override(ACPI_MADT_INTERRUPT_OVERRIDE *intr)
478 {
479 	void *new_ioapic, *old_ioapic;
480 	u_int new_pin, old_pin;
481 	enum intr_trigger trig;
482 	enum intr_polarity pol;
483 
484 	if (acpi_quirks & ACPI_Q_MADT_IRQ0 && intr->SourceIrq == 0 &&
485 	    intr->GlobalIrq == 2) {
486 		if (bootverbose)
487 			printf("MADT: Skipping timer override\n");
488 		return;
489 	}
490 
491 	if (madt_find_interrupt(intr->GlobalIrq, &new_ioapic, &new_pin) != 0) {
492 		printf("MADT: Could not find APIC for vector %u (IRQ %u)\n",
493 		    intr->GlobalIrq, intr->SourceIrq);
494 		return;
495 	}
496 
497 	madt_parse_interrupt_values(intr, &trig, &pol);
498 
499 	/* Remap the IRQ if it is mapped to a different interrupt vector. */
500 	if (intr->SourceIrq != intr->GlobalIrq) {
501 		/*
502 		 * If the SCI is remapped to a non-ISA global interrupt,
503 		 * then override the vector we use to setup and allocate
504 		 * the interrupt.
505 		 */
506 		if (intr->GlobalIrq > 15 &&
507 		    intr->SourceIrq == AcpiGbl_FADT.SciInterrupt)
508 			acpi_OverrideInterruptLevel(intr->GlobalIrq);
509 		else
510 			ioapic_remap_vector(new_ioapic, new_pin,
511 			    intr->SourceIrq);
512 		if (madt_find_interrupt(intr->SourceIrq, &old_ioapic,
513 		    &old_pin) != 0)
514 			printf("MADT: Could not find APIC for source IRQ %u\n",
515 			    intr->SourceIrq);
516 		else if (ioapic_get_vector(old_ioapic, old_pin) ==
517 		    intr->SourceIrq)
518 			ioapic_disable_pin(old_ioapic, old_pin);
519 	}
520 
521 	/* Program the polarity and trigger mode. */
522 	ioapic_set_triggermode(new_ioapic, new_pin, trig);
523 	ioapic_set_polarity(new_ioapic, new_pin, pol);
524 }
525 
526 /*
527  * Parse an entry for an NMI routed to an IO APIC.
528  */
529 static void
530 madt_parse_nmi(ACPI_MADT_NMI_SOURCE *nmi)
531 {
532 	void *ioapic;
533 	u_int pin;
534 
535 	if (madt_find_interrupt(nmi->GlobalIrq, &ioapic, &pin) != 0) {
536 		printf("MADT: Could not find APIC for vector %u\n",
537 		    nmi->GlobalIrq);
538 		return;
539 	}
540 
541 	ioapic_set_nmi(ioapic, pin);
542 	if (!(nmi->IntiFlags & ACPI_MADT_TRIGGER_CONFORMS))
543 		ioapic_set_triggermode(ioapic, pin,
544 		    interrupt_trigger(nmi->IntiFlags, 0));
545 	if (!(nmi->IntiFlags & ACPI_MADT_POLARITY_CONFORMS))
546 		ioapic_set_polarity(ioapic, pin,
547 		    interrupt_polarity(nmi->IntiFlags, 0));
548 }
549 
550 /*
551  * Parse an entry for an NMI routed to a local APIC LVT pin.
552  */
553 static void
554 madt_parse_local_nmi(ACPI_MADT_LOCAL_APIC_NMI *nmi)
555 {
556 	u_int apic_id, pin;
557 
558 	if (nmi->ProcessorId == 0xff)
559 		apic_id = APIC_ID_ALL;
560 	else if (madt_find_cpu(nmi->ProcessorId, &apic_id) != 0) {
561 		if (bootverbose)
562 			printf("MADT: Ignoring local NMI routed to "
563 			    "ACPI CPU %u\n", nmi->ProcessorId);
564 		return;
565 	}
566 	if (nmi->Lint == 0)
567 		pin = APIC_LVT_LINT0;
568 	else
569 		pin = APIC_LVT_LINT1;
570 	lapic_set_lvt_mode(apic_id, pin, APIC_LVT_DM_NMI);
571 	if (!(nmi->IntiFlags & ACPI_MADT_TRIGGER_CONFORMS))
572 		lapic_set_lvt_triggermode(apic_id, pin,
573 		    interrupt_trigger(nmi->IntiFlags, 0));
574 	if (!(nmi->IntiFlags & ACPI_MADT_POLARITY_CONFORMS))
575 		lapic_set_lvt_polarity(apic_id, pin,
576 		    interrupt_polarity(nmi->IntiFlags, 0));
577 }
578 
579 /*
580  * Parse interrupt entries.
581  */
582 static void
583 madt_parse_ints(ACPI_SUBTABLE_HEADER *entry, void *arg __unused)
584 {
585 
586 	switch (entry->Type) {
587 	case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE:
588 		madt_parse_interrupt_override(
589 			(ACPI_MADT_INTERRUPT_OVERRIDE *)entry);
590 		break;
591 	case ACPI_MADT_TYPE_NMI_SOURCE:
592 		madt_parse_nmi((ACPI_MADT_NMI_SOURCE *)entry);
593 		break;
594 	case ACPI_MADT_TYPE_LOCAL_APIC_NMI:
595 		madt_parse_local_nmi((ACPI_MADT_LOCAL_APIC_NMI *)entry);
596 		break;
597 	}
598 }
599 
600 /*
601  * Setup per-CPU ACPI IDs.
602  */
603 static void
604 madt_set_ids(void *dummy)
605 {
606 	struct lapic_info *la;
607 	struct pcpu *pc;
608 	u_int i;
609 
610 	if (madt == NULL)
611 		return;
612 	CPU_FOREACH(i) {
613 		pc = pcpu_find(i);
614 		KASSERT(pc != NULL, ("no pcpu data for CPU %u", i));
615 		la = &lapics[pc->pc_apic_id];
616 		if (!la->la_enabled)
617 			panic("APIC: CPU with APIC ID %u is not enabled",
618 			    pc->pc_apic_id);
619 		pc->pc_acpi_id = la->la_acpi_id;
620 		if (bootverbose)
621 			printf("APIC: CPU %u has ACPI ID %u\n", i,
622 			    la->la_acpi_id);
623 	}
624 }
625 SYSINIT(madt_set_ids, SI_SUB_CPU, SI_ORDER_MIDDLE, madt_set_ids, NULL);
626