Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Enumerate CPUs, GIC, and generic timer using FDT da...



details:   https://anonhg.NetBSD.org/src/rev/48267b20ab97
branches:  trunk
changeset: 824212:48267b20ab97
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun May 28 00:40:20 2017 +0000

description:
Enumerate CPUs, GIC, and generic timer using FDT data instead of relying
on hard-coded tables in mainbus.

diffstat:

 sys/arch/arm/fdt/armv7_fdt.c          |  78 ++++++++++++++++++++++++++++++
 sys/arch/arm/fdt/cpu_fdt.c            |  91 +++++++++++++++++++++++++++++++++++
 sys/arch/arm/fdt/files.fdt            |  15 +++++-
 sys/arch/arm/fdt/gic_fdt.c            |  38 +++++++++++++-
 sys/arch/arm/fdt/gtmr_fdt.c           |  74 ++++++++++++++++++++++++++++
 sys/arch/arm/nvidia/files.tegra       |   8 +--
 sys/arch/arm/nvidia/tegra_fdt.c       |  80 ------------------------------
 sys/arch/arm/nvidia/tegra_var.h       |   3 +-
 sys/arch/evbarm/conf/TEGRA            |  27 +++++-----
 sys/arch/evbarm/tegra/tegra_machdep.c |  17 +-----
 10 files changed, 309 insertions(+), 122 deletions(-)

diffs (truncated from 582 to 300 lines):

