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: releng/11.0/sys/arm/xilinx/zy7_mp.c 296100 2016-02-26 16:04:47Z andrew $");
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
34281092Sandrew#include <vm/vm.h>
35281092Sandrew#include <vm/pmap.h>
36281092Sandrew
37295319Smmel#include <machine/cpu.h>
38265099Sian#include <machine/smp.h>
39265099Sian#include <machine/fdt.h>
40265099Sian#include <machine/intr.h>
41265099Sian
42265099Sian#include <arm/xilinx/zy7_reg.h>
43265099Sian
44265099Sian#define	ZYNQ7_CPU1_ENTRY	0xfffffff0
45265099Sian
46277265Sian#define	SCU_CONTROL_REG		0xf8f00000
47277265Sian#define	   SCU_CONTROL_ENABLE	(1 << 0)
48277265Sian
49265099Sianvoid
50265099Sianplatform_mp_setmaxid(void)
51265099Sian{
52265099Sian
53265099Sian	mp_maxid = 1;
54290547Stijl	mp_ncpus = 2;
55265099Sian}
56265099Sian
57265099Sianvoid
58265099Sianplatform_mp_start_ap(void)
59265099Sian{
60277265Sian	bus_space_handle_t scu_handle;
61265099Sian	bus_space_handle_t ocm_handle;
62277265Sian	uint32_t scu_ctrl;
63265099Sian
64277265Sian	/* Map in SCU control register. */
65277265Sian	if (bus_space_map(fdtbus_bs_tag, SCU_CONTROL_REG, 4,
66277265Sian			  0, &scu_handle) != 0)
67277265Sian		panic("platform_mp_start_ap: Couldn't map SCU config reg\n");
68277265Sian
69277265Sian	/* Set SCU enable bit. */
70277265Sian	scu_ctrl = bus_space_read_4(fdtbus_bs_tag, scu_handle, 0);
71277265Sian	scu_ctrl |= SCU_CONTROL_ENABLE;
72277265Sian	bus_space_write_4(fdtbus_bs_tag, scu_handle, 0, scu_ctrl);
73277265Sian
74277265Sian	bus_space_unmap(fdtbus_bs_tag, scu_handle, 4);
75277265Sian
76265099Sian	/* Map in magic location to give entry address to CPU1. */
77265099Sian	if (bus_space_map(fdtbus_bs_tag, ZYNQ7_CPU1_ENTRY, 4,
78265099Sian	    0, &ocm_handle) != 0)
79265099Sian		panic("platform_mp_start_ap: Couldn't map OCM\n");
80265099Sian
81265099Sian	/* Write start address for CPU1. */
82265099Sian	bus_space_write_4(fdtbus_bs_tag, ocm_handle, 0,
83265099Sian	    pmap_kextract((vm_offset_t)mpentry));
84265099Sian
85277265Sian	bus_space_unmap(fdtbus_bs_tag, ocm_handle, 4);
86277265Sian
87265099Sian	/*
88277265Sian	 * The SCU is enabled above but I think the second CPU doesn't
89265099Sian	 * turn on filtering until after the wake-up below. I think that's why
90265099Sian	 * things don't work if I don't put these cache ops here.  Also, the
91265099Sian	 * magic location, 0xfffffff0, isn't in the SCU's filtering range so it
92265099Sian	 * needs a write-back too.
93265099Sian	 */
94295319Smmel	dcache_wbinv_poc_all();
95265099Sian
96265099Sian	/* Wake up CPU1. */
97265099Sian	armv7_sev();
98265099Sian}
99