1*532ed618SSoby Mathew /* 2*532ed618SSoby Mathew * Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved. 3*532ed618SSoby Mathew * 4*532ed618SSoby Mathew * Redistribution and use in source and binary forms, with or without 5*532ed618SSoby Mathew * modification, are permitted provided that the following conditions are met: 6*532ed618SSoby Mathew * 7*532ed618SSoby Mathew * Redistributions of source code must retain the above copyright notice, this 8*532ed618SSoby Mathew * list of conditions and the following disclaimer. 9*532ed618SSoby Mathew * 10*532ed618SSoby Mathew * Redistributions in binary form must reproduce the above copyright notice, 11*532ed618SSoby Mathew * this list of conditions and the following disclaimer in the documentation 12*532ed618SSoby Mathew * and/or other materials provided with the distribution. 13*532ed618SSoby Mathew * 14*532ed618SSoby Mathew * Neither the name of ARM nor the names of its contributors may be used 15*532ed618SSoby Mathew * to endorse or promote products derived from this software without specific 16*532ed618SSoby Mathew * prior written permission. 17*532ed618SSoby Mathew * 18*532ed618SSoby Mathew * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19*532ed618SSoby Mathew * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*532ed618SSoby Mathew * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*532ed618SSoby Mathew * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22*532ed618SSoby Mathew * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23*532ed618SSoby Mathew * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24*532ed618SSoby Mathew * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25*532ed618SSoby Mathew * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26*532ed618SSoby Mathew * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27*532ed618SSoby Mathew * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28*532ed618SSoby Mathew * POSSIBILITY OF SUCH DAMAGE. 29*532ed618SSoby Mathew */ 30*532ed618SSoby Mathew 31*532ed618SSoby Mathew #ifndef __RUNTIME_SVC_H__ 32*532ed618SSoby Mathew #define __RUNTIME_SVC_H__ 33*532ed618SSoby Mathew 34*532ed618SSoby Mathew #include <bl_common.h> /* to include exception types */ 35*532ed618SSoby Mathew #include <smcc_helpers.h> /* to include SMCC definitions */ 36*532ed618SSoby Mathew 37*532ed618SSoby Mathew 38*532ed618SSoby Mathew /******************************************************************************* 39*532ed618SSoby Mathew * Structure definition, typedefs & constants for the runtime service framework 40*532ed618SSoby Mathew ******************************************************************************/ 41*532ed618SSoby Mathew 42*532ed618SSoby Mathew /* 43*532ed618SSoby Mathew * Constants to allow the assembler access a runtime service 44*532ed618SSoby Mathew * descriptor 45*532ed618SSoby Mathew */ 46*532ed618SSoby Mathew #define RT_SVC_SIZE_LOG2 5 47*532ed618SSoby Mathew #define SIZEOF_RT_SVC_DESC (1 << RT_SVC_SIZE_LOG2) 48*532ed618SSoby Mathew #define RT_SVC_DESC_INIT 16 49*532ed618SSoby Mathew #define RT_SVC_DESC_HANDLE 24 50*532ed618SSoby Mathew 51*532ed618SSoby Mathew /* 52*532ed618SSoby Mathew * The function identifier has 6 bits for the owning entity number and 53*532ed618SSoby Mathew * single bit for the type of smc call. When taken together these 54*532ed618SSoby Mathew * values limit the maximum number of runtime services to 128. 55*532ed618SSoby Mathew */ 56*532ed618SSoby Mathew #define MAX_RT_SVCS 128 57*532ed618SSoby Mathew 58*532ed618SSoby Mathew #ifndef __ASSEMBLY__ 59*532ed618SSoby Mathew 60*532ed618SSoby Mathew /* Prototype for runtime service initializing function */ 61*532ed618SSoby Mathew typedef int32_t (*rt_svc_init_t)(void); 62*532ed618SSoby Mathew 63*532ed618SSoby Mathew /* 64*532ed618SSoby Mathew * Prototype for runtime service SMC handler function. x0 (SMC Function ID) to 65*532ed618SSoby Mathew * x4 are as passed by the caller. Rest of the arguments to SMC and the context 66*532ed618SSoby Mathew * can be accessed using the handle pointer. The cookie parameter is reserved 67*532ed618SSoby Mathew * for future use 68*532ed618SSoby Mathew */ 69*532ed618SSoby Mathew typedef uintptr_t (*rt_svc_handle_t)(uint32_t smc_fid, 70*532ed618SSoby Mathew u_register_t x1, 71*532ed618SSoby Mathew u_register_t x2, 72*532ed618SSoby Mathew u_register_t x3, 73*532ed618SSoby Mathew u_register_t x4, 74*532ed618SSoby Mathew void *cookie, 75*532ed618SSoby Mathew void *handle, 76*532ed618SSoby Mathew u_register_t flags); 77*532ed618SSoby Mathew typedef struct rt_svc_desc { 78*532ed618SSoby Mathew uint8_t start_oen; 79*532ed618SSoby Mathew uint8_t end_oen; 80*532ed618SSoby Mathew uint8_t call_type; 81*532ed618SSoby Mathew const char *name; 82*532ed618SSoby Mathew rt_svc_init_t init; 83*532ed618SSoby Mathew rt_svc_handle_t handle; 84*532ed618SSoby Mathew } rt_svc_desc_t; 85*532ed618SSoby Mathew 86*532ed618SSoby Mathew /* 87*532ed618SSoby Mathew * Convenience macro to declare a service descriptor 88*532ed618SSoby Mathew */ 89*532ed618SSoby Mathew #define DECLARE_RT_SVC(_name, _start, _end, _type, _setup, _smch) \ 90*532ed618SSoby Mathew static const rt_svc_desc_t __svc_desc_ ## _name \ 91*532ed618SSoby Mathew __section("rt_svc_descs") __used = { \ 92*532ed618SSoby Mathew .start_oen = _start, \ 93*532ed618SSoby Mathew .end_oen = _end, \ 94*532ed618SSoby Mathew .call_type = _type, \ 95*532ed618SSoby Mathew .name = #_name, \ 96*532ed618SSoby Mathew .init = _setup, \ 97*532ed618SSoby Mathew .handle = _smch } 98*532ed618SSoby Mathew 99*532ed618SSoby Mathew /* 100*532ed618SSoby Mathew * Compile time assertions related to the 'rt_svc_desc' structure to: 101*532ed618SSoby Mathew * 1. ensure that the assembler and the compiler view of the size 102*532ed618SSoby Mathew * of the structure are the same. 103*532ed618SSoby Mathew * 2. ensure that the assembler and the compiler see the initialisation 104*532ed618SSoby Mathew * routine at the same offset. 105*532ed618SSoby Mathew * 3. ensure that the assembler and the compiler see the handler 106*532ed618SSoby Mathew * routine at the same offset. 107*532ed618SSoby Mathew */ 108*532ed618SSoby Mathew CASSERT((sizeof(rt_svc_desc_t) == SIZEOF_RT_SVC_DESC), \ 109*532ed618SSoby Mathew assert_sizeof_rt_svc_desc_mismatch); 110*532ed618SSoby Mathew CASSERT(RT_SVC_DESC_INIT == __builtin_offsetof(rt_svc_desc_t, init), \ 111*532ed618SSoby Mathew assert_rt_svc_desc_init_offset_mismatch); 112*532ed618SSoby Mathew CASSERT(RT_SVC_DESC_HANDLE == __builtin_offsetof(rt_svc_desc_t, handle), \ 113*532ed618SSoby Mathew assert_rt_svc_desc_handle_offset_mismatch); 114*532ed618SSoby Mathew 115*532ed618SSoby Mathew 116*532ed618SSoby Mathew /* 117*532ed618SSoby Mathew * This macro combines the call type and the owning entity number corresponding 118*532ed618SSoby Mathew * to a runtime service to generate a unique owning entity number. This unique 119*532ed618SSoby Mathew * oen is used to access an entry in the 'rt_svc_descs_indices' array. The entry 120*532ed618SSoby Mathew * contains the index of the service descriptor in the 'rt_svc_descs' array. 121*532ed618SSoby Mathew */ 122*532ed618SSoby Mathew #define get_unique_oen(oen, call_type) ((oen & FUNCID_OEN_MASK) | \ 123*532ed618SSoby Mathew ((call_type & FUNCID_TYPE_MASK) \ 124*532ed618SSoby Mathew << FUNCID_OEN_WIDTH)) 125*532ed618SSoby Mathew 126*532ed618SSoby Mathew /******************************************************************************* 127*532ed618SSoby Mathew * Function & variable prototypes 128*532ed618SSoby Mathew ******************************************************************************/ 129*532ed618SSoby Mathew void runtime_svc_init(void); 130*532ed618SSoby Mathew extern uintptr_t __RT_SVC_DESCS_START__; 131*532ed618SSoby Mathew extern uintptr_t __RT_SVC_DESCS_END__; 132*532ed618SSoby Mathew void init_crash_reporting(void); 133*532ed618SSoby Mathew 134*532ed618SSoby Mathew #endif /*__ASSEMBLY__*/ 135*532ed618SSoby Mathew #endif /* __RUNTIME_SVC_H__ */ 136