aboutsummaryrefslogtreecommitdiff
path: root/platform/ext/target/arm/musca_b1/sse_200/services/include/tfm_ioctl_api.h
blob: b391bf6eedc262d84449e14f1dd924603d20dfee (plain)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*
 * Copyright (c) 2019, Arm Limited. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *
 */

#ifndef __TFM_IOCTL_API__
#define __TFM_IOCTL_API__

#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include "tfm_api.h"
#include "tfm_platform_api.h"

#ifdef __cplusplus
extern "C" {
#endif

enum tfm_platform_ioctl_reqest_types_t {
    TFM_PLATFORM_IOCTL_PIN_SERVICE,
    TFM_PLATFORM_IOCTL_GPIO_SERVICE,
};

/*!
 * \enum tfm_gpio_service_type_t
 *
 * \brief GPIO service types (supported types may vary based on the platform)
 */
enum tfm_gpio_service_type_t {
    TFM_GPIO_SERVICE_TYPE_INIT = 0,          /*!< Init */
    TFM_GPIO_SERVICE_TYPE_PIN_CONFIG,        /*!< Pin config */
    TFM_GPIO_SERVICE_TYPE_PIN_WRITE,         /*!< Pin write */
    TFM_GPIO_SERVICE_TYPE_PIN_READ,          /*!< Pin read */
    TFM_GPIO_SERVICE_TYPE_PORT_CONFIG,       /*!< Port config */
    TFM_GPIO_SERVICE_TYPE_PORT_WRITE,        /*!< Port write */
    TFM_GPIO_SERVICE_TYPE_PORT_READ,         /*!< Port read */
    TFM_GPIO_SERVICE_TYPE_MAX = INT_MAX      /*!< Max to force enum max size */
};

/*!
 * \struct tfm_gpio_service_args_t
 *
 * \brief Argument list for each platform GPIO service
 */
struct tfm_gpio_service_args_t {
    enum tfm_gpio_service_type_t type;
    union {
        struct gpio_config_args { /*!< TFM_GPIO_SERVICE_TYPE_PIN_CONFIG ||
                                       TFM_GPIO_SERVICE_TYPE_PORT_CONFIG  */
            uint32_t pin_num_or_mask;
            uint32_t direction;
        } gpio_config;
        struct gpio_write_args { /*!< TFM_GPIO_SERVICE_TYPE_PIN_WRITE ||
                                      TFM_GPIO_SERVICE_TYPE_PORT_WRITE */
            uint32_t pin_num_or_mask;
            uint32_t value;
        } gpio_write;
        struct gpio_read_args { /*!< TFM_GPIO_SERVICE_TYPE_PIN_READ ||
                                     TFM_GPIO_SERVICE_TYPE_PORT_READ */
            uint32_t pin_num_or_mask;
        } gpio_read;
    } u;
};

/*!
 * \struct tfm_gpio_service_out_t
 *
 * \brief Output list for each GPIO platform service
 */
struct tfm_gpio_service_out_t {
    union {
        uint32_t result;               /*!< Generic result */
        struct gpio_read_result { /*!< TFM_GPIO_SERVICE_TYPE_PIN_READ ||
                                       TFM_GPIO_SERVICE_TYPE_PORT_READ */
            uint32_t result;
            uint32_t data;
        } gpio_read_result;
    } u;
};

/*!
 * \enum tfm_pin_service_type_t
 *
 * \brief Pin service types
 */
enum tfm_pin_service_type_t {
    TFM_PIN_SERVICE_TYPE_SET_ALTFUNC     = 0,   /*!< Set alternate function type */
    TFM_PIN_SERVICE_TYPE_SET_DEFAULT_IN,        /*!< Set default in function type */
    TFM_PIN_SERVICE_TYPE_SET_PIN_MODE,          /*!< Set pin mode function type */
    TFM_PIN_SERVICE_TYPE_MAX = INT_MAX          /*!< Max to force enum max size */
};

/*!
 * \struct tfm_pin_service_args_t
 *
 * \brief Argument list for each platform pin service
 */
struct tfm_pin_service_args_t {
    enum tfm_pin_service_type_t type;
    union {
        struct set_altfunc { /*!< TFM_PIN_SERVICE_TYPE_SET_ALTFUNC */
            uint32_t alt_func;
            uint64_t pin_mask;
        } set_altfunc;
        struct set_default_in { /*!< TFM_PIN_SERVICE_TYPE_SET_DEFAULT_IN */
            uint32_t alt_func;
            uint32_t pin_value;
            bool default_in_value;
        } set_default_in;
        struct set_pin_mode { /*!< TFM_PIN_SERVICE_TYPE_SET_PIN_MODE */
            uint64_t pin_mask;
            uint32_t pin_mode;
        } set_pin_mode;
    } u;
};

/*!
 * \brief Sets pin alternate function for the given pins
 *
 * \param[in]  alt_func     Alternate function to set (allowed values vary
 *                          based on the platform)
 * \param[in]  pin_mask     Pin mask of the selected pins
 * \param[out] result       Return error value
 *
 * \return Returns values as specified by the \ref tfm_platform_err_t
 */
enum tfm_platform_err_t
tfm_platform_set_pin_alt_func(uint32_t alt_func, uint64_t pin_mask,
                              uint32_t *result);

/*!
 * \brief Sets default in value to use when the alternate function is not
 *        selected for the pin
 *
 * \param[in]  alt_func          Alternate function to use (allowed values vary
 *                               based on the platform)
 * \param[in]  pin_value         Pin value to use
 * \param[in]  default_in_value  Default in value to set
 * \param[out] result            Return error value
 *
 * \return Returns values as specified by the \ref tfm_platform_err_t
 */
enum tfm_platform_err_t
tfm_platform_set_pin_default_in(uint32_t alt_func, uint32_t pin_value,
                                bool default_in_value, uint32_t *result);

/*!
 * \brief Sets pin mode for the selected pins
 *
 * \param[in]  pin_mask     Pin mask of the selected pins
 * \param[in]  pin_mode     Pin mode to set for the selected pins
 * \param[out] result       Return error value
 *
 * \return Returns values as specified by the \ref tfm_platform_err_t
 */
enum tfm_platform_err_t
tfm_platform_set_pin_mode(uint64_t pin_mask, uint32_t pin_mode,
                          uint32_t *result);

/*!
 * \brief Initializes GPIO module
 *
 * \param[out] result       Return error value
 *
 * \return Returns values as specified by the \ref tfm_platform_err_t
 */
enum tfm_platform_err_t tfm_platform_gpio_init(uint32_t *result);

/*!
 * \brief Configures a GPIO pin as input or output
 *
 * \param[in]  pin_num       Pin number of the selected pin
 * \param[in]  direction     Direction of the pin: 0 for input, 1 for output
 * \param[out] result        Return error value
 *
 * \return Returns values as specified by the \ref tfm_platform_err_t
 */
enum tfm_platform_err_t
tfm_platform_gpio_pin_config(uint32_t pin_num, uint32_t direction,
                             uint32_t *result);

/*!
 * \brief Sets state of a selected GPIO pin
 *
 * \param[in]  pin_num  Pin number of the selected pin
 * \param[in]  value    Value to set for the pin
 * \param[out] result   Return error value
 *
 * \return Returns values as specified by the \ref tfm_platform_err_t
 */
enum tfm_platform_err_t
tfm_platform_gpio_pin_write(uint32_t pin_num, uint32_t value, uint32_t *result);

/*!
 * \brief Reads state of a selected GPIO pin
 *
 * \param[in]     pin_num  Pin number of the selected pin
 * \param[in,out] data     Bit value read from the IO pin
 * \param[out]    result   Return error value
 *
 * \return Returns values as specified by the \ref tfm_platform_err_t
 */
enum tfm_platform_err_t
tfm_platform_gpio_pin_read(uint32_t pin_num, uint32_t *data, uint32_t *result);

/*!
 * \brief Configures GPIO pins as input or output
 *
 * \param[in]  pin_mask      Pin mask of the selected pins
 * \param[in]  direction     Direction of the pin: 0 for input, 1 for output
 * \param[out] result        Return error value
 *
 * \return Returns values as specified by the \ref tfm_platform_err_t
 */
enum tfm_platform_err_t
tfm_platform_gpio_port_config(uint32_t pin_mask, uint32_t direction,
                              uint32_t *result);

/*!
 * \brief Sets state of a selected GPIO pins
 *
 * \param[in]  pin_mask  Pin mask of the selected pins
 * \param[in]  value     Value mask to set for the pins
 * \param[out] result    Return error value
 *
 * \return Returns values as specified by the \ref tfm_platform_err_t
 */
enum tfm_platform_err_t
tfm_platform_gpio_port_write(uint32_t pin_mask, uint32_t value,
                             uint32_t *result);

/*!
 * \brief Reads state of a selected GPIO pins
 *
 * \param[in]     pin_mask Pin mask of the selected pins
 * \param[in,out] data     Bit value mask read from the IO pins
 * \param[out]    result   Return error value
 *
 * \return Returns values as specified by the \ref tfm_platform_err_t
 */
enum tfm_platform_err_t
tfm_platform_gpio_port_read(uint32_t pin_mask, uint32_t *data,
                            uint32_t *result);

#ifdef __cplusplus
}
#endif

#endif /* __TFM_IOCTL_API__ */