zy7_mp.c revision 265099
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: head/sys/arm/xilinx/zy7_mp.c 265099 2014-04-29 17:48:57Z ian $");
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
42265099Sianvoid
43265099Sianplatform_mp_init_secondary(void)
44265099Sian{
45265099Sian
46265099Sian	gic_init_secondary();
47265099Sian}
48265099Sian
49265099Sianvoid
50265099Sianplatform_mp_setmaxid(void)
51265099Sian{
52265099Sian
53265099Sian	mp_maxid = 1;
54265099Sian}
55265099Sian
56265099Sianint
57265099Sianplatform_mp_probe(void)
58265099Sian{
59265099Sian
60265099Sian	mp_ncpus = 2;
61265099Sian	return (1);
62265099Sian}
63265099Sian
64265099Sianvoid
65265099Sianplatform_mp_start_ap(void)
66265099Sian{
67265099Sian	bus_space_handle_t ocm_handle;
68265099Sian
69265099Sian	/* Map in magic location to give entry address to CPU1. */
70265099Sian	if (bus_space_map(fdtbus_bs_tag, ZYNQ7_CPU1_ENTRY, 4,
71265099Sian	    0, &ocm_handle) != 0)
72265099Sian		panic("platform_mp_start_ap: Couldn't map OCM\n");
73265099Sian
74265099Sian	/* Write start address for CPU1. */
75265099Sian	bus_space_write_4(fdtbus_bs_tag, ocm_handle, 0,
76265099Sian	    pmap_kextract((vm_offset_t)mpentry));
77265099Sian
78265099Sian	/*
79265099Sian	 * The SCU is enabled by the BOOTROM but I think the second CPU doesn't
80265099Sian	 * turn on filtering until after the wake-up below. I think that's why
81265099Sian	 * things don't work if I don't put these cache ops here.  Also, the
82265099Sian	 * magic location, 0xfffffff0, isn't in the SCU's filtering range so it
83265099Sian	 * needs a write-back too.
84265099Sian	 */
85265099Sian	cpu_idcache_wbinv_all();
86265099Sian	cpu_l2cache_wbinv_all();
87265099Sian
88265099Sian	/* Wake up CPU1. */
89265099Sian	armv7_sev();
90265099Sian
91265099Sian	bus_space_unmap(fdtbus_bs_tag, ocm_handle, 4);
92265099Sian}
93265099Sian
94265099Sianvoid
95265099Sianplatform_ipi_send(cpuset_t cpus, u_int ipi)
96265099Sian{
97265099Sian
98265099Sian	pic_ipi_send(cpus, ipi);
99265099Sian}
100