Commit 7157e75f authored by Arun Gopalakrishnan's avatar Arun Gopalakrishnan Committed by Hari Kanigeri

ARM OMAP4 Syslink IPC MessageQ, MessageQ Transport Changes

This patch can be used to sync with the syslink drop 2.0.0.6
for above modules
The major changes are
   1. The atomic function usage came in the above modules
   2. Some logical changes came in some of the functions
      in above modules (messageq get, messageq put etc.)
   3. Some of the data structures were changed
   4. Few new functions introduced in place of macros
Signed-off-by: default avatarArun M G <arunmg@ti.com>
parent 76f0d569
...@@ -183,6 +183,12 @@ ...@@ -183,6 +183,12 @@
*/ */
#define MESSAGEQ_E_ALREADYEXISTS MESSAGEQ_MAKE_FAILURE(20) #define MESSAGEQ_E_ALREADYEXISTS MESSAGEQ_MAKE_FAILURE(20)
/*!
* @def MESSAGEQ_E_TIMEOUT
* @brief Timeout while attempting to get a message
*/
#define MESSAGEQ_E_TIMEOUT MESSAGEQ_MAKE_FAILURE(21)
/*! /*!
* @def MESSAGEQ_SUCCESS * @def MESSAGEQ_SUCCESS
* @brief Operation successful. * @brief Operation successful.
...@@ -201,9 +207,19 @@ ...@@ -201,9 +207,19 @@
* ============================================================================= * =============================================================================
*/ */
/*! /*!
* Mask to extract priority setting * @brief Mask to extract version setting
*/
#define MESSAGEQ_HEADERVERSION 0x2000u
/*!
* @brief Mask to extract priority setting
*/ */
#define MESSAGEQ_PRIORITYMASK 0x3 #define MESSAGEQ_PRIORITYMASK 0x3u
/*!
* @brief Mask to extract priority setting
*/
#define MESSAGEQ_TRANSPORTPRIORITYMASK 0x01u
/*! /*!
* Mask to extract version setting * Mask to extract version setting
...@@ -243,10 +259,10 @@ enum messageq_priority { ...@@ -243,10 +259,10 @@ enum messageq_priority {
/*!< Normal priority message */ /*!< Normal priority message */
MESSAGEQ_HIGHPRI = 1, MESSAGEQ_HIGHPRI = 1,
/*!< High priority message */ /*!< High priority message */
MESSAGEQ_URGENTPRI = 2, MESSAGEQ_RESERVEDPRI = 2,
/*!< Urgent priority message */
MESSAGEQ_RESERVEDPRI = 3
/*!< Reserved value for message priority */ /*!< Reserved value for message priority */
MESSAGEQ_URGENTPRI = 3
/*!< Urgent priority message */
}; };
/*! Structure which defines the first field in every message */ /*! Structure which defines the first field in every message */
...@@ -273,6 +289,8 @@ struct msgheader { ...@@ -273,6 +289,8 @@ struct msgheader {
/*!< Maximum length for Message queue names */ /*!< Maximum length for Message queue names */
u16 heap_id; u16 heap_id;
/*!< Maximum length for Message queue names */ /*!< Maximum length for Message queue names */
u32 reserved;
/*!< Reserved field */
}; };
/*! Structure which defines the first field in every message */ /*! Structure which defines the first field in every message */
#define messageq_msg struct msgheader * #define messageq_msg struct msgheader *
...@@ -317,6 +335,8 @@ struct messageq_config { ...@@ -317,6 +335,8 @@ struct messageq_config {
struct messageq_params { struct messageq_params {
u32 reserved; u32 reserved;
/*!< No parameters required currently. Reserved field. */ /*!< No parameters required currently. Reserved field. */
u32 max_name_len;
/*!< Maximum length for Message queue names */
}; };
/* ============================================================================= /* =============================================================================
...@@ -363,7 +383,8 @@ void messageq_static_msg_init(messageq_msg msg, u32 size); ...@@ -363,7 +383,8 @@ void messageq_static_msg_init(messageq_msg msg, u32 size);
int messageq_put(u32 queueId, messageq_msg msg); int messageq_put(u32 queueId, messageq_msg msg);
/* Gets a message for a message queue and blocks if the queue is empty */ /* Gets a message for a message queue and blocks if the queue is empty */
messageq_msg messageq_get(void *messageq_handle, u32 timeout); int messageq_get(void *messageq_handle, messageq_msg *msg,
u32 timeout);
/* Register a heap with MessageQ */ /* Register a heap with MessageQ */
int messageq_register_heap(void *heap_handle, u16 heap_id); int messageq_register_heap(void *heap_handle, u16 heap_id);
......
...@@ -144,9 +144,8 @@ ...@@ -144,9 +144,8 @@
* @brief Module configuration structure. * @brief Module configuration structure.
*/ */
struct messageq_transportshm_config { struct messageq_transportshm_config {
void *gate_handle; u32 reserved;
/*!< Handle of gate to be used for local thread safety. If provided as /*!< Reserved value */
NULL, gate handle is created internally. */
}; };
/*! /*!
......
...@@ -119,6 +119,9 @@ struct messageq_transportshm_cmd_args { ...@@ -119,6 +119,9 @@ struct messageq_transportshm_cmd_args {
void *messageq_transportshm_handle; void *messageq_transportshm_handle;
u16 proc_id; u16 proc_id;
struct messageq_transportshm_params *params; struct messageq_transportshm_params *params;
u32 shared_addr_srptr;
void *knl_lock_handle;
void *knl_notify_driver;
} create; } create;
struct { struct {
......
...@@ -60,22 +60,24 @@ exit: ...@@ -60,22 +60,24 @@ exit:
*/ */
static inline int messageq_ioctl_get(struct messageq_cmd_args *cargs) static inline int messageq_ioctl_get(struct messageq_cmd_args *cargs)
{ {
messageq_msg msg; messageq_msg msg = NULL;
u32 *msg_srptr = SHAREDREGION_INVALIDSRPTR; u32 *msg_srptr = SHAREDREGION_INVALIDSRPTR;
int index; int index;
msg = messageq_get(cargs->args.get.messageq_handle, cargs->api_status = messageq_get(cargs->args.get.messageq_handle,
&msg,
cargs->args.get.timeout); cargs->args.get.timeout);
if (unlikely(msg == NULL)) if (unlikely(cargs->api_status < 0))
goto exit; goto exit;
index = sharedregion_get_index(msg); index = sharedregion_get_index(msg);
if (unlikely(index < 0)) if (unlikely(index < 0)) {
cargs->api_status = index;
goto exit; goto exit;
}
msg_srptr = sharedregion_get_srptr(msg, index); msg_srptr = sharedregion_get_srptr(msg, index);
cargs->api_status = 0;
exit: exit:
cargs->args.get.msg_srptr = msg_srptr; cargs->args.get.msg_srptr = msg_srptr;
return 0; return 0;
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
/* Syslink headers */ /* Syslink headers */
#include <gt.h> #include <gt.h>
#include <syslink/atomic_linux.h>
/* Module level headers */ /* Module level headers */
#include <multiproc.h> #include <multiproc.h>
#include <nameserver.h> #include <nameserver.h>
...@@ -48,6 +48,12 @@ ...@@ -48,6 +48,12 @@
/* messageq_transportshm Version. */ /* messageq_transportshm Version. */
#define MESSAGEQ_TRANSPORTSHM_VERSION 1 #define MESSAGEQ_TRANSPORTSHM_VERSION 1
/*!
* @brief Macro to make a correct module magic number with refCount
*/
#define MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(x) \
((MESSAGEQ_TRANSPORTSHM_MODULEID << 12u) | (x))
/* ============================================================================= /* =============================================================================
* Structures & Enums * Structures & Enums
* ============================================================================= * =============================================================================
...@@ -57,14 +63,13 @@ ...@@ -57,14 +63,13 @@
* module specific information. * module specific information.
*/ */
struct messageq_transportshm_moduleobject { struct messageq_transportshm_moduleobject {
atomic_t ref_count;
struct messageq_transportshm_config cfg; struct messageq_transportshm_config cfg;
/*< messageq_transportshm configuration structure */ /*< messageq_transportshm configuration structure */
struct messageq_transportshm_config def_cfg; struct messageq_transportshm_config def_cfg;
/*< Default module configuration */ /*< Default module configuration */
struct messageq_transportshm_params def_inst_params; struct messageq_transportshm_params def_inst_params;
/*< Default instance parameters */ /*< Default instance parameters */
bool is_setup;
/*< Indicates whether the messageq_transportshm module is setup. */
void *gate_handle; void *gate_handle;
/*< Handle to the gate for local thread safety */ /*< Handle to the gate for local thread safety */
}; };
...@@ -73,8 +78,8 @@ struct messageq_transportshm_moduleobject { ...@@ -73,8 +78,8 @@ struct messageq_transportshm_moduleobject {
* Structure of attributes in shared memory * Structure of attributes in shared memory
*/ */
struct messageq_transportshm_attrs { struct messageq_transportshm_attrs {
u32 version; volatile u32 version;
u32 flag; volatile u32 flag;
}; };
/* /*
...@@ -82,13 +87,13 @@ struct messageq_transportshm_attrs { ...@@ -82,13 +87,13 @@ struct messageq_transportshm_attrs {
* instances. * instances.
*/ */
struct messageq_transportshm_object { struct messageq_transportshm_object {
struct messageq_transportshm_attrs *attrs[2]; volatile struct messageq_transportshm_attrs *attrs[2];
/* Attributes for both processors */ /* Attributes for both processors */
void *my_listmp_handle; void *my_listmp_handle;
/* List for this processor */ /* List for this processor */
void *remote_listmp_handle; void *remote_listmp_handle;
/* List for remote processor */ /* List for remote processor */
int status; volatile int status;
/* Current status */ /* Current status */
int my_index; int my_index;
/* 0 | 1 */ /* 0 | 1 */
...@@ -104,6 +109,8 @@ struct messageq_transportshm_object { ...@@ -104,6 +109,8 @@ struct messageq_transportshm_object {
/* Gate for critical regions */ /* Gate for critical regions */
struct messageq_transportshm_params params; struct messageq_transportshm_params params;
/* Instance specific parameters */ /* Instance specific parameters */
u32 priority;
/*!< Priority of messages supported by this transport */
}; };
/* ============================================================================= /* =============================================================================
...@@ -116,9 +123,8 @@ struct messageq_transportshm_object { ...@@ -116,9 +123,8 @@ struct messageq_transportshm_object {
* messageq_transportshm state object variable * messageq_transportshm state object variable
*/ */
static struct messageq_transportshm_moduleobject messageq_transportshm_state = { static struct messageq_transportshm_moduleobject messageq_transportshm_state = {
.is_setup = false,
.gate_handle = NULL, .gate_handle = NULL,
.def_cfg.gate_handle = NULL, .def_cfg.reserved = 0,
.def_inst_params.gate = NULL, .def_inst_params.gate = NULL,
.def_inst_params.shared_addr = 0x0, .def_inst_params.shared_addr = 0x0,
.def_inst_params.shared_addr_size = 0x0, .def_inst_params.shared_addr_size = 0x0,
...@@ -166,7 +172,9 @@ void messageq_transportshm_get_config( ...@@ -166,7 +172,9 @@ void messageq_transportshm_get_config(
if (WARN_ON(cfg == NULL)) if (WARN_ON(cfg == NULL))
goto exit; goto exit;
if (messageq_transportshm_state.is_setup == false) { if (atomic_cmpmask_and_lt(&(messageq_transportshm_state.ref_count),
MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(0),
MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(1)) == true) {
memcpy(cfg, &(messageq_transportshm_state.def_cfg), memcpy(cfg, &(messageq_transportshm_state.def_cfg),
sizeof(struct messageq_transportshm_config)); sizeof(struct messageq_transportshm_config));
} else { } else {
...@@ -206,20 +214,27 @@ int messageq_transportshm_setup(struct messageq_transportshm_config *cfg) ...@@ -206,20 +214,27 @@ int messageq_transportshm_setup(struct messageq_transportshm_config *cfg)
gt_1trace(mqtshm_debugmask, GT_ENTER, gt_1trace(mqtshm_debugmask, GT_ENTER,
"messageq_transportshm_setup", cfg); "messageq_transportshm_setup", cfg);
/* This sets the refCount variable is not initialized, upper 16 bits is
* written with module Id to ensure correctness of refCount variable.
*/
atomic_cmpmask_and_set(&messageq_transportshm_state.ref_count,
MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(0),
MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(0));
if (atomic_inc_return(&messageq_transportshm_state.ref_count)
!= MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(1u)) {
status = -EEXIST;;
goto exit;
}
if (cfg == NULL) { if (cfg == NULL) {
messageq_transportshm_get_config(&tmpCfg); messageq_transportshm_get_config(&tmpCfg);
cfg = &tmpCfg; cfg = &tmpCfg;
} }
if (cfg->gate_handle != NULL) {
messageq_transportshm_state.gate_handle = cfg->gate_handle;
} else {
/* User has not provided any gate handle, so create a
default handle. */
messageq_transportshm_state.gate_handle = \ messageq_transportshm_state.gate_handle = \
kmalloc(sizeof(struct mutex), GFP_KERNEL); kmalloc(sizeof(struct mutex), GFP_KERNEL);
mutex_init(messageq_transportshm_state.gate_handle); mutex_init(messageq_transportshm_state.gate_handle);
}
if (messageq_transportshm_state.gate_handle == NULL) { if (messageq_transportshm_state.gate_handle == NULL) {
/* @retval MESSAGEQTRANSPORTSHM_E_FAIL Failed to create /* @retval MESSAGEQTRANSPORTSHM_E_FAIL Failed to create
...@@ -230,13 +245,14 @@ int messageq_transportshm_setup(struct messageq_transportshm_config *cfg) ...@@ -230,13 +245,14 @@ int messageq_transportshm_setup(struct messageq_transportshm_config *cfg)
"messageq_transportshm_setup", "messageq_transportshm_setup",
status, status,
"Failed to create GateMutex!"); "Failed to create GateMutex!");
atomic_set(&messageq_transportshm_state.ref_count,
MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(0));
goto exit; goto exit;
} }
/* Copy the user provided values into the state object. */ /* Copy the user provided values into the state object. */
memcpy(&messageq_transportshm_state.cfg, cfg, memcpy(&messageq_transportshm_state.cfg, cfg,
sizeof(struct messageq_transportshm_config)); sizeof(struct messageq_transportshm_config));
messageq_transportshm_state.is_setup = true;
exit: exit:
gt_1trace(mqtshm_debugmask, GT_LEAVE, gt_1trace(mqtshm_debugmask, GT_LEAVE,
...@@ -261,18 +277,26 @@ int messageq_transportshm_destroy(void) ...@@ -261,18 +277,26 @@ int messageq_transportshm_destroy(void)
gt_0trace(mqtshm_debugmask, GT_ENTER, "messageq_transportshm_destroy"); gt_0trace(mqtshm_debugmask, GT_ENTER, "messageq_transportshm_destroy");
/* Check if the gate_handle was created internally. */ if (WARN_ON(atomic_cmpmask_and_lt(
if (messageq_transportshm_state.cfg.gate_handle == NULL) { &(messageq_transportshm_state.ref_count),
MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(0),
MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(1)) == true)) {
status = -ENODEV;
goto exit;
}
if (atomic_dec_return(&messageq_transportshm_state.ref_count)
== MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(0)) {
if (messageq_transportshm_state.gate_handle != NULL) { if (messageq_transportshm_state.gate_handle != NULL) {
kfree(messageq_transportshm_state.gate_handle); kfree(messageq_transportshm_state.gate_handle);
messageq_transportshm_state.gate_handle = NULL; messageq_transportshm_state.gate_handle = NULL;
} }
/* Decrease the ref_count */
atomic_set(&messageq_transportshm_state.ref_count,
MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(0));
} }
messageq_transportshm_state.is_setup = false; exit:
gt_1trace(mqtshm_debugmask, GT_LEAVE,
"messageq_transportshm_destroy", status);
return status; return status;
} }
...@@ -291,6 +315,12 @@ void messageq_transportshm_params_init(void *mqtshm_handle, ...@@ -291,6 +315,12 @@ void messageq_transportshm_params_init(void *mqtshm_handle,
"messageq_transportshm_params_init", mqtshm_handle, "messageq_transportshm_params_init", mqtshm_handle,
params); params);
if (WARN_ON(atomic_cmpmask_and_lt(
&(messageq_transportshm_state.ref_count),
MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(0),
MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(1)) == true))
goto exit;
BUG_ON(params == NULL); BUG_ON(params == NULL);
if (WARN_ON(params == NULL)) { if (WARN_ON(params == NULL)) {
/* @retval None */ /* @retval None */
...@@ -337,11 +367,17 @@ void *messageq_transportshm_create(u16 proc_id, ...@@ -337,11 +367,17 @@ void *messageq_transportshm_create(u16 proc_id,
int my_index; int my_index;
int remote_index; int remote_index;
listmp_sharedmemory_params listmp_params[2]; listmp_sharedmemory_params listmp_params[2];
u32 *volatile otherflag; volatile u32 *otherflag;
gt_2trace(mqtshm_debugmask, GT_ENTER, "messageq_transportshm_create", gt_2trace(mqtshm_debugmask, GT_ENTER, "messageq_transportshm_create",
proc_id, params); proc_id, params);
if (WARN_ON(atomic_cmpmask_and_lt(
&(messageq_transportshm_state.ref_count),
MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(0),
MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(1)) == true))
goto exit;
BUG_ON(params == NULL); BUG_ON(params == NULL);
if (WARN_ON(params == NULL)) { if (WARN_ON(params == NULL)) {
status = -EINVAL; status = -EINVAL;
...@@ -398,6 +434,7 @@ void *messageq_transportshm_create(u16 proc_id, ...@@ -398,6 +434,7 @@ void *messageq_transportshm_create(u16 proc_id,
handle->notify_driver = params->notify_driver; handle->notify_driver = params->notify_driver;
handle->notify_event_no = params->notify_event_no; handle->notify_event_no = params->notify_event_no;
handle->priority = params->priority;
handle->proc_id = proc_id; handle->proc_id = proc_id;
handle->my_index = my_index; handle->my_index = my_index;
handle->remote_index = remote_index; handle->remote_index = remote_index;
...@@ -424,8 +461,8 @@ void *messageq_transportshm_create(u16 proc_id, ...@@ -424,8 +461,8 @@ void *messageq_transportshm_create(u16 proc_id,
handle->my_listmp_handle = listmp_sharedmemory_create handle->my_listmp_handle = listmp_sharedmemory_create
(&(listmp_params[my_index])); (&(listmp_params[my_index]));
handle->attrs[my_index]->flag = MESSAGEQ_TRANSPORTSHM_UP;
handle->attrs[my_index]->version = MESSAGEQ_TRANSPORTSHM_VERSION; handle->attrs[my_index]->version = MESSAGEQ_TRANSPORTSHM_VERSION;
handle->attrs[my_index]->flag = MESSAGEQ_TRANSPORTSHM_UP;
/* Store in volatile to make sure it is not compiled out... */ /* Store in volatile to make sure it is not compiled out... */
otherflag = &(handle->attrs[remote_index]->flag); otherflag = &(handle->attrs[remote_index]->flag);
...@@ -442,7 +479,7 @@ void *messageq_transportshm_create(u16 proc_id, ...@@ -442,7 +479,7 @@ void *messageq_transportshm_create(u16 proc_id,
gt_2trace(mqtshm_debugmask, GT_4CLASS, gt_2trace(mqtshm_debugmask, GT_4CLASS,
"messageq_transportshm_create", "messageq_transportshm_create",
MESSAGEQ_TRANSPORTSHM_E_BADVERSION, MESSAGEQ_TRANSPORTSHM_E_BADVERSION,
"Notify register failed!"); "Incorrect version of remote transport!");
goto exit; goto exit;
} }
...@@ -496,6 +533,14 @@ int messageq_transportshm_delete(void **mqtshm_handleptr) ...@@ -496,6 +533,14 @@ int messageq_transportshm_delete(void **mqtshm_handleptr)
gt_1trace(mqtshm_debugmask, GT_ENTER, "messageq_transportshm_delete", gt_1trace(mqtshm_debugmask, GT_ENTER, "messageq_transportshm_delete",
mqtshm_handleptr); mqtshm_handleptr);
if (WARN_ON(atomic_cmpmask_and_lt(
&(messageq_transportshm_state.ref_count),
MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(0),
MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(1)) == true)) {
status = -ENODEV;
goto exit;
}
BUG_ON(mqtshm_handleptr == NULL); BUG_ON(mqtshm_handleptr == NULL);
if (WARN_ON(mqtshm_handleptr == NULL)) { if (WARN_ON(mqtshm_handleptr == NULL)) {
status = -EINVAL; status = -EINVAL;
...@@ -575,9 +620,17 @@ int messageq_transportshm_put(void *mqtshm_handle, ...@@ -575,9 +620,17 @@ int messageq_transportshm_put(void *mqtshm_handle,
gt_2trace(mqtshm_debugmask, GT_ENTER, "messageq_transportshm_put", gt_2trace(mqtshm_debugmask, GT_ENTER, "messageq_transportshm_put",
obj, msg); obj, msg);
if (WARN_ON(atomic_cmpmask_and_lt(
&(messageq_transportshm_state.ref_count),
MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(0),
MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(1)) == true)) {
status = -ENODEV;
goto exit;
}
BUG_ON(mqtshm_handle == NULL);
BUG_ON(msg == NULL); BUG_ON(msg == NULL);
BUG_ON(obj == NULL);
if (WARN_ON(msg == NULL)) { if (WARN_ON(msg == NULL)) {
status = -EINVAL; status = -EINVAL;
goto exit; goto exit;
......
...@@ -141,10 +141,13 @@ static inline int messageq_transportshm_ioctl_create( ...@@ -141,10 +141,13 @@ static inline int messageq_transportshm_ioctl_create(
goto exit; goto exit;
} }
params.shared_addr = sharedregion_get_ptr((u32 *)params.shared_addr); params.shared_addr = sharedregion_get_ptr(
(u32 *)cargs->args.create.shared_addr_srptr);
if (unlikely(params.shared_addr == NULL)) if (unlikely(params.shared_addr == NULL))
goto exit; goto exit;
params.gate = cargs->args.create.knl_lock_handle;
params.notify_driver = cargs->args.create.knl_notify_driver;
cargs->args.create.messageq_transportshm_handle = \ cargs->args.create.messageq_transportshm_handle = \
messageq_transportshm_create(cargs->args.create.proc_id, messageq_transportshm_create(cargs->args.create.proc_id,
&params); &params);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment