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 #include <vm/pmap.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/smp.h>
45
46 #include <arm/qualcomm/qcom_scm_defs.h>
47 #include <arm/qualcomm/qcom_scm_legacy_defs.h>
48 #include <arm/qualcomm/qcom_scm_legacy.h>
49
50 #include <dev/psci/smccc.h>
51
52 /*
53 * Set the cold boot address for (later) a mask of CPUs.
54 *
55 * Don't set it for CPU0, that CPU is the boot CPU and is already alive.
56 *
57 * For now it sets it on CPU1..3.
58 *
59 * This works on the IPQ4019 as tested; the retval is 0x0.
60 */
61 uint32_t
qcom_scm_legacy_mp_set_cold_boot_address(vm_offset_t mp_entry_func)62 qcom_scm_legacy_mp_set_cold_boot_address(vm_offset_t mp_entry_func)
63 {
64 struct arm_smccc_res res;
65 int ret;
66 int context_id;
67
68 uint32_t scm_arg0 = QCOM_SCM_LEGACY_ATOMIC_ID(QCOM_SCM_SVC_BOOT,
69 QCOM_SCM_BOOT_SET_ADDR, 2);
70
71 uint32_t scm_arg1 = QCOM_SCM_FLAG_COLDBOOT_CPU1
72 | QCOM_SCM_FLAG_COLDBOOT_CPU2
73 | QCOM_SCM_FLAG_COLDBOOT_CPU3;
74 uint32_t scm_arg2 = pmap_kextract((vm_offset_t)mp_entry_func);
75
76 ret = arm_smccc_invoke_smc(scm_arg0, (uint32_t) &context_id, scm_arg1,
77 scm_arg2, &res);
78
79 if (ret == 0 && res.a0 == 0)
80 return (0);
81 printf("%s: called; error; ret=0x%08x; retval[0]=0x%08x\n",
82 __func__, ret, res.a0);
83
84 return (0);
85 }
86