#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.14 2022/12/12 01:07:52 gutteridge Exp $");
#include "acpica.h"
#include <sys/param.h>
#include <sys/device.h>
#include <sys/errno.h>
#include <dev/acpi/acpica.h>
#include <dev/acpi/acpivar.h>
#include <actables.h>
static int mainbus_match(device_t, cfdata_t, void *);
static void mainbus_attach(device_t, device_t, void *);
CFATTACH_DECL_NEW(mainbus, 0, mainbus_match, mainbus_attach, NULL, NULL);
static int
mainbus_match(device_t parent, cfdata_t match, void *aux)
{
return 1;
}
static void
mainbus_attach(device_t parent, device_t self, void *aux)
{
#if NACPICA > 0
struct acpibus_attach_args aaa;
#endif
ACPI_PHYSICAL_ADDRESS rsdp_ptr;
ACPI_MADT_LOCAL_SAPIC *entry;
ACPI_TABLE_MADT *table;
ACPI_TABLE_RSDP *rsdp;
ACPI_TABLE_XSDT *xsdt;
char *end, *p;
int tables, i;
aprint_naive("\n");
aprint_normal("\n");
if ((rsdp_ptr = AcpiOsGetRootPointer()) == 0)
panic("cpu not found");
rsdp = (ACPI_TABLE_RSDP *)IA64_PHYS_TO_RR7(rsdp_ptr);
xsdt = (ACPI_TABLE_XSDT *)IA64_PHYS_TO_RR7(rsdp->XsdtPhysicalAddress);
tables = (UINT64 *)((char *)xsdt + xsdt->Header.Length) -
xsdt->TableOffsetEntry;
for (i = 0; i < tables; i++) {
int len;
char *sig;
table = (ACPI_TABLE_MADT *)
IA64_PHYS_TO_RR7(xsdt->TableOffsetEntry[i]);
sig = table->Header.Signature;
if (strncmp(sig, ACPI_SIG_MADT, ACPI_NAMESEG_SIZE) != 0)
continue;
len = table->Header.Length;
if (ACPI_FAILURE(AcpiUtChecksum((void *)table, len)))
continue;
end = (char *)table + table->Header.Length;
p = (char *)(table + 1);
while (p < end) {
entry = (ACPI_MADT_LOCAL_SAPIC *)p;
if (entry->Header.Type == ACPI_MADT_TYPE_LOCAL_SAPIC)
config_found(self, entry, NULL,
CFARGS(.iattr = "cpubus"));
p += entry->Header.Length;
}
}
#if NACPICA > 0
acpi_probe();
aaa.aa_iot = IA64_BUS_SPACE_IO;
aaa.aa_memt = IA64_BUS_SPACE_MEM;
aaa.aa_pc = 0;
aaa.aa_pciflags =
PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY |
PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY |
PCI_FLAGS_MWI_OKAY;
aaa.aa_ic = 0;
aaa.aa_dmat = NULL;
aaa.aa_dmat64 = NULL;
config_found(self, &aaa, NULL,
CFARGS(.iattr = "acpibus"));
#endif
return;
}