xref: /freebsd/sys/arm/xilinx/zy7_mp.c (revision b2d48be1bc7df45ddd13b143a160d0acb5a383c5)
1 /*-
2  * Copyright (c) 2013 Thomas Skibo.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24 
25 #include <sys/cdefs.h>
26 __FBSDID("$FreeBSD$");
27 #include <sys/param.h>
28 #include <sys/systm.h>
29 #include <sys/bus.h>
30 #include <sys/lock.h>
31 #include <sys/mutex.h>
32 #include <sys/smp.h>
33 
34 #include <vm/vm.h>
35 #include <vm/pmap.h>
36 
37 #include <machine/smp.h>
38 #include <machine/fdt.h>
39 #include <machine/intr.h>
40 
41 #include <arm/xilinx/zy7_reg.h>
42 
43 #define	ZYNQ7_CPU1_ENTRY	0xfffffff0
44 
45 #define	SCU_CONTROL_REG		0xf8f00000
46 #define	   SCU_CONTROL_ENABLE	(1 << 0)
47 
48 void
49 platform_mp_init_secondary(void)
50 {
51 
52 	arm_init_secondary_ic();
53 }
54 
55 void
56 platform_mp_setmaxid(void)
57 {
58 
59 	mp_maxid = 1;
60 }
61 
62 int
63 platform_mp_probe(void)
64 {
65 
66 	mp_ncpus = 2;
67 	return (1);
68 }
69 
70 void
71 platform_mp_start_ap(void)
72 {
73 	bus_space_handle_t scu_handle;
74 	bus_space_handle_t ocm_handle;
75 	uint32_t scu_ctrl;
76 
77 	/* Map in SCU control register. */
78 	if (bus_space_map(fdtbus_bs_tag, SCU_CONTROL_REG, 4,
79 			  0, &scu_handle) != 0)
80 		panic("platform_mp_start_ap: Couldn't map SCU config reg\n");
81 
82 	/* Set SCU enable bit. */
83 	scu_ctrl = bus_space_read_4(fdtbus_bs_tag, scu_handle, 0);
84 	scu_ctrl |= SCU_CONTROL_ENABLE;
85 	bus_space_write_4(fdtbus_bs_tag, scu_handle, 0, scu_ctrl);
86 
87 	bus_space_unmap(fdtbus_bs_tag, scu_handle, 4);
88 
89 	/* Map in magic location to give entry address to CPU1. */
90 	if (bus_space_map(fdtbus_bs_tag, ZYNQ7_CPU1_ENTRY, 4,
91 	    0, &ocm_handle) != 0)
92 		panic("platform_mp_start_ap: Couldn't map OCM\n");
93 
94 	/* Write start address for CPU1. */
95 	bus_space_write_4(fdtbus_bs_tag, ocm_handle, 0,
96 	    pmap_kextract((vm_offset_t)mpentry));
97 
98 	bus_space_unmap(fdtbus_bs_tag, ocm_handle, 4);
99 
100 	/*
101 	 * The SCU is enabled above but I think the second CPU doesn't
102 	 * turn on filtering until after the wake-up below. I think that's why
103 	 * things don't work if I don't put these cache ops here.  Also, the
104 	 * magic location, 0xfffffff0, isn't in the SCU's filtering range so it
105 	 * needs a write-back too.
106 	 */
107 	cpu_idcache_wbinv_all();
108 	cpu_l2cache_wbinv_all();
109 
110 	/* Wake up CPU1. */
111 	armv7_sev();
112 }
113 
114 void
115 platform_ipi_send(cpuset_t cpus, u_int ipi)
116 {
117 
118 	pic_ipi_send(cpus, ipi);
119 }
120