1532ed618SSoby Mathew /* 2532ed618SSoby Mathew * Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved. 3532ed618SSoby Mathew * 4532ed618SSoby Mathew * Redistribution and use in source and binary forms, with or without 5532ed618SSoby Mathew * modification, are permitted provided that the following conditions are met: 6532ed618SSoby Mathew * 7532ed618SSoby Mathew * Redistributions of source code must retain the above copyright notice, this 8532ed618SSoby Mathew * list of conditions and the following disclaimer. 9532ed618SSoby Mathew * 10532ed618SSoby Mathew * Redistributions in binary form must reproduce the above copyright notice, 11532ed618SSoby Mathew * this list of conditions and the following disclaimer in the documentation 12532ed618SSoby Mathew * and/or other materials provided with the distribution. 13532ed618SSoby Mathew * 14532ed618SSoby Mathew * Neither the name of ARM nor the names of its contributors may be used 15532ed618SSoby Mathew * to endorse or promote products derived from this software without specific 16532ed618SSoby Mathew * prior written permission. 17532ed618SSoby Mathew * 18532ed618SSoby Mathew * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19532ed618SSoby Mathew * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20532ed618SSoby Mathew * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21532ed618SSoby Mathew * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22532ed618SSoby Mathew * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23532ed618SSoby Mathew * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24532ed618SSoby Mathew * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25532ed618SSoby Mathew * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26532ed618SSoby Mathew * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27532ed618SSoby Mathew * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28532ed618SSoby Mathew * POSSIBILITY OF SUCH DAMAGE. 29532ed618SSoby Mathew */ 30532ed618SSoby Mathew 31532ed618SSoby Mathew #ifndef __RUNTIME_SVC_H__ 32532ed618SSoby Mathew #define __RUNTIME_SVC_H__ 33532ed618SSoby Mathew 34532ed618SSoby Mathew #include <bl_common.h> /* to include exception types */ 35532ed618SSoby Mathew #include <smcc_helpers.h> /* to include SMCC definitions */ 36532ed618SSoby Mathew 37532ed618SSoby Mathew 38532ed618SSoby Mathew /******************************************************************************* 39532ed618SSoby Mathew * Structure definition, typedefs & constants for the runtime service framework 40532ed618SSoby Mathew ******************************************************************************/ 41532ed618SSoby Mathew 42532ed618SSoby Mathew /* 43532ed618SSoby Mathew * Constants to allow the assembler access a runtime service 44532ed618SSoby Mathew * descriptor 45532ed618SSoby Mathew */ 46*1ae0a49aSSoby Mathew #ifdef AARCH32 47*1ae0a49aSSoby Mathew #define RT_SVC_SIZE_LOG2 4 48*1ae0a49aSSoby Mathew #define RT_SVC_DESC_INIT 8 49*1ae0a49aSSoby Mathew #define RT_SVC_DESC_HANDLE 12 50*1ae0a49aSSoby Mathew #else 51532ed618SSoby Mathew #define RT_SVC_SIZE_LOG2 5 52532ed618SSoby Mathew #define RT_SVC_DESC_INIT 16 53532ed618SSoby Mathew #define RT_SVC_DESC_HANDLE 24 54*1ae0a49aSSoby Mathew #endif /* AARCH32 */ 55*1ae0a49aSSoby Mathew #define SIZEOF_RT_SVC_DESC (1 << RT_SVC_SIZE_LOG2) 56*1ae0a49aSSoby Mathew 57532ed618SSoby Mathew 58532ed618SSoby Mathew /* 59532ed618SSoby Mathew * The function identifier has 6 bits for the owning entity number and 60532ed618SSoby Mathew * single bit for the type of smc call. When taken together these 61532ed618SSoby Mathew * values limit the maximum number of runtime services to 128. 62532ed618SSoby Mathew */ 63532ed618SSoby Mathew #define MAX_RT_SVCS 128 64532ed618SSoby Mathew 65532ed618SSoby Mathew #ifndef __ASSEMBLY__ 66532ed618SSoby Mathew 67532ed618SSoby Mathew /* Prototype for runtime service initializing function */ 68532ed618SSoby Mathew typedef int32_t (*rt_svc_init_t)(void); 69532ed618SSoby Mathew 70532ed618SSoby Mathew /* 71532ed618SSoby Mathew * Prototype for runtime service SMC handler function. x0 (SMC Function ID) to 72532ed618SSoby Mathew * x4 are as passed by the caller. Rest of the arguments to SMC and the context 73532ed618SSoby Mathew * can be accessed using the handle pointer. The cookie parameter is reserved 74532ed618SSoby Mathew * for future use 75532ed618SSoby Mathew */ 76532ed618SSoby Mathew typedef uintptr_t (*rt_svc_handle_t)(uint32_t smc_fid, 77532ed618SSoby Mathew u_register_t x1, 78532ed618SSoby Mathew u_register_t x2, 79532ed618SSoby Mathew u_register_t x3, 80532ed618SSoby Mathew u_register_t x4, 81532ed618SSoby Mathew void *cookie, 82532ed618SSoby Mathew void *handle, 83532ed618SSoby Mathew u_register_t flags); 84532ed618SSoby Mathew typedef struct rt_svc_desc { 85532ed618SSoby Mathew uint8_t start_oen; 86532ed618SSoby Mathew uint8_t end_oen; 87532ed618SSoby Mathew uint8_t call_type; 88532ed618SSoby Mathew const char *name; 89532ed618SSoby Mathew rt_svc_init_t init; 90532ed618SSoby Mathew rt_svc_handle_t handle; 91532ed618SSoby Mathew } rt_svc_desc_t; 92532ed618SSoby Mathew 93532ed618SSoby Mathew /* 94532ed618SSoby Mathew * Convenience macro to declare a service descriptor 95532ed618SSoby Mathew */ 96532ed618SSoby Mathew #define DECLARE_RT_SVC(_name, _start, _end, _type, _setup, _smch) \ 97532ed618SSoby Mathew static const rt_svc_desc_t __svc_desc_ ## _name \ 98532ed618SSoby Mathew __section("rt_svc_descs") __used = { \ 99532ed618SSoby Mathew .start_oen = _start, \ 100532ed618SSoby Mathew .end_oen = _end, \ 101532ed618SSoby Mathew .call_type = _type, \ 102532ed618SSoby Mathew .name = #_name, \ 103532ed618SSoby Mathew .init = _setup, \ 104532ed618SSoby Mathew .handle = _smch } 105532ed618SSoby Mathew 106532ed618SSoby Mathew /* 107532ed618SSoby Mathew * Compile time assertions related to the 'rt_svc_desc' structure to: 108532ed618SSoby Mathew * 1. ensure that the assembler and the compiler view of the size 109532ed618SSoby Mathew * of the structure are the same. 110532ed618SSoby Mathew * 2. ensure that the assembler and the compiler see the initialisation 111532ed618SSoby Mathew * routine at the same offset. 112532ed618SSoby Mathew * 3. ensure that the assembler and the compiler see the handler 113532ed618SSoby Mathew * routine at the same offset. 114532ed618SSoby Mathew */ 115532ed618SSoby Mathew CASSERT((sizeof(rt_svc_desc_t) == SIZEOF_RT_SVC_DESC), \ 116532ed618SSoby Mathew assert_sizeof_rt_svc_desc_mismatch); 117532ed618SSoby Mathew CASSERT(RT_SVC_DESC_INIT == __builtin_offsetof(rt_svc_desc_t, init), \ 118532ed618SSoby Mathew assert_rt_svc_desc_init_offset_mismatch); 119532ed618SSoby Mathew CASSERT(RT_SVC_DESC_HANDLE == __builtin_offsetof(rt_svc_desc_t, handle), \ 120532ed618SSoby Mathew assert_rt_svc_desc_handle_offset_mismatch); 121532ed618SSoby Mathew 122532ed618SSoby Mathew 123532ed618SSoby Mathew /* 124532ed618SSoby Mathew * This macro combines the call type and the owning entity number corresponding 125532ed618SSoby Mathew * to a runtime service to generate a unique owning entity number. This unique 126532ed618SSoby Mathew * oen is used to access an entry in the 'rt_svc_descs_indices' array. The entry 127532ed618SSoby Mathew * contains the index of the service descriptor in the 'rt_svc_descs' array. 128532ed618SSoby Mathew */ 129532ed618SSoby Mathew #define get_unique_oen(oen, call_type) ((oen & FUNCID_OEN_MASK) | \ 130532ed618SSoby Mathew ((call_type & FUNCID_TYPE_MASK) \ 131532ed618SSoby Mathew << FUNCID_OEN_WIDTH)) 132532ed618SSoby Mathew 133*1ae0a49aSSoby Mathew /* 134*1ae0a49aSSoby Mathew * This macro generates the unique owning entity number from the SMC Function 135*1ae0a49aSSoby Mathew * ID. This unique oen is used to access an entry in the 136*1ae0a49aSSoby Mathew * 'rt_svc_descs_indices' array to invoke the corresponding runtime service 137*1ae0a49aSSoby Mathew * handler during SMC handling. 138*1ae0a49aSSoby Mathew */ 139*1ae0a49aSSoby Mathew #define get_unique_oen_from_smc_fid(fid) \ 140*1ae0a49aSSoby Mathew get_unique_oen(((fid) >> FUNCID_OEN_SHIFT), \ 141*1ae0a49aSSoby Mathew ((fid) >> FUNCID_TYPE_SHIFT)) 142*1ae0a49aSSoby Mathew 143532ed618SSoby Mathew /******************************************************************************* 144532ed618SSoby Mathew * Function & variable prototypes 145532ed618SSoby Mathew ******************************************************************************/ 146532ed618SSoby Mathew void runtime_svc_init(void); 147*1ae0a49aSSoby Mathew uintptr_t handle_runtime_svc(uint32_t smc_fid, void *cookie, void *handle, 148*1ae0a49aSSoby Mathew unsigned int flags); 149532ed618SSoby Mathew extern uintptr_t __RT_SVC_DESCS_START__; 150532ed618SSoby Mathew extern uintptr_t __RT_SVC_DESCS_END__; 151532ed618SSoby Mathew void init_crash_reporting(void); 152532ed618SSoby Mathew 153532ed618SSoby Mathew #endif /*__ASSEMBLY__*/ 154532ed618SSoby Mathew #endif /* __RUNTIME_SVC_H__ */ 155