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.
This commit is contained in:
skrll 2023-06-12 12:58:17 +00:00
parent a810700be5
commit ecd207b422
6 changed files with 109 additions and 13 deletions

View File

@ -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)
{
}

View File

@ -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

View File

@ -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);
}

View File

@ -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

View File

@ -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 <jmcneill@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 2023/05/07 12:41:49 skrll Exp $");
#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 self, void *aux)
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;

View File

@ -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 <jmcneill@invisible.ca>
@ -552,6 +552,8 @@ const char * fdtbus_get_string(int, const char *);
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 *);