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
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>
-rw-r--r--Android.mk22
-rw-r--r--libdce_android.c96
-rw-r--r--memplugin.h25
-rw-r--r--memplugin_android.c203
4 files changed, 329 insertions, 17 deletions
diff --git a/Android.mk b/Android.mk
index a648153..d4e3146 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,18 +1,3 @@
1#
2# Copyright (C) 2010 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16LOCAL_PATH:= $(call my-dir) 1LOCAL_PATH:= $(call my-dir)
17 2
18# 3#
@@ -28,18 +13,23 @@ LOCAL_C_INCLUDES += \
28 $(LOCAL_PATH)/packages/xdctools/ \ 13 $(LOCAL_PATH)/packages/xdctools/ \
29 $(LOCAL_PATH)/ \ 14 $(LOCAL_PATH)/ \
30 hardware/ti/ipc/packages/ \ 15 hardware/ti/ipc/packages/ \
16 external/libdrm/include/drm \
17 external/libdrm/omap \
18 external/libdrm
31 19
32LOCAL_SHARED_LIBRARIES := \ 20LOCAL_SHARED_LIBRARIES := \
33 libmmrpc \ 21 libmmrpc \
34 libc \ 22 libc \
35 libcutils \ 23 libcutils \
36 liblog \ 24 liblog \
25 libdrm \
26 libdrm_omap
37 27
38LOCAL_CFLAGS += -DBUILDOS_ANDROID -DDCE_DEBUG_ENABLE=1 -DDCE_DEBUG_LEVEL=1 28LOCAL_CFLAGS += -DBUILDOS_ANDROID -DDCE_DEBUG_ENABLE=1 -DDCE_DEBUG_LEVEL=1
39 29
40LOCAL_MODULE_TAGS:= optional 30LOCAL_MODULE_TAGS:= optional
41 31
42LOCAL_SRC_FILES:= libdce.c 32LOCAL_SRC_FILES:= libdce.c libdce_android.c memplugin_android.c
43 33
44 34
45LOCAL_MODULE:= libdce 35LOCAL_MODULE:= libdce
diff --git a/libdce_android.c b/libdce_android.c
new file mode 100644
index 0000000..300c311
--- /dev/null
+++ b/libdce_android.c
@@ -0,0 +1,96 @@
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 <stdlib.h>
34#include <string.h>
35#include <stdio.h>
36
37#include <ti/ipc/mm/MmRpc.h>
38#include "dce_priv.h"
39#include "libdce.h"
40#include "dce_rpc.h"
41#include "memplugin.h"
42
43
44extern MmRpc_Handle MmRpcHandle[];
45
46int dce_buf_lock(int num, size_t *handle)
47{
48 int i;
49 MmRpc_BufDesc *desc = NULL;
50 dce_error_status eError = DCE_EOK;
51
52 _ASSERT(num > 0, DCE_EINVALID_INPUT);
53
54 desc = malloc(num * sizeof(MmRpc_BufDesc));
55 _ASSERT(desc != NULL, DCE_EOUT_OF_MEMORY);
56
57 for( i = 0; i < num; i++ ) {
58 desc[i].handle = handle[i];
59 }
60
61 eError = MmRpc_use(MmRpcHandle[IPU], MmRpc_BufType_Handle, num, desc);
62
63 _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL);
64EXIT:
65 if( desc ) {
66 free(desc);
67 }
68 return (eError);
69}
70
71int dce_buf_unlock(int num, size_t *handle)
72{
73 int i;
74 MmRpc_BufDesc *desc = NULL;
75 dce_error_status eError = DCE_EOK;
76
77 _ASSERT(num > 0, DCE_EINVALID_INPUT);
78
79 desc = malloc(num * sizeof(MmRpc_BufDesc));
80 _ASSERT(desc != NULL, DCE_EOUT_OF_MEMORY);
81
82 for( i = 0; i < num; i++ ) {
83 desc[i].handle = handle[i];
84 }
85
86 eError = MmRpc_release(MmRpcHandle[IPU], MmRpc_BufType_Handle, num, desc);
87
88 _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL);
89EXIT:
90 if( desc ) {
91 free(desc);
92 }
93 return (eError);
94}
95
96
diff --git a/memplugin.h b/memplugin.h
index 0c98b4b..0073cf1 100644
--- a/memplugin.h
+++ b/memplugin.h
@@ -83,6 +83,7 @@ typedef enum MemoryRegion {
83 MEM_TILER16_2D, 83 MEM_TILER16_2D,
84 MEM_CARVEOUT, 84 MEM_CARVEOUT,
85 MEM_SHARED, 85 MEM_SHARED,
86 MEM_GRALLOC,
86 MEM_MAX 87 MEM_MAX
87} MemRegion; 88} MemRegion;
88 89
@@ -99,12 +100,34 @@ typedef enum mem_error_status {
99 MEM_EINVALID_INPUT = -1, 100 MEM_EINVALID_INPUT = -1,
100 MEM_EOUT_OF_TILER_MEMORY = -2, 101 MEM_EOUT_OF_TILER_MEMORY = -2,
101 MEM_EOUT_OF_SHMEMORY = -3, 102 MEM_EOUT_OF_SHMEMORY = -3,
102 MEM_EOUT_OF_SYSTEM_MEMORY = -4 103 MEM_EOUT_OF_SYSTEM_MEMORY = -4,
104 MEM_EOPEN_FAILURE = -5,
103} mem_error_status; 105} mem_error_status;
104 106
105void *memplugin_alloc(int sz, int height, MemRegion region, int align, int flags); 107void *memplugin_alloc(int sz, int height, MemRegion region, int align, int flags);
106void memplugin_free(void *ptr); 108void memplugin_free(void *ptr);
107int32_t memplugin_share(void *ptr); 109int32_t memplugin_share(void *ptr);
108 110
111#ifdef BUILDOS_ANDROID
112typedef enum BufAccessMode {
113 MemAccess_8Bit,
114 MemAccess_16Bit,
115 MemAccess_32Bit
116}BufAccessMode;
117
118typedef struct Mem_2DParams {
119 uint32_t nHeight;
120 uint32_t nWidth;
121 uint32_t nStride;
122 BufAccessMode eAccessMode;
123}Mem_2DParams;
124
125void *memplugin_alloc_noheader(MemHeader *memHdr, int sz, int height, MemRegion region, int align, int flags);
126void memplugin_free_noheader(MemHeader *memHdr);
127
128int memplugin_open();
129int memplugin_close();
130#endif
131
109#endif /* __MEMPLUGIN_H__ */ 132#endif /* __MEMPLUGIN_H__ */
110 133
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