2 * Copyright (C) 2012 Samsung Electronics Co., Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
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 FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Inki Dae <inki.dae@samsung.com>
37 #include <linux/stddef.h>
41 #include "exynos_drm.h"
42 #include "exynos_drmif.h"
45 * Create exynos drm device object.
47 * @fd: file descriptor to exynos drm driver opened.
49 * if true, return the device object else NULL.
51 struct exynos_device * exynos_device_create(int fd)
53 struct exynos_device *dev;
55 dev = calloc(sizeof(*dev), 1);
57 fprintf(stderr, "failed to create device[%s].\n",
68 * Destroy exynos drm device object
70 * @dev: exynos drm device object.
72 void exynos_device_destroy(struct exynos_device *dev)
78 * Create a exynos buffer object to exynos drm device.
80 * @dev: exynos drm device object.
81 * @size: user-desired size.
82 * flags: user-desired memory type.
83 * user can set one or more types among several types to memory
84 * allocation and cache attribute types. and as default,
85 * EXYNOS_BO_NONCONTIG and EXYNOS-BO_NONCACHABLE types would
88 * if true, return a exynos buffer object else NULL.
90 struct exynos_bo * exynos_bo_create(struct exynos_device *dev,
91 size_t size, uint32_t flags)
94 struct drm_exynos_gem_create req = {
100 fprintf(stderr, "invalid size.\n");
104 bo = calloc(sizeof(*bo), 1);
106 fprintf(stderr, "failed to create bo[%s].\n",
113 if (drmIoctl(dev->fd, DRM_IOCTL_EXYNOS_GEM_CREATE, &req)){
114 fprintf(stderr, "failed to create gem object[%s].\n",
119 bo->handle = req.handle;
132 * Get information to gem region allocated.
134 * @dev: exynos drm device object.
135 * @handle: gem handle to request gem info.
136 * @size: size to gem object and returned by kernel side.
137 * @flags: gem flags to gem object and returned by kernel side.
139 * with this function call, you can get flags and size to gem handle
142 * if true, return 0 else negative.
144 int exynos_bo_get_info(struct exynos_device *dev, uint32_t handle,
145 size_t *size, uint32_t *flags)
148 struct drm_exynos_gem_info req = {
152 ret = drmIoctl(dev->fd, DRM_IOCTL_EXYNOS_GEM_GET, &req);
154 fprintf(stderr, "failed to get gem object information[%s].\n",
166 * Destroy a exynos buffer object.
168 * @bo: a exynos buffer object to be destroyed.
170 void exynos_bo_destroy(struct exynos_bo *bo)
176 munmap(bo->vaddr, bo->size);
179 struct drm_gem_close req = {
180 .handle = bo->handle,
183 drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_CLOSE, &req);
191 * Get a exynos buffer object from a gem global object name.
193 * @dev: a exynos device object.
194 * @name: a gem global object name exported by another process.
196 * this interface is used to get a exynos buffer object from a gem
197 * global object name sent by another process for buffer sharing.
199 * if true, return a exynos buffer object else NULL.
202 struct exynos_bo * exynos_bo_from_name(struct exynos_device *dev, uint32_t name)
204 struct exynos_bo *bo;
205 struct drm_gem_open req = {
209 bo = calloc(sizeof(*bo), 1);
211 fprintf(stderr, "failed to allocate bo[%s].\n",
216 if (drmIoctl(dev->fd, DRM_IOCTL_GEM_OPEN, &req)) {
217 fprintf(stderr, "failed to open gem object[%s].\n",
224 bo->handle = req.handle;
234 * Get a gem global object name from a gem object handle.
236 * @bo: a exynos buffer object including gem handle.
237 * @name: a gem global object name to be got by kernel driver.
239 * this interface is used to get a gem global object name from a gem object
240 * handle to a buffer that wants to share it with another process.
242 * if true, return 0 else negative.
244 int exynos_bo_get_name(struct exynos_bo *bo, uint32_t *name)
247 struct drm_gem_flink req = {
248 .handle = bo->handle,
252 ret = drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_FLINK, &req);
254 fprintf(stderr, "failed to get gem global name[%s].\n",
267 uint32_t exynos_bo_handle(struct exynos_bo *bo)
273 * Mmap a buffer to user space.
275 * @bo: a exynos buffer object including a gem object handle to be mmapped
278 * if true, user pointer mmaped else NULL.
280 void *exynos_bo_map(struct exynos_bo *bo)
283 struct exynos_device *dev = bo->dev;
284 struct drm_exynos_gem_mmap req = {
285 .handle = bo->handle,
290 ret = drmIoctl(dev->fd, DRM_IOCTL_EXYNOS_GEM_MMAP, &req);
292 fprintf(stderr, "failed to mmap[%s].\n",
297 bo->vaddr = req.mapped;
304 * Export gem object to dmabuf as file descriptor.
306 * @dev: a exynos device object.
307 * @handle: gem handle to be exported into dmabuf as file descriptor.
308 * @fd: file descriptor to dmabuf exported from gem handle and
309 * returned by kernel side.
311 * if true, return 0 else negative.
313 int exynos_prime_handle_to_fd(struct exynos_device *dev, uint32_t handle,
317 struct drm_prime_handle req = {
321 ret = drmIoctl(dev->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &req);
323 fprintf(stderr, "failed to mmap[%s].\n",
333 * Import file descriptor into gem handle.
335 * @dev: a exynos device object.
336 * @fd: file descriptor exported into dmabuf.
337 * @handle: gem handle to gem object imported from file descriptor
338 * and returned by kernel side.
340 * if true, return 0 else negative.
342 int exynos_prime_fd_to_handle(struct exynos_device *dev, int fd,
346 struct drm_prime_handle req = {
350 ret = drmIoctl(dev->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &req);
352 fprintf(stderr, "failed to mmap[%s].\n",
357 *handle = req.handle;
364 * Request Wireless Display connection or disconnection.
366 * @dev: a exynos device object.
367 * @connect: indicate whether connectoin or disconnection request.
368 * @ext: indicate whether edid data includes extentions data or not.
369 * @edid: a pointer to edid data from Wireless Display device.
371 * this interface is used to request Virtual Display driver connection or
372 * disconnection. for this, user should get a edid data from the Wireless
373 * Display device and then send that data to kernel driver with connection
376 * if true, return 0 else negative.
378 int exynos_vidi_connection(struct exynos_device *dev, uint32_t connect,
379 uint32_t ext, void *edid)
381 struct drm_exynos_vidi_connection req = {
382 .connection = connect,
388 ret = drmIoctl(dev->fd, DRM_IOCTL_EXYNOS_VIDI_CONNECTION, &req);
390 fprintf(stderr, "failed to request vidi connection[%s].\n",