Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 2 | * Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +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 | |
| 31 | #ifndef __RUNTIME_SVC_H__ |
| 32 | #define __RUNTIME_SVC_H__ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 33 | |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 34 | #include <bl_common.h> /* to include exception types */ |
| 35 | #include <smcc_helpers.h> /* to include SMCC definitions */ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 36 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 37 | |
Achin Gupta | 4a826dd | 2013-11-25 14:00:56 +0000 | [diff] [blame] | 38 | /******************************************************************************* |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 39 | * Structure definition, typedefs & constants for the runtime service framework |
Achin Gupta | 4a826dd | 2013-11-25 14:00:56 +0000 | [diff] [blame] | 40 | ******************************************************************************/ |
Achin Gupta | 4a826dd | 2013-11-25 14:00:56 +0000 | [diff] [blame] | 41 | |
Achin Gupta | 7421b46 | 2014-02-01 18:53:26 +0000 | [diff] [blame] | 42 | /* |
| 43 | * Constants to allow the assembler access a runtime service |
| 44 | * descriptor |
| 45 | */ |
Soby Mathew | a9482df | 2016-05-05 12:49:09 +0100 | [diff] [blame] | 46 | #ifdef AARCH32 |
| 47 | #define RT_SVC_SIZE_LOG2 4 |
| 48 | #define RT_SVC_DESC_INIT 8 |
| 49 | #define RT_SVC_DESC_HANDLE 12 |
| 50 | #else |
Achin Gupta | 07f4e07 | 2014-02-02 12:02:23 +0000 | [diff] [blame] | 51 | #define RT_SVC_SIZE_LOG2 5 |
Achin Gupta | 7421b46 | 2014-02-01 18:53:26 +0000 | [diff] [blame] | 52 | #define RT_SVC_DESC_INIT 16 |
| 53 | #define RT_SVC_DESC_HANDLE 24 |
Soby Mathew | a9482df | 2016-05-05 12:49:09 +0100 | [diff] [blame] | 54 | #endif /* AARCH32 */ |
| 55 | #define SIZEOF_RT_SVC_DESC (1 << RT_SVC_SIZE_LOG2) |
| 56 | |
Achin Gupta | 7421b46 | 2014-02-01 18:53:26 +0000 | [diff] [blame] | 57 | |
| 58 | /* |
| 59 | * The function identifier has 6 bits for the owning entity number and |
| 60 | * single bit for the type of smc call. When taken together these |
| 61 | * values limit the maximum number of runtime services to 128. |
| 62 | */ |
| 63 | #define MAX_RT_SVCS 128 |
| 64 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 65 | #ifndef __ASSEMBLY__ |
| 66 | |
Achin Gupta | 7421b46 | 2014-02-01 18:53:26 +0000 | [diff] [blame] | 67 | /* Prototype for runtime service initializing function */ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 68 | typedef int32_t (*rt_svc_init_t)(void); |
Achin Gupta | 7421b46 | 2014-02-01 18:53:26 +0000 | [diff] [blame] | 69 | |
Achin Gupta | 7421b46 | 2014-02-01 18:53:26 +0000 | [diff] [blame] | 70 | /* |
| 71 | * Prototype for runtime service SMC handler function. x0 (SMC Function ID) to |
| 72 | * x4 are as passed by the caller. Rest of the arguments to SMC and the context |
| 73 | * can be accessed using the handle pointer. The cookie parameter is reserved |
| 74 | * for future use |
| 75 | */ |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 76 | typedef uintptr_t (*rt_svc_handle_t)(uint32_t smc_fid, |
| 77 | u_register_t x1, |
| 78 | u_register_t x2, |
| 79 | u_register_t x3, |
| 80 | u_register_t x4, |
Achin Gupta | 7421b46 | 2014-02-01 18:53:26 +0000 | [diff] [blame] | 81 | void *cookie, |
| 82 | void *handle, |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 83 | u_register_t flags); |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 84 | typedef struct rt_svc_desc { |
Achin Gupta | 7421b46 | 2014-02-01 18:53:26 +0000 | [diff] [blame] | 85 | uint8_t start_oen; |
| 86 | uint8_t end_oen; |
| 87 | uint8_t call_type; |
| 88 | const char *name; |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 89 | rt_svc_init_t init; |
| 90 | rt_svc_handle_t handle; |
| 91 | } rt_svc_desc_t; |
Achin Gupta | 7421b46 | 2014-02-01 18:53:26 +0000 | [diff] [blame] | 92 | |
| 93 | /* |
| 94 | * Convenience macro to declare a service descriptor |
| 95 | */ |
| 96 | #define DECLARE_RT_SVC(_name, _start, _end, _type, _setup, _smch) \ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 97 | static const rt_svc_desc_t __svc_desc_ ## _name \ |
Soren Brinkmann | 46dd170 | 2016-01-14 10:11:05 -0800 | [diff] [blame] | 98 | __section("rt_svc_descs") __used = { \ |
Soby Mathew | 7162afa | 2016-01-12 10:28:42 +0000 | [diff] [blame] | 99 | .start_oen = _start, \ |
| 100 | .end_oen = _end, \ |
| 101 | .call_type = _type, \ |
| 102 | .name = #_name, \ |
| 103 | .init = _setup, \ |
| 104 | .handle = _smch } |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 105 | |
Achin Gupta | 7421b46 | 2014-02-01 18:53:26 +0000 | [diff] [blame] | 106 | /* |
| 107 | * Compile time assertions related to the 'rt_svc_desc' structure to: |
| 108 | * 1. ensure that the assembler and the compiler view of the size |
| 109 | * of the structure are the same. |
| 110 | * 2. ensure that the assembler and the compiler see the initialisation |
| 111 | * routine at the same offset. |
Achin Gupta | 07f4e07 | 2014-02-02 12:02:23 +0000 | [diff] [blame] | 112 | * 3. ensure that the assembler and the compiler see the handler |
Achin Gupta | 7421b46 | 2014-02-01 18:53:26 +0000 | [diff] [blame] | 113 | * routine at the same offset. |
| 114 | */ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 115 | CASSERT((sizeof(rt_svc_desc_t) == SIZEOF_RT_SVC_DESC), \ |
Achin Gupta | 7421b46 | 2014-02-01 18:53:26 +0000 | [diff] [blame] | 116 | assert_sizeof_rt_svc_desc_mismatch); |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 117 | CASSERT(RT_SVC_DESC_INIT == __builtin_offsetof(rt_svc_desc_t, init), \ |
Achin Gupta | 7421b46 | 2014-02-01 18:53:26 +0000 | [diff] [blame] | 118 | assert_rt_svc_desc_init_offset_mismatch); |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 119 | CASSERT(RT_SVC_DESC_HANDLE == __builtin_offsetof(rt_svc_desc_t, handle), \ |
Achin Gupta | 7421b46 | 2014-02-01 18:53:26 +0000 | [diff] [blame] | 120 | assert_rt_svc_desc_handle_offset_mismatch); |
| 121 | |
| 122 | |
| 123 | /* |
| 124 | * This macro combines the call type and the owning entity number corresponding |
| 125 | * to a runtime service to generate a unique owning entity number. This unique |
| 126 | * oen is used to access an entry in the 'rt_svc_descs_indices' array. The entry |
| 127 | * contains the index of the service descriptor in the 'rt_svc_descs' array. |
| 128 | */ |
| 129 | #define get_unique_oen(oen, call_type) ((oen & FUNCID_OEN_MASK) | \ |
| 130 | ((call_type & FUNCID_TYPE_MASK) \ |
| 131 | << FUNCID_OEN_WIDTH)) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 132 | |
Soby Mathew | a9482df | 2016-05-05 12:49:09 +0100 | [diff] [blame] | 133 | /* |
| 134 | * This macro generates the unique owning entity number from the SMC Function |
| 135 | * ID. This unique oen is used to access an entry in the |
| 136 | * 'rt_svc_descs_indices' array to invoke the corresponding runtime service |
| 137 | * handler during SMC handling. |
| 138 | */ |
| 139 | #define get_unique_oen_from_smc_fid(fid) \ |
| 140 | get_unique_oen(((fid) >> FUNCID_OEN_SHIFT), \ |
| 141 | ((fid) >> FUNCID_TYPE_SHIFT)) |
| 142 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 143 | /******************************************************************************* |
| 144 | * Function & variable prototypes |
| 145 | ******************************************************************************/ |
Juan Castillo | 2d55240 | 2014-06-13 17:05:10 +0100 | [diff] [blame] | 146 | void runtime_svc_init(void); |
Soby Mathew | a9482df | 2016-05-05 12:49:09 +0100 | [diff] [blame] | 147 | uintptr_t handle_runtime_svc(uint32_t smc_fid, void *cookie, void *handle, |
| 148 | unsigned int flags); |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 149 | extern uintptr_t __RT_SVC_DESCS_START__; |
| 150 | extern uintptr_t __RT_SVC_DESCS_END__; |
Andrew Thoelke | 8c28fe0 | 2014-06-02 11:40:35 +0100 | [diff] [blame] | 151 | void init_crash_reporting(void); |
Andrew Thoelke | 8c28fe0 | 2014-06-02 11:40:35 +0100 | [diff] [blame] | 152 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 153 | #endif /*__ASSEMBLY__*/ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 154 | #endif /* __RUNTIME_SVC_H__ */ |