Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Add a generic Arm64 platform definition that is use...



details:   https://anonhg.NetBSD.org/src/rev/44e6be83d1a4
branches:  trunk
changeset: 466892:44e6be83d1a4
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Jan 05 17:16:07 2020 +0000

description:
Add a generic Arm64 platform definition that is used as a fallback.

The generic platform assumes PSCI, a generic timer, pre-initialized UART
clocks, and adds a 4KB entry to the devmap for the console UART device.

diffstat:

 sys/arch/arm/fdt/arm64_platform.c    |  122 +++++++++++++++++++++++++++++++++++
 sys/arch/arm/fdt/arm_fdt.c           |   21 ++++-
 sys/arch/arm/fdt/arm_fdtvar.h        |    4 +-
 sys/arch/evbarm/conf/files.generic64 |    4 +-
 4 files changed, 145 insertions(+), 6 deletions(-)

diffs (213 lines):

diff -r 176e91e7f6da -r 44e6be83d1a4 sys/arch/arm/fdt/arm64_platform.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/fdt/arm64_platform.c Sun Jan 05 17:16:07 2020 +0000
@@ -0,0 +1,122 @@
+/* $NetBSD: arm64_platform.c,v 1.1 2020/01/05 17:16:07 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2020 Jared McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * 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 AUTHOR ``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 AUTHOR 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 "opt_soc.h"
+#include "opt_multiprocessor.h"
+#include "opt_console.h"
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: arm64_platform.c,v 1.1 2020/01/05 17:16:07 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/cortex/gtmr_var.h>
+
+#include <arm/arm/psci.h>
+#include <arm/fdt/psci_fdtvar.h>
+
+#include <libfdt.h>
+
+#include <arch/evbarm/fdt/platform.h>
+
+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;
+
+static void
+arm64_platform_init_attach_args(struct fdt_attach_args *faa)
+{
+       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
+arm64_platform_device_register(device_t self, void *aux)
+{
+}
+
+static void
+arm64_platform_bootstrap(void)
+{
+}
+
+static const struct pmap_devmap *
+arm64_platform_devmap(void)
+{
+       static const struct pmap_devmap devmap_empty[] = {
+               DEVMAP_ENTRY_END
+       };
+       static struct pmap_devmap devmap_uart[] = {
+               DEVMAP_ENTRY(KERNEL_IO_VBASE, 0, L3_SIZE),
+               DEVMAP_ENTRY_END
+       };
+       bus_addr_t uart_base;
+
+       const int phandle = fdtbus_get_stdout_phandle();
+       if (phandle <= 0)
+               return devmap_empty;
+
+       if (fdtbus_get_reg(phandle, 0, &uart_base, NULL) != 0)
+               return devmap_empty;
+
+       devmap_uart[0].pd_pa = DEVMAP_TRUNC_ADDR(uart_base);
+
+       return devmap_uart;
+}
+
+static u_int
+arm64_platform_uart_freq(void)
+{
+       return 0;
+}
+
+static const struct arm_platform arm64_platform = {
+       .ap_devmap = arm64_platform_devmap,
+       .ap_bootstrap = arm64_platform_bootstrap,
+       .ap_init_attach_args = arm64_platform_init_attach_args,
+       .ap_device_register = arm64_platform_device_register,
+       .ap_reset = psci_fdt_reset,
+       .ap_delay = gtmr_delay,
+       .ap_uart_freq = arm64_platform_uart_freq,
+       .ap_mpstart = arm_fdt_cpu_mpstart,
+};
+
+ARM_PLATFORM(arm64, ARM_PLATFORM_DEFAULT, &arm64_platform);
diff -r 176e91e7f6da -r 44e6be83d1a4 sys/arch/arm/fdt/arm_fdt.c
--- a/sys/arch/arm/fdt/arm_fdt.c        Sun Jan 05 16:41:07 2020 +0000
+++ b/sys/arch/arm/fdt/arm_fdt.c        Sun Jan 05 17:16:07 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: arm_fdt.c,v 1.9 2019/01/03 12:54:25 jmcneill Exp $ */
+/* $NetBSD: arm_fdt.c,v 1.10 2020/01/05 17:16:07 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -29,7 +29,7 @@
 #include "opt_arm_timer.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: arm_fdt.c,v 1.9 2019/01/03 12:54:25 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arm_fdt.c,v 1.10 2020/01/05 17:16:07 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -87,10 +87,10 @@
 arm_fdt_platform(void)
 {
        static const struct arm_platform_info *booted_platform = NULL;
+       __link_set_decl(arm_platforms, struct arm_platform_info);
+       struct arm_platform_info * const *info;
 
        if (booted_platform == NULL) {
-               __link_set_decl(arm_platforms, struct arm_platform_info);
-               struct arm_platform_info * const *info;
                const struct arm_platform_info *best_info = NULL;
                const int phandle = OF_peer(0);
                int match, best_match = 0;
@@ -107,6 +107,19 @@
                booted_platform = best_info;
        }
 
+       /*
+        * No SoC specific platform was found. Try to find a generic
+        * platform definition and use that if available.
+        */
+       if (booted_platform == NULL) {
+               __link_set_foreach(info, arm_platforms) {
+                       if (strcmp((*info)->api_compat, ARM_PLATFORM_DEFAULT) == 0) {
+                               booted_platform = *info;
+                               break;
+                       }
+               }
+       }
+
        return booted_platform == NULL ? NULL : booted_platform->api_ops;
 }
 
diff -r 176e91e7f6da -r 44e6be83d1a4 sys/arch/arm/fdt/arm_fdtvar.h
--- a/sys/arch/arm/fdt/arm_fdtvar.h     Sun Jan 05 16:41:07 2020 +0000
+++ b/sys/arch/arm/fdt/arm_fdtvar.h     Sun Jan 05 17:16:07 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: arm_fdtvar.h,v 1.15 2019/01/31 13:06:10 skrll Exp $ */
+/* $NetBSD: arm_fdtvar.h,v 1.16 2020/01/05 17:16:07 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -52,6 +52,8 @@
        const struct arm_platform *     api_ops;
 };
 
+#define ARM_PLATFORM_DEFAULT           ""
+
 #define _ARM_PLATFORM_REGISTER(name)   \
        __link_set_add_rodata(arm_platforms, __CONCAT(name,_platinfo));
 
diff -r 176e91e7f6da -r 44e6be83d1a4 sys/arch/evbarm/conf/files.generic64
--- a/sys/arch/evbarm/conf/files.generic64      Sun Jan 05 16:41:07 2020 +0000
+++ b/sys/arch/evbarm/conf/files.generic64      Sun Jan 05 17:16:07 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.generic64,v 1.12 2019/03/17 08:17:56 skrll Exp $
+#      $NetBSD: files.generic64,v 1.13 2020/01/05 17:16:07 jmcneill Exp $
 #
 # A generic (aarch64) kernel configuration info
 #
@@ -8,6 +8,8 @@
 
 include "arch/evbarm/conf/files.fdt"
 
+file   arch/arm/fdt/arm64_platform.c
+
 # Add other board files here
 #
 include "arch/arm/acpi/files.acpi"



Home | Main Index | Thread Index | Old Index