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 facility for platform-specific callbacks and ...



details:   https://anonhg.NetBSD.org/src/rev/992ec833b8b1
branches:  trunk
changeset: 353936:992ec833b8b1
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun May 28 23:39:30 2017 +0000

description:
Add a facility for platform-specific callbacks and use it to remove most
of the Tegra-specific code from tegra_machdep.c.

Platform code matches on the compatible property of the root ("/") DT node
and allows for chip-specific implementations of the following:

 - devmap: Return a 0-terminated list of static device map entries.
 - bootstrap: Early initialization of platform-specific facilities.
 - early_putchar: Provides an implementation of putchar for use in early
     debug messages.
 - device_register: Platform-specific device register callback.
 - reset: Platform-specific CPU reset implementation.
 - consinit: Platform-specific console init implementation.

diffstat:

 sys/arch/arm/fdt/armv7_fdt.c          |   36 ++++-
 sys/arch/arm/fdt/armv7_fdtvar.h       |   60 +++++++
 sys/arch/arm/nvidia/files.tegra       |    3 +-
 sys/arch/arm/nvidia/tegra_platform.c  |  223 ++++++++++++++++++++++++++++
 sys/arch/evbarm/tegra/platform.h      |    4 +-
 sys/arch/evbarm/tegra/tegra_machdep.c |  264 +++++----------------------------
 6 files changed, 361 insertions(+), 229 deletions(-)

diffs (truncated from 787 to 300 lines):

diff -r aca20edf41d2 -r 992ec833b8b1 sys/arch/arm/fdt/armv7_fdt.c
--- a/sys/arch/arm/fdt/armv7_fdt.c      Sun May 28 23:32:14 2017 +0000
+++ b/sys/arch/arm/fdt/armv7_fdt.c      Sun May 28 23:39:30 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: armv7_fdt.c,v 1.1 2017/05/28 00:40:20 jmcneill Exp $ */
+/* $NetBSD: armv7_fdt.c,v 1.2 2017/05/28 23:39:30 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: armv7_fdt.c,v 1.1 2017/05/28 00:40:20 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: armv7_fdt.c,v 1.2 2017/05/28 23:39:30 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -39,6 +39,8 @@
 #include <dev/fdt/fdtvar.h>
 #include <dev/ofw/openfirm.h>
 
+#include <arm/fdt/armv7_fdtvar.h>
+
 static int     armv7_fdt_match(device_t, cfdata_t, void *);
 static void    armv7_fdt_attach(device_t, device_t, void *);
 
@@ -51,6 +53,9 @@
 extern struct bus_space armv7_generic_a4x_bs_tag;
 extern struct arm32_bus_dma_tag armv7_generic_dma_tag;
 
+static struct armv7_platlist armv7_platform_list =
+    TAILQ_HEAD_INITIALIZER(armv7_platform_list);
+
 int
 armv7_fdt_match(device_t parent, cfdata_t cf, void *aux)
 {
@@ -76,3 +81,30 @@
        };
        config_found(self, &faa, NULL);
 }
+
+const struct armv7_platform *
+armv7_fdt_platform(void)
+{
+       static const struct armv7_platform_info *booted_platform = NULL;
+
+       if (booted_platform == NULL) {
+               __link_set_decl(armv7_platforms, struct armv7_platform_info);
+               struct armv7_platform_info * const *info;
+               const struct armv7_platform_info *best_info = NULL;
+               const int phandle = OF_peer(0);
+               int match, best_match = 0;
+
+               __link_set_foreach(info, armv7_platforms) {
+                       const char * const compat[] = { (*info)->compat, NULL };
+                       match = of_match_compatible(phandle, compat);
+                       if (match > best_match) {
+                               best_match = match;
+                               best_info = *info;
+                       }
+               }
+
+               booted_platform = best_info;
+       }
+
+       return booted_platform == NULL ? NULL : booted_platform->ops;
+}
diff -r aca20edf41d2 -r 992ec833b8b1 sys/arch/arm/fdt/armv7_fdtvar.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/fdt/armv7_fdtvar.h   Sun May 28 23:39:30 2017 +0000
@@ -0,0 +1,60 @@
+/* $NetBSD: armv7_fdtvar.h,v 1.1 2017/05/28 23:39:30 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2017 Jared D. 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.
+ */
+
+#ifndef _ARM_ARMV7_FDTVAR_H
+#define _ARM_ARMV7_FDTVAR_H
+
+struct armv7_platform {
+       const struct pmap_devmap *      (*devmap)(void);
+       void                            (*bootstrap)(void);
+       void                            (*early_putchar)(char);
+       void                            (*device_register)(device_t, void *);
+       void                            (*reset)(void);
+       void                            (*consinit)(void);
+};
+
+struct armv7_platform_info {
+       const char *                    compat;
+       const struct armv7_platform *   ops;
+};
+
+#define _ARMV7_PLATFORM_REGISTER(name) \
+       __link_set_add_rodata(armv7_platforms, __CONCAT(name,_platinfo));
+
+#define ARMV7_PLATFORM(_name, _compat, _ops)                           \
+static const struct armv7_platform_info __CONCAT(_name,_platinfo) = {  \
+       .compat = (_compat),                                            \
+       .ops = (_ops)                                                   \
+};                                                                     \
+_ARMV7_PLATFORM_REGISTER(_name)
+
+TAILQ_HEAD(armv7_platlist, armv7_platform_info);
+
+const struct armv7_platform *  armv7_fdt_platform(void);
+
+#endif /* !_ARM_ARMV7_FDTVAR_H */
diff -r aca20edf41d2 -r 992ec833b8b1 sys/arch/arm/nvidia/files.tegra
--- a/sys/arch/arm/nvidia/files.tegra   Sun May 28 23:32:14 2017 +0000
+++ b/sys/arch/arm/nvidia/files.tegra   Sun May 28 23:39:30 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.tegra,v 1.37 2017/05/28 00:40:20 jmcneill Exp $
+#      $NetBSD: files.tegra,v 1.38 2017/05/28 23:39:30 jmcneill Exp $
 #
 # Configuration info for NVIDIA Tegra ARM Peripherals
 #
