From patchwork Fri Jan 10 07:44:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyungwon Hwang X-Patchwork-Id: 3464941 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 780B9C02DC for ; Fri, 10 Jan 2014 07:44:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 79B3C2010C for ; Fri, 10 Jan 2014 07:44:43 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id E49D620122 for ; Fri, 10 Jan 2014 07:44:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DD88BFC18B; Thu, 9 Jan 2014 23:44:38 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by gabe.freedesktop.org (Postfix) with ESMTP id 4BD7AFC1CF for ; Thu, 9 Jan 2014 23:44:37 -0800 (PST) Received: from epcpsbgr3.samsung.com (u143.gpu120.samsung.co.kr [203.254.230.143]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MZ6009ADDI7MVD0@mailout1.samsung.com> for dri-devel@lists.freedesktop.org; Fri, 10 Jan 2014 16:44:31 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.116]) by epcpsbgr3.samsung.com (EPCPMTA) with SMTP id EB.4C.10092.FD4AFC25; Fri, 10 Jan 2014 16:44:31 +0900 (KST) X-AuditID: cbfee68f-b7f156d00000276c-dd-52cfa4df04d6 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 86.DB.28157.FD4AFC25; Fri, 10 Jan 2014 16:44:31 +0900 (KST) Received: from hwh-ubuntu ([10.252.81.131]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MZ6001H0DI7D940@mmp1.samsung.com>; Fri, 10 Jan 2014 16:44:31 +0900 (KST) Date: Fri, 10 Jan 2014 16:44:30 +0900 From: Hyungwon Hwang To: Rob Clark Subject: [PATCH RESEND] tests/kmstest: support exynos Message-id: <20140110164430.3ee2c409@hwh-ubuntu> In-reply-to: References: <20140107154054.77daf1c5@hwh-ubuntu> Organization: Samsung Electronics. X-Mailer: Claws Mail 3.9.3 (GTK+ 2.24.13; i686-pc-linux-gnu) MIME-version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOIsWRmVeSWpSXmKPExsWyRsSkRPf+kvNBBj92q1hcP29nceXrezaL SfcnsFg8X/iD2WLG5JdsDqweO2fdZfe4332cyaNvyyrGAOYoLpuU1JzMstQifbsErowbB9rZ C67rV6zo38/WwPhCtYuRk0NCwERi97SvjBC2mMSFe+vZuhi5OIQEljJKfOj7ygJTtPzTTXaI xCJGiRkd85kgnN+MEivX/GADqWIRUJW4dn0zE4jNJqAnseDaD3YQW0RAWWLV1v1gk5gFVjJK nP4pAWILC5hKLF6xHqyGV8BA4t7HLmYQm1MgWOL9h0NgM4UEyiX+XNgCdh6/gJLEzdaJzBAX 2UhMXbOUCaJXUOLH5HtQ87UkNm9rYoWw5SU2r3nLDHKohMA+dom+12ehDhWQ+Db5EFADB1BC VmLTAaiZkhIHV9xgmcAoPgvJ2FlIxs5CMnYBI/MqRtHUguSC4qT0ImO94sTc4tK8dL3k/NxN jMBIO/3vWf8OxrsHrA8xJgOtnMgsJZqcD4zUvJJ4Q2MzIwtTE1NjI3NLM9KElcR57z9MChIS SE8sSc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3jSewFllWLpyYcbCxoCUlLzYfT2p z5ab5pQqsRRnJBpqMRcVJwIA43WEaScDAAA= DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Cc: Seung-Woo Kim , "dri-devel@lists.freedesktop.org" X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In this patch, to support exynos for KMS, Exynos KMS driver is newly added. Also, Exynos is added to the list of kmstest supported modules. Signed-off-by: Hyungwon Hwang --- libkms/exynos.c | 207 ++++++++++++++++++++++++++++++++++++++++++++++++++ libkms/internal.h | 2 + libkms/linux.c | 4 + tests/kmstest/main.c | 1 + 4 files changed, 214 insertions(+) create mode 100644 libkms/exynos.c diff --git a/libkms/exynos.c b/libkms/exynos.c new file mode 100644 index 0000000..93e36a1 --- /dev/null +++ b/libkms/exynos.c @@ -0,0 +1,207 @@ +/* exynos.c + * + * Copyright 2009 Samsung Electronics Co., Ltd. + * Authors: + * SooChan Lim + * Sangjin LEE + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + */ + +#define HAVE_STDINT_H +#define _FILE_OFFSET_BITS 64 + +#include +#include +#include +#include +#include "internal.h" + +#include +#include +#include "xf86drm.h" + +#include "exynos_drm.h" + +struct exynos_bo +{ + struct kms_bo base; + unsigned map_count; +}; + +static int +exynos_get_prop(struct kms_driver *kms, unsigned key, unsigned *out) +{ + switch (key) { + case KMS_BO_TYPE: + *out = KMS_BO_TYPE_SCANOUT_X8R8G8B8 | KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8; + break; + default: + return -EINVAL; + } + return 0; +} + +static int +exynos_destroy(struct kms_driver *kms) +{ + free(kms); + return 0; +} + +static int +exynos_bo_create(struct kms_driver *kms, + const unsigned width, const unsigned height, + const enum kms_bo_type type, const unsigned *attr, + struct kms_bo **out) +{ + struct drm_exynos_gem_create arg; + unsigned size, pitch; + struct exynos_bo *bo; + int i, ret; + + for (i = 0; attr[i]; i += 2) { + switch (attr[i]) { + case KMS_WIDTH: + case KMS_HEIGHT: + case KMS_BO_TYPE: + break; + default: + return -EINVAL; + } + } + + bo = calloc(1, sizeof(*bo)); + if (!bo) + return -ENOMEM; + + if (type == KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8) { + pitch = 64 * 4; + size = 64 * 64 * 4; + } else if (type == KMS_BO_TYPE_SCANOUT_X8R8G8B8) { + pitch = width * 4; + pitch = (pitch + 512 - 1) & ~(512 - 1); + size = pitch * ((height + 4 - 1) & ~(4 - 1)); + } else { + return -EINVAL; + } + + memset(&arg, 0, sizeof(arg)); + arg.size = size; + + ret = drmCommandWriteRead(kms->fd, DRM_EXYNOS_GEM_CREATE, &arg, sizeof(arg)); + if (ret) + goto err_free; + + bo->base.kms = kms; + bo->base.handle = arg.handle; + bo->base.size = size; + bo->base.pitch = pitch; + + *out = &bo->base; + + return 0; + +err_free: + free(bo); + return ret; +} + +static int +exynos_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out) +{ + switch (key) { + default: + return -EINVAL; + } +} + +static int +exynos_bo_map(struct kms_bo *_bo, void **out) +{ + struct exynos_bo *bo = (struct exynos_bo *)_bo; + struct drm_exynos_gem_map_off arg; + void *map = NULL; + int ret; + + if (bo->base.ptr) { + bo->map_count++; + *out = bo->base.ptr; + return 0; + } + + memset(&arg, 0, sizeof(arg)); + arg.handle = bo->base.handle; + + ret = drmCommandWriteRead(bo->base.kms->fd, DRM_EXYNOS_GEM_MAP_OFFSET, &arg, sizeof(arg)); + if (ret) + return ret; + + map = mmap(0, bo->base.size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->base.kms->fd, arg.offset); + if (map == MAP_FAILED) + return -errno; + + bo->base.ptr = map; + bo->map_count++; + *out = bo->base.ptr; + + return 0; +} + +static int +exynos_bo_unmap(struct kms_bo *_bo) +{ + struct exynos_bo *bo = (struct exynos_bo *)_bo; + bo->map_count--; + return 0; +} + +static int +exynos_bo_destroy(struct kms_bo *_bo) +{ + struct exynos_bo *bo = (struct exynos_bo *)_bo; + struct drm_gem_close arg; + int ret; + + if (bo->base.ptr) { + /* XXX Sanity check map_count */ + munmap(bo->base.ptr, bo->base.size); + bo->base.ptr = NULL; + } + + memset(&arg, 0, sizeof(arg)); + arg.handle = bo->base.handle; + + ret = drmIoctl(bo->base.kms->fd, DRM_IOCTL_GEM_CLOSE, &arg); + if (ret) + return -errno; + + free(bo); + return 0; +} + +int +exynos_create(int fd, struct kms_driver **out) +{ + struct kms_driver *kms; + + kms = calloc(1, sizeof(*kms)); + if (!kms) + return -ENOMEM; + + kms->fd = fd; + + kms->bo_create = exynos_bo_create; + kms->bo_map = exynos_bo_map; + kms->bo_unmap = exynos_bo_unmap; + kms->bo_get_prop = exynos_bo_get_prop; + kms->bo_destroy = exynos_bo_destroy; + kms->get_prop = exynos_get_prop; + kms->destroy = exynos_destroy; + *out = kms; + + return 0; +} diff --git a/libkms/internal.h b/libkms/internal.h index 5e2501e..f831b57 100644 --- a/libkms/internal.h +++ b/libkms/internal.h @@ -74,4 +74,6 @@ int nouveau_create(int fd, struct kms_driver **out); int radeon_create(int fd, struct kms_driver **out); +int exynos_create(int fd, struct kms_driver **out); + #endif diff --git a/libkms/linux.c b/libkms/linux.c index eec0162..9b4f29e 100644 --- a/libkms/linux.c +++ b/libkms/linux.c @@ -115,6 +115,10 @@ linux_from_sysfs(int fd, struct kms_driver **out) else if (!strcmp(name, "radeon")) ret = radeon_create(fd, out); #endif +#ifdef HAVE_EXYNOS + else if (!strcmp(name, "exynos")) + ret = exynos_create(fd, out); +#endif else ret = -ENOSYS; diff --git a/tests/kmstest/main.c b/tests/kmstest/main.c index 5df0a38..449d75f 100644 --- a/tests/kmstest/main.c +++ b/tests/kmstest/main.c @@ -61,6 +61,7 @@ char *drivers[] = { "radeon", "nouveau", "vmwgfx", + "exynos", NULL };