Path: blob/main/sys/arm/nvidia/tegra124/tegra124_mp.c
39507 views
/*-1* Copyright (c) 2016 Michal Meloun <[email protected]>2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR14* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES15* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.16* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,17* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT18* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,19* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY20* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT21* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF22* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.23*/2425#include <sys/param.h>26#include <sys/systm.h>27#include <sys/bus.h>28#include <sys/kernel.h>29#include <sys/lock.h>30#include <sys/mutex.h>31#include <sys/smp.h>3233#include <vm/vm.h>34#include <vm/pmap.h>3536#include <machine/cpu.h>37#include <machine/intr.h>38#include <machine/fdt.h>39#include <machine/smp.h>40#include <machine/platformvar.h>41#include <machine/pmap.h>4243#include <arm/nvidia/tegra124/tegra124_mp.h>4445#define PMC_PHYSBASE 0x7000e40046#define PMC_SIZE 0x40047#define PMC_CONTROL_REG 0x048#define PMC_PWRGATE_TOGGLE 0x3049#define PCM_PWRGATE_TOGGLE_START (1 << 8)50#define PMC_PWRGATE_STATUS 0x385152#define TEGRA_EXCEPTION_VECTORS_BASE 0x6000F000 /* exception vectors */53#define TEGRA_EXCEPTION_VECTORS_SIZE 102454#define TEGRA_EXCEPTION_VECTOR_ENTRY 0x1005556void57tegra124_mp_setmaxid(platform_t plat)58{59int ncpu;6061/* If we've already set the global vars don't bother to do it again. */62if (mp_ncpus != 0)63return;6465/* Read current CP15 Cache Size ID Register */66ncpu = cp15_l2ctlr_get();67ncpu = CPUV7_L2CTLR_NPROC(ncpu);6869mp_ncpus = ncpu;70mp_maxid = ncpu - 1;71}7273void74tegra124_mp_start_ap(platform_t plat)75{76bus_space_handle_t pmc;77bus_space_handle_t exvec;78int i;79uint32_t val;80uint32_t mask;8182if (bus_space_map(fdtbus_bs_tag, PMC_PHYSBASE, PMC_SIZE, 0, &pmc) != 0)83panic("Couldn't map the PMC\n");84if (bus_space_map(fdtbus_bs_tag, TEGRA_EXCEPTION_VECTORS_BASE,85TEGRA_EXCEPTION_VECTORS_SIZE, 0, &exvec) != 0)86panic("Couldn't map the exception vectors\n");8788bus_space_write_4(fdtbus_bs_tag, exvec , TEGRA_EXCEPTION_VECTOR_ENTRY,89pmap_kextract((vm_offset_t)mpentry));90bus_space_read_4(fdtbus_bs_tag, exvec , TEGRA_EXCEPTION_VECTOR_ENTRY);9192/* Wait until POWERGATE is ready (max 20 APB cycles). */93do {94val = bus_space_read_4(fdtbus_bs_tag, pmc,95PMC_PWRGATE_TOGGLE);96} while ((val & PCM_PWRGATE_TOGGLE_START) != 0);9798for (i = 1; i < mp_ncpus; i++) {99val = bus_space_read_4(fdtbus_bs_tag, pmc, PMC_PWRGATE_STATUS);100mask = 1 << (i + 8); /* cpu mask */101if ((val & mask) == 0) {102/* Wait until POWERGATE is ready (max 20 APB cycles). */103do {104val = bus_space_read_4(fdtbus_bs_tag, pmc,105PMC_PWRGATE_TOGGLE);106} while ((val & PCM_PWRGATE_TOGGLE_START) != 0);107bus_space_write_4(fdtbus_bs_tag, pmc,108PMC_PWRGATE_TOGGLE,109PCM_PWRGATE_TOGGLE_START | (8 + i));110111/* Wait until CPU is powered */112do {113val = bus_space_read_4(fdtbus_bs_tag, pmc,114PMC_PWRGATE_STATUS);115} while ((val & mask) == 0);116}117}118dsb();119sev();120bus_space_unmap(fdtbus_bs_tag, pmc, PMC_SIZE);121bus_space_unmap(fdtbus_bs_tag, exvec, TEGRA_EXCEPTION_VECTORS_SIZE);122}123124125