Path: blob/main/sys/arm/mv/armada38x/armada38x_mp.c
39537 views
/*-1* Copyright (c) 2015 Semihalf.2* Copyright (c) 2015 Stormshield.3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*/2627#include <sys/param.h>28#include <sys/systm.h>29#include <sys/bus.h>30#include <sys/smp.h>3132#include <machine/smp.h>33#include <machine/fdt.h>34#include <machine/intr.h>35#include <machine/platformvar.h>3637#include <dev/ofw/ofw_bus.h>38#include <dev/ofw/ofw_bus_subr.h>3940#include <arm/mv/mvreg.h>4142#include "pmsu.h"4344static int cpu_reset_deassert(void);45void mv_a38x_platform_mp_setmaxid(platform_t plate);46void mv_a38x_platform_mp_start_ap(platform_t plate);4748static int49cpu_reset_deassert(void)50{51bus_space_handle_t vaddr;52uint32_t reg;53int rv;5455rv = bus_space_map(fdtbus_bs_tag, (bus_addr_t)MV_CPU_RESET_BASE,56MV_CPU_RESET_REGS_LEN, 0, &vaddr);57if (rv != 0)58return (rv);5960/* CPU1 is held at reset by default - clear assert bit to release it */61reg = bus_space_read_4(fdtbus_bs_tag, vaddr, CPU_RESET_OFFSET(1));62reg &= ~CPU_RESET_ASSERT;6364bus_space_write_4(fdtbus_bs_tag, vaddr, CPU_RESET_OFFSET(1), reg);6566bus_space_unmap(fdtbus_bs_tag, vaddr, MV_CPU_RESET_REGS_LEN);6768return (0);69}7071static int72platform_cnt_cpus(void)73{74bus_space_handle_t vaddr_scu;75phandle_t cpus_node, child;76char device_type[16];77int fdt_cpu_count = 0;78int reg_cpu_count = 0;79uint32_t val;80int rv;8182cpus_node = OF_finddevice("/cpus");83if (cpus_node == -1) {84/* Default is one core */85mp_ncpus = 1;86return (0);87}8889/* Get number of 'cpu' nodes from FDT */90for (child = OF_child(cpus_node); child != 0; child = OF_peer(child)) {91/* Check if child is a CPU */92memset(device_type, 0, sizeof(device_type));93rv = OF_getprop(child, "device_type", device_type,94sizeof(device_type) - 1);95if (rv < 0)96continue;97if (strcmp(device_type, "cpu") != 0)98continue;99100fdt_cpu_count++;101}102103/* Get number of CPU cores from SCU register to cross-check with FDT */104rv = bus_space_map(fdtbus_bs_tag, (bus_addr_t)MV_SCU_BASE,105MV_SCU_REGS_LEN, 0, &vaddr_scu);106if (rv != 0) {107/* Default is one core */108mp_ncpus = 1;109return (0);110}111112val = bus_space_read_4(fdtbus_bs_tag, vaddr_scu, MV_SCU_REG_CONFIG);113bus_space_unmap(fdtbus_bs_tag, vaddr_scu, MV_SCU_REGS_LEN);114reg_cpu_count = (val & SCU_CFG_REG_NCPU_MASK) + 1;115116/* Set mp_ncpus to number of cpus in FDT unless SOC contains only one */117mp_ncpus = min(reg_cpu_count, fdt_cpu_count);118/* mp_ncpus must be at least 1 */119mp_ncpus = max(1, mp_ncpus);120121return (mp_ncpus);122}123124void125mv_a38x_platform_mp_setmaxid(platform_t plate)126{127128/* Armada38x family supports maximum 2 cores */129mp_ncpus = platform_cnt_cpus();130mp_maxid = mp_ncpus - 1;131}132133void134mv_a38x_platform_mp_start_ap(platform_t plate)135{136int rv;137138/* Write secondary entry address to PMSU register */139rv = pmsu_boot_secondary_cpu();140if (rv != 0)141return;142143/* Release CPU1 from reset */144cpu_reset_deassert();145}146147148