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