Commit f4502e35 authored by Subramaniam C.A's avatar Subramaniam C.A Committed by Hari Kanigeri

SYSLINK Notify IPC migrations to include syslink specific atomic calls

This patch uses syslink atomic calls to check and set
states of the notify driver module
Signed-off-by: default avatarC A Subramaniam <subramaniam.ca@ti.com>
parent b3a91b47
......@@ -108,7 +108,7 @@
/*
* The module has not been setup.
*/
#define NOTIFY_E_SETUP NOTIFY_MAKE_FAILURE(13)
#define NOTIFY_E_INVALIDSTATE NOTIFY_MAKE_FAILURE(13)
/*
* Maximum number of supported drivers have already been registered.
......@@ -184,6 +184,11 @@
*/
#define NOTIFY_MAXNESTDEPTH 2
/* brief Macro to make a correct module magic number with refCount */
#define NOTIFY_MAKE_MAGICSTAMP(x) ((NOTIFY_MODULEID << 12u) | (x))
/*
* const NOTIFYSHMDRV_DRIVERNAME
*
......@@ -213,8 +218,6 @@
struct notify_config {
u32 maxDrivers;
/* Maximum number of drivers that can be created for Notify at a time */
struct mutex *gate_handle;
/* Handle of gate to be used for local thread safety */
};
typedef void (*notify_callback_fxn)(u16 proc_id, u32 eventNo, void *arg,
......
......@@ -79,10 +79,15 @@
*/
#define CMD_NOTIFY_ENABLEEVENT (NOTIFY_BASE_CMD + 10u)
/*
* Command for Notify_exit
/*!
* @brief Command for Notify_attach
*/
#define CMD_NOTIFY_ATTACH (NOTIFY_BASE_CMD + 11u)
/*!
* @brief Command for Notify_detach
*/
#define CMD_NOTIFY_EXIT (NOTIFY_BASE_CMD + 11u)
#define CMD_NOTIFY_DETACH (NOTIFY_BASE_CMD + 12u)
/*
* const NOTIFY_SYSTEM_KEY_MASK
......@@ -140,6 +145,7 @@ struct notify_cmd_args_register_event {
u32 eventNo;
notify_callback_fxn fnNotifyCbck;
void *cbckArg;
u32 pid;
};
/*
......@@ -152,6 +158,7 @@ struct notify_cmd_args_unregister_event {
u32 eventNo;
notify_callback_fxn fnNotifyCbck;
void *cbckArg;
u32 pid;
};
/*
......@@ -417,6 +424,7 @@ struct notify_drv_proc_module {
* specific information.
*/
struct notify_module_object {
atomic_t ref_count;
struct notify_config cfg;
/* Notify configuration structure */
struct notify_config def_cfg;
......@@ -427,8 +435,6 @@ struct notify_module_object {
/* Array of configured drivers. */
u32 disable_depth;
/* Current disable depth for Notify module. */
bool is_setup;
/* Indicates whether the Notify module is setup. */
};
#endif /* !defined (NOTIFYDRIVERDEFS_H) */
......@@ -27,6 +27,7 @@
#include <syslink/GlobalTypes.h>
#include <syslink/gt.h>
#include <syslink/multiproc.h>
#include <syslink/atomic_linux.h>
/*
* func _notify_is_support_proc
......@@ -38,8 +39,6 @@ static bool _notify_is_support_proc(struct notify_driver_object *drv_handle,
int proc_id);
struct notify_module_object notify_state = {
.is_setup = false,
.def_cfg.gate_handle = NULL,
.def_cfg.maxDrivers = 2,
};
EXPORT_SYMBOL(notify_state);
......@@ -61,7 +60,9 @@ void notify_get_config(struct notify_config *cfg)
{
BUG_ON(cfg == NULL);
if (notify_state.is_setup == false)
if (atomic_cmpmask_and_lt(&(notify_state.ref_count),
NOTIFY_MAKE_MAGICSTAMP(0),
NOTIFY_MAKE_MAGICSTAMP(1)) == false)
memcpy(cfg, &notify_state.def_cfg,
sizeof(struct notify_config));
else
......@@ -92,29 +93,40 @@ int notify_setup(struct notify_config *cfg)
int status = NOTIFY_SUCCESS;
struct notify_config tmpCfg;
atomic_cmpmask_and_set(&notify_state.ref_count,
NOTIFY_MAKE_MAGICSTAMP(0),
NOTIFY_MAKE_MAGICSTAMP(0));
if (atomic_inc_return(&notify_state.ref_count)
!= NOTIFY_MAKE_MAGICSTAMP(1u)) {
status = NOTIFY_S_ALREADYSETUP;
} else {
if (cfg == NULL) {
notify_get_config(&tmpCfg);
cfg = &tmpCfg;
}
if (cfg->gate_handle != NULL) {
notify_state.gate_handle = cfg->gate_handle;
} else {
notify_state.gate_handle = kmalloc(sizeof(struct mutex),
GFP_ATOMIC);
/*User has not provided any gate handle,
so create a default handle.*/
mutex_init(notify_state.gate_handle);
}
if (WARN_ON(cfg->maxDrivers > NOTIFY_MAX_DRIVERS)) {
status = NOTIFY_E_CONFIG;
kfree(notify_state.gate_handle);
atomic_set(&notify_state.ref_count,
NOTIFY_MAKE_MAGICSTAMP(0));
goto func_end;
}
memcpy(&notify_state.cfg, cfg, sizeof(struct notify_config));
memset(&notify_state.drivers, 0,
(sizeof(struct notify_driver_object) * NOTIFY_MAX_DRIVERS));
(sizeof(struct notify_driver_object) *
NOTIFY_MAX_DRIVERS));
notify_state.disable_depth = 0;
notify_state.is_setup = true;
}
func_end:
return status;
}
......@@ -130,19 +142,31 @@ EXPORT_SYMBOL(notify_setup);
int notify_destroy(void)
{
int i;
int status = NOTIFY_SUCCESS;
/* Check if any Notify driver instances have not been deleted so far.
* If not, assert.
if (atomic_cmpmask_and_lt(&(notify_state.ref_count),
NOTIFY_MAKE_MAGICSTAMP(0),
NOTIFY_MAKE_MAGICSTAMP(1)) == true) {
status = NOTIFY_E_INVALIDSTATE;
} else {
if (atomic_dec_return(&(notify_state.ref_count)) ==
NOTIFY_MAKE_MAGICSTAMP(0)) {
/* Check if any Notify driver instances have
* not been deleted so far. If not, assert.
*/
for (i = 0; i < NOTIFY_MAX_DRIVERS; i++)
WARN_ON(notify_state.drivers[i].is_init != false);
WARN_ON(notify_state.drivers[i].is_init
!= false);
if (notify_state.cfg.gate_handle == NULL) {
if (notify_state.gate_handle != NULL)
kfree(notify_state.gate_handle);
atomic_set(&notify_state.ref_count,
NOTIFY_MAKE_MAGICSTAMP(0));
}
notify_state.is_setup = false;
return NOTIFY_SUCCESS;
}
return status;
}
EXPORT_SYMBOL(notify_destroy);
......@@ -161,8 +185,15 @@ int notify_register_event(void *notify_driver_handle, u16 proc_id,
(struct notify_driver_object *)notify_driver_handle;
BUG_ON(drv_handle == NULL);
if (atomic_cmpmask_and_lt(&(notify_state.ref_count),
NOTIFY_MAKE_MAGICSTAMP(0),
NOTIFY_MAKE_MAGICSTAMP(1)) == true) {
status = NOTIFY_E_INVALIDSTATE;
goto func_end;
}
if (WARN_ON(drv_handle->is_init == false)) {
status = NOTIFY_E_SETUP;
status = NOTIFY_E_INVALIDSTATE;
goto func_end;
}
if (WARN_ON(_notify_is_support_proc(drv_handle, proc_id) != true)) {
......@@ -211,8 +242,15 @@ int notify_unregister_event(void *notify_driver_handle, u16 proc_id,
struct notify_driver_object *drv_handle =
(struct notify_driver_object *)notify_driver_handle;
BUG_ON(drv_handle == NULL);
if (atomic_cmpmask_and_lt(&(notify_state.ref_count),
NOTIFY_MAKE_MAGICSTAMP(0),
NOTIFY_MAKE_MAGICSTAMP(1)) == true) {
status = NOTIFY_E_INVALIDSTATE;
goto func_end;
}
if (WARN_ON(drv_handle->is_init == false)) {
status = NOTIFY_E_SETUP;
status = NOTIFY_E_INVALIDSTATE;
goto func_end;
}
if (WARN_ON(_notify_is_support_proc(drv_handle, proc_id) != true)) {
......@@ -261,8 +299,15 @@ int notify_sendevent(void *notify_driver_handle, u16 proc_id,
struct notify_driver_object *drv_handle =
(struct notify_driver_object *)notify_driver_handle;
BUG_ON(drv_handle == NULL);
if (atomic_cmpmask_and_lt(&(notify_state.ref_count),
NOTIFY_MAKE_MAGICSTAMP(0),
NOTIFY_MAKE_MAGICSTAMP(1)) == true) {
status = NOTIFY_E_INVALIDSTATE;
goto func_end;
}
if (WARN_ON(drv_handle->is_init == false)) {
status = NOTIFY_E_SETUP;
status = NOTIFY_E_INVALIDSTATE;
goto func_end;
}
if (WARN_ON(_notify_is_support_proc(drv_handle, proc_id) != true)) {
......@@ -311,10 +356,15 @@ u32 notify_disable(u16 proc_id)
struct notify_driver_object *drv_handle;
int i;
BUG_ON(notify_state.is_setup != true);
if (atomic_cmpmask_and_lt(&(notify_state.ref_count),
NOTIFY_MAKE_MAGICSTAMP(0),
NOTIFY_MAKE_MAGICSTAMP(1)) == true)
WARN_ON(1);
if (mutex_lock_interruptible(notify_state.gate_handle) != 0)
WARN_ON(1);
for (i = 0; i < notify_state.cfg.maxDrivers; i++) {
drv_handle = &(notify_state.drivers[i]);
WARN_ON(_notify_is_support_proc(drv_handle, proc_id)
......@@ -354,7 +404,11 @@ void notify_restore(u32 key, u16 proc_id)
struct notify_driver_object *drv_handle;
int i;
BUG_ON(notify_state.is_setup != true);
if (atomic_cmpmask_and_lt(&(notify_state.ref_count),
NOTIFY_MAKE_MAGICSTAMP(0),
NOTIFY_MAKE_MAGICSTAMP(1)) == true)
WARN_ON(1);
if (mutex_lock_interruptible(notify_state.gate_handle) != 0)
WARN_ON(1);
notify_state.disable_depth--;
......@@ -384,8 +438,16 @@ void notify_disable_event(void *notify_driver_handle, u16 proc_id, u32 event_no)
struct notify_driver_object *drv_handle =
(struct notify_driver_object *)notify_driver_handle;
BUG_ON(drv_handle == NULL);
if (atomic_cmpmask_and_lt(&(notify_state.ref_count),
NOTIFY_MAKE_MAGICSTAMP(0),
NOTIFY_MAKE_MAGICSTAMP(1)) == true) {
status = NOTIFY_E_INVALIDSTATE;
goto func_end;
}
if (WARN_ON(drv_handle->is_init == false)) {
status = NOTIFY_E_SETUP;
status = NOTIFY_E_INVALIDSTATE;
goto func_end;
}
if (WARN_ON(_notify_is_support_proc(drv_handle, proc_id) != true)) {
......@@ -429,6 +491,13 @@ void notify_enable_event(void *notify_driver_handle, u16 proc_id, u32 event_no)
(struct notify_driver_object *) notify_driver_handle;
BUG_ON(drv_handle == NULL);
if (atomic_cmpmask_and_lt(&(notify_state.ref_count),
NOTIFY_MAKE_MAGICSTAMP(0),
NOTIFY_MAKE_MAGICSTAMP(1)) == true) {
goto func_end;
}
if (WARN_ON(drv_handle->is_init == false))
goto func_end;
if (WARN_ON(_notify_is_support_proc(drv_handle, proc_id) != true))
......
......@@ -27,6 +27,7 @@
#include <syslink/notify.h>
#include <syslink/notify_driver.h>
#include <syslink/atomic_linux.h>
/*
*func notify_register_driver
......@@ -43,12 +44,18 @@ int notify_register_driver(char *driver_name,
struct notify_driver_object *drv_handle = NULL;
int i;
BUG_ON(notify_state.is_setup == false);
BUG_ON(driver_name == NULL);
BUG_ON(fn_table == NULL);
BUG_ON(drv_attrs == NULL);
BUG_ON(driver_handle == NULL);
if (atomic_cmpmask_and_lt(&(notify_state.ref_count),
NOTIFY_MAKE_MAGICSTAMP(0),
NOTIFY_MAKE_MAGICSTAMP(1)) == true) {
status = NOTIFY_E_INVALIDSTATE;
goto func_end;
}
/*Initialize to status that indicates that an empty slot was not
*found for the driver.
*/
......@@ -85,6 +92,8 @@ int notify_register_driver(char *driver_name,
drv_handle->driver_object = NULL;
/*is_setup is set when driverInit is called. */
*driver_handle = drv_handle;
func_end:
return status;
}
EXPORT_SYMBOL(notify_register_driver);
......@@ -100,8 +109,11 @@ int notify_unregister_driver(struct notify_driver_object *drv_handle)
BUG_ON(drv_handle == NULL);
if (WARN_ON(notify_state.is_setup == false)) {
status = NOTIFY_E_SETUP;
if (atomic_cmpmask_and_lt(&(notify_state.ref_count),
NOTIFY_MAKE_MAGICSTAMP(0),
NOTIFY_MAKE_MAGICSTAMP(1)) == true) {
status = NOTIFY_E_INVALIDSTATE;
} else {
/* Unregister the driver. */
drv_handle->is_init = NOTIFY_DRIVERINITSTATUS_NOTDONE;
......@@ -129,8 +141,10 @@ int notify_get_driver_handle(char *driver_name,
BUG_ON(handle == NULL);
if (WARN_ON(notify_state.is_setup == false)) {
status = NOTIFY_E_SETUP;
if (atomic_cmpmask_and_lt(&(notify_state.ref_count),
NOTIFY_MAKE_MAGICSTAMP(0),
NOTIFY_MAKE_MAGICSTAMP(1)) == true) {
status = NOTIFY_E_INVALIDSTATE;
} else if (WARN_ON(driver_name == NULL))
status = NOTIFY_E_INVALIDARG;
else {
......
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