2003-11-03 22:17:44 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2003 John Baldwin <jhb@FreeBSD.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. Neither the name of the author nor the names of any co-contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/smp.h>
|
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_param.h>
|
|
|
|
#include <vm/pmap.h>
|
|
|
|
|
|
|
|
#include <machine/apicreg.h>
|
|
|
|
#include <machine/frame.h>
|
|
|
|
#include <machine/intr_machdep.h>
|
|
|
|
#include <machine/apicvar.h>
|
|
|
|
#include <machine/md_var.h>
|
|
|
|
#include <machine/specialreg.h>
|
|
|
|
|
|
|
|
#include "acpi.h"
|
2004-05-10 18:33:08 +00:00
|
|
|
#include <contrib/dev/acpica/actables.h>
|
2003-11-03 22:17:44 +00:00
|
|
|
#include <dev/acpica/acpivar.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
|
2003-11-10 19:52:58 +00:00
|
|
|
#define NIOAPICS 32 /* Max number of I/O APICs */
|
|
|
|
#define NLAPICS 32 /* Max number of local APICs */
|
2003-11-03 22:17:44 +00:00
|
|
|
|
|
|
|
typedef void madt_entry_handler(APIC_HEADER *entry, void *arg);
|
|
|
|
|
|
|
|
/* These two arrays are indexed by APIC IDs. */
|
|
|
|
struct ioapic_info {
|
|
|
|
void *io_apic;
|
|
|
|
UINT32 io_vector;
|
|
|
|
} ioapics[NIOAPICS];
|
|
|
|
|
|
|
|
struct lapic_info {
|
|
|
|
u_int la_enabled:1;
|
2004-06-01 19:49:38 +00:00
|
|
|
u_int la_acpi_id:8;
|
|
|
|
} lapics[NLAPICS];
|
2003-11-03 22:17:44 +00:00
|
|
|
|
2004-05-04 20:39:24 +00:00
|
|
|
static int madt_found_sci_override;
|
2003-12-09 03:04:19 +00:00
|
|
|
static MULTIPLE_APIC_TABLE *madt;
|
2003-11-03 22:17:44 +00:00
|
|
|
static vm_paddr_t madt_physaddr;
|
|
|
|
static vm_offset_t madt_length;
|
|
|
|
|
|
|
|
MALLOC_DEFINE(M_MADT, "MADT Table", "ACPI MADT Table Items");
|
|
|
|
|
2004-05-04 20:39:24 +00:00
|
|
|
static enum intr_polarity interrupt_polarity(UINT16 Polarity, UINT8 Source);
|
|
|
|
static enum intr_trigger interrupt_trigger(UINT16 TriggerMode, 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);
|
|
|
|
static void *madt_map(vm_paddr_t pa, int offset, vm_offset_t length);
|
|
|
|
static void *madt_map_table(vm_paddr_t pa, int offset, const char *sig);
|
|
|
|
static void madt_parse_apics(APIC_HEADER *entry, void *arg);
|
2003-12-09 03:04:19 +00:00
|
|
|
static void madt_parse_interrupt_override(MADT_INTERRUPT_OVERRIDE *intr);
|
2003-11-03 22:17:44 +00:00
|
|
|
static void madt_parse_ints(APIC_HEADER *entry, void *arg __unused);
|
2003-12-09 03:04:19 +00:00
|
|
|
static void madt_parse_local_nmi(MADT_LOCAL_APIC_NMI *nmi);
|
|
|
|
static void madt_parse_nmi(MADT_NMI_SOURCE *nmi);
|
2003-11-03 22:17:44 +00:00
|
|
|
static int madt_probe(void);
|
|
|
|
static int madt_probe_cpus(void);
|
|
|
|
static void madt_probe_cpus_handler(APIC_HEADER *entry, void *arg __unused);
|
|
|
|
static int madt_probe_table(vm_paddr_t address);
|
|
|
|
static void madt_register(void *dummy);
|
|
|
|
static int madt_setup_local(void);
|
|
|
|
static int madt_setup_io(void);
|
|
|
|
static void madt_unmap(void *data, vm_offset_t length);
|
|
|
|
static void madt_unmap_table(void *table);
|
|
|
|
static void madt_walk_table(madt_entry_handler *handler, void *arg);
|
|
|
|
|
|
|
|
static struct apic_enumerator madt_enumerator = {
|
|
|
|
"MADT",
|
|
|
|
madt_probe,
|
|
|
|
madt_probe_cpus,
|
|
|
|
madt_setup_local,
|
|
|
|
madt_setup_io
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Code to abuse the crashdump map to map in the tables for the early
|
|
|
|
* probe. We cheat and make the following assumptions about how we
|
|
|
|
* use this KVA: page 0 is used to map in the first page of each table
|
|
|
|
* found via the RSDT or XSDT and pages 1 to n are used to map in the
|
|
|
|
* RSDT or XSDT. The offset is in pages; the length is in bytes.
|
|
|
|
*/
|
|
|
|
static void *
|
|
|
|
madt_map(vm_paddr_t pa, int offset, vm_offset_t length)
|
|
|
|
{
|
|
|
|
vm_offset_t va, off;
|
|
|
|
void *data;
|
|
|
|
|
|
|
|
off = pa & PAGE_MASK;
|
|
|
|
length = roundup(length + off, PAGE_SIZE);
|
|
|
|
pa = pa & PG_FRAME;
|
|
|
|
va = (vm_offset_t)pmap_kenter_temporary(pa, offset) +
|
|
|
|
(offset * PAGE_SIZE);
|
|
|
|
data = (void *)(va + off);
|
|
|
|
length -= PAGE_SIZE;
|
|
|
|
while (length > 0) {
|
|
|
|
va += PAGE_SIZE;
|
|
|
|
pa += PAGE_SIZE;
|
|
|
|
length -= PAGE_SIZE;
|
|
|
|
pmap_kenter(va, pa);
|
|
|
|
invlpg(va);
|
|
|
|
}
|
|
|
|
return (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
madt_unmap(void *data, vm_offset_t length)
|
|
|
|
{
|
|
|
|
vm_offset_t va, off;
|
|
|
|
|
|
|
|
va = (vm_offset_t)data;
|
|
|
|
off = va & PAGE_MASK;
|
|
|
|
length = roundup(length + off, PAGE_SIZE);
|
|
|
|
va &= ~PAGE_MASK;
|
|
|
|
while (length > 0) {
|
|
|
|
pmap_kremove(va);
|
|
|
|
invlpg(va);
|
|
|
|
va += PAGE_SIZE;
|
|
|
|
length -= PAGE_SIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
madt_map_table(vm_paddr_t pa, int offset, const char *sig)
|
|
|
|
{
|
|
|
|
ACPI_TABLE_HEADER *header;
|
|
|
|
vm_offset_t length;
|
2004-05-10 18:33:08 +00:00
|
|
|
void *table;
|
2003-11-03 22:17:44 +00:00
|
|
|
|
|
|
|
header = madt_map(pa, offset, sizeof(ACPI_TABLE_HEADER));
|
|
|
|
if (strncmp(header->Signature, sig, 4) != 0) {
|
|
|
|
madt_unmap(header, sizeof(ACPI_TABLE_HEADER));
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
length = header->Length;
|
|
|
|
madt_unmap(header, sizeof(ACPI_TABLE_HEADER));
|
2004-05-10 18:33:08 +00:00
|
|
|
table = madt_map(pa, offset, length);
|
|
|
|
if (ACPI_FAILURE(AcpiTbVerifyTableChecksum(table))) {
|
|
|
|
if (bootverbose)
|
|
|
|
printf("MADT: Failed checksum for table %s\n", sig);
|
|
|
|
madt_unmap(table, length);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
return (table);
|
2003-11-03 22:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
madt_unmap_table(void *table)
|
|
|
|
{
|
|
|
|
ACPI_TABLE_HEADER *header;
|
|
|
|
|
|
|
|
header = (ACPI_TABLE_HEADER *)table;
|
|
|
|
madt_unmap(table, header->Length);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look for an ACPI Multiple APIC Description Table ("APIC")
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
madt_probe(void)
|
|
|
|
{
|
|
|
|
ACPI_POINTER rsdp_ptr;
|
|
|
|
RSDP_DESCRIPTOR *rsdp;
|
|
|
|
RSDT_DESCRIPTOR *rsdt;
|
|
|
|
XSDT_DESCRIPTOR *xsdt;
|
|
|
|
int i, count;
|
|
|
|
|
|
|
|
if (resource_disabled("acpi", 0))
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map in the RSDP. Since ACPI uses AcpiOsMapMemory() which in turn
|
|
|
|
* calls pmap_mapdev() to find the RSDP, we assume that we can use
|
|
|
|
* pmap_mapdev() to map the RSDP.
|
|
|
|
*/
|
|
|
|
if (AcpiOsGetRootPointer(ACPI_LOGICAL_ADDRESSING, &rsdp_ptr) != AE_OK)
|
|
|
|
return (ENXIO);
|
2003-11-14 22:26:29 +00:00
|
|
|
#ifdef __i386__
|
2003-11-03 22:17:44 +00:00
|
|
|
KASSERT(rsdp_ptr.Pointer.Physical < KERNLOAD, ("RSDP too high"));
|
2003-11-14 22:26:29 +00:00
|
|
|
#endif
|
2003-11-03 22:17:44 +00:00
|
|
|
rsdp = pmap_mapdev(rsdp_ptr.Pointer.Physical, sizeof(RSDP_DESCRIPTOR));
|
|
|
|
if (rsdp == NULL) {
|
|
|
|
if (bootverbose)
|
|
|
|
printf("MADT: Failed to map RSDP\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For ACPI < 2.0, use the RSDT. For ACPI >= 2.0, use the XSDT.
|
|
|
|
* We map the XSDT and RSDT at page 1 in the crashdump area.
|
|
|
|
* Page 0 is used to map in the headers of candidate ACPI tables.
|
|
|
|
*/
|
|
|
|
if (rsdp->Revision >= 2) {
|
2004-05-10 18:33:08 +00:00
|
|
|
/*
|
|
|
|
* AcpiOsGetRootPointer only verifies the checksum for
|
|
|
|
* the version 1.0 portion of the RSDP. Version 2.0 has
|
|
|
|
* an additional checksum that we verify first.
|
|
|
|
*/
|
|
|
|
if (AcpiTbChecksum(rsdp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0) {
|
|
|
|
if (bootverbose)
|
|
|
|
printf("MADT: RSDP failed extended checksum\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
2003-11-03 22:17:44 +00:00
|
|
|
xsdt = madt_map_table(rsdp->XsdtPhysicalAddress, 1, XSDT_SIG);
|
|
|
|
if (xsdt == NULL) {
|
|
|
|
if (bootverbose)
|
|
|
|
printf("MADT: Failed to map XSDT\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
2003-12-09 03:04:19 +00:00
|
|
|
count = (xsdt->Length - sizeof(ACPI_TABLE_HEADER)) /
|
2003-11-03 22:17:44 +00:00
|
|
|
sizeof(UINT64);
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
if (madt_probe_table(xsdt->TableOffsetEntry[i]))
|
|
|
|
break;
|
|
|
|
madt_unmap_table(xsdt);
|
|
|
|
} else {
|
|
|
|
rsdt = madt_map_table(rsdp->RsdtPhysicalAddress, 1, RSDT_SIG);
|
|
|
|
if (rsdt == NULL) {
|
|
|
|
if (bootverbose)
|
|
|
|
printf("MADT: Failed to map RSDT\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
2003-12-09 03:04:19 +00:00
|
|
|
count = (rsdt->Length - sizeof(ACPI_TABLE_HEADER)) /
|
2003-11-03 22:17:44 +00:00
|
|
|
sizeof(UINT32);
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
if (madt_probe_table(rsdt->TableOffsetEntry[i]))
|
|
|
|
break;
|
|
|
|
madt_unmap_table(rsdt);
|
|
|
|
}
|
|
|
|
pmap_unmapdev((vm_offset_t)rsdp, sizeof(RSDP_DESCRIPTOR));
|
|
|
|
if (madt_physaddr == 0) {
|
|
|
|
if (bootverbose)
|
|
|
|
printf("MADT: No MADT table found\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
if (bootverbose)
|
2003-11-04 01:07:04 +00:00
|
|
|
printf("MADT: Found table at 0x%jx\n",
|
|
|
|
(uintmax_t)madt_physaddr);
|
2003-11-03 22:17:44 +00:00
|
|
|
|
2004-05-10 18:33:08 +00:00
|
|
|
/*
|
|
|
|
* Verify that we can map the full table and that its checksum is
|
|
|
|
* correct, etc.
|
|
|
|
*/
|
|
|
|
madt = madt_map_table(madt_physaddr, 0, APIC_SIG);
|
|
|
|
if (madt == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
madt_unmap_table(madt);
|
|
|
|
madt = NULL;
|
|
|
|
|
2003-11-03 22:17:44 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See if a given ACPI table is the MADT.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
madt_probe_table(vm_paddr_t address)
|
|
|
|
{
|
|
|
|
ACPI_TABLE_HEADER *table;
|
|
|
|
|
|
|
|
table = madt_map(address, 0, sizeof(ACPI_TABLE_HEADER));
|
|
|
|
if (table == NULL) {
|
|
|
|
if (bootverbose)
|
2003-11-04 01:07:04 +00:00
|
|
|
printf("MADT: Failed to map table at 0x%jx\n",
|
|
|
|
(uintmax_t)address);
|
2003-11-03 22:17:44 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (bootverbose)
|
2003-11-04 01:07:04 +00:00
|
|
|
printf("Table '%.4s' at 0x%jx\n", table->Signature,
|
|
|
|
(uintmax_t)address);
|
2003-11-03 22:17:44 +00:00
|
|
|
|
|
|
|
if (strncmp(table->Signature, APIC_SIG, 4) != 0) {
|
|
|
|
madt_unmap(table, sizeof(ACPI_TABLE_HEADER));
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
madt_physaddr = address;
|
|
|
|
madt_length = table->Length;
|
|
|
|
madt_unmap(table, sizeof(ACPI_TABLE_HEADER));
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run through the MP table enumerating CPUs.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
madt_probe_cpus(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
madt = madt_map_table(madt_physaddr, 0, APIC_SIG);
|
|
|
|
KASSERT(madt != NULL, ("Unable to re-map MADT"));
|
|
|
|
madt_walk_table(madt_probe_cpus_handler, NULL);
|
|
|
|
madt_unmap_table(madt);
|
|
|
|
madt = NULL;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the local APIC on the BSP.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
madt_setup_local(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
madt = pmap_mapdev(madt_physaddr, madt_length);
|
|
|
|
lapic_init((uintptr_t)madt->LocalApicAddress);
|
|
|
|
printf("ACPI APIC Table: <%.*s %.*s>\n",
|
2003-12-09 03:04:19 +00:00
|
|
|
(int)sizeof(madt->OemId), madt->OemId,
|
|
|
|
(int)sizeof(madt->OemTableId), madt->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-26 19:34:24 +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-04 20:39:24 +00:00
|
|
|
void *ioapic;
|
|
|
|
u_int pin;
|
2003-11-03 22:17:44 +00:00
|
|
|
int i;
|
|
|
|
|
2004-01-26 19:34:24 +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");
|
|
|
|
}
|
|
|
|
|
2003-11-03 22:17:44 +00:00
|
|
|
/* First, we run through adding I/O APIC's. */
|
2004-05-10 18:49:58 +00:00
|
|
|
if (madt->PCATCompat)
|
|
|
|
ioapic_enable_mixed_mode();
|
2003-11-03 22:17:44 +00:00
|
|
|
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-04 20:39:24 +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) {
|
|
|
|
if (madt_find_interrupt(AcpiGbl_FADT->SciInt, &ioapic, &pin)
|
|
|
|
!= 0)
|
|
|
|
printf("MADT: Could not find APIC for SCI IRQ %d\n",
|
|
|
|
AcpiGbl_FADT->SciInt);
|
|
|
|
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. */
|
|
|
|
for (i = 0; i < NIOAPICS; i++)
|
|
|
|
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);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
madt_register(void *dummy __unused)
|
|
|
|
{
|
|
|
|
|
|
|
|
apic_register_enumerator(&madt_enumerator);
|
|
|
|
}
|
2003-12-03 20:33:18 +00:00
|
|
|
SYSINIT(madt_register, SI_SUB_CPU - 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
|
|
|
|
madt_walk_table(madt_entry_handler *handler, void *arg)
|
|
|
|
{
|
|
|
|
APIC_HEADER *entry;
|
|
|
|
u_char *p, *end;
|
|
|
|
|
2003-12-09 03:04:19 +00:00
|
|
|
end = (u_char *)(madt) + madt->Length;
|
2003-11-03 22:17:44 +00:00
|
|
|
for (p = (u_char *)(madt + 1); p < end; ) {
|
|
|
|
entry = (APIC_HEADER *)p;
|
|
|
|
handler(entry, arg);
|
|
|
|
p += entry->Length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
madt_probe_cpus_handler(APIC_HEADER *entry, void *arg)
|
|
|
|
{
|
2003-12-09 03:04:19 +00:00
|
|
|
MADT_PROCESSOR_APIC *proc;
|
2003-11-03 22:17:44 +00:00
|
|
|
struct lapic_info *la;
|
|
|
|
|
|
|
|
switch (entry->Type) {
|
2003-12-09 03:04:19 +00:00
|
|
|
case APIC_PROCESSOR:
|
2003-11-03 22:17:44 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2003-12-09 03:04:19 +00:00
|
|
|
proc = (MADT_PROCESSOR_APIC *)entry;
|
2003-11-03 22:17:44 +00:00
|
|
|
if (bootverbose)
|
|
|
|
printf("MADT: Found CPU APIC ID %d ACPI ID %d: %s\n",
|
2003-12-09 03:04:19 +00:00
|
|
|
proc->LocalApicId, proc->ProcessorId,
|
2003-11-03 22:17:44 +00:00
|
|
|
proc->ProcessorEnabled ? "enabled" : "disabled");
|
2004-06-10 20:03:46 +00:00
|
|
|
if (!proc->ProcessorEnabled)
|
|
|
|
break;
|
2004-06-01 19:49:38 +00:00
|
|
|
if (proc->LocalApicId >= NLAPICS)
|
2003-11-03 22:17:44 +00:00
|
|
|
panic("%s: CPU ID %d too high", __func__,
|
2004-06-01 19:49:38 +00:00
|
|
|
proc->LocalApicId);
|
|
|
|
la = &lapics[proc->LocalApicId];
|
2004-06-10 20:03:46 +00:00
|
|
|
KASSERT(la->la_enabled == 0,
|
2004-06-01 19:49:38 +00:00
|
|
|
("Duplicate local APIC ID %d", proc->LocalApicId));
|
2004-06-10 20:03:46 +00:00
|
|
|
la->la_enabled = 1;
|
2004-06-01 19:49:38 +00:00
|
|
|
la->la_acpi_id = proc->ProcessorId;
|
2004-06-10 20:03:46 +00:00
|
|
|
lapic_create(proc->LocalApicId, 0);
|
2003-11-03 22:17:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add an I/O APIC from an entry in the table.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
madt_parse_apics(APIC_HEADER *entry, void *arg __unused)
|
|
|
|
{
|
2003-12-09 03:04:19 +00:00
|
|
|
MADT_IO_APIC *apic;
|
2003-11-03 22:17:44 +00:00
|
|
|
|
|
|
|
switch (entry->Type) {
|
|
|
|
case APIC_IO:
|
2003-12-09 03:04:19 +00:00
|
|
|
apic = (MADT_IO_APIC *)entry;
|
2003-11-03 22:17:44 +00:00
|
|
|
if (bootverbose)
|
2003-12-09 03:04:19 +00:00
|
|
|
printf("MADT: Found IO APIC ID %d, Interrupt %d at %p\n",
|
|
|
|
apic->IoApicId, apic->Interrupt,
|
|
|
|
(void *)(uintptr_t)apic->Address);
|
2003-11-03 22:17:44 +00:00
|
|
|
if (apic->IoApicId >= NIOAPICS)
|
|
|
|
panic("%s: I/O APIC ID %d too high", __func__,
|
|
|
|
apic->IoApicId);
|
|
|
|
if (ioapics[apic->IoApicId].io_apic != NULL)
|
|
|
|
panic("%s: Double APIC ID %d", __func__,
|
|
|
|
apic->IoApicId);
|
|
|
|
ioapics[apic->IoApicId].io_apic = ioapic_create(
|
2003-12-09 03:04:19 +00:00
|
|
|
(uintptr_t)apic->Address, apic->IoApicId,
|
|
|
|
apic->Interrupt);
|
|
|
|
ioapics[apic->IoApicId].io_vector = apic->Interrupt;
|
2003-11-03 22:17:44 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-05-11 20:06:32 +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
|
2004-05-04 20:39:24 +00:00
|
|
|
* (Active Hi, Edge Triggered) for conforming values except for the ACPI
|
2004-05-11 20:06:32 +00:00
|
|
|
* SCI for which we use Active Lo, Level Triggered.
|
2003-11-03 22:17:44 +00:00
|
|
|
*/
|
2004-05-04 20:39:24 +00:00
|
|
|
static enum intr_polarity
|
|
|
|
interrupt_polarity(UINT16 Polarity, UINT8 Source)
|
2003-11-03 22:17:44 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
switch (Polarity) {
|
2003-12-09 03:04:19 +00:00
|
|
|
case POLARITY_CONFORMS:
|
2004-05-04 20:39:24 +00:00
|
|
|
if (Source == AcpiGbl_FADT->SciInt)
|
|
|
|
return (INTR_POLARITY_LOW);
|
|
|
|
else
|
|
|
|
return (INTR_POLARITY_HIGH);
|
2003-12-09 03:04:19 +00:00
|
|
|
case POLARITY_ACTIVE_HIGH:
|
2004-05-04 20:39:24 +00:00
|
|
|
return (INTR_POLARITY_HIGH);
|
2003-12-09 03:04:19 +00:00
|
|
|
case POLARITY_ACTIVE_LOW:
|
2004-05-04 20:39:24 +00:00
|
|
|
return (INTR_POLARITY_LOW);
|
2003-11-03 22:17:44 +00:00
|
|
|
default:
|
|
|
|
panic("Bogus Interrupt Polarity");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-04 20:39:24 +00:00
|
|
|
static enum intr_trigger
|
|
|
|
interrupt_trigger(UINT16 TriggerMode, UINT8 Source)
|
2003-11-03 22:17:44 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
switch (TriggerMode) {
|
2003-12-09 03:04:19 +00:00
|
|
|
case TRIGGER_CONFORMS:
|
2004-05-04 20:39:24 +00:00
|
|
|
if (Source == AcpiGbl_FADT->SciInt)
|
|
|
|
return (INTR_TRIGGER_LEVEL);
|
|
|
|
else
|
|
|
|
return (INTR_TRIGGER_EDGE);
|
2003-12-09 03:04:19 +00:00
|
|
|
case TRIGGER_EDGE:
|
2004-05-04 20:39:24 +00:00
|
|
|
return (INTR_TRIGGER_EDGE);
|
2003-12-09 03:04:19 +00:00
|
|
|
case TRIGGER_LEVEL:
|
2004-05-04 20:39:24 +00:00
|
|
|
return (INTR_TRIGGER_LEVEL);
|
2003-11-03 22:17:44 +00:00
|
|
|
default:
|
|
|
|
panic("Bogus Interrupt Trigger Mode");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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-01 19:49:38 +00:00
|
|
|
int i;
|
2003-11-03 22:17:44 +00:00
|
|
|
|
2004-06-01 19:49:38 +00:00
|
|
|
for (i = 0; i < NLAPICS; i++) {
|
2004-06-10 20:03:46 +00:00
|
|
|
if (!lapics[i].la_enabled)
|
2004-06-01 19:49:38 +00:00
|
|
|
continue;
|
|
|
|
if (lapics[i].la_acpi_id != acpi_id)
|
|
|
|
continue;
|
|
|
|
*apic_id = i;
|
2004-06-10 20:03:46 +00:00
|
|
|
return (0);
|
2004-06-01 19:49:38 +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;
|
|
|
|
for (i = 0; i < NIOAPICS; i++) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse an interrupt source override for an ISA interrupt.
|
|
|
|
*/
|
|
|
|
static void
|
2003-12-09 03:04:19 +00:00
|
|
|
madt_parse_interrupt_override(MADT_INTERRUPT_OVERRIDE *intr)
|
2003-11-03 22:17:44 +00:00
|
|
|
{
|
2003-11-05 23:15:52 +00:00
|
|
|
void *new_ioapic, *old_ioapic;
|
|
|
|
u_int new_pin, old_pin;
|
2004-05-04 20:39:24 +00:00
|
|
|
enum intr_trigger trig;
|
|
|
|
enum intr_polarity pol;
|
|
|
|
char buf[64];
|
2003-11-03 22:17:44 +00:00
|
|
|
|
|
|
|
if (bootverbose)
|
|
|
|
printf("MADT: intr override: source %u, irq %u\n",
|
2003-12-09 03:04:19 +00:00
|
|
|
intr->Source, intr->Interrupt);
|
2003-11-03 22:17:44 +00:00
|
|
|
KASSERT(intr->Bus == 0, ("bus for interrupt overrides must be zero"));
|
2003-12-09 03:04:19 +00:00
|
|
|
if (madt_find_interrupt(intr->Interrupt, &new_ioapic,
|
2003-11-05 23:15:52 +00:00
|
|
|
&new_pin) != 0) {
|
2003-11-03 22:17:44 +00:00
|
|
|
printf("MADT: Could not find APIC for vector %d (IRQ %d)\n",
|
2003-12-09 03:04:19 +00:00
|
|
|
intr->Interrupt, intr->Source);
|
2003-11-03 22:17:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-05-04 20:39:24 +00:00
|
|
|
/*
|
|
|
|
* Lookup the appropriate trigger and polarity modes for this
|
|
|
|
* entry.
|
|
|
|
*/
|
|
|
|
trig = interrupt_trigger(intr->TriggerMode, intr->Source);
|
|
|
|
pol = interrupt_polarity(intr->Polarity, intr->Source);
|
|
|
|
|
2004-01-26 19:34:24 +00:00
|
|
|
/*
|
|
|
|
* If the SCI is identity mapped but has edge trigger and
|
2004-04-16 19:46:30 +00:00
|
|
|
* active-hi polarity or the force_sci_lo tunable is set,
|
|
|
|
* force it to use level/lo.
|
2004-01-26 19:34:24 +00:00
|
|
|
*/
|
2004-05-04 20:39:24 +00:00
|
|
|
if (intr->Source == AcpiGbl_FADT->SciInt) {
|
|
|
|
madt_found_sci_override = 1;
|
|
|
|
if (getenv_string("hw.acpi.sci.trigger", buf, sizeof(buf))) {
|
|
|
|
if (tolower(buf[0]) == 'e')
|
|
|
|
trig = INTR_TRIGGER_EDGE;
|
|
|
|
else if (tolower(buf[0]) == 'l')
|
|
|
|
trig = INTR_TRIGGER_LEVEL;
|
|
|
|
else
|
|
|
|
panic(
|
|
|
|
"Invalid trigger %s: must be 'edge' or 'level'",
|
|
|
|
buf);
|
|
|
|
printf("MADT: Forcing SCI to %s trigger\n",
|
|
|
|
trig == INTR_TRIGGER_EDGE ? "edge" : "level");
|
|
|
|
}
|
|
|
|
if (getenv_string("hw.acpi.sci.polarity", buf, sizeof(buf))) {
|
|
|
|
if (tolower(buf[0]) == 'h')
|
|
|
|
pol = INTR_POLARITY_HIGH;
|
|
|
|
else if (tolower(buf[0]) == 'l')
|
|
|
|
pol = INTR_POLARITY_LOW;
|
|
|
|
else
|
|
|
|
panic(
|
|
|
|
"Invalid polarity %s: must be 'high' or 'low'",
|
|
|
|
buf);
|
|
|
|
printf("MADT: Forcing SCI to active %s polarity\n",
|
|
|
|
pol == INTR_POLARITY_HIGH ? "high" : "low");
|
|
|
|
}
|
|
|
|
}
|
2004-01-26 19:34:24 +00:00
|
|
|
|
2004-05-04 20:39:24 +00:00
|
|
|
/* Remap the IRQ if it is mapped to a different interrupt vector. */
|
2003-12-09 03:04:19 +00:00
|
|
|
if (intr->Source != intr->Interrupt) {
|
2004-01-26 19:34:24 +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.
|
|
|
|
*/
|
|
|
|
if (intr->Interrupt > 15 &&
|
|
|
|
intr->Source == AcpiGbl_FADT->SciInt)
|
2003-12-09 03:04:19 +00:00
|
|
|
acpi_OverrideInterruptLevel(intr->Interrupt);
|
2003-11-11 18:20:10 +00:00
|
|
|
else
|
|
|
|
ioapic_remap_vector(new_ioapic, new_pin, intr->Source);
|
2003-11-05 23:15:52 +00:00
|
|
|
if (madt_find_interrupt(intr->Source, &old_ioapic,
|
|
|
|
&old_pin) != 0)
|
|
|
|
printf("MADT: Could not find APIC for source IRQ %d\n",
|
|
|
|
intr->Source);
|
2003-11-06 14:47:53 +00:00
|
|
|
else if (ioapic_get_vector(old_ioapic, old_pin) ==
|
|
|
|
intr->Source)
|
2003-11-05 23:15:52 +00:00
|
|
|
ioapic_disable_pin(old_ioapic, old_pin);
|
|
|
|
}
|
2004-05-04 20:39:24 +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
|
2003-12-09 03:04:19 +00:00
|
|
|
madt_parse_nmi(MADT_NMI_SOURCE *nmi)
|
2003-11-03 22:17:44 +00:00
|
|
|
{
|
|
|
|
void *ioapic;
|
|
|
|
u_int pin;
|
|
|
|
|
2003-12-09 03:04:19 +00:00
|
|
|
if (madt_find_interrupt(nmi->Interrupt, &ioapic, &pin) != 0) {
|
2003-11-03 22:17:44 +00:00
|
|
|
printf("MADT: Could not find APIC for vector %d\n",
|
2003-12-09 03:04:19 +00:00
|
|
|
nmi->Interrupt);
|
2003-11-03 22:17:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ioapic_set_nmi(ioapic, pin);
|
2003-12-09 03:04:19 +00:00
|
|
|
if (nmi->TriggerMode != TRIGGER_CONFORMS)
|
2003-11-03 22:17:44 +00:00
|
|
|
ioapic_set_triggermode(ioapic, pin,
|
2004-05-04 20:39:24 +00:00
|
|
|
interrupt_trigger(nmi->TriggerMode, 0));
|
2003-12-09 03:04:19 +00:00
|
|
|
if (nmi->Polarity != TRIGGER_CONFORMS)
|
2003-11-03 22:17:44 +00:00
|
|
|
ioapic_set_polarity(ioapic, pin,
|
2004-05-04 20:39:24 +00:00
|
|
|
interrupt_polarity(nmi->Polarity, 0));
|
2003-11-03 22:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse an entry for an NMI routed to a local APIC LVT pin.
|
|
|
|
*/
|
|
|
|
static void
|
2003-12-09 03:04:19 +00:00
|
|
|
madt_parse_local_nmi(MADT_LOCAL_APIC_NMI *nmi)
|
2003-11-03 22:17:44 +00:00
|
|
|
{
|
|
|
|
u_int apic_id, pin;
|
|
|
|
|
2003-12-09 03:04:19 +00:00
|
|
|
if (nmi->ProcessorId == 0xff)
|
2003-11-03 22:17:44 +00:00
|
|
|
apic_id = APIC_ID_ALL;
|
2003-12-09 03:04:19 +00:00
|
|
|
else if (madt_find_cpu(nmi->ProcessorId, &apic_id) != 0) {
|
2003-11-03 22:17:44 +00:00
|
|
|
if (bootverbose)
|
|
|
|
printf("MADT: Ignoring local NMI routed to ACPI CPU %u\n",
|
2003-12-09 03:04:19 +00:00
|
|
|
nmi->ProcessorId);
|
2003-11-03 22:17:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-12-09 03:04:19 +00:00
|
|
|
if (nmi->Lint == 0)
|
2003-11-03 22:17:44 +00:00
|
|
|
pin = LVT_LINT0;
|
|
|
|
else
|
|
|
|
pin = LVT_LINT1;
|
|
|
|
lapic_set_lvt_mode(apic_id, pin, APIC_LVT_DM_NMI);
|
2003-12-09 03:04:19 +00:00
|
|
|
if (nmi->TriggerMode != TRIGGER_CONFORMS)
|
2003-11-03 22:17:44 +00:00
|
|
|
lapic_set_lvt_triggermode(apic_id, pin,
|
2004-05-04 20:39:24 +00:00
|
|
|
interrupt_trigger(nmi->TriggerMode, 0));
|
2003-12-09 03:04:19 +00:00
|
|
|
if (nmi->Polarity != POLARITY_CONFORMS)
|
2003-11-03 22:17:44 +00:00
|
|
|
lapic_set_lvt_polarity(apic_id, pin,
|
2004-05-04 20:39:24 +00:00
|
|
|
interrupt_polarity(nmi->Polarity, 0));
|
2003-11-03 22:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse interrupt entries.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
madt_parse_ints(APIC_HEADER *entry, void *arg __unused)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (entry->Type) {
|
2003-12-09 03:04:19 +00:00
|
|
|
case APIC_XRUPT_OVERRIDE:
|
2003-11-03 22:17:44 +00:00
|
|
|
madt_parse_interrupt_override(
|
2003-12-09 03:04:19 +00:00
|
|
|
(MADT_INTERRUPT_OVERRIDE *)entry);
|
2003-11-03 22:17:44 +00:00
|
|
|
break;
|
|
|
|
case APIC_NMI:
|
2003-12-09 03:04:19 +00:00
|
|
|
madt_parse_nmi((MADT_NMI_SOURCE *)entry);
|
2003-11-03 22:17:44 +00:00
|
|
|
break;
|
2003-12-09 03:04:19 +00:00
|
|
|
case APIC_LOCAL_NMI:
|
|
|
|
madt_parse_local_nmi((MADT_LOCAL_APIC_NMI *)entry);
|
2003-11-03 22:17:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup per-CPU ACPI IDs.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
madt_set_ids(void *dummy)
|
|
|
|
{
|
2004-06-01 19:49:38 +00:00
|
|
|
struct lapic_info *la;
|
2003-11-03 22:17:44 +00:00
|
|
|
struct pcpu *pc;
|
2004-06-01 19:49:38 +00:00
|
|
|
u_int i;
|
2003-11-03 22:17:44 +00:00
|
|
|
|
|
|
|
if (madt == NULL)
|
|
|
|
return;
|
2003-12-03 20:33:18 +00:00
|
|
|
for (i = 0; i <= mp_maxid; i++) {
|
2003-11-03 22:17:44 +00:00
|
|
|
if (CPU_ABSENT(i))
|
|
|
|
continue;
|
|
|
|
pc = pcpu_find(i);
|
|
|
|
KASSERT(pc != NULL, ("no pcpu data for CPU %d", i));
|
2004-06-01 19:49:38 +00:00
|
|
|
la = &lapics[pc->pc_apic_id];
|
2004-06-10 20:03:46 +00:00
|
|
|
if (!la->la_enabled)
|
2004-06-01 19:49:38 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
SYSINIT(madt_set_ids, SI_SUB_CPU, SI_ORDER_ANY, madt_set_ids, NULL)
|