/*-1* Copyright (c) 2013 Thomas Skibo. All rights reserved.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions5* are met:6* 1. Redistributions of source code must retain the above copyright7* notice, this list of conditions and the following disclaimer.8* 2. Redistributions in binary form must reproduce the above copyright9* notice, this list of conditions and the following disclaimer in the10* documentation and/or other materials provided with the distribution.11*12* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR13* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES14* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.15* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,16* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT17* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,18* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY19* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT20* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF21* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.22*/2324#include "opt_platform.h"2526#include <sys/param.h>27#include <sys/systm.h>28#include <sys/bus.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/smp.h>38#include <machine/fdt.h>39#include <machine/intr.h>40#include <machine/platformvar.h>4142#include <arm/xilinx/zy7_machdep.h>43#include <arm/xilinx/zy7_reg.h>44#include <arm/xilinx/zy7_slcr.h>4546#define ZYNQ7_CPU1_ENTRY 0xfffffff04748#define SCU_CONTROL_REG 0xf8f0000049#define SCU_CONTROL_ENABLE 150#define SCU_CONFIG_REG 0xf8f0000451#define SCU_CONFIG_N_CPUS_MASK 35253#define SLCR_PSS_IDCODE 0xf80005305455void56zynq7_mp_setmaxid(platform_t plat)57{58bus_space_handle_t slcr_handle;59int device_id;60bus_space_handle_t scu_handle;6162if (mp_ncpus != 0)63return;6465/* Map in SLCR PSS_IDCODE register. */66if (bus_space_map(fdtbus_bs_tag, SLCR_PSS_IDCODE, 4, 0,67&slcr_handle) != 0)68panic("%s: Could not map SLCR IDCODE reg.\n", __func__);6970device_id = bus_space_read_4(fdtbus_bs_tag, slcr_handle, 0) &71ZY7_SLCR_PSS_IDCODE_DEVICE_MASK;7273bus_space_unmap(fdtbus_bs_tag, slcr_handle, 4);7475/*76* Zynq XC7z0xxS single core chips indicate incorrect number of CPUs in77* SCU configuration register.78*/79if (device_id == ZY7_SLCR_PSS_IDCODE_DEVICE_7Z007S ||80device_id == ZY7_SLCR_PSS_IDCODE_DEVICE_7Z012S ||81device_id == ZY7_SLCR_PSS_IDCODE_DEVICE_7Z014S) {82mp_maxid = 0;83mp_ncpus = 1;84return;85}8687/* Map in SCU config register. */88if (bus_space_map(fdtbus_bs_tag, SCU_CONFIG_REG, 4, 0,89&scu_handle) != 0)90panic("zynq7_mp_setmaxid: Could not map SCU config reg.\n");9192mp_maxid = bus_space_read_4(fdtbus_bs_tag, scu_handle, 0) &93SCU_CONFIG_N_CPUS_MASK;94mp_ncpus = mp_maxid + 1;9596bus_space_unmap(fdtbus_bs_tag, scu_handle, 4);97}9899void100zynq7_mp_start_ap(platform_t plat)101{102bus_space_handle_t scu_handle;103bus_space_handle_t ocm_handle;104uint32_t scu_ctrl;105106/* Map in SCU control register. */107if (bus_space_map(fdtbus_bs_tag, SCU_CONTROL_REG, 4,1080, &scu_handle) != 0)109panic("%s: Could not map SCU control reg.\n", __func__);110111/* Set SCU enable bit. */112scu_ctrl = bus_space_read_4(fdtbus_bs_tag, scu_handle, 0);113scu_ctrl |= SCU_CONTROL_ENABLE;114bus_space_write_4(fdtbus_bs_tag, scu_handle, 0, scu_ctrl);115116bus_space_unmap(fdtbus_bs_tag, scu_handle, 4);117118/* Map in magic location to give entry address to CPU1. */119if (bus_space_map(fdtbus_bs_tag, ZYNQ7_CPU1_ENTRY, 4,1200, &ocm_handle) != 0)121panic("%s: Could not map OCM\n", __func__);122123/* Write start address for CPU1. */124bus_space_write_4(fdtbus_bs_tag, ocm_handle, 0,125pmap_kextract((vm_offset_t)mpentry));126127bus_space_unmap(fdtbus_bs_tag, ocm_handle, 4);128129/*130* The SCU is enabled above but I think the second CPU doesn't131* turn on filtering until after the wake-up below. I think that's why132* things don't work if I don't put these cache ops here. Also, the133* magic location, 0xfffffff0, isn't in the SCU's filtering range so it134* needs a write-back too.135*/136dcache_wbinv_poc_all();137138/* Wake up CPU1. */139dsb();140sev();141}142143144