Commit 22d408d1 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 64d169e8
...@@ -164,7 +164,7 @@ struct notify_ducatidrv_params { ...@@ -164,7 +164,7 @@ struct notify_ducatidrv_params {
*/ */
struct notify_ducatidrv_config { struct notify_ducatidrv_config {
void *gate_handle; u32 reserved;
}; };
/* Function to get the default configuration for the Notify module. */ /* Function to get the default configuration for the Notify module. */
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <syslink/notify_ducatidriver.h> #include <syslink/notify_ducatidriver.h>
#include <syslink/notify_dispatcher.h> #include <syslink/notify_dispatcher.h>
#include <syslink/multiproc.h> #include <syslink/multiproc.h>
#include <syslink/atomic_linux.h>
...@@ -62,6 +63,13 @@ ...@@ -62,6 +63,13 @@
#define PROCAPPM3 3 #define PROCAPPM3 3
#define MAX_SUBPROC_EVENTS 15 #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); static void notify_ducatidrv_isr(void *ref_data);
...@@ -72,7 +80,7 @@ struct notify_ducatidrv_object { ...@@ -72,7 +80,7 @@ struct notify_ducatidrv_object {
struct notify_ducatidrv_params params; struct notify_ducatidrv_params params;
short int proc_id; short int proc_id;
struct notify_drv_eventlist *event_list; 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_shmdrv_eventreg *reg_chart;
struct notify_driver_object *drv_handle; struct notify_driver_object *drv_handle;
short int self_id; short int self_id;
...@@ -85,18 +93,16 @@ struct notify_ducatidrv_object { ...@@ -85,18 +93,16 @@ struct notify_ducatidrv_object {
* the module specific information. * the module specific information.
*/ */
struct notify_ducatidrv_module { struct notify_ducatidrv_module {
atomic_t ref_count;
struct notify_ducatidrv_config cfg; struct notify_ducatidrv_config cfg;
struct notify_ducatidrv_config def_cfg; struct notify_ducatidrv_config def_cfg;
struct notify_ducatidrv_params def_inst_params; struct notify_ducatidrv_params def_inst_params;
bool is_setup;
struct mutex *gate_handle; struct mutex *gate_handle;
} ; } ;
static struct notify_ducatidrv_module notify_ducatidriver_state = { static struct notify_ducatidrv_module notify_ducatidriver_state = {
.is_setup = false,
.gate_handle = NULL, .gate_handle = NULL,
.def_cfg.gate_handle = 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,
.def_inst_params.num_events = NOTIFYSHMDRV_MAX_EVENTS, .def_inst_params.num_events = NOTIFYSHMDRV_MAX_EVENTS,
...@@ -129,9 +135,17 @@ void notify_ducatidrv_getconfig(struct notify_ducatidrv_config *cfg) ...@@ -129,9 +135,17 @@ void notify_ducatidrv_getconfig(struct notify_ducatidrv_config *cfg)
{ {
BUG_ON(cfg == NULL); BUG_ON(cfg == NULL);
memcpy(cfg, if (atomic_cmpmask_and_lt(&(notify_ducatidriver_state.ref_count),
&(notify_ducatidriver_state.def_cfg), NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(0),
sizeof(struct notify_ducatidrv_config)); 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); EXPORT_SYMBOL(notify_ducatidrv_getconfig);
...@@ -189,6 +203,15 @@ void notify_ducatidrv_params_init(struct notify_driver_object *handle, ...@@ -189,6 +203,15 @@ void notify_ducatidrv_params_init(struct notify_driver_object *handle,
{ {
struct notify_ducatidrv_object *driver_obj; struct notify_ducatidrv_object *driver_obj;
BUG_ON(params == NULL); 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) { if (handle == NULL) {
memcpy(params, memcpy(params,
&(notify_ducatidriver_state.def_inst_params), &(notify_ducatidriver_state.def_inst_params),
...@@ -217,7 +240,7 @@ struct notify_driver_object *notify_ducatidrv_create(char *driver_name, ...@@ -217,7 +240,7 @@ struct notify_driver_object *notify_ducatidrv_create(char *driver_name,
struct notify_ducatidrv_object *driver_obj = NULL; struct notify_ducatidrv_object *driver_obj = NULL;
struct notify_driver_object *drv_handle = NULL; struct notify_driver_object *drv_handle = NULL;
struct notify_drv_eventlist *event_list = 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_driver_attrs drv_attrs;
struct notify_interface fxn_table; struct notify_interface fxn_table;
int proc_id; int proc_id;
...@@ -231,7 +254,14 @@ struct notify_driver_object *notify_ducatidrv_create(char *driver_name, ...@@ -231,7 +254,14 @@ struct notify_driver_object *notify_ducatidrv_create(char *driver_name,
BUG_ON(driver_name == NULL); BUG_ON(driver_name == NULL);
BUG_ON(params == 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. WARN_ON(mutex_lock_interruptible(notify_ducatidriver_state.
gate_handle) != 0); gate_handle) != 0);
...@@ -466,6 +496,14 @@ int notify_ducatidrv_delete(struct notify_driver_object **handle_ptr) ...@@ -466,6 +496,14 @@ int notify_ducatidrv_delete(struct notify_driver_object **handle_ptr)
int interrupt_no; int interrupt_no;
int mbx_ret_val = 0; 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); WARN_ON(handle_ptr == NULL);
if (handle_ptr == NULL) if (handle_ptr == NULL)
return -1; return -1;
...@@ -546,14 +584,30 @@ EXPORT_SYMBOL(notify_ducatidrv_delete); ...@@ -546,14 +584,30 @@ EXPORT_SYMBOL(notify_ducatidrv_delete);
int notify_ducatidrv_destroy(void) int notify_ducatidrv_destroy(void)
{ {
int status = 0; int status = 0;
WARN_ON(notify_ducatidriver_state.is_setup != true);
/* Check if the gate_handle was created internally. */ if (atomic_cmpmask_and_lt(&(notify_ducatidriver_state.ref_count),
if (notify_ducatidriver_state.cfg.gate_handle == NULL) { 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) if (notify_ducatidriver_state.gate_handle != NULL)
kfree(notify_ducatidriver_state.gate_handle); 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; return status;
} }
EXPORT_SYMBOL(notify_ducatidrv_destroy); EXPORT_SYMBOL(notify_ducatidrv_destroy);
...@@ -585,23 +639,33 @@ int notify_ducatidrv_setup(struct notify_ducatidrv_config *cfg) ...@@ -585,23 +639,33 @@ int notify_ducatidrv_setup(struct notify_ducatidrv_config *cfg)
cfg = &tmp_cfg; cfg = &tmp_cfg;
} }
if (cfg->gate_handle != NULL) /* Init the ref_count to 0 */
notify_ducatidriver_state.gate_handle = cfg->gate_handle; atomic_cmpmask_and_set(&(notify_ducatidriver_state.ref_count),
else { NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(0),
notify_ducatidriver_state.gate_handle = NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(0));
kmalloc(sizeof(struct mutex), GFP_KERNEL);
mutex_init(notify_ducatidriver_state.gate_handle); 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) { if (notify_ducatidriver_state.gate_handle == NULL) {
atomic_set(&(notify_ducatidriver_state.ref_count),
NOTIFYDRIVERSHM_MAKE_MAGICSTAMP(0));
status = -ENOMEM; status = -ENOMEM;
} else { } else {
memcpy(&notify_ducatidriver_state.cfg, memcpy(&notify_ducatidriver_state.cfg,
cfg, sizeof(struct notify_ducatidrv_config)); cfg, sizeof(struct notify_ducatidrv_config));
notify_ducatidriver_state.is_setup = true;
} }
return status; return status;
} }
EXPORT_SYMBOL(notify_ducatidrv_setup); EXPORT_SYMBOL(notify_ducatidrv_setup);
...@@ -625,8 +689,8 @@ int notify_ducatidrv_register_event( ...@@ -625,8 +689,8 @@ int notify_ducatidrv_register_event(
struct notify_drv_eventlist *event_list; struct notify_drv_eventlist *event_list;
struct notify_ducatidrv_object *driver_object; struct notify_ducatidrv_object *driver_object;
struct notify_shmdrv_eventreg *reg_chart; struct notify_shmdrv_eventreg *reg_chart;
struct notify_shmdrv_ctrl *ctrl_ptr; volatile struct notify_shmdrv_ctrl *ctrl_ptr;
struct notify_shmdrv_event_entry *self_event_chart; volatile struct notify_shmdrv_event_entry *self_event_chart;
int i; int i;
int j; int j;
BUG_ON(handle == NULL); BUG_ON(handle == NULL);
...@@ -741,9 +805,9 @@ int notify_ducatidrv_unregister_event( ...@@ -741,9 +805,9 @@ int notify_ducatidrv_unregister_event(
struct notify_ducatidrv_object *driver_object; struct notify_ducatidrv_object *driver_object;
struct notify_drv_eventlist *event_list; struct notify_drv_eventlist *event_list;
struct notify_shmdrv_eventreg *reg_chart; 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_drv_eventlistner unreg_info;
struct notify_shmdrv_event_entry *self_event_chart; volatile struct notify_shmdrv_event_entry *self_event_chart;
int i; int i;
int j; int j;
...@@ -830,9 +894,9 @@ int notify_ducatidrv_sendevent(struct notify_driver_object *handle, ...@@ -830,9 +894,9 @@ int notify_ducatidrv_sendevent(struct notify_driver_object *handle,
{ {
int status = 0; int status = 0;
struct notify_ducatidrv_object *driver_object; struct notify_ducatidrv_object *driver_object;
struct notify_shmdrv_ctrl *ctrl_ptr; volatile struct notify_shmdrv_ctrl *ctrl_ptr;
int max_poll_count; 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; struct mbox_config *mbox_hw_config;
int mbox_module_no; int mbox_module_no;
int mbx_ret_val = 0; int mbx_ret_val = 0;
...@@ -1042,10 +1106,10 @@ static void notify_ducatidrv_isr(void *ref_data) ...@@ -1042,10 +1106,10 @@ static void notify_ducatidrv_isr(void *ref_data)
int i = 0; int i = 0;
struct list_head *temp; struct list_head *temp;
int j = 0; 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_ducatidrv_object *driver_obj;
struct notify_shmdrv_eventreg *reg_chart; 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(); struct mbox_config *mbox_hw_config = ntfy_disp_get_config();
unsigned long int mbox_module_no = mbox_hw_config->mbox_modules; unsigned long int mbox_module_no = mbox_hw_config->mbox_modules;
int event_no; 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