2010-07-28 21:00:22

by Ernesto Ramos

[permalink] [raw]
Subject: [PATCH 0/5] use idr kernel library instead of handles

From: Rene Sapiens <[email protected]>

Use idr kernel library to send/receive node and stream ids to the
user instead of kernel address.
This id will be use to access the node and stream handles at the
kernel side, if id does not match to any handle
error -EFAULT is returned.

For processor handle, dspbridge driver will make sure
the handle is valid by using the handle stored in process context.

Ernesto Ramos (5):
staging:ti dspbridge: use node id instead of kernel address
staging:ti dspbridge: avoid errors if node handle is zero
staging:ti dspbridge: use processor handle from context instead of
user's
staging:ti dspbridge: use stream id instead of kernel address
staging:ti dspbridge: avoid errors if stream id is zero

.../staging/tidspbridge/include/dspbridge/drv.h | 11 +-
.../staging/tidspbridge/include/dspbridge/node.h | 14 +-
.../include/dspbridge/resourcecleanup.h | 12 -
.../staging/tidspbridge/include/dspbridge/strm.h | 22 +-
drivers/staging/tidspbridge/pmgr/dspapi.c | 329 ++++++++++++++++----
drivers/staging/tidspbridge/rmgr/drv.c | 303 ++++++-------------
drivers/staging/tidspbridge/rmgr/drv_interface.c | 18 +-
drivers/staging/tidspbridge/rmgr/node.c | 109 ++++---
drivers/staging/tidspbridge/rmgr/strm.c | 54 ++--
9 files changed, 485 insertions(+), 387 deletions(-)


2010-07-28 21:00:29

by Ernesto Ramos

[permalink] [raw]
Subject: [PATCH] staging:ti dspbridge: avoid errors if node handle is zero

As 'zero' can be a perfectly good id, it can be picked up as
a NULL from userspace, avoid issues in API and user apps if node
handle is zero.

Signed-off-by: Ernesto Ramos <[email protected]>
---
drivers/staging/tidspbridge/pmgr/dspapi.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/tidspbridge/pmgr/dspapi.c b/drivers/staging/tidspbridge/pmgr/dspapi.c
index 6eda7c5..f46aaf6 100644
--- a/drivers/staging/tidspbridge/pmgr/dspapi.c
+++ b/drivers/staging/tidspbridge/pmgr/dspapi.c
@@ -1059,7 +1059,7 @@ inline void find_node_handle(struct node_res_object **noderes,
{
rcu_read_lock();
*noderes = idr_find(((struct process_context *)pr_ctxt)->node_id,
- (int)hnode);
+ (int)hnode - 1);
rcu_read_unlock();
return;
}
@@ -1077,6 +1077,7 @@ u32 nodewrap_allocate(union trapped_args *args, void *pr_ctxt)
u8 *pargs = NULL;
struct dsp_nodeattrin proc_attr_in, *attr_in = NULL;
struct node_res_object *node_res;
+ int nodeid;

