Antonio Nino Diaz | 3c817f4 | 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 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 7 | #ifndef SMCCC_H |
| 8 | #define SMCCC_H |
Antonio Nino Diaz | 3c817f4 | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 9 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | #include <lib/utils_def.h> |
Antonio Nino Diaz | 3c817f4 | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 11 | |
Antonio Nino Diaz | 35c8cfc | 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) \ |
Antonio Nino Diaz | 39ed74d | 2018-05-02 09:52:35 +0100 | [diff] [blame] | 17 | ((((uint32_t)(_major) & SMCCC_VERSION_MAJOR_MASK) << \ |
| 18 | SMCCC_VERSION_MAJOR_SHIFT) \ |
| 19 | | (((uint32_t)(_minor) & SMCCC_VERSION_MINOR_MASK) << \ |
| 20 | SMCCC_VERSION_MINOR_SHIFT)) |
Antonio Nino Diaz | 3c817f4 | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 21 | |
Antonio Nino Diaz | 35c8cfc | 2018-04-23 15:43:29 +0100 | [diff] [blame] | 22 | #if SMCCC_MAJOR_VERSION == 1 |
| 23 | # define SMCCC_MINOR_VERSION U(1) |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 24 | # include <lib/smccc_v1.h> |
Antonio Nino Diaz | 35c8cfc | 2018-04-23 15:43:29 +0100 | [diff] [blame] | 25 | #elif SMCCC_MAJOR_VERSION == 2 |
| 26 | # define SMCCC_MINOR_VERSION U(0) |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 27 | # include <lib/smccc_v2.h> |
Antonio Nino Diaz | 35c8cfc | 2018-04-23 15:43:29 +0100 | [diff] [blame] | 28 | #else |
| 29 | # error "Unsupported version of SMCCC." |
Antonio Nino Diaz | 3c817f4 | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 30 | #endif |
Antonio Nino Diaz | 35c8cfc | 2018-04-23 15:43:29 +0100 | [diff] [blame] | 31 | |
| 32 | /* Various flags passed to SMC handlers */ |
| 33 | #define SMC_FROM_SECURE (U(0) << 0) |
| 34 | #define SMC_FROM_NON_SECURE (U(1) << 0) |
Antonio Nino Diaz | 3c817f4 | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 35 | |
| 36 | #ifndef __ASSEMBLY__ |
| 37 | |
Antonio Nino Diaz | 3c817f4 | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 38 | #include <stdint.h> |
| 39 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 40 | #include <lib/cassert.h> |
| 41 | |
Antonio Nino Diaz | e881147 | 2018-04-17 15:10:18 +0100 | [diff] [blame] | 42 | #define is_caller_non_secure(_f) (((_f) & SMC_FROM_NON_SECURE) != U(0)) |
| 43 | #define is_caller_secure(_f) (!is_caller_non_secure(_f)) |
Antonio Nino Diaz | 3c817f4 | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 44 | |
| 45 | /* The macro below is used to identify a Standard Service SMC call */ |
Antonio Nino Diaz | 35c8cfc | 2018-04-23 15:43:29 +0100 | [diff] [blame] | 46 | #define is_std_svc_call(_fid) (GET_SMC_OEN(_fid) == OEN_STD_START) |
Antonio Nino Diaz | 3c817f4 | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 47 | |
| 48 | /* The macro below is used to identify a Arm Architectural Service SMC call */ |
Antonio Nino Diaz | 35c8cfc | 2018-04-23 15:43:29 +0100 | [diff] [blame] | 49 | #define is_arm_arch_svc_call(_fid) (GET_SMC_OEN(_fid) == OEN_ARM_START) |
Antonio Nino Diaz | 3c817f4 | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 50 | |
| 51 | /* The macro below is used to identify a valid Fast SMC call */ |
| 52 | #define is_valid_fast_smc(_fid) ((!(((_fid) >> 16) & U(0xff))) && \ |
| 53 | (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST)) |
| 54 | |
| 55 | /* |
| 56 | * Macro to define UUID for services. Apart from defining and initializing a |
| 57 | * uuid_t structure, this macro verifies that the first word of the defined UUID |
| 58 | * does not equal SMC_UNK. This is to ensure that the caller won't mistake the |
| 59 | * returned UUID in x0 for an invalid SMC error return |
| 60 | */ |
Roberto Vargas | eace8f1 | 2018-04-26 13:36:53 +0100 | [diff] [blame] | 61 | #define DEFINE_SVC_UUID2(_name, _tl, _tm, _th, _cl, _ch, \ |
| 62 | _n0, _n1, _n2, _n3, _n4, _n5) \ |
| 63 | CASSERT((uint32_t)(_tl) != (uint32_t) SMC_UNK, invalid_svc_uuid);\ |
| 64 | static const uuid_t _name = { \ |
| 65 | {(_tl >> 24) & 0xFF, \ |
| 66 | (_tl >> 16) & 0xFF, \ |
| 67 | (_tl >> 8) & 0xFF, \ |
| 68 | (_tl & 0xFF)}, \ |
| 69 | {(_tm >> 8) & 0xFF, \ |
| 70 | (_tm & 0xFF)}, \ |
| 71 | {(_th >> 8) & 0xFF, \ |
| 72 | (_th & 0xFF)}, \ |
| 73 | _cl, _ch, \ |
| 74 | { _n0, _n1, _n2, _n3, _n4, _n5 } \ |
| 75 | } |
Antonio Nino Diaz | 3c817f4 | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 76 | |
Sandrine Bailleux | c5e8978 | 2018-07-02 13:01:16 +0200 | [diff] [blame] | 77 | /* |
| 78 | * Return a UUID in the SMC return registers. |
| 79 | * |
| 80 | * Acccording to section 5.3 of the SMCCC, UUIDs are returned as a single |
| 81 | * 128-bit value using the SMC32 calling convention. This value is mapped to |
| 82 | * argument registers x0-x3 on AArch64 (resp. r0-r3 on AArch32). x0 for example |
| 83 | * shall hold bytes 0 to 3, with byte 0 in the low-order bits. |
| 84 | */ |
| 85 | static inline uint32_t smc_uuid_word(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3) |
| 86 | { |
| 87 | return ((uint32_t) b0) | (((uint32_t) b1) << 8) | |
| 88 | (((uint32_t) b2) << 16) | (((uint32_t) b3) << 24); |
| 89 | } |
| 90 | |
| 91 | #define SMC_UUID_RET(_h, _uuid) \ |
| 92 | SMC_RET4(handle, \ |
| 93 | smc_uuid_word((_uuid).time_low[0], (_uuid).time_low[1], \ |
| 94 | (_uuid).time_low[2], (_uuid).time_low[3]), \ |
| 95 | smc_uuid_word((_uuid).time_mid[0], (_uuid).time_mid[1], \ |
| 96 | (_uuid).time_hi_and_version[0], \ |
| 97 | (_uuid).time_hi_and_version[1]), \ |
| 98 | smc_uuid_word((_uuid).clock_seq_hi_and_reserved, \ |
| 99 | (_uuid).clock_seq_low, (_uuid).node[0], \ |
| 100 | (_uuid).node[1]), \ |
| 101 | smc_uuid_word((_uuid).node[2], (_uuid).node[3], \ |
| 102 | (_uuid).node[4], (_uuid).node[5])) |
| 103 | |
Antonio Nino Diaz | 3c817f4 | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 104 | #endif /*__ASSEMBLY__*/ |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 105 | #endif /* SMCCC_H */ |