omap_drm.c revision 3f012e29
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
42e6188e58Smrg#include <libdrm_macros.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
95e6188e58Smrgstruct 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
118e6188e58Smrgstruct omap_device * omap_device_ref(struct omap_device *dev)
119e88f27b3Smrg{
120e88f27b3Smrg	atomic_inc(&dev->refcnt);
121e88f27b3Smrg	return dev;
122e88f27b3Smrg}
123e88f27b3Smrg
124e6188e58Smrgvoid 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
135e6188e58Smrgint
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
153e6188e58Smrgint
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;
1893f012e29Smrg	bo->fd = -1;
190e88f27b3Smrg	atomic_set(&bo->refcnt, 1);
191e88f27b3Smrg	/* add ourselves to the handle table: */
192e88f27b3Smrg	drmHashInsert(dev->handle_table, handle, bo);
193e88f27b3Smrg	return bo;
194e88f27b3Smrg}
195e88f27b3Smrg
196e88f27b3Smrg/* allocate a new buffer object */
197e88f27b3Smrgstatic struct omap_bo * omap_bo_new_impl(struct omap_device *dev,
198e88f27b3Smrg		union omap_gem_size size, uint32_t flags)
199e88f27b3Smrg{
200e88f27b3Smrg	struct omap_bo *bo = NULL;
201e88f27b3Smrg	struct drm_omap_gem_new req = {
202e88f27b3Smrg			.size = size,
203e88f27b3Smrg			.flags = flags,
204e88f27b3Smrg	};
205e88f27b3Smrg
206e88f27b3Smrg	if (size.bytes == 0) {
207e88f27b3Smrg		goto fail;
208e88f27b3Smrg	}
209e88f27b3Smrg
210e88f27b3Smrg	if (drmCommandWriteRead(dev->fd, DRM_OMAP_GEM_NEW, &req, sizeof(req))) {
211e88f27b3Smrg		goto fail;
212e88f27b3Smrg	}
213e88f27b3Smrg
214e88f27b3Smrg	pthread_mutex_lock(&table_lock);
215e88f27b3Smrg	bo = bo_from_handle(dev, req.handle);
216e88f27b3Smrg	pthread_mutex_unlock(&table_lock);
217e88f27b3Smrg
218e88f27b3Smrg	if (flags & OMAP_BO_TILED) {
219e88f27b3Smrg		bo->size = round_up(size.tiled.width, PAGE_SIZE) * size.tiled.height;
220e88f27b3Smrg	} else {
221e88f27b3Smrg		bo->size = size.bytes;
222e88f27b3Smrg	}
223e88f27b3Smrg
224e88f27b3Smrg	return bo;
225e88f27b3Smrg
226e88f27b3Smrgfail:
227e88f27b3Smrg	free(bo);
228e88f27b3Smrg	return NULL;
229e88f27b3Smrg}
230e88f27b3Smrg
231e88f27b3Smrg
232e88f27b3Smrg/* allocate a new (un-tiled) buffer object */
233e6188e58Smrgstruct omap_bo *
234baaff307Smrgomap_bo_new(struct omap_device *dev, uint32_t size, uint32_t flags)
235e88f27b3Smrg{
236e88f27b3Smrg	union omap_gem_size gsize = {
237e88f27b3Smrg			.bytes = size,
238e88f27b3Smrg	};
239e88f27b3Smrg	if (flags & OMAP_BO_TILED) {
240e88f27b3Smrg		return NULL;
241e88f27b3Smrg	}
242e88f27b3Smrg	return omap_bo_new_impl(dev, gsize, flags);
243e88f27b3Smrg}
244e88f27b3Smrg
245e88f27b3Smrg/* allocate a new buffer object */
246e6188e58Smrgstruct omap_bo *
247baaff307Smrgomap_bo_new_tiled(struct omap_device *dev, uint32_t width,
248baaff307Smrg		  uint32_t height, uint32_t flags)
249e88f27b3Smrg{
250e88f27b3Smrg	union omap_gem_size gsize = {
251e88f27b3Smrg			.tiled = {
252e88f27b3Smrg				.width = width,
253e88f27b3Smrg				.height = height,
254e88f27b3Smrg			},
255e88f27b3Smrg	};
256e88f27b3Smrg	if (!(flags & OMAP_BO_TILED)) {
257e88f27b3Smrg		return NULL;
258e88f27b3Smrg	}
259e88f27b3Smrg	return omap_bo_new_impl(dev, gsize, flags);
260e88f27b3Smrg}
261e88f27b3Smrg
262e6188e58Smrgstruct omap_bo *omap_bo_ref(struct omap_bo *bo)
263e88f27b3Smrg{
264e88f27b3Smrg	atomic_inc(&bo->refcnt);
265e88f27b3Smrg	return bo;
266e88f27b3Smrg}
267e88f27b3Smrg
268e88f27b3Smrg/* get buffer info */
269e88f27b3Smrgstatic int get_buffer_info(struct omap_bo *bo)
270e88f27b3Smrg{
271e88f27b3Smrg	struct drm_omap_gem_info req = {
272e88f27b3Smrg			.handle = bo->handle,
273e88f27b3Smrg	};
274e88f27b3Smrg	int ret = drmCommandWriteRead(bo->dev->fd, DRM_OMAP_GEM_INFO,
275e88f27b3Smrg			&req, sizeof(req));
276e88f27b3Smrg	if (ret) {
277e88f27b3Smrg		return ret;
278e88f27b3Smrg	}
279e88f27b3Smrg
280e88f27b3Smrg	/* really all we need for now is mmap offset */
281e88f27b3Smrg	bo->offset = req.offset;
282e88f27b3Smrg	bo->size = req.size;
283e88f27b3Smrg
284e88f27b3Smrg	return 0;
285e88f27b3Smrg}
286e88f27b3Smrg
287e88f27b3Smrg/* import a buffer object from DRI2 name */
288e6188e58Smrgstruct omap_bo *
289baaff307Smrgomap_bo_from_name(struct omap_device *dev, uint32_t name)
290e88f27b3Smrg{
291e88f27b3Smrg	struct omap_bo *bo = NULL;
292e88f27b3Smrg	struct drm_gem_open req = {
293e88f27b3Smrg			.name = name,
294e88f27b3Smrg	};
295e88f27b3Smrg
296e88f27b3Smrg	pthread_mutex_lock(&table_lock);
297e88f27b3Smrg
298e88f27b3Smrg	if (drmIoctl(dev->fd, DRM_IOCTL_GEM_OPEN, &req)) {
299e88f27b3Smrg		goto fail;
300e88f27b3Smrg	}
301e88f27b3Smrg
302e88f27b3Smrg	bo = lookup_bo(dev, req.handle);
303e88f27b3Smrg	if (!bo) {
304e88f27b3Smrg		bo = bo_from_handle(dev, req.handle);
305e88f27b3Smrg		bo->name = name;
306e88f27b3Smrg	}
307e88f27b3Smrg
308e88f27b3Smrg	pthread_mutex_unlock(&table_lock);
309e88f27b3Smrg
310e88f27b3Smrg	return bo;
311e88f27b3Smrg
312e88f27b3Smrgfail:
313e88f27b3Smrg	pthread_mutex_unlock(&table_lock);
314e88f27b3Smrg	free(bo);
315e88f27b3Smrg	return NULL;
316e88f27b3Smrg}
317e88f27b3Smrg
318e88f27b3Smrg/* import a buffer from dmabuf fd, does not take ownership of the
319e88f27b3Smrg * fd so caller should close() the fd when it is otherwise done
320e88f27b3Smrg * with it (even if it is still using the 'struct omap_bo *')
321e88f27b3Smrg */
322e6188e58Smrgstruct omap_bo *
323baaff307Smrgomap_bo_from_dmabuf(struct omap_device *dev, int fd)
324e88f27b3Smrg{
325e88f27b3Smrg	struct omap_bo *bo = NULL;
326e88f27b3Smrg	struct drm_prime_handle req = {
327e88f27b3Smrg			.fd = fd,
328e88f27b3Smrg	};
329e88f27b3Smrg	int ret;
330e88f27b3Smrg
331e88f27b3Smrg	pthread_mutex_lock(&table_lock);
332e88f27b3Smrg
333e88f27b3Smrg	ret = drmIoctl(dev->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &req);
334e88f27b3Smrg	if (ret) {
335e88f27b3Smrg		goto fail;
336e88f27b3Smrg	}
337e88f27b3Smrg
338e88f27b3Smrg	bo = lookup_bo(dev, req.handle);
339e88f27b3Smrg	if (!bo) {
340e88f27b3Smrg		bo = bo_from_handle(dev, req.handle);
341e88f27b3Smrg	}
342e88f27b3Smrg
343e88f27b3Smrg	pthread_mutex_unlock(&table_lock);
344e88f27b3Smrg
345e88f27b3Smrg	return bo;
346e88f27b3Smrg
347e88f27b3Smrgfail:
348e88f27b3Smrg	pthread_mutex_unlock(&table_lock);
349e88f27b3Smrg	free(bo);
350e88f27b3Smrg	return NULL;
351e88f27b3Smrg}
352e88f27b3Smrg
353e88f27b3Smrg/* destroy a buffer object */
354e6188e58Smrgvoid omap_bo_del(struct omap_bo *bo)
355e88f27b3Smrg{
356e88f27b3Smrg	if (!bo) {
357e88f27b3Smrg		return;
358e88f27b3Smrg	}
359e88f27b3Smrg
360e88f27b3Smrg	if (!atomic_dec_and_test(&bo->refcnt))
361e88f27b3Smrg		return;
362e88f27b3Smrg
363e88f27b3Smrg	if (bo->map) {
364e88f27b3Smrg		munmap(bo->map, bo->size);
365e88f27b3Smrg	}
366e88f27b3Smrg
3673f012e29Smrg	if (bo->fd >= 0) {
368e88f27b3Smrg		close(bo->fd);
369e88f27b3Smrg	}
370e88f27b3Smrg
371e88f27b3Smrg	if (bo->handle) {
372e88f27b3Smrg		struct drm_gem_close req = {
373e88f27b3Smrg				.handle = bo->handle,
374e88f27b3Smrg		};
375e88f27b3Smrg		pthread_mutex_lock(&table_lock);
376e88f27b3Smrg		drmHashDelete(bo->dev->handle_table, bo->handle);
377e88f27b3Smrg		drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_CLOSE, &req);
378e88f27b3Smrg		pthread_mutex_unlock(&table_lock);
379e88f27b3Smrg	}
380e88f27b3Smrg
381e88f27b3Smrg	omap_device_del(bo->dev);
382e88f27b3Smrg
383e88f27b3Smrg	free(bo);
384e88f27b3Smrg}
385e88f27b3Smrg
386e88f27b3Smrg/* get the global flink/DRI2 buffer name */
387e6188e58Smrgint omap_bo_get_name(struct omap_bo *bo, uint32_t *name)
388e88f27b3Smrg{
389e88f27b3Smrg	if (!bo->name) {
390e88f27b3Smrg		struct drm_gem_flink req = {
391e88f27b3Smrg				.handle = bo->handle,
392e88f27b3Smrg		};
393e88f27b3Smrg		int ret;
394e88f27b3Smrg
395e88f27b3Smrg		ret = drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_FLINK, &req);
396e88f27b3Smrg		if (ret) {
397e88f27b3Smrg			return ret;
398e88f27b3Smrg		}
399e88f27b3Smrg
400e88f27b3Smrg		bo->name = req.name;
401e88f27b3Smrg	}
402e88f27b3Smrg
403e88f27b3Smrg	*name = bo->name;
404e88f27b3Smrg
405e88f27b3Smrg	return 0;
406e88f27b3Smrg}
407e88f27b3Smrg
408e6188e58Smrguint32_t omap_bo_handle(struct omap_bo *bo)
409e88f27b3Smrg{
410e88f27b3Smrg	return bo->handle;
411e88f27b3Smrg}
412e88f27b3Smrg
413e88f27b3Smrg/* caller owns the dmabuf fd that is returned and is responsible
414e88f27b3Smrg * to close() it when done
415e88f27b3Smrg */
416e6188e58Smrgint omap_bo_dmabuf(struct omap_bo *bo)
417e88f27b3Smrg{
4183f012e29Smrg	if (bo->fd < 0) {
419e88f27b3Smrg		struct drm_prime_handle req = {
420e88f27b3Smrg				.handle = bo->handle,
421e88f27b3Smrg				.flags = DRM_CLOEXEC,
422e88f27b3Smrg		};
423e88f27b3Smrg		int ret;
424e88f27b3Smrg
425e88f27b3Smrg		ret = drmIoctl(bo->dev->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &req);
426e88f27b3Smrg		if (ret) {
427e88f27b3Smrg			return ret;
428e88f27b3Smrg		}
429e88f27b3Smrg
430e88f27b3Smrg		bo->fd = req.fd;
431e88f27b3Smrg	}
432e88f27b3Smrg	return dup(bo->fd);
433e88f27b3Smrg}
434e88f27b3Smrg
435e6188e58Smrguint32_t omap_bo_size(struct omap_bo *bo)
436e88f27b3Smrg{
437e88f27b3Smrg	if (!bo->size) {
438e88f27b3Smrg		get_buffer_info(bo);
439e88f27b3Smrg	}
440e88f27b3Smrg	return bo->size;
441e88f27b3Smrg}
442e88f27b3Smrg
443e6188e58Smrgvoid *omap_bo_map(struct omap_bo *bo)
444e88f27b3Smrg{
445e88f27b3Smrg	if (!bo->map) {
446e88f27b3Smrg		if (!bo->offset) {
447e88f27b3Smrg			get_buffer_info(bo);
448e88f27b3Smrg		}
449e88f27b3Smrg
450e88f27b3Smrg		bo->map = mmap(0, bo->size, PROT_READ | PROT_WRITE,
451e88f27b3Smrg				MAP_SHARED, bo->dev->fd, bo->offset);
452e88f27b3Smrg		if (bo->map == MAP_FAILED) {
453e88f27b3Smrg			bo->map = NULL;
454e88f27b3Smrg		}
455e88f27b3Smrg	}
456e88f27b3Smrg	return bo->map;
457e88f27b3Smrg}
458e88f27b3Smrg
459e6188e58Smrgint omap_bo_cpu_prep(struct omap_bo *bo, enum omap_gem_op op)
460e88f27b3Smrg{
461e88f27b3Smrg	struct drm_omap_gem_cpu_prep req = {
462e88f27b3Smrg			.handle = bo->handle,
463e88f27b3Smrg			.op = op,
464e88f27b3Smrg	};
465e88f27b3Smrg	return drmCommandWrite(bo->dev->fd,
466e88f27b3Smrg			DRM_OMAP_GEM_CPU_PREP, &req, sizeof(req));
467e88f27b3Smrg}
468e88f27b3Smrg
469e6188e58Smrgint omap_bo_cpu_fini(struct omap_bo *bo, enum omap_gem_op op)
470e88f27b3Smrg{
471e88f27b3Smrg	struct drm_omap_gem_cpu_fini req = {
472e88f27b3Smrg			.handle = bo->handle,
473e88f27b3Smrg			.op = op,
474e88f27b3Smrg			.nregions = 0,
475e88f27b3Smrg	};
476e88f27b3Smrg	return drmCommandWrite(bo->dev->fd,
477e88f27b3Smrg			DRM_OMAP_GEM_CPU_FINI, &req, sizeof(req));
478e88f27b3Smrg}
479