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

SYSLINK Notify-Ducati Adds syslink specific atomic functions to check and set driver state.

Uses syslink atomic calls to maintain driver state in the
notify ducati driver module.
Signed-off-by: default avatarC A Subramaniam <subramaniam.ca@ti.com>
parent 75fb96e5
......@@ -164,7 +164,7 @@ struct notify_ducatidrv_params {
*/
struct notify_ducatidrv_config {
void *gate_handle;
u32 reserved;
};
/* Function to get the default configuration for the Notify module. */
......
......@@ -29,6 +29,7 @@
#include <syslink/notify_ducatidriver.h>
#include <syslink/notify_dispatcher.h>
#include <syslink/multiproc.h>
#include <syslink/atomic_linux.h>
......@@ -62,6 +63,13 @@
#define PROCAPPM3 3
#define MAX_SUBPROC_EVENTS 15
/*FIXME MOVE THIS TO A SUITABLE HEADER */
#define NOTIFYDRIVERSHM_MODULEID (u32) 0xb9d4
/* Macro to make a correct module magic number with refCount */
#define NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(x) \
((NOTIFYDRIVERSHM_MODULEID << 12u) | (x))
static void notify_ducatidrv_isr(void *ref_data);
......@@ -72,7 +80,7 @@ struct notify_ducatidrv_object {
struct notify_ducatidrv_params params;
short int proc_id;
struct notify_drv_eventlist *event_list;
struct notify_shmdrv_ctrl *ctrl_ptr;
volatile struct notify_shmdrv_ctrl *ctrl_ptr;
struct notify_shmdrv_eventreg *reg_chart;
struct notify_driver_object *drv_handle;
short int self_id;
......@@ -85,18 +93,16 @@ struct notify_ducatidrv_object {
* the module specific information.
*/
struct notify_ducatidrv_module {
atomic_t ref_count;
struct notify_ducatidrv_config cfg;
struct notify_ducatidrv_config def_cfg;
struct notify_ducatidrv_params def_inst_params;
bool is_setup;
struct mutex *gate_handle;
} ;
static struct notify_ducatidrv_module notify_ducatidriver_state = {
.is_setup = false,
.gate_handle = NULL,
.def_cfg.gate_handle = NULL,
.def_inst_params.shared_addr = 0x0,
.def_inst_params.shared_addr_size = 0x0,
.def_inst_params.num_events = NOTIFYSHMDRV_MAX_EVENTS,
......@@ -129,9 +135,17 @@ void notify_ducatidrv_getconfig(struct notify_ducatidrv_config *cfg)
{
BUG_ON(cfg == NULL);
memcpy(cfg,
&(notify_ducatidriver_state.def_cfg),
sizeof(struct notify_ducatidrv_config));
if (atomic_cmpmask_and_lt(&(notify_ducatidriver_state.ref_count),
NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(0),
NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(1))
== true)
memcpy(cfg,
&(notify_ducatidriver_state.def_cfg),
sizeof(struct notify_ducatidrv_config));
else
memcpy(cfg,
&(notify_ducatidriver_state.cfg),
sizeof(struct notify_ducatidrv_config));
}
EXPORT_SYMBOL(notify_ducatidrv_getconfig);
......@@ -189,6 +203,15 @@ void notify_ducatidrv_params_init(struct notify_driver_object *handle,
{
struct notify_ducatidrv_object *driver_obj;
BUG_ON(params == NULL);
if (atomic_cmpmask_and_lt(&(notify_ducatidriver_state.ref_count),
NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(0),
NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(1))
== true) {
/*FIXME not intialized to be returned */
BUG_ON(1);
}
if (handle == NULL) {
memcpy(params,
&(notify_ducatidriver_state.def_inst_params),
......@@ -217,7 +240,7 @@ struct notify_driver_object *notify_ducatidrv_create(char *driver_name,
struct notify_ducatidrv_object *driver_obj = NULL;
struct notify_driver_object *drv_handle = NULL;
struct notify_drv_eventlist *event_list = NULL;
struct notify_shmdrv_proc_ctrl *ctrl_ptr = NULL;
volatile struct notify_shmdrv_proc_ctrl *ctrl_ptr = NULL;
struct notify_driver_attrs drv_attrs;
struct notify_interface fxn_table;
int proc_id;
......@@ -231,7 +254,14 @@ struct notify_driver_object *notify_ducatidrv_create(char *driver_name,
BUG_ON(driver_name == NULL);
BUG_ON(params == NULL);
BUG_ON(notify_ducatidriver_state.is_setup == false);
if (atomic_cmpmask_and_lt(&(notify_ducatidriver_state.ref_count),
NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(0),
NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(1))
== true) {
goto func_end;
}
WARN_ON(mutex_lock_interruptible(notify_ducatidriver_state.
gate_handle) != 0);
......@@ -466,6 +496,14 @@ int notify_ducatidrv_delete(struct notify_driver_object **handle_ptr)
int interrupt_no;
int mbx_ret_val = 0;
if (atomic_cmpmask_and_lt(&(notify_ducatidriver_state.ref_count),
NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(0),
NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(1))
== true) {
/*FIXME not intialized to be returned */
return -1;
}
WARN_ON(handle_ptr == NULL);
if (handle_ptr == NULL)
return -1;
......@@ -546,14 +584,30 @@ EXPORT_SYMBOL(notify_ducatidrv_delete);
int notify_ducatidrv_destroy(void)
{
int status = 0;
WARN_ON(notify_ducatidriver_state.is_setup != true);
/* Check if the gate_handle was created internally. */
if (notify_ducatidriver_state.cfg.gate_handle == NULL) {
if (atomic_cmpmask_and_lt(&(notify_ducatidriver_state.ref_count),
NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(0),
NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(1))
== true)
/* FIXME Invalid state to be reuurned. */
return -1;
if (atomic_dec_return(&(notify_ducatidriver_state.ref_count)) ==
NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(0)) {
/* Check if the gate_handle was created internally. */
if (notify_ducatidriver_state.gate_handle != NULL)
kfree(notify_ducatidriver_state.gate_handle);
/* FIXME- Why do we need to reset this if we already
* decremented it to 0 */
atomic_set(&(notify_ducatidriver_state.ref_count),
NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(0));
}
notify_ducatidriver_state.is_setup = false;
return status;
}
EXPORT_SYMBOL(notify_ducatidrv_destroy);
......@@ -585,23 +639,33 @@ int notify_ducatidrv_setup(struct notify_ducatidrv_config *cfg)
cfg = &tmp_cfg;
}
if (cfg->gate_handle != NULL)
notify_ducatidriver_state.gate_handle = cfg->gate_handle;
else {
notify_ducatidriver_state.gate_handle =
kmalloc(sizeof(struct mutex), GFP_KERNEL);
mutex_init(notify_ducatidriver_state.gate_handle);
/* Init the ref_count to 0 */
atomic_cmpmask_and_set(&(notify_ducatidriver_state.ref_count),
NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(0),
NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(0));
if (atomic_inc_return(&(notify_ducatidriver_state.ref_count)) !=
NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(1u)) {
/* FIXME Already exists status to be returned. */
return -1;
}
/* Create a default gate handle here */
notify_ducatidriver_state.gate_handle =
kmalloc(sizeof(struct mutex), GFP_KERNEL);
mutex_init(notify_ducatidriver_state.gate_handle);
if (notify_ducatidriver_state.gate_handle == NULL) {
atomic_set(&(notify_ducatidriver_state.ref_count),
NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(0));
status = -ENOMEM;
} else {
memcpy(&notify_ducatidriver_state.cfg,
cfg, sizeof(struct notify_ducatidrv_config));
notify_ducatidriver_state.is_setup = true;
}
return status;
}
EXPORT_SYMBOL(notify_ducatidrv_setup);
......@@ -625,8 +689,8 @@ int notify_ducatidrv_register_event(
struct notify_drv_eventlist *event_list;
struct notify_ducatidrv_object *driver_object;
struct notify_shmdrv_eventreg *reg_chart;
struct notify_shmdrv_ctrl *ctrl_ptr;
struct notify_shmdrv_event_entry *self_event_chart;
volatile struct notify_shmdrv_ctrl *ctrl_ptr;
volatile struct notify_shmdrv_event_entry *self_event_chart;
int i;
int j;
BUG_ON(handle == NULL);
......@@ -741,9 +805,9 @@ int notify_ducatidrv_unregister_event(
struct notify_ducatidrv_object *driver_object;
struct notify_drv_eventlist *event_list;
struct notify_shmdrv_eventreg *reg_chart;
struct notify_shmdrv_ctrl *ctrl_ptr = NULL;
volatile struct notify_shmdrv_ctrl *ctrl_ptr = NULL;
struct notify_drv_eventlistner unreg_info;
struct notify_shmdrv_event_entry *self_event_chart;
volatile struct notify_shmdrv_event_entry *self_event_chart;
int i;
int j;
......@@ -830,9 +894,9 @@ int notify_ducatidrv_sendevent(struct notify_driver_object *handle,
{
int status = 0;
struct notify_ducatidrv_object *driver_object;
struct notify_shmdrv_ctrl *ctrl_ptr;
volatile struct notify_shmdrv_ctrl *ctrl_ptr;
int max_poll_count;
struct notify_shmdrv_event_entry *other_event_chart;
volatile struct notify_shmdrv_event_entry *other_event_chart;
struct mbox_config *mbox_hw_config;
int mbox_module_no;
int mbx_ret_val = 0;
......@@ -1042,10 +1106,10 @@ static void notify_ducatidrv_isr(void *ref_data)
int i = 0;
struct list_head *temp;
int j = 0;
struct notify_shmdrv_event_entry *self_event_chart;
volatile struct notify_shmdrv_event_entry *self_event_chart;
struct notify_ducatidrv_object *driver_obj;
struct notify_shmdrv_eventreg *reg_chart;
struct notify_shmdrv_proc_ctrl *proc_ctrl_ptr;
volatile struct notify_shmdrv_proc_ctrl *proc_ctrl_ptr;
struct mbox_config *mbox_hw_config = ntfy_disp_get_config();
unsigned long int mbox_module_no = mbox_hw_config->mbox_modules;
int event_no;
......
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