omap_drm.c revision baaff307
1e88f27b3Smrg/* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */ 2e88f27b3Smrg 3e88f27b3Smrg/* 4e88f27b3Smrg * Copyright (C) 2011 Texas Instruments, Inc 5e88f27b3Smrg * 6e88f27b3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7e88f27b3Smrg * copy of this software and associated documentation files (the "Software"), 8e88f27b3Smrg * to deal in the Software without restriction, including without limitation 9e88f27b3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10e88f27b3Smrg * and/or sell copies of the Software, and to permit persons to whom the 11e88f27b3Smrg * Software is furnished to do so, subject to the following conditions: 12e88f27b3Smrg * 13e88f27b3Smrg * The above copyright notice and this permission notice (including the next 14e88f27b3Smrg * paragraph) shall be included in all copies or substantial portions of the 15e88f27b3Smrg * Software. 16e88f27b3Smrg * 17e88f27b3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18e88f27b3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19e88f27b3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20e88f27b3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21e88f27b3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22e88f27b3Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23e88f27b3Smrg * SOFTWARE. 24e88f27b3Smrg * 25e88f27b3Smrg * Authors: 26e88f27b3Smrg * Rob Clark <rob@ti.com> 27e88f27b3Smrg */ 28e88f27b3Smrg 29e88f27b3Smrg#ifdef HAVE_CONFIG_H 30e88f27b3Smrg#include "config.h" 31e88f27b3Smrg#endif 32e88f27b3Smrg 33e88f27b3Smrg#include <stdlib.h> 34e88f27b3Smrg#include <linux/stddef.h> 35e88f27b3Smrg#include <linux/types.h> 36e88f27b3Smrg#include <errno.h> 37e88f27b3Smrg#include <sys/mman.h> 38e88f27b3Smrg#include <fcntl.h> 39e88f27b3Smrg#include <unistd.h> 40e88f27b3Smrg#include <pthread.h> 41e88f27b3Smrg 42baaff307Smrg#include <libdrm.h> 43e88f27b3Smrg#include <xf86drm.h> 44e88f27b3Smrg#include <xf86atomic.h> 45e88f27b3Smrg 46e88f27b3Smrg#include "omap_drm.h" 47e88f27b3Smrg#include "omap_drmif.h" 48e88f27b3Smrg 49e88f27b3Smrg#define __round_mask(x, y) ((__typeof__(x))((y)-1)) 50e88f27b3Smrg#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) 51e88f27b3Smrg#define PAGE_SIZE 4096 52e88f27b3Smrg 53e88f27b3Smrgstatic pthread_mutex_t table_lock = PTHREAD_MUTEX_INITIALIZER; 54e88f27b3Smrgstatic void * dev_table; 55e88f27b3Smrg 56e88f27b3Smrgstruct omap_device { 57e88f27b3Smrg int fd; 58e88f27b3Smrg atomic_t refcnt; 59e88f27b3Smrg 60e88f27b3Smrg /* The handle_table is used to track GEM bo handles associated w/ 61e88f27b3Smrg * this fd. This is needed, in particular, when importing 62e88f27b3Smrg * dmabuf's because we don't want multiple 'struct omap_bo's 63e88f27b3Smrg * floating around with the same handle. Otherwise, when the 64e88f27b3Smrg * first one is omap_bo_del()'d the handle becomes no longer 65e88f27b3Smrg * valid, and the remaining 'struct omap_bo's are left pointing 66e88f27b3Smrg * to an invalid handle (and possible a GEM bo that is already 67e88f27b3Smrg * free'd). 68e88f27b3Smrg */ 69e88f27b3Smrg void *handle_table; 70e88f27b3Smrg}; 71e88f27b3Smrg 72e88f27b3Smrg/* a GEM buffer object allocated from the DRM device */ 73e88f27b3Smrgstruct omap_bo { 74e88f27b3Smrg struct omap_device *dev; 75e88f27b3Smrg void *map; /* userspace mmap'ing (if there is one) */ 76e88f27b3Smrg uint32_t size; 77e88f27b3Smrg uint32_t handle; 78e88f27b3Smrg uint32_t name; /* flink global handle (DRI2 name) */ 79e88f27b3Smrg uint64_t offset; /* offset to mmap() */ 80e88f27b3Smrg int fd; /* dmabuf handle */ 81e88f27b3Smrg atomic_t refcnt; 82e88f27b3Smrg}; 83e88f27b3Smrg 84e88f27b3Smrgstatic struct omap_device * omap_device_new_impl(int fd) 85e88f27b3Smrg{ 86e88f27b3Smrg struct omap_device *dev = calloc(sizeof(*dev), 1); 87e88f27b3Smrg if (!dev) 88e88f27b3Smrg return NULL; 89e88f27b3Smrg dev->fd = fd; 90e88f27b3Smrg atomic_set(&dev->refcnt, 1); 91e88f27b3Smrg dev->handle_table = drmHashCreate(); 92e88f27b3Smrg return dev; 93e88f27b3Smrg} 94e88f27b3Smrg 95baaff307Smrgdrm_public struct omap_device * omap_device_new(int fd) 96e88f27b3Smrg{ 97e88f27b3Smrg struct omap_device *dev = NULL; 98e88f27b3Smrg 99e88f27b3Smrg pthread_mutex_lock(&table_lock); 100e88f27b3Smrg 101e88f27b3Smrg if (!dev_table) 102e88f27b3Smrg dev_table = drmHashCreate(); 103e88f27b3Smrg 104e88f27b3Smrg if (drmHashLookup(dev_table, fd, (void **)&dev)) { 105e88f27b3Smrg /* not found, create new device */ 106e88f27b3Smrg dev = omap_device_new_impl(fd); 107e88f27b3Smrg drmHashInsert(dev_table, fd, dev); 108e88f27b3Smrg } else { 109e88f27b3Smrg /* found, just incr refcnt */ 110e88f27b3Smrg dev = omap_device_ref(dev); 111e88f27b3Smrg } 112e88f27b3Smrg 113e88f27b3Smrg pthread_mutex_unlock(&table_lock); 114e88f27b3Smrg 115e88f27b3Smrg return dev; 116e88f27b3Smrg} 117e88f27b3Smrg 118baaff307Smrgdrm_public struct omap_device * omap_device_ref(struct omap_device *dev) 119e88f27b3Smrg{ 120e88f27b3Smrg atomic_inc(&dev->refcnt); 121e88f27b3Smrg return dev; 122e88f27b3Smrg} 123e88f27b3Smrg 124baaff307Smrgdrm_public void omap_device_del(struct omap_device *dev) 125e88f27b3Smrg{ 126e88f27b3Smrg if (!atomic_dec_and_test(&dev->refcnt)) 127e88f27b3Smrg return; 128e88f27b3Smrg pthread_mutex_lock(&table_lock); 129e88f27b3Smrg drmHashDestroy(dev->handle_table); 130e88f27b3Smrg drmHashDelete(dev_table, dev->fd); 131e88f27b3Smrg pthread_mutex_unlock(&table_lock); 132e88f27b3Smrg free(dev); 133e88f27b3Smrg} 134e88f27b3Smrg 135baaff307Smrgdrm_public int 136baaff307Smrgomap_get_param(struct omap_device *dev, uint64_t param, uint64_t *value) 137e88f27b3Smrg{ 138e88f27b3Smrg struct drm_omap_param req = { 139e88f27b3Smrg .param = param, 140e88f27b3Smrg }; 141e88f27b3Smrg int ret; 142e88f27b3Smrg 143e88f27b3Smrg ret = drmCommandWriteRead(dev->fd, DRM_OMAP_GET_PARAM, &req, sizeof(req)); 144e88f27b3Smrg if (ret) { 145e88f27b3Smrg return ret; 146e88f27b3Smrg } 147e88f27b3Smrg 148e88f27b3Smrg *value = req.value; 149e88f27b3Smrg 150e88f27b3Smrg return 0; 151e88f27b3Smrg} 152e88f27b3Smrg 153baaff307Smrgdrm_public int 154baaff307Smrgomap_set_param(struct omap_device *dev, uint64_t param, uint64_t value) 155e88f27b3Smrg{ 156e88f27b3Smrg struct drm_omap_param req = { 157e88f27b3Smrg .param = param, 158e88f27b3Smrg .value = value, 159e88f27b3Smrg }; 160e88f27b3Smrg return drmCommandWrite(dev->fd, DRM_OMAP_SET_PARAM, &req, sizeof(req)); 161e88f27b3Smrg} 162e88f27b3Smrg 163e88f27b3Smrg/* lookup a buffer from it's handle, call w/ table_lock held: */ 164e88f27b3Smrgstatic struct omap_bo * lookup_bo(struct omap_device *dev, 165e88f27b3Smrg uint32_t handle) 166e88f27b3Smrg{ 167e88f27b3Smrg struct omap_bo *bo = NULL; 168e88f27b3Smrg if (!drmHashLookup(dev->handle_table, handle, (void **)&bo)) { 169e88f27b3Smrg /* found, incr refcnt and return: */ 170e88f27b3Smrg bo = omap_bo_ref(bo); 171e88f27b3Smrg } 172e88f27b3Smrg return bo; 173e88f27b3Smrg} 174e88f27b3Smrg 175e88f27b3Smrg/* allocate a new buffer object, call w/ table_lock held */ 176e88f27b3Smrgstatic struct omap_bo * bo_from_handle(struct omap_device *dev, 177e88f27b3Smrg uint32_t handle) 178e88f27b3Smrg{ 179e88f27b3Smrg struct omap_bo *bo = calloc(sizeof(*bo), 1); 180e88f27b3Smrg if (!bo) { 181e88f27b3Smrg struct drm_gem_close req = { 182e88f27b3Smrg .handle = handle, 183e88f27b3Smrg }; 184e88f27b3Smrg drmIoctl(dev->fd, DRM_IOCTL_GEM_CLOSE, &req); 185e88f27b3Smrg return NULL; 186e88f27b3Smrg } 187e88f27b3Smrg bo->dev = omap_device_ref(dev); 188e88f27b3Smrg bo->handle = handle; 189e88f27b3Smrg atomic_set(&bo->refcnt, 1); 190e88f27b3Smrg /* add ourselves to the handle table: */ 191e88f27b3Smrg drmHashInsert(dev->handle_table, handle, bo); 192e88f27b3Smrg return bo; 193e88f27b3Smrg} 194e88f27b3Smrg 195e88f27b3Smrg/* allocate a new buffer object */ 196e88f27b3Smrgstatic struct omap_bo * omap_bo_new_impl(struct omap_device *dev, 197e88f27b3Smrg union omap_gem_size size, uint32_t flags) 198e88f27b3Smrg{ 199e88f27b3Smrg struct omap_bo *bo = NULL; 200e88f27b3Smrg struct drm_omap_gem_new req = { 201e88f27b3Smrg .size = size, 202e88f27b3Smrg .flags = flags, 203e88f27b3Smrg }; 204e88f27b3Smrg 205e88f27b3Smrg if (size.bytes == 0) { 206e88f27b3Smrg goto fail; 207e88f27b3Smrg } 208e88f27b3Smrg 209e88f27b3Smrg if (drmCommandWriteRead(dev->fd, DRM_OMAP_GEM_NEW, &req, sizeof(req))) { 210e88f27b3Smrg goto fail; 211e88f27b3Smrg } 212e88f27b3Smrg 213e88f27b3Smrg pthread_mutex_lock(&table_lock); 214e88f27b3Smrg bo = bo_from_handle(dev, req.handle); 215e88f27b3Smrg pthread_mutex_unlock(&table_lock); 216e88f27b3Smrg 217e88f27b3Smrg if (flags & OMAP_BO_TILED) { 218e88f27b3Smrg bo->size = round_up(size.tiled.width, PAGE_SIZE) * size.tiled.height; 219e88f27b3Smrg } else { 220e88f27b3Smrg bo->size = size.bytes; 221e88f27b3Smrg } 222e88f27b3Smrg 223e88f27b3Smrg return bo; 224e88f27b3Smrg 225e88f27b3Smrgfail: 226e88f27b3Smrg free(bo); 227e88f27b3Smrg return NULL; 228e88f27b3Smrg} 229e88f27b3Smrg 230e88f27b3Smrg 231e88f27b3Smrg/* allocate a new (un-tiled) buffer object */ 232baaff307Smrgdrm_public struct omap_bo * 233baaff307Smrgomap_bo_new(struct omap_device *dev, uint32_t size, uint32_t flags) 234e88f27b3Smrg{ 235e88f27b3Smrg union omap_gem_size gsize = { 236e88f27b3Smrg .bytes = size, 237e88f27b3Smrg }; 238e88f27b3Smrg if (flags & OMAP_BO_TILED) { 239e88f27b3Smrg return NULL; 240e88f27b3Smrg } 241e88f27b3Smrg return omap_bo_new_impl(dev, gsize, flags); 242e88f27b3Smrg} 243e88f27b3Smrg 244e88f27b3Smrg/* allocate a new buffer object */ 245baaff307Smrgdrm_public struct omap_bo * 246baaff307Smrgomap_bo_new_tiled(struct omap_device *dev, uint32_t width, 247baaff307Smrg uint32_t height, uint32_t flags) 248e88f27b3Smrg{ 249e88f27b3Smrg union omap_gem_size gsize = { 250e88f27b3Smrg .tiled = { 251e88f27b3Smrg .width = width, 252e88f27b3Smrg .height = height, 253e88f27b3Smrg }, 254e88f27b3Smrg }; 255e88f27b3Smrg if (!(flags & OMAP_BO_TILED)) { 256e88f27b3Smrg return NULL; 257e88f27b3Smrg } 258e88f27b3Smrg return omap_bo_new_impl(dev, gsize, flags); 259e88f27b3Smrg} 260e88f27b3Smrg 261baaff307Smrgdrm_public struct omap_bo *omap_bo_ref(struct omap_bo *bo) 262e88f27b3Smrg{ 263e88f27b3Smrg atomic_inc(&bo->refcnt); 264e88f27b3Smrg return bo; 265e88f27b3Smrg} 266e88f27b3Smrg 267e88f27b3Smrg/* get buffer info */ 268e88f27b3Smrgstatic int get_buffer_info(struct omap_bo *bo) 269e88f27b3Smrg{ 270e88f27b3Smrg struct drm_omap_gem_info req = { 271e88f27b3Smrg .handle = bo->handle, 272e88f27b3Smrg }; 273e88f27b3Smrg int ret = drmCommandWriteRead(bo->dev->fd, DRM_OMAP_GEM_INFO, 274e88f27b3Smrg &req, sizeof(req)); 275e88f27b3Smrg if (ret) { 276e88f27b3Smrg return ret; 277e88f27b3Smrg } 278e88f27b3Smrg 279e88f27b3Smrg /* really all we need for now is mmap offset */ 280e88f27b3Smrg bo->offset = req.offset; 281e88f27b3Smrg bo->size = req.size; 282e88f27b3Smrg 283e88f27b3Smrg return 0; 284e88f27b3Smrg} 285e88f27b3Smrg 286e88f27b3Smrg/* import a buffer object from DRI2 name */ 287baaff307Smrgdrm_public struct omap_bo * 288baaff307Smrgomap_bo_from_name(struct omap_device *dev, uint32_t name) 289e88f27b3Smrg{ 290e88f27b3Smrg struct omap_bo *bo = NULL; 291e88f27b3Smrg struct drm_gem_open req = { 292e88f27b3Smrg .name = name, 293e88f27b3Smrg }; 294e88f27b3Smrg 295e88f27b3Smrg pthread_mutex_lock(&table_lock); 296e88f27b3Smrg 297e88f27b3Smrg if (drmIoctl(dev->fd, DRM_IOCTL_GEM_OPEN, &req)) { 298e88f27b3Smrg goto fail; 299e88f27b3Smrg } 300e88f27b3Smrg 301e88f27b3Smrg bo = lookup_bo(dev, req.handle); 302e88f27b3Smrg if (!bo) { 303e88f27b3Smrg bo = bo_from_handle(dev, req.handle); 304e88f27b3Smrg bo->name = name; 305e88f27b3Smrg } 306e88f27b3Smrg 307e88f27b3Smrg pthread_mutex_unlock(&table_lock); 308e88f27b3Smrg 309e88f27b3Smrg return bo; 310e88f27b3Smrg 311e88f27b3Smrgfail: 312e88f27b3Smrg pthread_mutex_unlock(&table_lock); 313e88f27b3Smrg free(bo); 314e88f27b3Smrg return NULL; 315e88f27b3Smrg} 316e88f27b3Smrg 317e88f27b3Smrg/* import a buffer from dmabuf fd, does not take ownership of the 318e88f27b3Smrg * fd so caller should close() the fd when it is otherwise done 319e88f27b3Smrg * with it (even if it is still using the 'struct omap_bo *') 320e88f27b3Smrg */ 321baaff307Smrgdrm_public struct omap_bo * 322baaff307Smrgomap_bo_from_dmabuf(struct omap_device *dev, int fd) 323e88f27b3Smrg{ 324e88f27b3Smrg struct omap_bo *bo = NULL; 325e88f27b3Smrg struct drm_prime_handle req = { 326e88f27b3Smrg .fd = fd, 327e88f27b3Smrg }; 328e88f27b3Smrg int ret; 329e88f27b3Smrg 330e88f27b3Smrg pthread_mutex_lock(&table_lock); 331e88f27b3Smrg 332e88f27b3Smrg ret = drmIoctl(dev->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &req); 333e88f27b3Smrg if (ret) { 334e88f27b3Smrg goto fail; 335e88f27b3Smrg } 336e88f27b3Smrg 337e88f27b3Smrg bo = lookup_bo(dev, req.handle); 338e88f27b3Smrg if (!bo) { 339e88f27b3Smrg bo = bo_from_handle(dev, req.handle); 340e88f27b3Smrg } 341e88f27b3Smrg 342e88f27b3Smrg pthread_mutex_unlock(&table_lock); 343e88f27b3Smrg 344e88f27b3Smrg return bo; 345e88f27b3Smrg 346e88f27b3Smrgfail: 347e88f27b3Smrg pthread_mutex_unlock(&table_lock); 348e88f27b3Smrg free(bo); 349e88f27b3Smrg return NULL; 350e88f27b3Smrg} 351e88f27b3Smrg 352e88f27b3Smrg/* destroy a buffer object */ 353baaff307Smrgdrm_public void omap_bo_del(struct omap_bo *bo) 354e88f27b3Smrg{ 355e88f27b3Smrg if (!bo) { 356e88f27b3Smrg return; 357e88f27b3Smrg } 358e88f27b3Smrg 359e88f27b3Smrg if (!atomic_dec_and_test(&bo->refcnt)) 360e88f27b3Smrg return; 361e88f27b3Smrg 362e88f27b3Smrg if (bo->map) { 363e88f27b3Smrg munmap(bo->map, bo->size); 364e88f27b3Smrg } 365e88f27b3Smrg 366e88f27b3Smrg if (bo->fd) { 367e88f27b3Smrg close(bo->fd); 368e88f27b3Smrg } 369e88f27b3Smrg 370e88f27b3Smrg if (bo->handle) { 371e88f27b3Smrg struct drm_gem_close req = { 372e88f27b3Smrg .handle = bo->handle, 373e88f27b3Smrg }; 374e88f27b3Smrg pthread_mutex_lock(&table_lock); 375e88f27b3Smrg drmHashDelete(bo->dev->handle_table, bo->handle); 376e88f27b3Smrg drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_CLOSE, &req); 377e88f27b3Smrg pthread_mutex_unlock(&table_lock); 378e88f27b3Smrg } 379e88f27b3Smrg 380e88f27b3Smrg omap_device_del(bo->dev); 381e88f27b3Smrg 382e88f27b3Smrg free(bo); 383e88f27b3Smrg} 384e88f27b3Smrg 385e88f27b3Smrg/* get the global flink/DRI2 buffer name */ 386baaff307Smrgdrm_public int omap_bo_get_name(struct omap_bo *bo, uint32_t *name) 387e88f27b3Smrg{ 388e88f27b3Smrg if (!bo->name) { 389e88f27b3Smrg struct drm_gem_flink req = { 390e88f27b3Smrg .handle = bo->handle, 391e88f27b3Smrg }; 392e88f27b3Smrg int ret; 393e88f27b3Smrg 394e88f27b3Smrg ret = drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_FLINK, &req); 395e88f27b3Smrg if (ret) { 396e88f27b3Smrg return ret; 397e88f27b3Smrg } 398e88f27b3Smrg 399e88f27b3Smrg bo->name = req.name; 400e88f27b3Smrg } 401e88f27b3Smrg 402e88f27b3Smrg *name = bo->name; 403e88f27b3Smrg 404e88f27b3Smrg return 0; 405e88f27b3Smrg} 406e88f27b3Smrg 407baaff307Smrgdrm_public uint32_t omap_bo_handle(struct omap_bo *bo) 408e88f27b3Smrg{ 409e88f27b3Smrg return bo->handle; 410e88f27b3Smrg} 411e88f27b3Smrg 412e88f27b3Smrg/* caller owns the dmabuf fd that is returned and is responsible 413e88f27b3Smrg * to close() it when done 414e88f27b3Smrg */ 415baaff307Smrgdrm_public int omap_bo_dmabuf(struct omap_bo *bo) 416e88f27b3Smrg{ 417e88f27b3Smrg if (!bo->fd) { 418e88f27b3Smrg struct drm_prime_handle req = { 419e88f27b3Smrg .handle = bo->handle, 420e88f27b3Smrg .flags = DRM_CLOEXEC, 421e88f27b3Smrg }; 422e88f27b3Smrg int ret; 423e88f27b3Smrg 424e88f27b3Smrg ret = drmIoctl(bo->dev->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &req); 425e88f27b3Smrg if (ret) { 426e88f27b3Smrg return ret; 427e88f27b3Smrg } 428e88f27b3Smrg 429e88f27b3Smrg bo->fd = req.fd; 430e88f27b3Smrg } 431e88f27b3Smrg return dup(bo->fd); 432e88f27b3Smrg} 433e88f27b3Smrg 434baaff307Smrgdrm_public uint32_t omap_bo_size(struct omap_bo *bo) 435e88f27b3Smrg{ 436e88f27b3Smrg if (!bo->size) { 437e88f27b3Smrg get_buffer_info(bo); 438e88f27b3Smrg } 439e88f27b3Smrg return bo->size; 440e88f27b3Smrg} 441e88f27b3Smrg 442baaff307Smrgdrm_public void *omap_bo_map(struct omap_bo *bo) 443e88f27b3Smrg{ 444e88f27b3Smrg if (!bo->map) { 445e88f27b3Smrg if (!bo->offset) { 446e88f27b3Smrg get_buffer_info(bo); 447e88f27b3Smrg } 448e88f27b3Smrg 449e88f27b3Smrg bo->map = mmap(0, bo->size, PROT_READ | PROT_WRITE, 450e88f27b3Smrg MAP_SHARED, bo->dev->fd, bo->offset); 451e88f27b3Smrg if (bo->map == MAP_FAILED) { 452e88f27b3Smrg bo->map = NULL; 453e88f27b3Smrg } 454e88f27b3Smrg } 455e88f27b3Smrg return bo->map; 456e88f27b3Smrg} 457e88f27b3Smrg 458baaff307Smrgdrm_public int omap_bo_cpu_prep(struct omap_bo *bo, enum omap_gem_op op) 459e88f27b3Smrg{ 460e88f27b3Smrg struct drm_omap_gem_cpu_prep req = { 461e88f27b3Smrg .handle = bo->handle, 462e88f27b3Smrg .op = op, 463e88f27b3Smrg }; 464e88f27b3Smrg return drmCommandWrite(bo->dev->fd, 465e88f27b3Smrg DRM_OMAP_GEM_CPU_PREP, &req, sizeof(req)); 466e88f27b3Smrg} 467e88f27b3Smrg 468baaff307Smrgdrm_public int omap_bo_cpu_fini(struct omap_bo *bo, enum omap_gem_op op) 469e88f27b3Smrg{ 470e88f27b3Smrg struct drm_omap_gem_cpu_fini req = { 471e88f27b3Smrg .handle = bo->handle, 472e88f27b3Smrg .op = op, 473e88f27b3Smrg .nregions = 0, 474e88f27b3Smrg }; 475e88f27b3Smrg return drmCommandWrite(bo->dev->fd, 476e88f27b3Smrg DRM_OMAP_GEM_CPU_FINI, &req, sizeof(req)); 477e88f27b3Smrg} 478