2003-11-03 22:17:44 +00:00
|
|
|
/*-
|
2017-11-27 15:11:47 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2003-11-03 22:17:44 +00:00
|
|
|
* Copyright (c) 2003 John Baldwin <jhb@FreeBSD.org>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/kernel.h>
|
2015-02-14 09:00:12 +00:00
|
|
|
#include <sys/limits.h>
|
2003-11-03 22:17:44 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/smp.h>
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/pmap.h>
|
|
|
|
|
2010-11-01 18:18:46 +00:00
|
|
|
#include <x86/apicreg.h>
|
2003-11-03 22:17:44 +00:00
|
|
|
#include <machine/intr_machdep.h>
|
2014-01-23 20:10:22 +00:00
|
|
|
#include <x86/apicvar.h>
|
2015-02-09 21:00:56 +00:00
|
|
|
#include <machine/md_var.h>
|
2015-02-14 09:00:12 +00:00
|
|
|
#include <x86/vmware.h>
|
2003-11-03 22:17:44 +00:00
|
|
|
|
2009-06-05 18:44:36 +00:00
|
|
|
#include <contrib/dev/acpica/include/acpi.h>
|
2016-10-04 20:27:15 +00:00
|
|
|
#include <contrib/dev/acpica/include/aclocal.h>
|
2009-06-05 18:44:36 +00:00
|
|
|
#include <contrib/dev/acpica/include/actables.h>
|
|
|
|
|
2003-11-03 22:17:44 +00:00
|
|
|
#include <dev/acpica/acpivar.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
|
|
|
|
/* These two arrays are indexed by APIC IDs. */
|
2012-03-28 18:53:48 +00:00
|
|
|
static struct {
|
2003-11-03 22:17:44 +00:00
|
|
|
void *io_apic;
|
|
|
|
UINT32 io_vector;
|
2012-03-28 18:53:48 +00:00
|
|
|
} *ioapics;
|
2003-11-03 22:17:44 +00:00
|
|
|
|
2012-03-28 18:53:48 +00:00
|
|
|
static struct lapic_info {
|
2015-06-09 10:49:40 +00:00
|
|
|
u_int la_enabled;
|
|
|
|
u_int la_acpi_id;
|
2017-08-10 09:16:03 +00:00
|
|
|
} *lapics;
|
2003-11-03 22:17:44 +00:00
|
|
|
|
2014-08-04 08:58:50 +00:00
|
|
|
int madt_found_sci_override;
|
2007-03-22 18:16:43 +00:00
|
|
|
static ACPI_TABLE_MADT *madt;
|
2003-11-03 22:17:44 +00:00
|
|
|
static vm_paddr_t madt_physaddr;
|
|
|
|
static vm_offset_t madt_length;
|
|
|
|
|
2011-11-07 06:44:47 +00:00
|
|
|
static MALLOC_DEFINE(M_MADT, "madt_table", "ACPI MADT Table Items");
|
2003-11-03 22:17:44 +00:00
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
static enum intr_polarity interrupt_polarity(UINT16 IntiFlags, UINT8 Source);
|
|
|
|
static enum intr_trigger interrupt_trigger(UINT16 IntiFlags, UINT8 Source);
|
2003-11-03 22:17:44 +00:00
|
|
|
static int madt_find_cpu(u_int acpi_id, u_int *apic_id);
|
|
|
|
static int madt_find_interrupt(int intr, void **apic, u_int *pin);
|
2007-03-22 18:16:43 +00:00
|
|
|
static void madt_parse_apics(ACPI_SUBTABLE_HEADER *entry, void *arg);
|
|
|
|
static void madt_parse_interrupt_override(
|
|
|
|
ACPI_MADT_INTERRUPT_OVERRIDE *intr);
|
|
|
|
static void madt_parse_ints(ACPI_SUBTABLE_HEADER *entry,
|
|
|
|
void *arg __unused);
|
|
|
|
static void madt_parse_local_nmi(ACPI_MADT_LOCAL_APIC_NMI *nmi);
|
|
|
|
static void madt_parse_nmi(ACPI_MADT_NMI_SOURCE *nmi);
|
2003-11-03 22:17:44 +00:00
|
|
|
static int madt_probe(void);
|
|
|
|
static int madt_probe_cpus(void);
|
2007-03-22 18:16:43 +00:00
|
|
|
static void madt_probe_cpus_handler(ACPI_SUBTABLE_HEADER *entry,
|
|
|
|
void *arg __unused);
|
2017-08-10 09:15:18 +00:00
|
|
|
static void madt_setup_cpus_handler(ACPI_SUBTABLE_HEADER *entry,
|
|
|
|
void *arg __unused);
|
2003-11-03 22:17:44 +00:00
|
|
|
static void madt_register(void *dummy);
|
|
|
|
static int madt_setup_local(void);
|
|
|
|
static int madt_setup_io(void);
|
2009-09-23 15:42:35 +00:00
|
|
|
static void madt_walk_table(acpi_subtable_handler *handler, void *arg);
|
2003-11-03 22:17:44 +00:00
|
|
|
|
|
|
|
static struct apic_enumerator madt_enumerator = {
|
2018-07-13 17:42:48 +00:00
|
|
|
.apic_name = "MADT",
|
|
|
|
.apic_probe = madt_probe,
|
|
|
|
.apic_probe_cpus = madt_probe_cpus,
|
|
|
|
.apic_setup_local = madt_setup_local,
|
|
|
|
.apic_setup_io = madt_setup_io
|
2003-11-03 22:17:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look for an ACPI Multiple APIC Description Table ("APIC")
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
madt_probe(void)
|
|
|
|
{
|
|
|
|
|
2009-09-23 15:42:35 +00:00
|
|
|
madt_physaddr = acpi_find_table(ACPI_SIG_MADT);
|
|
|
|
if (madt_physaddr == 0)
|
2003-11-03 22:17:44 +00:00
|
|
|
return (ENXIO);
|
2014-08-04 08:56:20 +00:00
|
|
|
return (-50);
|
2003-11-03 22:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run through the MP table enumerating CPUs.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
madt_probe_cpus(void)
|
|
|
|
{
|
|
|
|
|
2009-09-23 15:42:35 +00:00
|
|
|
madt = acpi_map_table(madt_physaddr, ACPI_SIG_MADT);
|
|
|
|
madt_length = madt->Header.Length;
|
2003-11-03 22:17:44 +00:00
|
|
|
KASSERT(madt != NULL, ("Unable to re-map MADT"));
|
|
|
|
madt_walk_table(madt_probe_cpus_handler, NULL);
|
2009-09-23 15:42:35 +00:00
|
|
|
acpi_unmap_table(madt);
|
2003-11-03 22:17:44 +00:00
|
|
|
madt = NULL;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the local APIC on the BSP.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
madt_setup_local(void)
|
|
|
|
{
|
2015-02-09 21:00:56 +00:00
|
|
|
ACPI_TABLE_DMAR *dmartbl;
|
|
|
|
vm_paddr_t dmartbl_physaddr;
|
2015-08-21 15:13:25 +00:00
|
|
|
const char *reason;
|
|
|
|
char *hw_vendor;
|
2015-02-14 09:00:12 +00:00
|
|
|
u_int p[4];
|
2016-09-19 15:58:45 +00:00
|
|
|
int user_x2apic;
|
|
|
|
bool bios_x2apic;
|
2003-11-03 22:17:44 +00:00
|
|
|
|
2015-02-09 21:00:56 +00:00
|
|
|
if ((cpu_feature2 & CPUID2_X2APIC) != 0) {
|
2015-08-21 15:13:25 +00:00
|
|
|
reason = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Automatically detect several configurations where
|
|
|
|
* x2APIC mode is known to cause troubles. User can
|
|
|
|
* override the setting with hw.x2apic_enable tunable.
|
|
|
|
*/
|
2015-02-09 21:00:56 +00:00
|
|
|
dmartbl_physaddr = acpi_find_table(ACPI_SIG_DMAR);
|
|
|
|
if (dmartbl_physaddr != 0) {
|
|
|
|
dmartbl = acpi_map_table(dmartbl_physaddr,
|
|
|
|
ACPI_SIG_DMAR);
|
2016-09-19 15:58:45 +00:00
|
|
|
if ((dmartbl->Flags & ACPI_DMAR_X2APIC_OPT_OUT) != 0)
|
2015-08-21 15:13:25 +00:00
|
|
|
reason = "by DMAR table";
|
2015-02-09 21:00:56 +00:00
|
|
|
acpi_unmap_table(dmartbl);
|
|
|
|
}
|
2015-02-14 09:00:12 +00:00
|
|
|
if (vm_guest == VM_GUEST_VMWARE) {
|
|
|
|
vmware_hvcall(VMW_HVCMD_GETVCPU_INFO, p);
|
|
|
|
if ((p[0] & VMW_VCPUINFO_VCPU_RESERVED) != 0 ||
|
2016-09-19 15:58:45 +00:00
|
|
|
(p[0] & VMW_VCPUINFO_LEGACY_X2APIC) == 0)
|
|
|
|
reason =
|
|
|
|
"inside VMWare without intr redirection";
|
2015-02-25 16:44:07 +00:00
|
|
|
} else if (vm_guest == VM_GUEST_XEN) {
|
2015-08-21 15:13:25 +00:00
|
|
|
reason = "due to running under XEN";
|
2015-12-03 10:59:10 +00:00
|
|
|
} else if (vm_guest == VM_GUEST_NO &&
|
|
|
|
CPUID_TO_FAMILY(cpu_id) == 0x6 &&
|
|
|
|
CPUID_TO_MODEL(cpu_id) == 0x2a) {
|
2015-08-21 15:13:25 +00:00
|
|
|
hw_vendor = kern_getenv("smbios.planar.maker");
|
|
|
|
/*
|
2015-12-03 10:59:10 +00:00
|
|
|
* It seems that some Lenovo and ASUS
|
|
|
|
* SandyBridge-based notebook BIOSes have a
|
|
|
|
* bug which prevents booting AP in x2APIC
|
|
|
|
* mode. Since the only way to detect mobile
|
|
|
|
* CPU is to check northbridge pci id, which
|
|
|
|
* cannot be done that early, disable x2APIC
|
|
|
|
* for all Lenovo and ASUS SandyBridge
|
|
|
|
* machines.
|
2015-08-21 15:13:25 +00:00
|
|
|
*/
|
2015-12-03 10:59:10 +00:00
|
|
|
if (hw_vendor != NULL) {
|
|
|
|
if (!strcmp(hw_vendor, "LENOVO") ||
|
|
|
|
!strcmp(hw_vendor,
|
|
|
|
"ASUSTeK Computer Inc.")) {
|
|
|
|
reason =
|
|
|
|
"for a suspected SandyBridge BIOS bug";
|
|
|
|
}
|
|
|
|
freeenv(hw_vendor);
|
2015-08-21 15:13:25 +00:00
|
|
|
}
|
2015-02-14 09:00:12 +00:00
|
|
|
}
|
2016-09-19 15:58:45 +00:00
|
|
|
bios_x2apic = lapic_is_x2apic();
|
|
|
|
if (reason != NULL && bios_x2apic) {
|
|
|
|
if (bootverbose)
|
|
|
|
printf("x2APIC should be disabled %s but "
|
|
|
|
"already enabled by BIOS; enabling.\n",
|
|
|
|
reason);
|
|
|
|
reason = NULL;
|
|
|
|
}
|
|
|
|
if (reason == NULL)
|
|
|
|
x2apic_mode = 1;
|
|
|
|
else if (bootverbose)
|
2015-08-21 15:13:25 +00:00
|
|
|
printf("x2APIC available but disabled %s\n", reason);
|
2016-09-19 15:58:45 +00:00
|
|
|
user_x2apic = x2apic_mode;
|
|
|
|
TUNABLE_INT_FETCH("hw.x2apic_enable", &user_x2apic);
|
|
|
|
if (user_x2apic != x2apic_mode) {
|
|
|
|
if (bios_x2apic && !user_x2apic)
|
|
|
|
printf("x2APIC disabled by tunable and "
|
|
|
|
"enabled by BIOS; ignoring tunable.");
|
|
|
|
else
|
|
|
|
x2apic_mode = user_x2apic;
|
|
|
|
}
|
2015-02-09 21:00:56 +00:00
|
|
|
}
|
|
|
|
|
2017-08-10 09:16:40 +00:00
|
|
|
/*
|
|
|
|
* Truncate max_apic_id if not in x2APIC mode. Some structures
|
|
|
|
* will already be allocated with the previous max_apic_id, but
|
|
|
|
* at least we can prevent wasting more memory elsewhere.
|
|
|
|
*/
|
|
|
|
if (!x2apic_mode)
|
|
|
|
max_apic_id = min(max_apic_id, xAPIC_MAX_APIC_ID);
|
|
|
|
|
2017-08-10 09:16:03 +00:00
|
|
|
madt = pmap_mapbios(madt_physaddr, madt_length);
|
|
|
|
lapics = malloc(sizeof(*lapics) * (max_apic_id + 1), M_MADT,
|
|
|
|
M_WAITOK | M_ZERO);
|
|
|
|
madt_walk_table(madt_setup_cpus_handler, NULL);
|
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
lapic_init(madt->Address);
|
2003-11-03 22:17:44 +00:00
|
|
|
printf("ACPI APIC Table: <%.*s %.*s>\n",
|
2007-03-22 18:16:43 +00:00
|
|
|
(int)sizeof(madt->Header.OemId), madt->Header.OemId,
|
|
|
|
(int)sizeof(madt->Header.OemTableId), madt->Header.OemTableId);
|
2003-11-03 22:17:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We ignore 64-bit local APIC override entries. Should we
|
|
|
|
* perhaps emit a warning here if we find one?
|
|
|
|
*/
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-01-30 00:24:45 +00:00
|
|
|
* Enumerate I/O APICs and setup interrupt sources.
|
2003-11-03 22:17:44 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
madt_setup_io(void)
|
|
|
|
{
|
2004-05-16 20:30:47 +00:00
|
|
|
void *ioapic;
|
|
|
|
u_int pin;
|
2003-11-03 22:17:44 +00:00
|
|
|
int i;
|
|
|
|
|
2017-08-10 09:16:03 +00:00
|
|
|
KASSERT(lapics != NULL, ("local APICs not initialized"));
|
|
|
|
|
2004-01-30 00:24:45 +00:00
|
|
|
/* Try to initialize ACPI so that we can access the FADT. */
|
|
|
|
i = acpi_Startup();
|
|
|
|
if (ACPI_FAILURE(i)) {
|
|
|
|
printf("MADT: ACPI Startup failed with %s\n",
|
|
|
|
AcpiFormatException(i));
|
|
|
|
printf("Try disabling either ACPI or apic support.\n");
|
|
|
|
panic("Using MADT but ACPI doesn't work");
|
|
|
|
}
|
2012-03-28 18:53:48 +00:00
|
|
|
|
2017-08-10 09:16:40 +00:00
|
|
|
ioapics = malloc(sizeof(*ioapics) * (IOAPIC_MAX_ID + 1), M_MADT,
|
2012-03-28 18:53:48 +00:00
|
|
|
M_WAITOK | M_ZERO);
|
|
|
|
|
2003-11-03 22:17:44 +00:00
|
|
|
/* First, we run through adding I/O APIC's. */
|
|
|
|
madt_walk_table(madt_parse_apics, NULL);
|
|
|
|
|
|
|
|
/* Second, we run through the table tweaking interrupt sources. */
|
|
|
|
madt_walk_table(madt_parse_ints, NULL);
|
|
|
|
|
2004-05-16 20:30:47 +00:00
|
|
|
/*
|
|
|
|
* If there was not an explicit override entry for the SCI,
|
|
|
|
* force it to use level trigger and active-low polarity.
|
|
|
|
*/
|
|
|
|
if (!madt_found_sci_override) {
|
2007-03-22 18:16:43 +00:00
|
|
|
if (madt_find_interrupt(AcpiGbl_FADT.SciInterrupt, &ioapic,
|
|
|
|
&pin) != 0)
|
|
|
|
printf("MADT: Could not find APIC for SCI IRQ %u\n",
|
|
|
|
AcpiGbl_FADT.SciInterrupt);
|
2004-05-16 20:30:47 +00:00
|
|
|
else {
|
|
|
|
printf(
|
|
|
|
"MADT: Forcing active-low polarity and level trigger for SCI\n");
|
|
|
|
ioapic_set_polarity(ioapic, pin, INTR_POLARITY_LOW);
|
|
|
|
ioapic_set_triggermode(ioapic, pin, INTR_TRIGGER_LEVEL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-03 22:17:44 +00:00
|
|
|
/* Third, we register all the I/O APIC's. */
|
2017-08-10 09:16:40 +00:00
|
|
|
for (i = 0; i <= IOAPIC_MAX_ID; i++)
|
2003-11-03 22:17:44 +00:00
|
|
|
if (ioapics[i].io_apic != NULL)
|
|
|
|
ioapic_register(ioapics[i].io_apic);
|
|
|
|
|
|
|
|
/* Finally, we throw the switch to enable the I/O APIC's. */
|
|
|
|
acpi_SetDefaultIntrModel(ACPI_INTR_APIC);
|
|
|
|
|
2012-03-28 18:53:48 +00:00
|
|
|
free(ioapics, M_MADT);
|
|
|
|
ioapics = NULL;
|
|
|
|
|
2017-08-10 09:16:03 +00:00
|
|
|
/* NB: this is the last use of the lapics array. */
|
|
|
|
free(lapics, M_MADT);
|
|
|
|
lapics = NULL;
|
|
|
|
|
2003-11-03 22:17:44 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
madt_register(void *dummy __unused)
|
|
|
|
{
|
|
|
|
|
|
|
|
apic_register_enumerator(&madt_enumerator);
|
|
|
|
}
|
2010-11-08 20:05:22 +00:00
|
|
|
SYSINIT(madt_register, SI_SUB_TUNABLES - 1, SI_ORDER_FIRST, madt_register, NULL);
|
2003-11-03 22:17:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the handler routine for each entry in the MADT table.
|
|
|
|
*/
|
|
|
|
static void
|
2009-09-23 15:42:35 +00:00
|
|
|
madt_walk_table(acpi_subtable_handler *handler, void *arg)
|
2003-11-03 22:17:44 +00:00
|
|
|
{
|
|
|
|
|
2009-09-23 15:42:35 +00:00
|
|
|
acpi_walk_subtables(madt + 1, (char *)madt + madt->Header.Length,
|
|
|
|
handler, arg);
|
2003-11-03 22:17:44 +00:00
|
|
|
}
|
|
|
|
|
2017-08-10 09:15:18 +00:00
|
|
|
static void
|
|
|
|
madt_parse_cpu(unsigned int apic_id, unsigned int flags)
|
|
|
|
{
|
|
|
|
|
2017-08-10 17:46:57 +00:00
|
|
|
if (!(flags & ACPI_MADT_ENABLED) ||
|
|
|
|
#ifdef SMP
|
|
|
|
mp_ncpus == MAXCPU ||
|
|
|
|
#endif
|
2017-08-10 09:15:18 +00:00
|
|
|
apic_id > MAX_APIC_ID)
|
|
|
|
return;
|
|
|
|
|
2017-08-10 17:46:57 +00:00
|
|
|
#ifdef SMP
|
2017-08-10 09:15:18 +00:00
|
|
|
mp_ncpus++;
|
|
|
|
mp_maxid = mp_ncpus - 1;
|
2017-08-10 17:46:57 +00:00
|
|
|
#endif
|
2017-08-10 09:15:18 +00:00
|
|
|
max_apic_id = max(apic_id, max_apic_id);
|
|
|
|
}
|
|
|
|
|
2015-06-09 10:49:40 +00:00
|
|
|
static void
|
|
|
|
madt_add_cpu(u_int acpi_id, u_int apic_id, u_int flags)
|
|
|
|
{
|
|
|
|
struct lapic_info *la;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The MADT does not include a BSP flag, so we have to let the
|
|
|
|
* MP code figure out which CPU is the BSP on its own.
|
|
|
|
*/
|
|
|
|
if (bootverbose)
|
|
|
|
printf("MADT: Found CPU APIC ID %u ACPI ID %u: %s\n",
|
|
|
|
apic_id, acpi_id, flags & ACPI_MADT_ENABLED ?
|
|
|
|
"enabled" : "disabled");
|
|
|
|
if (!(flags & ACPI_MADT_ENABLED))
|
|
|
|
return;
|
2017-08-10 09:16:03 +00:00
|
|
|
if (apic_id > max_apic_id) {
|
2015-06-09 10:49:40 +00:00
|
|
|
printf("MADT: Ignoring local APIC ID %u (too high)\n",
|
|
|
|
apic_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
la = &lapics[apic_id];
|
|
|
|
KASSERT(la->la_enabled == 0, ("Duplicate local APIC ID %u", apic_id));
|
|
|
|
la->la_enabled = 1;
|
|
|
|
la->la_acpi_id = acpi_id;
|
|
|
|
lapic_create(apic_id, 0);
|
|
|
|
}
|
|
|
|
|
2003-11-03 22:17:44 +00:00
|
|
|
static void
|
2007-03-22 18:16:43 +00:00
|
|
|
madt_probe_cpus_handler(ACPI_SUBTABLE_HEADER *entry, void *arg)
|
2003-11-03 22:17:44 +00:00
|
|
|
{
|
2007-03-22 18:16:43 +00:00
|
|
|
ACPI_MADT_LOCAL_APIC *proc;
|
2015-06-09 10:49:40 +00:00
|
|
|
ACPI_MADT_LOCAL_X2APIC *x2apic;
|
2003-11-03 22:17:44 +00:00
|
|
|
|
2017-08-10 09:15:18 +00:00
|
|
|
switch (entry->Type) {
|
|
|
|
case ACPI_MADT_TYPE_LOCAL_APIC:
|
|
|
|
proc = (ACPI_MADT_LOCAL_APIC *)entry;
|
|
|
|
madt_parse_cpu(proc->Id, proc->LapicFlags);
|
|
|
|
break;
|
|
|
|
case ACPI_MADT_TYPE_LOCAL_X2APIC:
|
|
|
|
x2apic = (ACPI_MADT_LOCAL_X2APIC *)entry;
|
|
|
|
madt_parse_cpu(x2apic->LocalApicId, x2apic->LapicFlags);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
madt_setup_cpus_handler(ACPI_SUBTABLE_HEADER *entry, void *arg)
|
|
|
|
{
|
|
|
|
ACPI_MADT_LOCAL_APIC *proc;
|
|
|
|
ACPI_MADT_LOCAL_X2APIC *x2apic;
|
|
|
|
|
2003-11-03 22:17:44 +00:00
|
|
|
switch (entry->Type) {
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TYPE_LOCAL_APIC:
|
|
|
|
proc = (ACPI_MADT_LOCAL_APIC *)entry;
|
2015-06-09 10:49:40 +00:00
|
|
|
madt_add_cpu(proc->ProcessorId, proc->Id, proc->LapicFlags);
|
|
|
|
break;
|
|
|
|
case ACPI_MADT_TYPE_LOCAL_X2APIC:
|
|
|
|
x2apic = (ACPI_MADT_LOCAL_X2APIC *)entry;
|
|
|
|
madt_add_cpu(x2apic->Uid, x2apic->LocalApicId,
|
|
|
|
x2apic->LapicFlags);
|
2003-11-03 22:17:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add an I/O APIC from an entry in the table.
|
|
|
|
*/
|
|
|
|
static void
|
2007-03-22 18:16:43 +00:00
|
|
|
madt_parse_apics(ACPI_SUBTABLE_HEADER *entry, void *arg __unused)
|
2003-11-03 22:17:44 +00:00
|
|
|
{
|
2007-03-22 18:16:43 +00:00
|
|
|
ACPI_MADT_IO_APIC *apic;
|
2003-11-03 22:17:44 +00:00
|
|
|
|
|
|
|
switch (entry->Type) {
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TYPE_IO_APIC:
|
|
|
|
apic = (ACPI_MADT_IO_APIC *)entry;
|
2003-11-03 22:17:44 +00:00
|
|
|
if (bootverbose)
|
2007-03-22 18:16:43 +00:00
|
|
|
printf(
|
|
|
|
"MADT: Found IO APIC ID %u, Interrupt %u at %p\n",
|
|
|
|
apic->Id, apic->GlobalIrqBase,
|
2003-12-09 03:04:19 +00:00
|
|
|
(void *)(uintptr_t)apic->Address);
|
2017-08-10 09:16:40 +00:00
|
|
|
if (apic->Id > IOAPIC_MAX_ID)
|
2007-03-22 18:16:43 +00:00
|
|
|
panic("%s: I/O APIC ID %u too high", __func__,
|
|
|
|
apic->Id);
|
|
|
|
if (ioapics[apic->Id].io_apic != NULL)
|
|
|
|
panic("%s: Double APIC ID %u", __func__, apic->Id);
|
|
|
|
ioapics[apic->Id].io_apic = ioapic_create(apic->Address,
|
|
|
|
apic->Id, apic->GlobalIrqBase);
|
|
|
|
ioapics[apic->Id].io_vector = apic->GlobalIrqBase;
|
2003-11-03 22:17:44 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-05-16 20:30:47 +00:00
|
|
|
* Determine properties of an interrupt source. Note that for ACPI these
|
|
|
|
* functions are only used for ISA interrupts, so we assume ISA bus values
|
|
|
|
* (Active Hi, Edge Triggered) for conforming values except for the ACPI
|
|
|
|
* SCI for which we use Active Lo, Level Triggered.
|
2003-11-03 22:17:44 +00:00
|
|
|
*/
|
2004-05-16 20:30:47 +00:00
|
|
|
static enum intr_polarity
|
2007-03-22 18:16:43 +00:00
|
|
|
interrupt_polarity(UINT16 IntiFlags, UINT8 Source)
|
2003-11-03 22:17:44 +00:00
|
|
|
{
|
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
switch (IntiFlags & ACPI_MADT_POLARITY_MASK) {
|
2014-03-28 02:38:14 +00:00
|
|
|
default:
|
2014-07-28 13:47:02 +00:00
|
|
|
printf("WARNING: Bogus Interrupt Polarity. Assume CONFORMS\n");
|
2014-03-28 02:38:14 +00:00
|
|
|
/* FALLTHROUGH*/
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_POLARITY_CONFORMS:
|
|
|
|
if (Source == AcpiGbl_FADT.SciInterrupt)
|
2004-05-16 20:30:47 +00:00
|
|
|
return (INTR_POLARITY_LOW);
|
|
|
|
else
|
|
|
|
return (INTR_POLARITY_HIGH);
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_POLARITY_ACTIVE_HIGH:
|
2004-05-16 20:30:47 +00:00
|
|
|
return (INTR_POLARITY_HIGH);
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_POLARITY_ACTIVE_LOW:
|
2014-03-28 02:38:14 +00:00
|
|
|
return (INTR_POLARITY_LOW);
|
2003-11-03 22:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-16 20:30:47 +00:00
|
|
|
static enum intr_trigger
|
2007-03-22 18:16:43 +00:00
|
|
|
interrupt_trigger(UINT16 IntiFlags, UINT8 Source)
|
2003-11-03 22:17:44 +00:00
|
|
|
{
|
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
switch (IntiFlags & ACPI_MADT_TRIGGER_MASK) {
|
2014-03-28 02:38:14 +00:00
|
|
|
default:
|
2014-07-28 13:47:02 +00:00
|
|
|
printf("WARNING: Bogus Interrupt Trigger Mode. Assume CONFORMS.\n");
|
2014-03-28 02:38:14 +00:00
|
|
|
/*FALLTHROUGH*/
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TRIGGER_CONFORMS:
|
|
|
|
if (Source == AcpiGbl_FADT.SciInterrupt)
|
2004-05-16 20:30:47 +00:00
|
|
|
return (INTR_TRIGGER_LEVEL);
|
|
|
|
else
|
|
|
|
return (INTR_TRIGGER_EDGE);
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TRIGGER_EDGE:
|
2004-05-16 20:30:47 +00:00
|
|
|
return (INTR_TRIGGER_EDGE);
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TRIGGER_LEVEL:
|
2014-03-28 02:38:14 +00:00
|
|
|
return (INTR_TRIGGER_LEVEL);
|
2003-11-03 22:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the local APIC ID associated with a given ACPI Processor ID.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
madt_find_cpu(u_int acpi_id, u_int *apic_id)
|
|
|
|
{
|
2004-06-03 20:25:05 +00:00
|
|
|
int i;
|
2003-11-03 22:17:44 +00:00
|
|
|
|
2017-08-10 09:16:03 +00:00
|
|
|
for (i = 0; i <= max_apic_id; i++) {
|
2004-06-10 21:30:08 +00:00
|
|
|
if (!lapics[i].la_enabled)
|
2004-06-03 20:25:05 +00:00
|
|
|
continue;
|
|
|
|
if (lapics[i].la_acpi_id != acpi_id)
|
|
|
|
continue;
|
|
|
|
*apic_id = i;
|
2004-06-10 21:30:08 +00:00
|
|
|
return (0);
|
2004-06-03 20:25:05 +00:00
|
|
|
}
|
|
|
|
return (ENOENT);
|
2003-11-03 22:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the IO APIC and pin on that APIC associated with a given global
|
|
|
|
* interrupt.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
madt_find_interrupt(int intr, void **apic, u_int *pin)
|
|
|
|
{
|
|
|
|
int i, best;
|
|
|
|
|
|
|
|
best = -1;
|
2017-08-10 09:16:40 +00:00
|
|
|
for (i = 0; i <= IOAPIC_MAX_ID; i++) {
|
2003-11-03 22:17:44 +00:00
|
|
|
if (ioapics[i].io_apic == NULL ||
|
|
|
|
ioapics[i].io_vector > intr)
|
|
|
|
continue;
|
|
|
|
if (best == -1 ||
|
|
|
|
ioapics[best].io_vector < ioapics[i].io_vector)
|
|
|
|
best = i;
|
|
|
|
}
|
|
|
|
if (best == -1)
|
|
|
|
return (ENOENT);
|
|
|
|
*apic = ioapics[best].io_apic;
|
|
|
|
*pin = intr - ioapics[best].io_vector;
|
|
|
|
if (*pin > 32)
|
|
|
|
printf("WARNING: Found intpin of %u for vector %d\n", *pin,
|
|
|
|
intr);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2014-08-04 08:58:50 +00:00
|
|
|
void
|
|
|
|
madt_parse_interrupt_values(void *entry,
|
|
|
|
enum intr_trigger *trig, enum intr_polarity *pol)
|
2003-11-03 22:17:44 +00:00
|
|
|
{
|
2014-08-04 08:58:50 +00:00
|
|
|
ACPI_MADT_INTERRUPT_OVERRIDE *intr;
|
2004-05-16 20:30:47 +00:00
|
|
|
char buf[64];
|
2003-11-03 22:17:44 +00:00
|
|
|
|
2014-08-04 08:58:50 +00:00
|
|
|
intr = entry;
|
|
|
|
|
2003-11-03 22:17:44 +00:00
|
|
|
if (bootverbose)
|
2005-02-22 21:52:52 +00:00
|
|
|
printf("MADT: Interrupt override: source %u, irq %u\n",
|
2007-03-22 18:16:43 +00:00
|
|
|
intr->SourceIrq, intr->GlobalIrq);
|
2003-11-03 22:17:44 +00:00
|
|
|
KASSERT(intr->Bus == 0, ("bus for interrupt overrides must be zero"));
|
|
|
|
|
2004-01-30 00:24:45 +00:00
|
|
|
/*
|
2004-05-16 20:30:47 +00:00
|
|
|
* Lookup the appropriate trigger and polarity modes for this
|
|
|
|
* entry.
|
|
|
|
*/
|
2014-08-04 08:58:50 +00:00
|
|
|
*trig = interrupt_trigger(intr->IntiFlags, intr->SourceIrq);
|
|
|
|
*pol = interrupt_polarity(intr->IntiFlags, intr->SourceIrq);
|
|
|
|
|
2004-05-16 20:30:47 +00:00
|
|
|
/*
|
2004-01-30 00:24:45 +00:00
|
|
|
* If the SCI is identity mapped but has edge trigger and
|
2004-05-16 20:30:47 +00:00
|
|
|
* active-hi polarity or the force_sci_lo tunable is set,
|
|
|
|
* force it to use level/lo.
|
2004-01-30 00:24:45 +00:00
|
|
|
*/
|
2007-03-22 18:16:43 +00:00
|
|
|
if (intr->SourceIrq == AcpiGbl_FADT.SciInterrupt) {
|
2004-05-16 20:30:47 +00:00
|
|
|
madt_found_sci_override = 1;
|
|
|
|
if (getenv_string("hw.acpi.sci.trigger", buf, sizeof(buf))) {
|
|
|
|
if (tolower(buf[0]) == 'e')
|
2014-08-04 08:58:50 +00:00
|
|
|
*trig = INTR_TRIGGER_EDGE;
|
2004-05-16 20:30:47 +00:00
|
|
|
else if (tolower(buf[0]) == 'l')
|
2014-08-04 08:58:50 +00:00
|
|
|
*trig = INTR_TRIGGER_LEVEL;
|
2004-05-16 20:30:47 +00:00
|
|
|
else
|
|
|
|
panic(
|
|
|
|
"Invalid trigger %s: must be 'edge' or 'level'",
|
|
|
|
buf);
|
|
|
|
printf("MADT: Forcing SCI to %s trigger\n",
|
2014-08-04 08:58:50 +00:00
|
|
|
*trig == INTR_TRIGGER_EDGE ? "edge" : "level");
|
2004-05-16 20:30:47 +00:00
|
|
|
}
|
|
|
|
if (getenv_string("hw.acpi.sci.polarity", buf, sizeof(buf))) {
|
|
|
|
if (tolower(buf[0]) == 'h')
|
2014-08-04 08:58:50 +00:00
|
|
|
*pol = INTR_POLARITY_HIGH;
|
2004-05-16 20:30:47 +00:00
|
|
|
else if (tolower(buf[0]) == 'l')
|
2014-08-04 08:58:50 +00:00
|
|
|
*pol = INTR_POLARITY_LOW;
|
2004-05-16 20:30:47 +00:00
|
|
|
else
|
|
|
|
panic(
|
|
|
|
"Invalid polarity %s: must be 'high' or 'low'",
|
|
|
|
buf);
|
|
|
|
printf("MADT: Forcing SCI to active %s polarity\n",
|
2014-08-04 08:58:50 +00:00
|
|
|
*pol == INTR_POLARITY_HIGH ? "high" : "low");
|
2004-05-16 20:30:47 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-04 08:58:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse an interrupt source override for an ISA interrupt.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
madt_parse_interrupt_override(ACPI_MADT_INTERRUPT_OVERRIDE *intr)
|
|
|
|
{
|
|
|
|
void *new_ioapic, *old_ioapic;
|
|
|
|
u_int new_pin, old_pin;
|
|
|
|
enum intr_trigger trig;
|
|
|
|
enum intr_polarity pol;
|
|
|
|
|
|
|
|
if (acpi_quirks & ACPI_Q_MADT_IRQ0 && intr->SourceIrq == 0 &&
|
|
|
|
intr->GlobalIrq == 2) {
|
|
|
|
if (bootverbose)
|
|
|
|
printf("MADT: Skipping timer override\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (madt_find_interrupt(intr->GlobalIrq, &new_ioapic, &new_pin) != 0) {
|
|
|
|
printf("MADT: Could not find APIC for vector %u (IRQ %u)\n",
|
|
|
|
intr->GlobalIrq, intr->SourceIrq);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
madt_parse_interrupt_values(intr, &trig, &pol);
|
2004-01-30 00:24:45 +00:00
|
|
|
|
2004-05-16 20:30:47 +00:00
|
|
|
/* Remap the IRQ if it is mapped to a different interrupt vector. */
|
2007-03-22 18:16:43 +00:00
|
|
|
if (intr->SourceIrq != intr->GlobalIrq) {
|
2004-01-30 00:24:45 +00:00
|
|
|
/*
|
|
|
|
* If the SCI is remapped to a non-ISA global interrupt,
|
|
|
|
* then override the vector we use to setup and allocate
|
|
|
|
* the interrupt.
|
|
|
|
*/
|
2007-03-22 18:16:43 +00:00
|
|
|
if (intr->GlobalIrq > 15 &&
|
|
|
|
intr->SourceIrq == AcpiGbl_FADT.SciInterrupt)
|
|
|
|
acpi_OverrideInterruptLevel(intr->GlobalIrq);
|
2003-11-11 18:20:10 +00:00
|
|
|
else
|
2007-03-22 18:16:43 +00:00
|
|
|
ioapic_remap_vector(new_ioapic, new_pin,
|
|
|
|
intr->SourceIrq);
|
|
|
|
if (madt_find_interrupt(intr->SourceIrq, &old_ioapic,
|
2003-11-05 23:15:52 +00:00
|
|
|
&old_pin) != 0)
|
2007-03-22 18:16:43 +00:00
|
|
|
printf("MADT: Could not find APIC for source IRQ %u\n",
|
|
|
|
intr->SourceIrq);
|
2003-11-06 14:47:53 +00:00
|
|
|
else if (ioapic_get_vector(old_ioapic, old_pin) ==
|
2007-03-22 18:16:43 +00:00
|
|
|
intr->SourceIrq)
|
2003-11-05 23:15:52 +00:00
|
|
|
ioapic_disable_pin(old_ioapic, old_pin);
|
|
|
|
}
|
2004-05-16 20:30:47 +00:00
|
|
|
|
|
|
|
/* Program the polarity and trigger mode. */
|
|
|
|
ioapic_set_triggermode(new_ioapic, new_pin, trig);
|
|
|
|
ioapic_set_polarity(new_ioapic, new_pin, pol);
|
2003-11-03 22:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse an entry for an NMI routed to an IO APIC.
|
|
|
|
*/
|
|
|
|
static void
|
2007-03-22 18:16:43 +00:00
|
|
|
madt_parse_nmi(ACPI_MADT_NMI_SOURCE *nmi)
|
2003-11-03 22:17:44 +00:00
|
|
|
{
|
|
|
|
void *ioapic;
|
|
|
|
u_int pin;
|
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
if (madt_find_interrupt(nmi->GlobalIrq, &ioapic, &pin) != 0) {
|
|
|
|
printf("MADT: Could not find APIC for vector %u\n",
|
|
|
|
nmi->GlobalIrq);
|
2003-11-03 22:17:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ioapic_set_nmi(ioapic, pin);
|
2007-03-22 18:16:43 +00:00
|
|
|
if (!(nmi->IntiFlags & ACPI_MADT_TRIGGER_CONFORMS))
|
2003-11-03 22:17:44 +00:00
|
|
|
ioapic_set_triggermode(ioapic, pin,
|
2007-03-22 18:16:43 +00:00
|
|
|
interrupt_trigger(nmi->IntiFlags, 0));
|
2014-03-27 06:08:07 +00:00
|
|
|
if (!(nmi->IntiFlags & ACPI_MADT_POLARITY_CONFORMS))
|
2003-11-03 22:17:44 +00:00
|
|
|
ioapic_set_polarity(ioapic, pin,
|
2007-03-22 18:16:43 +00:00
|
|
|
interrupt_polarity(nmi->IntiFlags, 0));
|
2003-11-03 22:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse an entry for an NMI routed to a local APIC LVT pin.
|
|
|
|
*/
|
|
|
|
static void
|
2015-06-09 10:49:40 +00:00
|
|
|
madt_handle_local_nmi(u_int acpi_id, UINT8 Lint, UINT16 IntiFlags)
|
2003-11-03 22:17:44 +00:00
|
|
|
{
|
|
|
|
u_int apic_id, pin;
|
|
|
|
|
2015-06-09 10:49:40 +00:00
|
|
|
if (acpi_id == 0xffffffff)
|
2003-11-03 22:17:44 +00:00
|
|
|
apic_id = APIC_ID_ALL;
|
2015-06-09 10:49:40 +00:00
|
|
|
else if (madt_find_cpu(acpi_id, &apic_id) != 0) {
|
2003-11-03 22:17:44 +00:00
|
|
|
if (bootverbose)
|
2007-03-22 18:16:43 +00:00
|
|
|
printf("MADT: Ignoring local NMI routed to "
|
2015-06-09 10:49:40 +00:00
|
|
|
"ACPI CPU %u\n", acpi_id);
|
2003-11-03 22:17:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-06-09 10:49:40 +00:00
|
|
|
if (Lint == 0)
|
2013-12-09 21:08:52 +00:00
|
|
|
pin = APIC_LVT_LINT0;
|
2003-11-03 22:17:44 +00:00
|
|
|
else
|
2013-12-09 21:08:52 +00:00
|
|
|
pin = APIC_LVT_LINT1;
|
2003-11-03 22:17:44 +00:00
|
|
|
lapic_set_lvt_mode(apic_id, pin, APIC_LVT_DM_NMI);
|
2015-06-09 10:49:40 +00:00
|
|
|
if (!(IntiFlags & ACPI_MADT_TRIGGER_CONFORMS))
|
2003-11-03 22:17:44 +00:00
|
|
|
lapic_set_lvt_triggermode(apic_id, pin,
|
2015-06-09 10:49:40 +00:00
|
|
|
interrupt_trigger(IntiFlags, 0));
|
|
|
|
if (!(IntiFlags & ACPI_MADT_POLARITY_CONFORMS))
|
2003-11-03 22:17:44 +00:00
|
|
|
lapic_set_lvt_polarity(apic_id, pin,
|
2015-06-09 10:49:40 +00:00
|
|
|
interrupt_polarity(IntiFlags, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
madt_parse_local_nmi(ACPI_MADT_LOCAL_APIC_NMI *nmi)
|
|
|
|
{
|
|
|
|
|
|
|
|
madt_handle_local_nmi(nmi->ProcessorId == 0xff ? 0xffffffff :
|
|
|
|
nmi->ProcessorId, nmi->Lint, nmi->IntiFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
madt_parse_local_x2apic_nmi(ACPI_MADT_LOCAL_X2APIC_NMI *nmi)
|
|
|
|
{
|
|
|
|
|
|
|
|
madt_handle_local_nmi(nmi->Uid, nmi->Lint, nmi->IntiFlags);
|
2003-11-03 22:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse interrupt entries.
|
|
|
|
*/
|
|
|
|
static void
|
2007-03-22 18:16:43 +00:00
|
|
|
madt_parse_ints(ACPI_SUBTABLE_HEADER *entry, void *arg __unused)
|
2003-11-03 22:17:44 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
switch (entry->Type) {
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE:
|
2003-11-03 22:17:44 +00:00
|
|
|
madt_parse_interrupt_override(
|
2007-03-22 18:16:43 +00:00
|
|
|
(ACPI_MADT_INTERRUPT_OVERRIDE *)entry);
|
2003-11-03 22:17:44 +00:00
|
|
|
break;
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TYPE_NMI_SOURCE:
|
|
|
|
madt_parse_nmi((ACPI_MADT_NMI_SOURCE *)entry);
|
2003-11-03 22:17:44 +00:00
|
|
|
break;
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TYPE_LOCAL_APIC_NMI:
|
|
|
|
madt_parse_local_nmi((ACPI_MADT_LOCAL_APIC_NMI *)entry);
|
2003-11-03 22:17:44 +00:00
|
|
|
break;
|
2015-06-09 10:49:40 +00:00
|
|
|
case ACPI_MADT_TYPE_LOCAL_X2APIC_NMI:
|
|
|
|
madt_parse_local_x2apic_nmi(
|
|
|
|
(ACPI_MADT_LOCAL_X2APIC_NMI *)entry);
|
|
|
|
break;
|
2003-11-03 22:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup per-CPU ACPI IDs.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
madt_set_ids(void *dummy)
|
|
|
|
{
|
2004-06-03 20:25:05 +00:00
|
|
|
struct lapic_info *la;
|
2003-11-03 22:17:44 +00:00
|
|
|
struct pcpu *pc;
|
2004-06-03 20:25:05 +00:00
|
|
|
u_int i;
|
2003-11-03 22:17:44 +00:00
|
|
|
|
|
|
|
if (madt == NULL)
|
|
|
|
return;
|
2017-08-10 09:16:03 +00:00
|
|
|
|
|
|
|
KASSERT(lapics != NULL, ("local APICs not initialized"));
|
|
|
|
|
2010-06-11 18:46:34 +00:00
|
|
|
CPU_FOREACH(i) {
|
2003-11-03 22:17:44 +00:00
|
|
|
pc = pcpu_find(i);
|
2007-03-22 18:16:43 +00:00
|
|
|
KASSERT(pc != NULL, ("no pcpu data for CPU %u", i));
|
2004-06-03 20:25:05 +00:00
|
|
|
la = &lapics[pc->pc_apic_id];
|
2004-06-10 21:30:08 +00:00
|
|
|
if (!la->la_enabled)
|
2004-06-03 20:25:05 +00:00
|
|
|
panic("APIC: CPU with APIC ID %u is not enabled",
|
|
|
|
pc->pc_apic_id);
|
|
|
|
pc->pc_acpi_id = la->la_acpi_id;
|
|
|
|
if (bootverbose)
|
|
|
|
printf("APIC: CPU %u has ACPI ID %u\n", i,
|
|
|
|
la->la_acpi_id);
|
2003-11-03 22:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-05 23:11:01 +00:00
|
|
|
SYSINIT(madt_set_ids, SI_SUB_CPU, SI_ORDER_MIDDLE, madt_set_ids, NULL);
|