2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2021 Adrian Chadd <adrian@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
28 #include "opt_platform.h"
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/systm.h>
36 #include <sys/reboot.h>
37 #include <sys/devmap.h>
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>
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>
53 #include <dev/psci/smccc.h>
56 * Set the cold boot address for (later) a mask of CPUs.
58 * Don't set it for CPU0, that CPU is the boot CPU and is already alive.
60 * For now it sets it on CPU1..3.
62 * This works on the IPQ4019 as tested; the retval is 0x0.
65 qcom_scm_legacy_mp_set_cold_boot_address(vm_offset_t mp_entry_func)
67 struct arm_smccc_res res;
71 uint32_t scm_arg0 = QCOM_SCM_LEGACY_ATOMIC_ID(QCOM_SCM_SVC_BOOT,
72 QCOM_SCM_BOOT_SET_ADDR, 2);
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);
79 ret = arm_smccc_smc(scm_arg0, (uint32_t) &context_id, scm_arg1,
80 scm_arg2, 0, 0, 0, 0, &res);
82 if (ret == 0 && res.a0 == 0)
84 printf("%s: called; error; ret=0x%08x; retval[0]=0x%08x\n",
85 __func__, ret, res.a0);