aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErnesto Ramos <ernesto@ti.com>2010-07-28 17:04:56 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2010-08-02 20:11:03 -0400
commit4ec09714a0a5861c3e786967024ddfff00b0add6 (patch)
tree1004c64c1886e958f4a284a72f0f7770e75cdaed
parent6bcc9beed2d46c0db479a3750af4b2cbd7a92401 (diff)
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 <ernesto@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/staging/tidspbridge/include/dspbridge/drv.h5
-rw-r--r--drivers/staging/tidspbridge/include/dspbridge/resourcecleanup.h6
-rw-r--r--drivers/staging/tidspbridge/include/dspbridge/strm.h22
-rw-r--r--drivers/staging/tidspbridge/pmgr/dspapi.c115
-rw-r--r--drivers/staging/tidspbridge/rmgr/drv.c146
-rw-r--r--drivers/staging/tidspbridge/rmgr/drv_interface.c13
-rw-r--r--drivers/staging/tidspbridge/rmgr/strm.c54
7 files changed, 192 insertions, 169 deletions
diff --git a/drivers/staging/tidspbridge/include/dspbridge/drv.h b/drivers/staging/tidspbridge/include/dspbridge/drv.h
index 0b36a11820b5..f3650153ef35 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 {
131 void *hstream; 131 void *hstream;
132 u32 num_bufs; 132 u32 num_bufs;
133 u32 dir; 133 u32 dir;
134 struct strm_res_object *next; 134 int id;
135}; 135};
136 136
137/* Overall Bridge process resource usage state */ 137/* Overall Bridge process resource usage state */
@@ -173,8 +173,7 @@ struct process_context {
173 struct dspheap_res_object *pdspheap_list; 173 struct dspheap_res_object *pdspheap_list;
174 174
175 /* Stream resources */ 175 /* Stream resources */
176 struct strm_res_object *pstrm_list; 176 struct idr *stream_id;
177 struct mutex strm_mutex;
178}; 177};
179 178
180/* 179/*
diff --git a/drivers/staging/tidspbridge/include/dspbridge/resourcecleanup.h b/drivers/staging/tidspbridge/include/dspbridge/resourcecleanup.h
index d17c7fb69d92..dfaf0c6c06f1 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,
47 void *strm_res, 47 void *strm_res,
48 void *process_ctxt); 48 void *process_ctxt);
49 49
50extern int drv_get_strm_res_element(void *stream_obj, void *strm_resources,
51 void *process_ctxt);
52
53extern int drv_proc_remove_strm_res_element(void *strm_res,
54 void *process_ctxt);
55
56extern int drv_remove_all_strm_res_elements(void *process_ctxt); 50extern int drv_remove_all_strm_res_elements(void *process_ctxt);
57 51
58extern enum node_state node_get_state(void *hnode); 52extern 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 0ddc7979e796..3e4671e7f91b 100644
--- a/drivers/staging/tidspbridge/include/dspbridge/strm.h
+++ b/drivers/staging/tidspbridge/include/dspbridge/strm.h
@@ -29,7 +29,7 @@
29 * Purpose: 29 * Purpose:
30 * Allocate data buffer(s) for use with a stream. 30 * Allocate data buffer(s) for use with a stream.
31 * Parameter: 31 * Parameter:
32 * stream_obj: Stream handle returned from strm_open(). 32 * strmres: Stream resource info handle returned from strm_open().
33 * usize: Size (GPP bytes) of the buffer(s). 33 * usize: Size (GPP bytes) of the buffer(s).
34 * num_bufs: Number of buffers to allocate. 34 * num_bufs: Number of buffers to allocate.
35 * ap_buffer: Array to hold buffer addresses. 35 * ap_buffer: Array to hold buffer addresses.
@@ -44,7 +44,7 @@
44 * ap_buffer != NULL. 44 * ap_buffer != NULL.
45 * Ensures: 45 * Ensures:
46 */ 46 */
47extern int strm_allocate_buffer(struct strm_object *stream_obj, 47extern int strm_allocate_buffer(struct strm_res_object *strmres,
48 u32 usize, 48 u32 usize,
49 u8 **ap_buffer, 49 u8 **ap_buffer,
50 u32 num_bufs, 50 u32 num_bufs,
@@ -55,7 +55,7 @@ extern int strm_allocate_buffer(struct strm_object *stream_obj,
55 * Purpose: 55 * Purpose:
56 * Close a stream opened with strm_open(). 56 * Close a stream opened with strm_open().
57 * Parameter: 57 * Parameter:
58 * stream_obj: Stream handle returned from strm_open(). 58 * strmres: Stream resource info handle returned from strm_open().
59 * Returns: 59 * Returns:
60 * 0: Success. 60 * 0: Success.
61 * -EFAULT: Invalid stream_obj. 61 * -EFAULT: Invalid stream_obj.
@@ -66,7 +66,7 @@ extern int strm_allocate_buffer(struct strm_object *stream_obj,
66 * strm_init(void) called. 66 * strm_init(void) called.
67 * Ensures: 67 * Ensures:
68 */ 68 */
69extern int strm_close(struct strm_object *stream_obj, 69extern int strm_close(struct strm_res_object *strmres,
70 struct process_context *pr_ctxt); 70 struct process_context *pr_ctxt);
71 71
72/* 72/*
@@ -125,7 +125,7 @@ extern void strm_exit(void);
125 * Purpose: 125 * Purpose:
126 * Free buffer(s) allocated with strm_allocate_buffer. 126 * Free buffer(s) allocated with strm_allocate_buffer.
127 * Parameter: 127 * Parameter:
128 * stream_obj: Stream handle returned from strm_open(). 128 * strmres: Stream resource info handle returned from strm_open().
129 * ap_buffer: Array containing buffer addresses. 129 * ap_buffer: Array containing buffer addresses.
130 * num_bufs: Number of buffers to be freed. 130 * num_bufs: Number of buffers to be freed.
131 * Returns: 131 * Returns:
@@ -137,7 +137,7 @@ extern void strm_exit(void);
137 * ap_buffer != NULL. 137 * ap_buffer != NULL.
138 * Ensures: 138 * Ensures:
139 */ 139 */
140extern int strm_free_buffer(struct strm_object *stream_obj, 140extern int strm_free_buffer(struct strm_res_object *strmres,
141 u8 **ap_buffer, u32 num_bufs, 141 u8 **ap_buffer, u32 num_bufs,
142 struct process_context *pr_ctxt); 142 struct process_context *pr_ctxt);
143 143
@@ -254,7 +254,7 @@ extern int strm_issue(struct strm_object *stream_obj, u8 * pbuf,
254 * index: Stream index. 254 * index: Stream index.
255 * pattr: Pointer to structure containing attributes to be 255 * pattr: Pointer to structure containing attributes to be
256 * applied to stream. Cannot be NULL. 256 * applied to stream. Cannot be NULL.
257 * strm_objct: Location to store stream handle on output. 257 * strmres: Location to store stream resuorce info handle on output.
258 * Returns: 258 * Returns:
259 * 0: Success. 259 * 0: Success.
260 * -EFAULT: Invalid hnode. 260 * -EFAULT: Invalid hnode.
@@ -264,15 +264,15 @@ extern int strm_issue(struct strm_object *stream_obj, u8 * pbuf,
264 * -EINVAL: Invalid index. 264 * -EINVAL: Invalid index.
265 * Requires: 265 * Requires:
266 * strm_init(void) called. 266 * strm_init(void) called.
267 * strm_objct != NULL. 267 * strmres != NULL.
268 * pattr != NULL. 268 * pattr != NULL.
269 * Ensures: 269 * Ensures:
270 * 0: *strm_objct is valid. 270 * 0: *strmres is valid.
271 * error: *strm_objct == NULL. 271 * error: *strmres == NULL.
272 */ 272 */
273extern int strm_open(struct node_object *hnode, u32 dir, 273extern int strm_open(struct node_object *hnode, u32 dir,
274 u32 index, struct strm_attr *pattr, 274 u32 index, struct strm_attr *pattr,
275 struct strm_object **strm_objct, 275 struct strm_res_object **strmres,
276 struct process_context *pr_ctxt); 276 struct process_context *pr_ctxt);
277 277
278/* 278/*
diff --git a/drivers/staging/tidspbridge/pmgr/dspapi.c b/drivers/staging/tidspbridge/pmgr/dspapi.c
index d7613eb49dad..47892dd47388 100644
--- a/drivers/staging/tidspbridge/pmgr/dspapi.c
+++ b/drivers/staging/tidspbridge/pmgr/dspapi.c
@@ -1520,6 +1520,19 @@ func_cont:
1520} 1520}
1521 1521
1522/* 1522/*
1523 * ======== find_strm_handle =========
1524 */
1525inline void find_strm_handle(struct strm_res_object **strmres,
1526 void *pr_ctxt, void *hstream)
1527{
1528 rcu_read_lock();
1529 *strmres = idr_find(((struct process_context *)pr_ctxt)->stream_id,
1530 (int)hstream);
1531 rcu_read_unlock();
1532 return;
1533}
1534
1535/*
1523 * ======== strmwrap_allocate_buffer ======== 1536 * ======== strmwrap_allocate_buffer ========
1524 */ 1537 */
1525u32 strmwrap_allocate_buffer(union trapped_args *args, void *pr_ctxt) 1538u32 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)
1527 int status; 1540 int status;
1528 u8 **ap_buffer = NULL; 1541 u8 **ap_buffer = NULL;
1529 u32 num_bufs = args->args_strm_allocatebuffer.num_bufs; 1542 u32 num_bufs = args->args_strm_allocatebuffer.num_bufs;
1543 struct strm_res_object *strm_res;
1544
1545 find_strm_handle(&strm_res, pr_ctxt,
1546 args->args_strm_allocatebuffer.hstream);
1547
1548 if (!strm_res)
1549 return -EFAULT;
1530 1550
1531 if (num_bufs > MAX_BUFS) 1551 if (num_bufs > MAX_BUFS)
1532 return -EINVAL; 1552 return -EINVAL;
@@ -1535,7 +1555,7 @@ u32 strmwrap_allocate_buffer(union trapped_args *args, void *pr_ctxt)
1535 if (ap_buffer == NULL) 1555 if (ap_buffer == NULL)
1536 return -ENOMEM; 1556 return -ENOMEM;
1537 1557
1538 status = strm_allocate_buffer(args->args_strm_allocatebuffer.hstream, 1558 status = strm_allocate_buffer(strm_res,
1539 args->args_strm_allocatebuffer.usize, 1559 args->args_strm_allocatebuffer.usize,
1540 ap_buffer, num_bufs, pr_ctxt); 1560 ap_buffer, num_bufs, pr_ctxt);
1541 if (!status) { 1561 if (!status) {
@@ -1543,7 +1563,7 @@ u32 strmwrap_allocate_buffer(union trapped_args *args, void *pr_ctxt)
1543 status, num_bufs); 1563 status, num_bufs);
1544 if (status) { 1564 if (status) {
1545 status = -EFAULT; 1565 status = -EFAULT;
1546 strm_free_buffer(args->args_strm_allocatebuffer.hstream, 1566 strm_free_buffer(strm_res,
1547 ap_buffer, num_bufs, pr_ctxt); 1567 ap_buffer, num_bufs, pr_ctxt);
1548 } 1568 }
1549 } 1569 }
@@ -1557,7 +1577,14 @@ u32 strmwrap_allocate_buffer(union trapped_args *args, void *pr_ctxt)
1557 */ 1577 */
1558u32 strmwrap_close(union trapped_args *args, void *pr_ctxt) 1578u32 strmwrap_close(union trapped_args *args, void *pr_ctxt)
1559{ 1579{
1560 return strm_close(args->args_strm_close.hstream, pr_ctxt); 1580 struct strm_res_object *strm_res;
1581
1582 find_strm_handle(&strm_res, pr_ctxt, args->args_strm_close.hstream);
1583
1584 if (!strm_res)
1585 return -EFAULT;
1586
1587 return strm_close(strm_res, pr_ctxt);
1561} 1588}
1562 1589
1563/* 1590/*
@@ -1568,6 +1595,13 @@ u32 strmwrap_free_buffer(union trapped_args *args, void *pr_ctxt)
1568 int status = 0; 1595 int status = 0;
1569 u8 **ap_buffer = NULL; 1596 u8 **ap_buffer = NULL;
1570 u32 num_bufs = args->args_strm_freebuffer.num_bufs; 1597 u32 num_bufs = args->args_strm_freebuffer.num_bufs;
1598 struct strm_res_object *strm_res;
1599
1600 find_strm_handle(&strm_res, pr_ctxt,
1601 args->args_strm_freebuffer.hstream);
1602
1603 if (!strm_res)
1604 return -EFAULT;
1571 1605
1572 if (num_bufs > MAX_BUFS) 1606 if (num_bufs > MAX_BUFS)
1573 return -EINVAL; 1607 return -EINVAL;
@@ -1579,10 +1613,10 @@ u32 strmwrap_free_buffer(union trapped_args *args, void *pr_ctxt)
1579 CP_FM_USR(ap_buffer, args->args_strm_freebuffer.ap_buffer, status, 1613 CP_FM_USR(ap_buffer, args->args_strm_freebuffer.ap_buffer, status,
1580 num_bufs); 1614 num_bufs);
1581 1615
1582 if (!status) { 1616 if (!status)
1583 status = strm_free_buffer(args->args_strm_freebuffer.hstream, 1617 status = strm_free_buffer(strm_res,
1584 ap_buffer, num_bufs, pr_ctxt); 1618 ap_buffer, num_bufs, pr_ctxt);
1585 } 1619
1586 CP_TO_USR(args->args_strm_freebuffer.ap_buffer, ap_buffer, status, 1620 CP_TO_USR(args->args_strm_freebuffer.ap_buffer, ap_buffer, status,
1587 num_bufs); 1621 num_bufs);
1588 kfree(ap_buffer); 1622 kfree(ap_buffer);
@@ -1609,6 +1643,13 @@ u32 strmwrap_get_info(union trapped_args *args, void *pr_ctxt)
1609 struct stream_info strm_info; 1643 struct stream_info strm_info;
1610 struct dsp_streaminfo user; 1644 struct dsp_streaminfo user;
1611 struct dsp_streaminfo *temp; 1645 struct dsp_streaminfo *temp;
1646 struct strm_res_object *strm_res;
1647
1648 find_strm_handle(&strm_res, pr_ctxt,
1649 args->args_strm_getinfo.hstream);
1650
1651 if (!strm_res)
1652 return -EFAULT;
1612 1653
1613 CP_FM_USR(&strm_info, args->args_strm_getinfo.stream_info, status, 1); 1654 CP_FM_USR(&strm_info, args->args_strm_getinfo.stream_info, status, 1);
1614 temp = strm_info.user_strm; 1655 temp = strm_info.user_strm;
@@ -1616,7 +1657,7 @@ u32 strmwrap_get_info(union trapped_args *args, void *pr_ctxt)
1616 strm_info.user_strm = &user; 1657 strm_info.user_strm = &user;
1617 1658
1618 if (!status) { 1659 if (!status) {
1619 status = strm_get_info(args->args_strm_getinfo.hstream, 1660 status = strm_get_info(strm_res->hstream,
1620 &strm_info, 1661 &strm_info,
1621 args->args_strm_getinfo. 1662 args->args_strm_getinfo.
1622 stream_info_size); 1663 stream_info_size);
@@ -1633,9 +1674,14 @@ u32 strmwrap_get_info(union trapped_args *args, void *pr_ctxt)
1633u32 strmwrap_idle(union trapped_args *args, void *pr_ctxt) 1674u32 strmwrap_idle(union trapped_args *args, void *pr_ctxt)
1634{ 1675{
1635 u32 ret; 1676 u32 ret;
1677 struct strm_res_object *strm_res;
1678
1679 find_strm_handle(&strm_res, pr_ctxt, args->args_strm_idle.hstream);
1636 1680
1637 ret = strm_idle(args->args_strm_idle.hstream, 1681 if (!strm_res)
1638 args->args_strm_idle.flush_flag); 1682 return -EFAULT;
1683
1684 ret = strm_idle(strm_res->hstream, args->args_strm_idle.flush_flag);
1639 1685
1640 return ret; 1686 return ret;
1641} 1687}
@@ -1646,6 +1692,12 @@ u32 strmwrap_idle(union trapped_args *args, void *pr_ctxt)
1646u32 strmwrap_issue(union trapped_args *args, void *pr_ctxt) 1692u32 strmwrap_issue(union trapped_args *args, void *pr_ctxt)
1647{ 1693{
1648 int status = 0; 1694 int status = 0;
1695 struct strm_res_object *strm_res;
1696
1697 find_strm_handle(&strm_res, pr_ctxt, args->args_strm_issue.hstream);
1698
1699 if (!strm_res)
1700 return -EFAULT;
1649 1701
1650 if (!args->args_strm_issue.pbuffer) 1702 if (!args->args_strm_issue.pbuffer)
1651 return -EFAULT; 1703 return -EFAULT;
@@ -1653,7 +1705,7 @@ u32 strmwrap_issue(union trapped_args *args, void *pr_ctxt)
1653 /* No need of doing CP_FM_USR for the user buffer (pbuffer) 1705 /* No need of doing CP_FM_USR for the user buffer (pbuffer)
1654 as this is done in Bridge internal function bridge_chnl_add_io_req 1706 as this is done in Bridge internal function bridge_chnl_add_io_req
1655 in chnl_sm.c */ 1707 in chnl_sm.c */
1656 status = strm_issue(args->args_strm_issue.hstream, 1708 status = strm_issue(strm_res->hstream,
1657 args->args_strm_issue.pbuffer, 1709 args->args_strm_issue.pbuffer,
1658 args->args_strm_issue.dw_bytes, 1710 args->args_strm_issue.dw_bytes,
1659 args->args_strm_issue.dw_buf_size, 1711 args->args_strm_issue.dw_buf_size,
@@ -1669,7 +1721,7 @@ u32 strmwrap_open(union trapped_args *args, void *pr_ctxt)
1669{ 1721{
1670 int status = 0; 1722 int status = 0;
1671 struct strm_attr attr; 1723 struct strm_attr attr;
1672 struct strm_object *strm_obj; 1724 struct strm_res_object *strm_res_obj;
1673 struct dsp_streamattrin strm_attr_in; 1725 struct dsp_streamattrin strm_attr_in;
1674 struct node_res_object *node_res; 1726 struct node_res_object *node_res;
1675 1727
@@ -1691,9 +1743,9 @@ u32 strmwrap_open(union trapped_args *args, void *pr_ctxt)
1691 } 1743 }
1692 status = strm_open(node_res->hnode, 1744 status = strm_open(node_res->hnode,
1693 args->args_strm_open.direction, 1745 args->args_strm_open.direction,
1694 args->args_strm_open.index, &attr, &strm_obj, 1746 args->args_strm_open.index, &attr, &strm_res_obj,
1695 pr_ctxt); 1747 pr_ctxt);
1696 CP_TO_USR(args->args_strm_open.ph_stream, &strm_obj, status, 1); 1748 CP_TO_USR(args->args_strm_open.ph_stream, &strm_res_obj->id, status, 1);
1697 return status; 1749 return status;
1698} 1750}
1699 1751
@@ -1707,8 +1759,14 @@ u32 strmwrap_reclaim(union trapped_args *args, void *pr_ctxt)
1707 u32 ul_bytes; 1759 u32 ul_bytes;
1708 u32 dw_arg; 1760 u32 dw_arg;
1709 u32 ul_buf_size; 1761 u32 ul_buf_size;
1762 struct strm_res_object *strm_res;
1763
1764 find_strm_handle(&strm_res, pr_ctxt, args->args_strm_reclaim.hstream);
1765
1766 if (!strm_res)
1767 return -EFAULT;
1710 1768
1711 status = strm_reclaim(args->args_strm_reclaim.hstream, &buf_ptr, 1769 status = strm_reclaim(strm_res->hstream, &buf_ptr,
1712 &ul_bytes, &ul_buf_size, &dw_arg); 1770 &ul_bytes, &ul_buf_size, &dw_arg);
1713 CP_TO_USR(args->args_strm_reclaim.buf_ptr, &buf_ptr, status, 1); 1771 CP_TO_USR(args->args_strm_reclaim.buf_ptr, &buf_ptr, status, 1);
1714 CP_TO_USR(args->args_strm_reclaim.bytes, &ul_bytes, status, 1); 1772 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)
1729{ 1787{
1730 int status = 0; 1788 int status = 0;
1731 struct dsp_notification notification; 1789 struct dsp_notification notification;
1790 struct strm_res_object *strm_res;
1791
1792 find_strm_handle(&strm_res, pr_ctxt,
1793 args->args_strm_registernotify.hstream);
1794
1795 if (!strm_res)
1796 return -EFAULT;
1732 1797
1733 /* Initialize the notification data structure */ 1798 /* Initialize the notification data structure */
1734 notification.ps_name = NULL; 1799 notification.ps_name = NULL;
1735 notification.handle = NULL; 1800 notification.handle = NULL;
1736 1801
1737 status = strm_register_notify(args->args_strm_registernotify.hstream, 1802 status = strm_register_notify(strm_res->hstream,
1738 args->args_strm_registernotify.event_mask, 1803 args->args_strm_registernotify.event_mask,
1739 args->args_strm_registernotify. 1804 args->args_strm_registernotify.
1740 notify_type, &notification); 1805 notify_type, &notification);
@@ -1752,12 +1817,28 @@ u32 strmwrap_select(union trapped_args *args, void *pr_ctxt)
1752 u32 mask; 1817 u32 mask;
1753 struct strm_object *strm_tab[MAX_STREAMS]; 1818 struct strm_object *strm_tab[MAX_STREAMS];
1754 int status = 0; 1819 int status = 0;
1820 struct strm_res_object *strm_res;
1821 int *ids[MAX_STREAMS];
1822 int i;
1755 1823
1756 if (args->args_strm_select.strm_num > MAX_STREAMS) 1824 if (args->args_strm_select.strm_num > MAX_STREAMS)
1757 return -EINVAL; 1825 return -EINVAL;
1758 1826
1759 CP_FM_USR(strm_tab, args->args_strm_select.stream_tab, status, 1827 CP_FM_USR(ids, args->args_strm_select.stream_tab, status,
1760 args->args_strm_select.strm_num); 1828 args->args_strm_select.strm_num);
1829
1830 if (status)
1831 return status;
1832
1833 for (i = 0; i < args->args_strm_select.strm_num; i++) {
1834 find_strm_handle(&strm_res, pr_ctxt, ids[i]);
1835
1836 if (!strm_res)
1837 return -EFAULT;
1838
1839 strm_tab[i] = strm_res->hstream;
1840 }
1841
1761 if (!status) { 1842 if (!status) {
1762 status = strm_select(strm_tab, args->args_strm_select.strm_num, 1843 status = strm_select(strm_tab, args->args_strm_select.strm_num,
1763 &mask, args->args_strm_select.utimeout); 1844 &mask, args->args_strm_select.utimeout);
diff --git a/drivers/staging/tidspbridge/rmgr/drv.c b/drivers/staging/tidspbridge/rmgr/drv.c
index c8d9d2551ff0..8a8dea6efeda 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,
211 (struct strm_res_object **)strm_res; 211 (struct strm_res_object **)strm_res;
212 struct process_context *ctxt = (struct process_context *)process_ctxt; 212 struct process_context *ctxt = (struct process_context *)process_ctxt;
213 int status = 0; 213 int status = 0;
214 struct strm_res_object *temp_strm_res = NULL; 214 int retval;
215 215
216 *pstrm_res = kzalloc(sizeof(struct strm_res_object), GFP_KERNEL); 216 *pstrm_res = kzalloc(sizeof(struct strm_res_object), GFP_KERNEL);
217 if (*pstrm_res == NULL) 217 if (*pstrm_res == NULL) {
218 status = -EFAULT; 218 status = -EFAULT;
219 goto func_end;
220 }
219 221
220 if (!status) { 222 (*pstrm_res)->hstream = stream_obj;
221 if (mutex_lock_interruptible(&ctxt->strm_mutex)) { 223 retval = idr_get_new(ctxt->stream_id, *pstrm_res,
222 kfree(*pstrm_res); 224 &(*pstrm_res)->id);
223 return -EPERM; 225 if (retval == -EAGAIN) {
226 if (!idr_pre_get(ctxt->stream_id, GFP_KERNEL)) {
227 pr_err("%s: OUT OF MEMORY\n", __func__);
228 status = -ENOMEM;
229 goto func_end;
224 } 230 }
225 (*pstrm_res)->hstream = stream_obj;
226 if (ctxt->pstrm_list != NULL) {
227 temp_strm_res = ctxt->pstrm_list;
228 while (temp_strm_res->next != NULL)
229 temp_strm_res = temp_strm_res->next;
230 231
231 temp_strm_res->next = *pstrm_res; 232 retval = idr_get_new(ctxt->stream_id, *pstrm_res,
232 } else { 233 &(*pstrm_res)->id);
233 ctxt->pstrm_list = *pstrm_res;
234 }
235 mutex_unlock(&ctxt->strm_mutex);
236 } 234 }
237 return status; 235 if (retval) {
238} 236 pr_err("%s: FAILED, IDR is FULL\n", __func__);
239 237 status = -EPERM;
240/* Release Stream resource element context
241* This function called after the actual resource is freed
242 */
243int drv_proc_remove_strm_res_element(void *strm_res, void *process_ctxt)
244{
245 struct strm_res_object *pstrm_res = (struct strm_res_object *)strm_res;
246 struct process_context *ctxt = (struct process_context *)process_ctxt;
247 struct strm_res_object *temp_strm_res;
248 int status = 0;
249
250 if (mutex_lock_interruptible(&ctxt->strm_mutex))
251 return -EPERM;
252 temp_strm_res = ctxt->pstrm_list;
253
254 if (ctxt->pstrm_list == pstrm_res) {
255 ctxt->pstrm_list = pstrm_res->next;
256 } else {
257 while (temp_strm_res && temp_strm_res->next != pstrm_res)
258 temp_strm_res = temp_strm_res->next;
259 if (temp_strm_res == NULL)
260 status = -ENOENT;
261 else
262 temp_strm_res->next = pstrm_res->next;
263 } 238 }
264 mutex_unlock(&ctxt->strm_mutex); 239
265 kfree(pstrm_res); 240func_end:
266 return status; 241 return status;
267} 242}
268 243
269/* Release all Stream resources and its context 244static int drv_proc_free_strm_res(int id, void *p, void *process_ctxt)
270* This is called from .bridge_release.
271 */
272int drv_remove_all_strm_res_elements(void *process_ctxt)
273{ 245{
274 struct process_context *ctxt = (struct process_context *)process_ctxt; 246 struct process_context *ctxt = process_ctxt;
275 int status = 0; 247 struct strm_res_object *strm_res = p;
276 struct strm_res_object *strm_res = NULL;
277 struct strm_res_object *strm_tmp = NULL;
278 struct stream_info strm_info; 248 struct stream_info strm_info;
279 struct dsp_streaminfo user; 249 struct dsp_streaminfo user;
280 u8 **ap_buffer = NULL; 250 u8 **ap_buffer = NULL;
@@ -283,60 +253,38 @@ int drv_remove_all_strm_res_elements(void *process_ctxt)
283 u32 dw_arg; 253 u32 dw_arg;
284 s32 ul_buf_size; 254 s32 ul_buf_size;
285 255
286 strm_tmp = ctxt->pstrm_list; 256 if (strm_res->num_bufs) {
287 while (strm_tmp) { 257 ap_buffer = kmalloc((strm_res->num_bufs *
288 strm_res = strm_tmp; 258 sizeof(u8 *)), GFP_KERNEL);
289 strm_tmp = strm_tmp->next; 259 if (ap_buffer) {
290 if (strm_res->num_bufs) { 260 strm_free_buffer(strm_res,
291 ap_buffer = kmalloc((strm_res->num_bufs * 261 ap_buffer,
292 sizeof(u8 *)), GFP_KERNEL); 262 strm_res->num_bufs,
293 if (ap_buffer) { 263 ctxt);
294 status = strm_free_buffer(strm_res->hstream, 264 kfree(ap_buffer);
295 ap_buffer,
296 strm_res->num_bufs,
297 ctxt);
298 kfree(ap_buffer);
299 }
300 } 265 }
301 strm_info.user_strm = &user;
302 user.number_bufs_in_stream = 0;
303 strm_get_info(strm_res->hstream, &strm_info, sizeof(strm_info));
304 while (user.number_bufs_in_stream--)
305 strm_reclaim(strm_res->hstream, &buf_ptr, &ul_bytes,
306 (u32 *) &ul_buf_size, &dw_arg);
307 status = strm_close(strm_res->hstream, ctxt);
308 } 266 }
309 return status; 267 strm_info.user_strm = &user;
268 user.number_bufs_in_stream = 0;
269 strm_get_info(strm_res->hstream, &strm_info, sizeof(strm_info));
270 while (user.number_bufs_in_stream--)
271 strm_reclaim(strm_res->hstream, &buf_ptr, &ul_bytes,
272 (u32 *) &ul_buf_size, &dw_arg);
273 strm_close(strm_res, ctxt);
274 return 0;
310} 275}
311 276
312/* Getting the stream resource element */ 277/* Release all Stream resources and its context
313int drv_get_strm_res_element(void *stream_obj, void *strm_resources, 278* This is called from .bridge_release.
314 void *process_ctxt) 279 */
280int drv_remove_all_strm_res_elements(void *process_ctxt)
315{ 281{
316 struct strm_res_object **strm_res = 282 struct process_context *ctxt = process_ctxt;
317 (struct strm_res_object **)strm_resources;
318 struct process_context *ctxt = (struct process_context *)process_ctxt;
319 int status = 0;
320 struct strm_res_object *temp_strm2 = NULL;
321 struct strm_res_object *temp_strm;
322
323 if (mutex_lock_interruptible(&ctxt->strm_mutex))
324 return -EPERM;
325
326 temp_strm = ctxt->pstrm_list;
327 while ((temp_strm != NULL) && (temp_strm->hstream != stream_obj)) {
328 temp_strm2 = temp_strm;
329 temp_strm = temp_strm->next;
330 }
331
332 mutex_unlock(&ctxt->strm_mutex);
333 283
334 if (temp_strm != NULL) 284 idr_for_each(ctxt->stream_id, drv_proc_free_strm_res, ctxt);
335 *strm_res = temp_strm; 285 idr_destroy(ctxt->stream_id);
336 else
337 status = -ENOENT;
338 286
339 return status; 287 return 0;
340} 288}
341 289
342/* Updating the stream resource element */ 290/* Updating the stream resource element */
diff --git a/drivers/staging/tidspbridge/rmgr/drv_interface.c b/drivers/staging/tidspbridge/rmgr/drv_interface.c
index 900cdd356f76..7ee89492a755 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)
511 INIT_LIST_HEAD(&pr_ctxt->dmm_map_list); 511 INIT_LIST_HEAD(&pr_ctxt->dmm_map_list);
512 spin_lock_init(&pr_ctxt->dmm_rsv_lock); 512 spin_lock_init(&pr_ctxt->dmm_rsv_lock);
513 INIT_LIST_HEAD(&pr_ctxt->dmm_rsv_list); 513 INIT_LIST_HEAD(&pr_ctxt->dmm_rsv_list);
514 mutex_init(&pr_ctxt->strm_mutex);
515 514
516 pr_ctxt->node_id = kzalloc(sizeof(struct idr), GFP_KERNEL); 515 pr_ctxt->node_id = kzalloc(sizeof(struct idr), GFP_KERNEL);
517 if (pr_ctxt->node_id) 516 if (pr_ctxt->node_id) {
518 idr_init(pr_ctxt->node_id); 517 idr_init(pr_ctxt->node_id);
518 } else {
519 status = -ENOMEM;
520 goto err;
521 }
522
523 pr_ctxt->stream_id = kzalloc(sizeof(struct idr), GFP_KERNEL);
524 if (pr_ctxt->stream_id)
525 idr_init(pr_ctxt->stream_id);
519 else 526 else
520 status = -ENOMEM; 527 status = -ENOMEM;
521 } else { 528 } else {
522 status = -ENOMEM; 529 status = -ENOMEM;
523 } 530 }
524 531err:
525 filp->private_data = pr_ctxt; 532 filp->private_data = pr_ctxt;
526#ifdef CONFIG_TIDSPBRIDGE_RECOVERY 533#ifdef CONFIG_TIDSPBRIDGE_RECOVERY
527 if (!status) 534 if (!status)
diff --git a/drivers/staging/tidspbridge/rmgr/strm.c b/drivers/staging/tidspbridge/rmgr/strm.c
index df8458e874c1..ef2ec9497b1c 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);
96 * Purpose: 96 * Purpose:
97 * Allocates buffers for a stream. 97 * Allocates buffers for a stream.
98 */ 98 */
99int strm_allocate_buffer(struct strm_object *stream_obj, u32 usize, 99int strm_allocate_buffer(struct strm_res_object *strmres, u32 usize,
100 u8 **ap_buffer, u32 num_bufs, 100 u8 **ap_buffer, u32 num_bufs,
101 struct process_context *pr_ctxt) 101 struct process_context *pr_ctxt)
102{ 102{
103 int status = 0; 103 int status = 0;
104 u32 alloc_cnt = 0; 104 u32 alloc_cnt = 0;
105 u32 i; 105 u32 i;
106 106 struct strm_object *stream_obj = strmres->hstream;
107 void *hstrm_res;
108 107
109 DBC_REQUIRE(refs > 0); 108 DBC_REQUIRE(refs > 0);
110 DBC_REQUIRE(ap_buffer != NULL); 109 DBC_REQUIRE(ap_buffer != NULL);
@@ -134,14 +133,12 @@ int strm_allocate_buffer(struct strm_object *stream_obj, u32 usize,
134 } 133 }
135 } 134 }
136 if (status) 135 if (status)
137 strm_free_buffer(stream_obj, ap_buffer, alloc_cnt, pr_ctxt); 136 strm_free_buffer(strmres, ap_buffer, alloc_cnt, pr_ctxt);
138 137
139 if (status) 138 if (status)
140 goto func_end; 139 goto func_end;
141 140
142 if (drv_get_strm_res_element(stream_obj, &hstrm_res, pr_ctxt) != 141 drv_proc_update_strm_res(num_bufs, strmres);
143 -ENOENT)
144 drv_proc_update_strm_res(num_bufs, hstrm_res);
145 142
146func_end: 143func_end:
147 return status; 144 return status;
@@ -152,14 +149,13 @@ func_end:
152 * Purpose: 149 * Purpose:
153 * Close a stream opened with strm_open(). 150 * Close a stream opened with strm_open().
154 */ 151 */
155int strm_close(struct strm_object *stream_obj, 152int strm_close(struct strm_res_object *strmres,
156 struct process_context *pr_ctxt) 153 struct process_context *pr_ctxt)
157{ 154{
158 struct bridge_drv_interface *intf_fxns; 155 struct bridge_drv_interface *intf_fxns;
159 struct chnl_info chnl_info_obj; 156 struct chnl_info chnl_info_obj;
160 int status = 0; 157 int status = 0;
161 158 struct strm_object *stream_obj = strmres->hstream;
162 void *hstrm_res;
163 159
164 DBC_REQUIRE(refs > 0); 160 DBC_REQUIRE(refs > 0);
165 161
@@ -183,9 +179,7 @@ int strm_close(struct strm_object *stream_obj,
183 if (status) 179 if (status)
184 goto func_end; 180 goto func_end;
185 181
186 if (drv_get_strm_res_element(stream_obj, &hstrm_res, pr_ctxt) != 182 idr_remove(pr_ctxt->stream_id, strmres->id);
187 -ENOENT)
188 drv_proc_remove_strm_res_element(hstrm_res, pr_ctxt);
189func_end: 183func_end:
190 DBC_ENSURE(status == 0 || status == -EFAULT || 184 DBC_ENSURE(status == 0 || status == -EFAULT ||
191 status == -EPIPE || status == -EPERM); 185 status == -EPIPE || status == -EPERM);
@@ -270,13 +264,12 @@ void strm_exit(void)
270 * Purpose: 264 * Purpose:
271 * Frees the buffers allocated for a stream. 265 * Frees the buffers allocated for a stream.
272 */ 266 */
273int strm_free_buffer(struct strm_object *stream_obj, u8 ** ap_buffer, 267int strm_free_buffer(struct strm_res_object *strmres, u8 ** ap_buffer,
274 u32 num_bufs, struct process_context *pr_ctxt) 268 u32 num_bufs, struct process_context *pr_ctxt)
275{ 269{
276 int status = 0; 270 int status = 0;
277 u32 i = 0; 271 u32 i = 0;
278 272 struct strm_object *stream_obj = strmres->hstream;
279 void *hstrm_res = NULL;
280 273
281 DBC_REQUIRE(refs > 0); 274 DBC_REQUIRE(refs > 0);
282 DBC_REQUIRE(ap_buffer != NULL); 275 DBC_REQUIRE(ap_buffer != NULL);
@@ -295,9 +288,7 @@ int strm_free_buffer(struct strm_object *stream_obj, u8 ** ap_buffer,
295 ap_buffer[i] = NULL; 288 ap_buffer[i] = NULL;
296 } 289 }
297 } 290 }
298 if (drv_get_strm_res_element(stream_obj, hstrm_res, pr_ctxt) != 291 drv_proc_update_strm_res(num_bufs - i, strmres);
299 -ENOENT)
300 drv_proc_update_strm_res(num_bufs - i, hstrm_res);
301 292
302 return status; 293 return status;
303} 294}
@@ -467,7 +458,7 @@ int strm_issue(struct strm_object *stream_obj, u8 *pbuf, u32 ul_bytes,
467 */ 458 */
468int strm_open(struct node_object *hnode, u32 dir, u32 index, 459int strm_open(struct node_object *hnode, u32 dir, u32 index,
469 struct strm_attr *pattr, 460 struct strm_attr *pattr,
470 struct strm_object **strm_objct, 461 struct strm_res_object **strmres,
471 struct process_context *pr_ctxt) 462 struct process_context *pr_ctxt)
472{ 463{
473 struct strm_mgr *strm_mgr_obj; 464 struct strm_mgr *strm_mgr_obj;
@@ -479,12 +470,12 @@ int strm_open(struct node_object *hnode, u32 dir, u32 index,
479 int status = 0; 470 int status = 0;
480 struct cmm_object *hcmm_mgr = NULL; /* Shared memory manager hndl */ 471 struct cmm_object *hcmm_mgr = NULL; /* Shared memory manager hndl */
481 472
482 void *hstrm_res; 473 void *stream_res;
483 474
484 DBC_REQUIRE(refs > 0); 475 DBC_REQUIRE(refs > 0);
485 DBC_REQUIRE(strm_objct != NULL); 476 DBC_REQUIRE(strmres != NULL);
486 DBC_REQUIRE(pattr != NULL); 477 DBC_REQUIRE(pattr != NULL);
487 *strm_objct = NULL; 478 *strmres = NULL;
488 if (dir != DSP_TONODE && dir != DSP_FROMNODE) { 479 if (dir != DSP_TONODE && dir != DSP_FROMNODE) {
489 status = -EPERM; 480 status = -EPERM;
490 } else { 481 } else {
@@ -594,22 +585,25 @@ func_cont:
594 } 585 }
595 } 586 }
596 if (!status) { 587 if (!status) {
597 *strm_objct = strm_obj; 588 status = drv_proc_insert_strm_res_element(strm_obj,
598 drv_proc_insert_strm_res_element(*strm_objct, &hstrm_res, 589 &stream_res, pr_ctxt);
599 pr_ctxt); 590 if (status)
591 delete_strm(strm_obj);
592 else
593 *strmres = (struct strm_res_object *)stream_res;
600 } else { 594 } else {
601 (void)delete_strm(strm_obj); 595 (void)delete_strm(strm_obj);
602 } 596 }
603 597
604 /* ensure we return a documented error code */ 598 /* ensure we return a documented error code */
605 DBC_ENSURE((!status && *strm_objct) || 599 DBC_ENSURE((!status && strm_obj) ||
606 (*strm_objct == NULL && (status == -EFAULT || 600 (*strmres == NULL && (status == -EFAULT ||
607 status == -EPERM 601 status == -EPERM
608 || status == -EINVAL))); 602 || status == -EINVAL)));
609 603
610 dev_dbg(bridge, "%s: hnode: %p dir: 0x%x index: 0x%x pattr: %p " 604 dev_dbg(bridge, "%s: hnode: %p dir: 0x%x index: 0x%x pattr: %p "
611 "strm_objct: %p status: 0x%x\n", __func__, 605 "strmres: %p status: 0x%x\n", __func__,
612 hnode, dir, index, pattr, strm_objct, status); 606 hnode, dir, index, pattr, strmres, status);
613 return status; 607 return status;
614} 608}
615 609