Vishal Bhoj | 78e9049 | 2015-12-07 01:36:32 +0530 | [diff] [blame] | 1 | /* |
| 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 |
| 58 | struct fb_dmabuf_export |
| 59 | { |
| 60 | __u32 fd; |
| 61 | __u32 flags; |
| 62 | }; |
John Stultz | e5c5bb3 | 2018-03-20 18:16:49 -0700 | [diff] [blame] | 63 | |
| 64 | /* Un-comment this line to use dma_buf framebuffer */ |
Vishal Bhoj | 78e9049 | 2015-12-07 01:36:32 +0530 | [diff] [blame] | 65 | /*#define FBIOGET_DMABUF _IOR('F', 0x21, struct fb_dmabuf_export)*/ |
| 66 | |
| 67 | #if PLATFORM_SDK_VERSION >= 21 |
| 68 | typedef int ion_user_handle_t; |
| 69 | #define ION_INVALID_HANDLE 0 |
| 70 | #else |
| 71 | |
| 72 | typedef struct ion_handle *ion_user_handle_t; |
| 73 | |
| 74 | #define ION_INVALID_HANDLE NULL |
| 75 | #endif /* new libion */ |
| 76 | |
| 77 | #endif /* GRALLOC_ARM_DMA_BUF_MODULE */ |
| 78 | |
| 79 | |
| 80 | #endif |
| 81 | |
| 82 | /* the max string size of GRALLOC_HARDWARE_GPU0 & GRALLOC_HARDWARE_FB0 |
| 83 | * 8 is big enough for "gpu0" & "fb0" currently |
| 84 | */ |
| 85 | #define MALI_GRALLOC_HARDWARE_MAX_STR_LEN 8 |
| 86 | #define NUM_FB_BUFFERS 2 |
| 87 | |
| 88 | #if GRALLOC_ARM_UMP_MODULE |
| 89 | #include <ump/ump.h> |
| 90 | #endif |
| 91 | |
| 92 | #define MALI_IGNORE(x) (void)x |
| 93 | typedef enum |
| 94 | { |
| 95 | MALI_YUV_NO_INFO, |
| 96 | MALI_YUV_BT601_NARROW, |
| 97 | MALI_YUV_BT601_WIDE, |
| 98 | MALI_YUV_BT709_NARROW, |
| 99 | MALI_YUV_BT709_WIDE, |
| 100 | } mali_gralloc_yuv_info; |
| 101 | |
| 102 | struct private_handle_t; |
| 103 | |
| 104 | struct private_module_t |
| 105 | { |
| 106 | gralloc_module_t base; |
| 107 | |
| 108 | private_handle_t *framebuffer; |
| 109 | uint32_t flags; |
| 110 | uint32_t numBuffers; |
| 111 | uint32_t bufferMask; |
| 112 | pthread_mutex_t lock; |
| 113 | buffer_handle_t currentBuffer; |
| 114 | int ion_client; |
Laura Abbott | 311955b | 2017-06-30 11:39:35 +0530 | [diff] [blame] | 115 | int system_heap_id; |
| 116 | bool gralloc_legacy_ion; |
Vishal Bhoj | 78e9049 | 2015-12-07 01:36:32 +0530 | [diff] [blame] | 117 | |
| 118 | struct fb_var_screeninfo info; |
| 119 | struct fb_fix_screeninfo finfo; |
| 120 | float xdpi; |
| 121 | float ydpi; |
| 122 | float fps; |
| 123 | |
| 124 | enum |
| 125 | { |
| 126 | // flag to indicate we'll post this buffer |
| 127 | PRIV_USAGE_LOCKED_FOR_POST = 0x80000000 |
| 128 | }; |
| 129 | |
| 130 | /* default constructor */ |
| 131 | private_module_t(); |
| 132 | }; |
| 133 | |
| 134 | #ifdef __cplusplus |
| 135 | struct private_handle_t : public native_handle |
| 136 | { |
| 137 | #else |
| 138 | struct private_handle_t |
| 139 | { |
| 140 | struct native_handle nativeHandle; |
| 141 | #endif |
| 142 | |
| 143 | enum |
| 144 | { |
| 145 | PRIV_FLAGS_FRAMEBUFFER = 0x00000001, |
| 146 | PRIV_FLAGS_USES_UMP = 0x00000002, |
| 147 | PRIV_FLAGS_USES_ION = 0x00000004, |
| 148 | }; |
| 149 | |
| 150 | enum |
| 151 | { |
| 152 | LOCK_STATE_WRITE = 1 << 31, |
| 153 | LOCK_STATE_MAPPED = 1 << 30, |
John Stultz | 3728745 | 2016-01-20 20:08:46 -0800 | [diff] [blame] | 154 | LOCK_STATE_UNREGISTERED = 1 << 29, |
John Stultz | e5c5bb3 | 2018-03-20 18:16:49 -0700 | [diff] [blame] | 155 | LOCK_STATE_READ_MASK = 0x3FFFFFFF |
Vishal Bhoj | 78e9049 | 2015-12-07 01:36:32 +0530 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | // ints |
| 159 | #if GRALLOC_ARM_DMA_BUF_MODULE |
| 160 | /*shared file descriptor for dma_buf sharing*/ |
| 161 | int share_fd; |
| 162 | #endif |
| 163 | int magic; |
| 164 | int flags; |
| 165 | int usage; |
| 166 | int size; |
| 167 | int width; |
| 168 | int height; |
| 169 | int format; |
| 170 | int stride; |
| 171 | union |
| 172 | { |
| 173 | void *base; |
| 174 | uint64_t padding; |
| 175 | }; |
| 176 | int lockState; |
| 177 | int writeOwner; |
| 178 | int pid; |
| 179 | |
| 180 | mali_gralloc_yuv_info yuv_info; |
| 181 | |
| 182 | // Following members are for UMP memory only |
| 183 | #if GRALLOC_ARM_UMP_MODULE |
| 184 | int ump_id; |
| 185 | int ump_mem_handle; |
| 186 | #endif |
| 187 | |
| 188 | // Following members is for framebuffer only |
John Stultz | e5c5bb3 | 2018-03-20 18:16:49 -0700 | [diff] [blame] | 189 | int fd; //Shallow copy, DO NOT duplicate |
Vishal Bhoj | 78e9049 | 2015-12-07 01:36:32 +0530 | [diff] [blame] | 190 | int offset; |
John Stultz | e5c5bb3 | 2018-03-20 18:16:49 -0700 | [diff] [blame] | 191 | union |
| 192 | { |
| 193 | void *fb_paddr; |
| 194 | uint64_t fb_paddr_padding; |
| 195 | }; |
Vishal Bhoj | 78e9049 | 2015-12-07 01:36:32 +0530 | [diff] [blame] | 196 | #if GRALLOC_ARM_DMA_BUF_MODULE |
John Stultz | e5c5bb3 | 2018-03-20 18:16:49 -0700 | [diff] [blame] | 197 | ion_user_handle_t ion_hnd; |
Vishal Bhoj | 78e9049 | 2015-12-07 01:36:32 +0530 | [diff] [blame] | 198 | #endif |
| 199 | |
| 200 | #if GRALLOC_ARM_DMA_BUF_MODULE |
| 201 | #define GRALLOC_ARM_NUM_FDS 1 |
| 202 | #else |
| 203 | #define GRALLOC_ARM_NUM_FDS 0 |
| 204 | #endif |
| 205 | |
| 206 | #ifdef __cplusplus |
| 207 | static const int sNumFds = GRALLOC_ARM_NUM_FDS; |
| 208 | static const int sMagic = 0x3141592; |
| 209 | |
| 210 | #if GRALLOC_ARM_UMP_MODULE |
| 211 | private_handle_t(int flags, int usage, int size, void *base, int lock_state, ump_secure_id secure_id, ump_handle handle): |
| 212 | #if GRALLOC_ARM_DMA_BUF_MODULE |
| 213 | share_fd(-1), |
| 214 | #endif |
| 215 | magic(sMagic), |
| 216 | flags(flags), |
| 217 | usage(usage), |
| 218 | size(size), |
| 219 | width(0), |
| 220 | height(0), |
| 221 | format(0), |
| 222 | stride(0), |
| 223 | base(base), |
| 224 | lockState(lock_state), |
| 225 | writeOwner(0), |
| 226 | pid(getpid()), |
| 227 | yuv_info(MALI_YUV_NO_INFO), |
| 228 | ump_id((int)secure_id), |
| 229 | ump_mem_handle((int)handle), |
John Stultz | e5c5bb3 | 2018-03-20 18:16:49 -0700 | [diff] [blame] | 230 | fd(0), |
| 231 | offset(0), |
| 232 | fb_paddr(NULL) |
Vishal Bhoj | 78e9049 | 2015-12-07 01:36:32 +0530 | [diff] [blame] | 233 | #if GRALLOC_ARM_DMA_BUF_MODULE |
| 234 | , |
John Stultz | e5c5bb3 | 2018-03-20 18:16:49 -0700 | [diff] [blame] | 235 | ion_hnd(ION_INVALID_HANDLE) |
Vishal Bhoj | 78e9049 | 2015-12-07 01:36:32 +0530 | [diff] [blame] | 236 | #endif |
| 237 | |
| 238 | { |
| 239 | version = sizeof(native_handle); |
| 240 | numFds = sNumFds; |
| 241 | numInts = (sizeof(private_handle_t) - sizeof(native_handle)) / sizeof(int) - sNumFds; |
| 242 | } |
| 243 | #endif |
| 244 | |
| 245 | #if GRALLOC_ARM_DMA_BUF_MODULE |
| 246 | private_handle_t(int flags, int usage, int size, void *base, int lock_state): |
| 247 | share_fd(-1), |
| 248 | magic(sMagic), |
| 249 | flags(flags), |
| 250 | usage(usage), |
| 251 | size(size), |
| 252 | width(0), |
| 253 | height(0), |
| 254 | format(0), |
| 255 | stride(0), |
| 256 | base(base), |
| 257 | lockState(lock_state), |
| 258 | writeOwner(0), |
| 259 | pid(getpid()), |
| 260 | yuv_info(MALI_YUV_NO_INFO), |
| 261 | #if GRALLOC_ARM_UMP_MODULE |
| 262 | ump_id((int)UMP_INVALID_SECURE_ID), |
| 263 | ump_mem_handle((int)UMP_INVALID_MEMORY_HANDLE), |
| 264 | #endif |
John Stultz | e5c5bb3 | 2018-03-20 18:16:49 -0700 | [diff] [blame] | 265 | fd(0), |
Vishal Bhoj | 78e9049 | 2015-12-07 01:36:32 +0530 | [diff] [blame] | 266 | offset(0), |
John Stultz | e5c5bb3 | 2018-03-20 18:16:49 -0700 | [diff] [blame] | 267 | fb_paddr(NULL), |
| 268 | ion_hnd(ION_INVALID_HANDLE) |
Vishal Bhoj | 78e9049 | 2015-12-07 01:36:32 +0530 | [diff] [blame] | 269 | |
| 270 | { |
| 271 | version = sizeof(native_handle); |
| 272 | numFds = sNumFds; |
| 273 | numInts = (sizeof(private_handle_t) - sizeof(native_handle)) / sizeof(int) - sNumFds; |
| 274 | } |
| 275 | |
| 276 | #endif |
| 277 | |
John Stultz | e5c5bb3 | 2018-03-20 18:16:49 -0700 | [diff] [blame] | 278 | private_handle_t(int flags, int usage, int size, void *base, int lock_state, int fb_file, int fb_offset, void *fb_paddr): |
Vishal Bhoj | 78e9049 | 2015-12-07 01:36:32 +0530 | [diff] [blame] | 279 | #if GRALLOC_ARM_DMA_BUF_MODULE |
| 280 | share_fd(-1), |
| 281 | #endif |
| 282 | magic(sMagic), |
| 283 | flags(flags), |
| 284 | usage(usage), |
| 285 | size(size), |
| 286 | width(0), |
| 287 | height(0), |
| 288 | format(0), |
| 289 | stride(0), |
| 290 | base(base), |
| 291 | lockState(lock_state), |
| 292 | writeOwner(0), |
| 293 | pid(getpid()), |
| 294 | yuv_info(MALI_YUV_NO_INFO), |
| 295 | #if GRALLOC_ARM_UMP_MODULE |
| 296 | ump_id((int)UMP_INVALID_SECURE_ID), |
| 297 | ump_mem_handle((int)UMP_INVALID_MEMORY_HANDLE), |
| 298 | #endif |
John Stultz | e5c5bb3 | 2018-03-20 18:16:49 -0700 | [diff] [blame] | 299 | fd(fb_file), |
| 300 | offset(fb_offset), |
| 301 | fb_paddr(fb_paddr) |
Vishal Bhoj | 78e9049 | 2015-12-07 01:36:32 +0530 | [diff] [blame] | 302 | #if GRALLOC_ARM_DMA_BUF_MODULE |
| 303 | , |
John Stultz | e5c5bb3 | 2018-03-20 18:16:49 -0700 | [diff] [blame] | 304 | ion_hnd(ION_INVALID_HANDLE) |
Vishal Bhoj | 78e9049 | 2015-12-07 01:36:32 +0530 | [diff] [blame] | 305 | #endif |
| 306 | |
| 307 | { |
| 308 | version = sizeof(native_handle); |
| 309 | numFds = sNumFds; |
| 310 | numInts = (sizeof(private_handle_t) - sizeof(native_handle)) / sizeof(int) - sNumFds; |
| 311 | } |
| 312 | |
| 313 | ~private_handle_t() |
| 314 | { |
| 315 | magic = 0; |
| 316 | } |
| 317 | |
| 318 | bool usesPhysicallyContiguousMemory() |
| 319 | { |
| 320 | return (flags & PRIV_FLAGS_FRAMEBUFFER) ? true : false; |
| 321 | } |
| 322 | |
| 323 | static int validate(const native_handle *h) |
| 324 | { |
| 325 | const private_handle_t *hnd = (const private_handle_t *)h; |
| 326 | |
John Stultz | e5c5bb3 | 2018-03-20 18:16:49 -0700 | [diff] [blame] | 327 | if (!hnd || hnd->version != sizeof(native_handle) || hnd->magic != sMagic) |
Chia-I Wu | a12e37d | 2017-05-08 12:46:13 -0700 | [diff] [blame] | 328 | { |
| 329 | return -EINVAL; |
| 330 | } |
| 331 | |
| 332 | int numFds = sNumFds; |
| 333 | int numInts = (sizeof(private_handle_t) - sizeof(native_handle)) / sizeof(int) - sNumFds; |
John Stultz | e5c5bb3 | 2018-03-20 18:16:49 -0700 | [diff] [blame] | 334 | |
Chia-I Wu | a12e37d | 2017-05-08 12:46:13 -0700 | [diff] [blame] | 335 | #if GRALLOC_ARM_DMA_BUF_MODULE |
John Stultz | e5c5bb3 | 2018-03-20 18:16:49 -0700 | [diff] [blame] | 336 | if (hnd->share_fd < 0) |
| 337 | { |
Chia-I Wu | a12e37d | 2017-05-08 12:46:13 -0700 | [diff] [blame] | 338 | numFds--; |
| 339 | numInts++; |
| 340 | } |
| 341 | #endif |
| 342 | |
John Stultz | e5c5bb3 | 2018-03-20 18:16:49 -0700 | [diff] [blame] | 343 | if (hnd->numFds != numFds || hnd->numInts != numInts) |
Vishal Bhoj | 78e9049 | 2015-12-07 01:36:32 +0530 | [diff] [blame] | 344 | { |
| 345 | return -EINVAL; |
| 346 | } |
| 347 | |
| 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | static private_handle_t *dynamicCast(const native_handle *in) |
| 352 | { |
| 353 | if (validate(in) == 0) |
| 354 | { |
| 355 | return (private_handle_t *) in; |
| 356 | } |
| 357 | |
| 358 | return NULL; |
| 359 | } |
| 360 | #endif |
| 361 | }; |
| 362 | |
| 363 | #endif /* GRALLOC_PRIV_H_ */ |