1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2021 Adrian Chadd <adrian@FreeBSD.org>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28 #include "opt_platform.h"
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/bus.h>
33 #include <sys/reboot.h>
34 #include <sys/smp.h>
35
36 #include <vm/vm.h>
37
38 #include <machine/cpu.h>
39 #include <machine/bus.h>
40 #include <machine/intr.h>
41 #include <machine/machdep.h>
42 #include <machine/platformvar.h>
43 #include <machine/smp.h>
44
45 #include <dev/fdt/fdt_common.h>
46 #include <dev/ofw/openfirm.h>
47 #include <dev/ofw/ofw_cpu.h>
48
49 #include <arm/qualcomm/ipq4018_machdep.h>
50 #include <arm/qualcomm/qcom_scm_legacy.h>
51 #include <arm/qualcomm/qcom_cpu_kpssv2.h>
52
53 #include "platform_if.h"
54
55 void
ipq4018_mp_setmaxid(platform_t plat)56 ipq4018_mp_setmaxid(platform_t plat)
57 {
58 int ncpu;
59
60 /* If we've already set the global vars don't bother to do it again. */
61 if (mp_ncpus != 0)
62 return;
63
64 /* Read current CP15 Cache Size ID Register */
65 ncpu = cp15_l2ctlr_get();
66 ncpu = CPUV7_L2CTLR_NPROC(ncpu);
67
68 mp_ncpus = ncpu;
69 mp_maxid = ncpu - 1;
70
71 printf("SMP: ncpu=%d\n", ncpu);
72 }
73
74 static bool
ipq4018_start_ap(u_int id,phandle_t node,u_int addr_cells,pcell_t * arg)75 ipq4018_start_ap(u_int id, phandle_t node, u_int addr_cells, pcell_t *arg)
76 {
77
78 /*
79 * For the IPQ401x we assume the enable method is
80 * "qcom,kpss-acc-v2". If this path gets turned into
81 * something more generic for other 32 bit qualcomm
82 * SoCs then we'll likely want to turn this into a
83 * switch based on "enable-method".
84 */
85 return qcom_cpu_kpssv2_regulator_start(id, node);
86 }
87
88 void
ipq4018_mp_start_ap(platform_t plat)89 ipq4018_mp_start_ap(platform_t plat)
90 {
91 int ret;
92
93 /*
94 * First step - SCM call to set the cold boot address to mpentry, so
95 * CPUs hopefully start in the MP path.
96 */
97 ret = qcom_scm_legacy_mp_set_cold_boot_address((vm_offset_t) mpentry);
98 if (ret != 0)
99 panic("%s: Couldn't set cold boot address via SCM "
100 "(error 0x%08x)", __func__, ret);
101
102 /*
103 * Next step - loop over the CPU nodes and do the per-CPU setup
104 * required to power on the CPUs themselves.
105 */
106 ofw_cpu_early_foreach(ipq4018_start_ap, true);
107
108 /*
109 * The next set of IPIs to the CPUs will wake them up and enter
110 * mpentry.
111 */
112 }
113