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