blob: 03f906ef57656aa741f3bfb2ea18cf74927b75e7 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Yatharth Kochar6c0566c2015-10-02 17:56:48 +01002 * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
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 Gupta4f6ad662013-10-25 09:08:21 +010033
Yatharth Kochar6c0566c2015-10-02 17:56:48 +010034#include <bl_common.h> /* to include exception types */
35#include <smcc_helpers.h> /* to include SMCC definitions */
Achin Gupta4f6ad662013-10-25 09:08:21 +010036
Achin Gupta4f6ad662013-10-25 09:08:21 +010037
Achin Gupta4a826dd2013-11-25 14:00:56 +000038/*******************************************************************************
Jeenu Viswambharancaa84932014-02-06 10:36:15 +000039 * Structure definition, typedefs & constants for the runtime service framework
Achin Gupta4a826dd2013-11-25 14:00:56 +000040 ******************************************************************************/
Achin Gupta4a826dd2013-11-25 14:00:56 +000041
Achin Gupta7421b462014-02-01 18:53:26 +000042/*
43 * Constants to allow the assembler access a runtime service
44 * descriptor
45 */
Achin Gupta07f4e072014-02-02 12:02:23 +000046#define RT_SVC_SIZE_LOG2 5
47#define SIZEOF_RT_SVC_DESC (1 << RT_SVC_SIZE_LOG2)
Achin Gupta7421b462014-02-01 18:53:26 +000048#define RT_SVC_DESC_INIT 16
49#define RT_SVC_DESC_HANDLE 24
50
51/*
52 * The function identifier has 6 bits for the owning entity number and
53 * single bit for the type of smc call. When taken together these
54 * values limit the maximum number of runtime services to 128.
55 */
56#define MAX_RT_SVCS 128
57
Achin Gupta4f6ad662013-10-25 09:08:21 +010058#ifndef __ASSEMBLY__
59
Achin Gupta7421b462014-02-01 18:53:26 +000060/* Prototype for runtime service initializing function */
Dan Handleye2712bc2014-04-10 15:37:22 +010061typedef int32_t (*rt_svc_init_t)(void);
Achin Gupta7421b462014-02-01 18:53:26 +000062
Achin Gupta7421b462014-02-01 18:53:26 +000063/*
64 * Prototype for runtime service SMC handler function. x0 (SMC Function ID) to
65 * x4 are as passed by the caller. Rest of the arguments to SMC and the context
66 * can be accessed using the handle pointer. The cookie parameter is reserved
67 * for future use
68 */
Dan Handleye2712bc2014-04-10 15:37:22 +010069typedef uint64_t (*rt_svc_handle_t)(uint32_t smc_fid,
Achin Gupta7421b462014-02-01 18:53:26 +000070 uint64_t x1,
71 uint64_t x2,
72 uint64_t x3,
73 uint64_t x4,
74 void *cookie,
75 void *handle,
76 uint64_t flags);
Dan Handleye2712bc2014-04-10 15:37:22 +010077typedef struct rt_svc_desc {
Achin Gupta7421b462014-02-01 18:53:26 +000078 uint8_t start_oen;
79 uint8_t end_oen;
80 uint8_t call_type;
81 const char *name;
Dan Handleye2712bc2014-04-10 15:37:22 +010082 rt_svc_init_t init;
83 rt_svc_handle_t handle;
84} rt_svc_desc_t;
Achin Gupta7421b462014-02-01 18:53:26 +000085
86/*
87 * Convenience macro to declare a service descriptor
88 */
89#define DECLARE_RT_SVC(_name, _start, _end, _type, _setup, _smch) \
Dan Handleye2712bc2014-04-10 15:37:22 +010090 static const rt_svc_desc_t __svc_desc_ ## _name \
Soren Brinkmann46dd1702016-01-14 10:11:05 -080091 __section("rt_svc_descs") __used = { \
Soby Mathew7162afa2016-01-12 10:28:42 +000092 .start_oen = _start, \
93 .end_oen = _end, \
94 .call_type = _type, \
95 .name = #_name, \
96 .init = _setup, \
97 .handle = _smch }
Achin Gupta4f6ad662013-10-25 09:08:21 +010098
Achin Gupta7421b462014-02-01 18:53:26 +000099/*
100 * Compile time assertions related to the 'rt_svc_desc' structure to:
101 * 1. ensure that the assembler and the compiler view of the size
102 * of the structure are the same.
103 * 2. ensure that the assembler and the compiler see the initialisation
104 * routine at the same offset.
Achin Gupta07f4e072014-02-02 12:02:23 +0000105 * 3. ensure that the assembler and the compiler see the handler
Achin Gupta7421b462014-02-01 18:53:26 +0000106 * routine at the same offset.
107 */
Dan Handleye2712bc2014-04-10 15:37:22 +0100108CASSERT((sizeof(rt_svc_desc_t) == SIZEOF_RT_SVC_DESC), \
Achin Gupta7421b462014-02-01 18:53:26 +0000109 assert_sizeof_rt_svc_desc_mismatch);
Dan Handleye2712bc2014-04-10 15:37:22 +0100110CASSERT(RT_SVC_DESC_INIT == __builtin_offsetof(rt_svc_desc_t, init), \
Achin Gupta7421b462014-02-01 18:53:26 +0000111 assert_rt_svc_desc_init_offset_mismatch);
Dan Handleye2712bc2014-04-10 15:37:22 +0100112CASSERT(RT_SVC_DESC_HANDLE == __builtin_offsetof(rt_svc_desc_t, handle), \
Achin Gupta7421b462014-02-01 18:53:26 +0000113 assert_rt_svc_desc_handle_offset_mismatch);
114
115
116/*
117 * This macro combines the call type and the owning entity number corresponding
118 * to a runtime service to generate a unique owning entity number. This unique
119 * oen is used to access an entry in the 'rt_svc_descs_indices' array. The entry
120 * contains the index of the service descriptor in the 'rt_svc_descs' array.
121 */
122#define get_unique_oen(oen, call_type) ((oen & FUNCID_OEN_MASK) | \
123 ((call_type & FUNCID_TYPE_MASK) \
124 << FUNCID_OEN_WIDTH))
Achin Gupta4f6ad662013-10-25 09:08:21 +0100125
126/*******************************************************************************
127 * Function & variable prototypes
128 ******************************************************************************/
Juan Castillo2d552402014-06-13 17:05:10 +0100129void runtime_svc_init(void);
Achin Gupta7421b462014-02-01 18:53:26 +0000130extern uint64_t __RT_SVC_DESCS_START__;
131extern uint64_t __RT_SVC_DESCS_END__;
Andrew Thoelke8c28fe02014-06-02 11:40:35 +0100132void init_crash_reporting(void);
Andrew Thoelke8c28fe02014-06-02 11:40:35 +0100133
Achin Gupta4f6ad662013-10-25 09:08:21 +0100134#endif /*__ASSEMBLY__*/
Achin Gupta4f6ad662013-10-25 09:08:21 +0100135#endif /* __RUNTIME_SVC_H__ */