1
2
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
/*
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio.
This file is part of ChibiOS.
ChibiOS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
ChibiOS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file tsclient.h
* @brief TSSI client module macros and structures.
*
* @addtogroup TSSI
* @{
*/
#ifndef TSCLIENT_H
#define TSCLIENT_H
/*===========================================================================*/
/* Module constants. */
/*===========================================================================*/
/* Service registry errors as returned by smc.*/
#define SMC_SVC_OK MSG_OK /* No error.*/
#define SMC_SVC_INTR (msg_t)-1 /* Service interrupted.*/
#define SMC_SVC_NOENT (msg_t)-2 /* No existent service.*/
#define SMC_SVC_INVALID (msg_t)-3 /* Invalid service parameter(s).*/
#define SMC_SVC_BADH (msg_t)-4 /* Invalid service handle.*/
#define SMC_SVC_EXIST (msg_t)-5 /* Service already exists.*/
#define SMC_SVC_NHND (msg_t)-6 /* No more services.*/
#define SMC_SVC_BUSY (msg_t)-7 /* Service busy.*/
/* Special trusted service handles.*/
#define TS_HND_DISCOVERY ((ts_service_t *)1) /* Discovery service handle.*/
#define TS_HND_STQRY ((ts_service_t *)2) /* Query status service handle.*/
#define TS_HND_IDLE ((ts_service_t *)3) /* Idle service handle.*/
/*===========================================================================*/
/* Module pre-compile time settings. */
/*===========================================================================*/
#define TS_GRANTED_TIMESLICE 1000 /* Microseconds.*/
#define TS_CHECK_EVENT_HOOK(f) { \
(void)f; \
}
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/*===========================================================================*/
/* Module data structures and types. */
/*===========================================================================*/
typedef uint8_t * ts_params_area_t;
typedef void * ts_service_t;
/*===========================================================================*/
/* Module macros. */
/*===========================================================================*/
/*===========================================================================*/
/* Module inline functions. */
/*===========================================================================*/
/**
* @brief Call a service via smc instruction.
* @note see tsInvoke1()
*
* @notapi
*/
static inline int64_t tsInvoke0(ts_service_t handle, ts_params_area_t data,
size_t size, sysinterval_t yieldtime) {
register int64_t result asm("r0");
register int32_t r0 asm("r0") = (int32_t) handle;
register int32_t r1 asm("r1") = (int32_t) data;
register int32_t r2 asm("r2") = (int32_t) size;
register int32_t r3 asm("r3") = (int32_t) yieldtime;
__asm volatile ("smc #0" : "=r" (result) : "r" (r0), "r" (r1), "r" (r2),
"r" (r3) : "memory");
return result;
}
/**
* @brief Call a service via smc instruction.
* @details call a given service via smc and evaluate the eventflags mask
* returned by the secure world. The flags mask is checked by a
* macro, TS_CHECK_EVENT_HOOK, supplied by the user.
*
* @param[in] handle The handle of the service to invoke.
* The handle is obtained by an invoke to discovery
* service.
* @param[in,out] svc_data Service request data, often a reference to a more
* complex structure.
* @param[in] svc_datalen Size of the svc_data memory area.
* @param[in] yieldtime The time yield to SEC service to run, in microsec.
*
* @return A 64bit value. It is composed by the 32bit service
* status in the lo-word with the 32bit event mask in
* the hi-word.
* The retval values are returned in the lower word
* as 32bit int.
* @retval SMC_SVC_OK generic success value.
* @retval SMC_SVC_INTR call interrupted.
* @retval SMC_SVC_BUSY the service has a pending request.
* @retval SMC_SVC_INVALID bad parameters.
* @retval SMC_SVC_NOENT no such service.
* @retval SMC_SVC_BADH bad handle.
*
* @api
*/
static inline int64_t tsInvoke1(ts_service_t handle, ts_params_area_t data,
size_t size, sysinterval_t timeslice) {
int64_t result;
eventflags_t f;
result = tsInvoke0(handle, data, size, timeslice);
f = (eventflags_t)(result >> 32);
TS_CHECK_EVENT_HOOK(f);
return result;
}
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
#ifdef __cplusplus
extern "C" {
#endif
msg_t tsInvokeService(ts_service_t handle, ts_params_area_t data,
size_t size, sysinterval_t svc_nsec_time);
#ifdef __cplusplus
}
#endif
/*===========================================================================*/
/* Module inline functions. */
/*===========================================================================*/
#endif /* TSCLIENT_H */
/** @} */
|