3 * Copyright 2009 Samsung Electronics Co., Ltd.
5 * SooChan Lim <sc1.lim@samsung.com>
6 * Sangjin LEE <lsj119@samsung.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
25 #include <sys/ioctl.h>
28 #include "exynos_drm.h"
37 exynos_get_prop(struct kms_driver *kms, unsigned key, unsigned *out)
41 *out = KMS_BO_TYPE_SCANOUT_X8R8G8B8 | KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8;
50 exynos_destroy(struct kms_driver *kms)
57 exynos_bo_create(struct kms_driver *kms,
58 const unsigned width, const unsigned height,
59 const enum kms_bo_type type, const unsigned *attr,
62 struct drm_exynos_gem_create arg;
67 for (i = 0; attr[i]; i += 2) {
78 bo = calloc(1, sizeof(*bo));
82 if (type == KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8) {
85 } else if (type == KMS_BO_TYPE_SCANOUT_X8R8G8B8) {
87 pitch = (pitch + 512 - 1) & ~(512 - 1);
88 size = pitch * ((height + 4 - 1) & ~(4 - 1));
93 memset(&arg, 0, sizeof(arg));
96 ret = drmCommandWriteRead(kms->fd, DRM_EXYNOS_GEM_CREATE, &arg, sizeof(arg));
101 bo->base.handle = arg.handle;
102 bo->base.size = size;
103 bo->base.pitch = pitch;
115 exynos_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out)
124 exynos_bo_map(struct kms_bo *_bo, void **out)
126 struct exynos_bo *bo = (struct exynos_bo *)_bo;
127 struct drm_exynos_gem_map_off arg;
137 memset(&arg, 0, sizeof(arg));
138 arg.handle = bo->base.handle;
140 ret = drmCommandWriteRead(bo->base.kms->fd, DRM_EXYNOS_GEM_MAP_OFFSET, &arg, sizeof(arg));
144 map = mmap(0, bo->base.size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->base.kms->fd, arg.offset);
145 if (map == MAP_FAILED)
156 exynos_bo_unmap(struct kms_bo *_bo)
158 struct exynos_bo *bo = (struct exynos_bo *)_bo;
164 exynos_bo_destroy(struct kms_bo *_bo)
166 struct exynos_bo *bo = (struct exynos_bo *)_bo;
167 struct drm_gem_close arg;
171 /* XXX Sanity check map_count */
172 munmap(bo->base.ptr, bo->base.size);
176 memset(&arg, 0, sizeof(arg));
177 arg.handle = bo->base.handle;
179 ret = drmIoctl(bo->base.kms->fd, DRM_IOCTL_GEM_CLOSE, &arg);
188 exynos_create(int fd, struct kms_driver **out)
190 struct kms_driver *kms;
192 kms = calloc(1, sizeof(*kms));
198 kms->bo_create = exynos_bo_create;
199 kms->bo_map = exynos_bo_map;
200 kms->bo_unmap = exynos_bo_unmap;
201 kms->bo_get_prop = exynos_bo_get_prop;
202 kms->bo_destroy = exynos_bo_destroy;
203 kms->get_prop = exynos_get_prop;
204 kms->destroy = exynos_destroy;