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>
42 #include "exynos_drm.h"
43 #include "exynos_drmif.h"
46 * Create exynos drm device object.
48 * @fd: file descriptor to exynos drm driver opened.
50 * if true, return the device object else NULL.
52 drm_public struct exynos_device * exynos_device_create(int fd)
54 struct exynos_device *dev;
56 dev = calloc(sizeof(*dev), 1);
58 fprintf(stderr, "failed to create device[%s].\n",
69 * Destroy exynos drm device object
71 * @dev: exynos drm device object.
73 drm_public void exynos_device_destroy(struct exynos_device *dev)
79 * Create a exynos buffer object to exynos drm device.
81 * @dev: exynos drm device object.
82 * @size: user-desired size.
83 * flags: user-desired memory type.
84 * user can set one or more types among several types to memory
85 * allocation and cache attribute types. and as default,
86 * EXYNOS_BO_NONCONTIG and EXYNOS-BO_NONCACHABLE types would
89 * if true, return a exynos buffer object else NULL.
91 drm_public struct exynos_bo * exynos_bo_create(struct exynos_device *dev,
92 size_t size, uint32_t flags)
95 struct drm_exynos_gem_create req = {
101 fprintf(stderr, "invalid size.\n");
105 bo = calloc(sizeof(*bo), 1);
107 fprintf(stderr, "failed to create bo[%s].\n",
114 if (drmIoctl(dev->fd, DRM_IOCTL_EXYNOS_GEM_CREATE, &req)){
115 fprintf(stderr, "failed to create gem object[%s].\n",
120 bo->handle = req.handle;
133 * Get information to gem region allocated.
135 * @dev: exynos drm device object.
136 * @handle: gem handle to request gem info.
137 * @size: size to gem object and returned by kernel side.
138 * @flags: gem flags to gem object and returned by kernel side.
140 * with this function call, you can get flags and size to gem handle
143 * if true, return 0 else negative.
145 drm_public int exynos_bo_get_info(struct exynos_device *dev, uint32_t handle,
146 size_t *size, uint32_t *flags)
149 struct drm_exynos_gem_info req = {
153 ret = drmIoctl(dev->fd, DRM_IOCTL_EXYNOS_GEM_GET, &req);
155 fprintf(stderr, "failed to get gem object information[%s].\n",
167 * Destroy a exynos buffer object.
169 * @bo: a exynos buffer object to be destroyed.
171 drm_public void exynos_bo_destroy(struct exynos_bo *bo)
177 munmap(bo->vaddr, bo->size);
180 struct drm_gem_close req = {
181 .handle = bo->handle,
184 drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_CLOSE, &req);
192 * Get a exynos buffer object from a gem global object name.
194 * @dev: a exynos device object.
195 * @name: a gem global object name exported by another process.
197 * this interface is used to get a exynos buffer object from a gem
198 * global object name sent by another process for buffer sharing.
200 * if true, return a exynos buffer object else NULL.
203 drm_public struct exynos_bo *
204 exynos_bo_from_name(struct exynos_device *dev, uint32_t name)
206 struct exynos_bo *bo;
207 struct drm_gem_open req = {
211 bo = calloc(sizeof(*bo), 1);
213 fprintf(stderr, "failed to allocate bo[%s].\n",
218 if (drmIoctl(dev->fd, DRM_IOCTL_GEM_OPEN, &req)) {
219 fprintf(stderr, "failed to open gem object[%s].\n",
226 bo->handle = req.handle;
236 * Get a gem global object name from a gem object handle.
238 * @bo: a exynos buffer object including gem handle.
239 * @name: a gem global object name to be got by kernel driver.
241 * this interface is used to get a gem global object name from a gem object
242 * handle to a buffer that wants to share it with another process.
244 * if true, return 0 else negative.
246 drm_public int exynos_bo_get_name(struct exynos_bo *bo, uint32_t *name)
249 struct drm_gem_flink req = {
250 .handle = bo->handle,
254 ret = drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_FLINK, &req);
256 fprintf(stderr, "failed to get gem global name[%s].\n",
269 drm_public uint32_t exynos_bo_handle(struct exynos_bo *bo)
275 * Mmap a buffer to user space.
277 * @bo: a exynos buffer object including a gem object handle to be mmapped
280 * if true, user pointer mmaped else NULL.
282 drm_public void *exynos_bo_map(struct exynos_bo *bo)
285 struct exynos_device *dev = bo->dev;
286 struct drm_exynos_gem_mmap req = {
287 .handle = bo->handle,
292 ret = drmIoctl(dev->fd, DRM_IOCTL_EXYNOS_GEM_MMAP, &req);
294 fprintf(stderr, "failed to mmap[%s].\n",
299 bo->vaddr = (void *)(uintptr_t)req.mapped;
306 * Export gem object to dmabuf as file descriptor.
308 * @dev: exynos device object
309 * @handle: gem handle to export as file descriptor of dmabuf
310 * @fd: file descriptor returned from kernel
312 * @return: 0 on success, -1 on error, and errno will be set
315 exynos_prime_handle_to_fd(struct exynos_device *dev, uint32_t handle, int *fd)
317 return drmPrimeHandleToFD(dev->fd, handle, 0, fd);
321 * Import file descriptor into gem handle.
323 * @dev: exynos device object
324 * @fd: file descriptor of dmabuf to import
325 * @handle: gem handle returned from kernel
327 * @return: 0 on success, -1 on error, and errno will be set
330 exynos_prime_fd_to_handle(struct exynos_device *dev, int fd, uint32_t *handle)
332 return drmPrimeFDToHandle(dev->fd, fd, handle);
338 * Request Wireless Display connection or disconnection.
340 * @dev: a exynos device object.
341 * @connect: indicate whether connectoin or disconnection request.
342 * @ext: indicate whether edid data includes extentions data or not.
343 * @edid: a pointer to edid data from Wireless Display device.
345 * this interface is used to request Virtual Display driver connection or
346 * disconnection. for this, user should get a edid data from the Wireless
347 * Display device and then send that data to kernel driver with connection
350 * if true, return 0 else negative.
353 exynos_vidi_connection(struct exynos_device *dev, uint32_t connect,
354 uint32_t ext, void *edid)
356 struct drm_exynos_vidi_connection req = {
357 .connection = connect,
359 .edid = (uint64_t)(uintptr_t)edid,
363 ret = drmIoctl(dev->fd, DRM_IOCTL_EXYNOS_VIDI_CONNECTION, &req);
365 fprintf(stderr, "failed to request vidi connection[%s].\n",