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.
15 #define _FILE_OFFSET_BITS 64
24 #include <sys/ioctl.h>
27 #include "exynos_drm.h"
36 exynos_get_prop(struct kms_driver *kms, unsigned key, unsigned *out)
40 *out = KMS_BO_TYPE_SCANOUT_X8R8G8B8 | KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8;
49 exynos_destroy(struct kms_driver *kms)
56 exynos_bo_create(struct kms_driver *kms,
57 const unsigned width, const unsigned height,
58 const enum kms_bo_type type, const unsigned *attr,
61 struct drm_exynos_gem_create arg;
66 for (i = 0; attr[i]; i += 2) {
77 bo = calloc(1, sizeof(*bo));
81 if (type == KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8) {
84 } else if (type == KMS_BO_TYPE_SCANOUT_X8R8G8B8) {
86 pitch = (pitch + 512 - 1) & ~(512 - 1);
87 size = pitch * ((height + 4 - 1) & ~(4 - 1));
92 memset(&arg, 0, sizeof(arg));
95 ret = drmCommandWriteRead(kms->fd, DRM_EXYNOS_GEM_CREATE, &arg, sizeof(arg));
100 bo->base.handle = arg.handle;
101 bo->base.size = size;
102 bo->base.pitch = pitch;
114 exynos_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out)
123 exynos_bo_map(struct kms_bo *_bo, void **out)
125 struct exynos_bo *bo = (struct exynos_bo *)_bo;
126 struct drm_exynos_gem_map_off arg;
136 memset(&arg, 0, sizeof(arg));
137 arg.handle = bo->base.handle;
139 ret = drmCommandWriteRead(bo->base.kms->fd, DRM_EXYNOS_GEM_MAP_OFFSET, &arg, sizeof(arg));
143 map = mmap(0, bo->base.size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->base.kms->fd, arg.offset);
144 if (map == MAP_FAILED)
155 exynos_bo_unmap(struct kms_bo *_bo)
157 struct exynos_bo *bo = (struct exynos_bo *)_bo;
163 exynos_bo_destroy(struct kms_bo *_bo)
165 struct exynos_bo *bo = (struct exynos_bo *)_bo;
166 struct drm_gem_close arg;
170 /* XXX Sanity check map_count */
171 munmap(bo->base.ptr, bo->base.size);
175 memset(&arg, 0, sizeof(arg));
176 arg.handle = bo->base.handle;
178 ret = drmIoctl(bo->base.kms->fd, DRM_IOCTL_GEM_CLOSE, &arg);
187 exynos_create(int fd, struct kms_driver **out)
189 struct kms_driver *kms;
191 kms = calloc(1, sizeof(*kms));
197 kms->bo_create = exynos_bo_create;
198 kms->bo_map = exynos_bo_map;
199 kms->bo_unmap = exynos_bo_unmap;
200 kms->bo_get_prop = exynos_bo_get_prop;
201 kms->bo_destroy = exynos_bo_destroy;
202 kms->get_prop = exynos_get_prop;
203 kms->destroy = exynos_destroy;