zy7_mp.c revision 265099
1141098Sdes/*- 2117610Sdes * Copyright (c) 2013 Thomas Skibo. All rights reserved. 3141098Sdes * 4117610Sdes * Redistribution and use in source and binary forms, with or without 5117610Sdes * modification, are permitted provided that the following conditions 6117610Sdes * are met: 7117610Sdes * 1. Redistributions of source code must retain the above copyright 8117610Sdes * notice, this list of conditions and the following disclaimer. 9117610Sdes * 2. Redistributions in binary form must reproduce the above copyright 10117610Sdes * notice, this list of conditions and the following disclaimer in the 11117610Sdes * documentation and/or other materials provided with the distribution. 12117610Sdes * 13117610Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14141098Sdes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15117610Sdes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16141098Sdes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17117610Sdes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18117610Sdes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19141098Sdes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20141098Sdes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21141098Sdes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22141098Sdes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23141098Sdes */ 24141098Sdes 25141098Sdes#include <sys/cdefs.h> 26141098Sdes__FBSDID("$FreeBSD: head/sys/arm/xilinx/zy7_mp.c 265099 2014-04-29 17:48:57Z ian $"); 27117610Sdes#include <sys/param.h> 28117610Sdes#include <sys/systm.h> 29141098Sdes#include <sys/bus.h> 30141098Sdes#include <sys/lock.h> 31141098Sdes#include <sys/mutex.h> 32141098Sdes#include <sys/smp.h> 33141098Sdes 34141098Sdes#include <machine/smp.h> 35141098Sdes#include <machine/fdt.h> 36141098Sdes#include <machine/intr.h> 37141098Sdes 38141098Sdes#include <arm/xilinx/zy7_reg.h> 39141098Sdes 40141098Sdes#define ZYNQ7_CPU1_ENTRY 0xfffffff0 41141098Sdes 42141098Sdesvoid 43141098Sdesplatform_mp_init_secondary(void) 44117610Sdes{ 45141098Sdes 46141098Sdes gic_init_secondary(); 47141098Sdes} 48141098Sdes 49141098Sdesvoid 50141098Sdesplatform_mp_setmaxid(void) 51141098Sdes{ 52141098Sdes 53141098Sdes mp_maxid = 1; 54141098Sdes} 55141098Sdes 56141098Sdesint 57141098Sdesplatform_mp_probe(void) 58141098Sdes{ 59141098Sdes 60141098Sdes mp_ncpus = 2; 61141098Sdes return (1); 62117610Sdes} 63141098Sdes 64141098Sdesvoid 65141098Sdesplatform_mp_start_ap(void) 66141098Sdes{ 67117610Sdes bus_space_handle_t ocm_handle; 68141098Sdes 69141098Sdes /* Map in magic location to give entry address to CPU1. */ 70141098Sdes if (bus_space_map(fdtbus_bs_tag, ZYNQ7_CPU1_ENTRY, 4, 71117610Sdes 0, &ocm_handle) != 0) 72117610Sdes panic("platform_mp_start_ap: Couldn't map OCM\n"); 73141098Sdes 74117610Sdes /* Write start address for CPU1. */ 75117610Sdes bus_space_write_4(fdtbus_bs_tag, ocm_handle, 0, 76117610Sdes pmap_kextract((vm_offset_t)mpentry)); 77117610Sdes 78117610Sdes /* 79141098Sdes * The SCU is enabled by the BOOTROM but I think the second CPU doesn't 80141098Sdes * turn on filtering until after the wake-up below. I think that's why 81141098Sdes * things don't work if I don't put these cache ops here. Also, the 82117610Sdes * magic location, 0xfffffff0, isn't in the SCU's filtering range so it 83141098Sdes * needs a write-back too. 84141098Sdes */ 85141098Sdes cpu_idcache_wbinv_all(); 86141098Sdes cpu_l2cache_wbinv_all(); 87141098Sdes 88117610Sdes /* Wake up CPU1. */ 89117610Sdes armv7_sev(); 90117610Sdes 91117610Sdes bus_space_unmap(fdtbus_bs_tag, ocm_handle, 4); 92117610Sdes} 93117610Sdes 94117610Sdesvoid 95141098Sdesplatform_ipi_send(cpuset_t cpus, u_int ipi) 96117610Sdes{ 97141098Sdes 98117610Sdes pic_ipi_send(cpus, ipi); 99141098Sdes} 100141098Sdes