Path: blob/main/sys/arm/broadcom/bcm2835/bcm2836_mp.c
39566 views
/*-1* Copyright (C) 2015 Daisuke Aoyama <[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 AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15*16* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*28*/2930#include <sys/param.h>31#include <sys/systm.h>32#include <sys/kernel.h>33#include <sys/bus.h>34#include <sys/smp.h>3536#include <vm/vm.h>37#include <vm/pmap.h>3839#include <machine/cpu.h>40#include <machine/smp.h>41#include <machine/bus.h>42#include <machine/fdt.h>43#include <machine/intr.h>44#include <machine/platformvar.h>4546#include <arm/broadcom/bcm2835/bcm2836_mp.h>4748#ifdef DEBUG49#define DPRINTF(fmt, ...) do { \50printf("%s:%u: ", __func__, __LINE__); \51printf(fmt, ##__VA_ARGS__); \52} while (0)53#else54#define DPRINTF(fmt, ...)55#endif5657#define ARM_LOCAL_BASE 0x4000000058#define ARM_LOCAL_SIZE 0x000010005960/* mailbox registers */61#define MBOXINTRCTRL_CORE(n) (0x00000050 + (0x04 * (n)))62#define MBOX0SET_CORE(n) (0x00000080 + (0x10 * (n)))63#define MBOX1SET_CORE(n) (0x00000084 + (0x10 * (n)))64#define MBOX2SET_CORE(n) (0x00000088 + (0x10 * (n)))65#define MBOX3SET_CORE(n) (0x0000008C + (0x10 * (n)))66#define MBOX0CLR_CORE(n) (0x000000C0 + (0x10 * (n)))67#define MBOX1CLR_CORE(n) (0x000000C4 + (0x10 * (n)))68#define MBOX2CLR_CORE(n) (0x000000C8 + (0x10 * (n)))69#define MBOX3CLR_CORE(n) (0x000000CC + (0x10 * (n)))7071static bus_space_handle_t bs_periph;7273#define BSRD4(addr) \74bus_space_read_4(fdtbus_bs_tag, bs_periph, (addr))75#define BSWR4(addr, val) \76bus_space_write_4(fdtbus_bs_tag, bs_periph, (addr), (val))7778void79bcm2836_mp_setmaxid(platform_t plat)80{8182DPRINTF("platform_mp_setmaxid\n");83if (mp_ncpus != 0)84return;8586mp_ncpus = 4;87mp_maxid = mp_ncpus - 1;88DPRINTF("mp_maxid=%d\n", mp_maxid);89}9091void92bcm2836_mp_start_ap(platform_t plat)93{94uint32_t val;95int i, retry;9697DPRINTF("platform_mp_start_ap\n");9899/* initialize */100if (bus_space_map(fdtbus_bs_tag, ARM_LOCAL_BASE, ARM_LOCAL_SIZE,1010, &bs_periph) != 0)102panic("can't map local peripheral\n");103for (i = 0; i < mp_ncpus; i++) {104/* clear mailbox 0/3 */105BSWR4(MBOX0CLR_CORE(i), 0xffffffff);106BSWR4(MBOX3CLR_CORE(i), 0xffffffff);107}108wmb();109dcache_wbinv_poc_all();110111/* boot secondary CPUs */112for (i = 1; i < mp_ncpus; i++) {113/* set entry point to mailbox 3 */114BSWR4(MBOX3SET_CORE(i),115(uint32_t)pmap_kextract((vm_offset_t)mpentry));116/* Firmware put cores in WFE state, need SEV to wake up. */117dsb();118sev();119120/* wait for bootup */121retry = 1000;122do {123/* check entry point */124val = BSRD4(MBOX3CLR_CORE(i));125if (val == 0)126break;127DELAY(100);128retry--;129if (retry <= 0) {130printf("can't start for CPU%d\n", i);131break;132}133} while (1);134135/* dsb and sev */136dsb();137sev();138139/* recode AP in CPU map */140CPU_SET(i, &all_cpus);141}142}143144145