/* Optional argument */
if (psize) {
@@ -1112,7 +1113,8 @@ u32 nodewrap_allocate(union trapped_args *args, void *pr_ctxt)
attr_in, &node_res, pr_ctxt);
}
if (!status) {
- CP_TO_USR(args->args_node_allocate.ph_node, &node_res->id,
+ nodeid = node_res->id + 1;
+ CP_TO_USR(args->args_node_allocate.ph_node, &nodeid,
status, 1);
if (status) {
status = -EFAULT;
--
1.5.4.5

2010-07-28 21:00:48

by Ernesto Ramos

[permalink] [raw]
Subject: [PATCH] staging:ti dspbridge: use stream id instead of kernel address

Send stream ids to the user instead of handles, then when
the id is coming from user dspbridge can retrive the handle
using id and avoid using invalid handles.

Signed-off-by: Ernesto Ramos <[email protected]>
---
.../staging/tidspbridge/include/dspbridge/drv.h | 5 +-
.../include/dspbridge/resourcecleanup.h | 6 -
.../staging/tidspbridge/include/dspbridge/strm.h | 22 ++--
drivers/staging/tidspbridge/pmgr/dspapi.c | 115 +++++++++++++---
drivers/staging/tidspbridge/rmgr/drv.c | 148 +++++++-------------
drivers/staging/tidspbridge/rmgr/drv_interface.c | 13 ++-
drivers/staging/tidspbridge/rmgr/strm.c | 54 +++----
7 files changed, 193 insertions(+), 170 deletions(-)

diff --git a/drivers/staging/tidspbridge/include/dspbridge/drv.h b/drivers/staging/tidspbridge/include/dspbridge/drv.h
index 0b36a11..f365015 100644
--- a/drivers/staging/tidspbridge/include/dspbridge/drv.h
+++ b/drivers/staging/tidspbridge/include/dspbridge/drv.h
@@ -131,7 +131,7 @@ struct strm_res_object {
void *hstream;
u32 num_bufs;
u32 dir;
- struct strm_res_object *next;
+ int id;
};

/* Overall Bridge process resource usage state */
@@ -173,8 +173,7 @@ struct process_context {
struct dspheap_res_object *pdspheap_list;

/* Stream resources */
- struct strm_res_object *pstrm_list;
- struct mutex strm_mutex;
+ struct idr *stream_id;
};

/*
diff --git a/drivers/staging/tidspbridge/include/dspbridge/resourcecleanup.h b/drivers/staging/tidspbridge/include/dspbridge/resourcecleanup.h
index d17c7fb..dfaf0c6 100644
--- a/drivers/staging/tidspbridge/include/dspbridge/resourcecleanup.h
+++ b/drivers/staging/tidspbridge/include/dspbridge/resourcecleanup.h
@@ -47,12 +47,6 @@ extern int drv_proc_insert_strm_res_element(void *stream_obj,
void *strm_res,
void *process_ctxt);

-extern int drv_get_strm_res_element(void *stream_obj, void *strm_resources,
- void *process_ctxt);
-
-extern int drv_proc_remove_strm_res_element(void *strm_res,
- void *process_ctxt);
-
extern int drv_remove_all_strm_res_elements(void *process_ctxt);

extern enum node_state node_get_state(void *hnode);
diff --git a/drivers/staging/tidspbridge/include/dspbridge/strm.h b/drivers/staging/tidspbridge/include/dspbridge/strm.h
index 0ddc797..3e4671e 100644
--- a/drivers/staging/tidspbridge/include/dspbridge/strm.h
+++ b/drivers/staging/tidspbridge/include/dspbridge/strm.h
@@ -29,7 +29,7 @@
* Purpose:
* Allocate data buffer(s) for use with a stream.
* Parameter:
- * stream_obj: Stream handle returned from strm_open().
+ * strmres: Stream resource info handle returned from strm_open().
* usize: Size (GPP bytes) of the buffer(s).
* num_bufs: Number of buffers to allocate.
* ap_buffer: Array to hold buffer addresses.
@@ -44,7 +44,7 @@
* ap_buffer != NULL.
* Ensures:
*/
-extern int strm_allocate_buffer(struct strm_object *stream_obj,
+extern int strm_allocate_buffer(struct strm_res_object *strmres,
u32 usize,
u8 **ap_buffer,
u32 num_bufs,
@@ -55,7 +55,7 @@ extern int strm_allocate_buffer(struct strm_object *stream_obj,
* Purpose:
* Close a stream opened with strm_open().
* Parameter:
- * stream_obj: Stream handle returned from strm_open().
+ * strmres: Stream resource info handle returned from strm_open().
* Returns:
* 0: Success.
* -EFAULT: Invalid stream_obj.
@@ -66,7 +66,7 @@ extern int strm_allocate_buffer(struct strm_object *stream_obj,
* strm_init(void) called.
* Ensures:
*/
-extern int strm_close(struct strm_object *stream_obj,
+extern int strm_close(struct strm_res_object *strmres,
struct process_context *pr_ctxt);

/*
@@ -125,7 +125,7 @@ extern void strm_exit(void);
* Purpose:
* Free buffer(s) allocated with strm_allocate_buffer.
* Parameter:
- * stream_obj: Stream handle returned from strm_open().
+ * strmres: Stream resource info handle returned from strm_open().
* ap_buffer: Array containing buffer addresses.
* num_bufs: Number of buffers to be freed.
* Returns:
@@ -137,7 +137,7 @@ extern void strm_exit(void);
* ap_buffer != NULL.
* Ensures:
*/
-extern int strm_free_buffer(struct strm_object *stream_obj,
+extern int strm_free_buffer(struct strm_res_object *strmres,
u8 **ap_buffer, u32 num_bufs,
struct process_context *pr_ctxt);

@@ -254,7 +254,7 @@ extern int strm_issue(struct strm_object *stream_obj, u8 * pbuf,
* index: Stream index.
* pattr: Pointer to structure containing attributes to be
* applied to stream. Cannot be NULL.
- * strm_objct: Location to store stream handle on output.
+ * strmres: Location to store stream resuorce info handle on output.
* Returns:
* 0: Success.
* -EFAULT: Invalid hnode.
@@ -264,15 +264,15 @@ extern int strm_issue(struct strm_object *stream_obj, u8 * pbuf,
* -EINVAL: Invalid index.
* Requires:
* strm_init(void) called.
- * strm_objct != NULL.
+ * strmres != NULL.
* pattr != NULL.
* Ensures:
- * 0: *strm_objct is valid.
- * error: *strm_objct == NULL.
+ * 0: *strmres is valid.
+ * error: *strmres == NULL.
*/
extern int strm_open(struct node_object *hnode, u32 dir,
u32 index, struct strm_attr *pattr,
- struct strm_object **strm_objct,
+ struct strm_res_object **strmres,
struct process_context *pr_ctxt);

/*
diff --git a/drivers/staging/tidspbridge/pmgr/dspapi.c b/drivers/staging/tidspbridge/pmgr/dspapi.c
index d7613eb..47892dd 100644
--- a/drivers/staging/tidspbridge/pmgr/dspapi.c
+++ b/drivers/staging/tidspbridge/pmgr/dspapi.c
@@ -1520,6 +1520,19 @@ func_cont:
}

/*
+ * ======== find_strm_handle =========
+ */
+inline void find_strm_handle(struct strm_res_object **strmres,
+ void *pr_ctxt, void *hstream)
+{
+ rcu_read_lock();
+ *strmres = idr_find(((struct process_context *)pr_ctxt)->stream_id,
+ (int)hstream);
+ rcu_read_unlock();
+ return;
+}
+
+/*
* ======== strmwrap_allocate_buffer ========
*/
u32 strmwrap_allocate_buffer(union trapped_args *args, void *pr_ctxt)
@@ -1527,6 +1540,13 @@ u32 strmwrap_allocate_buffer(union trapped_args *args, void *pr_ctxt)
int status;
u8 **ap_buffer = NULL;
u32 num_bufs = args->args_strm_allocatebuffer.num_bufs;
+ struct strm_res_object *strm_res;
+
+ find_strm_handle(&strm_res, pr_ctxt,
+ args->args_strm_allocatebuffer.hstream);
+
+ if (!strm_res)
+ return -EFAULT;

if (num_bufs > MAX_BUFS)
return -EINVAL;
@@ -1535,7 +1555,7 @@ u32 strmwrap_allocate_buffer(union trapped_args *args, void *pr_ctxt)
if (ap_buffer == NULL)
return -ENOMEM;

- status = strm_allocate_buffer(args->args_strm_allocatebuffer.hstream,
+ status = strm_allocate_buffer(strm_res,
args->args_strm_allocatebuffer.usize,
ap_buffer, num_bufs, pr_ctxt);
if (!status) {
@@ -1543,7 +1563,7 @@ u32 strmwrap_allocate_buffer(union trapped_args *args, void *pr_ctxt)
status, num_bufs);
if (status) {
status = -EFAULT;
- strm_free_buffer(args->args_strm_allocatebuffer.hstream,
+ strm_free_buffer(strm_res,
ap_buffer, num_bufs, pr_ctxt);
}
}
@@ -1557,7 +1577,14 @@ u32 strmwrap_allocate_buffer(union trapped_args *args, void *pr_ctxt)
*/
u32 strmwrap_close(union trapped_args *args, void *pr_ctxt)
{
- return strm_close(args->args_strm_close.hstream, pr_ctxt);
+ struct strm_res_object *strm_res;
+
+ find_strm_handle(&strm_res, pr_ctxt, args->args_strm_close.hstream);
+
+ if (!strm_res)
+ return -EFAULT;
+
+ return strm_close(strm_res, pr_ctxt);
}

/*
@@ -1568,6 +1595,13 @@ u32 strmwrap_free_buffer(union trapped_args *args, void *pr_ctxt)
int status = 0;
u8 **ap_buffer = NULL;
u32 num_bufs = args->args_strm_freebuffer.num_bufs;
+ struct strm_res_object *strm_res;
+
+ find_strm_handle(&strm_res, pr_ctxt,
+ args->args_strm_freebuffer.hstream);
+
+ if (!strm_res)
+ return -EFAULT;

if (num_bufs > MAX_BUFS)
return -EINVAL;
@@ -1579,10 +1613,10 @@ u32 strmwrap_free_buffer(union trapped_args *args, void *pr_ctxt)
CP_FM_USR(ap_buffer, args->args_strm_freebuffer.ap_buffer, status,
num_bufs);

- if (!status) {
- status = strm_free_buffer(args->args_strm_freebuffer.hstream,
+ if (!status)
+ status = strm_free_buffer(strm_res,
ap_buffer, num_bufs, pr_ctxt);
- }
+
CP_TO_USR(args->args_strm_freebuffer.ap_buffer, ap_buffer, status,
num_bufs);
kfree(ap_buffer);
@@ -1609,6 +1643,13 @@ u32 strmwrap_get_info(union trapped_args *args, void *pr_ctxt)
struct stream_info strm_info;
struct dsp_streaminfo user;
struct dsp_streaminfo *temp;
+ struct strm_res_object *strm_res;
+
+ find_strm_handle(&strm_res, pr_ctxt,
+ args->args_strm_getinfo.hstream);
+
+ if (!strm_res)
+ return -EFAULT;

CP_FM_USR(&strm_info, args->args_strm_getinfo.stream_info, status, 1);
temp = strm_info.user_strm;
@@ -1616,7 +1657,7 @@ u32 strmwrap_get_info(union trapped_args *args, void *pr_ctxt)
strm_info.user_strm = &user;

if (!status) {
- status = strm_get_info(args->args_strm_getinfo.hstream,
+ status = strm_get_info(strm_res->hstream,
&strm_info,
args->args_strm_getinfo.
stream_info_size);
@@ -1633,9 +1674,14 @@ u32 strmwrap_get_info(union trapped_args *args, void *pr_ctxt)
u32 strmwrap_idle(union trapped_args *args, void *pr_ctxt)
{
u32 ret;
+ struct strm_res_object *strm_res;
+
+ find_strm_handle(&strm_res, pr_ctxt, args->args_strm_idle.hstream);

- ret = strm_idle(args->args_strm_idle.hstream,
- args->args_strm_idle.flush_flag);
+ if (!strm_res)
+ return -EFAULT;
+
+ ret = strm_idle(strm_res->hstream, args->args_strm_idle.flush_flag);

return ret;
}
@@ -1646,6 +1692,12 @@ u32 strmwrap_idle(union trapped_args *args, void *pr_ctxt)
u32 strmwrap_issue(union trapped_args *args, void *pr_ctxt)
{
int status = 0;
+ struct strm_res_object *strm_res;
+
+ find_strm_handle(&strm_res, pr_ctxt, args->args_strm_issue.hstream);
+
+ if (!strm_res)
+ return -EFAULT;

if (!args->args_strm_issue.pbuffer)
return -EFAULT;
@@ -1653,7 +1705,7 @@ u32 strmwrap_issue(union trapped_args *args, void *pr_ctxt)
/* No need of doing CP_FM_USR for the user buffer (pbuffer)
as this is done in Bridge internal function bridge_chnl_add_io_req
in chnl_sm.c */
- status = strm_issue(args->args_strm_issue.hstream,
+ status = strm_issue(strm_res->hstream,
args->args_strm_issue.pbuffer,
args->args_strm_issue.dw_bytes,
args->args_strm_issue.dw_buf_size,
@@ -1669,7 +1721,7 @@ u32 strmwrap_open(union trapped_args *args, void *pr_ctxt)
{
int status = 0;
struct strm_attr attr;
- struct strm_object *strm_obj;
+ struct strm_res_object *strm_res_obj;
struct dsp_streamattrin strm_attr_in;
struct node_res_object *node_res;

@@ -1691,9 +1743,9 @@ u32 strmwrap_open(union trapped_args *args, void *pr_ctxt)
}
status = strm_open(node_res->hnode,
args->args_strm_open.direction,
- args->args_strm_open.index, &attr, &strm_obj,
+ args->args_strm_open.index, &attr, &strm_res_obj,
pr_ctxt);
- CP_TO_USR(args->args_strm_open.ph_stream, &strm_obj, status, 1);
+ CP_TO_USR(args->args_strm_open.ph_stream, &strm_res_obj->id, status, 1);
return status;
}

@@ -1707,8 +1759,14 @@ u32 strmwrap_reclaim(union trapped_args *args, void *pr_ctxt)
u32 ul_bytes;
u32 dw_arg;
u32 ul_buf_size;
+ struct strm_res_object *strm_res;
+
+ find_strm_handle(&strm_res, pr_ctxt, args->args_strm_reclaim.hstream);
+
+ if (!strm_res)
+ return -EFAULT;

- status = strm_reclaim(args->args_strm_reclaim.hstream, &buf_ptr,
+ status = strm_reclaim(strm_res->hstream, &buf_ptr,
&ul_bytes, &ul_buf_size, &dw_arg);
CP_TO_USR(args->args_strm_reclaim.buf_ptr, &buf_ptr, status, 1);
CP_TO_USR(args->args_strm_reclaim.bytes, &ul_bytes, status, 1);
@@ -1729,12 +1787,19 @@ u32 strmwrap_register_notify(union trapped_args *args, void *pr_ctxt)
{
int status = 0;
struct dsp_notification notification;
+ struct strm_res_object *strm_res;
+
+ find_strm_handle(&strm_res, pr_ctxt,
+ args->args_strm_registernotify.hstream);
+
+ if (!strm_res)
+ return -EFAULT;

/* Initialize the notification data structure */
notification.ps_name = NULL;
notification.handle = NULL;

- status = strm_register_notify(args->args_strm_registernotify.hstream,
+ status = strm_register_notify(strm_res->hstream,
args->args_strm_registernotify.event_mask,
args->args_strm_registernotify.
notify_type, &notification);
@@ -1752,12 +1817,28 @@ u32 strmwrap_select(union trapped_args *args, void *pr_ctxt)
u32 mask;
struct strm_object *strm_tab[MAX_STREAMS];
int status = 0;
+ struct strm_res_object *strm_res;
+ int *ids[MAX_STREAMS];
+ int i;

if (args->args_strm_select.strm_num > MAX_STREAMS)
return -EINVAL;

- CP_FM_USR(strm_tab, args->args_strm_select.stream_tab, status,
- args->args_strm_select.strm_num);
+ CP_FM_USR(ids, args->args_strm_select.stream_tab, status,
+ args->args_strm_select.strm_num);
+
+ if (status)
+ return status;
+
+ for (i = 0; i < args->args_strm_select.strm_num; i++) {
+ find_strm_handle(&strm_res, pr_ctxt, ids[i]);
+
+ if (!strm_res)
+ return -EFAULT;
+
+ strm_tab[i] = strm_res->hstream;
+ }
+
if (!status) {
status = strm_select(strm_tab, args->args_strm_select.strm_num,
&mask, args->args_strm_select.utimeout);
diff --git a/drivers/staging/tidspbridge/rmgr/drv.c b/drivers/staging/tidspbridge/rmgr/drv.c
index c8d9d25..8a8dea6 100644
--- a/drivers/staging/tidspbridge/rmgr/drv.c
+++ b/drivers/staging/tidspbridge/rmgr/drv.c
@@ -211,70 +211,40 @@ int drv_proc_insert_strm_res_element(void *stream_obj,
(struct strm_res_object **)strm_res;
struct process_context *ctxt = (struct process_context *)process_ctxt;
int status = 0;
- struct strm_res_object *temp_strm_res = NULL;
+ int retval;

*pstrm_res = kzalloc(sizeof(struct strm_res_object), GFP_KERNEL);
- if (*pstrm_res == NULL)
+ if (*pstrm_res == NULL) {
status = -EFAULT;
+ goto func_end;
+ }

- if (!status) {
- if (mutex_lock_interruptible(&ctxt->strm_mutex)) {
- kfree(*pstrm_res);
- return -EPERM;
+ (*pstrm_res)->hstream = stream_obj;
+ retval = idr_get_new(ctxt->stream_id, *pstrm_res,
+ &(*pstrm_res)->id);
+ if (retval == -EAGAIN) {
+ if (!idr_pre_get(ctxt->stream_id, GFP_KERNEL)) {
+ pr_err("%s: OUT OF MEMORY\n", __func__);
+ status = -ENOMEM;
+ goto func_end;
}
- (*pstrm_res)->hstream = stream_obj;
- if (ctxt->pstrm_list != NULL) {
- temp_strm_res = ctxt->pstrm_list;
- while (temp_strm_res->next != NULL)
- temp_strm_res = temp_strm_res->next;

- temp_strm_res->next = *pstrm_res;
- } else {
- ctxt->pstrm_list = *pstrm_res;
- }
- mutex_unlock(&ctxt->strm_mutex);
+ retval = idr_get_new(ctxt->stream_id, *pstrm_res,
+ &(*pstrm_res)->id);
}
- return status;
-}
-
-/* Release Stream resource element context
-* This function called after the actual resource is freed
- */
-int drv_proc_remove_strm_res_element(void *strm_res, void *process_ctxt)
-{
- struct strm_res_object *pstrm_res = (struct strm_res_object *)strm_res;
- struct process_context *ctxt = (struct process_context *)process_ctxt;
- struct strm_res_object *temp_strm_res;
- int status = 0;
-
- if (mutex_lock_interruptible(&ctxt->strm_mutex))
- return -EPERM;
- temp_strm_res = ctxt->pstrm_list;
-
- if (ctxt->pstrm_list == pstrm_res) {
- ctxt->pstrm_list = pstrm_res->next;
- } else {
- while (temp_strm_res && temp_strm_res->next != pstrm_res)
- temp_strm_res = temp_strm_res->next;
- if (temp_strm_res == NULL)
- status = -ENOENT;
- else
- temp_strm_res->next = pstrm_res->next;
+ if (retval) {
+ pr_err("%s: FAILED, IDR is FULL\n", __func__);
+ status = -EPERM;
}
- mutex_unlock(&ctxt->strm_mutex);
- kfree(pstrm_res);
+
+func_end:
return status;
}

-/* Release all Stream resources and its context
-* This is called from .bridge_release.
- */
-int drv_remove_all_strm_res_elements(void *process_ctxt)
+static int drv_proc_free_strm_res(int id, void *p, void *process_ctxt)
{
- struct process_context *ctxt = (struct process_context *)process_ctxt;
- int status = 0;
- struct strm_res_object *strm_res = NULL;
- struct strm_res_object *strm_tmp = NULL;
+ struct process_context *ctxt = process_ctxt;
+ struct strm_res_object *strm_res = p;
struct stream_info strm_info;
struct dsp_streaminfo user;
u8 **ap_buffer = NULL;
@@ -283,60 +253,38 @@ int drv_remove_all_strm_res_elements(void *process_ctxt)
u32 dw_arg;
s32 ul_buf_size;

- strm_tmp = ctxt->pstrm_list;
- while (strm_tmp) {
- strm_res = strm_tmp;
- strm_tmp = strm_tmp->next;
- if (strm_res->num_bufs) {
- ap_buffer = kmalloc((strm_res->num_bufs *
- sizeof(u8 *)), GFP_KERNEL);
- if (ap_buffer) {
- status = strm_free_buffer(strm_res->hstream,
- ap_buffer,
- strm_res->num_bufs,
- ctxt);
- kfree(ap_buffer);
- }
+ if (strm_res->num_bufs) {
+ ap_buffer = kmalloc((strm_res->num_bufs *
+ sizeof(u8 *)), GFP_KERNEL);
+ if (ap_buffer) {
+ strm_free_buffer(strm_res,
+ ap_buffer,
+ strm_res->num_bufs,
+ ctxt);
+ kfree(ap_buffer);
}
- strm_info.user_strm = &user;
- user.number_bufs_in_stream = 0;
- strm_get_info(strm_res->hstream, &strm_info, sizeof(strm_info));
- while (user.number_bufs_in_stream--)
- strm_reclaim(strm_res->hstream, &buf_ptr, &ul_bytes,
- (u32 *) &ul_buf_size, &dw_arg);
- status = strm_close(strm_res->hstream, ctxt);
}
- return status;
+ strm_info.user_strm = &user;
+ user.number_bufs_in_stream = 0;
+ strm_get_info(strm_res->hstream, &strm_info, sizeof(strm_info));
+ while (user.number_bufs_in_stream--)
+ strm_reclaim(strm_res->hstream, &buf_ptr, &ul_bytes,
+ (u32 *) &ul_buf_size, &dw_arg);
+ strm_close(strm_res, ctxt);
+ return 0;
}

-/* Getting the stream resource element */
-int drv_get_strm_res_element(void *stream_obj, void *strm_resources,
- void *process_ctxt)
+/* Release all Stream resources and its context
+* This is called from .bridge_release.
+ */
+int drv_remove_all_strm_res_elements(void *process_ctxt)
{
- struct strm_res_object **strm_res =
- (struct strm_res_object **)strm_resources;
- struct process_context *ctxt = (struct process_context *)process_ctxt;
- int status = 0;
- struct strm_res_object *temp_strm2 = NULL;
- struct strm_res_object *temp_strm;
-
- if (mutex_lock_interruptible(&ctxt->strm_mutex))
- return -EPERM;
-
- temp_strm = ctxt->pstrm_list;
- while ((temp_strm != NULL) && (temp_strm->hstream != stream_obj)) {
- temp_strm2 = temp_strm;
- temp_strm = temp_strm->next;
- }
-
- mutex_unlock(&ctxt->strm_mutex);
+ struct process_context *ctxt = process_ctxt;

- if (temp_strm != NULL)
- *strm_res = temp_strm;
- else
- status = -ENOENT;
+ idr_for_each(ctxt->stream_id, drv_proc_free_strm_res, ctxt);
+ idr_destroy(ctxt->stream_id);

- return status;
+ return 0;
}

/* Updating the stream resource element */
diff --git a/drivers/staging/tidspbridge/rmgr/drv_interface.c b/drivers/staging/tidspbridge/rmgr/drv_interface.c
index 900cdd3..7ee8949 100644
--- a/drivers/staging/tidspbridge/rmgr/drv_interface.c
+++ b/drivers/staging/tidspbridge/rmgr/drv_interface.c
@@ -511,17 +511,24 @@ static int bridge_open(struct inode *ip, struct file *filp)
INIT_LIST_HEAD(&pr_ctxt->dmm_map_list);
spin_lock_init(&pr_ctxt->dmm_rsv_lock);
INIT_LIST_HEAD(&pr_ctxt->dmm_rsv_list);
- mutex_init(&pr_ctxt->strm_mutex);

pr_ctxt->node_id = kzalloc(sizeof(struct idr), GFP_KERNEL);
- if (pr_ctxt->node_id)
+ if (pr_ctxt->node_id) {
idr_init(pr_ctxt->node_id);
+ } else {
+ status = -ENOMEM;
+ goto err;
+ }
+
+ pr_ctxt->stream_id = kzalloc(sizeof(struct idr), GFP_KERNEL);
+ if (pr_ctxt->stream_id)
+ idr_init(pr_ctxt->stream_id);
else
status = -ENOMEM;
} else {
status = -ENOMEM;
}
-
+err:
filp->private_data = pr_ctxt;
#ifdef CONFIG_TIDSPBRIDGE_RECOVERY
if (!status)
diff --git a/drivers/staging/tidspbridge/rmgr/strm.c b/drivers/staging/tidspbridge/rmgr/strm.c
index df8458e..ef2ec94 100644
--- a/drivers/staging/tidspbridge/rmgr/strm.c
+++ b/drivers/staging/tidspbridge/rmgr/strm.c
@@ -96,15 +96,14 @@ static int delete_strm(struct strm_object *stream_obj);
* Purpose:
* Allocates buffers for a stream.
*/
-int strm_allocate_buffer(struct strm_object *stream_obj, u32 usize,
+int strm_allocate_buffer(struct strm_res_object *strmres, u32 usize,
u8 **ap_buffer, u32 num_bufs,
struct process_context *pr_ctxt)
{
int status = 0;
u32 alloc_cnt = 0;
u32 i;
-
- void *hstrm_res;
+ struct strm_object *stream_obj = strmres->hstream;

DBC_REQUIRE(refs > 0);
DBC_REQUIRE(ap_buffer != NULL);
@@ -134,14 +133,12 @@ int strm_allocate_buffer(struct strm_object *stream_obj, u32 usize,
}
}
if (status)
- strm_free_buffer(stream_obj, ap_buffer, alloc_cnt, pr_ctxt);
+ strm_free_buffer(strmres, ap_buffer, alloc_cnt, pr_ctxt);

if (status)
goto func_end;

- if (drv_get_strm_res_element(stream_obj, &hstrm_res, pr_ctxt) !=
- -ENOENT)
- drv_proc_update_strm_res(num_bufs, hstrm_res);
+ drv_proc_update_strm_res(num_bufs, strmres);

func_end:
return status;
@@ -152,14 +149,13 @@ func_end:
* Purpose:
* Close a stream opened with strm_open().
*/
-int strm_close(struct strm_object *stream_obj,
+int strm_close(struct strm_res_object *strmres,
struct process_context *pr_ctxt)
{
struct bridge_drv_interface *intf_fxns;
struct chnl_info chnl_info_obj;
int status = 0;
-
- void *hstrm_res;
+ struct strm_object *stream_obj = strmres->hstream;

DBC_REQUIRE(refs > 0);

@@ -183,9 +179,7 @@ int strm_close(struct strm_object *stream_obj,
if (status)
goto func_end;

- if (drv_get_strm_res_element(stream_obj, &hstrm_res, pr_ctxt) !=
- -ENOENT)
- drv_proc_remove_strm_res_element(hstrm_res, pr_ctxt);
+ idr_remove(pr_ctxt->stream_id, strmres->id);
func_end:
DBC_ENSURE(status == 0 || status == -EFAULT ||
status == -EPIPE || status == -EPERM);
@@ -270,13 +264,12 @@ void strm_exit(void)
* Purpose:
* Frees the buffers allocated for a stream.
*/
-int strm_free_buffer(struct strm_object *stream_obj, u8 ** ap_buffer,
+int strm_free_buffer(struct strm_res_object *strmres, u8 ** ap_buffer,
u32 num_bufs, struct process_context *pr_ctxt)
{
int status = 0;
u32 i = 0;
-
- void *hstrm_res = NULL;
+ struct strm_object *stream_obj = strmres->hstream;

DBC_REQUIRE(refs > 0);
DBC_REQUIRE(ap_buffer != NULL);
@@ -295,9 +288,7 @@ int strm_free_buffer(struct strm_object *stream_obj, u8 ** ap_buffer,
ap_buffer[i] = NULL;
}
}
- if (drv_get_strm_res_element(stream_obj, hstrm_res, pr_ctxt) !=
- -ENOENT)
- drv_proc_update_strm_res(num_bufs - i, hstrm_res);
+ drv_proc_update_strm_res(num_bufs - i, strmres);

return status;
}
@@ -467,7 +458,7 @@ int strm_issue(struct strm_object *stream_obj, u8 *pbuf, u32 ul_bytes,
*/
int strm_open(struct node_object *hnode, u32 dir, u32 index,
struct strm_attr *pattr,
- struct strm_object **strm_objct,
+ struct strm_res_object **strmres,
struct process_context *pr_ctxt)
{
struct strm_mgr *strm_mgr_obj;
@@ -479,12 +470,12 @@ int strm_open(struct node_object *hnode, u32 dir, u32 index,
int status = 0;
struct cmm_object *hcmm_mgr = NULL; /* Shared memory manager hndl */

- void *hstrm_res;
+ void *stream_res;

DBC_REQUIRE(refs > 0);
- DBC_REQUIRE(strm_objct != NULL);
+ DBC_REQUIRE(strmres != NULL);
DBC_REQUIRE(pattr != NULL);
- *strm_objct = NULL;
+ *strmres = NULL;
if (dir != DSP_TONODE && dir != DSP_FROMNODE) {
status = -EPERM;
} else {
@@ -594,22 +585,25 @@ func_cont:
}
}
if (!status) {
- *strm_objct = strm_obj;
- drv_proc_insert_strm_res_element(*strm_objct, &hstrm_res,
- pr_ctxt);
+ status = drv_proc_insert_strm_res_element(strm_obj,
+ &stream_res, pr_ctxt);
+ if (status)
+ delete_strm(strm_obj);
+ else
+ *strmres = (struct strm_res_object *)stream_res;
} else {
(void)delete_strm(strm_obj);
}

/* ensure we return a documented error code */
- DBC_ENSURE((!status && *strm_objct) ||
- (*strm_objct == NULL && (status == -EFAULT ||
+ DBC_ENSURE((!status && strm_obj) ||
+ (*strmres == NULL && (status == -EFAULT ||
status == -EPERM
|| status == -EINVAL)));

dev_dbg(bridge, "%s: hnode: %p dir: 0x%x index: 0x%x pattr: %p "
- "strm_objct: %p status: 0x%x\n", __func__,
- hnode, dir, index, pattr, strm_objct, status);
+ "strmres: %p status: 0x%x\n", __func__,
+ hnode, dir, index, pattr, strmres, status);
return status;
}

--
1.5.4.5

2010-07-28 21:00:50

by Ernesto Ramos

[permalink] [raw]
Subject: [PATCH] staging:ti dspbridge: use node id instead of kernel address

Use idr kernel library to send/receive node ids to the
user instead of kernel address.
This id will be use to access the node handles at the
kernel side, if id does not match to any handle
error -EFAULT is returned.

Signed-off-by: Ernesto Ramos <[email protected]>
---
.../staging/tidspbridge/include/dspbridge/drv.h | 6 +-
.../staging/tidspbridge/include/dspbridge/node.h | 14 +-
.../include/dspbridge/resourcecleanup.h | 6 -
drivers/staging/tidspbridge/pmgr/dspapi.c | 158 +++++++++++++++++---
drivers/staging/tidspbridge/rmgr/drv.c | 151 ++++++-------------
drivers/staging/tidspbridge/rmgr/drv_interface.c | 7 +-
drivers/staging/tidspbridge/rmgr/node.c | 109 +++++++-------
7 files changed, 256 insertions(+), 195 deletions(-)

diff --git a/drivers/staging/tidspbridge/include/dspbridge/drv.h b/drivers/staging/tidspbridge/include/dspbridge/drv.h
index 28541f7..0b36a11 100644
--- a/drivers/staging/tidspbridge/include/dspbridge/drv.h
+++ b/drivers/staging/tidspbridge/include/dspbridge/drv.h
@@ -24,6 +24,7 @@
#include <dspbridge/devdefs.h>

#include <dspbridge/drvdefs.h>
+#include <linux/idr.h>

#define DRV_ASSIGN 1
#define DRV_RELEASE 0
@@ -81,7 +82,7 @@ struct node_res_object {
s32 node_allocated; /* Node status */
s32 heap_allocated; /* Heap status */
s32 streams_allocated; /* Streams status */
- struct node_res_object *next;
+ int id;
};

/* used to cache dma mapping information */
@@ -158,8 +159,7 @@ struct process_context {
void *hprocessor;

/* DSP Node resources */
- struct node_res_object *node_list;
- struct mutex node_mutex;
+ struct idr *node_id;

/* DMM mapped memory resources */
struct list_head dmm_map_list;
diff --git a/drivers/staging/tidspbridge/include/dspbridge/node.h b/drivers/staging/tidspbridge/include/dspbridge/node.h
index 61d2d9b..49ed5c1 100644
--- a/drivers/staging/tidspbridge/include/dspbridge/node.h
+++ b/drivers/staging/tidspbridge/include/dspbridge/node.h
@@ -36,7 +36,7 @@
* pargs: Optional arguments to be passed to the node.
* attr_in: Optional pointer to node attributes (priority,
* timeout...)
- * ph_node: Location to store node handle on output.
+ * noderes: Location to store node resource info.
* Returns:
* 0: Success.
* -ENOMEM: Insufficient memory on GPP.
@@ -50,17 +50,17 @@
* node_init(void) called.
* hprocessor != NULL.
* node_uuid != NULL.
- * ph_node != NULL.
+ * noderes != NULL.
* Ensures:
* 0: IsValidNode(*ph_node).
- * error: *ph_node == NULL.
+ * error: *noderes == NULL.
*/
extern int node_allocate(struct proc_object *hprocessor,
const struct dsp_uuid *node_uuid,
const struct dsp_cbdata
*pargs, const struct dsp_nodeattrin
*attr_in,
- struct node_object **ph_node,
+ struct node_res_object **noderes,
struct process_context *pr_ctxt);

/*
@@ -242,7 +242,9 @@ extern int node_create_mgr(struct node_mgr **node_man,
* delete function. Loads the node's delete function if necessary.
* GPP side resources are freed after node's delete function returns.
* Parameters:
- * hnode: Node handle returned from node_allocate().
+ * noderes: Node resource info handle returned from
+ * node_allocate().
+ * pr_ctxt: Poninter to process context data.
* Returns:
* 0: Success.
* -EFAULT: Invalid hnode.
@@ -254,7 +256,7 @@ extern int node_create_mgr(struct node_mgr **node_man,
* Ensures:
* 0: hnode is invalid.
*/
-extern int node_delete(struct node_object *hnode,
+extern int node_delete(struct node_res_object *noderes,
struct process_context *pr_ctxt);

/*
diff --git a/drivers/staging/tidspbridge/include/dspbridge/resourcecleanup.h b/drivers/staging/tidspbridge/include/dspbridge/resourcecleanup.h
index 4e1b8a2..d17c7fb 100644
--- a/drivers/staging/tidspbridge/include/dspbridge/resourcecleanup.h
+++ b/drivers/staging/tidspbridge/include/dspbridge/resourcecleanup.h
@@ -34,17 +34,11 @@ extern int drv_remove_all_resources(void *process_ctxt);
extern int drv_remove_proc_context(struct drv_object *driver_obj,
void *pr_ctxt);

-extern int drv_get_node_res_element(void *hnode, void *node_resource,
- void *process_ctx);
-
extern int drv_insert_node_res_element(void *hnode, void *node_resource,
void *process_ctxt);

extern void drv_proc_node_update_heap_status(void *node_resource, s32 status);

-extern int drv_remove_node_res_element(void *node_resource,
- void *process_ctxt);
-
extern void drv_proc_node_update_status(void *node_resource, s32 status);

extern int drv_proc_update_strm_res(u32 num_bufs, void *strm_resources);
diff --git a/drivers/staging/tidspbridge/pmgr/dspapi.c b/drivers/staging/tidspbridge/pmgr/dspapi.c
index da08dfc..6eda7c5 100644
--- a/drivers/staging/tidspbridge/pmgr/dspapi.c
+++ b/drivers/staging/tidspbridge/pmgr/dspapi.c
@@ -1052,6 +1052,20 @@ u32 procwrap_stop(union trapped_args *args, void *pr_ctxt)
}

/*
+ * ======== find_handle =========
+ */
+inline void find_node_handle(struct node_res_object **noderes,
+ void *pr_ctxt, void *hnode)
+{
+ rcu_read_lock();
+ *noderes = idr_find(((struct process_context *)pr_ctxt)->node_id,
+ (int)hnode);
+ rcu_read_unlock();
+ return;
+}
+
+
+/*
* ======== nodewrap_allocate ========
*/
u32 nodewrap_allocate(union trapped_args *args, void *pr_ctxt)
@@ -1062,7 +1076,7 @@ u32 nodewrap_allocate(union trapped_args *args, void *pr_ctxt)
u32 __user *psize = (u32 __user *) args->args_node_allocate.pargs;
u8 *pargs = NULL;
struct dsp_nodeattrin proc_attr_in, *attr_in = NULL;
- struct node_object *hnode;
+ struct node_res_object *node_res;

/* Optional argument */
if (psize) {
@@ -1095,13 +1109,14 @@ u32 nodewrap_allocate(union trapped_args *args, void *pr_ctxt)
if (!status) {
status = node_allocate(args->args_node_allocate.hprocessor,
&node_uuid, (struct dsp_cbdata *)pargs,
- attr_in, &hnode, pr_ctxt);
+ attr_in, &node_res, pr_ctxt);
}
if (!status) {
- CP_TO_USR(args->args_node_allocate.ph_node, &hnode, status, 1);
+ CP_TO_USR(args->args_node_allocate.ph_node, &node_res->id,
+ status, 1);
if (status) {
status = -EFAULT;
- node_delete(hnode, pr_ctxt);
+ node_delete(node_res, pr_ctxt);
}
}
func_cont:
@@ -1119,6 +1134,13 @@ u32 nodewrap_alloc_msg_buf(union trapped_args *args, void *pr_ctxt)
struct dsp_bufferattr *pattr = NULL;
struct dsp_bufferattr attr;
u8 *pbuffer = NULL;
+ struct node_res_object *node_res;
+
+ find_node_handle(&node_res, pr_ctxt,
+ args->args_node_allocmsgbuf.hnode);
+
+ if (!node_res)
+ return -EFAULT;

if (!args->args_node_allocmsgbuf.usize)
return -EINVAL;
@@ -1132,7 +1154,7 @@ u32 nodewrap_alloc_msg_buf(union trapped_args *args, void *pr_ctxt)
/* argument */
CP_FM_USR(&pbuffer, args->args_node_allocmsgbuf.pbuffer, status, 1);
if (!status) {
- status = node_alloc_msg_buf(args->args_node_allocmsgbuf.hnode,
+ status = node_alloc_msg_buf(node_res->hnode,
args->args_node_allocmsgbuf.usize,
pattr, &pbuffer);
}
@@ -1146,8 +1168,15 @@ u32 nodewrap_alloc_msg_buf(union trapped_args *args, void *pr_ctxt)
u32 nodewrap_change_priority(union trapped_args *args, void *pr_ctxt)
{
u32 ret;
+ struct node_res_object *node_res;

- ret = node_change_priority(args->args_node_changepriority.hnode,
+ find_node_handle(&node_res, pr_ctxt,
+ args->args_node_changepriority.hnode);
+
+ if (!node_res)
+ return -EFAULT;
+
+ ret = node_change_priority(node_res->hnode,
args->args_node_changepriority.prio);

return ret;
@@ -1164,6 +1193,29 @@ u32 nodewrap_connect(union trapped_args *args, void *pr_ctxt)
u32 cb_data_size;
u32 __user *psize = (u32 __user *) args->args_node_connect.conn_param;
u8 *pargs = NULL;
+ struct node_res_object *node_res1, *node_res2;
+ struct node_object *node1 = NULL, *node2 = NULL;
+
+ if ((int)args->args_node_connect.hnode != DSP_HGPPNODE) {
+ find_node_handle(&node_res1, pr_ctxt,
+ args->args_node_connect.hnode);
+ if (node_res1)
+ node1 = node_res1->hnode;
+ } else {
+ node1 = args->args_node_connect.hnode;
+ }
+
+ if ((int)args->args_node_connect.other_node != DSP_HGPPNODE) {
+ find_node_handle(&node_res2, pr_ctxt,
+ args->args_node_connect.other_node);
+ if (node_res2)
+ node2 = node_res2->hnode;
+ } else {
+ node2 = args->args_node_connect.other_node;
+ }
+
+ if (!node1 || !node2)
+ return -EFAULT;

/* Optional argument */
if (psize) {
@@ -1191,9 +1243,9 @@ u32 nodewrap_connect(union trapped_args *args, void *pr_ctxt)

}
if (!status) {
- status = node_connect(args->args_node_connect.hnode,
+ status = node_connect(node1,
args->args_node_connect.stream_id,
- args->args_node_connect.other_node,
+ node2,
args->args_node_connect.other_stream,
pattrs, (struct dsp_cbdata *)pargs);
}
@@ -1209,8 +1261,14 @@ func_cont:
u32 nodewrap_create(union trapped_args *args, void *pr_ctxt)
{
u32 ret;
+ struct node_res_object *node_res;
+
+ find_node_handle(&node_res, pr_ctxt, args->args_node_create.hnode);

- ret = node_create(args->args_node_create.hnode);
+ if (!node_res)
+ return -EFAULT;
+
+ ret = node_create(node_res->hnode);

return ret;
}
@@ -1221,8 +1279,14 @@ u32 nodewrap_create(union trapped_args *args, void *pr_ctxt)
u32 nodewrap_delete(union trapped_args *args, void *pr_ctxt)
{
u32 ret;
+ struct node_res_object *node_res;
+
+ find_node_handle(&node_res, pr_ctxt, args->args_node_delete.hnode);
+
+ if (!node_res)
+ return -EFAULT;

- ret = node_delete(args->args_node_delete.hnode, pr_ctxt);
+ ret = node_delete(node_res, pr_ctxt);

return ret;
}
@@ -1235,6 +1299,13 @@ u32 nodewrap_free_msg_buf(union trapped_args *args, void *pr_ctxt)
int status = 0;
struct dsp_bufferattr *pattr = NULL;
struct dsp_bufferattr attr;
+ struct node_res_object *node_res;
+
+ find_node_handle(&node_res, pr_ctxt, args->args_node_freemsgbuf.hnode);
+
+ if (!node_res)
+ return -EFAULT;
+
if (args->args_node_freemsgbuf.pattr) { /* Optional argument */
CP_FM_USR(&attr, args->args_node_freemsgbuf.pattr, status, 1);
if (!status)
@@ -1246,7 +1317,7 @@ u32 nodewrap_free_msg_buf(union trapped_args *args, void *pr_ctxt)
return -EFAULT;

if (!status) {
- status = node_free_msg_buf(args->args_node_freemsgbuf.hnode,
+ status = node_free_msg_buf(node_res->hnode,
args->args_node_freemsgbuf.pbuffer,
pattr);
}
@@ -1261,8 +1332,14 @@ u32 nodewrap_get_attr(union trapped_args *args, void *pr_ctxt)
{
int status = 0;
struct dsp_nodeattr attr;
+ struct node_res_object *node_res;

- status = node_get_attr(args->args_node_getattr.hnode, &attr,
+ find_node_handle(&node_res, pr_ctxt, args->args_node_getattr.hnode);
+
+ if (!node_res)
+ return -EFAULT;
+
+ status = node_get_attr(node_res->hnode, &attr,
args->args_node_getattr.attr_size);
CP_TO_USR(args->args_node_getattr.pattr, &attr, status, 1);

@@ -1276,8 +1353,14 @@ u32 nodewrap_get_message(union trapped_args *args, void *pr_ctxt)
{
int status;
struct dsp_msg msg;
+ struct node_res_object *node_res;
+
+ find_node_handle(&node_res, pr_ctxt, args->args_node_getmessage.hnode);

- status = node_get_message(args->args_node_getmessage.hnode, &msg,
+ if (!node_res)
+ return -EFAULT;
+
+ status = node_get_message(node_res->hnode, &msg,
args->args_node_getmessage.utimeout);

CP_TO_USR(args->args_node_getmessage.message, &msg, status, 1);
@@ -1291,8 +1374,14 @@ u32 nodewrap_get_message(union trapped_args *args, void *pr_ctxt)
u32 nodewrap_pause(union trapped_args *args, void *pr_ctxt)
{
u32 ret;
+ struct node_res_object *node_res;
+
+ find_node_handle(&node_res, pr_ctxt, args->args_node_pause.hnode);
+
+ if (!node_res)
+ return -EFAULT;

- ret = node_pause(args->args_node_pause.hnode);
+ ret = node_pause(node_res->hnode);

return ret;
}
@@ -1304,12 +1393,18 @@ u32 nodewrap_put_message(union trapped_args *args, void *pr_ctxt)
{
int status = 0;
struct dsp_msg msg;
+ struct node_res_object *node_res;
+
+ find_node_handle(&node_res, pr_ctxt, args->args_node_putmessage.hnode);
+
+ if (!node_res)
+ return -EFAULT;

CP_FM_USR(&msg, args->args_node_putmessage.message, status, 1);

if (!status) {
status =
- node_put_message(args->args_node_putmessage.hnode, &msg,
+ node_put_message(node_res->hnode, &msg,
args->args_node_putmessage.utimeout);
}

@@ -1323,6 +1418,13 @@ u32 nodewrap_register_notify(union trapped_args *args, void *pr_ctxt)
{
int status = 0;
struct dsp_notification notification;
+ struct node_res_object *node_res;
+
+ find_node_handle(&node_res, pr_ctxt,
+ args->args_node_registernotify.hnode);
+
+ if (!node_res)
+ return -EFAULT;

/* Initialize the notification data structure */
notification.ps_name = NULL;
@@ -1333,7 +1435,7 @@ u32 nodewrap_register_notify(union trapped_args *args, void *pr_ctxt)
args->args_proc_register_notify.hnotification,
status, 1);

- status = node_register_notify(args->args_node_registernotify.hnode,
+ status = node_register_notify(node_res->hnode,
args->args_node_registernotify.event_mask,
args->args_node_registernotify.
notify_type, &notification);
@@ -1348,8 +1450,14 @@ u32 nodewrap_register_notify(union trapped_args *args, void *pr_ctxt)
u32 nodewrap_run(union trapped_args *args, void *pr_ctxt)
{
u32 ret;
+ struct node_res_object *node_res;
+
+ find_node_handle(&node_res, pr_ctxt, args->args_node_run.hnode);
+
+ if (!node_res)
+ return -EFAULT;

- ret = node_run(args->args_node_run.hnode);
+ ret = node_run(node_res->hnode);

return ret;
}
@@ -1361,8 +1469,14 @@ u32 nodewrap_terminate(union trapped_args *args, void *pr_ctxt)
{
int status;
int tempstatus;
+ struct node_res_object *node_res;

- status = node_terminate(args->args_node_terminate.hnode, &tempstatus);
+ find_node_handle(&node_res, pr_ctxt, args->args_node_terminate.hnode);
+
+ if (!node_res)
+ return -EFAULT;
+
+ status = node_terminate(node_res->hnode, &tempstatus);

CP_TO_USR(args->args_node_terminate.pstatus, &tempstatus, status, 1);

@@ -1548,6 +1662,12 @@ u32 strmwrap_open(union trapped_args *args, void *pr_ctxt)
struct strm_attr attr;
struct strm_object *strm_obj;
struct dsp_streamattrin strm_attr_in;
+ struct node_res_object *node_res;
+
+ find_node_handle(&node_res, pr_ctxt, args->args_strm_open.hnode);
+
+ if (!node_res)
+ return -EFAULT;

CP_FM_USR(&attr, args->args_strm_open.attr_in, status, 1);

@@ -1560,7 +1680,7 @@ u32 strmwrap_open(union trapped_args *args, void *pr_ctxt)
}

}
- status = strm_open(args->args_strm_open.hnode,
+ status = strm_open(node_res->hnode,
args->args_strm_open.direction,
args->args_strm_open.index, &attr, &strm_obj,
pr_ctxt);
diff --git a/drivers/staging/tidspbridge/rmgr/drv.c b/drivers/staging/tidspbridge/rmgr/drv.c
index 12c270a..c8d9d25 100644
--- a/drivers/staging/tidspbridge/rmgr/drv.c
+++ b/drivers/staging/tidspbridge/rmgr/drv.c
@@ -73,7 +73,7 @@ static int request_bridge_resources(struct cfg_hostres *res);

/* GPP PROCESS CLEANUP CODE */

-static int drv_proc_free_node_res(void *process_ctxt);
+static int drv_proc_free_node_res(int id, void *p, void *data);

/* Allocate and add a node resource element
* This function is called from .Node_Allocate. */
@@ -84,88 +84,61 @@ int drv_insert_node_res_element(void *hnode, void *node_resource,
(struct node_res_object **)node_resource;
struct process_context *ctxt = (struct process_context *)process_ctxt;
int status = 0;
- struct node_res_object *temp_node_res = NULL;
+ int retval;

*node_res_obj = kzalloc(sizeof(struct node_res_object), GFP_KERNEL);
- if (*node_res_obj == NULL)
- status = -EFAULT;
+ if (!*node_res_obj) {
+ status = -ENOMEM;
+ goto func_end;
+ }

- if (!status) {
- if (mutex_lock_interruptible(&ctxt->node_mutex)) {
- kfree(*node_res_obj);
- return -EPERM;
+ (*node_res_obj)->hnode = hnode;
+ retval = idr_get_new(ctxt->node_id, *node_res_obj,
+ &(*node_res_obj)->id);
+ if (retval == -EAGAIN) {
+ if (!idr_pre_get(ctxt->node_id, GFP_KERNEL)) {
+ pr_err("%s: OUT OF MEMORY\n", __func__);
+ status = -ENOMEM;
+ goto func_end;
}
- (*node_res_obj)->hnode = hnode;
- if (ctxt->node_list != NULL) {
- temp_node_res = ctxt->node_list;
- while (temp_node_res->next != NULL)
- temp_node_res = temp_node_res->next;

- temp_node_res->next = *node_res_obj;
- } else {
- ctxt->node_list = *node_res_obj;
- }
- mutex_unlock(&ctxt->node_mutex);
+ retval = idr_get_new(ctxt->node_id, *node_res_obj,
+ &(*node_res_obj)->id);
+ }
+ if (retval) {
+ pr_err("%s: FAILED, IDR is FULL\n", __func__);
+ status = -EFAULT;
}
+func_end:
+ if (status)
+ kfree(*node_res_obj);

return status;
}

/* Release all Node resources and its context
-* This is called from .Node_Delete. */
-int drv_remove_node_res_element(void *node_resource, void *process_ctxt)
+ * Actual Node De-Allocation */
+static int drv_proc_free_node_res(int id, void *p, void *data)
{
- struct node_res_object *node_res_obj =
- (struct node_res_object *)node_resource;
- struct process_context *ctxt = (struct process_context *)process_ctxt;
- struct node_res_object *temp_node;
- int status = 0;
-
- if (mutex_lock_interruptible(&ctxt->node_mutex))
- return -EPERM;
- temp_node = ctxt->node_list;
- if (temp_node == node_res_obj) {
- ctxt->node_list = node_res_obj->next;
- } else {
- while (temp_node && temp_node->next != node_res_obj)
- temp_node = temp_node->next;
- if (!temp_node)
- status = -ENOENT;
- else
- temp_node->next = node_res_obj->next;
- }
- mutex_unlock(&ctxt->node_mutex);
- kfree(node_res_obj);
- return status;
-}
-
-/* Actual Node De-Allocation */
-static int drv_proc_free_node_res(void *process_ctxt)
-{
- struct process_context *ctxt = (struct process_context *)process_ctxt;
- int status = 0;
- struct node_res_object *node_list = NULL;
- struct node_res_object *node_res_obj = NULL;
+ struct process_context *ctxt = data;
+ int status;
+ struct node_res_object *node_res_obj = p;
u32 node_state;

- node_list = ctxt->node_list;
- while (node_list != NULL) {
- node_res_obj = node_list;
- node_list = node_list->next;
- if (node_res_obj->node_allocated) {
- node_state = node_get_state(node_res_obj->hnode);
- if (node_state <= NODE_DELETING) {
- if ((node_state == NODE_RUNNING) ||
- (node_state == NODE_PAUSED) ||
- (node_state == NODE_TERMINATING))
- status = node_terminate
- (node_res_obj->hnode, &status);
-
- status = node_delete(node_res_obj->hnode, ctxt);
- }
+ if (node_res_obj->node_allocated) {
+ node_state = node_get_state(node_res_obj->hnode);
+ if (node_state <= NODE_DELETING) {
+ if ((node_state == NODE_RUNNING) ||
+ (node_state == NODE_PAUSED) ||
+ (node_state == NODE_TERMINATING))
+ node_terminate
+ (node_res_obj->hnode, &status);
+
+ node_delete(node_res_obj, ctxt);
}
}
- return status;
+
+ return 0;
}

/* Release all Mapped and Reserved DMM resources */
@@ -220,50 +193,12 @@ void drv_proc_node_update_heap_status(void *node_resource, s32 status)
*/
int drv_remove_all_node_res_elements(void *process_ctxt)
{
- struct process_context *ctxt = (struct process_context *)process_ctxt;
- int status = 0;
- struct node_res_object *temp_node2 = NULL;
- struct node_res_object *temp_node = NULL;
-
- drv_proc_free_node_res(ctxt);
- temp_node = ctxt->node_list;
- while (temp_node != NULL) {
- temp_node2 = temp_node;
- temp_node = temp_node->next;
- kfree(temp_node2);
- }
- ctxt->node_list = NULL;
- return status;
-}
+ struct process_context *ctxt = process_ctxt;

-/* Getting the node resource element */
-int drv_get_node_res_element(void *hnode, void *node_resource,
- void *process_ctxt)
-{
- struct node_res_object **node_res =
- (struct node_res_object **)node_resource;
- struct process_context *ctxt = (struct process_context *)process_ctxt;
- int status = 0;
- struct node_res_object *temp_node2 = NULL;
- struct node_res_object *temp_node = NULL;
-
- if (mutex_lock_interruptible(&ctxt->node_mutex))
- return -EPERM;
-
- temp_node = ctxt->node_list;
- while ((temp_node != NULL) && (temp_node->hnode != hnode)) {
- temp_node2 = temp_node;
- temp_node = temp_node->next;
- }
+ idr_for_each(ctxt->node_id, drv_proc_free_node_res, ctxt);
+ idr_destroy(ctxt->node_id);

- mutex_unlock(&ctxt->node_mutex);
-
- if (temp_node != NULL)
- *node_res = temp_node;
- else
- status = -ENOENT;
-
- return status;
+ return 0;
}

/* Allocate the STRM resource element
diff --git a/drivers/staging/tidspbridge/rmgr/drv_interface.c b/drivers/staging/tidspbridge/rmgr/drv_interface.c
index aec7cf7..900cdd3 100644
--- a/drivers/staging/tidspbridge/rmgr/drv_interface.c
+++ b/drivers/staging/tidspbridge/rmgr/drv_interface.c
@@ -511,8 +511,13 @@ static int bridge_open(struct inode *ip, struct file *filp)
INIT_LIST_HEAD(&pr_ctxt->dmm_map_list);
spin_lock_init(&pr_ctxt->dmm_rsv_lock);
INIT_LIST_HEAD(&pr_ctxt->dmm_rsv_list);
- mutex_init(&pr_ctxt->node_mutex);
mutex_init(&pr_ctxt->strm_mutex);
+
+ pr_ctxt->node_id = kzalloc(sizeof(struct idr), GFP_KERNEL);
+ if (pr_ctxt->node_id)
+ idr_init(pr_ctxt->node_id);
+ else
+ status = -ENOMEM;
} else {
status = -ENOMEM;
}
diff --git a/drivers/staging/tidspbridge/rmgr/node.c b/drivers/staging/tidspbridge/rmgr/node.c
index e2d02c4..6e9441e 100644
--- a/drivers/staging/tidspbridge/rmgr/node.c
+++ b/drivers/staging/tidspbridge/rmgr/node.c
@@ -291,11 +291,11 @@ enum node_state node_get_state(void *hnode)
* Allocate GPP resources to manage a node on the DSP.
*/
int node_allocate(struct proc_object *hprocessor,
- const struct dsp_uuid *node_uuid,
- const struct dsp_cbdata *pargs,
- const struct dsp_nodeattrin *attr_in,
- struct node_object **ph_node,
- struct process_context *pr_ctxt)
+ const struct dsp_uuid *node_uuid,
+ const struct dsp_cbdata *pargs,
+ const struct dsp_nodeattrin *attr_in,
+ struct node_res_object **noderes,
+ struct process_context *pr_ctxt)
{
struct node_mgr *hnode_mgr;
struct dev_object *hdev_obj;
@@ -327,10 +327,10 @@ int node_allocate(struct proc_object *hprocessor,

DBC_REQUIRE(refs > 0);
DBC_REQUIRE(hprocessor != NULL);
- DBC_REQUIRE(ph_node != NULL);
+ DBC_REQUIRE(noderes != NULL);
DBC_REQUIRE(node_uuid != NULL);

- *ph_node = NULL;
+ *noderes = NULL;

status = proc_get_processor_id(hprocessor, &proc_id);

@@ -653,9 +653,6 @@ func_cont:
* (for overlay and dll) */
pnode->phase_split = true;

- if (!status)
- *ph_node = pnode;
-
/* Notify all clients registered for DSP_NODESTATECHANGE. */
proc_notify_all_clients(hprocessor, DSP_NODESTATECHANGE);
} else {
@@ -666,16 +663,21 @@ func_cont:
}

if (!status) {
- drv_insert_node_res_element(*ph_node, &node_res, pr_ctxt);
+ status = drv_insert_node_res_element(pnode, &node_res, pr_ctxt);
+ if (status) {
+ delete_node(pnode, pr_ctxt);
+ goto func_end;
+ }
+
+ *noderes = (struct node_res_object *)node_res;
drv_proc_node_update_heap_status(node_res, true);
drv_proc_node_update_status(node_res, true);
}
- DBC_ENSURE((status && (*ph_node == NULL)) ||
- (!status && *ph_node));
+ DBC_ENSURE((status && *noderes == NULL) || (!status && *noderes));
func_end:
- dev_dbg(bridge, "%s: hprocessor: %p node_uuid: %p pargs: %p attr_in:"
- " %p ph_node: %p status: 0x%x\n", __func__, hprocessor,
- node_uuid, pargs, attr_in, ph_node, status);
+ dev_dbg(bridge, "%s: hprocessor: %p pNodeId: %p pargs: %p attr_in: %p "
+ "node_res: %p status: 0x%x\n", __func__, hprocessor,
+ node_uuid, pargs, attr_in, noderes, status);
return status;
}

@@ -1433,10 +1435,10 @@ int node_create_mgr(struct node_mgr **node_man,
* Loads the node's delete function if necessary. Free GPP side resources
* after node's delete function returns.
*/
-int node_delete(struct node_object *hnode,
+int node_delete(struct node_res_object *noderes,
struct process_context *pr_ctxt)
{
- struct node_object *pnode = (struct node_object *)hnode;
+ struct node_object *pnode = noderes->hnode;
struct node_mgr *hnode_mgr;
struct proc_object *hprocessor;
struct disp_object *disp_obj;
@@ -1449,32 +1451,32 @@ int node_delete(struct node_object *hnode,
u32 proc_id;
struct bridge_drv_interface *intf_fxns;

- void *node_res;
+ void *node_res = noderes;

struct dsp_processorstate proc_state;
DBC_REQUIRE(refs > 0);

- if (!hnode) {
+ if (!pnode) {
status = -EFAULT;
goto func_end;
}
/* create struct dsp_cbdata struct for PWR call */
cb_data.cb_data = PWR_TIMEOUT;
- hnode_mgr = hnode->hnode_mgr;
- hprocessor = hnode->hprocessor;
+ hnode_mgr = pnode->hnode_mgr;
+ hprocessor = pnode->hprocessor;
disp_obj = hnode_mgr->disp_obj;
- node_type = node_get_type(hnode);
+ node_type = node_get_type(pnode);
intf_fxns = hnode_mgr->intf_fxns;
/* Enter critical section */
mutex_lock(&hnode_mgr->node_mgr_lock);

- state = node_get_state(hnode);
+ state = node_get_state(pnode);
/* Execute delete phase code for non-device node in all cases
* except when the node was only allocated. Delete phase must be
* executed even if create phase was executed, but failed.
* If the node environment pointer is non-NULL, the delete phase
* code must be executed. */
- if (!(state == NODE_ALLOCATED && hnode->node_env == (u32) NULL) &&
+ if (!(state == NODE_ALLOCATED && pnode->node_env == (u32) NULL) &&
node_type != NODE_DEVICE) {
status = proc_get_processor_id(pnode->hprocessor, &proc_id);
if (status)
@@ -1487,26 +1489,26 @@ int node_delete(struct node_object *hnode,
* is now ok to unload it. If the node is running, we
* will unload the execute phase only after deleting
* the node. */
- if (state == NODE_PAUSED && hnode->loaded &&
- hnode->phase_split) {
+ if (state == NODE_PAUSED && pnode->loaded &&
+ pnode->phase_split) {
/* Ok to unload execute code as long as node
* is not * running */
status1 =
hnode_mgr->nldr_fxns.
- pfn_unload(hnode->nldr_node_obj,
+ pfn_unload(pnode->nldr_node_obj,
NLDR_EXECUTE);
- hnode->loaded = false;
- NODE_SET_STATE(hnode, NODE_DONE);
+ pnode->loaded = false;
+ NODE_SET_STATE(pnode, NODE_DONE);
}
/* Load delete phase code if not loaded or if haven't
* * unloaded EXECUTE phase */
- if ((!(hnode->loaded) || (state == NODE_RUNNING)) &&
- hnode->phase_split) {
+ if ((!(pnode->loaded) || (state == NODE_RUNNING)) &&
+ pnode->phase_split) {
status =
hnode_mgr->nldr_fxns.
- pfn_load(hnode->nldr_node_obj, NLDR_DELETE);
+ pfn_load(pnode->nldr_node_obj, NLDR_DELETE);
if (!status)
- hnode->loaded = true;
+ pnode->loaded = true;
else
pr_err("%s: fail - load delete code:"
" 0x%x\n", __func__, status);
@@ -1515,14 +1517,14 @@ int node_delete(struct node_object *hnode,
func_cont1:
if (!status) {
/* Unblock a thread trying to terminate the node */
- (void)sync_set_event(hnode->sync_done);
+ (void)sync_set_event(pnode->sync_done);
if (proc_id == DSP_UNIT) {
/* ul_delete_fxn = address of node's delete
* function */
- status = get_fxn_address(hnode, &ul_delete_fxn,
+ status = get_fxn_address(pnode, &ul_delete_fxn,
DELETEPHASE);
} else if (proc_id == IVA_UNIT)
- ul_delete_fxn = (u32) hnode->node_env;
+ ul_delete_fxn = (u32) pnode->node_env;
if (!status) {
status = proc_get_state(hprocessor,
&proc_state,
@@ -1530,22 +1532,22 @@ func_cont1:
dsp_processorstate));
if (proc_state.proc_state != PROC_ERROR) {
status =
- disp_node_delete(disp_obj, hnode,
+ disp_node_delete(disp_obj, pnode,
hnode_mgr->
ul_fxn_addrs
[RMSDELETENODE],
ul_delete_fxn,
- hnode->node_env);
+ pnode->node_env);
} else
- NODE_SET_STATE(hnode, NODE_DONE);
+ NODE_SET_STATE(pnode, NODE_DONE);

/* Unload execute, if not unloaded, and delete
* function */
if (state == NODE_RUNNING &&
- hnode->phase_split) {
+ pnode->phase_split) {
status1 =
hnode_mgr->nldr_fxns.
- pfn_unload(hnode->nldr_node_obj,
+ pfn_unload(pnode->nldr_node_obj,
NLDR_EXECUTE);
}
if (status1)
@@ -1553,10 +1555,10 @@ func_cont1:
" 0x%x\n", __func__, status1);

status1 =
- hnode_mgr->nldr_fxns.pfn_unload(hnode->
+ hnode_mgr->nldr_fxns.pfn_unload(pnode->
nldr_node_obj,
NLDR_DELETE);
- hnode->loaded = false;
+ pnode->loaded = false;
if (status1)
pr_err("%s: fail - unload delete code: "
"0x%x\n", __func__, status1);
@@ -1565,25 +1567,28 @@ func_cont1:
}
/* Free host side resources even if a failure occurred */
/* Remove node from hnode_mgr->node_list */
- lst_remove_elem(hnode_mgr->node_list, (struct list_head *)hnode);
+ lst_remove_elem(hnode_mgr->node_list, (struct list_head *)pnode);
hnode_mgr->num_nodes--;
/* Decrement count of nodes created on DSP */
if ((state != NODE_ALLOCATED) || ((state == NODE_ALLOCATED) &&
- (hnode->node_env != (u32) NULL)))
+ (pnode->node_env != (u32) NULL)))
hnode_mgr->num_created--;
/* Free host-side resources allocated by node_create()
* delete_node() fails if SM buffers not freed by client! */
- if (drv_get_node_res_element(hnode, &node_res, pr_ctxt) !=
- -ENOENT)
- drv_proc_node_update_status(node_res, false);
- delete_node(hnode, pr_ctxt);
+ drv_proc_node_update_status(node_res, false);
+ delete_node(pnode, pr_ctxt);
+
+ /*
+ * Release all Node resources and its context
+ */
+ idr_remove(pr_ctxt->node_id, ((struct node_res_object *)node_res)->id);
+ kfree(node_res);

- drv_remove_node_res_element(node_res, pr_ctxt);
/* Exit critical section */
mutex_unlock(&hnode_mgr->node_mgr_lock);
proc_notify_clients(hprocessor, DSP_NODESTATECHANGE);
func_end:
- dev_dbg(bridge, "%s: hnode: %p status 0x%x\n", __func__, hnode, status);
+ dev_dbg(bridge, "%s: pnode: %p status 0x%x\n", __func__, pnode, status);
return status;
}

--
1.5.4.5

2010-07-28 21:01:15

by Ernesto Ramos

[permalink] [raw]
Subject: [PATCH] staging:ti dspbridge: avoid errors if stream id is zero

As 'zero' can be a perfectly good id, it can be picked up as
a NULL from userspace, avoid issues in API and user apps if stream
handle is zero.

Signed-off-by: Ernesto Ramos <[email protected]>
---
drivers/staging/tidspbridge/pmgr/dspapi.c | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/tidspbridge/pmgr/dspapi.c b/drivers/staging/tidspbridge/pmgr/dspapi.c
index 47892dd..7b42f72 100644
--- a/drivers/staging/tidspbridge/pmgr/dspapi.c
+++ b/drivers/staging/tidspbridge/pmgr/dspapi.c
@@ -1527,7 +1527,7 @@ inline void find_strm_handle(struct strm_res_object **strmres,
{
rcu_read_lock();
*strmres = idr_find(((struct process_context *)pr_ctxt)->stream_id,
- (int)hstream);
+ (int)hstream - 1);
rcu_read_unlock();
return;
}
@@ -1724,6 +1724,7 @@ u32 strmwrap_open(union trapped_args *args, void *pr_ctxt)
struct strm_res_object *strm_res_obj;
struct dsp_streamattrin strm_attr_in;
struct node_res_object *node_res;
+ int strmid;

find_node_handle(&node_res, pr_ctxt, args->args_strm_open.hnode);

@@ -1745,7 +1746,10 @@ u32 strmwrap_open(union trapped_args *args, void *pr_ctxt)
args->args_strm_open.direction,
args->args_strm_open.index, &attr, &strm_res_obj,
pr_ctxt);
- CP_TO_USR(args->args_strm_open.ph_stream, &strm_res_obj->id, status, 1);
+ if (!status) {
+ strmid = strm_res_obj->id + 1;
+ CP_TO_USR(args->args_strm_open.ph_stream, &strmid, status, 1);
+ }
return status;
}

--
1.5.4.5

2010-07-28 21:01:34

by Ernesto Ramos

[permalink] [raw]
Subject: [PATCH] staging:ti dspbridge: use processor handle from context instead of user's

Make sure dspbridge driver uses a valid processor handle by
using the handle stored in process context.

Signed-off-by: Ernesto Ramos <[email protected]>
---
drivers/staging/tidspbridge/pmgr/dspapi.c | 50 +++++++++++++++++------------
1 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/tidspbridge/pmgr/dspapi.c b/drivers/staging/tidspbridge/pmgr/dspapi.c
index f46aaf6..d7613eb 100644
--- a/drivers/staging/tidspbridge/pmgr/dspapi.c
+++ b/drivers/staging/tidspbridge/pmgr/dspapi.c
@@ -616,6 +616,7 @@ u32 procwrap_ctrl(union trapped_args *args, void *pr_ctxt)
args->args_proc_ctrl.pargs;
u8 *pargs = NULL;
int status = 0;
+ void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;

if (psize) {
if (get_user(cb_data_size, psize)) {
@@ -633,7 +634,7 @@ u32 procwrap_ctrl(union trapped_args *args, void *pr_ctxt)
cb_data_size);
}
if (!status) {
- status = proc_ctrl(args->args_proc_ctrl.hprocessor,
+ status = proc_ctrl(hprocessor,
args->args_proc_ctrl.dw_cmd,
(struct dsp_cbdata *)pargs);
}
@@ -663,11 +664,12 @@ u32 procwrap_enum_node_info(union trapped_args *args, void *pr_ctxt)
void *node_tab[MAX_NODES];
u32 num_nodes;
u32 alloc_cnt;
+ void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;

if (!args->args_proc_enumnode_info.node_tab_size)
return -EINVAL;

- status = proc_enum_nodes(args->args_proc_enumnode_info.hprocessor,
+ status = proc_enum_nodes(hprocessor,
node_tab,
args->args_proc_enumnode_info.node_tab_size,
&num_nodes, &alloc_cnt);
@@ -747,13 +749,14 @@ u32 procwrap_enum_resources(union trapped_args *args, void *pr_ctxt)
{
int status = 0;
struct dsp_resourceinfo resource_info;
+ void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;

if (args->args_proc_enumresources.resource_info_size <
sizeof(struct dsp_resourceinfo))
return -EINVAL;

status =
- proc_get_resource_info(args->args_proc_enumresources.hprocessor,
+ proc_get_resource_info(hprocessor,
args->args_proc_enumresources.resource_type,
&resource_info,
args->args_proc_enumresources.
@@ -773,13 +776,13 @@ u32 procwrap_get_state(union trapped_args *args, void *pr_ctxt)
{
int status;
struct dsp_processorstate proc_state;
+ void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;

if (args->args_proc_getstate.state_info_size <
sizeof(struct dsp_processorstate))
return -EINVAL;

- status =
- proc_get_state(args->args_proc_getstate.hprocessor, &proc_state,
+ status = proc_get_state(hprocessor, &proc_state,
args->args_proc_getstate.state_info_size);
CP_TO_USR(args->args_proc_getstate.proc_state_obj, &proc_state, status,
1);
@@ -794,14 +797,14 @@ u32 procwrap_get_trace(union trapped_args *args, void *pr_ctxt)
{
int status;
u8 *pbuf;
+ void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;

if (args->args_proc_gettrace.max_size > MAX_TRACEBUFLEN)
return -EINVAL;

pbuf = kzalloc(args->args_proc_gettrace.max_size, GFP_KERNEL);
if (pbuf != NULL) {
- status = proc_get_trace(args->args_proc_gettrace.hprocessor,
- pbuf,
+ status = proc_get_trace(hprocessor, pbuf,
args->args_proc_gettrace.max_size);
} else {
status = -ENOMEM;
@@ -823,6 +826,7 @@ u32 procwrap_load(union trapped_args *args, void *pr_ctxt)
char *temp;
s32 count = args->args_proc_load.argc_index;
u8 **argv = NULL, **envp = NULL;
+ void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;

if (count <= 0 || count > MAX_LOADARGS) {
status = -EINVAL;
@@ -905,7 +909,7 @@ u32 procwrap_load(union trapped_args *args, void *pr_ctxt)
}

if (!status) {
- status = proc_load(args->args_proc_load.hprocessor,
+ status = proc_load(hprocessor,
args->args_proc_load.argc_index,
(const char **)argv, (const char **)envp);
}
@@ -936,6 +940,7 @@ u32 procwrap_map(union trapped_args *args, void *pr_ctxt)
{
int status;
void *map_addr;
+ void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;

if (!args->args_proc_mapmem.ul_size)
return -EINVAL;
@@ -948,8 +953,7 @@ u32 procwrap_map(union trapped_args *args, void *pr_ctxt)
if (!status) {
if (put_user(map_addr, args->args_proc_mapmem.pp_map_addr)) {
status = -EINVAL;
- proc_un_map(args->args_proc_mapmem.hprocessor,
- map_addr, pr_ctxt);
+ proc_un_map(hprocessor, map_addr, pr_ctxt);
}

}
@@ -963,13 +967,13 @@ u32 procwrap_register_notify(union trapped_args *args, void *pr_ctxt)
{
int status;
struct dsp_notification notification;
+ void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;

/* Initialize the notification data structure */
notification.ps_name = NULL;
notification.handle = NULL;

- status =
- proc_register_notify(args->args_proc_register_notify.hprocessor,
+ status = proc_register_notify(hprocessor,
args->args_proc_register_notify.event_mask,
args->args_proc_register_notify.notify_type,
&notification);
@@ -985,12 +989,13 @@ u32 procwrap_reserve_memory(union trapped_args *args, void *pr_ctxt)
{
int status;
void *prsv_addr;
+ void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;

if ((args->args_proc_rsvmem.ul_size <= 0) ||
(args->args_proc_rsvmem.ul_size & (PG_SIZE4K - 1)) != 0)
return -EINVAL;

- status = proc_reserve_memory(args->args_proc_rsvmem.hprocessor,
+ status = proc_reserve_memory(hprocessor,
args->args_proc_rsvmem.ul_size, &prsv_addr,
pr_ctxt);
if (!status) {
@@ -1010,7 +1015,7 @@ u32 procwrap_start(union trapped_args *args, void *pr_ctxt)
{
u32 ret;

- ret = proc_start(args->args_proc_start.hprocessor);
+ ret = proc_start(((struct process_context *)pr_ctxt)->hprocessor);
return ret;
}

@@ -1021,7 +1026,7 @@ u32 procwrap_un_map(union trapped_args *args, void *pr_ctxt)
{
int status;

- status = proc_un_map(args->args_proc_unmapmem.hprocessor,
+ status = proc_un_map(((struct process_context *)pr_ctxt)->hprocessor,
args->args_proc_unmapmem.map_addr, pr_ctxt);
return status;
}
@@ -1032,8 +1037,9 @@ u32 procwrap_un_map(union trapped_args *args, void *pr_ctxt)
u32 procwrap_un_reserve_memory(union trapped_args *args, void *pr_ctxt)
{
int status;
+ void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;

- status = proc_un_reserve_memory(args->args_proc_unrsvmem.hprocessor,
+ status = proc_un_reserve_memory(hprocessor,
args->args_proc_unrsvmem.prsv_addr,
pr_ctxt);
return status;
@@ -1046,7 +1052,7 @@ u32 procwrap_stop(union trapped_args *args, void *pr_ctxt)
{
u32 ret;

- ret = proc_stop(args->args_proc_stop.hprocessor);
+ ret = proc_stop(((struct process_context *)pr_ctxt)->hprocessor);

return ret;
}
@@ -1078,6 +1084,7 @@ u32 nodewrap_allocate(union trapped_args *args, void *pr_ctxt)
struct dsp_nodeattrin proc_attr_in, *attr_in = NULL;
struct node_res_object *node_res;
int nodeid;
+ void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;

/* Optional argument */
if (psize) {
@@ -1108,7 +1115,7 @@ u32 nodewrap_allocate(union trapped_args *args, void *pr_ctxt)

}
if (!status) {
- status = node_allocate(args->args_node_allocate.hprocessor,
+ status = node_allocate(hprocessor,
&node_uuid, (struct dsp_cbdata *)pargs,
attr_in, &node_res, pr_ctxt);
}
@@ -1493,6 +1500,7 @@ u32 nodewrap_get_uuid_props(union trapped_args *args, void *pr_ctxt)
int status = 0;
struct dsp_uuid node_uuid;
struct dsp_ndbprops *pnode_props = NULL;
+ void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;

CP_FM_USR(&node_uuid, args->args_node_getuuidprops.node_id_ptr, status,
1);
@@ -1501,8 +1509,7 @@ u32 nodewrap_get_uuid_props(union trapped_args *args, void *pr_ctxt)
pnode_props = kmalloc(sizeof(struct dsp_ndbprops), GFP_KERNEL);
if (pnode_props != NULL) {
status =
- node_get_uuid_props(args->args_node_getuuidprops.hprocessor,
- &node_uuid, pnode_props);
+ node_get_uuid_props(hprocessor, &node_uuid, pnode_props);
CP_TO_USR(args->args_node_getuuidprops.node_props, pnode_props,
status, 1);
} else
@@ -1788,8 +1795,9 @@ u32 cmmwrap_get_handle(union trapped_args *args, void *pr_ctxt)
{
int status = 0;
struct cmm_object *hcmm_mgr;
+ void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;

- status = cmm_get_handle(args->args_cmm_gethandle.hprocessor, &hcmm_mgr);
+ status = cmm_get_handle(hprocessor, &hcmm_mgr);

CP_TO_USR(args->args_cmm_gethandle.ph_cmm_mgr, &hcmm_mgr, status, 1);

--
1.5.4.5