DSPBRIDGE: Use node id instead of kernel address
Subsystems (2)
PATCH 1/1 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 DSP error DSP_EHANDlE is returned.
--- arch/arm/plat-omap/include/dspbridge/drv.h | 6 +- arch/arm/plat-omap/include/dspbridge/node.h | 4 +- .../plat-omap/include/dspbridge/resourcecleanup.h | 5 - drivers/dsp/bridge/pmgr/wcd.c | 158 +++++++++++++++++--- drivers/dsp/bridge/rmgr/drv.c | 150 ++++++------------- drivers/dsp/bridge/rmgr/drv_interface.c | 7 +- drivers/dsp/bridge/rmgr/node.c | 100 +++++++------ 7 files changed, 246 insertions(+), 184 deletions(-)
arch/arm/plat-omap/include/dspbridge/drv.h +3 -3
@@ -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 for DMM mapped memory accounting */
@@ -131,8 +132,7 @@ struct process_context {void *hprocessor;/* DSP Node resources */ -struct node_res_object *node_list; -struct mutex node_mutex; +struct idr *node_idp;/* DMM mapped memory resources */ struct list_head dmm_map_list;
arch/arm/plat-omap/include/dspbridge/node.h +2 -2
@@ -60,7 +60,7 @@ extern dsp_status node_allocate(struct proc_object *hprocessor, OPTIONAL IN CONST struct dsp_cbdata *pargs, OPTIONAL IN CONST struct dsp_nodeattrin *attr_in, - OUT struct node_object **ph_node, + OUT struct node_res_object **noderes, struct process_context *pr_ctxt);/*
@@ -261,7 +261,7 @@ extern dsp_status node_create_mgr(OUT struct node_mgr **phNodeMgr,* Ensures: * DSP_SOK: hnode is invalid. */ -extern dsp_status node_delete (struct node_object *hnode, +extern dsp_status node_delete (struct node_res_object *hnoderes,struct process_context *pr_ctxt);/*
arch/arm/plat-omap/include/dspbridge/resourcecleanup.h +0 -5
@@ -34,16 +34,11 @@ extern dsp_status drv_remove_all_resources(bhandle pPctxt);extern dsp_status drv_remove_proc_context (struct drv_object *hDRVObject,bhandle pr_ctxt); -extern dsp_status drv_get_node_res_element (bhandle hnode,bhandle node_res, -bhandle ctxt); -extern dsp_status drv_insert_node_res_element (bhandle hnode,bhandle node_res,bhandle ctxt);extern void drv_proc_node_update_heap_status (bhandle hNodeRes,s32 status); -extern dsp_status drv_remove_node_res_element (bhandle node_res,bhandle status); -extern void drv_proc_node_update_status (bhandle hNodeRes,s32 status);extern dsp_status drv_proc_update_strm_res (u32 num_bufs,bhandle strm_res);
drivers/dsp/bridge/pmgr/wcd.c +139 -19
308 lines not on this page · raw message
drivers/dsp/bridge/rmgr/drv.c +44 -108
189 lines not on this page · raw message
drivers/dsp/bridge/rmgr/drv_interface.c +6 -1
@@ -506,8 +506,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_idp =mem_calloc (sizeof (struct idr ),MEM_PAGED ); +if (pr_ctxt->node_idp) +idr_init (pr_ctxt->node_idp); +else + status = -ENOMEM ; }else { status = -ENOMEM ; }
drivers/dsp/bridge/rmgr/node.c +53 -47
235 lines not on this page · raw message
Signature · 1 line
1.5.4.5
PATCH 1/1 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.
--- drivers/dsp/bridge/pmgr/wcd.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
drivers/dsp/bridge/pmgr/wcd.c +4 -2
@@ -1028,7 +1028,7 @@ inline void find_node_handle(struct node_res_object **noderes, {rcu_read_lock (); *noderes =idr_find (((struct process_context *)pr_ctxt)->node_idp, - (int )hnode); + (int )hnode -1 );rcu_read_unlock ();return ; }
@@ -1046,6 +1046,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) {
@@ -1081,7 +1082,8 @@ u32 nodewrap_allocate(union Trapped_Args *args, void *pr_ctxt) attr_in, &node_res, pr_ctxt); }if (DSP_SUCCEEDED (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 (DSP_FAILED (status)) { status =DSP_EPOINTER ;
Signature · 1 line
1.5.4.5
PATCH 1/1 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.
--- drivers/dsp/bridge/pmgr/wcd.c | 56 ++++++++++++++++++++++++----------------- 1 files changed, 33 insertions(+), 23 deletions(-)
drivers/dsp/bridge/pmgr/wcd.c +33 -23
@@ -613,6 +613,7 @@ u32 procwrap_ctrl(union Trapped_Args *args, void *pr_ctxt) args->args_proc_ctrl.pargs;u8 *pargs =NULL ;dsp_status status =DSP_SOK ; +void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;if (psize) {if (get_user (cb_data_size, psize)) {
@@ -630,7 +631,7 @@ u32 procwrap_ctrl(union Trapped_Args *args, void *pr_ctxt) cb_data_size); }if (DSP_SUCCEEDED (status)) { - status =proc_ctrl (args->args_proc_ctrl.hprocessor, + status =proc_ctrl (hprocessor, args->args_proc_ctrl.dw_cmd, (struct dsp_cbdata *)pargs); }
@@ -660,11 +661,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 DSP_ESIZE ; - 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);
@@ -683,12 +685,13 @@ u32 procwrap_enum_node_info(union Trapped_Args *args, void *pr_ctxt)u32 procwrap_flush_memory (union Trapped_Args *args,void *pr_ctxt) {dsp_status status; +void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;if (args->args_proc_flushmemory.ul_flags >PROC_WRITEBACK_INVALIDATE_MEM )return DSP_EINVALIDARG ; - status =proc_flush_memory (args->args_proc_flushmemory.hprocessor, + status =proc_flush_memory (hprocessor, args->args_proc_flushmemory.pmpu_addr, args->args_proc_flushmemory.ul_size, args->args_proc_flushmemory.ul_flags);
@@ -701,9 +704,10 @@ u32 procwrap_flush_memory(union Trapped_Args *args, void *pr_ctxt)u32 procwrap_invalidate_memory (union Trapped_Args *args,void *pr_ctxt) {dsp_status status; +void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor; status = -proc_invalidate_memory (args->args_proc_invalidatememory.hprocessor, +proc_invalidate_memory (hprocessor, args->args_proc_invalidatememory.pmpu_addr, args->args_proc_invalidatememory.ul_size);return status;
@@ -716,13 +720,14 @@ u32 procwrap_enum_resources(union Trapped_Args *args, void *pr_ctxt) {dsp_status status =DSP_SOK ;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 DSP_ESIZE ; 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.
@@ -742,13 +747,13 @@ u32 procwrap_get_state(union Trapped_Args *args, void *pr_ctxt) {dsp_status 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 DSP_ESIZE ; - 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 );
@@ -763,14 +768,14 @@ u32 procwrap_get_trace(union Trapped_Args *args, void *pr_ctxt) {dsp_status status;u8 *pbuf; +void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;if (args->args_proc_gettrace.max_size >MAX_TRACEBUFLEN )return DSP_ESIZE ; pbuf =mem_calloc (args->args_proc_gettrace.max_size,MEM_NONPAGED );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 =DSP_EMEMORY ;
@@ -792,6 +797,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 =DSP_EINVALIDARG ;
@@ -874,7 +880,7 @@ u32 procwrap_load(union Trapped_Args *args, void *pr_ctxt) }if (DSP_SUCCEEDED (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); }
@@ -905,6 +911,7 @@ u32 procwrap_map(union Trapped_Args *args, void *pr_ctxt) {dsp_status status;void *map_addr; +void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;if (!args->args_proc_mapmem.ul_size)return DSP_ESIZE ;
@@ -917,8 +924,7 @@ u32 procwrap_map(union Trapped_Args *args, void *pr_ctxt)if (DSP_SUCCEEDED (status)) {if (put_user (map_addr, args->args_proc_mapmem.pp_map_addr)) { status =DSP_EINVALIDARG ; -proc_un_map (args->args_proc_mapmem.hprocessor, - map_addr, pr_ctxt); +proc_un_map (hprocessor, map_addr, pr_ctxt); } }
@@ -932,13 +938,13 @@ u32 procwrap_register_notify(union Trapped_Args *args, void *pr_ctxt) {dsp_status 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, ¬ification);
@@ -954,12 +960,13 @@ u32 procwrap_reserve_memory(union Trapped_Args *args, void *pr_ctxt) {dsp_status 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 DSP_ESIZE ; - 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 (DSP_SUCCEEDED (status)) {
@@ -979,7 +986,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; }
@@ -990,7 +997,7 @@ u32 procwrap_un_map(union Trapped_Args *args, void *pr_ctxt) {dsp_status 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; }
@@ -1001,8 +1008,9 @@ u32 procwrap_un_map(union Trapped_Args *args, void *pr_ctxt)u32 procwrap_un_reserve_memory (union Trapped_Args *args,void *pr_ctxt) {dsp_status 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;
@@ -1015,7 +1023,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; }
@@ -1047,6 +1055,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) {
@@ -1077,7 +1086,7 @@ u32 nodewrap_allocate(union Trapped_Args *args, void *pr_ctxt) }if (DSP_SUCCEEDED (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); }
@@ -1462,6 +1471,7 @@ u32 nodewrap_get_uuid_props(union Trapped_Args *args, void *pr_ctxt)dsp_status status =DSP_SOK ;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 );
@@ -1470,8 +1480,7 @@ u32 nodewrap_get_uuid_props(union Trapped_Args *args, void *pr_ctxt) pnode_props =mem_alloc (sizeof (struct dsp_ndbprops ),MEM_NONPAGED );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
@@ -1753,8 +1762,9 @@ u32 cmmwrap_get_handle(union Trapped_Args *args, void *pr_ctxt) {dsp_status status =DSP_SOK ;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 );
Signature · 1 line
1.5.4.5
PATCH 1/1 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.
--- arch/arm/plat-omap/include/dspbridge/drv.h | 5 +- .../plat-omap/include/dspbridge/resourcecleanup.h | 6 - arch/arm/plat-omap/include/dspbridge/strm.h | 8 +- drivers/dsp/bridge/pmgr/wcd.c | 115 +++++++++++++--- drivers/dsp/bridge/rmgr/drv.c | 151 +++++++------------- drivers/dsp/bridge/rmgr/drv_interface.c | 13 ++- drivers/dsp/bridge/rmgr/strm.c | 75 +++++----- 7 files changed, 198 insertions(+), 175 deletions(-)
arch/arm/plat-omap/include/dspbridge/drv.h +2 -3
@@ -114,7 +114,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 */
@@ -146,8 +146,7 @@ struct process_context {struct dspheap_res_object *pdspheap_list;/* Stream resources */ -struct strm_res_object *pstrm_list; -struct mutex strm_mutex; +struct idr *strm_idp; };/*
arch/arm/plat-omap/include/dspbridge/resourcecleanup.h +0 -6
@@ -47,12 +47,6 @@ extern dsp_status drv_proc_insert_strm_res_element(bhandle hStrm,bhandle strm_res, bhandle pPctxt); -extern dsp_status drv_get_strm_res_element (bhandle hStrm,bhandle strm_res, -bhandle ctxt); - -extern dsp_status drv_proc_remove_strm_res_element (bhandle strm_res, -bhandle ctxt); -extern dsp_status drv_remove_all_strm_res_elements (bhandle ctxt);extern enum node_state node_get_state (bhandle hnode);
arch/arm/plat-omap/include/dspbridge/strm.h +4 -4
@@ -44,7 +44,7 @@* ap_buffer != NULL. * Ensures: */ -extern dsp_status strm_allocate_buffer(struct strm_object *hStrm, +extern dsp_status strm_allocate_buffer(struct strm_res_object *strmres, u32 usize, OUT u8 **ap_buffer, u32 num_bufs,
@@ -66,7 +66,7 @@ extern dsp_status strm_allocate_buffer(struct strm_object *hStrm,* strm_init(void) called. * Ensures: */ -extern dsp_status strm_close (struct strm_object *hStrm, +extern dsp_status strm_close (struct strm_res_object *strmres,struct process_context *pr_ctxt);/*
@@ -137,7 +137,7 @@ extern void strm_exit(void);* ap_buffer != NULL. * Ensures: */ -extern dsp_status strm_free_buffer (struct strm_object *hStrm, +extern dsp_status strm_free_buffer (struct strm_res_object *strmres,u8 **ap_buffer,u32 num_bufs,struct process_context *pr_ctxt);
@@ -273,7 +273,7 @@ extern dsp_status strm_issue(struct strm_object *hStrm, IN u8 * pbuf,*/ extern dsp_status strm_open (struct node_object *hnode,u32 dir, u32 index, IN struct strm_attr *pattr, - OUT struct strm_object **phStrm, + OUT struct strm_res_object **strmres,struct process_context *pr_ctxt);/*
drivers/dsp/bridge/pmgr/wcd.c +98 -17
230 lines not on this page · raw message
drivers/dsp/bridge/rmgr/drv.c +48 -101
183 lines not on this page · raw message
drivers/dsp/bridge/rmgr/drv_interface.c +10 -3
@@ -506,17 +506,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_idp =mem_calloc (sizeof (struct idr ),MEM_PAGED ); -if (pr_ctxt->node_idp) +if (pr_ctxt->node_idp) {idr_init (pr_ctxt->node_idp); + }else { + status = -ENOMEM ; + goto err; + } + + pr_ctxt->strm_idp =mem_calloc (sizeof (struct idr ),MEM_PAGED ); +if (pr_ctxt->strm_idp) +idr_init (pr_ctxt->strm_idp);else status = -ENOMEM ; }else { status = -ENOMEM ; } - +err: filp->private_data = pr_ctxt;#ifdef CONFIG_BRIDGE_RECOVERY if (!status)
drivers/dsp/bridge/rmgr/strm.c +35 -40
195 lines not on this page · raw message
Signature · 1 line
1.5.4.5
PATCH 1/1 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.
--- drivers/dsp/bridge/pmgr/wcd.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
drivers/dsp/bridge/pmgr/wcd.c +6 -2
@@ -1498,7 +1498,7 @@ inline void find_strm_handle(struct strm_res_object **strmres, {rcu_read_lock (); *strmres =idr_find (((struct process_context *)pr_ctxt)->strm_idp, - (int )hstream); + (int )hstream -1 );rcu_read_unlock ();return ; }
@@ -1691,6 +1691,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);
@@ -1712,7 +1713,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 (DSP_SUCCEEDED (status)) { + strmid = strm_res_obj->id +1 ; +CP_TO_USR (args->args_strm_open.ph_stream, &strmid, status,1 ); + }return status; }
Signature · 1 line
1.5.4.5