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