Yatharth Kochar | bbf8f6f | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 1 | /* |
David Cunado | 9edac04 | 2017-01-19 10:26:16 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved. |
Yatharth Kochar | bbf8f6f | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
Soby Mathew | cf0b149 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 31 | #ifndef __SMCC_H__ |
| 32 | #define __SMCC_H__ |
Yatharth Kochar | bbf8f6f | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 33 | |
Scott Branden | 53d9c9c | 2017-04-10 11:45:52 -0700 | [diff] [blame] | 34 | #include <utils_def.h> |
David Cunado | 9edac04 | 2017-01-19 10:26:16 +0000 | [diff] [blame] | 35 | |
Yatharth Kochar | bbf8f6f | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 36 | /******************************************************************************* |
| 37 | * Bit definitions inside the function id as per the SMC calling convention |
| 38 | ******************************************************************************/ |
| 39 | #define FUNCID_TYPE_SHIFT 31 |
| 40 | #define FUNCID_CC_SHIFT 30 |
| 41 | #define FUNCID_OEN_SHIFT 24 |
| 42 | #define FUNCID_NUM_SHIFT 0 |
| 43 | |
| 44 | #define FUNCID_TYPE_MASK 0x1 |
| 45 | #define FUNCID_CC_MASK 0x1 |
| 46 | #define FUNCID_OEN_MASK 0x3f |
| 47 | #define FUNCID_NUM_MASK 0xffff |
| 48 | |
| 49 | #define FUNCID_TYPE_WIDTH 1 |
| 50 | #define FUNCID_CC_WIDTH 1 |
| 51 | #define FUNCID_OEN_WIDTH 6 |
| 52 | #define FUNCID_NUM_WIDTH 16 |
| 53 | |
| 54 | #define GET_SMC_CC(id) ((id >> FUNCID_CC_SHIFT) & \ |
| 55 | FUNCID_CC_MASK) |
| 56 | #define GET_SMC_TYPE(id) ((id >> FUNCID_TYPE_SHIFT) & \ |
| 57 | FUNCID_TYPE_MASK) |
| 58 | |
| 59 | #define SMC_64 1 |
| 60 | #define SMC_32 0 |
Antonio Nino Diaz | 7a317a7 | 2017-04-04 17:08:32 +0100 | [diff] [blame] | 61 | #define SMC_OK 0 |
Yatharth Kochar | bbf8f6f | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 62 | #define SMC_UNK 0xffffffff |
David Cunado | 9edac04 | 2017-01-19 10:26:16 +0000 | [diff] [blame] | 63 | #define SMC_TYPE_FAST ULL(1) |
Yatharth Kochar | bbf8f6f | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 64 | #define SMC_TYPE_STD 0 |
| 65 | #define SMC_PREEMPTED 0xfffffffe |
| 66 | /******************************************************************************* |
| 67 | * Owning entity number definitions inside the function id as per the SMC |
| 68 | * calling convention |
| 69 | ******************************************************************************/ |
| 70 | #define OEN_ARM_START 0 |
| 71 | #define OEN_ARM_END 0 |
| 72 | #define OEN_CPU_START 1 |
| 73 | #define OEN_CPU_END 1 |
| 74 | #define OEN_SIP_START 2 |
| 75 | #define OEN_SIP_END 2 |
| 76 | #define OEN_OEM_START 3 |
| 77 | #define OEN_OEM_END 3 |
| 78 | #define OEN_STD_START 4 /* Standard Calls */ |
| 79 | #define OEN_STD_END 4 |
| 80 | #define OEN_TAP_START 48 /* Trusted Applications */ |
| 81 | #define OEN_TAP_END 49 |
| 82 | #define OEN_TOS_START 50 /* Trusted OS */ |
| 83 | #define OEN_TOS_END 63 |
| 84 | #define OEN_LIMIT 64 |
| 85 | |
| 86 | #ifndef __ASSEMBLY__ |
| 87 | |
| 88 | #include <cassert.h> |
Yatharth Kochar | bbf8f6f | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 89 | #include <stdint.h> |
| 90 | |
| 91 | /* Various flags passed to SMC handlers */ |
| 92 | #define SMC_FROM_SECURE (0 << 0) |
| 93 | #define SMC_FROM_NON_SECURE (1 << 0) |
| 94 | |
| 95 | #define is_caller_non_secure(_f) (!!(_f & SMC_FROM_NON_SECURE)) |
| 96 | #define is_caller_secure(_f) (!(is_caller_non_secure(_f))) |
| 97 | |
Yatharth Kochar | bbf8f6f | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 98 | /* The macro below is used to identify a Standard Service SMC call */ |
| 99 | #define is_std_svc_call(_fid) ((((_fid) >> FUNCID_OEN_SHIFT) & \ |
| 100 | FUNCID_OEN_MASK) == OEN_STD_START) |
| 101 | |
| 102 | /* The macro below is used to identify a valid Fast SMC call */ |
| 103 | #define is_valid_fast_smc(_fid) ((!(((_fid) >> 16) & 0xff)) && \ |
| 104 | (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST)) |
| 105 | |
| 106 | /* |
| 107 | * Macro to define UUID for services. Apart from defining and initializing a |
| 108 | * uuid_t structure, this macro verifies that the first word of the defined UUID |
| 109 | * does not equal SMC_UNK. This is to ensure that the caller won't mistake the |
| 110 | * returned UUID in x0 for an invalid SMC error return |
| 111 | */ |
| 112 | #define DEFINE_SVC_UUID(_name, _tl, _tm, _th, _cl, _ch, \ |
| 113 | _n0, _n1, _n2, _n3, _n4, _n5) \ |
| 114 | CASSERT(_tl != SMC_UNK, invalid_svc_uuid);\ |
| 115 | static const uuid_t _name = { \ |
| 116 | _tl, _tm, _th, _cl, _ch, \ |
| 117 | { _n0, _n1, _n2, _n3, _n4, _n5 } \ |
| 118 | } |
| 119 | |
Yatharth Kochar | bbf8f6f | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 120 | #endif /*__ASSEMBLY__*/ |
Soby Mathew | cf0b149 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 121 | #endif /* __SMCC_H__ */ |