Skip to content

Commit

Permalink
staging: ti dspbridge: use stream id instead of kernel address
Browse files Browse the repository at this point in the history
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 <ernesto@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Ernesto Ramos authored and Greg Kroah-Hartman committed Aug 3, 2010
1 parent 6bcc9be commit 4ec0971
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 169 deletions.
5 changes: 2 additions & 3 deletions drivers/staging/tidspbridge/include/dspbridge/drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
};

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
22 changes: 11 additions & 11 deletions drivers/staging/tidspbridge/include/dspbridge/strm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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.
Expand All @@ -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);

/*
Expand Down Expand Up @@ -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:
Expand All @@ -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);

Expand Down Expand Up @@ -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.
Expand All @@ -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);

/*
Expand Down
115 changes: 98 additions & 17 deletions drivers/staging/tidspbridge/pmgr/dspapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,19 @@ u32 nodewrap_get_uuid_props(union trapped_args *args, void *pr_ctxt)
return status;
}

/*
* ======== 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 ========
*/
Expand All @@ -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;
Expand All @@ -1535,15 +1555,15 @@ 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) {
CP_TO_USR(args->args_strm_allocatebuffer.ap_buffer, ap_buffer,
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);
}
}
Expand All @@ -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);
}

/*
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -1609,14 +1643,21 @@ 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;

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);
Expand All @@ -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;
}
Expand All @@ -1646,14 +1692,20 @@ 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;

/* 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,
Expand All @@ -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;

Expand All @@ -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;
}

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Loading

0 comments on commit 4ec0971

Please sign in to comment.