aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPradeep Venkatasubbarao2014-03-24 02:48:35 -0500
committerPradeep Venkatasubbarao2014-03-25 23:04:42 -0500
commit1010fffb26ff3ee6e775b2f28d9016a88f26669a (patch)
tree68295d13b5bde5999fbe42cac00fdc95c7804171 /memplugin_linux.c
parent0ab31239d479f6954ba56977cfd358b373b3f9ed (diff)
downloadrepo-libdce-1010fffb26ff3ee6e775b2f28d9016a88f26669a.tar.gz
repo-libdce-1010fffb26ff3ee6e775b2f28d9016a88f26669a.tar.xz
repo-libdce-1010fffb26ff3ee6e775b2f28d9016a88f26669a.zip
[LINUX] Manage Tiler Pinning for dce DRM buffers
Applications using dce_alloc/dce_free calls to manage memory, leaked memory because on non-closure of the created dmabuf fds. Additionally, all memory allocated from Tiler/DMM via DRM need to be explictly pinned to tiler using dce_buf_lock/dce_buf_unlock calls. Hence in the earlier implementation, every call to dce_alloc/free had to be followed by a lock/unlock call to pin/unpin it to tiler. In order, to insulate the applications from the internal details of DRM memory management and for ease of use of alloc and free calls, dce_alloc now takes care of creating the dmabuf and pinning it to tiler while dce_free takes care of tiler unpinning and closure of dmabuf fd. Applications can continue to use dce_alloc and dce_free calls as before thus maintiaining backward compatibility. On the other hand, since the same interfaces are used for multiple remote core targets, like IPU and DSP, MemHeader struture is upgraded to hold the core for which the block of memory belongs to, to keep track of the core. Hence all applications/Remote cores using this version of libdce should recompile with the new MemHeader for proper functioning. Dependent IPUMM patch: https://gerrit.ext.ti.com/gerrit/omap/#/c/12994/ Change-Id: If09a1039b5b16f3cc5ff0e9c6c598932d8a2ce3e Signed-off-by: Pradeep Venkatasubbarao <pradeepv@ti.com> Signed-off-by: Amarinder Bindra <a-bindra@ti.com> Signed-off-by: Karthik Ramanan <a0393906@ti.com>
Diffstat (limited to 'memplugin_linux.c')
-rw-r--r--memplugin_linux.c40
1 files changed, 31 insertions, 9 deletions
diff --git a/memplugin_linux.c b/memplugin_linux.c
index ed14f17..5543a68 100644
--- a/memplugin_linux.c
+++ b/memplugin_linux.c
@@ -39,13 +39,18 @@ extern struct omap_device *OmapDev;
39/* memplugin_alloc - allocates omap_bo buffer with a header above it. 39/* memplugin_alloc - allocates omap_bo buffer with a header above it.
40 * @sz: Size of the buffer requsted 40 * @sz: Size of the buffer requsted
41 * @height: this parameter is currently not used 41 * @height: this parameter is currently not used
42 * @memory_type : Currently dce_alloc is used on for parameter buffer 42 * @region :Used to specify the region from where the memory is allocated->Not used.
43 * @align:Alignment. Not used
44 * @flags: Bit field. As of now, only the least significant 4 bits are considered
45 * to identify the core for which this allocation is needed. This information
46 * is needed to use the right tiler pin/unpin APIs (DSP or IPU).
47 * For future extensibility, many more attributes can be added as bit fields.
43 * Returns a virtual address pointer to omap_bo buffer or the param buffer 48 * Returns a virtual address pointer to omap_bo buffer or the param buffer
44 */ 49 */
45void *memplugin_alloc(int sz, int height, MemRegion region, int align, int flags) 50void *memplugin_alloc(int sz, int height, MemRegion region, int align, int flags)
46{ 51{
47 MemHeader *h; 52 MemHeader *h;
48 struct omap_bo *bo = omap_bo_new(OmapDev, sz + sizeof(MemHeader), OMAP_BO_CACHED); 53 struct omap_bo *bo = omap_bo_new(OmapDev, sz + sizeof(MemHeader), OMAP_BO_WC);
49 54
50 if( !bo ) { 55 if( !bo ) {
51 return (NULL); 56 return (NULL);
@@ -55,11 +60,17 @@ void *memplugin_alloc(int sz, int height, MemRegion region, int align, int flags
55 memset(H2P(h), 0, sz); 60 memset(H2P(h), 0, sz);
56 h->size = sz; 61 h->size = sz;
57 h->ptr = (void *)bo; 62 h->ptr = (void *)bo;
58 h->dma_buf_fd = 0; 63 /* get the fd from drm which needs to be closed by memplugin_free */
64 h->dma_buf_fd = omap_bo_dmabuf(bo);
59 h->region = region; 65 h->region = region;
66 h->flags = flags;/*Beware: This is a bit field.*/
67 /* lock the file descriptor */
68 if((flags & 0x0f) == DSP) /*Only the last 4 bits are considered*/
69 dsp_dce_buf_lock(1, &(h->dma_buf_fd));
70 else
71 dce_buf_lock(1, &(h->dma_buf_fd));
60 72
61 return (H2P(h)); 73 return (H2P(h));
62
63} 74}
64 75
65/* 76/*
@@ -70,6 +81,20 @@ void memplugin_free(void *ptr)
70{ 81{
71 if( ptr ) { 82 if( ptr ) {
72 MemHeader *h = P2H(ptr); 83 MemHeader *h = P2H(ptr);
84 if( h->dma_buf_fd ) {
85 /*
86 Identify the core for which this memory was allocated and
87 use the appropriate API. Last 4 bits of flags are assumed
88 to be containing core Id information.
89 */
90 if((h->flags & 0x0f) == DSP)
91 dsp_dce_buf_unlock(1, &(h->dma_buf_fd));
92 else
93 dce_buf_unlock(1, &(h->dma_buf_fd));
94 /* close the file descriptor */
95 close(h->dma_buf_fd);
96 }
97 /*Finally, Delete the buffer object*/
73 omap_bo_del((struct omap_bo *)h->ptr); 98 omap_bo_del((struct omap_bo *)h->ptr);
74 } 99 }
75} 100}
@@ -82,11 +107,8 @@ int32_t memplugin_share(void *ptr)
82{ 107{
83 if( ptr ) { 108 if( ptr ) {
84 MemHeader *h = P2H(ptr); 109 MemHeader *h = P2H(ptr);
85 if( !h->dma_buf_fd ) { 110 if( h->dma_buf_fd )
86 h->dma_buf_fd = omap_bo_dmabuf((struct omap_bo *)h->ptr); 111 return (h->dma_buf_fd);
87 }
88 return (h->dma_buf_fd);
89 } 112 }
90 return (-1); 113 return (-1);
91} 114}
92