Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/arm/acpi Add ACPI platform glue and basic device dr...
details: https://anonhg.NetBSD.org/src/rev/dc2f09b0c2e6
branches: trunk
changeset: 433933:dc2f09b0c2e6
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Fri Oct 12 22:20:04 2018 +0000
description:
Add ACPI platform glue and basic device drivers (CPU, GIC, Generic Timer,
SBSA UART).
diffstat:
sys/arch/arm/acpi/acpi_platform.c | 183 ++++++++++++++++++++++++++++++++++++++
sys/arch/arm/acpi/cpu_acpi.c | 101 ++++++++++++++++++++
sys/arch/arm/acpi/files.acpi | 27 +++++
sys/arch/arm/acpi/gic_acpi.c | 133 +++++++++++++++++++++++++++
sys/arch/arm/acpi/gtmr_acpi.c | 101 ++++++++++++++++++++
sys/arch/arm/acpi/plcom_acpi.c | 121 +++++++++++++++++++++++++
6 files changed, 666 insertions(+), 0 deletions(-)
diffs (truncated from 690 to 300 lines):
diff -r ef223ccb865b -r dc2f09b0c2e6 sys/arch/arm/acpi/acpi_platform.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/acpi/acpi_platform.c Fri Oct 12 22:20:04 2018 +0000
@@ -0,0 +1,183 @@
+/* $NetBSD: acpi_platform.c,v 1.1 2018/10/12 22:20:04 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jared McNeill <jmcneill%invisible.ca@localhost>.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: acpi_platform.c,v 1.1 2018/10/12 22:20:04 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/cpu.h>
+#include <sys/device.h>
+#include <sys/termios.h>
+
+#include <dev/fdt/fdtvar.h>
+#include <arm/fdt/arm_fdtvar.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <machine/bootconfig.h>
+#include <arm/cpufunc.h>
+#include <arm/locore.h>
+
+#include <arm/cortex/gtmr_var.h>
+
+#include <arm/arm/psci.h>
+#include <arm/fdt/psci_fdtvar.h>
+
+#include <evbarm/fdt/platform.h>
+
+#include <evbarm/dev/plcomreg.h>
+#include <evbarm/dev/plcomvar.h>
+#include <dev/ic/ns16550reg.h>
+#include <dev/ic/comreg.h>
+
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+#include <arch/arm/acpi/acpi_table.h>
+
+#define SPCR_INTERFACE_TYPE_PL011 0x0003
+
+extern struct bus_space arm_generic_bs_tag;
+
+static struct plcom_instance plcom_console;
+
+static const struct pmap_devmap *
+acpi_platform_devmap(void)
+{
+ static const struct pmap_devmap devmap[] = {
+ DEVMAP_ENTRY_END
+ };
+
+ return devmap;
+}
+
+static void
+acpi_platform_bootstrap(void)
+{
+}
+
+static void
+acpi_platform_startup(void)
+{
+ ACPI_TABLE_SPCR *spcr;
+ ACPI_TABLE_FADT *fadt;
+ ACPI_TABLE_MADT *madt;
+
+ /*
+ * Setup serial console device
+ */
+ if (ACPI_SUCCESS(acpi_table_find(ACPI_SIG_SPCR, (void **)&spcr))) {
+ if (spcr->InterfaceType == SPCR_INTERFACE_TYPE_PL011 &&
+ spcr->SerialPort.SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY &&
+ spcr->SerialPort.Address != 0) {
+
+ plcom_console.pi_type = PLCOM_TYPE_PL011;
+ plcom_console.pi_flags = PLC_FLAG_32BIT_ACCESS;
+ plcom_console.pi_iot = &arm_generic_bs_tag;
+ plcom_console.pi_iobase = spcr->SerialPort.Address;
+ plcom_console.pi_size = PL011COM_UART_SIZE;
+
+ plcomcnattach(&plcom_console, 115200 /* XXX */, 0, TTYDEF_CFLAG, -1);
+ }
+ acpi_table_unmap((ACPI_TABLE_HEADER *)spcr);
+ }
+
+ /*
+ * Initialize PSCI 0.2+ if implemented
+ */
+ if (ACPI_SUCCESS(acpi_table_find(ACPI_SIG_FADT, (void **)&fadt))) {
+ if (fadt->ArmBootFlags & ACPI_FADT_PSCI_COMPLIANT) {
+ if (fadt->ArmBootFlags & ACPI_FADT_PSCI_USE_HVC) {
+ psci_init(psci_call_hvc);
+ } else {
+ psci_init(psci_call_smc);
+ }
+ }
+ acpi_table_unmap((ACPI_TABLE_HEADER *)fadt);
+ }
+
+ /*
+ * Count CPUs
+ */
+ if (ACPI_SUCCESS(acpi_table_find(ACPI_SIG_MADT, (void **)&madt))) {
+ char *end = (char *)madt + madt->Header.Length;
+ char *where = (char *)madt + sizeof(ACPI_TABLE_MADT);
+ while (where < end) {
+ ACPI_SUBTABLE_HEADER *subtable = (ACPI_SUBTABLE_HEADER *)where;
+ if (subtable->Type == ACPI_MADT_TYPE_GENERIC_INTERRUPT)
+ arm_cpu_max++;
+ where += subtable->Length;
+ }
+ acpi_table_unmap((ACPI_TABLE_HEADER *)madt);
+ }
+}
+
+static void
+acpi_platform_init_attach_args(struct fdt_attach_args *faa)
+{
+ extern struct arm32_bus_dma_tag arm_generic_dma_tag;
+ extern struct bus_space arm_generic_bs_tag;
+ extern struct bus_space arm_generic_a4x_bs_tag;
+
+ faa->faa_bst = &arm_generic_bs_tag;
+ faa->faa_a4x_bst = &arm_generic_a4x_bs_tag;
+ faa->faa_dmat = &arm_generic_dma_tag;
+}
+
+static void
+acpi_platform_early_putchar(char c)
+{
+}
+
+static void
+acpi_platform_device_register(device_t self, void *aux)
+{
+}
+
+static u_int
+acpi_platform_uart_freq(void)
+{
+ return 0;
+}
+
+static const struct arm_platform acpi_platform = {
+ .ap_devmap = acpi_platform_devmap,
+ .ap_bootstrap = acpi_platform_bootstrap,
+ .ap_startup = acpi_platform_startup,
+ .ap_init_attach_args = acpi_platform_init_attach_args,
+ .ap_early_putchar = acpi_platform_early_putchar,
+ .ap_device_register = acpi_platform_device_register,
+ .ap_reset = psci_fdt_reset,
+ .ap_delay = gtmr_delay,
+ .ap_uart_freq = acpi_platform_uart_freq,
+};
+
+ARM_PLATFORM(virt, "netbsd,generic-acpi", &acpi_platform);
diff -r ef223ccb865b -r dc2f09b0c2e6 sys/arch/arm/acpi/cpu_acpi.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/acpi/cpu_acpi.c Fri Oct 12 22:20:04 2018 +0000
@@ -0,0 +1,101 @@
+/* $NetBSD: cpu_acpi.c,v 1.1 2018/10/12 22:20:04 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jared McNeill <jmcneill%invisible.ca@localhost>.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: cpu_acpi.c,v 1.1 2018/10/12 22:20:04 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/cpu.h>
+#include <sys/device.h>
+
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+
+#include <arm/armreg.h>
+#include <arm/cpu.h>
+#include <arm/cpufunc.h>
+#include <arm/locore.h>
+
+#include <arm/arm/psci.h>
+
+static int cpu_acpi_match(device_t, cfdata_t, void *);
+static void cpu_acpi_attach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(cpu_acpi, 0, cpu_acpi_match, cpu_acpi_attach, NULL, NULL);
+
+static register_t
+cpu_acpi_mpstart_pa(void)
+{
+ extern void aarch64_mpstart(void);
+ return (register_t)aarch64_kern_vtophys((vaddr_t)aarch64_mpstart);
+}
+
+static int
+cpu_acpi_match(device_t parent, cfdata_t cf, void *aux)
+{
+ ACPI_SUBTABLE_HEADER *hdrp = aux;
+
+ return hdrp->Type == ACPI_MADT_TYPE_GENERIC_INTERRUPT;
+}
+
+static void
+cpu_acpi_attach(device_t parent, device_t self, void *aux)
+{
+ ACPI_MADT_GENERIC_INTERRUPT *gicc = aux;
+ const uint64_t mpidr = gicc->ArmMpidr;
+ int error;
+
+ if (cpu_mpidr_aff_read() != mpidr) {
+ const u_int cpuindex = device_unit(self);
+
+ cpu_mpidr[cpuindex] = mpidr;
+ cpu_dcache_wb_range((vaddr_t)&cpu_mpidr[cpuindex], sizeof(cpu_mpidr[cpuindex]));
+
+ /* XXX support spin table */
+ error = psci_cpu_on(mpidr, cpu_acpi_mpstart_pa(), 0);
+ if (error != PSCI_SUCCESS) {
+ aprint_error_dev(self, "failed to start CPU\n");
+ return;
+ }
+
+ __asm __volatile("sev" ::: "memory");
+
+ for (u_int i = 0x10000000; i > 0; i--) {
+ membar_consumer();
+ if (arm_cpu_hatched & __BIT(cpuindex))
+ break;
+ }
+ }
+
+ /* Attach the CPU */
+ cpu_attach(self, mpidr);
+}
diff -r ef223ccb865b -r dc2f09b0c2e6 sys/arch/arm/acpi/files.acpi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/acpi/files.acpi Fri Oct 12 22:20:04 2018 +0000
@@ -0,0 +1,27 @@
+# $NetBSD: files.acpi,v 1.1 2018/10/12 22:20:04 jmcneill Exp $
+#
+# Configuration info for ACPI compliant ARM boards.
+#
Home |
Main Index |
Thread Index |
Old Index