xref: /freebsd/sys/arm/xilinx/zy7_mp.c (revision 087af50ab850785c51c7139e2f6379e5bd2865fe)
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 
2506177e52SIan Lepore #include <sys/cdefs.h>
2606177e52SIan Lepore __FBSDID("$FreeBSD$");
2706177e52SIan Lepore #include <sys/param.h>
2806177e52SIan Lepore #include <sys/systm.h>
2906177e52SIan Lepore #include <sys/bus.h>
3006177e52SIan Lepore #include <sys/lock.h>
3106177e52SIan Lepore #include <sys/mutex.h>
3206177e52SIan Lepore #include <sys/smp.h>
3306177e52SIan Lepore 
34*087af50aSAndrew Turner #include <vm/vm.h>
35*087af50aSAndrew Turner #include <vm/pmap.h>
36*087af50aSAndrew Turner 
3706177e52SIan Lepore #include <machine/smp.h>
3806177e52SIan Lepore #include <machine/fdt.h>
3906177e52SIan Lepore #include <machine/intr.h>
4006177e52SIan Lepore 
4106177e52SIan Lepore #include <arm/xilinx/zy7_reg.h>
4206177e52SIan Lepore 
4306177e52SIan Lepore #define	ZYNQ7_CPU1_ENTRY	0xfffffff0
4406177e52SIan Lepore 
4597665af9SIan Lepore #define	SCU_CONTROL_REG		0xf8f00000
4697665af9SIan Lepore #define	   SCU_CONTROL_ENABLE	(1 << 0)
4797665af9SIan Lepore 
4806177e52SIan Lepore void
4906177e52SIan Lepore platform_mp_init_secondary(void)
5006177e52SIan Lepore {
5106177e52SIan Lepore 
523f53a2d6SAndrew Turner 	arm_init_secondary_ic();
5306177e52SIan Lepore }
5406177e52SIan Lepore 
5506177e52SIan Lepore void
5606177e52SIan Lepore platform_mp_setmaxid(void)
5706177e52SIan Lepore {
5806177e52SIan Lepore 
5906177e52SIan Lepore 	mp_maxid = 1;
6006177e52SIan Lepore }
6106177e52SIan Lepore 
6206177e52SIan Lepore int
6306177e52SIan Lepore platform_mp_probe(void)
6406177e52SIan Lepore {
6506177e52SIan Lepore 
6606177e52SIan Lepore 	mp_ncpus = 2;
6706177e52SIan Lepore 	return (1);
6806177e52SIan Lepore }
6906177e52SIan Lepore 
7006177e52SIan Lepore void
7106177e52SIan Lepore platform_mp_start_ap(void)
7206177e52SIan Lepore {
7397665af9SIan Lepore 	bus_space_handle_t scu_handle;
7406177e52SIan Lepore 	bus_space_handle_t ocm_handle;
7597665af9SIan Lepore 	uint32_t scu_ctrl;
7697665af9SIan Lepore 
7797665af9SIan Lepore 	/* Map in SCU control register. */
7897665af9SIan Lepore 	if (bus_space_map(fdtbus_bs_tag, SCU_CONTROL_REG, 4,
7997665af9SIan Lepore 			  0, &scu_handle) != 0)
8097665af9SIan Lepore 		panic("platform_mp_start_ap: Couldn't map SCU config reg\n");
8197665af9SIan Lepore 
8297665af9SIan Lepore 	/* Set SCU enable bit. */
8397665af9SIan Lepore 	scu_ctrl = bus_space_read_4(fdtbus_bs_tag, scu_handle, 0);
8497665af9SIan Lepore 	scu_ctrl |= SCU_CONTROL_ENABLE;
8597665af9SIan Lepore 	bus_space_write_4(fdtbus_bs_tag, scu_handle, 0, scu_ctrl);
8697665af9SIan Lepore 
8797665af9SIan Lepore 	bus_space_unmap(fdtbus_bs_tag, scu_handle, 4);
8806177e52SIan Lepore 
8906177e52SIan Lepore 	/* Map in magic location to give entry address to CPU1. */
9006177e52SIan Lepore 	if (bus_space_map(fdtbus_bs_tag, ZYNQ7_CPU1_ENTRY, 4,
9106177e52SIan Lepore 	    0, &ocm_handle) != 0)
9206177e52SIan Lepore 		panic("platform_mp_start_ap: Couldn't map OCM\n");
9306177e52SIan Lepore 
9406177e52SIan Lepore 	/* Write start address for CPU1. */
9506177e52SIan Lepore 	bus_space_write_4(fdtbus_bs_tag, ocm_handle, 0,
9606177e52SIan Lepore 	    pmap_kextract((vm_offset_t)mpentry));
9706177e52SIan Lepore 
9897665af9SIan Lepore 	bus_space_unmap(fdtbus_bs_tag, ocm_handle, 4);
9997665af9SIan Lepore 
10006177e52SIan Lepore 	/*
10197665af9SIan Lepore 	 * The SCU is enabled above but I think the second CPU doesn't
10206177e52SIan Lepore 	 * turn on filtering until after the wake-up below. I think that's why
10306177e52SIan Lepore 	 * things don't work if I don't put these cache ops here.  Also, the
10406177e52SIan Lepore 	 * magic location, 0xfffffff0, isn't in the SCU's filtering range so it
10506177e52SIan Lepore 	 * needs a write-back too.
10606177e52SIan Lepore 	 */
10706177e52SIan Lepore 	cpu_idcache_wbinv_all();
10806177e52SIan Lepore 	cpu_l2cache_wbinv_all();
10906177e52SIan Lepore 
11006177e52SIan Lepore 	/* Wake up CPU1. */
11106177e52SIan Lepore 	armv7_sev();
11206177e52SIan Lepore }
11306177e52SIan Lepore 
11406177e52SIan Lepore void
11506177e52SIan Lepore platform_ipi_send(cpuset_t cpus, u_int ipi)
11606177e52SIan Lepore {
11706177e52SIan Lepore 
11806177e52SIan Lepore 	pic_ipi_send(cpus, ipi);
11906177e52SIan Lepore }
120