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>
29 #include "exynos_drm.h"
38 exynos_get_prop(struct kms_driver *kms, unsigned key, unsigned *out)
42 *out = KMS_BO_TYPE_SCANOUT_X8R8G8B8 | KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8;
51 exynos_destroy(struct kms_driver *kms)
58 exynos_bo_create(struct kms_driver *kms,
59 const unsigned width, const unsigned height,
60 const enum kms_bo_type type, const unsigned *attr,
63 struct drm_exynos_gem_create arg;
68 for (i = 0; attr[i]; i += 2) {
79 bo = calloc(1, sizeof(*bo));
83 if (type == KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8) {
86 } else if (type == KMS_BO_TYPE_SCANOUT_X8R8G8B8) {
88 pitch = (pitch + 512 - 1) & ~(512 - 1);
89 size = pitch * ((height + 4 - 1) & ~(4 - 1));
94 memset(&arg, 0, sizeof(arg));
97 ret = drmCommandWriteRead(kms->fd, DRM_EXYNOS_GEM_CREATE, &arg, sizeof(arg));
102 bo->base.handle = arg.handle;
103 bo->base.size = size;
104 bo->base.pitch = pitch;
116 exynos_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out)
125 exynos_bo_map(struct kms_bo *_bo, void **out)
127 struct exynos_bo *bo = (struct exynos_bo *)_bo;
128 struct drm_mode_map_dumb arg;
138 memset(&arg, 0, sizeof(arg));
139 arg.handle = bo->base.handle;
141 ret = drmIoctl(bo->base.kms->fd, DRM_IOCTL_MODE_MAP_DUMB, &arg);
145 map = drm_mmap(0, bo->base.size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->base.kms->fd, arg.offset);
146 if (map == MAP_FAILED)
157 exynos_bo_unmap(struct kms_bo *_bo)
159 struct exynos_bo *bo = (struct exynos_bo *)_bo;
165 exynos_bo_destroy(struct kms_bo *_bo)
167 struct exynos_bo *bo = (struct exynos_bo *)_bo;
168 struct drm_gem_close arg;
172 /* XXX Sanity check map_count */
173 munmap(bo->base.ptr, bo->base.size);
177 memset(&arg, 0, sizeof(arg));
178 arg.handle = bo->base.handle;
180 ret = drmIoctl(bo->base.kms->fd, DRM_IOCTL_GEM_CLOSE, &arg);
189 exynos_create(int fd, struct kms_driver **out)
191 struct kms_driver *kms;
193 kms = calloc(1, sizeof(*kms));
199 kms->bo_create = exynos_bo_create;
200 kms->bo_map = exynos_bo_map;
201 kms->bo_unmap = exynos_bo_unmap;
202 kms->bo_get_prop = exynos_bo_get_prop;
203 kms->bo_destroy = exynos_bo_destroy;
204 kms->get_prop = exynos_get_prop;
205 kms->destroy = exynos_destroy;