e37c74f0ab0817c8498c1cfcbe43ee42e5792987
1 /*
2 * Remote Processor Procedure Call Driver
3 *
4 * Copyright(c) 2012-2013 Texas Instruments. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name Texas Instruments nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
33 #ifndef _RPMSG_RPC_H_
34 #define _RPMSG_RPC_H_
36 #include <stdint.h>
37 #include <sys/types.h>
38 #include <ioctl.h>
39 #include <stddef.h>
41 #define __packed __attribute__ ((packed))
43 /**
44 * struct rppc_buf_fds - rppc buffer registration/deregistration
45 * @num: number of file descriptors
46 * @fds: pointer to the array holding the file descriptors
47 */
48 struct rppc_buf_fds {
49 uint32_t num;
50 int32_t *fds;
51 };
53 /*
54 * ioctl definitions
55 */
56 #define RPPC_IOC_MAGIC 'r'
57 #define RPPC_IOC_CREATE _IOW(RPPC_IOC_MAGIC, 1, struct rppc_create_instance)
58 #define RPPC_IOC_BUFREGISTER _IOW(RPPC_IOC_MAGIC, 2, struct rppc_buf_fds)
59 #define RPPC_IOC_BUFUNREGISTER _IOW(RPPC_IOC_MAGIC, 3, struct rppc_buf_fds)
60 #define RPPC_IOC_MAXNR (4)
62 #define RPPC_MAX_PARAMETERS (10)
63 #define RPPC_MAX_TRANSLATIONS (1024)
64 #define RPPC_MAX_INST_NAMELEN (48)
66 /**
67 * enum rppc_param_type - RPC function parameter type
68 * @RPPC_PARAM_TYPE_UNKNOWN: unrecognized parameter
69 * @RPPC_PARAM_TYPE_ATOMIC: an atomic data type, 1 byte to architecture limit
70 * sized bytes
71 * @RPPC_PARAM_TYPE_PTR: a pointer to shared memory. The fd field in the
72 * structures rppc_param and rppc_param_translation must
73 * contain the file descriptor of the associated dma_buf
74 * @RPPC_PARAM_TYPE_STRUCT: (unsupported) a structure type. Will be architecture
75 * width aligned in memory
76 *
77 * These enum values are used to identify the parameter type for every
78 * parameter argument of the remote function.
79 */
80 enum rppc_param_type {
81 RPPC_PARAM_TYPE_UNKNOWN = 0,
82 RPPC_PARAM_TYPE_ATOMIC,
83 RPPC_PARAM_TYPE_PTR,
84 RPPC_PARAM_TYPE_STRUCT,
85 };
87 /**
88 * struct rppc_param_translation - pointer translation helper structure
89 * @index: index of the parameter where the translation needs to be done in.
90 * used for computing the primary offset and mapping into kernel
91 * the page from the buffer referred to in the correspoding parameter
92 * @offset: offset from the primary base pointer to the pointer to translate.
93 * This is the secondary offset, and used either for mentioning the
94 * offset from an structure array element base, or within a single
95 * structure which itself is at an offset in an allocated buffer
96 * @base: the base user virtual address of the pointer to translate (used to
97 * calculate translated pointer offset)
98 * @fd: dma_buf file descriptor of the allocated buffer pointer within which
99 * the translated pointer is present
100 */
101 struct rppc_param_translation {
102 uint32_t index;
103 ptrdiff_t offset;
104 size_t base;
105 int32_t fd;
106 };
108 /**
109 * struct rppc_param - descriptor structure for each parameter
110 * @type: type of the parameter, as dictated by enum rppc_param_type
111 * @size: size of the data (for atomic types) or size of the containing
112 * structure in which translations are performed
113 * @data: either the parameter value itself (for atomic type) or
114 * the actual user space pointer address to the data (for pointer type)
115 * @base: the base user space pointer address of the original allocated buffer,
116 * providing a reference if data has the pointer that is at an offset
117 * from the original pointer
118 * @fd: file descriptor of the exported allocation (will be used to
119 * import the associated dma_buf within the driver).
120 */
121 struct rppc_param {
122 uint32_t type;
123 size_t size;
124 size_t data;
125 size_t base;
126 int32_t fd;
127 };
129 /**
130 * struct rppc_function - descriptor structure for the remote function
131 * @fxn_id: index of the function to invoke on the opened rppc device
132 * @num_params: number of parameters filled in the params field
133 * @params: array of parameter descriptor structures
134 * @num_translations: number of in-place translations to be performed within
135 * the arguments.
136 * @translations: an open array of the translation descriptor structures, whose
137 * length is given in @num_translations. Used for translating
138 * the pointers within the function data.
139 *
140 * This is the primary descriptor structure passed down from the userspace,
141 * describing the function, its parameter arguments and the needed translations.
142 */
143 struct rppc_function {
144 uint32_t fxn_id;
145 uint32_t num_params;
146 struct rppc_param params[RPPC_MAX_PARAMETERS];
147 uint32_t num_translations;
148 struct rppc_param_translation translations[0];
149 };
151 /**
152 * struct rppc_function_return - function return status descriptor structure
153 * @fxn_id: index of the function invoked on the opened rppc device
154 * @status: return value of the executed function
155 */
156 struct rppc_function_return {
157 uint32_t fxn_id;
158 uint32_t status;
159 };
161 /*
162 * helper macros for manipulating the function index in the marshalled packet
163 */
164 #define RPPC_DESC_EXEC_SYNC (0x0100)
165 #define RPPC_DESC_TYPE_MASK (0x0F00)
167 /*
168 * helper macros for manipulating the function index in the marshalled packet.
169 * The remote functions are offset by one relative to the client
170 * XXX: Remove the relative offset
171 */
172 #define RPPC_SET_FXN_IDX(idx) (((idx) + 1) | 0x80000000)
173 #define RPPC_FXN_MASK(idx) (((idx) - 1) & 0x7FFFFFFF)
175 /**
176 * struct rppc_packet - the actual marshalled packet
177 * @desc: type of function execution, currently only synchronous function
178 * invocations are supported
179 * @msg_id: an incremental message index identifier
180 * @flags: a combination of job id and pool id of the worker threads
181 * of the server
182 * @fxn_id: id of the function to execute
183 * @result: result of the remotely executed function
184 * @data_size: size of the payload packet
185 * @data: variable payload, containing the marshalled function data.
186 *
187 * This is actually a condensed structure of the Remote Command Messaging
188 * (RCM) structure. The initial fields of the structure are used by the
189 * remote-side server to schedule the execution of the function. The actual
190 * variable payload data starts from the .data field. This marshalled packet
191 * is the payload for a rpmsg message.
192 *
193 * XXX: remove or mask unneeded fields, some fields can be stripped down
194 */
195 struct rppc_packet {
196 uint16_t desc;
197 uint16_t msg_id;
198 uint32_t flags;
199 uint32_t fxn_id;
200 int32_t result;
201 uint32_t data_size;
202 uint8_t data[0];
203 } __packed;
206 //#ifdef __KERNEL__
208 #define RPPC_MAX_NUM_FUNCS (1024)
209 #define RPPC_MAX_CHANNEL_NAMELEN (64)
210 #define RPPC_MAX_FUNC_NAMELEN (64)
211 #define RPPC_MAX_NUM_PARAMS (10)
212 #define RPPC_MAX_INST_NAMELEN (48)
214 /* Added below definition for use with CREATE ioctl in QNX */
215 struct rppc_create_instance {
216 char name[RPPC_MAX_CHANNEL_NAMELEN];
217 };
219 /**
220 * enum rppc_param_direction - direction of the function parameter
221 * @RPPC_PARAMDIR_IN: input argument
222 * @RPPC_PARAMDIR_OUT: output argument
223 * @RPPC_PARAMDIR_BI: an in and out argument
224 * @RPPC_PARAMDIR_MAX: limit value for the direction type
225 *
226 * The parameter direction is described as relative to the function.
227 */
228 enum rppc_param_direction {
229 RPPC_PARAMDIR_IN = 0,
230 RPPC_PARAMDIR_OUT,
231 RPPC_PARAMDIR_BI,
232 RPPC_PARAMDIR_MAX
233 };
235 /**
236 * enum rppc_param_datatype - parameter data type and descriptor flags
237 * @RPPC_PARAM_VOID: parameter is of type 'void'
238 * @RPPC_PARAM_S08: parameter is of type 's8'
239 * @RPPC_PARAM_U08: parameter is of type 'u8'
240 * @RPPC_PARAM_S16: parameter is of type 's16'
241 * @RPPC_PARAM_U16: parameter is of type 'u16'
242 * @RPPC_PARAM_S32: parameter is of type 's32'
243 * @RPPC_PARAM_U32: parameter is of type 'u32'
244 * @RPPC_PARAM_S64: parameter is of type 's64'
245 * @RPPC_PARAM_U64: parameter is of type 'u64'
246 * @RPPC_PARAM_ATOMIC_MAX: limit value for scalar data types
247 * @RPPC_PARAM_MASK: mask field for retrieving the scalar data type
248 * @RPPC_PARAM_PTR: flag to indicate the data type is a pointer
249 * @RPPC_PARAM_MAX: max limit value used as a marker
250 *
251 * This enum is used to describe the data type for the parameters.
252 * A pointer of a data type is reflected by using an additional bit
253 * mask field.
254 */
255 enum rppc_param_datatype {
256 RPPC_PARAM_VOID = 0,
257 RPPC_PARAM_S08,
258 RPPC_PARAM_U08,
259 RPPC_PARAM_S16,
260 RPPC_PARAM_U16,
261 RPPC_PARAM_S32,
262 RPPC_PARAM_U32,
263 RPPC_PARAM_S64,
264 RPPC_PARAM_U64,
265 RPPC_PARAM_ATOMIC_MAX,
267 RPPC_PARAM_MASK = 0x7F,
268 RPPC_PARAM_PTR = 0x80,
270 RPPC_PARAM_MAX
271 };
273 /*
274 * helper macros to deal with parameter types
275 */
276 #define RPPC_PTR_TYPE(type) ((type) | RPPC_PARAM_PTR)
277 #define RPPC_IS_PTR(type) ((type) & RPPC_PARAM_PTR)
278 #define RPPC_IS_ATOMIC(type) (((type) > RPPC_PARAM_VOID) && \
279 ((type) < RPPC_PARAM_ATOMIC_MAX))
281 //#endif /* __KERNEL__ */
283 #endif /* _RPMSG_RPC_H_ */