Path: blob/main/sys/arm/qualcomm/qcom_scm_legacy.c
39534 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2021 Adrian Chadd <[email protected]>4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*/2627#include "opt_platform.h"2829#include <sys/param.h>30#include <sys/systm.h>31#include <sys/bus.h>32#include <sys/reboot.h>33#include <sys/smp.h>3435#include <vm/vm.h>36#include <vm/pmap.h>3738#include <machine/cpu.h>39#include <machine/bus.h>40#include <machine/intr.h>41#include <machine/machdep.h>42#include <machine/smp.h>4344#include <arm/qualcomm/qcom_scm_defs.h>45#include <arm/qualcomm/qcom_scm_legacy_defs.h>46#include <arm/qualcomm/qcom_scm_legacy.h>4748#include <dev/psci/smccc.h>4950/*51* Set the cold boot address for (later) a mask of CPUs.52*53* Don't set it for CPU0, that CPU is the boot CPU and is already alive.54*55* For now it sets it on CPU1..3.56*57* This works on the IPQ4019 as tested; the retval is 0x0.58*/59uint32_t60qcom_scm_legacy_mp_set_cold_boot_address(vm_offset_t mp_entry_func)61{62struct arm_smccc_res res;63int ret;64int context_id;6566uint32_t scm_arg0 = QCOM_SCM_LEGACY_ATOMIC_ID(QCOM_SCM_SVC_BOOT,67QCOM_SCM_BOOT_SET_ADDR, 2);6869uint32_t scm_arg1 = QCOM_SCM_FLAG_COLDBOOT_CPU170| QCOM_SCM_FLAG_COLDBOOT_CPU271| QCOM_SCM_FLAG_COLDBOOT_CPU3;72uint32_t scm_arg2 = pmap_kextract((vm_offset_t)mp_entry_func);7374ret = arm_smccc_invoke_smc(scm_arg0, (uint32_t) &context_id, scm_arg1,75scm_arg2, &res);7677if (ret == 0 && res.a0 == 0)78return (0);79printf("%s: called; error; ret=0x%08x; retval[0]=0x%08x\n",80__func__, ret, res.a0);8182return (0);83}848586