diff -r 77c9a9e4184b -r 48267b20ab97 sys/arch/arm/fdt/armv7_fdt.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/fdt/armv7_fdt.c      Sun May 28 00:40:20 2017 +0000
@@ -0,0 +1,78 @@
+/* $NetBSD: armv7_fdt.c,v 1.1 2017/05/28 00:40:20 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 <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: armv7_fdt.c,v 1.1 2017/05/28 00:40:20 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+
+#include <machine/cpu.h>
+#include <sys/bus.h>
+
+#include <dev/fdt/fdtvar.h>
+#include <dev/ofw/openfirm.h>
+
+static int     armv7_fdt_match(device_t, cfdata_t, void *);
+static void    armv7_fdt_attach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(armv7_fdt, 0,
+    armv7_fdt_match, armv7_fdt_attach, NULL, NULL);
+
+static bool armv7_fdt_found = false;
+
+extern struct bus_space armv7_generic_bs_tag;
+extern struct bus_space armv7_generic_a4x_bs_tag;
+extern struct arm32_bus_dma_tag armv7_generic_dma_tag;
+
+int
+armv7_fdt_match(device_t parent, cfdata_t cf, void *aux)
+{
+       if (armv7_fdt_found)
+               return 0;
+       return 1;
+}
+
+void
+armv7_fdt_attach(device_t parent, device_t self, void *aux)
+{
+       armv7_fdt_found = true;
+
+       aprint_naive("\n");
+       aprint_normal("\n");
+
+       struct fdt_attach_args faa = {
+               .faa_name = "",
+               .faa_bst = &armv7_generic_bs_tag,
+               .faa_a4x_bst = &armv7_generic_a4x_bs_tag,
+               .faa_dmat = &armv7_generic_dma_tag,
+               .faa_phandle = OF_peer(0),
+       };
+       config_found(self, &faa, NULL);
+}
diff -r 77c9a9e4184b -r 48267b20ab97 sys/arch/arm/fdt/cpu_fdt.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/fdt/cpu_fdt.c        Sun May 28 00:40:20 2017 +0000
@@ -0,0 +1,91 @@
+/* $NetBSD: cpu_fdt.c,v 1.1 2017/05/28 00:40:20 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2017 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 <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: cpu_fdt.c,v 1.1 2017/05/28 00:40:20 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/device.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+
+#include <dev/fdt/fdtvar.h>
+
+#include <arm/cpu.h>
+
+static int     cpu_fdt_match(device_t, cfdata_t, void *);
+static void    cpu_fdt_attach(device_t, device_t, void *);
+
+struct cpu_fdt_softc {
+       device_t                sc_dev;
+       int                     sc_phandle;
+};
+
+CFATTACH_DECL_NEW(cpu_fdt, sizeof(struct cpu_fdt_softc),
+       cpu_fdt_match, cpu_fdt_attach, NULL, NULL);
+
+static int
+cpu_fdt_match(device_t parent, cfdata_t cf, void *aux)
+{
+       const char * const compatible[] = {
+               "arm,cortex-a5",
+               "arm,cortex-a7",
+               "arm,cortex-a8",
+               "arm,cortex-a9",
+               "arm,cortex-a12",
+               "arm,cortex-a15",
+               "arm,cortex-a17",
+               "arm,cortex-a53",
+               "arm,cortex-a57",
+               "arm,cortex-a72",
+               "arm,cortex-a73",
+               NULL
+       };
+       struct fdt_attach_args * const faa = aux;
+
+       return of_compatible(faa->faa_phandle, compatible) >= 0;
+}
+
+static void
+cpu_fdt_attach(device_t parent, device_t self, void *aux)
+{
+       struct cpu_fdt_softc * const sc = device_private(self);
+       struct fdt_attach_args * const faa = aux;
+       bus_addr_t mpidr;
+
+       sc->sc_dev = self;
+       sc->sc_phandle = faa->faa_phandle;
+
+       if (fdtbus_get_reg(sc->sc_phandle, 0, &mpidr, NULL) != 0) {
+               aprint_error(": missing 'reg' property\n");
+               return;
+       }
+
+       cpu_attach(self, mpidr);
+}
diff -r 77c9a9e4184b -r 48267b20ab97 sys/arch/arm/fdt/files.fdt
--- a/sys/arch/arm/fdt/files.fdt        Sun May 28 00:38:40 2017 +0000
+++ b/sys/arch/arm/fdt/files.fdt        Sun May 28 00:40:20 2017 +0000
@@ -1,5 +1,16 @@
-# $NetBSD: files.fdt,v 1.1 2015/12/13 17:45:37 jmcneill Exp $
+# $NetBSD: files.fdt,v 1.2 2017/05/28 00:40:20 jmcneill Exp $
+
+device armv7fdt { }: bus_space_generic, fdtbus
+attach armv7fdt at root with armv7_fdt
+file   arch/arm/fdt/armv7_fdt.c                armv7_fdt
 
-device  gic
+attach cpu at cpus with cpu_fdt
+file   arch/arm/fdt/cpu_fdt.c                  cpu_fdt
+
+device gtmr: mpcorebus
+attach gtmr at fdt with gtmr_fdt
+file   arch/arm/fdt/gtmr_fdt.c                 gtmr_fdt
+
+device  gic: mpcorebus
 attach  gic at fdt with gic_fdt
 file    arch/arm/fdt/gic_fdt.c                 gic_fdt
diff -r 77c9a9e4184b -r 48267b20ab97 sys/arch/arm/fdt/gic_fdt.c
--- a/sys/arch/arm/fdt/gic_fdt.c        Sun May 28 00:38:40 2017 +0000
+++ b/sys/arch/arm/fdt/gic_fdt.c        Sun May 28 00:40:20 2017 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: gic_fdt.c,v 1.2 2016/01/05 21:53:48 marty Exp $ */
+/* $NetBSD: gic_fdt.c,v 1.3 2017/05/28 00:40:20 jmcneill Exp $ */
 
 /*-
- * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
+ * Copyright (c) 2015-2017 Jared McNeill <jmcneill%invisible.ca@localhost>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gic_fdt.c,v 1.2 2016/01/05 21:53:48 marty Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gic_fdt.c,v 1.3 2017/05/28 00:40:20 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -38,6 +38,7 @@
 #include <sys/kmem.h>
 
 #include <arm/cortex/gic_intr.h>
+#include <arm/cortex/mpcore_var.h>
 
 #include <dev/fdt/fdtvar.h>
 
@@ -83,6 +84,9 @@
 {
        struct gic_fdt_softc * const sc = device_private(self);
        struct fdt_attach_args * const faa = aux;
+       bus_addr_t addr_d, addr_c;
+       bus_size_t size_d, size_c;
+       bus_space_handle_t bsh;
        int error;
 
        sc->sc_dev = self;
@@ -97,6 +101,34 @@
 
        aprint_naive("\n");
        aprint_normal(": GIC\n");
+
+       if (fdtbus_get_reg(sc->sc_phandle, 0, &addr_d, &size_d) != 0) {
+               aprint_error(": couldn't get distributor address\n");
+               return;
+       }
+       if (fdtbus_get_reg(sc->sc_phandle, 1, &addr_c, &size_c) != 0) {
+               aprint_error(": couldn't get cpu interface address\n");
+               return;
+       }
+
+       const bus_addr_t addr = addr_d;
+       const bus_size_t size = (addr_c + size_c) - addr_d;
+
+       error = bus_space_map(faa->faa_bst, addr, size, 0, &bsh);
+       if (error) {
+               aprint_error(": couldn't map registers: %d\n", error);
+               return;
+       }
+
+       struct mpcore_attach_args mpcaa = {
+               .mpcaa_name = "armgic",
+               .mpcaa_memt = faa->faa_bst,
+               .mpcaa_memh = bsh,
+               .mpcaa_off1 = 0,
+               .mpcaa_off2 = addr_c - addr_d
+       };
+
+       config_found(self, &mpcaa, NULL);
 }
 
 static void *
diff -r 77c9a9e4184b -r 48267b20ab97 sys/arch/arm/fdt/gtmr_fdt.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/fdt/gtmr_fdt.c       Sun May 28 00:40:20 2017 +0000
@@ -0,0 +1,74 @@
+/* $NetBSD: gtmr_fdt.c,v 1.1 2017/05/28 00:40:20 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2017 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



Home | Main Index | Thread Index | Old Index