3 * Copyright 2009 Samsung Electronics Co., Ltd.
5 * SooChan Lim <sc1.lim@samsung.com>
6 * Sangjin LEE <lsj119@samsung.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 #include <sys/ioctl.h>
38 #include "libdrm_macros.h"
39 #include "exynos_drm.h"
48 exynos_get_prop(struct kms_driver *kms, unsigned key, unsigned *out)
52 *out = KMS_BO_TYPE_SCANOUT_X8R8G8B8 | KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8;
61 exynos_destroy(struct kms_driver *kms)
68 exynos_bo_create(struct kms_driver *kms,
69 const unsigned width, const unsigned height,
70 const enum kms_bo_type type, const unsigned *attr,
73 struct drm_exynos_gem_create arg;
78 for (i = 0; attr[i]; i += 2) {
89 bo = calloc(1, sizeof(*bo));
93 if (type == KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8) {
96 } else if (type == KMS_BO_TYPE_SCANOUT_X8R8G8B8) {
98 pitch = (pitch + 512 - 1) & ~(512 - 1);
99 size = pitch * ((height + 4 - 1) & ~(4 - 1));
105 memset(&arg, 0, sizeof(arg));
108 ret = drmCommandWriteRead(kms->fd, DRM_EXYNOS_GEM_CREATE, &arg, sizeof(arg));
113 bo->base.handle = arg.handle;
114 bo->base.size = size;
115 bo->base.pitch = pitch;
127 exynos_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out)
136 exynos_bo_map(struct kms_bo *_bo, void **out)
138 struct exynos_bo *bo = (struct exynos_bo *)_bo;
139 struct drm_exynos_gem_map arg;
149 memset(&arg, 0, sizeof(arg));
150 arg.handle = bo->base.handle;
152 ret = drmIoctl(bo->base.kms->fd, DRM_IOCTL_EXYNOS_GEM_MAP, &arg);
156 map = drm_mmap(0, bo->base.size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->base.kms->fd, arg.offset);
157 if (map == MAP_FAILED)
168 exynos_bo_unmap(struct kms_bo *_bo)
170 struct exynos_bo *bo = (struct exynos_bo *)_bo;
176 exynos_bo_destroy(struct kms_bo *_bo)
178 struct exynos_bo *bo = (struct exynos_bo *)_bo;
179 struct drm_gem_close arg;
183 /* XXX Sanity check map_count */
184 munmap(bo->base.ptr, bo->base.size);
188 memset(&arg, 0, sizeof(arg));
189 arg.handle = bo->base.handle;
191 ret = drmIoctl(bo->base.kms->fd, DRM_IOCTL_GEM_CLOSE, &arg);
200 exynos_create(int fd, struct kms_driver **out)
202 struct kms_driver *kms;
204 kms = calloc(1, sizeof(*kms));
210 kms->bo_create = exynos_bo_create;
211 kms->bo_map = exynos_bo_map;
212 kms->bo_unmap = exynos_bo_unmap;
213 kms->bo_get_prop = exynos_bo_get_prop;
214 kms->bo_destroy = exynos_bo_destroy;
215 kms->get_prop = exynos_get_prop;
216 kms->destroy = exynos_destroy;