Antonio Nino Diaz | 085e80e | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef __SMCCC_H__ |
| 8 | #define __SMCCC_H__ |
| 9 | |
| 10 | #include <utils_def.h> |
| 11 | |
Antonio Nino Diaz | 2f37046 | 2018-04-23 15:43:29 +0100 | [diff] [blame] | 12 | #define SMCCC_VERSION_MAJOR_SHIFT U(16) |
| 13 | #define SMCCC_VERSION_MAJOR_MASK U(0x7FFF) |
| 14 | #define SMCCC_VERSION_MINOR_SHIFT U(0) |
| 15 | #define SMCCC_VERSION_MINOR_MASK U(0xFFFF) |
| 16 | #define MAKE_SMCCC_VERSION(_major, _minor) \ |
| 17 | ( (((uint32_t)(_major) & SMCCC_VERSION_MAJOR_MASK) << SMCCC_VERSION_MAJOR_SHIFT) \ |
| 18 | | (((uint32_t)(_minor) & SMCCC_VERSION_MINOR_MASK) << SMCCC_VERSION_MINOR_SHIFT)) |
Antonio Nino Diaz | 085e80e | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 19 | |
Antonio Nino Diaz | 2f37046 | 2018-04-23 15:43:29 +0100 | [diff] [blame] | 20 | #if SMCCC_MAJOR_VERSION == 1 |
| 21 | # define SMCCC_MINOR_VERSION U(1) |
| 22 | # include <smccc_v1.h> |
| 23 | #elif SMCCC_MAJOR_VERSION == 2 |
| 24 | # define SMCCC_MINOR_VERSION U(0) |
| 25 | # include <smccc_v2.h> |
| 26 | #else |
| 27 | # error "Unsupported version of SMCCC." |
Antonio Nino Diaz | 085e80e | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 28 | #endif |
Antonio Nino Diaz | 2f37046 | 2018-04-23 15:43:29 +0100 | [diff] [blame] | 29 | |
| 30 | /* Various flags passed to SMC handlers */ |
| 31 | #define SMC_FROM_SECURE (U(0) << 0) |
| 32 | #define SMC_FROM_NON_SECURE (U(1) << 0) |
Antonio Nino Diaz | 085e80e | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 33 | |
| 34 | #ifndef __ASSEMBLY__ |
| 35 | |
| 36 | #include <cassert.h> |
| 37 | #include <stdint.h> |
| 38 | |
Antonio Nino Diaz | b3323cd | 2018-04-17 15:10:18 +0100 | [diff] [blame] | 39 | #define is_caller_non_secure(_f) (((_f) & SMC_FROM_NON_SECURE) != U(0)) |
| 40 | #define is_caller_secure(_f) (!is_caller_non_secure(_f)) |
Antonio Nino Diaz | 085e80e | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 41 | |
| 42 | /* The macro below is used to identify a Standard Service SMC call */ |
Antonio Nino Diaz | 2f37046 | 2018-04-23 15:43:29 +0100 | [diff] [blame] | 43 | #define is_std_svc_call(_fid) (GET_SMC_OEN(_fid) == OEN_STD_START) |
Antonio Nino Diaz | 085e80e | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 44 | |
| 45 | /* The macro below is used to identify a Arm Architectural Service SMC call */ |
Antonio Nino Diaz | 2f37046 | 2018-04-23 15:43:29 +0100 | [diff] [blame] | 46 | #define is_arm_arch_svc_call(_fid) (GET_SMC_OEN(_fid) == OEN_ARM_START) |
Antonio Nino Diaz | 085e80e | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 47 | |
| 48 | /* The macro below is used to identify a valid Fast SMC call */ |
| 49 | #define is_valid_fast_smc(_fid) ((!(((_fid) >> 16) & U(0xff))) && \ |
| 50 | (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST)) |
| 51 | |
| 52 | /* |
| 53 | * Macro to define UUID for services. Apart from defining and initializing a |
| 54 | * uuid_t structure, this macro verifies that the first word of the defined UUID |
| 55 | * does not equal SMC_UNK. This is to ensure that the caller won't mistake the |
| 56 | * returned UUID in x0 for an invalid SMC error return |
| 57 | */ |
| 58 | #define DEFINE_SVC_UUID(_name, _tl, _tm, _th, _cl, _ch, \ |
| 59 | _n0, _n1, _n2, _n3, _n4, _n5) \ |
| 60 | CASSERT((uint32_t)(_tl) != (uint32_t) SMC_UNK, invalid_svc_uuid);\ |
| 61 | static const uuid_t _name = { \ |
| 62 | _tl, _tm, _th, _cl, _ch, \ |
| 63 | { _n0, _n1, _n2, _n3, _n4, _n5 } \ |
| 64 | } |
| 65 | |
| 66 | #endif /*__ASSEMBLY__*/ |
| 67 | #endif /* __SMCCC_H__ */ |