Home | History | Annotate | Line # | Download | only in ia64
      1 /*	$NetBSD: mainbus.c,v 1.14 2022/12/12 01:07:52 gutteridge Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2006 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * Author:
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28  * POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #include <sys/cdefs.h>
     32 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.14 2022/12/12 01:07:52 gutteridge Exp $");
     33 
     34 #include "acpica.h"
     35 
     36 #include <sys/param.h>
     37 #include <sys/device.h>
     38 #include <sys/errno.h>
     39 
     40 #include <dev/acpi/acpica.h>
     41 #include <dev/acpi/acpivar.h>
     42 #include <actables.h>
     43 
     44 
     45 static int mainbus_match(device_t, cfdata_t, void *);
     46 static void mainbus_attach(device_t, device_t, void *);
     47 
     48 CFATTACH_DECL_NEW(mainbus, 0, mainbus_match, mainbus_attach, NULL, NULL);
     49 
     50 
     51 /*
     52  * Probe for the mainbus; always succeeds.
     53  */
     54 static int
     55 mainbus_match(device_t parent, cfdata_t match, void *aux)
     56 {
     57 
     58 	return 1;
     59 }
     60 
     61 /*
     62  * Attach the mainbus.
     63  */
     64 static void
     65 mainbus_attach(device_t parent, device_t self, void *aux)
     66 {
     67 #if NACPICA > 0
     68 	struct acpibus_attach_args aaa;
     69 #endif
     70 	ACPI_PHYSICAL_ADDRESS rsdp_ptr;
     71 	ACPI_MADT_LOCAL_SAPIC *entry;
     72 	ACPI_TABLE_MADT *table;
     73 	ACPI_TABLE_RSDP *rsdp;
     74 	ACPI_TABLE_XSDT *xsdt;
     75 	char *end, *p;
     76 	int tables, i;
     77 
     78 	aprint_naive("\n");
     79 	aprint_normal("\n");
     80 
     81 	if ((rsdp_ptr = AcpiOsGetRootPointer()) == 0)
     82 		panic("cpu not found");
     83 
     84 	rsdp = (ACPI_TABLE_RSDP *)IA64_PHYS_TO_RR7(rsdp_ptr);
     85 	xsdt = (ACPI_TABLE_XSDT *)IA64_PHYS_TO_RR7(rsdp->XsdtPhysicalAddress);
     86 
     87 	tables = (UINT64 *)((char *)xsdt + xsdt->Header.Length) -
     88 	    xsdt->TableOffsetEntry;
     89 
     90 	for (i = 0; i < tables; i++) {
     91 		int len;
     92 		char *sig;
     93 
     94 		table = (ACPI_TABLE_MADT *)
     95 		    IA64_PHYS_TO_RR7(xsdt->TableOffsetEntry[i]);
     96 
     97 		sig = table->Header.Signature;
     98 		if (strncmp(sig, ACPI_SIG_MADT, ACPI_NAMESEG_SIZE) != 0)
     99 			continue;
    100 		len = table->Header.Length;
    101 		if (ACPI_FAILURE(AcpiUtChecksum((void *)table, len)))
    102 			continue;
    103 
    104 		end = (char *)table + table->Header.Length;
    105 		p = (char *)(table + 1);
    106 		while (p < end) {
    107 			entry = (ACPI_MADT_LOCAL_SAPIC *)p;
    108 
    109 			if (entry->Header.Type == ACPI_MADT_TYPE_LOCAL_SAPIC)
    110 				config_found(self, entry, NULL,
    111 				    CFARGS(.iattr = "cpubus"));
    112 
    113 			p += entry->Header.Length;
    114 		}
    115 	}
    116 
    117 #if NACPICA > 0
    118 	acpi_probe();
    119 
    120 	aaa.aa_iot = IA64_BUS_SPACE_IO;
    121 	aaa.aa_memt = IA64_BUS_SPACE_MEM;
    122 	aaa.aa_pc = 0;
    123 	aaa.aa_pciflags =
    124 	    PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY |
    125 	    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY |
    126 	    PCI_FLAGS_MWI_OKAY;
    127 	aaa.aa_ic = 0;
    128 	aaa.aa_dmat = NULL;	/* XXX */
    129 	aaa.aa_dmat64 = NULL;	/* XXX */
    130 	config_found(self, &aaa, NULL,
    131 	    CFARGS(.iattr = "acpibus"));
    132 #endif
    133 
    134 	return;
    135 }
    136