summaryrefslogtreecommitdiff
path: root/arch/arm/plat-omap/include/syslink/messageq.h
blob: 1bfdecd7444467fdd08fc72962492e60e3a7ef50 (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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
/*
 *  messageq.h
 *
 *  The MessageQ module supports the structured sending and receiving of
 *  variable length messages. This module can be used for homogeneous or
 *  heterogeneous multi-processor messaging.
 *
 *  Copyright (C) 2009 Texas Instruments, Inc.
 *
 *  This package is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 *  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 *  WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 *  PURPOSE.
 */

#ifndef _MESSAGEQ_H_
#define _MESSAGEQ_H_

/* Standard headers */
#include <linux/types.h>

/* Utilities headers */
#include <linux/list.h>

/* Syslink headers */
#include <listmp.h>

/*!
 *  @def	MESSAGEQ_MODULEID
 *  @brief	Unique module ID.
 */
#define MESSAGEQ_MODULEID			(0xded2)


/* =============================================================================
 *  All success and failure codes for the module
 * =============================================================================
 */

/*!
 *  @def    MESSAGEQ_S_BUSY
 *  @brief  The resource is still in use
 */
#define MESSAGEQ_S_BUSY				2

/*!
 *  @def    MESSAGEQ_S_ALREADYSETUP
 *  @brief  The module has been already setup
 */
#define MESSAGEQ_S_ALREADYSETUP			1

/*!
 *  @def    MESSAGEQ_S_SUCCESS
 *  @brief  Operation is successful.
 */
#define MESSAGEQ_S_SUCCESS			0

/*!
 *  @def    MESSAGEQ_E_FAIL
 *  @brief  Operation is not successful.
 */
#define MESSAGEQ_E_FAIL				-1

/*!
 *  @def    MESSAGEQ_E_INVALIDARG
 *  @brief  There is an invalid argument.
 */
#define MESSAGEQ_E_INVALIDARG			-2

/*!
 *  @def    MESSAGEQ_E_MEMORY
 *  @brief  Operation resulted in memory failure.
 */
#define MESSAGEQ_E_MEMORY			-3

/*!
 *  @def    MESSAGEQ_E_ALREADYEXISTS
 *  @brief  The specified entity already exists.
 */
#define MESSAGEQ_E_ALREADYEXISTS		-4

/*!
 *  @def    MESSAGEQ_E_NOTFOUND
 *  @brief  Unable to find the specified entity.
 */
#define MESSAGEQ_E_NOTFOUND			-5

/*!
 *  @def    MESSAGEQ_E_TIMEOUT
 *  @brief  Operation timed out.
 */
#define MESSAGEQ_E_TIMEOUT			-6

/*!
 *  @def    MESSAGEQ_E_INVALIDSTATE
 *  @brief  Module is not initialized.
 */
#define MESSAGEQ_E_INVALIDSTATE			-7

/*!
 *  @def    MESSAGEQ_E_OSFAILURE
 *  @brief  A failure occurred in an OS-specific call
 */
#define MESSAGEQ_E_OSFAILURE			-8

/*!
 *  @def    MESSAGEQ_E_RESOURCE
 *  @brief  Specified resource is not available
 */
#define MESSAGEQ_E_RESOURCE			-9

/*!
 *  @def    MESSAGEQ_E_RESTART
 *  @brief  Operation was interrupted. Please restart the operation
 */
#define MESSAGEQ_E_RESTART			-10

/*!
 *  @def    MESSAGEQ_E_INVALIDMSG
 *  @brief  Operation is successful.
 */
#define MESSAGEQ_E_INVALIDMSG			-11

/*!
 *  @def    MESSAGEQ_E_NOTOWNER
 *  @brief  Not the owner
 */
#define MESSAGEQ_E_NOTOWNER			-12

/*!
 *  @def    MESSAGEQ_E_REMOTEACTIVE
 *  @brief  Operation is successful.
 */
#define MESSAGEQ_E_REMOTEACTIVE			-13

/*!
 *  @def    MESSAGEQ_E_INVALIDHEAPID
 *  @brief  Operation is successful.
 */
#define MESSAGEQ_E_INVALIDHEAPID		-14

/*!
 *  @def    MESSAGEQ_E_INVALIDPROCID
 *  @brief  Operation is successful.
 */
#define MESSAGEQ_E_INVALIDPROCID		-15

/*!
 *  @def    MESSAGEQ_E_MAXREACHED
 *  @brief  Operation is successful.
 */
#define MESSAGEQ_E_MAXREACHED			-16

/*!
 *  @def    MESSAGEQ_E_UNREGISTEREDHEAPID
 *  @brief  Operation is successful.
 */
#define MESSAGEQ_E_UNREGISTEREDHEAPID		-17

/*!
 *  @def    MESSAGEQ_E_CANNOTFREESTATICMSG
 *  @brief  Operation is successful.
 */
#define MESSAGEQ_E_CANNOTFREESTATICMSG		-18
/*!
 *  @def    MESSAGEQ_E_UNBLOCKED
 *  @brief  The resource is now unblocked
 */
#define MESSAGEQ_E_UNBLOCKED			-20


/* =============================================================================
 * Macros and types
 * =============================================================================
 */
/*!
 *	@brief	Mask to extract version setting
 */
#define MESSAGEQ_HEADERVERSION			0x2000u

/*! Mask to extract Trace setting */
#define MESSAGEQ_TRACEMASK			(uint) 0x1000

/*! Shift for Trace setting */
#define MESSAGEQ_TRACESHIFT			(uint) 12

/*!
 *	@brief	Mask to extract priority setting
 */
#define MESSAGEQ_PRIORITYMASK			0x3u

/*!
 *  Used as the timeout value to specify wait forever
 */
#define MESSAGEQ_FOREVER			(~((u32) 0))

/*!
 *  Invalid message id
 */
#define MESSAGEQ_INVALIDMSGID			0xFFFF

/*!
 * Invalid message queue
 */
#define MESSAGEQ_INVALIDMESSAGEQ		0xFFFF

/*!
 * Indicates that if maximum number of message queues are already created,
 * should allow growth to create additional Message Queue.
 */
#define MESSAGEQ_ALLOWGROWTH			(~((u32) 0))

/*!
 * Number of types of priority queues for each transport
 */
#define MESSAGEQ_NUM_PRIORITY_QUEUES		2


/* =============================================================================
 * Structures & Enums
 * =============================================================================
 */
/*!
 * Message priority
 */
enum messageq_priority {
	MESSAGEQ_NORMALPRI = 0,
	/*!< Normal priority message */
	MESSAGEQ_HIGHPRI = 1,
	/*!< High priority message */
	MESSAGEQ_RESERVEDPRI = 2,
	/*!< Reserved value for message priority */
	MESSAGEQ_URGENTPRI = 3
	/*!< Urgent priority message */
};

/*! Structure which defines the first field in every message */
struct msgheader {
	u32 reserved0;
	/*!< Reserved field */
	u32 reserved1;
	/*!< Reserved field */
	u32 msg_size;
	/*!< Size of the message (including header) */
	u16 flags;
	/*!< Flags */
	u16 msg_id;
	/*!< Maximum length for Message queue names */
	u16 dst_id;
	/*!< Maximum length for Message queue names */
	u16 dst_proc;
	/*!< Maximum length for Message queue names */
	u16 reply_id;
	/*!< Maximum length for Message queue names */
	u16 reply_proc;
	/*!< Maximum length for Message queue names */
	u16 src_proc;
	/*!< Maximum length for Message queue names */
	u16 heap_id;
	/*!< Maximum length for Message queue names */
	u16 seq_num;
	/*!< sequence number */
	u32 reserved;
	/*!< Reserved field */
};

/*! Structure which defines the first field in every message */
#define messageq_msg	struct msgheader *
/*typedef struct msgheader *messageq_msg;*/


/*!
 *  @brief	Structure defining config parameters for the MessageQ Buf module.
 */
struct messageq_config {
	bool trace_flag;
	/*!< Trace Flag
	*  This flag allows the configuration of the default module trace
	*  settings.
	*/

	u16 num_heaps;
	/*!< Number of heapIds in the system
	*  This allows MessageQ to pre-allocate the heaps table.
	*  The heaps table is used when registering heaps.
	*  The default is 1 since generally all systems need at least one heap.
	*  There is no default heap, so unless the system is only using
	*  staticMsgInit, the application must register a heap.
	*/

	u32 max_runtime_entries;
	/*!
	*  Maximum number of MessageQs that can be dynamically created
	*/

	u32 max_name_len;
	/*!< Maximum length for Message queue names */
};

struct messageq_params {
	void *synchronizer;
	/*!< Synchronizer instance used to signal IO completion
	*
	* The synchronizer is used in the #MessageQ_put and #MessageQ_get calls.
	* The synchronizer signal is called as part of the #MessageQ_put call.
	* The synchronizer waits in the #MessageQ_get if there are no messages
	* present.
	*/
};

/* =============================================================================
 *  APIs
 * =============================================================================
 */
/* Functions to get the configuration for messageq setup */
void messageq_get_config(struct messageq_config *cfg);

/* Function to setup the MessageQ module. */
int messageq_setup(const struct messageq_config *cfg);

/* Function to destroy the MessageQ module. */
int messageq_destroy(void);

/* Returns the amount of shared memory used by one transport instance.
 *
 *  The MessageQ module itself does not use any shared memory but the
 *  underlying transport may use some shared memory.
 */
uint messageq_shared_mem_req(void *shared_addr);

/* Calls the SetupProxy function to setup the MessageQ transports. */
int messageq_attach(u16 remote_proc_id, void *shared_addr);

/* Calls the SetupProxy function to detach the MessageQ transports. */
int messageq_detach(u16 remote_proc_id);

/* Initialize this config-params structure with supplier-specified
 * defaults before instance creation.
 */
void messageq_params_init(struct messageq_params *params);

/* Create a message queue */
void *messageq_create(char *name, const struct messageq_params *params);

/* Deletes a instance of MessageQ module. */
int messageq_delete(void **messageq_handleptr);

/* Open a message queue */
int messageq_open(char *name, u32 *queue_id);

/* Close an opened message queue handle */
int messageq_close(u32 *queue_id);

/* Allocates a message from the heap */
messageq_msg messageq_alloc(u16 heapId, u32 size);

/* Frees a message back to the heap */
int messageq_free(messageq_msg msg);

/* Initializes a message not obtained from MessageQ_alloc */
void messageq_static_msg_init(messageq_msg msg, u32 size);

/* Place a message onto a message queue */
int messageq_put(u32 queueId, messageq_msg msg);

/* Gets a message for a message queue and blocks if the queue is empty */
int messageq_get(void *messageq_handle, messageq_msg *msg, u32 timeout);

/* Register a heap with MessageQ */
int messageq_register_heap(void *heap_handle, u16 heap_id);

/* Unregister a heap with MessageQ */
int messageq_unregister_heap(u16 heapId);

/* Returns the number of messages in a message queue */
int messageq_count(void *messageq_handle);

/* Get the proc Id of the message. */
u16 messageq_get_proc_id(void *messageq_handle);

/* Get the queue Id of the message. */
u32 messageq_get_queue_id(void *messageq_handle);

/* Set the destination queue of the message. */
void messageq_set_reply_queue(void *messageq_handle, messageq_msg msg);

/* Set the tracing of a message */
void messageq_set_msg_trace(messageq_msg msg, bool trace_flag);

/*
 *  Functions to set Message properties
 */
/*!
 *  @brief   Returns the MessageQ_Queue handle of the destination
 *           message queue for the specified message.
 */
u32 messageq_get_dst_queue(messageq_msg msg);

/*!
 *  @brief   Returns the message ID of the specified message.
 */
u16 messageq_get_msg_id(messageq_msg msg);

/*!
 *  @brief   Returns the size of the specified message.
 */
u32 messageq_get_msg_size(messageq_msg msg);

/*!
 *  @brief	Gets the message priority of a message
 */
u32 messageq_get_msg_pri(messageq_msg msg);

/*!
 *  @brief   Returns the MessageQ_Queue handle of the destination
 *           message queue for the specified message.
 */
u32 messageq_get_reply_queue(messageq_msg msg);

/*!
 *  @brief   Sets the message ID in the specified message.
 */
void messageq_set_msg_id(messageq_msg msg, u16 msg_id);
/*!
 *  @brief   Sets the message priority in the specified message.
 */
void messageq_set_msg_pri(messageq_msg msg, u32 priority);

/* =============================================================================
 *  APIs called internally by MessageQ transports
 * =============================================================================
 */
/* Register a transport with MessageQ */
int messageq_register_transport(void *imessageq_transport_handle,
					u16 proc_id, u32 priority);

/* Unregister a transport with MessageQ */
void messageq_unregister_transport(u16 proc_id, u32 priority);

/* Unblock messageq to prevent waiting forever */
int messageq_unblock(void *messageq_handle);

#endif /* _MESSAGEQ_H_ */