summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunita Nadampalli2014-11-17 14:00:48 -0600
committerSunita Nadampalli2014-11-17 14:00:48 -0600
commit02907e6c0b25f3abbb90f762681a9b13abe29477 (patch)
tree83183f247f564db4507bc8a29b800676f8073cd3 /memplugin_android.c
parent5693201c37da9070928a751d79cbfed6bb8dd051 (diff)
downloadhardware-ti-libdce-02907e6c0b25f3abbb90f762681a9b13abe29477.tar.gz
hardware-ti-libdce-02907e6c0b25f3abbb90f762681a9b13abe29477.tar.xz
hardware-ti-libdce-02907e6c0b25f3abbb90f762681a9b13abe29477.zip
libdce[Android]: Added support for DRM based Android memplugin
This patch adds memplugin implementation for GEM allocator and dce buffer locking via MmRPC for Android builds. Android memplugin implement memplugin interface for buffers with and without memheaders. This implementation is for DRM/GEM buffer allocations. And libdce_android implements GEM buffer registration and unregistration with MmRPC. Change-Id: Ie72c988a37f987446f7d7c1d97225295de73d305 Signed-off-by: Sunita Nadampalli <sunitan@ti.com>
Diffstat (limited to 'memplugin_android.c')
-rw-r--r--memplugin_android.c203
1 files changed, 203 insertions, 0 deletions
diff --git a/memplugin_android.c b/memplugin_android.c
new file mode 100644
index 0000000..154ae7c
--- /dev/null
+++ b/memplugin_android.c
@@ -0,0 +1,203 @@
1/*
2 * Copyright (c) 2014, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <fcntl.h>
34#include <sys/ioctl.h>
35#include <sys/mman.h>
36#include <sys/eventfd.h>
37#include <fcntl.h>
38
39#include "memplugin.h"
40#include "libdce.h"
41
42#include <xf86drm.h>
43#include <omap_drm.h>
44#include <omap_drmif.h>
45#include <utils/Log.h>
46
47
48#define LINUX_PAGE_SIZE 4096
49#define INVALID_DRM_FD (-1)
50
51int OmapDrm_FD = INVALID_DRM_FD;
52struct omap_device *OmapDev = NULL;
53
54int memplugin_open()
55{
56 if (OmapDev)
57 return MEM_EOK;
58
59 /* Open omapdrm device */
60 if( OmapDrm_FD == INVALID_DRM_FD ) {
61 OmapDrm_FD = drmOpen("omapdrm", "platform:omapdrm:00");
62 if(OmapDrm_FD <= 0) {
63 ALOGE("omapdrm open failed\n");
64 return MEM_EOPEN_FAILURE;
65 }
66 }
67 OmapDev = omap_device_new(OmapDrm_FD);
68 if(OmapDev == NULL) {
69 close(OmapDrm_FD);
70 return MEM_EOPEN_FAILURE;
71 }
72
73 if (dce_ipc_init(IPU) != MEM_EOK) {
74 omap_device_del(OmapDev);
75 OmapDev = NULL;
76 close(OmapDrm_FD);
77 OmapDrm_FD = INVALID_DRM_FD;
78 return MEM_EOPEN_FAILURE;
79 }
80
81 return MEM_EOK;
82}
83
84int memplugin_close()
85{
86 omap_device_del(OmapDev);
87 OmapDev = NULL;
88 if (OmapDrm_FD) {
89 close(OmapDrm_FD);
90 OmapDrm_FD = INVALID_DRM_FD;
91 }
92
93 /* this ipc client is not associated with any codec engine
94 * this channel is used only for GEM buffer register/unregister,
95 * hence call deinit with -1 for the engine table index
96 */
97 dce_ipc_deinit(IPU, -1);
98
99 return MEM_EOK;
100}
101
102
103void *memplugin_alloc(int sz, int height, MemRegion region, int align, int flags)
104{
105 MemHeader *h = NULL;
106 struct omap_bo *bo = omap_bo_new(OmapDev, sz + sizeof(MemHeader), OMAP_BO_WC);
107
108 if( !bo ) {
109 return (NULL);
110 }
111
112 h = omap_bo_map(bo);
113 memset(H2P(h), 0, sz);
114 h->size = sz;
115 h->ptr = h + sizeof(MemHeader);
116 /* get the fd from drm which needs to be closed by memplugin_free */
117 h->dma_buf_fd = omap_bo_dmabuf(bo);
118 h->region = region;
119 h->flags = flags;/*Beware: This is a bit field.*/
120 h->handle = (void*)bo;
121 h->offset = 0;
122
123 dce_buf_lock(1, (size_t *)&(h->dma_buf_fd));
124
125 return (H2P(h));
126
127}
128
129void memplugin_free(void *ptr)
130{
131 if( ptr ) {
132 MemHeader *h = P2H(ptr);
133 if( h->dma_buf_fd ) {
134 dce_buf_unlock(1, (size_t *)&(h->dma_buf_fd));
135 /* close the file descriptor */
136 close(h->dma_buf_fd);
137 }
138 /*Finally, Delete the buffer object*/
139 omap_bo_del((struct omap_bo *)h->handle);
140 ptr = NULL;
141 }
142
143 return;
144}
145
146int32_t memplugin_share(void *ptr)
147{
148 if (!ptr)
149 return MEM_EINVALID_INPUT;
150
151 MemHeader *h = P2H(ptr);
152 return h->dma_buf_fd;
153
154}
155
156void *memplugin_alloc_noheader(MemHeader *memHdr, int sz, int height, MemRegion region, int align, int flags)
157{
158 MemHeader *h = memHdr;
159 if (!memHdr)
160 return NULL;
161
162 struct omap_bo *bo = omap_bo_new(OmapDev, sz, OMAP_BO_WC);
163
164 if( !bo ) {
165 return (NULL);
166 }
167
168 h->ptr = omap_bo_map(bo);
169
170 memset(h->ptr, 0, sz);
171
172 h->size = sz;
173 h->handle = (void *)bo;
174 /* get the fd from drm which needs to be closed by memplugin_free */
175 h->dma_buf_fd = omap_bo_dmabuf(bo);
176 h->region = region;
177 h->flags = flags;/*Beware: This is a bit field.*/
178 h->offset = 0;
179
180 dce_buf_lock(1, (size_t *)&(h->dma_buf_fd));
181
182 return (h->ptr);
183
184}
185
186void memplugin_free_noheader(MemHeader *memHdr)
187{
188 if (!memHdr)
189 return;
190
191 MemHeader *h = memHdr;
192 if( h->dma_buf_fd ) {
193 dce_buf_unlock(1, (size_t *)&(h->dma_buf_fd));
194 /* close the file descriptor */
195 close(h->dma_buf_fd);
196 }
197
198 /*Finally, Delete the buffer object*/
199 omap_bo_del((struct omap_bo *)h->ptr);
200
201 return;
202}
203