xref: /freebsd/sys/arm/qualcomm/ipq4018_mp.c (revision 315ee00f)
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/cdefs.h>
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/bus.h>
34 #include <sys/reboot.h>
35 #include <sys/devmap.h>
36 #include <sys/smp.h>
37 
38 #include <vm/vm.h>
39 
40 #include <machine/cpu.h>
41 #include <machine/bus.h>
42 #include <machine/intr.h>
43 #include <machine/machdep.h>
44 #include <machine/platformvar.h>
45 #include <machine/smp.h>
46 
47 #include <dev/fdt/fdt_common.h>
48 #include <dev/ofw/openfirm.h>
49 #include <dev/ofw/ofw_cpu.h>
50 
51 #include <arm/qualcomm/ipq4018_machdep.h>
52 #include <arm/qualcomm/qcom_scm_legacy.h>
53 #include <arm/qualcomm/qcom_cpu_kpssv2.h>
54 
55 #include "platform_if.h"
56 
57 void
58 ipq4018_mp_setmaxid(platform_t plat)
59 {
60 	int ncpu;
61 
62 	/* If we've already set the global vars don't bother to do it again. */
63 	if (mp_ncpus != 0)
64 		return;
65 
66 	/* Read current CP15 Cache Size ID Register */
67 	ncpu = cp15_l2ctlr_get();
68 	ncpu = CPUV7_L2CTLR_NPROC(ncpu);
69 
70 	mp_ncpus = ncpu;
71 	mp_maxid = ncpu - 1;
72 
73 	printf("SMP: ncpu=%d\n", ncpu);
74 }
75 
76 static bool
77 ipq4018_start_ap(u_int id, phandle_t node, u_int addr_cells, pcell_t *arg)
78 {
79 
80 	/*
81 	 * For the IPQ401x we assume the enable method is
82 	 * "qcom,kpss-acc-v2".  If this path gets turned into
83 	 * something more generic for other 32 bit qualcomm
84 	 * SoCs then we'll likely want to turn this into a
85 	 * switch based on "enable-method".
86 	 */
87 	return qcom_cpu_kpssv2_regulator_start(id, node);
88 }
89 
90 void
91 ipq4018_mp_start_ap(platform_t plat)
92 {
93 	int ret;
94 
95 	/*
96 	 * First step - SCM call to set the cold boot address to mpentry, so
97 	 * CPUs hopefully start in the MP path.
98 	 */
99 	ret = qcom_scm_legacy_mp_set_cold_boot_address((vm_offset_t) mpentry);
100 	if (ret != 0)
101 		panic("%s: Couldn't set cold boot address via SCM "
102 		    "(error 0x%08x)", __func__, ret);
103 
104 	/*
105 	 * Next step - loop over the CPU nodes and do the per-CPU setup
106 	 * required to power on the CPUs themselves.
107 	 */
108 	ofw_cpu_early_foreach(ipq4018_start_ap, true);
109 
110 	/*
111 	 * The next set of IPIs to the CPUs will wake them up and enter
112 	 * mpentry.
113 	 */
114 }
115