Home | History | Annotate | Line # | Download | only in acpi
acpi_platform.c revision 1.2
      1  1.2  jmcneill /* $NetBSD: acpi_platform.c,v 1.2 2018/10/13 00:08:29 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.1  jmcneill #include <sys/cdefs.h>
     33  1.2  jmcneill __KERNEL_RCSID(0, "$NetBSD: acpi_platform.c,v 1.2 2018/10/13 00:08:29 jmcneill Exp $");
     34  1.1  jmcneill 
     35  1.1  jmcneill #include <sys/param.h>
     36  1.1  jmcneill #include <sys/bus.h>
     37  1.1  jmcneill #include <sys/cpu.h>
     38  1.1  jmcneill #include <sys/device.h>
     39  1.1  jmcneill #include <sys/termios.h>
     40  1.1  jmcneill 
     41  1.1  jmcneill #include <dev/fdt/fdtvar.h>
     42  1.1  jmcneill #include <arm/fdt/arm_fdtvar.h>
     43  1.1  jmcneill 
     44  1.1  jmcneill #include <uvm/uvm_extern.h>
     45  1.1  jmcneill 
     46  1.1  jmcneill #include <machine/bootconfig.h>
     47  1.1  jmcneill #include <arm/cpufunc.h>
     48  1.1  jmcneill #include <arm/locore.h>
     49  1.1  jmcneill 
     50  1.1  jmcneill #include <arm/cortex/gtmr_var.h>
     51  1.1  jmcneill 
     52  1.1  jmcneill #include <arm/arm/psci.h>
     53  1.1  jmcneill #include <arm/fdt/psci_fdtvar.h>
     54  1.1  jmcneill 
     55  1.1  jmcneill #include <evbarm/fdt/platform.h>
     56  1.1  jmcneill 
     57  1.1  jmcneill #include <evbarm/dev/plcomreg.h>
     58  1.1  jmcneill #include <evbarm/dev/plcomvar.h>
     59  1.1  jmcneill #include <dev/ic/ns16550reg.h>
     60  1.1  jmcneill #include <dev/ic/comreg.h>
     61  1.1  jmcneill 
     62  1.1  jmcneill #include <dev/acpi/acpireg.h>
     63  1.1  jmcneill #include <dev/acpi/acpivar.h>
     64  1.1  jmcneill #include <arch/arm/acpi/acpi_table.h>
     65  1.1  jmcneill 
     66  1.1  jmcneill #define	SPCR_INTERFACE_TYPE_PL011	0x0003
     67  1.1  jmcneill 
     68  1.1  jmcneill extern struct bus_space arm_generic_bs_tag;
     69  1.1  jmcneill 
     70  1.1  jmcneill static struct plcom_instance plcom_console;
     71  1.1  jmcneill 
     72  1.1  jmcneill static const struct pmap_devmap *
     73  1.1  jmcneill acpi_platform_devmap(void)
     74  1.1  jmcneill {
     75  1.1  jmcneill 	static const struct pmap_devmap devmap[] = {
     76  1.1  jmcneill 		DEVMAP_ENTRY_END
     77  1.1  jmcneill 	};
     78  1.1  jmcneill 
     79  1.1  jmcneill 	return devmap;
     80  1.1  jmcneill }
     81  1.1  jmcneill 
     82  1.1  jmcneill static void
     83  1.1  jmcneill acpi_platform_bootstrap(void)
     84  1.1  jmcneill {
     85  1.1  jmcneill }
     86  1.1  jmcneill 
     87  1.1  jmcneill static void
     88  1.1  jmcneill acpi_platform_startup(void)
     89  1.1  jmcneill {
     90  1.1  jmcneill 	ACPI_TABLE_SPCR *spcr;
     91  1.1  jmcneill 	ACPI_TABLE_FADT *fadt;
     92  1.1  jmcneill 	ACPI_TABLE_MADT *madt;
     93  1.1  jmcneill 
     94  1.1  jmcneill 	/*
     95  1.1  jmcneill 	 * Setup serial console device
     96  1.1  jmcneill 	 */
     97  1.1  jmcneill 	if (ACPI_SUCCESS(acpi_table_find(ACPI_SIG_SPCR, (void **)&spcr))) {
     98  1.1  jmcneill 		if (spcr->InterfaceType == SPCR_INTERFACE_TYPE_PL011 &&
     99  1.1  jmcneill 		    spcr->SerialPort.SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY &&
    100  1.1  jmcneill 		    spcr->SerialPort.Address != 0) {
    101  1.1  jmcneill 
    102  1.1  jmcneill 			plcom_console.pi_type = PLCOM_TYPE_PL011;
    103  1.1  jmcneill 			plcom_console.pi_flags = PLC_FLAG_32BIT_ACCESS;
    104  1.1  jmcneill 			plcom_console.pi_iot = &arm_generic_bs_tag;
    105  1.1  jmcneill 			plcom_console.pi_iobase = spcr->SerialPort.Address;
    106  1.1  jmcneill 			plcom_console.pi_size = PL011COM_UART_SIZE;
    107  1.1  jmcneill 
    108  1.1  jmcneill 			plcomcnattach(&plcom_console, 115200 /* XXX */, 0, TTYDEF_CFLAG, -1);
    109  1.1  jmcneill 		}
    110  1.1  jmcneill 		acpi_table_unmap((ACPI_TABLE_HEADER *)spcr);
    111  1.1  jmcneill 	}
    112  1.1  jmcneill 
    113  1.1  jmcneill 	/*
    114  1.1  jmcneill 	 * Initialize PSCI 0.2+ if implemented
    115  1.1  jmcneill 	 */
    116  1.1  jmcneill 	if (ACPI_SUCCESS(acpi_table_find(ACPI_SIG_FADT, (void **)&fadt))) {
    117  1.1  jmcneill 		if (fadt->ArmBootFlags & ACPI_FADT_PSCI_COMPLIANT) {
    118  1.1  jmcneill 			if (fadt->ArmBootFlags & ACPI_FADT_PSCI_USE_HVC) {
    119  1.1  jmcneill 				psci_init(psci_call_hvc);
    120  1.1  jmcneill 			} else {
    121  1.1  jmcneill 				psci_init(psci_call_smc);
    122  1.1  jmcneill 			}
    123  1.1  jmcneill 		}
    124  1.1  jmcneill 		acpi_table_unmap((ACPI_TABLE_HEADER *)fadt);
    125  1.1  jmcneill 	}
    126  1.1  jmcneill 
    127  1.1  jmcneill 	/*
    128  1.1  jmcneill 	 * Count CPUs
    129  1.1  jmcneill 	 */
    130  1.1  jmcneill 	if (ACPI_SUCCESS(acpi_table_find(ACPI_SIG_MADT, (void **)&madt))) {
    131  1.1  jmcneill 		char *end = (char *)madt + madt->Header.Length;
    132  1.1  jmcneill 		char *where = (char *)madt + sizeof(ACPI_TABLE_MADT);
    133  1.1  jmcneill 		while (where < end) {
    134  1.1  jmcneill 			ACPI_SUBTABLE_HEADER *subtable = (ACPI_SUBTABLE_HEADER *)where;
    135  1.1  jmcneill 			if (subtable->Type == ACPI_MADT_TYPE_GENERIC_INTERRUPT)
    136  1.1  jmcneill 				arm_cpu_max++;
    137  1.1  jmcneill 			where += subtable->Length;
    138  1.1  jmcneill 		}
    139  1.1  jmcneill 		acpi_table_unmap((ACPI_TABLE_HEADER *)madt);
    140  1.1  jmcneill 	}
    141  1.1  jmcneill }
    142  1.1  jmcneill 
    143  1.1  jmcneill static void
    144  1.1  jmcneill acpi_platform_init_attach_args(struct fdt_attach_args *faa)
    145  1.1  jmcneill {
    146  1.1  jmcneill 	extern struct arm32_bus_dma_tag arm_generic_dma_tag;
    147  1.1  jmcneill 	extern struct bus_space arm_generic_bs_tag;
    148  1.1  jmcneill 	extern struct bus_space arm_generic_a4x_bs_tag;
    149  1.1  jmcneill 
    150  1.1  jmcneill 	faa->faa_bst = &arm_generic_bs_tag;
    151  1.1  jmcneill 	faa->faa_a4x_bst = &arm_generic_a4x_bs_tag;
    152  1.1  jmcneill 	faa->faa_dmat = &arm_generic_dma_tag;
    153  1.1  jmcneill }
    154  1.1  jmcneill 
    155  1.1  jmcneill static void
    156  1.1  jmcneill acpi_platform_early_putchar(char c)
    157  1.1  jmcneill {
    158  1.1  jmcneill }
    159  1.1  jmcneill 
    160  1.1  jmcneill static void
    161  1.1  jmcneill acpi_platform_device_register(device_t self, void *aux)
    162  1.1  jmcneill {
    163  1.1  jmcneill }
    164  1.1  jmcneill 
    165  1.2  jmcneill static void
    166  1.2  jmcneill acpi_platform_reset(void)
    167  1.2  jmcneill {
    168  1.2  jmcneill 	if (psci_available())
    169  1.2  jmcneill 		psci_system_reset();
    170  1.2  jmcneill }
    171  1.2  jmcneill 
    172  1.1  jmcneill static u_int
    173  1.1  jmcneill acpi_platform_uart_freq(void)
    174  1.1  jmcneill {
    175  1.1  jmcneill 	return 0;
    176  1.1  jmcneill }
    177  1.1  jmcneill 
    178  1.1  jmcneill static const struct arm_platform acpi_platform = {
    179  1.1  jmcneill 	.ap_devmap = acpi_platform_devmap,
    180  1.1  jmcneill 	.ap_bootstrap = acpi_platform_bootstrap,
    181  1.1  jmcneill 	.ap_startup = acpi_platform_startup,
    182  1.1  jmcneill 	.ap_init_attach_args = acpi_platform_init_attach_args,
    183  1.1  jmcneill 	.ap_early_putchar = acpi_platform_early_putchar,
    184  1.1  jmcneill 	.ap_device_register = acpi_platform_device_register,
    185  1.2  jmcneill 	.ap_reset = acpi_platform_reset,
    186  1.1  jmcneill 	.ap_delay = gtmr_delay,
    187  1.1  jmcneill 	.ap_uart_freq = acpi_platform_uart_freq,
    188  1.1  jmcneill };
    189  1.1  jmcneill 
    190  1.1  jmcneill ARM_PLATFORM(virt, "netbsd,generic-acpi", &acpi_platform);
    191