blob: 7b33ae2869245ea71d52dfedbcc8017fc35c8fb6 [file] [log] [blame]
Vishal Bhoj78e90492015-12-07 01:36:32 +05301/*
2 * Copyright (C) 2010 ARM Limited. All rights reserved.
3 *
4 * Copyright (C) 2008 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#ifndef GRALLOC_PRIV_H_
20#define GRALLOC_PRIV_H_
21
22#include <stdint.h>
23#include <pthread.h>
24#include <errno.h>
25#include <linux/fb.h>
26#include <sys/types.h>
27#include <unistd.h>
28
29#include <hardware/gralloc.h>
30#include <cutils/native_handle.h>
31#include <alloc_device.h>
32#include <utils/Log.h>
33
34#ifdef MALI_600
35#define GRALLOC_ARM_UMP_MODULE 0
36#define GRALLOC_ARM_DMA_BUF_MODULE 1
37#else
38
39/* NOTE:
40 * If your framebuffer device driver is integrated with UMP, you will have to
41 * change this IOCTL definition to reflect your integration with the framebuffer
42 * device.
43 * Expected return value is a UMP secure id backing your framebuffer device memory.
44 */
45
46/*#define IOCTL_GET_FB_UMP_SECURE_ID _IOR('F', 311, unsigned int)*/
47#define GRALLOC_ARM_UMP_MODULE 0
48#define GRALLOC_ARM_DMA_BUF_MODULE 1
49
50/* NOTE:
51 * If your framebuffer device driver is integrated with dma_buf, you will have to
52 * change this IOCTL definition to reflect your integration with the framebuffer
53 * device.
54 * Expected return value is a structure filled with a file descriptor
55 * backing your framebuffer device memory.
56 */
57#if GRALLOC_ARM_DMA_BUF_MODULE
58struct fb_dmabuf_export
59{
60 __u32 fd;
61 __u32 flags;
62};
63/*#define FBIOGET_DMABUF _IOR('F', 0x21, struct fb_dmabuf_export)*/
64
65#if PLATFORM_SDK_VERSION >= 21
66typedef int ion_user_handle_t;
67#define ION_INVALID_HANDLE 0
68#else
69
70typedef struct ion_handle *ion_user_handle_t;
71
72#define ION_INVALID_HANDLE NULL
73#endif /* new libion */
74
75#endif /* GRALLOC_ARM_DMA_BUF_MODULE */
76
77
78#endif
79
80/* the max string size of GRALLOC_HARDWARE_GPU0 & GRALLOC_HARDWARE_FB0
81 * 8 is big enough for "gpu0" & "fb0" currently
82 */
83#define MALI_GRALLOC_HARDWARE_MAX_STR_LEN 8
84#define NUM_FB_BUFFERS 2
85
86#if GRALLOC_ARM_UMP_MODULE
87#include <ump/ump.h>
88#endif
89
90#define MALI_IGNORE(x) (void)x
91typedef enum
92{
93 MALI_YUV_NO_INFO,
94 MALI_YUV_BT601_NARROW,
95 MALI_YUV_BT601_WIDE,
96 MALI_YUV_BT709_NARROW,
97 MALI_YUV_BT709_WIDE,
98} mali_gralloc_yuv_info;
99
100struct private_handle_t;
101
102struct private_module_t
103{
104 gralloc_module_t base;
105
106 private_handle_t *framebuffer;
107 uint32_t flags;
108 uint32_t numBuffers;
109 uint32_t bufferMask;
110 pthread_mutex_t lock;
111 buffer_handle_t currentBuffer;
112 int ion_client;
113
114 struct fb_var_screeninfo info;
115 struct fb_fix_screeninfo finfo;
116 float xdpi;
117 float ydpi;
118 float fps;
119
120 enum
121 {
122 // flag to indicate we'll post this buffer
123 PRIV_USAGE_LOCKED_FOR_POST = 0x80000000
124 };
125
126 /* default constructor */
127 private_module_t();
128};
129
130#ifdef __cplusplus
131struct private_handle_t : public native_handle
132{
133#else
134struct private_handle_t
135{
136 struct native_handle nativeHandle;
137#endif
138
139 enum
140 {
141 PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
142 PRIV_FLAGS_USES_UMP = 0x00000002,
143 PRIV_FLAGS_USES_ION = 0x00000004,
144 };
145
146 enum
147 {
148 LOCK_STATE_WRITE = 1 << 31,
149 LOCK_STATE_MAPPED = 1 << 30,
150 LOCK_STATE_READ_MASK = 0x3FFFFFFF
151 };
152
153 // ints
154#if GRALLOC_ARM_DMA_BUF_MODULE
155 /*shared file descriptor for dma_buf sharing*/
156 int share_fd;
157#endif
158 int magic;
159 int flags;
160 int usage;
161 int size;
162 int width;
163 int height;
164 int format;
165 int stride;
166 union
167 {
168 void *base;
169 uint64_t padding;
170 };
171 int lockState;
172 int writeOwner;
173 int pid;
174
175 mali_gralloc_yuv_info yuv_info;
176
177 // Following members are for UMP memory only
178#if GRALLOC_ARM_UMP_MODULE
179 int ump_id;
180 int ump_mem_handle;
181#endif
182
183 // Following members is for framebuffer only
184 int fd;
185 int offset;
186
187#if GRALLOC_ARM_DMA_BUF_MODULE
188 ion_user_handle_t ion_hnd;
189#endif
190
191#if GRALLOC_ARM_DMA_BUF_MODULE
192#define GRALLOC_ARM_NUM_FDS 1
193#else
194#define GRALLOC_ARM_NUM_FDS 0
195#endif
196
197#ifdef __cplusplus
198 static const int sNumFds = GRALLOC_ARM_NUM_FDS;
199 static const int sMagic = 0x3141592;
200
201#if GRALLOC_ARM_UMP_MODULE
202 private_handle_t(int flags, int usage, int size, void *base, int lock_state, ump_secure_id secure_id, ump_handle handle):
203#if GRALLOC_ARM_DMA_BUF_MODULE
204 share_fd(-1),
205#endif
206 magic(sMagic),
207 flags(flags),
208 usage(usage),
209 size(size),
210 width(0),
211 height(0),
212 format(0),
213 stride(0),
214 base(base),
215 lockState(lock_state),
216 writeOwner(0),
217 pid(getpid()),
218 yuv_info(MALI_YUV_NO_INFO),
219 ump_id((int)secure_id),
220 ump_mem_handle((int)handle),
221 fd(0),
222 offset(0)
223#if GRALLOC_ARM_DMA_BUF_MODULE
224 ,
225 ion_hnd(ION_INVALID_HANDLE)
226#endif
227
228 {
229 version = sizeof(native_handle);
230 numFds = sNumFds;
231 numInts = (sizeof(private_handle_t) - sizeof(native_handle)) / sizeof(int) - sNumFds;
232 }
233#endif
234
235#if GRALLOC_ARM_DMA_BUF_MODULE
236 private_handle_t(int flags, int usage, int size, void *base, int lock_state):
237 share_fd(-1),
238 magic(sMagic),
239 flags(flags),
240 usage(usage),
241 size(size),
242 width(0),
243 height(0),
244 format(0),
245 stride(0),
246 base(base),
247 lockState(lock_state),
248 writeOwner(0),
249 pid(getpid()),
250 yuv_info(MALI_YUV_NO_INFO),
251#if GRALLOC_ARM_UMP_MODULE
252 ump_id((int)UMP_INVALID_SECURE_ID),
253 ump_mem_handle((int)UMP_INVALID_MEMORY_HANDLE),
254#endif
255 fd(0),
256 offset(0),
257 ion_hnd(ION_INVALID_HANDLE)
258
259 {
260 version = sizeof(native_handle);
261 numFds = sNumFds;
262 numInts = (sizeof(private_handle_t) - sizeof(native_handle)) / sizeof(int) - sNumFds;
263 }
264
265#endif
266
267 private_handle_t(int flags, int usage, int size, void *base, int lock_state, int fb_file, int fb_offset):
268#if GRALLOC_ARM_DMA_BUF_MODULE
269 share_fd(-1),
270#endif
271 magic(sMagic),
272 flags(flags),
273 usage(usage),
274 size(size),
275 width(0),
276 height(0),
277 format(0),
278 stride(0),
279 base(base),
280 lockState(lock_state),
281 writeOwner(0),
282 pid(getpid()),
283 yuv_info(MALI_YUV_NO_INFO),
284#if GRALLOC_ARM_UMP_MODULE
285 ump_id((int)UMP_INVALID_SECURE_ID),
286 ump_mem_handle((int)UMP_INVALID_MEMORY_HANDLE),
287#endif
288 fd(fb_file),
289 offset(fb_offset)
290#if GRALLOC_ARM_DMA_BUF_MODULE
291 ,
292 ion_hnd(ION_INVALID_HANDLE)
293#endif
294
295 {
296 version = sizeof(native_handle);
297 numFds = sNumFds;
298 numInts = (sizeof(private_handle_t) - sizeof(native_handle)) / sizeof(int) - sNumFds;
299 }
300
301 ~private_handle_t()
302 {
303 magic = 0;
304 }
305
306 bool usesPhysicallyContiguousMemory()
307 {
308 return (flags & PRIV_FLAGS_FRAMEBUFFER) ? true : false;
309 }
310
311 static int validate(const native_handle *h)
312 {
313 const private_handle_t *hnd = (const private_handle_t *)h;
314
315 if (!h || h->version != sizeof(native_handle) || h->numFds != sNumFds ||
316 h->numInts != (sizeof(private_handle_t) - sizeof(native_handle)) / sizeof(int) - sNumFds ||
317 hnd->magic != sMagic)
318 {
319 return -EINVAL;
320 }
321
322 return 0;
323 }
324
325 static private_handle_t *dynamicCast(const native_handle *in)
326 {
327 if (validate(in) == 0)
328 {
329 return (private_handle_t *) in;
330 }
331
332 return NULL;
333 }
334#endif
335};
336
337#endif /* GRALLOC_PRIV_H_ */