xref: /freebsd/sys/arm/qualcomm/qcom_scm_legacy.c (revision 3332f1b444d4a73238e9f59cca27bfc95fe936bd)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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 __FBSDID("$FreeBSD$");
32 
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/bus.h>
36 #include <sys/reboot.h>
37 #include <sys/devmap.h>
38 #include <sys/smp.h>
39 
40 #include <vm/vm.h>
41 #include <vm/pmap.h>
42 
43 #include <machine/cpu.h>
44 #include <machine/bus.h>
45 #include <machine/intr.h>
46 #include <machine/machdep.h>
47 #include <machine/smp.h>
48 
49 #include <arm/qualcomm/qcom_scm_defs.h>
50 #include <arm/qualcomm/qcom_scm_legacy_defs.h>
51 #include <arm/qualcomm/qcom_scm_legacy.h>
52 
53 #include <dev/psci/smccc.h>
54 
55 /*
56  * Set the cold boot address for (later) a mask of CPUs.
57  *
58  * Don't set it for CPU0, that CPU is the boot CPU and is already alive.
59  *
60  * For now it sets it on CPU1..3.
61  *
62  * This works on the IPQ4019 as tested; the retval is 0x0.
63  */
64 uint32_t
65 qcom_scm_legacy_mp_set_cold_boot_address(vm_offset_t mp_entry_func)
66 {
67 	struct arm_smccc_res res;
68 	int ret;
69 	int context_id;
70 
71 	uint32_t scm_arg0 = QCOM_SCM_LEGACY_ATOMIC_ID(QCOM_SCM_SVC_BOOT,
72 	    QCOM_SCM_BOOT_SET_ADDR, 2);
73 
74 	uint32_t scm_arg1 = QCOM_SCM_FLAG_COLDBOOT_CPU1
75 	    | QCOM_SCM_FLAG_COLDBOOT_CPU2
76 	    | QCOM_SCM_FLAG_COLDBOOT_CPU3;
77 	uint32_t scm_arg2 = pmap_kextract((vm_offset_t)mp_entry_func);
78 
79 	ret = arm_smccc_smc(scm_arg0, (uint32_t) &context_id, scm_arg1,
80 	    scm_arg2, 0, 0, 0, 0, &res);
81 
82 	if (ret == 0 && res.a0 == 0)
83 		return (0);
84 	printf("%s: called; error; ret=0x%08x; retval[0]=0x%08x\n",
85 	    __func__, ret, res.a0);
86 
87 	return (0);
88 }
89