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 @@
*/
#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
* @brief Operation successful.
......@@ -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 0x3u
/*!
* @brief Mask to extract priority setting
*/
#define MESSAGEQ_PRIORITYMASK 0x3
#define MESSAGEQ_TRANSPORTPRIORITYMASK 0x01u
/*!
* Mask to extract version setting
......@@ -243,10 +259,10 @@ enum messageq_priority {
/*!< Normal priority message */
MESSAGEQ_HIGHPRI = 1,
/*!< High priority message */
MESSAGEQ_URGENTPRI = 2,
/*!< Urgent priority message */
MESSAGEQ_RESERVEDPRI = 3
MESSAGEQ_RESERVEDPRI = 2,
/*!< Reserved value for message priority */
MESSAGEQ_URGENTPRI = 3
/*!< Urgent priority message */
};
/*! Structure which defines the first field in every message */
......@@ -273,6 +289,8 @@ struct msgheader {
/*!< Maximum length for Message queue names */
u16 heap_id;
/*!< Maximum length for Message queue names */
u32 reserved;
/*!< Reserved field */
};
/*! Structure which defines the first field in every message */
#define messageq_msg struct msgheader *
......@@ -317,6 +335,8 @@ struct messageq_config {
struct messageq_params {
u32 reserved;
/*!< 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);
int messageq_put(u32 queueId, messageq_msg msg);
/* 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 */
int messageq_register_heap(void *heap_handle, u16 heap_id);
......
......@@ -144,9 +144,8 @@
* @brief Module configuration structure.
*/
struct messageq_transportshm_config {
void *gate_handle;
/*!< Handle of gate to be used for local thread safety. If provided as
NULL, gate handle is created internally. */
u32 reserved;
/*!< Reserved value */
};
/*!
......
......@@ -119,6 +119,9 @@ struct messageq_transportshm_cmd_args {
void *messageq_transportshm_handle;
u16 proc_id;
struct messageq_transportshm_params *params;
u32 shared_addr_srptr;
void *knl_lock_handle;
void *knl_notify_driver;
} create;
struct {
......
......@@ -60,22 +60,24 @@ exit:
*/
static inline int messageq_ioctl_get(struct messageq_cmd_args *cargs)
{
messageq_msg msg;
messageq_msg msg = NULL;
u32 *msg_srptr = SHAREDREGION_INVALIDSRPTR;
int index;
msg = messageq_get(cargs->args.get.messageq_handle,
cargs->args.get.timeout);
if (unlikely(msg == NULL))
cargs->api_status = messageq_get(cargs->args.get.messageq_handle,
&msg,
cargs->args.get.timeout);
if (unlikely(cargs->api_status < 0))
goto exit;
index = sharedregion_get_index(msg);
if (unlikely(index < 0))
if (unlikely(index < 0)) {
cargs->api_status = index;
goto exit;
}
msg_srptr = sharedregion_get_srptr(msg, index);
cargs->api_status = 0;
exit:
cargs->args.get.msg_srptr = msg_srptr;
return 0;
......
......@@ -24,7 +24,7 @@
/* Syslink headers */
#include <gt.h>
#include <syslink/atomic_linux.h>
/* Module level headers */
#include <multiproc.h>
#include <nameserver.h>
......@@ -48,6 +48,12 @@
/* messageq_transportshm Version. */
#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
* =============================================================================
......@@ -57,14 +63,13 @@
* module specific information.
*/
struct messageq_transportshm_moduleobject {
atomic_t ref_count;
struct messageq_transportshm_config cfg;
/*< messageq_transportshm configuration structure */
struct messageq_transportshm_config def_cfg;
/*< Default module configuration */
struct messageq_transportshm_params def_inst_params;
/*< Default instance parameters */
bool is_setup;
/*< Indicates whether the messageq_transportshm module is setup. */
void *gate_handle;
/*< Handle to the gate for local thread safety */
};
......@@ -73,8 +78,8 @@ struct messageq_transportshm_moduleobject {
* Structure of attributes in shared memory
*/
struct messageq_transportshm_attrs {
u32 version;
u32 flag;
volatile u32 version;
volatile u32 flag;
};
/*
......@@ -82,13 +87,13 @@ struct messageq_transportshm_attrs {
* instances.
*/
struct messageq_transportshm_object {
struct messageq_transportshm_attrs *attrs[2];
volatile struct messageq_transportshm_attrs *attrs[2];
/* Attributes for both processors */
void *my_listmp_handle;
/* List for this processor */
void *remote_listmp_handle;
/* List for remote processor */
int status;
volatile int status;
/* Current status */
int my_index;
/* 0 | 1 */
......@@ -104,6 +109,8 @@ struct messageq_transportshm_object {
/* Gate for critical regions */
struct messageq_transportshm_params params;
/* Instance specific parameters */
u32 priority;
/*!< Priority of messages supported by this transport */
};
/* =============================================================================
......@@ -116,9 +123,8 @@ struct messageq_transportshm_object {
* messageq_transportshm state object variable
*/
static struct messageq_transportshm_moduleobject messageq_transportshm_state = {
.is_setup = false,
.gate_handle = NULL,
.def_cfg.gate_handle = NULL,
.def_cfg.reserved = 0,
.def_inst_params.gate = NULL,
.def_inst_params.shared_addr = 0x0,
.def_inst_params.shared_addr_size = 0x0,
......@@ -166,7 +172,9 @@ void messageq_transportshm_get_config(
if (WARN_ON(cfg == NULL))
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),
sizeof(struct messageq_transportshm_config));
} else {
......@@ -206,20 +214,27 @@ int messageq_transportshm_setup(struct messageq_transportshm_config *cfg)
gt_1trace(mqtshm_debugmask, GT_ENTER,
"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) {
messageq_transportshm_get_config(&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 = \
kmalloc(sizeof(struct mutex), GFP_KERNEL);
mutex_init(messageq_transportshm_state.gate_handle);
}
messageq_transportshm_state.gate_handle = \
kmalloc(sizeof(struct mutex), GFP_KERNEL);
mutex_init(messageq_transportshm_state.gate_handle);
if (messageq_transportshm_state.gate_handle == NULL) {
/* @retval MESSAGEQTRANSPORTSHM_E_FAIL Failed to create
......@@ -230,13 +245,14 @@ int messageq_transportshm_setup(struct messageq_transportshm_config *cfg)
"messageq_transportshm_setup",
status,
"Failed to create GateMutex!");
atomic_set(&messageq_transportshm_state.ref_count,
MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(0));
goto exit;
}
/* Copy the user provided values into the state object. */
memcpy(&messageq_transportshm_state.cfg, cfg,
sizeof(struct messageq_transportshm_config));
messageq_transportshm_state.is_setup = true;
exit:
gt_1trace(mqtshm_debugmask, GT_LEAVE,
......@@ -261,18 +277,26 @@ int messageq_transportshm_destroy(void)
gt_0trace(mqtshm_debugmask, GT_ENTER, "messageq_transportshm_destroy");
/* Check if the gate_handle was created internally. */
if (messageq_transportshm_state.cfg.gate_handle == NULL) {
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;
}
if (atomic_dec_return(&messageq_transportshm_state.ref_count)
== MESSAGEQTRANSPORTSHM_MAKE_MAGICSTAMP(0)) {
if (messageq_transportshm_state.gate_handle != NULL) {
kfree(messageq_transportshm_state.gate_handle);
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;
gt_1trace(mqtshm_debugmask, GT_LEAVE,
"messageq_transportshm_destroy", status);
exit:
return status;
}
......@@ -291,6 +315,12 @@ void messageq_transportshm_params_init(void *mqtshm_handle,
"messageq_transportshm_params_init", mqtshm_handle,
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);
if (WARN_ON(params == NULL)) {
/* @retval None */
......@@ -337,11 +367,17 @@ void *messageq_transportshm_create(u16 proc_id,
int my_index;
int remote_index;
listmp_sharedmemory_params listmp_params[2];
u32 *volatile otherflag;
volatile u32 *otherflag;
gt_2trace(mqtshm_debugmask, GT_ENTER, "messageq_transportshm_create",
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);
if (WARN_ON(params == NULL)) {
status = -EINVAL;
......@@ -398,6 +434,7 @@ void *messageq_transportshm_create(u16 proc_id,
handle->notify_driver = params->notify_driver;
handle->notify_event_no = params->notify_event_no;
handle->priority = params->priority;
handle->proc_id = proc_id;
handle->my_index = my_index;
handle->remote_index = remote_index;
......@@ -424,8 +461,8 @@ void *messageq_transportshm_create(u16 proc_id,
handle->my_listmp_handle = listmp_sharedmemory_create
(&(listmp_params[my_index]));
handle->attrs[my_index]->flag = MESSAGEQ_TRANSPORTSHM_UP;
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... */
otherflag = &(handle->attrs[remote_index]->flag);
......@@ -442,7 +479,7 @@ void *messageq_transportshm_create(u16 proc_id,
gt_2trace(mqtshm_debugmask, GT_4CLASS,
"messageq_transportshm_create",
MESSAGEQ_TRANSPORTSHM_E_BADVERSION,
"Notify register failed!");
"Incorrect version of remote transport!");
goto exit;
}
......@@ -496,6 +533,14 @@ int messageq_transportshm_delete(void **mqtshm_handleptr)
gt_1trace(mqtshm_debugmask, GT_ENTER, "messageq_transportshm_delete",
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);
if (WARN_ON(mqtshm_handleptr == NULL)) {
status = -EINVAL;
......@@ -575,9 +620,17 @@ int messageq_transportshm_put(void *mqtshm_handle,
gt_2trace(mqtshm_debugmask, GT_ENTER, "messageq_transportshm_put",
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(obj == NULL);
if (WARN_ON(msg == NULL)) {
status = -EINVAL;
goto exit;
......
......@@ -141,10 +141,13 @@ static inline int messageq_transportshm_ioctl_create(
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))
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 = \
messageq_transportshm_create(cargs->args.create.proc_id,
&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