@@ -14,6 +14,7 @@
 file   arch/arm/arm32/armv7_generic_dma.c
 file   arch/arm/arm/bus_space_a4x.S
 
+file   arch/arm/nvidia/tegra_platform.c
 file   arch/arm/nvidia/tegra_soc.c
 file   arch/arm/nvidia/tegra_cpufreq.c
 
diff -r aca20edf41d2 -r 992ec833b8b1 sys/arch/arm/nvidia/tegra_platform.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/nvidia/tegra_platform.c      Sun May 28 23:39:30 2017 +0000
@@ -0,0 +1,223 @@
+/* $NetBSD: tegra_platform.c,v 1.1 2017/05/28 23:39:30 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2017 Jared D. 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_tegra.h"
+#include "opt_multiprocessor.h"
+
+#include "com.h"
+#include "ukbd.h"
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: tegra_platform.c,v 1.1 2017/05/28 23:39:30 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 <uvm/uvm_extern.h>
+
+#include <machine/bootconfig.h>
+#include <arm/cpufunc.h>
+
+#include <arm/nvidia/tegra_reg.h>
+#include <arm/nvidia/tegra_var.h>
+
+#include <arm/fdt/armv7_fdtvar.h>
+
+#if NUKBD > 0
+#include <dev/usb/ukbdvar.h>
+#endif
+
+#if NCOM > 0
+#include <dev/ic/ns16550reg.h>
+#include <dev/ic/comreg.h>
+#include <dev/ic/comvar.h>
+#ifndef CONMODE
+#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
+#endif
+#endif
+
+#define        DEVMAP_ALIGN(a) ((a) & ~L1_S_OFFSET)
+#define        DEVMAP_SIZE(s)  roundup2((s), L1_S_SIZE)
+#define        DEVMAP_ENTRY(va, pa, sz)                        \
+       {                                               \
+               .pd_va = DEVMAP_ALIGN(va),              \
+               .pd_pa = DEVMAP_ALIGN(pa),              \
+               .pd_size = DEVMAP_SIZE(sz),             \
+               .pd_prot = VM_PROT_READ|VM_PROT_WRITE,  \
+               .pd_cache = PTE_NOCACHE                 \
+       }
+#define        DEVMAP_ENTRY_END        { 0 }
+
+static const struct pmap_devmap *
+tegra_platform_devmap(void)
+{
+       static const struct pmap_devmap devmap[] = {
+               DEVMAP_ENTRY(TEGRA_HOST1X_VBASE,
+                            TEGRA_HOST1X_BASE,
+                            TEGRA_HOST1X_SIZE),
+               DEVMAP_ENTRY(TEGRA_PPSB_VBASE,
+                            TEGRA_PPSB_BASE,
+                            TEGRA_PPSB_SIZE),
+               DEVMAP_ENTRY(TEGRA_APB_VBASE,
+                            TEGRA_APB_BASE,
+                            TEGRA_APB_SIZE),
+               DEVMAP_ENTRY(TEGRA_AHB_A2_VBASE,
+                            TEGRA_AHB_A2_BASE,
+                            TEGRA_AHB_A2_SIZE),
+               DEVMAP_ENTRY_END
+       };      
+
+       return devmap;
+}
+
+static void
+tegra_platform_bootstrap(void)
+{
+       tegra_bootstrap();
+}
+
+static void
+tegra_platform_early_putchar(char c)
+{
+#ifdef CONSADDR
+#define CONSADDR_VA    (CONSADDR - TEGRA_APB_BASE + TEGRA_APB_VBASE)
+       volatile uint32_t *uartaddr = (volatile uint32_t *)CONSADDR_VA;
+
+       while ((uartaddr[com_lsr] & LSR_TXRDY) == 0)
+               ;
+
+       uartaddr[com_data] = c;
+#endif
+}
+
+static void
+tegra_platform_device_register(device_t self, void *aux)
+{
+       prop_dictionary_t dict = device_properties(self);
+
+       if (device_is_a(self, "tegrafb") &&
+           match_bootconf_option(boot_args, "console", "fb")) {
+               prop_dictionary_set_bool(dict, "is_console", true);
+#if NUKBD > 0
+               ukbd_cnattach();
+#endif
+       }
+
+       if (device_is_a(self, "tegradrm")) {
+               const char *video = get_bootconf_string(boot_args, "video");
+               if (video)
+                       prop_dictionary_set_cstring(dict, "HDMI-A-1", video);
+               if (match_bootconf_option(boot_args, "hdmi.forcemode", "dvi"))
+                       prop_dictionary_set_bool(dict, "force-dvi", true);
+       }
+
+       if (device_is_a(self, "tegracec"))
+               prop_dictionary_set_cstring(dict, "hdmi-device", "tegradrm0");
+
+       if (device_is_a(self, "nouveau")) {



Home | Main Index | Thread Index | Old Index