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