1 /*
2 * Copyright (c) 2012-2013, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its 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 "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
33 /**
34 * @file ti/ipc/mm/MmRpc.h
35 *
36 * @brief Multi-Media derived Remote Procedure Call
37 *
38 * @note MmRpc is currently only available for Linux and QNX.
39 *
40 *
41 */
43 #ifndef ti_ipc_mm_MmRpc__include
44 #define ti_ipc_mm_MmRpc__include
46 /* add includes here */
47 #include <stddef.h>
48 #include <stdint.h>
50 #if defined(__cplusplus)
51 extern "C" {
52 #endif
54 /*!
55 * @brief Operation is successful
56 */
57 #define MmRpc_S_SUCCESS (0)
59 /*!
60 * @brief Operation failed
61 */
62 #define MmRpc_E_FAIL (-1)
64 /*!
65 * @brief Invalid parameter type
66 */
67 #define MmRpc_E_INVALIDPARAM (-2)
69 /*!
70 * @brief Size of parameter array in function context structure
71 */
72 #define MmRpc_MAX_PARAMS (10)
74 /*!
75 * @brief Maximum size of translation array in function context structure
76 */
77 #define MmRpc_MAX_TRANSLATIONS (1024)
79 /*!
80 * @brief Macro for computing offset to a field of a structure.
81 *
82 * @code
83 * struct foobar {
84 * int a;
85 * int *p;
86 * };
87 *
88 * struct foobar *sp = ...;
89 * offset = MmRpc_OFFSET(sp, &sp->p);
90 * struct foobar st = ...;
91 * offset = MmRpc_OFFSET(&st, &st.p);
92 * @endcode
93 */
94 #define MmRpc_OFFSET(base, field) ((unsigned int)(field)-(unsigned int)(base))
96 /*!
97 * @brief MmRpc_Handle type
98 */
99 typedef struct MmRpc_Object *MmRpc_Handle;
101 /*!
102 * @brief MmRpc_ParamType enum
103 */
104 typedef enum {
105 MmRpc_ParamType_Scalar = 1, /*!< pass by value */
106 MmRpc_ParamType_Ptr, /*!< data pointer */
107 MmRpc_ParamType_OffPtr, /*!< buffer at offset in memory block */
108 MmRpc_ParamType_Elem /*!< array element */
109 } MmRpc_ParamType;
111 /*!
112 * @brief MmRpc_Param type
113 */
114 typedef struct {
115 MmRpc_ParamType type; /*!< parameter type */
117 union {
118 struct {
119 size_t size; /*!< size of the data */
120 size_t data; /*!< data (pass by value)*/
121 } scalar;
123 struct {
124 size_t size; /*!< size of the data referenced */
125 size_t addr; /*!< pointer value */
126 size_t handle; /*!< memory allocator handle */
127 } ptr;
129 struct {
130 size_t size; /*!< size (bytes) of param structure */
131 size_t base; /*!< param address */
132 size_t offset; /*!< offset within param */
133 size_t handle; /*!< memory allocator handle */
134 } offPtr;
136 } param;
137 } MmRpc_Param;
139 typedef struct {
140 uint32_t index; /*!< parameter index to base pointer */
141 ptrdiff_t offset; /*!< offset to embedded pointer
142 *
143 * If param type is MmRpc_ParamType_Ptr, offset
144 * to embedded pointer from addr. If param type
145 * is MmRpc_ParamType_OffPtr, offset to embedded
146 * pointer from base+offset.
147 */
148 size_t base; /*!< addr or file descriptor [+ data offset]
149 *
150 * If param type is MmRpc_ParamType_Ptr, the
151 * value of the embedded pointer. If param type
152 * is MmRpc_ParamType_OffPtr, the file descriptor
153 * of the block referenced by the embedded pointer
154 * plus an optional data offset.
155 */
156 size_t handle; /*!< memory allocator handle */
157 } MmRpc_Xlt;
159 /*!
160 * @brief Function call context structure
161 */
162 typedef struct {
163 uint32_t fxn_id; /*!< function id to call */
164 uint32_t num_params; /*!< number of parameters in params array */
165 MmRpc_Param params[MmRpc_MAX_PARAMS];
166 /*!< the array of parameters */
167 uint32_t num_xlts; /*!< number of translations in xltAry */
168 MmRpc_Xlt * xltAry; /*!< array of translations */
169 } MmRpc_FxnCtx;
171 /*!
172 * @brief Instance create parameters
173 */
174 typedef struct {
175 int reserved;
176 } MmRpc_Params;
178 /*!
179 * @brief Invoke a remote procedure call
180 *
181 */
182 int MmRpc_call(MmRpc_Handle handle, MmRpc_FxnCtx *ctx, int32_t *ret);
184 /*!
185 * @brief Create an MmRpc instance
186 *
187 */
188 int MmRpc_create(const char *service, const MmRpc_Params *params,
189 MmRpc_Handle *handlPtr);
191 /*!
192 * @brief Delete an MmRpc instance
193 *
194 */
195 int MmRpc_delete(MmRpc_Handle *handlePtr);
197 /*!
198 * @brief Initialize the instance create parameter structure
199 *
200 */
201 void MmRpc_Params_init(MmRpc_Params *params);
205 #if defined(__cplusplus)
206 }
207 #endif
208 #endif /* ti_ipc_mm_MmRpc__include */