omap_drm.c revision 7cdc0497
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#include <stdlib.h>
30e88f27b3Smrg#include <linux/stddef.h>
31e88f27b3Smrg#include <linux/types.h>
32e88f27b3Smrg#include <errno.h>
33e88f27b3Smrg#include <sys/mman.h>
34e88f27b3Smrg#include <fcntl.h>
35e88f27b3Smrg#include <unistd.h>
36e88f27b3Smrg#include <pthread.h>
37e88f27b3Smrg
38e6188e58Smrg#include <libdrm_macros.h>
39e88f27b3Smrg#include <xf86drm.h>
40e88f27b3Smrg#include <xf86atomic.h>
41e88f27b3Smrg
42e88f27b3Smrg#include "omap_drm.h"
43e88f27b3Smrg#include "omap_drmif.h"
44e88f27b3Smrg
45e88f27b3Smrg#define __round_mask(x, y) ((__typeof__(x))((y)-1))
46e88f27b3Smrg#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
47e88f27b3Smrg#define PAGE_SIZE 4096
48e88f27b3Smrg
49e88f27b3Smrgstatic pthread_mutex_t table_lock = PTHREAD_MUTEX_INITIALIZER;
50e88f27b3Smrgstatic void * dev_table;
51e88f27b3Smrg
52e88f27b3Smrgstruct omap_device {
53e88f27b3Smrg	int fd;
54e88f27b3Smrg	atomic_t refcnt;
55e88f27b3Smrg
56e88f27b3Smrg	/* The handle_table is used to track GEM bo handles associated w/
57e88f27b3Smrg	 * this fd.  This is needed, in particular, when importing
58e88f27b3Smrg	 * dmabuf's because we don't want multiple 'struct omap_bo's
59e88f27b3Smrg	 * floating around with the same handle.  Otherwise, when the
60e88f27b3Smrg	 * first one is omap_bo_del()'d the handle becomes no longer
61e88f27b3Smrg	 * valid, and the remaining 'struct omap_bo's are left pointing
62e88f27b3Smrg	 * to an invalid handle (and possible a GEM bo that is already
63e88f27b3Smrg	 * free'd).
64e88f27b3Smrg	 */
65e88f27b3Smrg	void *handle_table;
66e88f27b3Smrg};
67e88f27b3Smrg
68e88f27b3Smrg/* a GEM buffer object allocated from the DRM device */
69e88f27b3Smrgstruct omap_bo {
70e88f27b3Smrg	struct omap_device	*dev;
71e88f27b3Smrg	void		*map;		/* userspace mmap'ing (if there is one) */
72e88f27b3Smrg	uint32_t	size;
73e88f27b3Smrg	uint32_t	handle;
74e88f27b3Smrg	uint32_t	name;		/* flink global handle (DRI2 name) */
75e88f27b3Smrg	uint64_t	offset;		/* offset to mmap() */
76e88f27b3Smrg	int		fd;		/* dmabuf handle */
77e88f27b3Smrg	atomic_t	refcnt;
78e88f27b3Smrg};
79e88f27b3Smrg
80e88f27b3Smrgstatic struct omap_device * omap_device_new_impl(int fd)
81e88f27b3Smrg{
82e88f27b3Smrg	struct omap_device *dev = calloc(sizeof(*dev), 1);
83e88f27b3Smrg	if (!dev)
84e88f27b3Smrg		return NULL;
85e88f27b3Smrg	dev->fd = fd;
86e88f27b3Smrg	atomic_set(&dev->refcnt, 1);
87e88f27b3Smrg	dev->handle_table = drmHashCreate();
88e88f27b3Smrg	return dev;
89e88f27b3Smrg}
90e88f27b3Smrg
917cdc0497Smrgdrm_public struct omap_device * omap_device_new(int fd)
92e88f27b3Smrg{
93e88f27b3Smrg	struct omap_device *dev = NULL;
94e88f27b3Smrg
95e88f27b3Smrg	pthread_mutex_lock(&table_lock);
96e88f27b3Smrg
97e88f27b3Smrg	if (!dev_table)
98e88f27b3Smrg		dev_table = drmHashCreate();
99e88f27b3Smrg
100e88f27b3Smrg	if (drmHashLookup(dev_table, fd, (void **)&dev)) {
101e88f27b3Smrg		/* not found, create new device */
102e88f27b3Smrg		dev = omap_device_new_impl(fd);
103e88f27b3Smrg		drmHashInsert(dev_table, fd, dev);
104e88f27b3Smrg	} else {
105e88f27b3Smrg		/* found, just incr refcnt */
106e88f27b3Smrg		dev = omap_device_ref(dev);
107e88f27b3Smrg	}
108e88f27b3Smrg
109e88f27b3Smrg	pthread_mutex_unlock(&table_lock);
110e88f27b3Smrg
111e88f27b3Smrg	return dev;
112e88f27b3Smrg}
113e88f27b3Smrg
1147cdc0497Smrgdrm_public struct omap_device * omap_device_ref(struct omap_device *dev)
115e88f27b3Smrg{
116e88f27b3Smrg	atomic_inc(&dev->refcnt);
117e88f27b3Smrg	return dev;
118e88f27b3Smrg}
119e88f27b3Smrg
1207cdc0497Smrgdrm_public void omap_device_del(struct omap_device *dev)
121e88f27b3Smrg{
122e88f27b3Smrg	if (!atomic_dec_and_test(&dev->refcnt))
123e88f27b3Smrg		return;
124e88f27b3Smrg	pthread_mutex_lock(&table_lock);
125e88f27b3Smrg	drmHashDestroy(dev->handle_table);
126e88f27b3Smrg	drmHashDelete(dev_table, dev->fd);
127e88f27b3Smrg	pthread_mutex_unlock(&table_lock);
128e88f27b3Smrg	free(dev);
129e88f27b3Smrg}
130e88f27b3Smrg
1317cdc0497Smrgdrm_public int
132baaff307Smrgomap_get_param(struct omap_device *dev, uint64_t param, uint64_t *value)
133e88f27b3Smrg{
134e88f27b3Smrg	struct drm_omap_param req = {
135e88f27b3Smrg			.param = param,
136e88f27b3Smrg	};
137e88f27b3Smrg	int ret;
138e88f27b3Smrg
139e88f27b3Smrg	ret = drmCommandWriteRead(dev->fd, DRM_OMAP_GET_PARAM, &req, sizeof(req));
140e88f27b3Smrg	if (ret) {
141e88f27b3Smrg		return ret;
142e88f27b3Smrg	}
143e88f27b3Smrg
144e88f27b3Smrg	*value = req.value;
145e88f27b3Smrg
146e88f27b3Smrg	return 0;
147e88f27b3Smrg}
148e88f27b3Smrg
1497cdc0497Smrgdrm_public int
150baaff307Smrgomap_set_param(struct omap_device *dev, uint64_t param, uint64_t value)
151e88f27b3Smrg{
152e88f27b3Smrg	struct drm_omap_param req = {
153e88f27b3Smrg			.param = param,
154e88f27b3Smrg			.value = value,
155e88f27b3Smrg	};
156e88f27b3Smrg	return drmCommandWrite(dev->fd, DRM_OMAP_SET_PARAM, &req, sizeof(req));
157e88f27b3Smrg}
158e88f27b3Smrg
159e88f27b3Smrg/* lookup a buffer from it's handle, call w/ table_lock held: */
160e88f27b3Smrgstatic struct omap_bo * lookup_bo(struct omap_device *dev,
161e88f27b3Smrg		uint32_t handle)
162e88f27b3Smrg{
163e88f27b3Smrg	struct omap_bo *bo = NULL;
164e88f27b3Smrg	if (!drmHashLookup(dev->handle_table, handle, (void **)&bo)) {
165e88f27b3Smrg		/* found, incr refcnt and return: */
166e88f27b3Smrg		bo = omap_bo_ref(bo);
167e88f27b3Smrg	}
168e88f27b3Smrg	return bo;
169e88f27b3Smrg}
170e88f27b3Smrg
171e88f27b3Smrg/* allocate a new buffer object, call w/ table_lock held */
172e88f27b3Smrgstatic struct omap_bo * bo_from_handle(struct omap_device *dev,
173e88f27b3Smrg		uint32_t handle)
174e88f27b3Smrg{
175e88f27b3Smrg	struct omap_bo *bo = calloc(sizeof(*bo), 1);
176e88f27b3Smrg	if (!bo) {
177e88f27b3Smrg		struct drm_gem_close req = {
178e88f27b3Smrg				.handle = handle,
179e88f27b3Smrg		};
180e88f27b3Smrg		drmIoctl(dev->fd, DRM_IOCTL_GEM_CLOSE, &req);
181e88f27b3Smrg		return NULL;
182e88f27b3Smrg	}
183e88f27b3Smrg	bo->dev = omap_device_ref(dev);
184e88f27b3Smrg	bo->handle = handle;
1853f012e29Smrg	bo->fd = -1;
186e88f27b3Smrg	atomic_set(&bo->refcnt, 1);
187e88f27b3Smrg	/* add ourselves to the handle table: */
188e88f27b3Smrg	drmHashInsert(dev->handle_table, handle, bo);
189e88f27b3Smrg	return bo;
190e88f27b3Smrg}
191e88f27b3Smrg
192e88f27b3Smrg/* allocate a new buffer object */
193e88f27b3Smrgstatic struct omap_bo * omap_bo_new_impl(struct omap_device *dev,
194e88f27b3Smrg		union omap_gem_size size, uint32_t flags)
195e88f27b3Smrg{
196e88f27b3Smrg	struct omap_bo *bo = NULL;
197e88f27b3Smrg	struct drm_omap_gem_new req = {
198e88f27b3Smrg			.size = size,
199e88f27b3Smrg			.flags = flags,
200e88f27b3Smrg	};
201e88f27b3Smrg
202e88f27b3Smrg	if (size.bytes == 0) {
203e88f27b3Smrg		goto fail;
204e88f27b3Smrg	}
205e88f27b3Smrg
206e88f27b3Smrg	if (drmCommandWriteRead(dev->fd, DRM_OMAP_GEM_NEW, &req, sizeof(req))) {
207e88f27b3Smrg		goto fail;
208e88f27b3Smrg	}
209e88f27b3Smrg
210e88f27b3Smrg	pthread_mutex_lock(&table_lock);
211e88f27b3Smrg	bo = bo_from_handle(dev, req.handle);
212e88f27b3Smrg	pthread_mutex_unlock(&table_lock);
213e88f27b3Smrg
214e88f27b3Smrg	if (flags & OMAP_BO_TILED) {
215e88f27b3Smrg		bo->size = round_up(size.tiled.width, PAGE_SIZE) * size.tiled.height;
216e88f27b3Smrg	} else {
217e88f27b3Smrg		bo->size = size.bytes;
218e88f27b3Smrg	}
219e88f27b3Smrg
220e88f27b3Smrg	return bo;
221e88f27b3Smrg
222e88f27b3Smrgfail:
223e88f27b3Smrg	free(bo);
224e88f27b3Smrg	return NULL;
225e88f27b3Smrg}
226e88f27b3Smrg
227e88f27b3Smrg
228e88f27b3Smrg/* allocate a new (un-tiled) buffer object */
2297cdc0497Smrgdrm_public struct omap_bo *
230baaff307Smrgomap_bo_new(struct omap_device *dev, uint32_t size, uint32_t flags)
231e88f27b3Smrg{
232e88f27b3Smrg	union omap_gem_size gsize = {
233e88f27b3Smrg			.bytes = size,
234e88f27b3Smrg	};
235e88f27b3Smrg	if (flags & OMAP_BO_TILED) {
236e88f27b3Smrg		return NULL;
237e88f27b3Smrg	}
238e88f27b3Smrg	return omap_bo_new_impl(dev, gsize, flags);
239e88f27b3Smrg}
240e88f27b3Smrg
241e88f27b3Smrg/* allocate a new buffer object */
2427cdc0497Smrgdrm_public struct omap_bo *
243baaff307Smrgomap_bo_new_tiled(struct omap_device *dev, uint32_t width,
244baaff307Smrg		  uint32_t height, uint32_t flags)
245e88f27b3Smrg{
246e88f27b3Smrg	union omap_gem_size gsize = {
247e88f27b3Smrg			.tiled = {
248e88f27b3Smrg				.width = width,
249e88f27b3Smrg				.height = height,
250e88f27b3Smrg			},
251e88f27b3Smrg	};
252e88f27b3Smrg	if (!(flags & OMAP_BO_TILED)) {
253e88f27b3Smrg		return NULL;
254e88f27b3Smrg	}
255e88f27b3Smrg	return omap_bo_new_impl(dev, gsize, flags);
256e88f27b3Smrg}
257e88f27b3Smrg
2587cdc0497Smrgdrm_public struct omap_bo *omap_bo_ref(struct omap_bo *bo)
259e88f27b3Smrg{
260e88f27b3Smrg	atomic_inc(&bo->refcnt);
261e88f27b3Smrg	return bo;
262e88f27b3Smrg}
263e88f27b3Smrg
264e88f27b3Smrg/* get buffer info */
265e88f27b3Smrgstatic int get_buffer_info(struct omap_bo *bo)
266e88f27b3Smrg{
267e88f27b3Smrg	struct drm_omap_gem_info req = {
268e88f27b3Smrg			.handle = bo->handle,
269e88f27b3Smrg	};
270e88f27b3Smrg	int ret = drmCommandWriteRead(bo->dev->fd, DRM_OMAP_GEM_INFO,
271e88f27b3Smrg			&req, sizeof(req));
272e88f27b3Smrg	if (ret) {
273e88f27b3Smrg		return ret;
274e88f27b3Smrg	}
275e88f27b3Smrg
276e88f27b3Smrg	/* really all we need for now is mmap offset */
277e88f27b3Smrg	bo->offset = req.offset;
278e88f27b3Smrg	bo->size = req.size;
279e88f27b3Smrg
280e88f27b3Smrg	return 0;
281e88f27b3Smrg}
282e88f27b3Smrg
283e88f27b3Smrg/* import a buffer object from DRI2 name */
2847cdc0497Smrgdrm_public struct omap_bo *
285baaff307Smrgomap_bo_from_name(struct omap_device *dev, uint32_t name)
286e88f27b3Smrg{
287e88f27b3Smrg	struct omap_bo *bo = NULL;
288e88f27b3Smrg	struct drm_gem_open req = {
289e88f27b3Smrg			.name = name,
290e88f27b3Smrg	};
291e88f27b3Smrg
292e88f27b3Smrg	pthread_mutex_lock(&table_lock);
293e88f27b3Smrg
294e88f27b3Smrg	if (drmIoctl(dev->fd, DRM_IOCTL_GEM_OPEN, &req)) {
295e88f27b3Smrg		goto fail;
296e88f27b3Smrg	}
297e88f27b3Smrg
298e88f27b3Smrg	bo = lookup_bo(dev, req.handle);
299e88f27b3Smrg	if (!bo) {
300e88f27b3Smrg		bo = bo_from_handle(dev, req.handle);
301e88f27b3Smrg		bo->name = name;
302e88f27b3Smrg	}
303e88f27b3Smrg
304e88f27b3Smrg	pthread_mutex_unlock(&table_lock);
305e88f27b3Smrg
306e88f27b3Smrg	return bo;
307e88f27b3Smrg
308e88f27b3Smrgfail:
309e88f27b3Smrg	pthread_mutex_unlock(&table_lock);
310e88f27b3Smrg	free(bo);
311e88f27b3Smrg	return NULL;
312e88f27b3Smrg}
313e88f27b3Smrg
314e88f27b3Smrg/* import a buffer from dmabuf fd, does not take ownership of the
315e88f27b3Smrg * fd so caller should close() the fd when it is otherwise done
316e88f27b3Smrg * with it (even if it is still using the 'struct omap_bo *')
317e88f27b3Smrg */
3187cdc0497Smrgdrm_public struct omap_bo *
319baaff307Smrgomap_bo_from_dmabuf(struct omap_device *dev, int fd)
320e88f27b3Smrg{
321e88f27b3Smrg	struct omap_bo *bo = NULL;
322e88f27b3Smrg	struct drm_prime_handle req = {
323e88f27b3Smrg			.fd = fd,
324e88f27b3Smrg	};
325e88f27b3Smrg	int ret;
326e88f27b3Smrg
327e88f27b3Smrg	pthread_mutex_lock(&table_lock);
328e88f27b3Smrg
329e88f27b3Smrg	ret = drmIoctl(dev->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &req);
330e88f27b3Smrg	if (ret) {
331e88f27b3Smrg		goto fail;
332e88f27b3Smrg	}
333e88f27b3Smrg
334e88f27b3Smrg	bo = lookup_bo(dev, req.handle);
335e88f27b3Smrg	if (!bo) {
336e88f27b3Smrg		bo = bo_from_handle(dev, req.handle);
337e88f27b3Smrg	}
338e88f27b3Smrg
339e88f27b3Smrg	pthread_mutex_unlock(&table_lock);
340e88f27b3Smrg
341e88f27b3Smrg	return bo;
342e88f27b3Smrg
343e88f27b3Smrgfail:
344e88f27b3Smrg	pthread_mutex_unlock(&table_lock);
345e88f27b3Smrg	free(bo);
346e88f27b3Smrg	return NULL;
347e88f27b3Smrg}
348e88f27b3Smrg
349e88f27b3Smrg/* destroy a buffer object */
3507cdc0497Smrgdrm_public void omap_bo_del(struct omap_bo *bo)
351e88f27b3Smrg{
352e88f27b3Smrg	if (!bo) {
353e88f27b3Smrg		return;
354e88f27b3Smrg	}
355e88f27b3Smrg
356e88f27b3Smrg	if (!atomic_dec_and_test(&bo->refcnt))
357e88f27b3Smrg		return;
358e88f27b3Smrg
359e88f27b3Smrg	if (bo->map) {
360e88f27b3Smrg		munmap(bo->map, bo->size);
361e88f27b3Smrg	}
362e88f27b3Smrg
3633f012e29Smrg	if (bo->fd >= 0) {
364e88f27b3Smrg		close(bo->fd);
365e88f27b3Smrg	}
366e88f27b3Smrg
367e88f27b3Smrg	if (bo->handle) {
368e88f27b3Smrg		struct drm_gem_close req = {
369e88f27b3Smrg				.handle = bo->handle,
370e88f27b3Smrg		};
371e88f27b3Smrg		pthread_mutex_lock(&table_lock);
372e88f27b3Smrg		drmHashDelete(bo->dev->handle_table, bo->handle);
373e88f27b3Smrg		drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_CLOSE, &req);
374e88f27b3Smrg		pthread_mutex_unlock(&table_lock);
375e88f27b3Smrg	}
376e88f27b3Smrg
377e88f27b3Smrg	omap_device_del(bo->dev);
378e88f27b3Smrg
379e88f27b3Smrg	free(bo);
380e88f27b3Smrg}
381e88f27b3Smrg
382e88f27b3Smrg/* get the global flink/DRI2 buffer name */
3837cdc0497Smrgdrm_public int omap_bo_get_name(struct omap_bo *bo, uint32_t *name)
384e88f27b3Smrg{
385e88f27b3Smrg	if (!bo->name) {
386e88f27b3Smrg		struct drm_gem_flink req = {
387e88f27b3Smrg				.handle = bo->handle,
388e88f27b3Smrg		};
389e88f27b3Smrg		int ret;
390e88f27b3Smrg
391e88f27b3Smrg		ret = drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_FLINK, &req);
392e88f27b3Smrg		if (ret) {
393e88f27b3Smrg			return ret;
394e88f27b3Smrg		}
395e88f27b3Smrg
396e88f27b3Smrg		bo->name = req.name;
397e88f27b3Smrg	}
398e88f27b3Smrg
399e88f27b3Smrg	*name = bo->name;
400e88f27b3Smrg
401e88f27b3Smrg	return 0;
402e88f27b3Smrg}
403e88f27b3Smrg
4047cdc0497Smrgdrm_public uint32_t omap_bo_handle(struct omap_bo *bo)
405e88f27b3Smrg{
406e88f27b3Smrg	return bo->handle;
407e88f27b3Smrg}
408e88f27b3Smrg
409e88f27b3Smrg/* caller owns the dmabuf fd that is returned and is responsible
410e88f27b3Smrg * to close() it when done
411e88f27b3Smrg */
4127cdc0497Smrgdrm_public int omap_bo_dmabuf(struct omap_bo *bo)
413e88f27b3Smrg{
4143f012e29Smrg	if (bo->fd < 0) {
415e88f27b3Smrg		struct drm_prime_handle req = {
416e88f27b3Smrg				.handle = bo->handle,
417e88f27b3Smrg				.flags = DRM_CLOEXEC,
418e88f27b3Smrg		};
419e88f27b3Smrg		int ret;
420e88f27b3Smrg
421e88f27b3Smrg		ret = drmIoctl(bo->dev->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &req);
422e88f27b3Smrg		if (ret) {
423e88f27b3Smrg			return ret;
424e88f27b3Smrg		}
425e88f27b3Smrg
426e88f27b3Smrg		bo->fd = req.fd;
427e88f27b3Smrg	}
428e88f27b3Smrg	return dup(bo->fd);
429e88f27b3Smrg}
430e88f27b3Smrg
4317cdc0497Smrgdrm_public uint32_t omap_bo_size(struct omap_bo *bo)
432e88f27b3Smrg{
433e88f27b3Smrg	if (!bo->size) {
434e88f27b3Smrg		get_buffer_info(bo);
435e88f27b3Smrg	}
436e88f27b3Smrg	return bo->size;
437e88f27b3Smrg}
438e88f27b3Smrg
4397cdc0497Smrgdrm_public void *omap_bo_map(struct omap_bo *bo)
440e88f27b3Smrg{
441e88f27b3Smrg	if (!bo->map) {
442e88f27b3Smrg		if (!bo->offset) {
443e88f27b3Smrg			get_buffer_info(bo);
444e88f27b3Smrg		}
445e88f27b3Smrg
446e88f27b3Smrg		bo->map = mmap(0, bo->size, PROT_READ | PROT_WRITE,
447e88f27b3Smrg				MAP_SHARED, bo->dev->fd, bo->offset);
448e88f27b3Smrg		if (bo->map == MAP_FAILED) {
449e88f27b3Smrg			bo->map = NULL;
450e88f27b3Smrg		}
451e88f27b3Smrg	}
452e88f27b3Smrg	return bo->map;
453e88f27b3Smrg}
454e88f27b3Smrg
4557cdc0497Smrgdrm_public int omap_bo_cpu_prep(struct omap_bo *bo, enum omap_gem_op op)
456e88f27b3Smrg{
457e88f27b3Smrg	struct drm_omap_gem_cpu_prep req = {
458e88f27b3Smrg			.handle = bo->handle,
459e88f27b3Smrg			.op = op,
460e88f27b3Smrg	};
461e88f27b3Smrg	return drmCommandWrite(bo->dev->fd,
462e88f27b3Smrg			DRM_OMAP_GEM_CPU_PREP, &req, sizeof(req));
463e88f27b3Smrg}
464e88f27b3Smrg
4657cdc0497Smrgdrm_public int omap_bo_cpu_fini(struct omap_bo *bo, enum omap_gem_op op)
466e88f27b3Smrg{
467e88f27b3Smrg	struct drm_omap_gem_cpu_fini req = {
468e88f27b3Smrg			.handle = bo->handle,
469e88f27b3Smrg			.op = op,
470e88f27b3Smrg			.nregions = 0,
471e88f27b3Smrg	};
472e88f27b3Smrg	return drmCommandWrite(bo->dev->fd,
473e88f27b3Smrg			DRM_OMAP_GEM_CPU_FINI, &req, sizeof(req));
474e88f27b3Smrg}
475