| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2015, Linaro Limited |
|---|
| 3 | | - * |
|---|
| 4 | | - * This software is licensed under the terms of the GNU General Public |
|---|
| 5 | | - * License version 2, as published by the Free Software Foundation, and |
|---|
| 6 | | - * may be copied, distributed, and modified under those terms. |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 9 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | | - * GNU General Public License for more details. |
|---|
| 12 | | - * |
|---|
| 13 | 4 | */ |
|---|
| 14 | 5 | #ifndef __LINUX_ARM_SMCCC_H |
|---|
| 15 | 6 | #define __LINUX_ARM_SMCCC_H |
|---|
| 16 | 7 | |
|---|
| 8 | +#include <linux/init.h> |
|---|
| 17 | 9 | #include <uapi/linux/const.h> |
|---|
| 18 | 10 | |
|---|
| 19 | 11 | /* |
|---|
| 20 | 12 | * This file provides common defines for ARM SMC Calling Convention as |
|---|
| 21 | 13 | * specified in |
|---|
| 22 | | - * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html |
|---|
| 14 | + * https://developer.arm.com/docs/den0028/latest |
|---|
| 15 | + * |
|---|
| 16 | + * This code is up-to-date with version DEN 0028 C |
|---|
| 23 | 17 | */ |
|---|
| 24 | 18 | |
|---|
| 25 | 19 | #define ARM_SMCCC_STD_CALL _AC(0,U) |
|---|
| .. | .. |
|---|
| 54 | 48 | #define ARM_SMCCC_OWNER_SIP 2 |
|---|
| 55 | 49 | #define ARM_SMCCC_OWNER_OEM 3 |
|---|
| 56 | 50 | #define ARM_SMCCC_OWNER_STANDARD 4 |
|---|
| 51 | +#define ARM_SMCCC_OWNER_STANDARD_HYP 5 |
|---|
| 52 | +#define ARM_SMCCC_OWNER_VENDOR_HYP 6 |
|---|
| 57 | 53 | #define ARM_SMCCC_OWNER_TRUSTED_APP 48 |
|---|
| 58 | 54 | #define ARM_SMCCC_OWNER_TRUSTED_APP_END 49 |
|---|
| 59 | 55 | #define ARM_SMCCC_OWNER_TRUSTED_OS 50 |
|---|
| .. | .. |
|---|
| 64 | 60 | |
|---|
| 65 | 61 | #define ARM_SMCCC_VERSION_1_0 0x10000 |
|---|
| 66 | 62 | #define ARM_SMCCC_VERSION_1_1 0x10001 |
|---|
| 63 | +#define ARM_SMCCC_VERSION_1_2 0x10002 |
|---|
| 67 | 64 | |
|---|
| 68 | 65 | #define ARM_SMCCC_VERSION_FUNC_ID \ |
|---|
| 69 | 66 | ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ |
|---|
| .. | .. |
|---|
| 75 | 72 | ARM_SMCCC_SMC_32, \ |
|---|
| 76 | 73 | 0, 1) |
|---|
| 77 | 74 | |
|---|
| 75 | +#define ARM_SMCCC_ARCH_SOC_ID \ |
|---|
| 76 | + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ |
|---|
| 77 | + ARM_SMCCC_SMC_32, \ |
|---|
| 78 | + 0, 2) |
|---|
| 79 | + |
|---|
| 78 | 80 | #define ARM_SMCCC_ARCH_WORKAROUND_1 \ |
|---|
| 79 | 81 | ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ |
|---|
| 80 | 82 | ARM_SMCCC_SMC_32, \ |
|---|
| .. | .. |
|---|
| 84 | 86 | ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ |
|---|
| 85 | 87 | ARM_SMCCC_SMC_32, \ |
|---|
| 86 | 88 | 0, 0x7fff) |
|---|
| 89 | + |
|---|
| 90 | +#define ARM_SMCCC_ARCH_WORKAROUND_3 \ |
|---|
| 91 | + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ |
|---|
| 92 | + ARM_SMCCC_SMC_32, \ |
|---|
| 93 | + 0, 0x3fff) |
|---|
| 94 | + |
|---|
| 95 | +#define SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED 1 |
|---|
| 96 | + |
|---|
| 97 | +/* Paravirtualised time calls (defined by ARM DEN0057A) */ |
|---|
| 98 | +#define ARM_SMCCC_HV_PV_TIME_FEATURES \ |
|---|
| 99 | + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ |
|---|
| 100 | + ARM_SMCCC_SMC_64, \ |
|---|
| 101 | + ARM_SMCCC_OWNER_STANDARD_HYP, \ |
|---|
| 102 | + 0x20) |
|---|
| 103 | + |
|---|
| 104 | +#define ARM_SMCCC_HV_PV_TIME_ST \ |
|---|
| 105 | + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ |
|---|
| 106 | + ARM_SMCCC_SMC_64, \ |
|---|
| 107 | + ARM_SMCCC_OWNER_STANDARD_HYP, \ |
|---|
| 108 | + 0x21) |
|---|
| 109 | + |
|---|
| 110 | +/* TRNG entropy source calls (defined by ARM DEN0098) */ |
|---|
| 111 | +#define ARM_SMCCC_TRNG_VERSION \ |
|---|
| 112 | + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ |
|---|
| 113 | + ARM_SMCCC_SMC_32, \ |
|---|
| 114 | + ARM_SMCCC_OWNER_STANDARD, \ |
|---|
| 115 | + 0x50) |
|---|
| 116 | + |
|---|
| 117 | +#define ARM_SMCCC_TRNG_FEATURES \ |
|---|
| 118 | + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ |
|---|
| 119 | + ARM_SMCCC_SMC_32, \ |
|---|
| 120 | + ARM_SMCCC_OWNER_STANDARD, \ |
|---|
| 121 | + 0x51) |
|---|
| 122 | + |
|---|
| 123 | +#define ARM_SMCCC_TRNG_GET_UUID \ |
|---|
| 124 | + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ |
|---|
| 125 | + ARM_SMCCC_SMC_32, \ |
|---|
| 126 | + ARM_SMCCC_OWNER_STANDARD, \ |
|---|
| 127 | + 0x52) |
|---|
| 128 | + |
|---|
| 129 | +#define ARM_SMCCC_TRNG_RND32 \ |
|---|
| 130 | + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ |
|---|
| 131 | + ARM_SMCCC_SMC_32, \ |
|---|
| 132 | + ARM_SMCCC_OWNER_STANDARD, \ |
|---|
| 133 | + 0x53) |
|---|
| 134 | + |
|---|
| 135 | +#define ARM_SMCCC_TRNG_RND64 \ |
|---|
| 136 | + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ |
|---|
| 137 | + ARM_SMCCC_SMC_64, \ |
|---|
| 138 | + ARM_SMCCC_OWNER_STANDARD, \ |
|---|
| 139 | + 0x53) |
|---|
| 140 | + |
|---|
| 141 | +/* |
|---|
| 142 | + * Return codes defined in ARM DEN 0070A |
|---|
| 143 | + * ARM DEN 0070A is now merged/consolidated into ARM DEN 0028 C |
|---|
| 144 | + */ |
|---|
| 145 | +#define SMCCC_RET_SUCCESS 0 |
|---|
| 146 | +#define SMCCC_RET_NOT_SUPPORTED -1 |
|---|
| 147 | +#define SMCCC_RET_NOT_REQUIRED -2 |
|---|
| 148 | +#define SMCCC_RET_INVALID_PARAMETER -3 |
|---|
| 87 | 149 | |
|---|
| 88 | 150 | #ifndef __ASSEMBLY__ |
|---|
| 89 | 151 | |
|---|
| .. | .. |
|---|
| 104 | 166 | * When SMCCCv1.1 is not present, returns SMCCC_CONDUIT_NONE. |
|---|
| 105 | 167 | */ |
|---|
| 106 | 168 | enum arm_smccc_conduit arm_smccc_1_1_get_conduit(void); |
|---|
| 169 | + |
|---|
| 170 | +/** |
|---|
| 171 | + * arm_smccc_get_version() |
|---|
| 172 | + * |
|---|
| 173 | + * Returns the version to be used for SMCCCv1.1 or later. |
|---|
| 174 | + * |
|---|
| 175 | + * When SMCCCv1.1 or above is not present, returns SMCCCv1.0, but this |
|---|
| 176 | + * does not imply the presence of firmware or a valid conduit. Caller |
|---|
| 177 | + * handling SMCCCv1.0 must determine the conduit by other means. |
|---|
| 178 | + */ |
|---|
| 179 | +u32 arm_smccc_get_version(void); |
|---|
| 180 | + |
|---|
| 181 | +void __init arm_smccc_version_init(u32 version, enum arm_smccc_conduit conduit); |
|---|
| 107 | 182 | |
|---|
| 108 | 183 | /** |
|---|
| 109 | 184 | * struct arm_smccc_res - Result from SMC/HVC call |
|---|
| .. | .. |
|---|
| 191 | 266 | #define __count_args(...) \ |
|---|
| 192 | 267 | ___count_args(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0) |
|---|
| 193 | 268 | |
|---|
| 194 | | -#define __constraint_write_0 \ |
|---|
| 195 | | - "+r" (r0), "=&r" (r1), "=&r" (r2), "=&r" (r3) |
|---|
| 196 | | -#define __constraint_write_1 \ |
|---|
| 197 | | - "+r" (r0), "+r" (r1), "=&r" (r2), "=&r" (r3) |
|---|
| 198 | | -#define __constraint_write_2 \ |
|---|
| 199 | | - "+r" (r0), "+r" (r1), "+r" (r2), "=&r" (r3) |
|---|
| 200 | | -#define __constraint_write_3 \ |
|---|
| 201 | | - "+r" (r0), "+r" (r1), "+r" (r2), "+r" (r3) |
|---|
| 202 | | -#define __constraint_write_4 __constraint_write_3 |
|---|
| 203 | | -#define __constraint_write_5 __constraint_write_4 |
|---|
| 204 | | -#define __constraint_write_6 __constraint_write_5 |
|---|
| 205 | | -#define __constraint_write_7 __constraint_write_6 |
|---|
| 206 | | - |
|---|
| 207 | | -#define __constraint_read_0 |
|---|
| 208 | | -#define __constraint_read_1 |
|---|
| 209 | | -#define __constraint_read_2 |
|---|
| 210 | | -#define __constraint_read_3 |
|---|
| 211 | | -#define __constraint_read_4 "r" (r4) |
|---|
| 212 | | -#define __constraint_read_5 __constraint_read_4, "r" (r5) |
|---|
| 213 | | -#define __constraint_read_6 __constraint_read_5, "r" (r6) |
|---|
| 214 | | -#define __constraint_read_7 __constraint_read_6, "r" (r7) |
|---|
| 269 | +#define __constraint_read_0 "r" (arg0) |
|---|
| 270 | +#define __constraint_read_1 __constraint_read_0, "r" (arg1) |
|---|
| 271 | +#define __constraint_read_2 __constraint_read_1, "r" (arg2) |
|---|
| 272 | +#define __constraint_read_3 __constraint_read_2, "r" (arg3) |
|---|
| 273 | +#define __constraint_read_4 __constraint_read_3, "r" (arg4) |
|---|
| 274 | +#define __constraint_read_5 __constraint_read_4, "r" (arg5) |
|---|
| 275 | +#define __constraint_read_6 __constraint_read_5, "r" (arg6) |
|---|
| 276 | +#define __constraint_read_7 __constraint_read_6, "r" (arg7) |
|---|
| 215 | 277 | |
|---|
| 216 | 278 | #define __declare_arg_0(a0, res) \ |
|---|
| 217 | 279 | struct arm_smccc_res *___res = res; \ |
|---|
| 218 | | - register unsigned long r0 asm("r0") = (u32)a0; \ |
|---|
| 219 | | - register unsigned long r1 asm("r1"); \ |
|---|
| 220 | | - register unsigned long r2 asm("r2"); \ |
|---|
| 221 | | - register unsigned long r3 asm("r3") |
|---|
| 280 | + register unsigned long arg0 asm("r0") = (u32)a0 |
|---|
| 222 | 281 | |
|---|
| 223 | 282 | #define __declare_arg_1(a0, a1, res) \ |
|---|
| 224 | 283 | typeof(a1) __a1 = a1; \ |
|---|
| 225 | 284 | struct arm_smccc_res *___res = res; \ |
|---|
| 226 | | - register unsigned long r0 asm("r0") = (u32)a0; \ |
|---|
| 227 | | - register unsigned long r1 asm("r1") = __a1; \ |
|---|
| 228 | | - register unsigned long r2 asm("r2"); \ |
|---|
| 229 | | - register unsigned long r3 asm("r3") |
|---|
| 285 | + register unsigned long arg0 asm("r0") = (u32)a0; \ |
|---|
| 286 | + register typeof(a1) arg1 asm("r1") = __a1 |
|---|
| 230 | 287 | |
|---|
| 231 | 288 | #define __declare_arg_2(a0, a1, a2, res) \ |
|---|
| 232 | 289 | typeof(a1) __a1 = a1; \ |
|---|
| 233 | 290 | typeof(a2) __a2 = a2; \ |
|---|
| 234 | 291 | struct arm_smccc_res *___res = res; \ |
|---|
| 235 | | - register unsigned long r0 asm("r0") = (u32)a0; \ |
|---|
| 236 | | - register unsigned long r1 asm("r1") = __a1; \ |
|---|
| 237 | | - register unsigned long r2 asm("r2") = __a2; \ |
|---|
| 238 | | - register unsigned long r3 asm("r3") |
|---|
| 292 | + register unsigned long arg0 asm("r0") = (u32)a0; \ |
|---|
| 293 | + register typeof(a1) arg1 asm("r1") = __a1; \ |
|---|
| 294 | + register typeof(a2) arg2 asm("r2") = __a2 |
|---|
| 239 | 295 | |
|---|
| 240 | 296 | #define __declare_arg_3(a0, a1, a2, a3, res) \ |
|---|
| 241 | 297 | typeof(a1) __a1 = a1; \ |
|---|
| 242 | 298 | typeof(a2) __a2 = a2; \ |
|---|
| 243 | 299 | typeof(a3) __a3 = a3; \ |
|---|
| 244 | 300 | struct arm_smccc_res *___res = res; \ |
|---|
| 245 | | - register unsigned long r0 asm("r0") = (u32)a0; \ |
|---|
| 246 | | - register unsigned long r1 asm("r1") = __a1; \ |
|---|
| 247 | | - register unsigned long r2 asm("r2") = __a2; \ |
|---|
| 248 | | - register unsigned long r3 asm("r3") = __a3 |
|---|
| 301 | + register unsigned long arg0 asm("r0") = (u32)a0; \ |
|---|
| 302 | + register typeof(a1) arg1 asm("r1") = __a1; \ |
|---|
| 303 | + register typeof(a2) arg2 asm("r2") = __a2; \ |
|---|
| 304 | + register typeof(a3) arg3 asm("r3") = __a3 |
|---|
| 249 | 305 | |
|---|
| 250 | 306 | #define __declare_arg_4(a0, a1, a2, a3, a4, res) \ |
|---|
| 251 | 307 | typeof(a4) __a4 = a4; \ |
|---|
| 252 | 308 | __declare_arg_3(a0, a1, a2, a3, res); \ |
|---|
| 253 | | - register unsigned long r4 asm("r4") = __a4 |
|---|
| 309 | + register typeof(a4) arg4 asm("r4") = __a4 |
|---|
| 254 | 310 | |
|---|
| 255 | 311 | #define __declare_arg_5(a0, a1, a2, a3, a4, a5, res) \ |
|---|
| 256 | 312 | typeof(a5) __a5 = a5; \ |
|---|
| 257 | 313 | __declare_arg_4(a0, a1, a2, a3, a4, res); \ |
|---|
| 258 | | - register unsigned long r5 asm("r5") = __a5 |
|---|
| 314 | + register typeof(a5) arg5 asm("r5") = __a5 |
|---|
| 259 | 315 | |
|---|
| 260 | 316 | #define __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res) \ |
|---|
| 261 | 317 | typeof(a6) __a6 = a6; \ |
|---|
| 262 | 318 | __declare_arg_5(a0, a1, a2, a3, a4, a5, res); \ |
|---|
| 263 | | - register unsigned long r6 asm("r6") = __a6 |
|---|
| 319 | + register typeof(a6) arg6 asm("r6") = __a6 |
|---|
| 264 | 320 | |
|---|
| 265 | 321 | #define __declare_arg_7(a0, a1, a2, a3, a4, a5, a6, a7, res) \ |
|---|
| 266 | 322 | typeof(a7) __a7 = a7; \ |
|---|
| 267 | 323 | __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res); \ |
|---|
| 268 | | - register unsigned long r7 asm("r7") = __a7 |
|---|
| 324 | + register typeof(a7) arg7 asm("r7") = __a7 |
|---|
| 269 | 325 | |
|---|
| 270 | 326 | #define ___declare_args(count, ...) __declare_arg_ ## count(__VA_ARGS__) |
|---|
| 271 | 327 | #define __declare_args(count, ...) ___declare_args(count, __VA_ARGS__) |
|---|
| 272 | 328 | |
|---|
| 273 | 329 | #define ___constraints(count) \ |
|---|
| 274 | | - : __constraint_write_ ## count \ |
|---|
| 275 | 330 | : __constraint_read_ ## count \ |
|---|
| 276 | 331 | : "memory" |
|---|
| 277 | 332 | #define __constraints(count) ___constraints(count) |
|---|
| .. | .. |
|---|
| 283 | 338 | */ |
|---|
| 284 | 339 | #define __arm_smccc_1_1(inst, ...) \ |
|---|
| 285 | 340 | do { \ |
|---|
| 341 | + register unsigned long r0 asm("r0"); \ |
|---|
| 342 | + register unsigned long r1 asm("r1"); \ |
|---|
| 343 | + register unsigned long r2 asm("r2"); \ |
|---|
| 344 | + register unsigned long r3 asm("r3"); \ |
|---|
| 286 | 345 | __declare_args(__count_args(__VA_ARGS__), __VA_ARGS__); \ |
|---|
| 287 | | - asm volatile(inst "\n" \ |
|---|
| 346 | + asm volatile(inst "\n" : \ |
|---|
| 347 | + "=r" (r0), "=r" (r1), "=r" (r2), "=r" (r3) \ |
|---|
| 288 | 348 | __constraints(__count_args(__VA_ARGS__))); \ |
|---|
| 289 | 349 | if (___res) \ |
|---|
| 290 | 350 | *___res = (typeof(*___res)){r0, r1, r2, r3}; \ |
|---|
| .. | .. |
|---|
| 322 | 382 | */ |
|---|
| 323 | 383 | #define arm_smccc_1_1_hvc(...) __arm_smccc_1_1(SMCCC_HVC_INST, __VA_ARGS__) |
|---|
| 324 | 384 | |
|---|
| 325 | | -/* Return codes defined in ARM DEN 0070A */ |
|---|
| 326 | | -#define SMCCC_RET_SUCCESS 0 |
|---|
| 327 | | -#define SMCCC_RET_NOT_SUPPORTED -1 |
|---|
| 328 | | -#define SMCCC_RET_NOT_REQUIRED -2 |
|---|
| 329 | | - |
|---|
| 330 | 385 | /* |
|---|
| 331 | 386 | * Like arm_smccc_1_1* but always returns SMCCC_RET_NOT_SUPPORTED. |
|---|
| 332 | 387 | * Used when the SMCCC conduit is not defined. The empty asm statement |
|---|
| .. | .. |
|---|
| 335 | 390 | #define __fail_smccc_1_1(...) \ |
|---|
| 336 | 391 | do { \ |
|---|
| 337 | 392 | __declare_args(__count_args(__VA_ARGS__), __VA_ARGS__); \ |
|---|
| 338 | | - asm ("" __constraints(__count_args(__VA_ARGS__))); \ |
|---|
| 393 | + asm ("" : __constraints(__count_args(__VA_ARGS__))); \ |
|---|
| 339 | 394 | if (___res) \ |
|---|
| 340 | 395 | ___res->a0 = SMCCC_RET_NOT_SUPPORTED; \ |
|---|
| 341 | 396 | } while (0) |
|---|