Path: blob/main/sys/arm/mv/armadaxp/armadaxp_mp.c
108674 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2011 Semihalf.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#include <sys/param.h>29#include <sys/systm.h>30#include <sys/bus.h>31#include <sys/lock.h>32#include <sys/mutex.h>33#include <sys/smp.h>3435#include <vm/vm.h>36#include <vm/vm_kern.h>37#include <vm/vm_extern.h>38#include <vm/pmap.h>3940#include <dev/fdt/fdt_common.h>4142#include <machine/cpu.h>43#include <machine/smp.h>44#include <machine/fdt.h>45#include <machine/armreg.h>4647#include <arm/mv/mvwin.h>48#include <arm/mv/mvvar.h>4950#include <machine/platformvar.h>5152#define MV_AXP_CPU_DIVCLK_BASE (MV_BASE + 0x18700)53#define CPU_DIVCLK_CTRL0 0x0054#define CPU_DIVCLK_CTRL2_RATIO_FULL0 0x0855#define CPU_DIVCLK_CTRL2_RATIO_FULL1 0x0c56#define CPU_DIVCLK_MASK(x) (~(0xff << (8 * (x))))5758#define CPU_PMU(x) (MV_BASE + 0x22100 + (0x100 * (x)))59#define CPU_PMU_BOOT 0x246061#define MP (MV_BASE + 0x20800)62#define MP_SW_RESET(x) ((x) * 8)6364#define CPU_RESUME_CONTROL (0x20988)6566void armadaxp_init_coher_fabric(void);67int platform_get_ncpus(void);6869void mv_axp_platform_mp_setmaxid(platform_t plat);70void mv_axp_platform_mp_start_ap(platform_t plat);7172/* Coherency Fabric registers */73static uint32_t74read_cpu_clkdiv(uint32_t reg)75{7677return (bus_space_read_4(fdtbus_bs_tag, MV_AXP_CPU_DIVCLK_BASE, reg));78}7980static void81write_cpu_clkdiv(uint32_t reg, uint32_t val)82{8384bus_space_write_4(fdtbus_bs_tag, MV_AXP_CPU_DIVCLK_BASE, reg, val);85}8687void88mv_axp_platform_mp_setmaxid(platform_t plat)89{9091mp_ncpus = platform_get_ncpus();92mp_maxid = mp_ncpus - 1;93}9495void mptramp(void);96void mptramp_end(void);97extern vm_offset_t mptramp_pmu_boot;9899void100mv_axp_platform_mp_start_ap(platform_t plat)101{102uint32_t reg, *src, *dst, cpu_num, div_val, cputype;103vm_offset_t pmu_boot_off;104/*105* Initialization procedure depends on core revision,106* in this step CHIP ID is checked to choose proper procedure107*/108cputype = cp15_midr_get();109cputype &= CPU_ID_CPU_MASK;110111/*112* Set the PA of CPU0 Boot Address Redirect register used in113* mptramp according to the actual SoC registers' base address.114*/115pmu_boot_off = (CPU_PMU(0) - MV_BASE) + CPU_PMU_BOOT;116mptramp_pmu_boot = fdt_immr_pa + pmu_boot_off;117dst = pmap_mapdev(0xffff0000, PAGE_SIZE);118for (src = (uint32_t *)mptramp; src < (uint32_t *)mptramp_end;119src++, dst++) {120*dst = *src;121}122pmap_unmapdev(dst, PAGE_SIZE);123if (cputype == CPU_ID_MV88SV584X_V7) {124/* Core rev A0 */125div_val = read_cpu_clkdiv(CPU_DIVCLK_CTRL2_RATIO_FULL1);126div_val &= 0x3f;127128for (cpu_num = 1; cpu_num < mp_ncpus; cpu_num++ ) {129reg = read_cpu_clkdiv(CPU_DIVCLK_CTRL2_RATIO_FULL1);130reg &= CPU_DIVCLK_MASK(cpu_num);131reg |= div_val << (cpu_num * 8);132write_cpu_clkdiv(CPU_DIVCLK_CTRL2_RATIO_FULL1, reg);133}134} else {135/* Core rev Z1 */136div_val = 0x01;137138if (mp_ncpus > 1) {139reg = read_cpu_clkdiv(CPU_DIVCLK_CTRL2_RATIO_FULL0);140reg &= CPU_DIVCLK_MASK(3);141reg |= div_val << 24;142write_cpu_clkdiv(CPU_DIVCLK_CTRL2_RATIO_FULL0, reg);143}144145for (cpu_num = 2; cpu_num < mp_ncpus; cpu_num++ ) {146reg = read_cpu_clkdiv(CPU_DIVCLK_CTRL2_RATIO_FULL1);147reg &= CPU_DIVCLK_MASK(cpu_num);148reg |= div_val << (cpu_num * 8);149write_cpu_clkdiv(CPU_DIVCLK_CTRL2_RATIO_FULL1, reg);150}151}152153reg = read_cpu_clkdiv(CPU_DIVCLK_CTRL0);154reg |= ((0x1 << (mp_ncpus - 1)) - 1) << 21;155write_cpu_clkdiv(CPU_DIVCLK_CTRL0, reg);156reg = read_cpu_clkdiv(CPU_DIVCLK_CTRL0);157reg |= 0x01000000;158write_cpu_clkdiv(CPU_DIVCLK_CTRL0, reg);159160DELAY(100);161reg &= ~(0xf << 21);162write_cpu_clkdiv(CPU_DIVCLK_CTRL0, reg);163DELAY(100);164165bus_space_write_4(fdtbus_bs_tag, MV_BASE, CPU_RESUME_CONTROL, 0);166167for (cpu_num = 1; cpu_num < mp_ncpus; cpu_num++ )168bus_space_write_4(fdtbus_bs_tag, CPU_PMU(cpu_num), CPU_PMU_BOOT,169pmap_kextract((vm_offset_t)mpentry));170171dcache_wbinv_poc_all();172173for (cpu_num = 1; cpu_num < mp_ncpus; cpu_num++ )174bus_space_write_4(fdtbus_bs_tag, MP, MP_SW_RESET(cpu_num), 0);175176/* XXX: Temporary workaround for hangup after releasing AP's */177wmb();178DELAY(10);179180armadaxp_init_coher_fabric();181}182183184