Module Name: src Committed By: skrll Date: Mon Jun 12 12:58:17 UTC 2023
Modified Files: src/sys/arch/arm/fdt: files.fdt src/sys/arch/riscv/fdt: files.fdt src/sys/dev/fdt: cpus.c fdtvar.h Added Files: src/sys/arch/arm/fdt: cpus_fdt.c src/sys/arch/riscv/fdt: cpus_fdt.c Log Message: Call / define fdtbus_cpus_md_attach for platforms with cpus @ fdt. The RISC-V binding here seems somewhat of an abuse, but it exists in mainline linux. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/fdt/cpus_fdt.c cvs rdiff -u -r1.34 -r1.35 src/sys/arch/arm/fdt/files.fdt cvs rdiff -u -r0 -r1.1 src/sys/arch/riscv/fdt/cpus_fdt.c cvs rdiff -u -r1.1 -r1.2 src/sys/arch/riscv/fdt/files.fdt cvs rdiff -u -r1.7 -r1.8 src/sys/dev/fdt/cpus.c cvs rdiff -u -r1.78 -r1.79 src/sys/dev/fdt/fdtvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/arm/fdt/files.fdt diff -u src/sys/arch/arm/fdt/files.fdt:1.34 src/sys/arch/arm/fdt/files.fdt:1.35 --- src/sys/arch/arm/fdt/files.fdt:1.34 Thu Jul 22 00:47:55 2021 +++ src/sys/arch/arm/fdt/files.fdt Mon Jun 12 12:58:17 2023 @@ -1,4 +1,4 @@ -# $NetBSD: files.fdt,v 1.34 2021/07/22 00:47:55 jmcneill Exp $ +# $NetBSD: files.fdt,v 1.35 2023/06/12 12:58:17 skrll Exp $ include "dev/pckbport/files.pckbport" @@ -7,6 +7,7 @@ attach armfdt at root with arm_fdt file arch/arm/fdt/arm_fdt.c arm_fdt file arch/arm/fdt/arm_platform.c arm_fdt & gtmr_fdt & psci_fdt file arch/arm/fdt/arm_simplefb.c arm_fdt & wsdisplay & genfb +file arch/arm/fdt/cpus_fdt.c arm_fdt attach cpu at fdt with cpu_fdt file arch/arm/fdt/cpu_fdt.c cpu_fdt Index: src/sys/arch/riscv/fdt/files.fdt diff -u src/sys/arch/riscv/fdt/files.fdt:1.1 src/sys/arch/riscv/fdt/files.fdt:1.2 --- src/sys/arch/riscv/fdt/files.fdt:1.1 Sun May 7 12:41:48 2023 +++ src/sys/arch/riscv/fdt/files.fdt Mon Jun 12 12:58:17 2023 @@ -1,11 +1,11 @@ -# $NetBSD: files.fdt,v 1.1 2023/05/07 12:41:48 skrll Exp $ +# $NetBSD: files.fdt,v 1.2 2023/06/12 12:58:17 skrll Exp $ include "dev/pckbport/files.pckbport" file arch/riscv/fdt/riscv_platform.c +file arch/riscv/fdt/cpus_fdt.c file arch/riscv/fdt/fdt_dma_machdep.c -file arch/riscv/fdt/fdt_cpus_machdep.c attach cpu at fdt with cpu_fdt file arch/riscv/fdt/cpu_fdt.c cpu_fdt Index: src/sys/dev/fdt/cpus.c diff -u src/sys/dev/fdt/cpus.c:1.7 src/sys/dev/fdt/cpus.c:1.8 --- src/sys/dev/fdt/cpus.c:1.7 Sun May 7 12:41:49 2023 +++ src/sys/dev/fdt/cpus.c Mon Jun 12 12:58:17 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: cpus.c,v 1.7 2023/05/07 12:41:49 skrll Exp $ */ +/* $NetBSD: cpus.c,v 1.8 2023/06/12 12:58:17 skrll Exp $ */ /*- * Copyright (c) 2017 Jared McNeill <jmcne...@invisible.ca> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cpus.c,v 1.7 2023/05/07 12:41:49 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cpus.c,v 1.8 2023/06/12 12:58:17 skrll Exp $"); #include <sys/param.h> #include <sys/bus.h> @@ -39,10 +39,6 @@ __KERNEL_RCSID(0, "$NetBSD: cpus.c,v 1.7 #include <dev/fdt/fdtvar.h> -#ifdef __riscv -#include <machine/machdep.h> -#endif - static int cpus_match(device_t, cfdata_t, void *); static void cpus_attach(device_t, device_t, void *); @@ -68,9 +64,8 @@ cpus_attach(device_t parent, device_t se aprint_naive("\n"); aprint_normal("\n"); -#ifdef __riscv - cpus_fdt_md_attach(parent, self, faa); -#endif + fdtbus_cpus_md_attach(parent, self, faa); + for (child = OF_child(phandle); child; child = OF_peer(child)) { if (!cpus_cpu_enabled(child)) continue; Index: src/sys/dev/fdt/fdtvar.h diff -u src/sys/dev/fdt/fdtvar.h:1.78 src/sys/dev/fdt/fdtvar.h:1.79 --- src/sys/dev/fdt/fdtvar.h:1.78 Fri Apr 7 08:55:31 2023 +++ src/sys/dev/fdt/fdtvar.h Mon Jun 12 12:58:17 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: fdtvar.h,v 1.78 2023/04/07 08:55:31 skrll Exp $ */ +/* $NetBSD: fdtvar.h,v 1.79 2023/06/12 12:58:17 skrll Exp $ */ /*- * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca> @@ -552,6 +552,8 @@ const char * fdtbus_get_string(int, cons const char * fdtbus_get_string_index(int, const char *, u_int); int fdtbus_get_index(int, const char *, const char *, u_int *); +void fdtbus_cpus_md_attach(device_t, device_t, void *); + void fdt_add_bus(device_t, int, struct fdt_attach_args *); void fdt_add_bus_match(device_t, int, struct fdt_attach_args *, bool (*)(void *, int), void *); Added files: Index: src/sys/arch/arm/fdt/cpus_fdt.c diff -u /dev/null src/sys/arch/arm/fdt/cpus_fdt.c:1.1 --- /dev/null Mon Jun 12 12:58:17 2023 +++ src/sys/arch/arm/fdt/cpus_fdt.c Mon Jun 12 12:58:17 2023 @@ -0,0 +1,43 @@ +/* $NetBSD: cpus_fdt.c,v 1.1 2023/06/12 12:58:17 skrll Exp $ */ + +/*- + * Copyright (c) 2023 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Nick Hudson + * + * 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: cpus_fdt.c,v 1.1 2023/06/12 12:58:17 skrll Exp $"); + +#include <sys/param.h> +#include <sys/types.h> + +#include <dev/fdt/fdtvar.h> + +void +fdtbus_cpus_md_attach(device_t parent, device_t self, void *aux) +{ +} Index: src/sys/arch/riscv/fdt/cpus_fdt.c diff -u /dev/null src/sys/arch/riscv/fdt/cpus_fdt.c:1.1 --- /dev/null Mon Jun 12 12:58:17 2023 +++ src/sys/arch/riscv/fdt/cpus_fdt.c Mon Jun 12 12:58:17 2023 @@ -0,0 +1,55 @@ +/* $NetBSD: cpus_fdt.c,v 1.1 2023/06/12 12:58:17 skrll Exp $ */ + +/*- + * Copyright (c) 2023 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Nick Hudson + * + * 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: cpus_fdt.c,v 1.1 2023/06/12 12:58:17 skrll Exp $"); + +#include <sys/param.h> +#include <sys/types.h> + +#include <dev/fdt/fdtvar.h> + +#include <machine/machdep.h> + +void +fdtbus_cpus_md_attach(device_t parent, device_t self, void *aux) +{ + struct fdt_attach_args * const faa = aux; + const int cpus = faa->faa_phandle; + + uint32_t tbfreq; + int ret = of_getprop_uint32(cpus, "timebase-frequency", &tbfreq); + if (ret < 0) { + aprint_error(": can't get timebase frequency\n"); + return; + } + riscv_timer_frequency_set(tbfreq); +}