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_IPC_GETCONFIG,
167 LAD_NAMESERVER_SETUP,
168 LAD_NAMESERVER_DESTROY,
169 LAD_NAMESERVER_PARAMS_INIT,
170 LAD_NAMESERVER_CREATE,
171 LAD_NAMESERVER_DELETE,
172 LAD_NAMESERVER_ADD,
173 LAD_NAMESERVER_GET,
174 LAD_NAMESERVER_ADDUINT32,
175 LAD_NAMESERVER_GETUINT32,
176 LAD_NAMESERVER_GETLOCAL,
177 LAD_NAMESERVER_GETLOCALUINT32,
178 LAD_NAMESERVER_REMOVE,
179 LAD_NAMESERVER_REMOVEENTRY,
180 LAD_NAMESERVER_ATTACH,
181 LAD_NAMESERVER_DETACH,
182 LAD_MESSAGEQ_GETCONFIG,
183 LAD_MESSAGEQ_SETUP,
184 LAD_MESSAGEQ_DESTROY,
185 LAD_MESSAGEQ_CREATE,
186 LAD_MESSAGEQ_ANNOUNCE,
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 Char name[LAD_MESSAGEQCREATEMAXNAMELEN];
275 Void *serverHandle;
276 } messageQAnnounce;
277 struct {
278 Void *serverHandle;
279 } messageQDelete;
280 struct {
281 GateMP_RemoteProtect type;
282 } gateMPGetNumResources;
283 struct {
284 GateMP_RemoteProtect type;
285 } gateMPGetFreeResource;
286 struct {
287 GateMP_RemoteProtect type;
288 Int32 id;
289 } gateMPReleaseResource;
290 struct {
291 Bool result;
292 } gateMPIsSetup;
293 } args;
294 };
296 union LAD_ResponseObj {
297 struct {
298 Int status;
299 UInt32 len;
300 UInt8 buf[LAD_MAXENTRYVALUELEN];
301 } get;
302 struct {
303 Int status;
304 UInt32 val;
305 } getUInt32;
306 struct {
307 Int status;
308 Int assignedId;
309 } connect;
310 struct {
311 Int status;
312 NameServer_Handle handle;
313 } nsdelete;
314 struct {
315 Int status;
316 NameServer_Handle nameServerHandle;
317 } setup;
318 struct {
319 Int status;
320 Int queueId;
321 Void *serverHandle;
322 } messageQCreate;
323 struct {
324 Int status;
325 } messageQAnnounce;
326 struct {
327 Int status;
328 } messageQDelete;
329 struct {
330 Int status;
331 MessageQ_MsgHeader msg;
332 } msgInit;
333 struct {
334 Int status;
335 MessageQ_Config cfg;
336 } messageQGetConfig;
337 struct {
338 Int status;
339 MultiProc_Config cfg;
340 } multiprocGetConfig;
341 struct {
342 Int status;
343 NameServer_Handle nameServerHandle;
344 } gateMPStart;
345 struct {
346 Int status;
347 Int32 value;
348 } gateMPGetNumResources;
349 struct {
350 Int status;
351 Int32 id;
352 } gateMPGetFreeResource;
353 struct {
354 Int status;
355 } gateMPReleaseResource;
356 struct {
357 Int status;
358 Bool result;
359 } gateMPIsSetup;
360 struct {
361 Int status;
362 GateHWSpinlock_Config cfgParams;
363 } gateHWSpinlockGetConfig;
364 Ipc_Config ipcConfig;
365 NameServer_Params params;
366 NameServer_Handle handle;
367 Ptr entryPtr;
368 Int status;
369 };
372 #ifdef __cplusplus
373 }
374 #endif
376 #endif