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
25dc59c854SAndrew Turner #include "opt_platform.h"
26dc59c854SAndrew Turner
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
34087af50aSAndrew Turner #include <vm/vm.h>
35087af50aSAndrew Turner #include <vm/pmap.h>
36087af50aSAndrew Turner
37a89156f5SMichal Meloun #include <machine/cpu.h>
3806177e52SIan Lepore #include <machine/smp.h>
3906177e52SIan Lepore #include <machine/fdt.h>
4006177e52SIan Lepore #include <machine/intr.h>
41dc59c854SAndrew Turner #include <machine/platformvar.h>
4206177e52SIan Lepore
433185adf0SAndrew Turner #include <arm/xilinx/zy7_machdep.h>
4406177e52SIan Lepore #include <arm/xilinx/zy7_reg.h>
45*80d7c14cSJohn-Mark Gurney #include <arm/xilinx/zy7_slcr.h>
4606177e52SIan Lepore
4706177e52SIan Lepore #define ZYNQ7_CPU1_ENTRY 0xfffffff0
4806177e52SIan Lepore
4997665af9SIan Lepore #define SCU_CONTROL_REG 0xf8f00000
50*80d7c14cSJohn-Mark Gurney #define SCU_CONTROL_ENABLE 1
51*80d7c14cSJohn-Mark Gurney #define SCU_CONFIG_REG 0xf8f00004
52*80d7c14cSJohn-Mark Gurney #define SCU_CONFIG_N_CPUS_MASK 3
53*80d7c14cSJohn-Mark Gurney
54*80d7c14cSJohn-Mark Gurney #define SLCR_PSS_IDCODE 0xf8000530
5597665af9SIan Lepore
5606177e52SIan Lepore void
zynq7_mp_setmaxid(platform_t plat)57dc59c854SAndrew Turner zynq7_mp_setmaxid(platform_t plat)
5806177e52SIan Lepore {
59*80d7c14cSJohn-Mark Gurney bus_space_handle_t slcr_handle;
60*80d7c14cSJohn-Mark Gurney int device_id;
61*80d7c14cSJohn-Mark Gurney bus_space_handle_t scu_handle;
6206177e52SIan Lepore
63*80d7c14cSJohn-Mark Gurney if (mp_ncpus != 0)
64*80d7c14cSJohn-Mark Gurney return;
65*80d7c14cSJohn-Mark Gurney
66*80d7c14cSJohn-Mark Gurney /* Map in SLCR PSS_IDCODE register. */
67*80d7c14cSJohn-Mark Gurney if (bus_space_map(fdtbus_bs_tag, SLCR_PSS_IDCODE, 4, 0,
68*80d7c14cSJohn-Mark Gurney &slcr_handle) != 0)
69*80d7c14cSJohn-Mark Gurney panic("%s: Could not map SLCR IDCODE reg.\n", __func__);
70*80d7c14cSJohn-Mark Gurney
71*80d7c14cSJohn-Mark Gurney device_id = bus_space_read_4(fdtbus_bs_tag, slcr_handle, 0) &
72*80d7c14cSJohn-Mark Gurney ZY7_SLCR_PSS_IDCODE_DEVICE_MASK;
73*80d7c14cSJohn-Mark Gurney
74*80d7c14cSJohn-Mark Gurney bus_space_unmap(fdtbus_bs_tag, slcr_handle, 4);
75*80d7c14cSJohn-Mark Gurney
76*80d7c14cSJohn-Mark Gurney /*
77*80d7c14cSJohn-Mark Gurney * Zynq XC7z0xxS single core chips indicate incorrect number of CPUs in
78*80d7c14cSJohn-Mark Gurney * SCU configuration register.
79*80d7c14cSJohn-Mark Gurney */
80*80d7c14cSJohn-Mark Gurney if (device_id == ZY7_SLCR_PSS_IDCODE_DEVICE_7Z007S ||
81*80d7c14cSJohn-Mark Gurney device_id == ZY7_SLCR_PSS_IDCODE_DEVICE_7Z012S ||
82*80d7c14cSJohn-Mark Gurney device_id == ZY7_SLCR_PSS_IDCODE_DEVICE_7Z014S) {
83*80d7c14cSJohn-Mark Gurney mp_maxid = 0;
84*80d7c14cSJohn-Mark Gurney mp_ncpus = 1;
85*80d7c14cSJohn-Mark Gurney return;
86*80d7c14cSJohn-Mark Gurney }
87*80d7c14cSJohn-Mark Gurney
88*80d7c14cSJohn-Mark Gurney /* Map in SCU config register. */
89*80d7c14cSJohn-Mark Gurney if (bus_space_map(fdtbus_bs_tag, SCU_CONFIG_REG, 4, 0,
90*80d7c14cSJohn-Mark Gurney &scu_handle) != 0)
91*80d7c14cSJohn-Mark Gurney panic("zynq7_mp_setmaxid: Could not map SCU config reg.\n");
92*80d7c14cSJohn-Mark Gurney
93*80d7c14cSJohn-Mark Gurney mp_maxid = bus_space_read_4(fdtbus_bs_tag, scu_handle, 0) &
94*80d7c14cSJohn-Mark Gurney SCU_CONFIG_N_CPUS_MASK;
95*80d7c14cSJohn-Mark Gurney mp_ncpus = mp_maxid + 1;
96*80d7c14cSJohn-Mark Gurney
97*80d7c14cSJohn-Mark Gurney bus_space_unmap(fdtbus_bs_tag, scu_handle, 4);
9806177e52SIan Lepore }
9906177e52SIan Lepore
10006177e52SIan Lepore void
zynq7_mp_start_ap(platform_t plat)101dc59c854SAndrew Turner zynq7_mp_start_ap(platform_t plat)
10206177e52SIan Lepore {
10397665af9SIan Lepore bus_space_handle_t scu_handle;
10406177e52SIan Lepore bus_space_handle_t ocm_handle;
10597665af9SIan Lepore uint32_t scu_ctrl;
10697665af9SIan Lepore
10797665af9SIan Lepore /* Map in SCU control register. */
10897665af9SIan Lepore if (bus_space_map(fdtbus_bs_tag, SCU_CONTROL_REG, 4,
10997665af9SIan Lepore 0, &scu_handle) != 0)
1104ee4e0cdSJohn-Mark Gurney panic("%s: Could not map SCU control reg.\n", __func__);
11197665af9SIan Lepore
11297665af9SIan Lepore /* Set SCU enable bit. */
11397665af9SIan Lepore scu_ctrl = bus_space_read_4(fdtbus_bs_tag, scu_handle, 0);
11497665af9SIan Lepore scu_ctrl |= SCU_CONTROL_ENABLE;
11597665af9SIan Lepore bus_space_write_4(fdtbus_bs_tag, scu_handle, 0, scu_ctrl);
11697665af9SIan Lepore
11797665af9SIan Lepore bus_space_unmap(fdtbus_bs_tag, scu_handle, 4);
11806177e52SIan Lepore
11906177e52SIan Lepore /* Map in magic location to give entry address to CPU1. */
12006177e52SIan Lepore if (bus_space_map(fdtbus_bs_tag, ZYNQ7_CPU1_ENTRY, 4,
12106177e52SIan Lepore 0, &ocm_handle) != 0)
1224ee4e0cdSJohn-Mark Gurney panic("%s: Could not map OCM\n", __func__);
12306177e52SIan Lepore
12406177e52SIan Lepore /* Write start address for CPU1. */
12506177e52SIan Lepore bus_space_write_4(fdtbus_bs_tag, ocm_handle, 0,
12606177e52SIan Lepore pmap_kextract((vm_offset_t)mpentry));
12706177e52SIan Lepore
12897665af9SIan Lepore bus_space_unmap(fdtbus_bs_tag, ocm_handle, 4);
12997665af9SIan Lepore
13006177e52SIan Lepore /*
13197665af9SIan Lepore * The SCU is enabled above but I think the second CPU doesn't
13206177e52SIan Lepore * turn on filtering until after the wake-up below. I think that's why
13306177e52SIan Lepore * things don't work if I don't put these cache ops here. Also, the
13406177e52SIan Lepore * magic location, 0xfffffff0, isn't in the SCU's filtering range so it
13506177e52SIan Lepore * needs a write-back too.
13606177e52SIan Lepore */
137a89156f5SMichal Meloun dcache_wbinv_poc_all();
13806177e52SIan Lepore
13906177e52SIan Lepore /* Wake up CPU1. */
1407cc70732SMichal Meloun dsb();
1417cc70732SMichal Meloun sev();
14206177e52SIan Lepore }
143