Home | History | Annotate | Line # | Download | only in acpi
acpi_platform.c revision 1.17
      1  1.17  jmcneill /* $NetBSD: acpi_platform.c,v 1.17 2019/08/19 10:53:31 jmcneill Exp $ */
      2   1.1  jmcneill 
      3   1.1  jmcneill /*-
      4   1.1  jmcneill  * Copyright (c) 2018 The NetBSD Foundation, Inc.
      5   1.1  jmcneill  * All rights reserved.
      6   1.1  jmcneill  *
      7   1.1  jmcneill  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1  jmcneill  * by Jared McNeill <jmcneill (at) invisible.ca>.
      9   1.1  jmcneill  *
     10   1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
     11   1.1  jmcneill  * modification, are permitted provided that the following conditions
     12   1.1  jmcneill  * are met:
     13   1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     14   1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     15   1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     17   1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     18   1.1  jmcneill  *
     19   1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1  jmcneill  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1  jmcneill  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1  jmcneill  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1  jmcneill  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1  jmcneill  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1  jmcneill  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1  jmcneill  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1  jmcneill  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1  jmcneill  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1  jmcneill  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1  jmcneill  */
     31   1.1  jmcneill 
     32   1.4  jmcneill #include "com.h"
     33   1.4  jmcneill #include "plcom.h"
     34  1.15  jmcneill #include "wsdisplay.h"
     35  1.15  jmcneill #include "genfb.h"
     36   1.5  jmcneill #include "opt_efi.h"
     37  1.12       ryo #include "opt_multiprocessor.h"
     38   1.4  jmcneill 
     39   1.1  jmcneill #include <sys/cdefs.h>
     40  1.17  jmcneill __KERNEL_RCSID(0, "$NetBSD: acpi_platform.c,v 1.17 2019/08/19 10:53:31 jmcneill Exp $");
     41   1.1  jmcneill 
     42   1.1  jmcneill #include <sys/param.h>
     43   1.1  jmcneill #include <sys/bus.h>
     44   1.1  jmcneill #include <sys/cpu.h>
     45   1.1  jmcneill #include <sys/device.h>
     46   1.1  jmcneill #include <sys/termios.h>
     47   1.1  jmcneill 
     48   1.1  jmcneill #include <dev/fdt/fdtvar.h>
     49   1.1  jmcneill #include <arm/fdt/arm_fdtvar.h>
     50   1.1  jmcneill 
     51   1.1  jmcneill #include <uvm/uvm_extern.h>
     52   1.1  jmcneill 
     53   1.1  jmcneill #include <machine/bootconfig.h>
     54   1.1  jmcneill #include <arm/cpufunc.h>
     55   1.1  jmcneill #include <arm/locore.h>
     56   1.1  jmcneill 
     57   1.1  jmcneill #include <arm/cortex/gtmr_var.h>
     58   1.1  jmcneill 
     59   1.1  jmcneill #include <arm/arm/psci.h>
     60   1.1  jmcneill #include <arm/fdt/psci_fdtvar.h>
     61   1.1  jmcneill 
     62   1.1  jmcneill #include <evbarm/fdt/platform.h>
     63   1.1  jmcneill 
     64   1.1  jmcneill #include <evbarm/dev/plcomreg.h>
     65   1.1  jmcneill #include <evbarm/dev/plcomvar.h>
     66   1.1  jmcneill #include <dev/ic/ns16550reg.h>
     67   1.1  jmcneill #include <dev/ic/comreg.h>
     68   1.4  jmcneill #include <dev/ic/comvar.h>
     69   1.1  jmcneill 
     70  1.10  jmcneill #if NCOM > 0
     71  1.10  jmcneill #include <dev/pci/pcireg.h>
     72  1.10  jmcneill #include <dev/pci/pcivar.h>
     73  1.10  jmcneill #include <dev/pci/pucvar.h>
     74  1.10  jmcneill #endif
     75  1.10  jmcneill 
     76  1.15  jmcneill #if NWSDISPLAY > 0
     77  1.15  jmcneill #include <dev/wscons/wsconsio.h>
     78  1.15  jmcneill #include <dev/wscons/wsdisplayvar.h>
     79  1.15  jmcneill #include <dev/rasops/rasops.h>
     80  1.15  jmcneill #include <dev/wsfont/wsfont.h>
     81  1.15  jmcneill #include <dev/wscons/wsdisplay_vconsvar.h>
     82  1.15  jmcneill #endif
     83  1.15  jmcneill 
     84   1.5  jmcneill #ifdef EFI_RUNTIME
     85   1.5  jmcneill #include <arm/arm/efi_runtime.h>
     86   1.5  jmcneill #endif
     87   1.5  jmcneill 
     88   1.1  jmcneill #include <dev/acpi/acpireg.h>
     89   1.1  jmcneill #include <dev/acpi/acpivar.h>
     90   1.5  jmcneill #include <arm/acpi/acpi_table.h>
     91   1.5  jmcneill 
     92   1.5  jmcneill #include <libfdt.h>
     93   1.1  jmcneill 
     94   1.3  jmcneill #define	SPCR_BAUD_UNKNOWN			0
     95   1.3  jmcneill #define	SPCR_BAUD_9600				3
     96   1.3  jmcneill #define	SPCR_BAUD_19200				4
     97   1.3  jmcneill #define	SPCR_BAUD_57600				6
     98   1.3  jmcneill #define	SPCR_BAUD_115200			7
     99   1.1  jmcneill 
    100   1.1  jmcneill extern struct bus_space arm_generic_bs_tag;
    101   1.4  jmcneill extern struct bus_space arm_generic_a4x_bs_tag;
    102   1.1  jmcneill 
    103   1.7       rjs #if NPLCOM > 0
    104   1.1  jmcneill static struct plcom_instance plcom_console;
    105   1.7       rjs #endif
    106   1.1  jmcneill 
    107  1.14  jmcneill struct arm32_bus_dma_tag acpi_coherent_dma_tag;
    108  1.14  jmcneill static struct arm32_dma_range acpi_coherent_ranges[] = {
    109  1.13  jmcneill 	[0] = {
    110  1.13  jmcneill 		.dr_sysbase = 0,
    111  1.13  jmcneill 		.dr_busbase = 0,
    112  1.13  jmcneill 		.dr_len = UINTPTR_MAX,
    113  1.13  jmcneill 	 	.dr_flags = _BUS_DMAMAP_COHERENT,
    114  1.13  jmcneill 	}
    115  1.13  jmcneill };
    116  1.13  jmcneill 
    117   1.1  jmcneill static const struct pmap_devmap *
    118   1.1  jmcneill acpi_platform_devmap(void)
    119   1.1  jmcneill {
    120   1.1  jmcneill 	static const struct pmap_devmap devmap[] = {
    121   1.1  jmcneill 		DEVMAP_ENTRY_END
    122   1.1  jmcneill 	};
    123   1.1  jmcneill 
    124   1.1  jmcneill 	return devmap;
    125   1.1  jmcneill }
    126   1.1  jmcneill 
    127   1.1  jmcneill static void
    128   1.1  jmcneill acpi_platform_bootstrap(void)
    129   1.1  jmcneill {
    130  1.13  jmcneill 	extern struct arm32_bus_dma_tag arm_generic_dma_tag;
    131  1.13  jmcneill 
    132  1.14  jmcneill 	acpi_coherent_dma_tag = arm_generic_dma_tag;
    133  1.14  jmcneill 	acpi_coherent_dma_tag._ranges = acpi_coherent_ranges;
    134  1.14  jmcneill 	acpi_coherent_dma_tag._nranges = __arraycount(acpi_coherent_ranges);
    135   1.1  jmcneill }
    136   1.1  jmcneill 
    137  1.15  jmcneill #if NWSDISPLAY > 0 && NGENFB > 0
    138  1.15  jmcneill static struct wsscreen_descr acpi_platform_stdscreen = {
    139  1.15  jmcneill 	.name = "std",
    140  1.15  jmcneill 	.ncols = 0,
    141  1.15  jmcneill 	.nrows = 0,
    142  1.15  jmcneill 	.textops = NULL,
    143  1.15  jmcneill 	.fontwidth = 0,
    144  1.15  jmcneill 	.fontheight = 0,
    145  1.15  jmcneill 	.capabilities = 0,
    146  1.15  jmcneill 	.modecookie = NULL
    147  1.15  jmcneill };
    148  1.15  jmcneill 
    149  1.15  jmcneill static struct vcons_screen acpi_platform_screen;
    150  1.15  jmcneill 
    151  1.15  jmcneill static int
    152  1.15  jmcneill acpi_platform_find_simplefb(void)
    153  1.15  jmcneill {
    154  1.15  jmcneill 	static const char * simplefb_compatible[] = { "simple-framebuffer", NULL };
    155  1.15  jmcneill 	int chosen_phandle, child;
    156  1.15  jmcneill 
    157  1.15  jmcneill 	chosen_phandle = OF_finddevice("/chosen");
    158  1.15  jmcneill 	if (chosen_phandle == -1)
    159  1.15  jmcneill 		return -1;
    160  1.15  jmcneill 
    161  1.15  jmcneill 	for (child = OF_child(chosen_phandle); child; child = OF_peer(child)) {
    162  1.15  jmcneill 		if (!fdtbus_status_okay(child))
    163  1.15  jmcneill 			continue;
    164  1.15  jmcneill 		if (!of_match_compatible(child, simplefb_compatible))
    165  1.15  jmcneill 			continue;
    166  1.15  jmcneill 
    167  1.15  jmcneill 		return child;
    168  1.15  jmcneill 	}
    169  1.15  jmcneill 
    170  1.15  jmcneill 	return -1;
    171  1.15  jmcneill }
    172  1.15  jmcneill 
    173  1.15  jmcneill static void
    174  1.15  jmcneill acpi_platform_wsdisplay_preattach(void)
    175  1.15  jmcneill {
    176  1.15  jmcneill 	struct rasops_info *ri = &acpi_platform_screen.scr_ri;
    177  1.15  jmcneill 	bus_space_tag_t bst = &arm_generic_bs_tag;
    178  1.15  jmcneill 	bus_space_handle_t bsh;
    179  1.15  jmcneill 	uint32_t width, height, stride;
    180  1.15  jmcneill 	const char *format;
    181  1.15  jmcneill 	bus_addr_t addr;
    182  1.15  jmcneill 	bus_size_t size;
    183  1.15  jmcneill 	uint16_t depth;
    184  1.15  jmcneill 	long defattr;
    185  1.15  jmcneill 
    186  1.15  jmcneill 	memset(&acpi_platform_screen, 0, sizeof(acpi_platform_screen));
    187  1.15  jmcneill 
    188  1.15  jmcneill 	const int phandle = acpi_platform_find_simplefb();
    189  1.15  jmcneill 	if (phandle == -1)
    190  1.15  jmcneill 		return;
    191  1.15  jmcneill 
    192  1.15  jmcneill 	if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0 || size == 0)
    193  1.15  jmcneill 		return;
    194  1.15  jmcneill 
    195  1.15  jmcneill 	if (of_getprop_uint32(phandle, "width", &width) != 0 ||
    196  1.15  jmcneill 	    of_getprop_uint32(phandle, "height", &height) != 0 ||
    197  1.15  jmcneill 	    of_getprop_uint32(phandle, "stride", &stride) != 0 ||
    198  1.15  jmcneill 	    (format = fdtbus_get_string(phandle, "format")) == NULL)
    199  1.15  jmcneill 		return;
    200  1.15  jmcneill 
    201  1.15  jmcneill 	if (strcmp(format, "a8b8g8r8") == 0 ||
    202  1.15  jmcneill 	    strcmp(format, "x8r8g8b8") == 0) {
    203  1.15  jmcneill 		depth = 32;
    204  1.15  jmcneill 	} else if (strcmp(format, "r5g6b5") == 0) {
    205  1.15  jmcneill 		depth = 16;
    206  1.15  jmcneill 	} else {
    207  1.15  jmcneill 		return;
    208  1.15  jmcneill 	}
    209  1.15  jmcneill 
    210  1.15  jmcneill 	if (bus_space_map(bst, addr, size,
    211  1.15  jmcneill 	    BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE, &bsh) != 0)
    212  1.15  jmcneill 		return;
    213  1.15  jmcneill 
    214  1.15  jmcneill 	wsfont_init();
    215  1.15  jmcneill 
    216  1.15  jmcneill 	ri->ri_width = width;
    217  1.15  jmcneill 	ri->ri_height = height;
    218  1.15  jmcneill 	ri->ri_depth = depth;
    219  1.15  jmcneill 	ri->ri_stride = stride;
    220  1.15  jmcneill 	ri->ri_bits = bus_space_vaddr(bst, bsh);
    221  1.15  jmcneill 	ri->ri_flg = RI_CENTER | RI_FULLCLEAR | RI_CLEAR;
    222  1.15  jmcneill 	rasops_init(ri, ri->ri_height / 8, ri->ri_width / 8);
    223  1.15  jmcneill 	ri->ri_caps = WSSCREEN_WSCOLORS;
    224  1.15  jmcneill 	rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight,
    225  1.15  jmcneill 	    ri->ri_width / ri->ri_font->fontwidth);
    226  1.15  jmcneill 
    227  1.15  jmcneill 	acpi_platform_stdscreen.nrows = ri->ri_rows;
    228  1.15  jmcneill 	acpi_platform_stdscreen.ncols = ri->ri_cols;
    229  1.15  jmcneill 	acpi_platform_stdscreen.textops = &ri->ri_ops;
    230  1.15  jmcneill 	acpi_platform_stdscreen.capabilities = ri->ri_caps;
    231  1.15  jmcneill 
    232  1.15  jmcneill 	ri->ri_ops.allocattr(ri, 0, 0, 0, &defattr);
    233  1.15  jmcneill 
    234  1.15  jmcneill 	wsdisplay_preattach(&acpi_platform_stdscreen, ri, 0, 0, defattr);
    235  1.15  jmcneill }
    236  1.15  jmcneill #endif
    237  1.15  jmcneill 
    238   1.1  jmcneill static void
    239   1.1  jmcneill acpi_platform_startup(void)
    240   1.1  jmcneill {
    241   1.1  jmcneill 	ACPI_TABLE_SPCR *spcr;
    242   1.1  jmcneill 	ACPI_TABLE_FADT *fadt;
    243  1.12       ryo #ifdef MULTIPROCESSOR
    244   1.1  jmcneill 	ACPI_TABLE_MADT *madt;
    245  1.12       ryo #endif
    246   1.3  jmcneill 	int baud_rate;
    247   1.1  jmcneill 
    248   1.1  jmcneill 	/*
    249   1.1  jmcneill 	 * Setup serial console device
    250   1.1  jmcneill 	 */
    251   1.1  jmcneill 	if (ACPI_SUCCESS(acpi_table_find(ACPI_SIG_SPCR, (void **)&spcr))) {
    252   1.4  jmcneill 
    253   1.4  jmcneill 		switch (spcr->BaudRate) {
    254   1.4  jmcneill 		case SPCR_BAUD_9600:
    255   1.4  jmcneill 			baud_rate = 9600;
    256   1.4  jmcneill 			break;
    257   1.4  jmcneill 		case SPCR_BAUD_19200:
    258   1.4  jmcneill 			baud_rate = 19200;
    259   1.4  jmcneill 			break;
    260   1.4  jmcneill 		case SPCR_BAUD_57600:
    261   1.4  jmcneill 			baud_rate = 57600;
    262   1.4  jmcneill 			break;
    263   1.4  jmcneill 		case SPCR_BAUD_115200:
    264   1.4  jmcneill 		case SPCR_BAUD_UNKNOWN:
    265   1.4  jmcneill 		default:
    266   1.4  jmcneill 			baud_rate = 115200;
    267   1.4  jmcneill 			break;
    268   1.4  jmcneill 		}
    269   1.4  jmcneill 
    270   1.3  jmcneill 		if (spcr->SerialPort.SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY &&
    271   1.1  jmcneill 		    spcr->SerialPort.Address != 0) {
    272   1.3  jmcneill 			switch (spcr->InterfaceType) {
    273   1.4  jmcneill #if NPLCOM > 0
    274   1.9  jmcneill 			case ACPI_DBG2_ARM_PL011:
    275   1.9  jmcneill 			case ACPI_DBG2_ARM_SBSA_32BIT:
    276   1.9  jmcneill 			case ACPI_DBG2_ARM_SBSA_GENERIC:
    277   1.3  jmcneill 				plcom_console.pi_type = PLCOM_TYPE_PL011;
    278   1.3  jmcneill 				plcom_console.pi_iot = &arm_generic_bs_tag;
    279   1.3  jmcneill 				plcom_console.pi_iobase = spcr->SerialPort.Address;
    280   1.3  jmcneill 				plcom_console.pi_size = PL011COM_UART_SIZE;
    281  1.16  jmcneill 				plcom_console.pi_flags = PLC_FLAG_32BIT_ACCESS;
    282   1.1  jmcneill 
    283   1.3  jmcneill 				plcomcnattach(&plcom_console, baud_rate, 0, TTYDEF_CFLAG, -1);
    284   1.3  jmcneill 				break;
    285   1.4  jmcneill #endif
    286   1.4  jmcneill #if NCOM > 0
    287   1.9  jmcneill 			case ACPI_DBG2_16550_COMPATIBLE:
    288   1.9  jmcneill 			case ACPI_DBG2_16550_SUBSET:
    289   1.8  jmcneill 				if (ACPI_ACCESS_BIT_WIDTH(spcr->SerialPort.AccessWidth) == 8) {
    290   1.8  jmcneill 					comcnattach(&arm_generic_bs_tag, spcr->SerialPort.Address, baud_rate, -1,
    291   1.8  jmcneill 					    COM_TYPE_NORMAL, TTYDEF_CFLAG);
    292   1.8  jmcneill 				} else {
    293   1.8  jmcneill 					comcnattach(&arm_generic_a4x_bs_tag, spcr->SerialPort.Address, baud_rate, -1,
    294   1.8  jmcneill 					    COM_TYPE_NORMAL, TTYDEF_CFLAG);
    295   1.8  jmcneill 				}
    296   1.8  jmcneill 				break;
    297   1.9  jmcneill 			case ACPI_DBG2_BCM2835:
    298   1.4  jmcneill 				comcnattach(&arm_generic_a4x_bs_tag, spcr->SerialPort.Address + 0x40, baud_rate, -1,
    299   1.4  jmcneill 				    COM_TYPE_BCMAUXUART, TTYDEF_CFLAG);
    300   1.4  jmcneill 				cn_set_magic("+++++");
    301   1.4  jmcneill 				break;
    302   1.4  jmcneill #endif
    303   1.4  jmcneill 			default:
    304   1.4  jmcneill 				printf("SPCR: kernel does not support interface type %#x\n", spcr->InterfaceType);
    305   1.4  jmcneill 				break;
    306   1.3  jmcneill 			}
    307   1.1  jmcneill 		}
    308   1.1  jmcneill 		acpi_table_unmap((ACPI_TABLE_HEADER *)spcr);
    309   1.1  jmcneill 	}
    310   1.1  jmcneill 
    311   1.1  jmcneill 	/*
    312  1.15  jmcneill 	 * Setup framebuffer console, if present.
    313  1.15  jmcneill 	 */
    314  1.15  jmcneill #if NWSDISPLAY > 0 && NGENFB > 0
    315  1.15  jmcneill 	acpi_platform_wsdisplay_preattach();
    316  1.15  jmcneill #endif
    317  1.15  jmcneill 
    318  1.15  jmcneill 	/*
    319   1.1  jmcneill 	 * Initialize PSCI 0.2+ if implemented
    320   1.1  jmcneill 	 */
    321   1.1  jmcneill 	if (ACPI_SUCCESS(acpi_table_find(ACPI_SIG_FADT, (void **)&fadt))) {
    322   1.1  jmcneill 		if (fadt->ArmBootFlags & ACPI_FADT_PSCI_COMPLIANT) {
    323   1.1  jmcneill 			if (fadt->ArmBootFlags & ACPI_FADT_PSCI_USE_HVC) {
    324   1.1  jmcneill 				psci_init(psci_call_hvc);
    325   1.1  jmcneill 			} else {
    326   1.1  jmcneill 				psci_init(psci_call_smc);
    327   1.1  jmcneill 			}
    328   1.1  jmcneill 		}
    329   1.1  jmcneill 		acpi_table_unmap((ACPI_TABLE_HEADER *)fadt);
    330   1.1  jmcneill 	}
    331   1.1  jmcneill 
    332  1.12       ryo #ifdef MULTIPROCESSOR
    333   1.1  jmcneill 	/*
    334   1.1  jmcneill 	 * Count CPUs
    335   1.1  jmcneill 	 */
    336   1.1  jmcneill 	if (ACPI_SUCCESS(acpi_table_find(ACPI_SIG_MADT, (void **)&madt))) {
    337   1.1  jmcneill 		char *end = (char *)madt + madt->Header.Length;
    338   1.1  jmcneill 		char *where = (char *)madt + sizeof(ACPI_TABLE_MADT);
    339   1.1  jmcneill 		while (where < end) {
    340   1.1  jmcneill 			ACPI_SUBTABLE_HEADER *subtable = (ACPI_SUBTABLE_HEADER *)where;
    341   1.1  jmcneill 			if (subtable->Type == ACPI_MADT_TYPE_GENERIC_INTERRUPT)
    342   1.1  jmcneill 				arm_cpu_max++;
    343   1.1  jmcneill 			where += subtable->Length;
    344   1.1  jmcneill 		}
    345   1.1  jmcneill 		acpi_table_unmap((ACPI_TABLE_HEADER *)madt);
    346   1.1  jmcneill 	}
    347  1.12       ryo #endif /* MULTIPROCESSOR */
    348   1.1  jmcneill }
    349   1.1  jmcneill 
    350   1.1  jmcneill static void
    351   1.1  jmcneill acpi_platform_init_attach_args(struct fdt_attach_args *faa)
    352   1.1  jmcneill {
    353   1.1  jmcneill 	extern struct bus_space arm_generic_bs_tag;
    354   1.1  jmcneill 	extern struct bus_space arm_generic_a4x_bs_tag;
    355   1.1  jmcneill 
    356   1.1  jmcneill 	faa->faa_bst = &arm_generic_bs_tag;
    357   1.1  jmcneill 	faa->faa_a4x_bst = &arm_generic_a4x_bs_tag;
    358  1.14  jmcneill 	faa->faa_dmat = &acpi_coherent_dma_tag;
    359   1.1  jmcneill }
    360   1.1  jmcneill 
    361   1.1  jmcneill static void
    362   1.1  jmcneill acpi_platform_device_register(device_t self, void *aux)
    363   1.1  jmcneill {
    364  1.10  jmcneill #if NCOM > 0
    365  1.10  jmcneill 	prop_dictionary_t prop = device_properties(self);
    366  1.10  jmcneill 
    367  1.11  jmcneill 	if (device_is_a(self, "com")) {
    368  1.10  jmcneill 		ACPI_TABLE_SPCR *spcr;
    369  1.10  jmcneill 
    370  1.10  jmcneill 		if (ACPI_FAILURE(acpi_table_find(ACPI_SIG_SPCR, (void **)&spcr)))
    371  1.10  jmcneill 			return;
    372  1.11  jmcneill 
    373  1.10  jmcneill 		if (spcr->SerialPort.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
    374  1.10  jmcneill 			goto spcr_unmap;
    375  1.10  jmcneill 		if (spcr->SerialPort.Address == 0)
    376  1.10  jmcneill 			goto spcr_unmap;
    377  1.10  jmcneill 		if (spcr->InterfaceType != ACPI_DBG2_16550_COMPATIBLE &&
    378  1.10  jmcneill 		    spcr->InterfaceType != ACPI_DBG2_16550_SUBSET)
    379  1.10  jmcneill 			goto spcr_unmap;
    380  1.10  jmcneill 
    381  1.11  jmcneill 		if (device_is_a(device_parent(self), "puc")) {
    382  1.11  jmcneill 			const struct puc_attach_args * const paa = aux;
    383  1.11  jmcneill 			int b, d, f;
    384  1.11  jmcneill 
    385  1.11  jmcneill 			const int s = pci_get_segment(paa->pc);
    386  1.11  jmcneill 			pci_decompose_tag(paa->pc, paa->tag, &b, &d, &f);
    387  1.11  jmcneill 
    388  1.11  jmcneill 			if (spcr->PciSegment == s && spcr->PciBus == b &&
    389  1.11  jmcneill 			    spcr->PciDevice == d && spcr->PciFunction == f)
    390  1.11  jmcneill 				prop_dictionary_set_bool(prop, "force_console", true);
    391  1.11  jmcneill 		}
    392  1.11  jmcneill 
    393  1.11  jmcneill 		if (device_is_a(device_parent(self), "acpi")) {
    394  1.11  jmcneill 			struct acpi_attach_args * const aa = aux;
    395  1.11  jmcneill 			struct acpi_resources res;
    396  1.11  jmcneill 			struct acpi_mem *mem;
    397  1.11  jmcneill 
    398  1.11  jmcneill 			if (ACPI_FAILURE(acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
    399  1.11  jmcneill 			    &res, &acpi_resource_parse_ops_quiet)))
    400  1.11  jmcneill 				goto spcr_unmap;
    401  1.11  jmcneill 
    402  1.11  jmcneill 			mem = acpi_res_mem(&res, 0);
    403  1.11  jmcneill 			if (mem == NULL)
    404  1.11  jmcneill 				goto crs_cleanup;
    405  1.11  jmcneill 
    406  1.11  jmcneill 			if (mem->ar_base == spcr->SerialPort.Address)
    407  1.11  jmcneill 				prop_dictionary_set_bool(prop, "force_console", true);
    408  1.11  jmcneill 
    409  1.11  jmcneill crs_cleanup:
    410  1.11  jmcneill 			acpi_resource_cleanup(&res);
    411  1.11  jmcneill 		}
    412  1.10  jmcneill 
    413  1.10  jmcneill spcr_unmap:
    414  1.10  jmcneill 		acpi_table_unmap((ACPI_TABLE_HEADER *)spcr);
    415  1.10  jmcneill 	}
    416  1.10  jmcneill #endif
    417   1.1  jmcneill }
    418   1.1  jmcneill 
    419   1.2  jmcneill static void
    420   1.2  jmcneill acpi_platform_reset(void)
    421   1.2  jmcneill {
    422   1.5  jmcneill #ifdef EFI_RUNTIME
    423   1.5  jmcneill 	if (arm_efirt_reset(EFI_RESET_COLD) == 0)
    424   1.5  jmcneill 		return;
    425   1.5  jmcneill #endif
    426   1.2  jmcneill 	if (psci_available())
    427   1.2  jmcneill 		psci_system_reset();
    428   1.2  jmcneill }
    429   1.2  jmcneill 
    430   1.1  jmcneill static u_int
    431   1.1  jmcneill acpi_platform_uart_freq(void)
    432   1.1  jmcneill {
    433   1.1  jmcneill 	return 0;
    434   1.1  jmcneill }
    435   1.1  jmcneill 
    436   1.1  jmcneill static const struct arm_platform acpi_platform = {
    437   1.1  jmcneill 	.ap_devmap = acpi_platform_devmap,
    438   1.1  jmcneill 	.ap_bootstrap = acpi_platform_bootstrap,
    439   1.1  jmcneill 	.ap_startup = acpi_platform_startup,
    440   1.1  jmcneill 	.ap_init_attach_args = acpi_platform_init_attach_args,
    441   1.1  jmcneill 	.ap_device_register = acpi_platform_device_register,
    442   1.2  jmcneill 	.ap_reset = acpi_platform_reset,
    443   1.1  jmcneill 	.ap_delay = gtmr_delay,
    444   1.1  jmcneill 	.ap_uart_freq = acpi_platform_uart_freq,
    445   1.1  jmcneill };
    446   1.1  jmcneill 
    447  1.17  jmcneill ARM_PLATFORM(acpi, "netbsd,generic-acpi", &acpi_platform);
    448