106177e52SIan Lepore /*- 206177e52SIan Lepore * Copyright (c) 2013 Thomas Skibo. All rights reserved. 306177e52SIan Lepore * 406177e52SIan Lepore * Redistribution and use in source and binary forms, with or without 506177e52SIan Lepore * modification, are permitted provided that the following conditions 606177e52SIan Lepore * are met: 706177e52SIan Lepore * 1. Redistributions of source code must retain the above copyright 806177e52SIan Lepore * notice, this list of conditions and the following disclaimer. 906177e52SIan Lepore * 2. Redistributions in binary form must reproduce the above copyright 1006177e52SIan Lepore * notice, this list of conditions and the following disclaimer in the 1106177e52SIan Lepore * documentation and/or other materials provided with the distribution. 1206177e52SIan Lepore * 1306177e52SIan Lepore * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1406177e52SIan Lepore * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1506177e52SIan Lepore * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1606177e52SIan Lepore * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1706177e52SIan Lepore * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1806177e52SIan Lepore * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1906177e52SIan Lepore * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2006177e52SIan Lepore * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2106177e52SIan Lepore * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2206177e52SIan Lepore * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2306177e52SIan Lepore */ 2406177e52SIan Lepore 25dc59c854SAndrew Turner #include "opt_platform.h" 26dc59c854SAndrew Turner 2706177e52SIan Lepore #include <sys/cdefs.h> 2806177e52SIan Lepore __FBSDID("$FreeBSD$"); 2906177e52SIan Lepore #include <sys/param.h> 3006177e52SIan Lepore #include <sys/systm.h> 3106177e52SIan Lepore #include <sys/bus.h> 3206177e52SIan Lepore #include <sys/lock.h> 3306177e52SIan Lepore #include <sys/mutex.h> 3406177e52SIan Lepore #include <sys/smp.h> 3506177e52SIan Lepore 36087af50aSAndrew Turner #include <vm/vm.h> 37087af50aSAndrew Turner #include <vm/pmap.h> 38087af50aSAndrew Turner 39a89156f5SMichal Meloun #include <machine/cpu.h> 4006177e52SIan Lepore #include <machine/smp.h> 4106177e52SIan Lepore #include <machine/fdt.h> 4206177e52SIan Lepore #include <machine/intr.h> 43dc59c854SAndrew Turner #include <machine/platformvar.h> 4406177e52SIan Lepore 453185adf0SAndrew Turner #include <arm/xilinx/zy7_machdep.h> 4606177e52SIan Lepore #include <arm/xilinx/zy7_reg.h> 47*80d7c14cSJohn-Mark Gurney #include <arm/xilinx/zy7_slcr.h> 4806177e52SIan Lepore 4906177e52SIan Lepore #define ZYNQ7_CPU1_ENTRY 0xfffffff0 5006177e52SIan Lepore 5197665af9SIan Lepore #define SCU_CONTROL_REG 0xf8f00000 52*80d7c14cSJohn-Mark Gurney #define SCU_CONTROL_ENABLE 1 53*80d7c14cSJohn-Mark Gurney #define SCU_CONFIG_REG 0xf8f00004 54*80d7c14cSJohn-Mark Gurney #define SCU_CONFIG_N_CPUS_MASK 3 55*80d7c14cSJohn-Mark Gurney 56*80d7c14cSJohn-Mark Gurney #define SLCR_PSS_IDCODE 0xf8000530 5797665af9SIan Lepore 5806177e52SIan Lepore void 59dc59c854SAndrew Turner zynq7_mp_setmaxid(platform_t plat) 6006177e52SIan Lepore { 61*80d7c14cSJohn-Mark Gurney bus_space_handle_t slcr_handle; 62*80d7c14cSJohn-Mark Gurney int device_id; 63*80d7c14cSJohn-Mark Gurney bus_space_handle_t scu_handle; 6406177e52SIan Lepore 65*80d7c14cSJohn-Mark Gurney if (mp_ncpus != 0) 66*80d7c14cSJohn-Mark Gurney return; 67*80d7c14cSJohn-Mark Gurney 68*80d7c14cSJohn-Mark Gurney /* Map in SLCR PSS_IDCODE register. */ 69*80d7c14cSJohn-Mark Gurney if (bus_space_map(fdtbus_bs_tag, SLCR_PSS_IDCODE, 4, 0, 70*80d7c14cSJohn-Mark Gurney &slcr_handle) != 0) 71*80d7c14cSJohn-Mark Gurney panic("%s: Could not map SLCR IDCODE reg.\n", __func__); 72*80d7c14cSJohn-Mark Gurney 73*80d7c14cSJohn-Mark Gurney device_id = bus_space_read_4(fdtbus_bs_tag, slcr_handle, 0) & 74*80d7c14cSJohn-Mark Gurney ZY7_SLCR_PSS_IDCODE_DEVICE_MASK; 75*80d7c14cSJohn-Mark Gurney 76*80d7c14cSJohn-Mark Gurney bus_space_unmap(fdtbus_bs_tag, slcr_handle, 4); 77*80d7c14cSJohn-Mark Gurney 78*80d7c14cSJohn-Mark Gurney /* 79*80d7c14cSJohn-Mark Gurney * Zynq XC7z0xxS single core chips indicate incorrect number of CPUs in 80*80d7c14cSJohn-Mark Gurney * SCU configuration register. 81*80d7c14cSJohn-Mark Gurney */ 82*80d7c14cSJohn-Mark Gurney if (device_id == ZY7_SLCR_PSS_IDCODE_DEVICE_7Z007S || 83*80d7c14cSJohn-Mark Gurney device_id == ZY7_SLCR_PSS_IDCODE_DEVICE_7Z012S || 84*80d7c14cSJohn-Mark Gurney device_id == ZY7_SLCR_PSS_IDCODE_DEVICE_7Z014S) { 85*80d7c14cSJohn-Mark Gurney mp_maxid = 0; 86*80d7c14cSJohn-Mark Gurney mp_ncpus = 1; 87*80d7c14cSJohn-Mark Gurney return; 88*80d7c14cSJohn-Mark Gurney } 89*80d7c14cSJohn-Mark Gurney 90*80d7c14cSJohn-Mark Gurney /* Map in SCU config register. */ 91*80d7c14cSJohn-Mark Gurney if (bus_space_map(fdtbus_bs_tag, SCU_CONFIG_REG, 4, 0, 92*80d7c14cSJohn-Mark Gurney &scu_handle) != 0) 93*80d7c14cSJohn-Mark Gurney panic("zynq7_mp_setmaxid: Could not map SCU config reg.\n"); 94*80d7c14cSJohn-Mark Gurney 95*80d7c14cSJohn-Mark Gurney mp_maxid = bus_space_read_4(fdtbus_bs_tag, scu_handle, 0) & 96*80d7c14cSJohn-Mark Gurney SCU_CONFIG_N_CPUS_MASK; 97*80d7c14cSJohn-Mark Gurney mp_ncpus = mp_maxid + 1; 98*80d7c14cSJohn-Mark Gurney 99*80d7c14cSJohn-Mark Gurney bus_space_unmap(fdtbus_bs_tag, scu_handle, 4); 10006177e52SIan Lepore } 10106177e52SIan Lepore 10206177e52SIan Lepore void 103dc59c854SAndrew Turner zynq7_mp_start_ap(platform_t plat) 10406177e52SIan Lepore { 10597665af9SIan Lepore bus_space_handle_t scu_handle; 10606177e52SIan Lepore bus_space_handle_t ocm_handle; 10797665af9SIan Lepore uint32_t scu_ctrl; 10897665af9SIan Lepore 10997665af9SIan Lepore /* Map in SCU control register. */ 11097665af9SIan Lepore if (bus_space_map(fdtbus_bs_tag, SCU_CONTROL_REG, 4, 11197665af9SIan Lepore 0, &scu_handle) != 0) 1124ee4e0cdSJohn-Mark Gurney panic("%s: Could not map SCU control reg.\n", __func__); 11397665af9SIan Lepore 11497665af9SIan Lepore /* Set SCU enable bit. */ 11597665af9SIan Lepore scu_ctrl = bus_space_read_4(fdtbus_bs_tag, scu_handle, 0); 11697665af9SIan Lepore scu_ctrl |= SCU_CONTROL_ENABLE; 11797665af9SIan Lepore bus_space_write_4(fdtbus_bs_tag, scu_handle, 0, scu_ctrl); 11897665af9SIan Lepore 11997665af9SIan Lepore bus_space_unmap(fdtbus_bs_tag, scu_handle, 4); 12006177e52SIan Lepore 12106177e52SIan Lepore /* Map in magic location to give entry address to CPU1. */ 12206177e52SIan Lepore if (bus_space_map(fdtbus_bs_tag, ZYNQ7_CPU1_ENTRY, 4, 12306177e52SIan Lepore 0, &ocm_handle) != 0) 1244ee4e0cdSJohn-Mark Gurney panic("%s: Could not map OCM\n", __func__); 12506177e52SIan Lepore 12606177e52SIan Lepore /* Write start address for CPU1. */ 12706177e52SIan Lepore bus_space_write_4(fdtbus_bs_tag, ocm_handle, 0, 12806177e52SIan Lepore pmap_kextract((vm_offset_t)mpentry)); 12906177e52SIan Lepore 13097665af9SIan Lepore bus_space_unmap(fdtbus_bs_tag, ocm_handle, 4); 13197665af9SIan Lepore 13206177e52SIan Lepore /* 13397665af9SIan Lepore * The SCU is enabled above but I think the second CPU doesn't 13406177e52SIan Lepore * turn on filtering until after the wake-up below. I think that's why 13506177e52SIan Lepore * things don't work if I don't put these cache ops here. Also, the 13606177e52SIan Lepore * magic location, 0xfffffff0, isn't in the SCU's filtering range so it 13706177e52SIan Lepore * needs a write-back too. 13806177e52SIan Lepore */ 139a89156f5SMichal Meloun dcache_wbinv_poc_all(); 14006177e52SIan Lepore 14106177e52SIan Lepore /* Wake up CPU1. */ 1427cc70732SMichal Meloun dsb(); 1437cc70732SMichal Meloun sev(); 14406177e52SIan Lepore } 145