4
* The MessageQ module supports the structured sending and receiving of
5
* variable length messages. This module can be used for homogeneous or
6
* heterogeneous multi-processor messaging.
8
* Copyright (C) 2009 Texas Instruments, Inc.
10
* This package is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License version 2 as
12
* published by the Free Software Foundation.
14
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
23
/* Standard headers */
24
#include <linux/types.h>
26
/* Utilities headers */
27
#include <linux/list.h>
33
* @def MESSAGEQ_MODULEID
34
* @brief Unique module ID.
36
#define MESSAGEQ_MODULEID (0xded2)
39
/* =============================================================================
40
* All success and failure codes for the module
41
* =============================================================================
45
* @def MESSAGEQ_S_BUSY
46
* @brief The resource is still in use
48
#define MESSAGEQ_S_BUSY 2
51
* @def MESSAGEQ_S_ALREADYSETUP
52
* @brief The module has been already setup
54
#define MESSAGEQ_S_ALREADYSETUP 1
57
* @def MESSAGEQ_S_SUCCESS
58
* @brief Operation is successful.
60
#define MESSAGEQ_S_SUCCESS 0
63
* @def MESSAGEQ_E_FAIL
64
* @brief Operation is not successful.
66
#define MESSAGEQ_E_FAIL -1
69
* @def MESSAGEQ_E_INVALIDARG
70
* @brief There is an invalid argument.
72
#define MESSAGEQ_E_INVALIDARG -2
75
* @def MESSAGEQ_E_MEMORY
76
* @brief Operation resulted in memory failure.
78
#define MESSAGEQ_E_MEMORY -3
81
* @def MESSAGEQ_E_ALREADYEXISTS
82
* @brief The specified entity already exists.
84
#define MESSAGEQ_E_ALREADYEXISTS -4
87
* @def MESSAGEQ_E_NOTFOUND
88
* @brief Unable to find the specified entity.
90
#define MESSAGEQ_E_NOTFOUND -5
93
* @def MESSAGEQ_E_TIMEOUT
94
* @brief Operation timed out.
96
#define MESSAGEQ_E_TIMEOUT -6
99
* @def MESSAGEQ_E_INVALIDSTATE
100
* @brief Module is not initialized.
102
#define MESSAGEQ_E_INVALIDSTATE -7
105
* @def MESSAGEQ_E_OSFAILURE
106
* @brief A failure occurred in an OS-specific call
108
#define MESSAGEQ_E_OSFAILURE -8
111
* @def MESSAGEQ_E_RESOURCE
112
* @brief Specified resource is not available
114
#define MESSAGEQ_E_RESOURCE -9
117
* @def MESSAGEQ_E_RESTART
118
* @brief Operation was interrupted. Please restart the operation
120
#define MESSAGEQ_E_RESTART -10
123
* @def MESSAGEQ_E_INVALIDMSG
124
* @brief Operation is successful.
126
#define MESSAGEQ_E_INVALIDMSG -11
129
* @def MESSAGEQ_E_NOTOWNER
130
* @brief Not the owner
132
#define MESSAGEQ_E_NOTOWNER -12
135
* @def MESSAGEQ_E_REMOTEACTIVE
136
* @brief Operation is successful.
138
#define MESSAGEQ_E_REMOTEACTIVE -13
141
* @def MESSAGEQ_E_INVALIDHEAPID
142
* @brief Operation is successful.
144
#define MESSAGEQ_E_INVALIDHEAPID -14
147
* @def MESSAGEQ_E_INVALIDPROCID
148
* @brief Operation is successful.
150
#define MESSAGEQ_E_INVALIDPROCID -15
153
* @def MESSAGEQ_E_MAXREACHED
154
* @brief Operation is successful.
156
#define MESSAGEQ_E_MAXREACHED -16
159
* @def MESSAGEQ_E_UNREGISTEREDHEAPID
160
* @brief Operation is successful.
162
#define MESSAGEQ_E_UNREGISTEREDHEAPID -17
165
* @def MESSAGEQ_E_CANNOTFREESTATICMSG
166
* @brief Operation is successful.
168
#define MESSAGEQ_E_CANNOTFREESTATICMSG -18
170
* @def MESSAGEQ_E_UNBLOCKED
171
* @brief The resource is now unblocked
173
#define MESSAGEQ_E_UNBLOCKED -20
176
/* =============================================================================
178
* =============================================================================
181
* @brief Mask to extract version setting
183
#define MESSAGEQ_HEADERVERSION 0x2000u
185
/*! Mask to extract Trace setting */
186
#define MESSAGEQ_TRACEMASK (uint) 0x1000
188
/*! Shift for Trace setting */
189
#define MESSAGEQ_TRACESHIFT (uint) 12
192
* @brief Mask to extract priority setting
194
#define MESSAGEQ_PRIORITYMASK 0x3u
197
* Used as the timeout value to specify wait forever
199
#define MESSAGEQ_FOREVER (~((u32) 0))
204
#define MESSAGEQ_INVALIDMSGID 0xFFFF
207
* Invalid message queue
209
#define MESSAGEQ_INVALIDMESSAGEQ 0xFFFF
212
* Indicates that if maximum number of message queues are already created,
213
* should allow growth to create additional Message Queue.
215
#define MESSAGEQ_ALLOWGROWTH (~((u32) 0))
218
* Number of types of priority queues for each transport
220
#define MESSAGEQ_NUM_PRIORITY_QUEUES 2
223
/* =============================================================================
225
* =============================================================================
230
enum messageq_priority {
231
MESSAGEQ_NORMALPRI = 0,
232
/*!< Normal priority message */
233
MESSAGEQ_HIGHPRI = 1,
234
/*!< High priority message */
235
MESSAGEQ_RESERVEDPRI = 2,
236
/*!< Reserved value for message priority */
237
MESSAGEQ_URGENTPRI = 3
238
/*!< Urgent priority message */
241
/*! Structure which defines the first field in every message */
244
/*!< Reserved field */
246
/*!< Reserved field */
248
/*!< Size of the message (including header) */
252
/*!< Maximum length for Message queue names */
254
/*!< Maximum length for Message queue names */
256
/*!< Maximum length for Message queue names */
258
/*!< Maximum length for Message queue names */
260
/*!< Maximum length for Message queue names */
262
/*!< Maximum length for Message queue names */
264
/*!< Maximum length for Message queue names */
266
/*!< sequence number */
268
/*!< Reserved field */
271
/*! Structure which defines the first field in every message */
272
#define messageq_msg struct msgheader *
273
/*typedef struct msgheader *messageq_msg;*/
277
* @brief Structure defining config parameters for the MessageQ Buf module.
279
struct messageq_config {
282
* This flag allows the configuration of the default module trace
287
/*!< Number of heapIds in the system
288
* This allows MessageQ to pre-allocate the heaps table.
289
* The heaps table is used when registering heaps.
290
* The default is 1 since generally all systems need at least one heap.
291
* There is no default heap, so unless the system is only using
292
* staticMsgInit, the application must register a heap.
295
u32 max_runtime_entries;
297
* Maximum number of MessageQs that can be dynamically created
301
/*!< Maximum length for Message queue names */
304
struct messageq_params {
306
/*!< Synchronizer instance used to signal IO completion
308
* The synchronizer is used in the #MessageQ_put and #MessageQ_get calls.
309
* The synchronizer signal is called as part of the #MessageQ_put call.
310
* The synchronizer waits in the #MessageQ_get if there are no messages
315
/* =============================================================================
317
* =============================================================================
319
/* Functions to get the configuration for messageq setup */
320
void messageq_get_config(struct messageq_config *cfg);
322
/* Function to setup the MessageQ module. */
323
int messageq_setup(const struct messageq_config *cfg);
325
/* Function to destroy the MessageQ module. */
326
int messageq_destroy(void);
328
/* Returns the amount of shared memory used by one transport instance.
330
* The MessageQ module itself does not use any shared memory but the
331
* underlying transport may use some shared memory.
333
uint messageq_shared_mem_req(void *shared_addr);
335
/* Calls the SetupProxy function to setup the MessageQ transports. */
336
int messageq_attach(u16 remote_proc_id, void *shared_addr);
338
/* Calls the SetupProxy function to detach the MessageQ transports. */
339
int messageq_detach(u16 remote_proc_id);
341
/* Initialize this config-params structure with supplier-specified
342
* defaults before instance creation.
344
void messageq_params_init(struct messageq_params *params);
346
/* Create a message queue */
347
void *messageq_create(char *name, const struct messageq_params *params);
349
/* Deletes a instance of MessageQ module. */
350
int messageq_delete(void **messageq_handleptr);
352
/* Open a message queue */
353
int messageq_open(char *name, u32 *queue_id);
355
/* Close an opened message queue handle */
356
int messageq_close(u32 *queue_id);
358
/* Allocates a message from the heap */
359
messageq_msg messageq_alloc(u16 heapId, u32 size);
361
/* Frees a message back to the heap */
362
int messageq_free(messageq_msg msg);
364
/* Initializes a message not obtained from MessageQ_alloc */
365
void messageq_static_msg_init(messageq_msg msg, u32 size);
367
/* Place a message onto a message queue */
368
int messageq_put(u32 queueId, messageq_msg msg);
370
/* Gets a message for a message queue and blocks if the queue is empty */
371
int messageq_get(void *messageq_handle, messageq_msg *msg, u32 timeout);
373
/* Register a heap with MessageQ */
374
int messageq_register_heap(void *heap_handle, u16 heap_id);
376
/* Unregister a heap with MessageQ */
377
int messageq_unregister_heap(u16 heapId);
379
/* Returns the number of messages in a message queue */
380
int messageq_count(void *messageq_handle);
382
/* Get the proc Id of the message. */
383
u16 messageq_get_proc_id(void *messageq_handle);
385
/* Get the queue Id of the message. */
386
u32 messageq_get_queue_id(void *messageq_handle);
388
/* Set the destination queue of the message. */
389
void messageq_set_reply_queue(void *messageq_handle, messageq_msg msg);
391
/* Set the tracing of a message */
392
void messageq_set_msg_trace(messageq_msg msg, bool trace_flag);
395
* Functions to set Message properties
398
* @brief Returns the MessageQ_Queue handle of the destination
399
* message queue for the specified message.
401
u32 messageq_get_dst_queue(messageq_msg msg);
404
* @brief Returns the message ID of the specified message.
406
u16 messageq_get_msg_id(messageq_msg msg);
409
* @brief Returns the size of the specified message.
411
u32 messageq_get_msg_size(messageq_msg msg);
414
* @brief Gets the message priority of a message
416
u32 messageq_get_msg_pri(messageq_msg msg);
419
* @brief Returns the MessageQ_Queue handle of the destination
420
* message queue for the specified message.
422
u32 messageq_get_reply_queue(messageq_msg msg);
425
* @brief Sets the message ID in the specified message.
427
void messageq_set_msg_id(messageq_msg msg, u16 msg_id);
429
* @brief Sets the message priority in the specified message.
431
void messageq_set_msg_pri(messageq_msg msg, u32 priority);
433
/* =============================================================================
434
* APIs called internally by MessageQ transports
435
* =============================================================================
437
/* Register a transport with MessageQ */
438
int messageq_register_transport(void *imessageq_transport_handle,
439
u16 proc_id, u32 priority);
441
/* Unregister a transport with MessageQ */
442
void messageq_unregister_transport(u16 proc_id, u32 priority);
444
/* Unblock messageq to prevent waiting forever */
445
int messageq_unblock(void *messageq_handle);
447
#endif /* _MESSAGEQ_H_ */