Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com> |
| 3 | * Copyright (C) 2010-2011 LunarG Inc. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be included |
| 13 | * in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | #define LOG_TAG "GRALLOC-DRM" |
| 25 | |
| 26 | #include <cutils/log.h> |
| 27 | #include <cutils/atomic.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <errno.h> |
| 30 | #include <sys/types.h> |
| 31 | #include <sys/stat.h> |
| 32 | #include <fcntl.h> |
| 33 | |
| 34 | #include "gralloc_drm.h" |
| 35 | #include "gralloc_drm_priv.h" |
| 36 | |
| 37 | #define unlikely(x) __builtin_expect(!!(x), 0) |
| 38 | |
| 39 | #define GRALLOC_DRM_DEVICE "/dev/dri/card0" |
| 40 | |
| 41 | static int32_t gralloc_drm_pid = 0; |
| 42 | |
| 43 | /* |
| 44 | * Return the pid of the process. |
| 45 | */ |
| 46 | static int gralloc_drm_get_pid(void) |
| 47 | { |
| 48 | if (unlikely(!gralloc_drm_pid)) |
| 49 | android_atomic_write((int32_t) getpid(), &gralloc_drm_pid); |
| 50 | |
| 51 | return gralloc_drm_pid; |
| 52 | } |
| 53 | |
| 54 | /* |
| 55 | * Create the driver for a DRM fd. |
| 56 | */ |
| 57 | static struct gralloc_drm_drv_t * |
| 58 | init_drv_from_fd(int fd) |
| 59 | { |
| 60 | struct gralloc_drm_drv_t *drv = NULL; |
| 61 | drmVersionPtr version; |
| 62 | |
| 63 | /* get the kernel module name */ |
| 64 | version = drmGetVersion(fd); |
| 65 | if (!version) { |
Charles Johnson | b56dc92 | 2012-07-10 17:51:32 -0700 | [diff] [blame] | 66 | ALOGE("invalid DRM fd"); |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 67 | return NULL; |
| 68 | } |
| 69 | |
| 70 | if (version->name) { |
Chia-I Wu | a020bfa | 2011-06-13 08:48:44 +0800 | [diff] [blame] | 71 | #ifdef ENABLE_PIPE |
| 72 | drv = gralloc_drm_drv_create_for_pipe(fd, version->name); |
| 73 | #endif |
| 74 | |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 75 | #ifdef ENABLE_INTEL |
| 76 | if (!drv && !strcmp(version->name, "i915")) |
| 77 | drv = gralloc_drm_drv_create_for_intel(fd); |
| 78 | #endif |
| 79 | #ifdef ENABLE_RADEON |
| 80 | if (!drv && !strcmp(version->name, "radeon")) |
| 81 | drv = gralloc_drm_drv_create_for_radeon(fd); |
| 82 | #endif |
Chia-I Wu | 64345b4 | 2011-06-12 18:43:33 +0800 | [diff] [blame] | 83 | #ifdef ENABLE_NOUVEAU |
| 84 | if (!drv && !strcmp(version->name, "nouveau")) |
| 85 | drv = gralloc_drm_drv_create_for_nouveau(fd); |
| 86 | #endif |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | if (!drv) { |
Charles Johnson | b56dc92 | 2012-07-10 17:51:32 -0700 | [diff] [blame] | 90 | ALOGE("unsupported driver: %s", (version->name) ? |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 91 | version->name : "NULL"); |
| 92 | } |
| 93 | |
| 94 | drmFreeVersion(version); |
| 95 | |
| 96 | return drv; |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | * Create a DRM device object. |
| 101 | */ |
| 102 | struct gralloc_drm_t *gralloc_drm_create(void) |
| 103 | { |
| 104 | struct gralloc_drm_t *drm; |
| 105 | int err; |
| 106 | |
| 107 | drm = calloc(1, sizeof(*drm)); |
| 108 | if (!drm) |
| 109 | return NULL; |
| 110 | |
| 111 | drm->fd = open(GRALLOC_DRM_DEVICE, O_RDWR); |
| 112 | if (drm->fd < 0) { |
Charles Johnson | b56dc92 | 2012-07-10 17:51:32 -0700 | [diff] [blame] | 113 | ALOGE("failed to open %s", GRALLOC_DRM_DEVICE); |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 114 | return NULL; |
| 115 | } |
| 116 | |
| 117 | drm->drv = init_drv_from_fd(drm->fd); |
| 118 | if (!drm->drv) { |
| 119 | close(drm->fd); |
| 120 | free(drm); |
| 121 | return NULL; |
| 122 | } |
| 123 | |
| 124 | return drm; |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Destroy a DRM device object. |
| 129 | */ |
| 130 | void gralloc_drm_destroy(struct gralloc_drm_t *drm) |
| 131 | { |
| 132 | if (drm->drv) |
| 133 | drm->drv->destroy(drm->drv); |
| 134 | close(drm->fd); |
| 135 | free(drm); |
| 136 | } |
| 137 | |
| 138 | /* |
| 139 | * Get the file descriptor of a DRM device object. |
| 140 | */ |
| 141 | int gralloc_drm_get_fd(struct gralloc_drm_t *drm) |
| 142 | { |
| 143 | return drm->fd; |
| 144 | } |
| 145 | |
| 146 | /* |
| 147 | * Get the magic for authentication. |
| 148 | */ |
| 149 | int gralloc_drm_get_magic(struct gralloc_drm_t *drm, int32_t *magic) |
| 150 | { |
| 151 | return drmGetMagic(drm->fd, (drm_magic_t *) magic); |
| 152 | } |
| 153 | |
| 154 | /* |
| 155 | * Authenticate a magic. |
| 156 | */ |
| 157 | int gralloc_drm_auth_magic(struct gralloc_drm_t *drm, int32_t magic) |
| 158 | { |
| 159 | return drmAuthMagic(drm->fd, (drm_magic_t) magic); |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * Set as the master of a DRM device. |
| 164 | */ |
| 165 | int gralloc_drm_set_master(struct gralloc_drm_t *drm) |
| 166 | { |
Charles Johnson | b56dc92 | 2012-07-10 17:51:32 -0700 | [diff] [blame] | 167 | ALOGD("set master"); |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 168 | drmSetMaster(drm->fd); |
| 169 | drm->first_post = 1; |
| 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | /* |
| 175 | * Drop from the master of a DRM device. |
| 176 | */ |
| 177 | void gralloc_drm_drop_master(struct gralloc_drm_t *drm) |
| 178 | { |
| 179 | drmDropMaster(drm->fd); |
| 180 | } |
| 181 | |
| 182 | /* |
Chia-I Wu | 8542de3 | 2011-07-31 16:35:21 +0900 | [diff] [blame] | 183 | * Validate a buffer handle and return the associated bo. |
| 184 | */ |
| 185 | static struct gralloc_drm_bo_t *validate_handle(buffer_handle_t _handle, |
| 186 | struct gralloc_drm_t *drm) |
| 187 | { |
| 188 | struct gralloc_drm_handle_t *handle = gralloc_drm_handle(_handle); |
| 189 | |
| 190 | if (!handle) |
| 191 | return NULL; |
| 192 | |
| 193 | /* the buffer handle is passed to a new process */ |
| 194 | if (unlikely(handle->data_owner != gralloc_drm_pid)) { |
| 195 | struct gralloc_drm_bo_t *bo; |
| 196 | |
| 197 | /* check only */ |
| 198 | if (!drm) |
| 199 | return NULL; |
| 200 | |
| 201 | /* create the struct gralloc_drm_bo_t locally */ |
| 202 | if (handle->name) |
| 203 | bo = drm->drv->alloc(drm->drv, handle); |
| 204 | else /* an invalid handle */ |
| 205 | bo = NULL; |
| 206 | if (bo) { |
| 207 | bo->drm = drm; |
| 208 | bo->imported = 1; |
| 209 | bo->handle = handle; |
Andy Ross | 8ab337a | 2013-06-04 11:32:29 -0700 | [diff] [blame] | 210 | bo->refcount = 1; |
Chia-I Wu | 8542de3 | 2011-07-31 16:35:21 +0900 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | handle->data_owner = gralloc_drm_get_pid(); |
Chih-Wei Huang | 68a74eb | 2014-12-01 01:46:20 +0800 | [diff] [blame^] | 214 | handle->data = bo; |
Chia-I Wu | 8542de3 | 2011-07-31 16:35:21 +0900 | [diff] [blame] | 215 | } |
| 216 | |
Chih-Wei Huang | 68a74eb | 2014-12-01 01:46:20 +0800 | [diff] [blame^] | 217 | return handle->data; |
Chia-I Wu | 8542de3 | 2011-07-31 16:35:21 +0900 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /* |
| 221 | * Register a buffer handle. |
| 222 | */ |
| 223 | int gralloc_drm_handle_register(buffer_handle_t handle, struct gralloc_drm_t *drm) |
| 224 | { |
| 225 | return (validate_handle(handle, drm)) ? 0 : -EINVAL; |
| 226 | } |
| 227 | |
| 228 | /* |
| 229 | * Unregister a buffer handle. It is no-op for handles created locally. |
| 230 | */ |
| 231 | int gralloc_drm_handle_unregister(buffer_handle_t handle) |
| 232 | { |
| 233 | struct gralloc_drm_bo_t *bo; |
| 234 | |
| 235 | bo = validate_handle(handle, NULL); |
| 236 | if (!bo) |
| 237 | return -EINVAL; |
| 238 | |
| 239 | if (bo->imported) |
Tapani Pälli | a86ecd9 | 2012-08-01 16:06:00 +0300 | [diff] [blame] | 240 | gralloc_drm_bo_decref(bo); |
Chia-I Wu | 8542de3 | 2011-07-31 16:35:21 +0900 | [diff] [blame] | 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | /* |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 246 | * Create a buffer handle. |
| 247 | */ |
| 248 | static struct gralloc_drm_handle_t *create_bo_handle(int width, |
| 249 | int height, int format, int usage) |
| 250 | { |
| 251 | struct gralloc_drm_handle_t *handle; |
| 252 | |
| 253 | handle = calloc(1, sizeof(*handle)); |
| 254 | if (!handle) |
| 255 | return NULL; |
| 256 | |
| 257 | handle->base.version = sizeof(handle->base); |
| 258 | handle->base.numInts = GRALLOC_DRM_HANDLE_NUM_INTS; |
| 259 | handle->base.numFds = GRALLOC_DRM_HANDLE_NUM_FDS; |
| 260 | |
| 261 | handle->magic = GRALLOC_DRM_HANDLE_MAGIC; |
| 262 | handle->width = width; |
| 263 | handle->height = height; |
| 264 | handle->format = format; |
| 265 | handle->usage = usage; |
Tapani Pälli | 73e275e | 2013-01-21 14:58:33 +0200 | [diff] [blame] | 266 | handle->plane_mask = 0; |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 267 | |
| 268 | return handle; |
| 269 | } |
| 270 | |
| 271 | /* |
| 272 | * Create a bo. |
| 273 | */ |
| 274 | struct gralloc_drm_bo_t *gralloc_drm_bo_create(struct gralloc_drm_t *drm, |
| 275 | int width, int height, int format, int usage) |
| 276 | { |
| 277 | struct gralloc_drm_bo_t *bo; |
| 278 | struct gralloc_drm_handle_t *handle; |
| 279 | |
| 280 | handle = create_bo_handle(width, height, format, usage); |
| 281 | if (!handle) |
| 282 | return NULL; |
| 283 | |
Tapani Pälli | 73e275e | 2013-01-21 14:58:33 +0200 | [diff] [blame] | 284 | handle->plane_mask = planes_for_format(drm, format); |
| 285 | |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 286 | bo = drm->drv->alloc(drm->drv, handle); |
| 287 | if (!bo) { |
| 288 | free(handle); |
| 289 | return NULL; |
| 290 | } |
| 291 | |
| 292 | bo->drm = drm; |
| 293 | bo->imported = 0; |
| 294 | bo->handle = handle; |
Tapani Pälli | a86ecd9 | 2012-08-01 16:06:00 +0300 | [diff] [blame] | 295 | bo->fb_id = 0; |
| 296 | bo->refcount = 1; |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 297 | |
| 298 | handle->data_owner = gralloc_drm_get_pid(); |
Chih-Wei Huang | 68a74eb | 2014-12-01 01:46:20 +0800 | [diff] [blame^] | 299 | handle->data = bo; |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 300 | |
| 301 | return bo; |
| 302 | } |
| 303 | |
| 304 | /* |
Chia-I Wu | 2fc5da4 | 2011-07-29 19:57:04 +0900 | [diff] [blame] | 305 | * Destroy a bo. |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 306 | */ |
Tapani Pälli | a86ecd9 | 2012-08-01 16:06:00 +0300 | [diff] [blame] | 307 | static void gralloc_drm_bo_destroy(struct gralloc_drm_bo_t *bo) |
Chia-I Wu | 2fc5da4 | 2011-07-29 19:57:04 +0900 | [diff] [blame] | 308 | { |
| 309 | struct gralloc_drm_handle_t *handle = bo->handle; |
| 310 | int imported = bo->imported; |
| 311 | |
Tapani Pälli | a86ecd9 | 2012-08-01 16:06:00 +0300 | [diff] [blame] | 312 | /* gralloc still has a reference */ |
| 313 | if (bo->refcount) |
| 314 | return; |
| 315 | |
| 316 | gralloc_drm_bo_rm_fb(bo); |
| 317 | |
Chia-I Wu | 2fc5da4 | 2011-07-29 19:57:04 +0900 | [diff] [blame] | 318 | bo->drm->drv->free(bo->drm->drv, bo); |
| 319 | if (imported) { |
| 320 | handle->data_owner = 0; |
| 321 | handle->data = 0; |
| 322 | } |
| 323 | else { |
| 324 | free(handle); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | /* |
Tapani Pälli | a86ecd9 | 2012-08-01 16:06:00 +0300 | [diff] [blame] | 329 | * Decrease refcount, if no refs anymore then destroy. |
| 330 | */ |
| 331 | void gralloc_drm_bo_decref(struct gralloc_drm_bo_t *bo) |
| 332 | { |
| 333 | if (!--bo->refcount) |
| 334 | gralloc_drm_bo_destroy(bo); |
| 335 | } |
| 336 | |
| 337 | /* |
Chia-I Wu | 8542de3 | 2011-07-31 16:35:21 +0900 | [diff] [blame] | 338 | * Return the bo of a registered handle. |
Chia-I Wu | 2fc5da4 | 2011-07-29 19:57:04 +0900 | [diff] [blame] | 339 | */ |
Chia-I Wu | 8542de3 | 2011-07-31 16:35:21 +0900 | [diff] [blame] | 340 | struct gralloc_drm_bo_t *gralloc_drm_bo_from_handle(buffer_handle_t handle) |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 341 | { |
Chia-I Wu | 8542de3 | 2011-07-31 16:35:21 +0900 | [diff] [blame] | 342 | return validate_handle(handle, NULL); |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | /* |
Chia-I Wu | 8542de3 | 2011-07-31 16:35:21 +0900 | [diff] [blame] | 346 | * Get the buffer handle and stride of a bo. |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 347 | */ |
Chia-I Wu | 8542de3 | 2011-07-31 16:35:21 +0900 | [diff] [blame] | 348 | buffer_handle_t gralloc_drm_bo_get_handle(struct gralloc_drm_bo_t *bo, int *stride) |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 349 | { |
Chia-I Wu | 8542de3 | 2011-07-31 16:35:21 +0900 | [diff] [blame] | 350 | if (stride) |
| 351 | *stride = bo->handle->stride; |
| 352 | return &bo->handle->base; |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 353 | } |
| 354 | |
Tapani Pälli | 421d4ec | 2013-01-15 13:58:57 +0200 | [diff] [blame] | 355 | int gralloc_drm_get_gem_handle(buffer_handle_t _handle) |
| 356 | { |
| 357 | struct gralloc_drm_handle_t *handle = gralloc_drm_handle(_handle); |
| 358 | return (handle) ? handle->name : 0; |
| 359 | } |
| 360 | |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 361 | /* |
Tapani Pälli | a8f0334 | 2013-01-18 15:01:43 +0200 | [diff] [blame] | 362 | * Query YUV component offsets for a buffer handle |
| 363 | */ |
| 364 | void gralloc_drm_resolve_format(buffer_handle_t _handle, |
| 365 | uint32_t *pitches, uint32_t *offsets, uint32_t *handles) |
| 366 | { |
| 367 | struct gralloc_drm_handle_t *handle = gralloc_drm_handle(_handle); |
Chih-Wei Huang | 68a74eb | 2014-12-01 01:46:20 +0800 | [diff] [blame^] | 368 | struct gralloc_drm_bo_t *bo = handle->data; |
Tapani Pälli | a8f0334 | 2013-01-18 15:01:43 +0200 | [diff] [blame] | 369 | struct gralloc_drm_t *drm = bo->drm; |
| 370 | |
| 371 | /* if handle exists and driver implements resolve_format */ |
| 372 | if (handle && drm->drv->resolve_format) |
| 373 | drm->drv->resolve_format(drm->drv, bo, |
| 374 | pitches, offsets, handles); |
| 375 | } |
| 376 | |
| 377 | /* |
Chia-I Wu | 25e0413 | 2011-07-29 20:43:12 +0900 | [diff] [blame] | 378 | * Lock a bo. XXX thread-safety? |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 379 | */ |
Chia-I Wu | 25e0413 | 2011-07-29 20:43:12 +0900 | [diff] [blame] | 380 | int gralloc_drm_bo_lock(struct gralloc_drm_bo_t *bo, |
| 381 | int usage, int x, int y, int w, int h, |
| 382 | void **addr) |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 383 | { |
Chia-I Wu | 92eac93 | 2011-07-30 16:29:54 +0900 | [diff] [blame] | 384 | if ((bo->handle->usage & usage) != usage) { |
| 385 | /* make FB special for testing software renderer with */ |
Adrian Marius Negreanu | 65a831d | 2013-01-18 15:12:19 +0200 | [diff] [blame] | 386 | |
| 387 | if (!(bo->handle->usage & GRALLOC_USAGE_HW_FB) |
| 388 | && !(bo->handle->usage & GRALLOC_USAGE_HW_TEXTURE)) { |
| 389 | ALOGE("bo.usage:x%X/usage:x%X is not GRALLOC_USAGE_HW_FB or GRALLOC_USAGE_HW_TEXTURE" |
| 390 | ,bo->handle->usage,usage); |
Chia-I Wu | 92eac93 | 2011-07-30 16:29:54 +0900 | [diff] [blame] | 391 | return -EINVAL; |
Adrian Marius Negreanu | 65a831d | 2013-01-18 15:12:19 +0200 | [diff] [blame] | 392 | } |
Chia-I Wu | 92eac93 | 2011-07-30 16:29:54 +0900 | [diff] [blame] | 393 | } |
Chia-I Wu | 25e0413 | 2011-07-29 20:43:12 +0900 | [diff] [blame] | 394 | |
| 395 | /* allow multiple locks with compatible usages */ |
| 396 | if (bo->lock_count && (bo->locked_for & usage) != usage) |
| 397 | return -EINVAL; |
| 398 | |
| 399 | usage |= bo->locked_for; |
| 400 | |
| 401 | if (usage & (GRALLOC_USAGE_SW_WRITE_MASK | |
| 402 | GRALLOC_USAGE_SW_READ_MASK)) { |
| 403 | /* the driver is supposed to wait for the bo */ |
| 404 | int write = !!(usage & GRALLOC_USAGE_SW_WRITE_MASK); |
| 405 | int err = bo->drm->drv->map(bo->drm->drv, bo, |
| 406 | x, y, w, h, write, addr); |
| 407 | if (err) |
| 408 | return err; |
| 409 | } |
| 410 | else { |
| 411 | /* kernel handles the synchronization here */ |
| 412 | } |
| 413 | |
| 414 | bo->lock_count++; |
| 415 | bo->locked_for |= usage; |
| 416 | |
| 417 | return 0; |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | /* |
Chia-I Wu | 25e0413 | 2011-07-29 20:43:12 +0900 | [diff] [blame] | 421 | * Unlock a bo. |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 422 | */ |
Chia-I Wu | 25e0413 | 2011-07-29 20:43:12 +0900 | [diff] [blame] | 423 | void gralloc_drm_bo_unlock(struct gralloc_drm_bo_t *bo) |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 424 | { |
Chia-I Wu | 25e0413 | 2011-07-29 20:43:12 +0900 | [diff] [blame] | 425 | int mapped = bo->locked_for & |
| 426 | (GRALLOC_USAGE_SW_WRITE_MASK | GRALLOC_USAGE_SW_READ_MASK); |
| 427 | |
| 428 | if (!bo->lock_count) |
| 429 | return; |
| 430 | |
| 431 | if (mapped) |
| 432 | bo->drm->drv->unmap(bo->drm->drv, bo); |
| 433 | |
| 434 | bo->lock_count--; |
| 435 | if (!bo->lock_count) |
| 436 | bo->locked_for = 0; |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 437 | } |