1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2018 Andrew Turner 5 * 6 * This software was developed by SRI International and the University of 7 * Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237 8 * ("CTSRD"), as part of the DARPA CRASH research programme. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32 #ifndef _PSCI_SMCCC_H_ 33 #define _PSCI_SMCCC_H_ 34 35 #define SMCCC_MAKE_VERSION(maj, min) ((maj) << 16 | (min)) 36 #define SMCCC_VERSION_MAJOR(ver) (((ver) >> 16) & 0x7fff) 37 #define SMCCC_VERSION_MINOR(ver) ((ver) & 0xffff) 38 39 #define SMCCC_FUNC_ID(type, call_conv, range, func) \ 40 (((type) << 31) | \ 41 ((call_conv) << 30) | \ 42 (((range) & 0x3f) << 24) | \ 43 ((func) & 0xffff)) 44 45 #define SMCCC_YIELDING_CALL 0 46 #define SMCCC_FAST_CALL 1 47 48 #define SMCCC_32BIT_CALL 0 49 #define SMCCC_64BIT_CALL 1 50 51 #define SMCCC_ARM_ARCH_CALLS 0 52 #define SMCCC_CPU_SERVICE_CALLS 1 53 #define SMCCC_SIP_SERVICE_CALLS 2 54 #define SMCCC_OEM_SERVICE_CALLS 3 55 #define SMCCC_STD_SECURE_SERVICE_CALLS 4 56 #define SMCCC_STD_HYP_SERVICE_CALLS 5 57 #define SMCCC_VENDOR_HYP_SERVICE_CALLS 6 58 59 struct arm_smccc_res { 60 register_t a0; 61 register_t a1; 62 register_t a2; 63 register_t a3; 64 }; 65 66 /* 67 * Arm Architecture Calls. 68 * These are documented in the document ARM DEN 0070A. 69 */ 70 #define SMCCC_VERSION \ 71 SMCCC_FUNC_ID(SMCCC_FAST_CALL, SMCCC_32BIT_CALL, 0, 0) 72 #define SMCCC_ARCH_FEATURES \ 73 SMCCC_FUNC_ID(SMCCC_FAST_CALL, SMCCC_32BIT_CALL, 0, 1) 74 #define SMCCC_ARCH_WORKAROUND_1 \ 75 SMCCC_FUNC_ID(SMCCC_FAST_CALL, SMCCC_32BIT_CALL, 0, 0x8000) 76 #define SMCCC_ARCH_WORKAROUND_2 \ 77 SMCCC_FUNC_ID(SMCCC_FAST_CALL, SMCCC_32BIT_CALL, 0, 0x7fff) 78 79 /* The return values from ARM DEN 0070A. */ 80 #define SMCCC_RET_SUCCESS 0 81 #define SMCCC_RET_NOT_SUPPORTED -1 82 #define SMCCC_RET_NOT_REQUIRED -2 83 84 void smccc_init(void); 85 uint32_t smccc_get_version(void); 86 int32_t smccc_arch_features(uint32_t); 87 int smccc_arch_workaround_1(void); 88 int smccc_arch_workaround_2(int); 89 90 int arm_smccc_smc(register_t, register_t, register_t, register_t, register_t, 91 register_t, register_t, register_t, struct arm_smccc_res *res); 92 int arm_smccc_hvc(register_t, register_t, register_t, register_t, register_t, 93 register_t, register_t, register_t, struct arm_smccc_res *res); 94 95 #define arm_smccc_invoke_1(func, a0, res) \ 96 func(a0, 0, 0, 0, 0, 0, 0, 0, res) 97 #define arm_smccc_invoke_2(func, a0, a1, res) \ 98 func(a0, a1, 0, 0, 0, 0, 0, 0, res) 99 #define arm_smccc_invoke_3(func, a0, a1, a2, res) \ 100 func(a0, a1, a2, 0, 0, 0, 0, 0, res) 101 #define arm_smccc_invoke_4(func, a0, a1, a2, a3, res) \ 102 func(a0, a1, a2, a3, 0, 0, 0, 0, res) 103 #define arm_smccc_invoke_5(func, a0, a1, a2, a3, a4, res) \ 104 func(a0, a1, a2, a3, a4, 0, 0, 0, res) 105 #define arm_smccc_invoke_6(func, a0, a1, a2, a3, a4, a5, res) \ 106 func(a0, a1, a2, a3, a4, a5, 0, 0, res) 107 #define arm_smccc_invoke_7(func, a0, a1, a2, a3, a4, a5, a6, res) \ 108 func(a0, a1, a2, a3, a4, a5, a6, 0, res) 109 #define arm_smccc_invoke_8(func, a0, a1, a2, a3, a4, a5, a6, a7, res) \ 110 func(a0, a1, a2, a3, a4, a5, a6, a7, res) 111 112 #define _arm_smccc_invoke_macro(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) \ 113 NAME 114 #define _arm_smccc_invoke(func, a0, ...) \ 115 _arm_smccc_invoke_macro(__VA_ARGS__, arm_smccc_invoke_8, \ 116 arm_smccc_invoke_7, arm_smccc_invoke_6, arm_smccc_invoke_5, \ 117 arm_smccc_invoke_4, arm_smccc_invoke_3, arm_smccc_invoke_2, \ 118 arm_smccc_invoke_1)(func, a0, __VA_ARGS__) 119 120 #define arm_smccc_invoke_hvc(a0, ...) \ 121 _arm_smccc_invoke(arm_smccc_hvc, a0, __VA_ARGS__) 122 #define arm_smccc_invoke_smc(a0, ...) \ 123 _arm_smccc_invoke(arm_smccc_smc, a0, __VA_ARGS__) 124 #define arm_smccc_invoke(a0, ...) \ 125 _arm_smccc_invoke(psci_callfn, a0, __VA_ARGS__) 126 127 struct arm_smccc_1_2_regs { 128 register_t a0; 129 register_t a1; 130 register_t a2; 131 register_t a3; 132 register_t a4; 133 register_t a5; 134 register_t a6; 135 register_t a7; 136 register_t a8; 137 register_t a9; 138 register_t a10; 139 register_t a11; 140 register_t a12; 141 register_t a13; 142 register_t a14; 143 register_t a15; 144 register_t a16; 145 register_t a17; 146 }; 147 148 int arm_smccc_1_2_hvc(const struct arm_smccc_1_2_regs *args, 149 struct arm_smccc_1_2_regs *res); 150 int arm_smccc_1_2_smc(const struct arm_smccc_1_2_regs *args, 151 struct arm_smccc_1_2_regs *res); 152 #endif /* _PSCI_SMCCC_H_ */ 153