runtime_svc.h 5 KB
Newer Older
1
/*
2
 * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * Neither the name of ARM nor the names of its contributors may be used
 * to endorse or promote products derived from this software without specific
 * prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef __RUNTIME_SVC_H__
#define __RUNTIME_SVC_H__

34
35
#include <bl_common.h>		/* to include exception types */
#include <smcc_helpers.h>	/* to include SMCC definitions */
36
37


38
/*******************************************************************************
39
 * Structure definition, typedefs & constants for the runtime service framework
40
41
 ******************************************************************************/

Achin Gupta's avatar
Achin Gupta committed
42
43
44
45
/*
 * Constants to allow the assembler access a runtime service
 * descriptor
 */
46
47
#define RT_SVC_SIZE_LOG2	5
#define SIZEOF_RT_SVC_DESC	(1 << RT_SVC_SIZE_LOG2)
Achin Gupta's avatar
Achin Gupta committed
48
49
50
51
52
53
54
55
56
57
#define RT_SVC_DESC_INIT	16
#define RT_SVC_DESC_HANDLE	24

/*
 * The function identifier has 6 bits for the owning entity number and
 * single bit for the type of smc call. When taken together these
 * values limit the maximum number of runtime services to 128.
 */
#define MAX_RT_SVCS		128

58
59
#ifndef __ASSEMBLY__

Achin Gupta's avatar
Achin Gupta committed
60
/* Prototype for runtime service initializing function */
61
typedef int32_t (*rt_svc_init_t)(void);
Achin Gupta's avatar
Achin Gupta committed
62
63
64
65
66
67
68

/*
 * Prototype for runtime service SMC handler function. x0 (SMC Function ID) to
 * x4 are as passed by the caller. Rest of the arguments to SMC and the context
 * can be accessed using the handle pointer. The cookie parameter is reserved
 * for future use
 */
69
typedef uint64_t (*rt_svc_handle_t)(uint32_t smc_fid,
Achin Gupta's avatar
Achin Gupta committed
70
71
72
73
74
75
76
				  uint64_t x1,
				  uint64_t x2,
				  uint64_t x3,
				  uint64_t x4,
				  void *cookie,
				  void *handle,
				  uint64_t flags);
77
typedef struct rt_svc_desc {
Achin Gupta's avatar
Achin Gupta committed
78
79
80
81
	uint8_t start_oen;
	uint8_t end_oen;
	uint8_t call_type;
	const char *name;
82
83
84
	rt_svc_init_t init;
	rt_svc_handle_t handle;
} rt_svc_desc_t;
Achin Gupta's avatar
Achin Gupta committed
85
86
87
88
89

/*
 * Convenience macro to declare a service descriptor
 */
#define DECLARE_RT_SVC(_name, _start, _end, _type, _setup, _smch) \
90
	static const rt_svc_desc_t __svc_desc_ ## _name \
Achin Gupta's avatar
Achin Gupta committed
91
		__attribute__ ((section("rt_svc_descs"), used)) = { \
92
93
94
95
96
97
			.start_oen = _start, \
			.end_oen = _end, \
			.call_type = _type, \
			.name = #_name, \
			.init = _setup, \
			.handle = _smch }
98

Achin Gupta's avatar
Achin Gupta committed
99
100
101
102
103
104
/*
 * Compile time assertions related to the 'rt_svc_desc' structure to:
 * 1. ensure that the assembler and the compiler view of the size
 *    of the structure are the same.
 * 2. ensure that the assembler and the compiler see the initialisation
 *    routine at the same offset.
105
 * 3. ensure that the assembler and the compiler see the handler
Achin Gupta's avatar
Achin Gupta committed
106
107
 *    routine at the same offset.
 */
108
CASSERT((sizeof(rt_svc_desc_t) == SIZEOF_RT_SVC_DESC), \
Achin Gupta's avatar
Achin Gupta committed
109
	assert_sizeof_rt_svc_desc_mismatch);
110
CASSERT(RT_SVC_DESC_INIT == __builtin_offsetof(rt_svc_desc_t, init), \
Achin Gupta's avatar
Achin Gupta committed
111
	assert_rt_svc_desc_init_offset_mismatch);
112
CASSERT(RT_SVC_DESC_HANDLE == __builtin_offsetof(rt_svc_desc_t, handle), \
Achin Gupta's avatar
Achin Gupta committed
113
114
115
116
117
118
119
120
121
122
123
124
	assert_rt_svc_desc_handle_offset_mismatch);


/*
 * This macro combines the call type and the owning entity number corresponding
 * to a runtime service to generate a unique owning entity number. This unique
 * oen is used to access an entry in the 'rt_svc_descs_indices' array. The entry
 * contains the index of the service descriptor in the 'rt_svc_descs' array.
 */
#define get_unique_oen(oen, call_type)	((oen & FUNCID_OEN_MASK) |	\
					((call_type & FUNCID_TYPE_MASK) \
					 << FUNCID_OEN_WIDTH))
125
126
127
128

/*******************************************************************************
 * Function & variable prototypes
 ******************************************************************************/
129
void runtime_svc_init(void);
Achin Gupta's avatar
Achin Gupta committed
130
131
extern uint64_t __RT_SVC_DESCS_START__;
extern uint64_t __RT_SVC_DESCS_END__;
132
133
void init_crash_reporting(void);

134
135
#endif /*__ASSEMBLY__*/
#endif /* __RUNTIME_SVC_H__ */