1 /*
2 * Copyright (c) 2012-2015 Texas Instruments Incorporated - http://www.ti.com
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 */
32 /*
33 * ======== _lad.h ========
34 */
36 #ifndef _lad_
37 #define _lad_
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
43 #include <ti/ipc/MessageQ.h>
44 #include <_MessageQ.h>
45 #include <ti/ipc/NameServer.h>
46 #include <ti/ipc/MultiProc.h>
47 #include <_MultiProc.h>
48 #include <stdio.h>
49 #include <ti/ipc/GateMP.h>
50 #include <_GateMP.h>
51 #include <_Ipc.h>
52 #include <GateHWSpinlock.h>
53 #include <sys/time.h>
54 #include <ti/ipc/namesrv/_NameServerRemoteRpmsg.h>
56 extern Bool logFile;
57 extern FILE *logPtr;
58 extern struct timeval start_tv;
60 /*
61 * Macros for writing to log file.
62 *
63 * For the timestamp prefix, subtract the start time (which is established
64 * when the logFile is opened) so that the massive "since the epoch" value
65 * is not displayed. For this, subtract only the timeval.tv_sec (seconds)
66 * value so we don't have to worry about the "borrow" that results when
67 * start_tv.tv_usec > tv.tv_usec.
68 */
69 #define LOG0(a) \
70 if (logFile == TRUE) { \
71 struct timeval tv; \
72 gettimeofday(&tv, NULL); \
73 fprintf(logPtr, "[%d.%06d] " a, \
74 (unsigned int)(tv.tv_sec - start_tv.tv_sec), \
75 (unsigned int)tv.tv_usec); \
76 fflush(logPtr); \
77 }
79 #define LOG1(a, b) \
80 if (logFile == TRUE) { \
81 struct timeval tv; \
82 gettimeofday(&tv, NULL); \
83 fprintf(logPtr, "[%d.%06d] " a, \
84 (unsigned int)(tv.tv_sec - start_tv.tv_sec), \
85 (unsigned int)tv.tv_usec, b); \
86 fflush(logPtr); \
87 }
89 #define LOG2(a, b, c) \
90 if (logFile == TRUE) { \
91 struct timeval tv; \
92 gettimeofday(&tv, NULL); \
93 fprintf(logPtr, "[%d.%06d] " a, \
94 (unsigned int)(tv.tv_sec - start_tv.tv_sec), \
95 (unsigned int)tv.tv_usec, b, c); \
96 fflush(logPtr); \
97 }
99 #define LOG3(a, b, c, d) \
100 if (logFile == TRUE) { \
101 struct timeval tv; \
102 gettimeofday(&tv, NULL); \
103 fprintf(logPtr, "[%d.%06d] " a, \
104 (unsigned int)(tv.tv_sec - start_tv.tv_sec), \
105 (unsigned int)tv.tv_usec, b, c, d); \
106 fflush(logPtr); \
107 }
109 #define LOG4(a, b, c, d, e) \
110 if (logFile == TRUE) { \
111 struct timeval tv; \
112 gettimeofday(&tv, NULL); \
113 fprintf(logPtr, "[%d.%06d] " a, \
114 (unsigned int)(tv.tv_sec - start_tv.tv_sec), \
115 (unsigned int)tv.tv_usec, b, c, d, e); \
116 fflush(logPtr); \
117 }
119 /* macros for generating verbose output: */
120 #define PRINTVERBOSE0(a) \
121 if (verbose == TRUE) { printf(a); }
123 #define PRINTVERBOSE1(a, b) \
124 if (verbose == TRUE) { printf(a, b); }
126 #define PRINTVERBOSE2(a, b, c) \
127 if (verbose == TRUE) { printf(a, b, c); }
129 #define PRINTVERBOSE3(a, b, c, d) \
130 if (verbose == TRUE) { printf(a, b, c, d); }
133 /* LAD commmand FIFO strings: */
134 #if defined (IPC_BUILDOS_ANDROID)
135 #define LAD_COMMANDFIFO "/data/lad/LAD/LADCMDS"
136 #define LAD_ROOTDIR "/data/lad/"
137 #define LAD_WORKINGDIR "/data/lad/LAD/"
138 #else
139 #define LAD_COMMANDFIFO "/tmp/LAD/LADCMDS"
140 #define LAD_ROOTDIR "/tmp/"
141 #define LAD_WORKINGDIR "/tmp/LAD/"
142 #endif
144 #define LAD_RESPONSEFIFOPATH LAD_WORKINGDIR
145 #define LAD_PROTOCOLVERSION "03000000" /* MMSSRRRR */
147 #define LAD_MAXNUMCLIENTS 32 /* max simultaneous clients */
148 #define LAD_CONNECTTIMEOUT 5.0 /* LAD connect response timeout (sec) */
149 #define LAD_DISCONNECTTIMEOUT 5.0 /* LAD disconnect timeout (sec) */
150 #define LAD_MAXLENGTHFIFONAME 128 /* max length client FIFO name */
151 #define LAD_MAXLENGTHCOMMAND 512 /* size limit for LAD command string */
152 #define LAD_MAXLENGTHRESPONSE 512 /* size limit for LAD response string */
153 #define LAD_MAXLENGTHPROTOVERS 16 /* size limit for protocol version */
154 #define LAD_MAXLOGFILEPATH 256 /* size limit for LAD log file path */
155 #define LAD_COMMANDLENGTH sizeof(struct LAD_CommandObj)
156 #define LAD_RESPONSELENGTH sizeof(union LAD_ResponseObj)
158 #define LAD_MESSAGEQCREATEMAXNAMELEN 32
160 #define LAD_MAXENTRYNAMELEN MAXNAMEINCHAR /* max for LAD NameServer name */
161 #define LAD_MAXENTRYVALUELEN 32 /* size limit for LAD NameServer value */
163 typedef enum {
164 LAD_CONNECT = 0,
165 LAD_DISCONNECT,
166 LAD_RPROC_SETID,
167 LAD_IPC_GETCONFIG,
168 LAD_NAMESERVER_SETUP,
169 LAD_NAMESERVER_DESTROY,
170 LAD_NAMESERVER_PARAMS_INIT,
171 LAD_NAMESERVER_CREATE,
172 LAD_NAMESERVER_DELETE,
173 LAD_NAMESERVER_ADD,
174 LAD_NAMESERVER_GET,
175 LAD_NAMESERVER_ADDUINT32,
176 LAD_NAMESERVER_GETUINT32,
177 LAD_NAMESERVER_GETLOCAL,
178 LAD_NAMESERVER_GETLOCALUINT32,
179 LAD_NAMESERVER_REMOVE,
180 LAD_NAMESERVER_REMOVEENTRY,
181 LAD_NAMESERVER_ATTACH,
182 LAD_NAMESERVER_DETACH,
183 LAD_MESSAGEQ_GETCONFIG,
184 LAD_MESSAGEQ_SETUP,
185 LAD_MESSAGEQ_DESTROY,
186 LAD_MESSAGEQ_CREATE,
187 LAD_MESSAGEQ_DELETE,
188 LAD_MESSAGEQ_MSGINIT,
189 LAD_MULTIPROC_GETCONFIG,
190 LAD_GATEMP_ATTACH,
191 LAD_GATEMP_DETACH,
192 LAD_GATEMP_START,
193 LAD_GATEMP_GETNUMRESOURCES,
194 LAD_GATEMP_GETFREERESOURCE,
195 LAD_GATEMP_RELEASERESOURCE,
196 LAD_GATEMP_ISSETUP,
197 LAD_GATEHWSPINLOCK_GETCONFIG,
198 LAD_EXIT
199 } _LAD_Command;
201 struct LAD_CommandObj {
202 Int cmd;
203 Int clientId;
204 union {
205 struct {
206 Int pid;
207 Char name[LAD_MAXLENGTHFIFONAME];
208 Char protocol[LAD_MAXLENGTHPROTOVERS];
209 } connect;
210 struct {
211 Int procId;
212 Int rprocId;
213 } rprocSetId;
214 struct {
215 Char name[LAD_MAXENTRYNAMELEN];
216 NameServer_Params params;
217 } create;
218 struct {
219 NameServer_Handle handle;
220 } nsdelete;
221 struct {
222 NameServer_Handle handle;
223 Char name[LAD_MAXENTRYNAMELEN];
224 UInt8 buf[LAD_MAXENTRYVALUELEN];
225 UInt32 len;
226 } add;
227 struct {
228 NameServer_Handle handle;
229 Char name[LAD_MAXENTRYNAMELEN];
230 UInt32 len;
231 UInt16 procId[MultiProc_MAXPROCESSORS];
232 } get;
233 struct {
234 NameServer_Handle handle;
235 Char name[LAD_MAXENTRYNAMELEN];
236 UInt32 val;
237 } addUInt32;
238 struct {
239 NameServer_Handle handle;
240 Char name[LAD_MAXENTRYNAMELEN];
241 UInt16 procId[MultiProc_MAXPROCESSORS];
242 } getUInt32;
243 struct {
244 NameServer_Handle handle;
245 Char name[LAD_MAXENTRYNAMELEN];
246 UInt32 len;
247 } getLocal;
248 struct {
249 NameServer_Handle handle;
250 Char name[LAD_MAXENTRYNAMELEN];
251 } getLocalUInt32;
252 struct {
253 NameServer_Handle handle;
254 Char name[LAD_MAXENTRYNAMELEN];
255 } remove;
256 struct {
257 NameServer_Handle handle;
258 Ptr entryPtr;
259 } removeEntry;
260 struct {
261 UInt16 procId;
262 } attach;
263 struct {
264 UInt16 procId;
265 } detach;
266 struct {
267 MessageQ_Config cfg;
268 } messageQSetup;
269 struct {
270 Char name[LAD_MESSAGEQCREATEMAXNAMELEN];
271 MessageQ_Params params;
272 } messageQCreate;
273 struct {
274 Void *serverHandle;
275 } messageQDelete;
276 struct {
277 GateMP_RemoteProtect type;
278 } gateMPGetNumResources;
279 struct {
280 GateMP_RemoteProtect type;
281 } gateMPGetFreeResource;
282 struct {
283 GateMP_RemoteProtect type;
284 Int32 id;
285 } gateMPReleaseResource;
286 struct {
287 Bool result;
288 } gateMPIsSetup;
289 } args;
290 };
292 union LAD_ResponseObj {
293 struct {
294 Int status;
295 UInt32 len;
296 UInt8 buf[LAD_MAXENTRYVALUELEN];
297 } get;
298 struct {
299 Int status;
300 UInt32 val;
301 } getUInt32;
302 struct {
303 Int status;
304 Int assignedId;
305 } connect;
306 struct {
307 Int status;
308 NameServer_Handle handle;
309 } nsdelete;
310 struct {
311 Int status;
312 NameServer_Handle nameServerHandle;
313 } setup;
314 struct {
315 Int status;
316 Int queueId;
317 Void *serverHandle;
318 } messageQCreate;
319 struct {
320 Int status;
321 } messageQDelete;
322 struct {
323 Int status;
324 MessageQ_MsgHeader msg;
325 } msgInit;
326 struct {
327 Int status;
328 MessageQ_Config cfg;
329 } messageQGetConfig;
330 struct {
331 Int status;
332 MultiProc_Config cfg;
333 } multiprocGetConfig;
334 struct {
335 Int status;
336 NameServer_Handle nameServerHandle;
337 } gateMPStart;
338 struct {
339 Int status;
340 Int32 value;
341 } gateMPGetNumResources;
342 struct {
343 Int status;
344 Int32 id;
345 } gateMPGetFreeResource;
346 struct {
347 Int status;
348 } gateMPReleaseResource;
349 struct {
350 Int status;
351 Bool result;
352 } gateMPIsSetup;
353 struct {
354 Int status;
355 GateHWSpinlock_Config cfgParams;
356 } gateHWSpinlockGetConfig;
357 Ipc_Config ipcConfig;
358 NameServer_Params params;
359 NameServer_Handle handle;
360 Ptr entryPtr;
361 Int status;
362 };
365 #ifdef __cplusplus
366 }
367 #endif
369 #endif