1265099Sian/*- 2265099Sian * Copyright (c) 2013 Thomas Skibo. All rights reserved. 3265099Sian * 4265099Sian * Redistribution and use in source and binary forms, with or without 5265099Sian * modification, are permitted provided that the following conditions 6265099Sian * are met: 7265099Sian * 1. Redistributions of source code must retain the above copyright 8265099Sian * notice, this list of conditions and the following disclaimer. 9265099Sian * 2. Redistributions in binary form must reproduce the above copyright 10265099Sian * notice, this list of conditions and the following disclaimer in the 11265099Sian * documentation and/or other materials provided with the distribution. 12265099Sian * 13265099Sian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14265099Sian * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15265099Sian * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16265099Sian * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17265099Sian * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18265099Sian * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19265099Sian * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20265099Sian * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21265099Sian * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22265099Sian * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23265099Sian */ 24265099Sian 25265099Sian#include <sys/cdefs.h> 26265099Sian__FBSDID("$FreeBSD$"); 27265099Sian#include <sys/param.h> 28265099Sian#include <sys/systm.h> 29265099Sian#include <sys/bus.h> 30265099Sian#include <sys/lock.h> 31265099Sian#include <sys/mutex.h> 32265099Sian#include <sys/smp.h> 33265099Sian 34265099Sian#include <machine/smp.h> 35265099Sian#include <machine/fdt.h> 36265099Sian#include <machine/intr.h> 37265099Sian 38265099Sian#include <arm/xilinx/zy7_reg.h> 39265099Sian 40265099Sian#define ZYNQ7_CPU1_ENTRY 0xfffffff0 41265099Sian 42278701Sian#define SCU_CONTROL_REG 0xf8f00000 43278701Sian#define SCU_CONTROL_ENABLE (1 << 0) 44278701Sian 45265099Sianvoid 46265099Sianplatform_mp_init_secondary(void) 47265099Sian{ 48265099Sian 49265099Sian gic_init_secondary(); 50265099Sian} 51265099Sian 52265099Sianvoid 53265099Sianplatform_mp_setmaxid(void) 54265099Sian{ 55265099Sian 56265099Sian mp_maxid = 1; 57265099Sian} 58265099Sian 59265099Sianint 60265099Sianplatform_mp_probe(void) 61265099Sian{ 62265099Sian 63265099Sian mp_ncpus = 2; 64265099Sian return (1); 65265099Sian} 66265099Sian 67265099Sianvoid 68265099Sianplatform_mp_start_ap(void) 69265099Sian{ 70278701Sian bus_space_handle_t scu_handle; 71265099Sian bus_space_handle_t ocm_handle; 72278701Sian uint32_t scu_ctrl; 73265099Sian 74278701Sian /* Map in SCU control register. */ 75278701Sian if (bus_space_map(fdtbus_bs_tag, SCU_CONTROL_REG, 4, 76278701Sian 0, &scu_handle) != 0) 77278701Sian panic("platform_mp_start_ap: Couldn't map SCU config reg\n"); 78278701Sian 79278701Sian /* Set SCU enable bit. */ 80278701Sian scu_ctrl = bus_space_read_4(fdtbus_bs_tag, scu_handle, 0); 81278701Sian scu_ctrl |= SCU_CONTROL_ENABLE; 82278701Sian bus_space_write_4(fdtbus_bs_tag, scu_handle, 0, scu_ctrl); 83278701Sian 84278701Sian bus_space_unmap(fdtbus_bs_tag, scu_handle, 4); 85278701Sian 86265099Sian /* Map in magic location to give entry address to CPU1. */ 87265099Sian if (bus_space_map(fdtbus_bs_tag, ZYNQ7_CPU1_ENTRY, 4, 88265099Sian 0, &ocm_handle) != 0) 89265099Sian panic("platform_mp_start_ap: Couldn't map OCM\n"); 90265099Sian 91265099Sian /* Write start address for CPU1. */ 92265099Sian bus_space_write_4(fdtbus_bs_tag, ocm_handle, 0, 93265099Sian pmap_kextract((vm_offset_t)mpentry)); 94265099Sian 95278701Sian bus_space_unmap(fdtbus_bs_tag, ocm_handle, 4); 96278701Sian 97265099Sian /* 98278701Sian * The SCU is enabled above but I think the second CPU doesn't 99265099Sian * turn on filtering until after the wake-up below. I think that's why 100265099Sian * things don't work if I don't put these cache ops here. Also, the 101265099Sian * magic location, 0xfffffff0, isn't in the SCU's filtering range so it 102265099Sian * needs a write-back too. 103265099Sian */ 104265099Sian cpu_idcache_wbinv_all(); 105265099Sian cpu_l2cache_wbinv_all(); 106265099Sian 107265099Sian /* Wake up CPU1. */ 108265099Sian armv7_sev(); 109265099Sian} 110265099Sian 111265099Sianvoid 112265099Sianplatform_ipi_send(cpuset_t cpus, u_int ipi) 113265099Sian{ 114265099Sian 115265099Sian pic_ipi_send(cpus, ipi); 116265099Sian} 117