2001-10-04 08:45:19 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2001 Doug Rabson
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
2005-09-11 18:39:03 +00:00
|
|
|
#include <contrib/dev/acpica/acpi.h>
|
2004-05-01 04:08:14 +00:00
|
|
|
#include <contrib/dev/acpica/actables.h>
|
2001-10-04 08:45:19 +00:00
|
|
|
|
2003-08-16 16:57:57 +00:00
|
|
|
#include <machine/md_var.h>
|
2002-05-19 04:42:19 +00:00
|
|
|
|
2003-01-05 22:14:30 +00:00
|
|
|
extern u_int64_t ia64_lapic_address;
|
|
|
|
|
2001-10-29 02:16:02 +00:00
|
|
|
struct sapic *sapic_create(int, int, u_int64_t);
|
|
|
|
|
2001-10-04 08:45:19 +00:00
|
|
|
static void
|
2007-03-22 18:16:43 +00:00
|
|
|
print_entry(ACPI_SUBTABLE_HEADER *entry)
|
2001-10-04 08:45:19 +00:00
|
|
|
{
|
|
|
|
|
2003-09-07 23:09:08 +00:00
|
|
|
switch (entry->Type) {
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE: {
|
|
|
|
ACPI_MADT_INTERRUPT_OVERRIDE *iso =
|
|
|
|
(ACPI_MADT_INTERRUPT_OVERRIDE *)entry;
|
2003-09-07 23:09:08 +00:00
|
|
|
printf("\tInterrupt source override entry\n");
|
2007-03-22 18:16:43 +00:00
|
|
|
printf("\t\tBus=%u, Source=%u, Irq=0x%x\n", iso->Bus,
|
|
|
|
iso->SourceIrq, iso->GlobalIrq);
|
2003-09-07 23:09:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TYPE_IO_APIC:
|
2003-09-07 23:09:08 +00:00
|
|
|
printf("\tI/O APIC entry\n");
|
|
|
|
break;
|
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TYPE_IO_SAPIC: {
|
|
|
|
ACPI_MADT_IO_SAPIC *sapic = (ACPI_MADT_IO_SAPIC *)entry;
|
2003-09-07 23:09:08 +00:00
|
|
|
printf("\tI/O SAPIC entry\n");
|
2003-12-09 03:04:19 +00:00
|
|
|
printf("\t\tId=0x%x, InterruptBase=0x%x, Address=0x%lx\n",
|
2007-03-22 18:16:43 +00:00
|
|
|
sapic->Id, sapic->GlobalIrqBase, sapic->Address);
|
2003-09-07 23:09:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-10-04 08:45:19 +00:00
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TYPE_LOCAL_APIC_NMI:
|
2003-09-07 23:09:08 +00:00
|
|
|
printf("\tLocal APIC NMI entry\n");
|
|
|
|
break;
|
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE: {
|
|
|
|
ACPI_MADT_LOCAL_APIC_OVERRIDE *lapic =
|
|
|
|
(ACPI_MADT_LOCAL_APIC_OVERRIDE *)entry;
|
2003-09-07 23:09:08 +00:00
|
|
|
printf("\tLocal APIC override entry\n");
|
2003-12-09 03:04:19 +00:00
|
|
|
printf("\t\tLocal APIC address=0x%jx\n", lapic->Address);
|
2003-09-07 23:09:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TYPE_LOCAL_SAPIC: {
|
|
|
|
ACPI_MADT_LOCAL_SAPIC *sapic = (ACPI_MADT_LOCAL_SAPIC *)entry;
|
2003-09-07 23:09:08 +00:00
|
|
|
printf("\tLocal SAPIC entry\n");
|
2001-10-24 04:48:05 +00:00
|
|
|
printf("\t\tProcessorId=0x%x, Id=0x%x, Eid=0x%x",
|
2007-03-22 18:16:43 +00:00
|
|
|
sapic->ProcessorId, sapic->Id, sapic->Eid);
|
|
|
|
if (!(sapic->LapicFlags & ACPI_MADT_ENABLED))
|
2001-10-24 04:48:05 +00:00
|
|
|
printf(" (disabled)");
|
|
|
|
printf("\n");
|
2003-09-07 23:09:08 +00:00
|
|
|
break;
|
2001-10-24 04:48:05 +00:00
|
|
|
}
|
2001-10-04 08:45:19 +00:00
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TYPE_NMI_SOURCE:
|
2003-09-07 23:09:08 +00:00
|
|
|
printf("\tNMI entry\n");
|
|
|
|
break;
|
2003-01-05 22:14:30 +00:00
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TYPE_INTERRUPT_SOURCE: {
|
|
|
|
ACPI_MADT_INTERRUPT_SOURCE *pis =
|
|
|
|
(ACPI_MADT_INTERRUPT_SOURCE *)entry;
|
2003-09-07 23:09:08 +00:00
|
|
|
printf("\tPlatform interrupt entry\n");
|
2007-03-22 18:16:43 +00:00
|
|
|
printf("\t\tPolarity=%u, TriggerMode=%u, Id=0x%x, "
|
2003-09-07 23:09:08 +00:00
|
|
|
"Eid=0x%x, Vector=0x%x, Irq=%d\n",
|
2007-03-22 18:16:43 +00:00
|
|
|
pis->IntiFlags & ACPI_MADT_POLARITY_MASK,
|
|
|
|
(pis->IntiFlags & ACPI_MADT_TRIGGER_MASK) >> 2,
|
|
|
|
pis->Id, pis->Eid, pis->IoSapicVector, pis->GlobalIrq);
|
2003-09-07 23:09:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TYPE_LOCAL_APIC:
|
2003-09-07 23:09:08 +00:00
|
|
|
printf("\tLocal APIC entry\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("\tUnknown type %d entry\n", entry->Type);
|
|
|
|
break;
|
|
|
|
}
|
2001-10-04 08:45:19 +00:00
|
|
|
}
|
|
|
|
|
2003-09-07 23:09:08 +00:00
|
|
|
void
|
|
|
|
ia64_probe_sapics(void)
|
2001-10-04 08:45:19 +00:00
|
|
|
{
|
2007-03-22 18:16:43 +00:00
|
|
|
ACPI_PHYSICAL_ADDRESS rsdp_ptr;
|
|
|
|
ACPI_SUBTABLE_HEADER *entry;
|
|
|
|
ACPI_TABLE_MADT *table;
|
|
|
|
ACPI_TABLE_RSDP *rsdp;
|
|
|
|
ACPI_TABLE_XSDT *xsdt;
|
2002-05-12 05:54:21 +00:00
|
|
|
char *end, *p;
|
2003-09-07 23:09:08 +00:00
|
|
|
int t, tables;
|
2001-10-04 08:45:19 +00:00
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
if ((rsdp_ptr = AcpiOsGetRootPointer()) == 0)
|
2003-09-07 23:09:08 +00:00
|
|
|
return;
|
2002-03-15 09:47:16 +00:00
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
rsdp = (ACPI_TABLE_RSDP *)IA64_PHYS_TO_RR7(rsdp_ptr);
|
|
|
|
xsdt = (ACPI_TABLE_XSDT *)IA64_PHYS_TO_RR7(rsdp->XsdtPhysicalAddress);
|
2002-05-12 05:54:21 +00:00
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
tables = (UINT64 *)((char *)xsdt + xsdt->Header.Length) -
|
2003-09-07 23:09:08 +00:00
|
|
|
xsdt->TableOffsetEntry;
|
2003-01-05 22:14:30 +00:00
|
|
|
|
2003-09-07 23:09:08 +00:00
|
|
|
for (t = 0; t < tables; t++) {
|
2007-03-22 18:16:43 +00:00
|
|
|
table = (ACPI_TABLE_MADT *)
|
2003-09-07 23:09:08 +00:00
|
|
|
IA64_PHYS_TO_RR7(xsdt->TableOffsetEntry[t]);
|
2002-05-12 05:54:21 +00:00
|
|
|
|
2001-10-05 10:30:09 +00:00
|
|
|
if (bootverbose)
|
2003-09-07 23:09:08 +00:00
|
|
|
printf("Table '%c%c%c%c' at %p\n",
|
2007-03-22 18:16:43 +00:00
|
|
|
table->Header.Signature[0],
|
|
|
|
table->Header.Signature[1],
|
|
|
|
table->Header.Signature[2],
|
|
|
|
table->Header.Signature[3], table);
|
|
|
|
|
|
|
|
if (strncmp(table->Header.Signature, ACPI_SIG_MADT,
|
|
|
|
ACPI_NAME_SIZE) != 0 ||
|
|
|
|
ACPI_FAILURE(AcpiTbChecksum((void *)table,
|
|
|
|
table->Header.Length)))
|
2003-09-07 23:09:08 +00:00
|
|
|
continue;
|
2001-10-04 08:45:19 +00:00
|
|
|
|
2003-09-07 23:09:08 +00:00
|
|
|
/* Save the address of the processor interrupt block. */
|
|
|
|
if (bootverbose)
|
2007-03-22 18:16:43 +00:00
|
|
|
printf("\tLocal APIC address=0x%x\n", table->Address);
|
|
|
|
ia64_lapic_address = table->Address;
|
2001-10-04 08:45:19 +00:00
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
end = (char *)table + table->Header.Length;
|
2003-09-07 23:09:08 +00:00
|
|
|
p = (char *)(table + 1);
|
|
|
|
while (p < end) {
|
2007-03-22 18:16:43 +00:00
|
|
|
entry = (ACPI_SUBTABLE_HEADER *)p;
|
2001-10-29 02:16:02 +00:00
|
|
|
|
2001-10-04 08:45:19 +00:00
|
|
|
if (bootverbose)
|
2003-09-07 23:09:08 +00:00
|
|
|
print_entry(entry);
|
|
|
|
|
|
|
|
switch (entry->Type) {
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TYPE_IO_SAPIC: {
|
|
|
|
ACPI_MADT_IO_SAPIC *sapic =
|
|
|
|
(ACPI_MADT_IO_SAPIC *)entry;
|
|
|
|
sapic_create(sapic->Id, sapic->GlobalIrqBase,
|
|
|
|
sapic->Address);
|
2003-09-07 23:09:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-10-04 08:45:19 +00:00
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE: {
|
|
|
|
ACPI_MADT_LOCAL_APIC_OVERRIDE *lapic =
|
|
|
|
(ACPI_MADT_LOCAL_APIC_OVERRIDE *)entry;
|
2003-12-09 03:04:19 +00:00
|
|
|
ia64_lapic_address = lapic->Address;
|
2003-09-07 23:09:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-10-04 08:45:19 +00:00
|
|
|
|
2003-09-07 23:09:08 +00:00
|
|
|
#ifdef SMP
|
2007-03-22 18:16:43 +00:00
|
|
|
case ACPI_MADT_TYPE_LOCAL_SAPIC: {
|
|
|
|
ACPI_MADT_LOCAL_SAPIC *sapic =
|
|
|
|
(ACPI_MADT_LOCAL_SAPIC *)entry;
|
|
|
|
if (sapic->LapicFlags & ACPI_MADT_ENABLED)
|
2003-09-07 23:09:08 +00:00
|
|
|
cpu_mp_add(sapic->ProcessorId,
|
2007-03-22 18:16:43 +00:00
|
|
|
sapic->Id, sapic->Eid);
|
2003-09-07 23:09:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2001-10-04 08:45:19 +00:00
|
|
|
|
2003-09-07 23:09:08 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2001-10-04 08:45:19 +00:00
|
|
|
|
2003-09-07 23:09:08 +00:00
|
|
|
p += entry->Length;
|
2001-10-04 08:45:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-07 23:09:08 +00:00
|
|
|
/*
|
|
|
|
* Count the number of local SAPIC entries in the APIC table. Every enabled
|
|
|
|
* entry corresponds to a processor.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ia64_count_cpus(void)
|
2001-10-04 08:45:19 +00:00
|
|
|
{
|
2007-03-22 18:16:43 +00:00
|
|
|
ACPI_PHYSICAL_ADDRESS rsdp_ptr;
|
|
|
|
ACPI_MADT_LOCAL_SAPIC *entry;
|
|
|
|
ACPI_TABLE_MADT *table;
|
|
|
|
ACPI_TABLE_RSDP *rsdp;
|
|
|
|
ACPI_TABLE_XSDT *xsdt;
|
2003-09-07 23:09:08 +00:00
|
|
|
char *end, *p;
|
|
|
|
int cpus, t, tables;
|
2001-10-04 08:45:19 +00:00
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
if ((rsdp_ptr = AcpiOsGetRootPointer()) == 0)
|
2003-09-07 23:09:08 +00:00
|
|
|
return (0);
|
2001-10-29 02:16:02 +00:00
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
rsdp = (ACPI_TABLE_RSDP *)IA64_PHYS_TO_RR7(rsdp_ptr);
|
|
|
|
xsdt = (ACPI_TABLE_XSDT *)IA64_PHYS_TO_RR7(rsdp->XsdtPhysicalAddress);
|
2001-10-29 02:16:02 +00:00
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
tables = (UINT64 *)((char *)xsdt + xsdt->Header.Length) -
|
2003-09-07 23:09:08 +00:00
|
|
|
xsdt->TableOffsetEntry;
|
2001-10-29 02:16:02 +00:00
|
|
|
|
2003-09-07 23:09:08 +00:00
|
|
|
cpus = 0;
|
2001-10-29 02:16:02 +00:00
|
|
|
|
2003-09-07 23:09:08 +00:00
|
|
|
for (t = 0; t < tables; t++) {
|
2007-03-22 18:16:43 +00:00
|
|
|
table = (ACPI_TABLE_MADT *)
|
2003-09-07 23:09:08 +00:00
|
|
|
IA64_PHYS_TO_RR7(xsdt->TableOffsetEntry[t]);
|
2002-03-15 09:47:16 +00:00
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
if (strncmp(table->Header.Signature, ACPI_SIG_MADT,
|
|
|
|
ACPI_NAME_SIZE) != 0 ||
|
|
|
|
ACPI_FAILURE(AcpiTbChecksum((void *)table,
|
|
|
|
table->Header.Length)))
|
2003-09-07 23:09:08 +00:00
|
|
|
continue;
|
2002-03-15 09:47:16 +00:00
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
end = (char *)table + table->Header.Length;
|
2003-09-07 23:09:08 +00:00
|
|
|
p = (char *)(table + 1);
|
|
|
|
while (p < end) {
|
2007-03-22 18:16:43 +00:00
|
|
|
entry = (ACPI_MADT_LOCAL_SAPIC *)p;
|
2003-09-07 23:09:08 +00:00
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
if (entry->Header.Type == ACPI_MADT_TYPE_LOCAL_SAPIC &&
|
|
|
|
(entry->LapicFlags & ACPI_MADT_ENABLED))
|
2003-09-07 23:09:08 +00:00
|
|
|
cpus++;
|
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
p += entry->Header.Length;
|
2003-09-07 23:09:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (cpus);
|
2001-10-04 08:45:19 +00:00
|
|
|
}
|