Index: sys/conf/options.riscv =================================================================== --- sys/conf/options.riscv +++ sys/conf/options.riscv @@ -4,3 +4,4 @@ FPE opt_global.h INTRNG opt_global.h PLATFORM opt_global.h +SIFIVE_FU540 opt_global.h Index: sys/riscv/sifive/files.sifive =================================================================== --- sys/riscv/sifive/files.sifive +++ sys/riscv/sifive/files.sifive @@ -3,3 +3,4 @@ riscv/sifive/fu540_prci.c standard riscv/sifive/fu540_spi.c optional fu540spi spibus riscv/sifive/sifive_uart.c standard +riscv/sifive/sifive_machdep.c standard Index: sys/riscv/sifive/sifive_machdep.c =================================================================== --- /dev/null +++ sys/riscv/sifive/sifive_machdep.c @@ -0,0 +1,118 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2019 Axiado Corporation + * All rights reserved. + * + * This software was developed in part by Nick O'Brien for Axiado + * Corporation. + * + * 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 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 AUTHOR 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 "opt_platform.h" + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include "platform_if.h" + +#ifdef FDT +#include +#include +#endif + +#if defined(SIFIVE_FU540) + +static platform_attach_t sifive_fu540_attach; +static platform_mp_setmaxid_t sifive_fu540_mp_setmaxid; + +static int +sifive_fu540_attach(platform_t plat) +{ + + return (0); +} + +#ifdef FDT +static boolean_t +cpu_check_mmu(u_int id, phandle_t node, u_int addr_size, pcell_t *reg) +{ + + /* Check if this hart supports MMU. */ + if (OF_getproplen(node, "mmu-type") < 0) + return (0); + + return (1); +} +#endif + +static void +sifive_fu540_mp_setmaxid(platform_t plat) +{ + +#ifdef FDT + int cores; + + cores = ofw_cpu_early_foreach(cpu_check_mmu, true); + if (cores > 0) { + cores = MIN(cores, MAXCPU); + if (bootverbose) + printf("Found %d CPUs in the device tree\n", cores); + mp_ncpus = cores; + mp_maxid = cores - 1; + cpu_enum_method = CPUS_FDT; + return; + } +#endif + + if (bootverbose) + printf("No CPU data, limiting to 1 core\n"); + mp_ncpus = 1; + mp_maxid = 0; +} + +static platform_method_t fu540_methods[] = { + PLATFORMMETHOD(platform_attach, sifive_fu540_attach), + PLATFORMMETHOD(platform_mp_setmaxid, sifive_fu540_mp_setmaxid), + + PLATFORMMETHOD_END, +}; + +FDT_PLATFORM_DEF(fu540, "fu540", 0, "sifive,fu540g"); + +#endif /* SIFIVE_FU540 */