From patchwork Tue Sep 12 08:08:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 112249 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4862989qgf; Tue, 12 Sep 2017 01:09:29 -0700 (PDT) X-Google-Smtp-Source: ADKCNb5fIWbUsyoIz2B8gYJROur0x6n7oAODwozyr0hladX8btlPhq74CU79A7IUNaOGpvJ46dCM X-Received: by 10.99.65.68 with SMTP id o65mr14060675pga.193.1505203769449; Tue, 12 Sep 2017 01:09:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505203769; cv=none; d=google.com; s=arc-20160816; b=Yyo5esyjt07WFRK12jeYZUjZNbQr+394OIZxZ2vYRzJRv80v2wJGZDpJeuBVBzPDhV qwU7yK39fFwNs2FxMOh174CYhHOuQGAGEZMg6R5d2PLYDhbzZSMz3g6BWlaJQTKboKIC dpcPzvk97me85+e+18W65eQrTGCUGG9h9OiulJ6hueKQUfdmCEN2vCh/KeKMcvDY1GtC sOoMWPIUAxkKfuhOWlv7tilshS37t7riu3V0vPi1ZQHcsnV7kK6aQl5iUge/uf7fZFrT ZWR6ospoWlXm2NRuaMm3A7V77g8HbFrzLXqmRUT6EPP+FSA8YdgpGo5KFErZeCda9DXn ISDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:cc:references:cms-type:in-reply-to:message-id :date:subject:to:from:delivered-to:arc-authentication-results; bh=dFFulEpVNktHoBl+Enoq/40RiDt0HtQBpgUfHqb20O0=; b=ZHccPvSXJ7hno4eNERKhandevHG23Cr4Kx7swRdhk8LYTC2oYG+ws2fSw9d8rufzYs 1fXuKFLjIPWUkGmeuavSiKMYx5k5orDM+ExcMSEy6qjbqj+A8mb72JBmCuIfLH22wFFt 7veEtyfXY/pHV5pIE8jue6P1jedVO20bSLy4t/uW2GH0yipju5aQK8i1j1SvKNDhZplg U4PIQ/g+MWez3qiLc4dhbKKqKqwykzA67qothqKBGcfCpg2rKL4bMiqxjQbNQEOWiSk/ LybfgWKEhcZq41RT/KJH4JROzWgmOnCZcRwG7jiut0QZSDxFCBcmjnC8fRCaQVUK1aJS bbRg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id b28si7595014pfj.204.2017.09.12.01.09.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Sep 2017 01:09:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 83ADD8991A; Tue, 12 Sep 2017 08:09:21 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id AB58789935 for ; Tue, 12 Sep 2017 08:09:16 +0000 (UTC) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20170912080915euoutp02567066df181908325a997814ec893d03~jjtcguRf61646216462euoutp02D; Tue, 12 Sep 2017 08:09:15 +0000 (GMT) Received: from eusmges4.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20170912080914eucas1p21e8f8e680a4ae3e4ae99c3d1fb3074b3~jjtbxSt--1874718747eucas1p2B; Tue, 12 Sep 2017 08:09:14 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges4.samsung.com (EUCPMTA) with SMTP id A1.AE.12944.92697B95; Tue, 12 Sep 2017 09:09:14 +0100 (BST) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170912080913eucas1p19d4abd204d3a7ab7a98848fe9e9df262~jjtbEMgQl1364513645eucas1p1M; Tue, 12 Sep 2017 08:09:13 +0000 (GMT) X-AuditID: cbfec7f4-f79ab6d000003290-6b-59b79629fd0e Received: from eusync4.samsung.com ( [203.254.199.214]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id E8.3D.20118.92697B95; Tue, 12 Sep 2017 09:09:13 +0100 (BST) Received: from AMDC2765.digital.local ([106.116.147.25]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OW500MV7QN2C7A0@eusync4.samsung.com>; Tue, 12 Sep 2017 09:09:13 +0100 (BST) From: Marek Szyprowski To: dri-devel@lists.freedesktop.org, linux-samsung-soc@vger.kernel.org Subject: [PATCH / code example] userspace: Simple tool for testing IPP v2 API Date: Tue, 12 Sep 2017 10:08:59 +0200 Message-id: <1505203739-29747-8-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1505203739-29747-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrLIsWRmVeSWpSXmKPExsWy7djP87pa07ZHGvzZyGRxa905VouNM9az Wlz5+p7NYtL9CSwW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EksIRR4uDB1YwQThOTxJJNG5lAqtgEDCW63naxgdgiAm4S TYdnsoIUMQs8YpLo3X+JBSQhLOArsePyXkYQm0VAVWLj2WNgzbwCHhLbF31ng1gnJ3Hy2GRW EJtTwFOir+chM4gtBFRzaP5ZtgmMvAsYGVYxiqSWFuem5xYb6RUn5haX5qXrJefnbmIEhty2 Yz+37GDsehd8iFGAg1GJh1eje1ukEGtiWXFl7iFGCQ5mJRHeHz3bI4V4UxIrq1KL8uOLSnNS iw8xSnOwKInz9u5ZHSkkkJ5YkpqdmlqQWgSTZeLglGpgFAuKDrqdW3cvbAbrhOmcD6NKagrO W0yM0/H5/IXh0s62A7/fyP28nbapIbp76YcTXq9v+G/5MqfBaYnFkhSDzrXczNel10cZXPxY mzr5d+78xaoOZ1feXpMVlPU1OXiCzanDihNaTj7XPvyIT/LxDVWb75u+2i5S+VB1PifhbXpy nmJvfvDKu0osxRmJhlrMRcWJAF9CeYM1AgAA X-CMS-MailID: 20170912080913eucas1p19d4abd204d3a7ab7a98848fe9e9df262 X-Msg-Generator: CA X-Sender-IP: 182.198.249.180 X-Local-Sender: =?utf-8?q?Marek_Szyprowski=1BSRPOL-Kernel_=28TP=29=1B?= =?utf-8?b?7IK87ISx7KCE7J6QG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Global-Sender: =?utf-8?q?Marek_Szyprowski=1BSRPOL-Kernel_=28TP=29=1BSam?= =?utf-8?q?sung_Electronics=1BSenior_Software_Engineer?= X-Sender-Code: =?utf-8?q?C10=1BEHQ=1BC10CD02CD027392?= CMS-TYPE: 201P X-CMS-RootMailID: 20170912080913eucas1p19d4abd204d3a7ab7a98848fe9e9df262 X-RootMTR: 20170912080913eucas1p19d4abd204d3a7ab7a98848fe9e9df262 References: <1505203739-29747-1-git-send-email-m.szyprowski@samsung.com> Cc: Bartlomiej Zolnierkiewicz , Seung-Woo Kim , Krzysztof Kozlowski , Tobias Jakobi , Sylwester Nawrocki , Marek Szyprowski X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This is simple example how Exynos DRM IPP v2 API can be used from userspace. The code allocates two GEM buffers, fills first with test pattern and then performs 180 degree rotation of the image data. Signed-off-by: Marek Szyprowski --- rotate.c | 235 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 rotate.c diff --git a/rotate.c b/rotate.c new file mode 100644 index 0000000..ab0c5d0 --- /dev/null +++ b/rotate.c @@ -0,0 +1,234 @@ +/* + * Copyright (C) 2017 Samsung Electronics Co.Ltd + * Author: Marek Szyprowski + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + */ + +#define _FILE_OFFSET_BITS 64 + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +struct bo { + void *ptr; + size_t size; + size_t offset; + size_t pitch; + int width; + int height; + unsigned int handle; + unsigned int fourcc; +}; + +struct bo *bo_create(int fd, unsigned int width, unsigned int height, + unsigned int bpp, unsigned int fourcc) +{ + struct drm_exynos_gem_create create_arg = { }; + struct drm_exynos_gem_map map_arg = { }; + struct bo *bo; + int ret; + + bo = calloc(1, sizeof(*bo)); + if (bo == NULL) { + fprintf(stderr, "failed to allocate buffer object\n"); + return NULL; + } + + bo->size = width * height * bpp / 8; + bo->pitch = width * bpp / 8; + bo->width = width; + bo->height = height; + + create_arg.size = bo->size; + create_arg.flags = EXYNOS_BO_NONCONTIG; + + if (drmCommandWriteRead(fd, DRM_EXYNOS_GEM_CREATE, &create_arg, + sizeof(create_arg))) { + fprintf(stderr, "cannot create Exynos GEM object (%d): %m\n", + errno); + return NULL; + } + + bo->handle = create_arg.handle; + bo->fourcc = fourcc; + + map_arg.handle = bo->handle; + + if (drmCommandWriteRead(fd, DRM_EXYNOS_GEM_MAP, &map_arg, + sizeof(map_arg))) { + fprintf(stderr, "cannot map Exynos GEM object (%d): %m\n", + errno); + return NULL; + } + + bo->ptr = mmap(0, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, + map_arg.offset); + if (bo->ptr == MAP_FAILED) + return NULL; + + return bo; +} + +void bo_destroy(int fd, struct bo *bo) +{ + struct drm_gem_close arg = { }; + int ret; + + if (bo->ptr) + munmap(bo->ptr, bo->size); + + arg.handle = bo->handle; + ret = drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, &arg); + if (ret) + fprintf(stderr, "failed to destroy dumb buffer (%d): %m\n", + errno); + + free(bo); +} + +struct bo *bo_create_xrgb(int fd, unsigned int width, unsigned int height) +{ + return bo_create(fd, width, height, 32, DRM_FORMAT_XRGB8888); +} + +struct exynos_drm_ipp_std_task { + struct drm_exynos_ipp_task_buffer buf[2]; + struct drm_exynos_ipp_task_rect rect[2]; + struct drm_exynos_ipp_task_transform transform; +} __packed; + +int process_fb(int fd, struct bo *src_bo, int sx, int sy, int sw, int sh, + struct bo *dst_bo, int dx, int dy, int dw, int dh, int rotation) +{ + struct exynos_drm_ipp_std_task task = { }; + struct drm_exynos_ioctl_ipp_commit arg = { }; + uint32_t id = 0; /* hardcoded first available IPP module */ + + task.buf[0].id = DRM_EXYNOS_IPP_TASK_BUFFER | + DRM_EXYNOS_IPP_TASK_TYPE_SOURCE; + task.buf[0].fourcc = src_bo->fourcc; + task.buf[0].width = src_bo->width; + task.buf[0].height = src_bo->height; + task.buf[0].pitch[0] = src_bo->pitch; + task.buf[0].gem_id[0] = src_bo->handle; + + task.buf[1].id = DRM_EXYNOS_IPP_TASK_BUFFER | + DRM_EXYNOS_IPP_TASK_TYPE_DESTINATION; + task.buf[1].fourcc = dst_bo->fourcc; + task.buf[1].width = dst_bo->width; + task.buf[1].height = dst_bo->height; + task.buf[1].pitch[0] = dst_bo->pitch; + task.buf[1].gem_id[0] = dst_bo->handle; + + task.rect[0].id = DRM_EXYNOS_IPP_TASK_RECTANGLE | + DRM_EXYNOS_IPP_TASK_TYPE_SOURCE; + task.rect[0].x = sx; + task.rect[0].y = sy; + task.rect[0].w = sw; + task.rect[0].h = sh; + + task.rect[1].id = DRM_EXYNOS_IPP_TASK_RECTANGLE | + DRM_EXYNOS_IPP_TASK_TYPE_DESTINATION; + task.rect[1].x = dx; + task.rect[1].y = dy; + task.rect[1].w = dw; + task.rect[1].h = dh; + + task.transform.id = DRM_EXYNOS_IPP_TASK_TRANSFORM; + task.transform.rotation = rotation; + + arg.flags = 0; + arg.ipp_id = id; + arg.params_size = sizeof(task); + arg.params_ptr = (unsigned long)(&task); + arg.user_data = 0; + + if (drmCommandWriteRead(fd, DRM_EXYNOS_IPP_COMMIT, &arg, sizeof(arg))) { + fprintf(stderr, "failed to commit Exynos IPP task (%d): %m\n", + errno); + return errno; + } + + return 0; +} + +int main(int argc, char *argv[]) +{ + struct bo *buf1, *buf2; + int fd; + int err; + int width = 640; + int height = 480; + int val = 1, x, y; + + fd = open("/dev/dri/card0", O_RDWR); + + buf1 = bo_create_xrgb(fd, width, height); + buf2 = bo_create_xrgb(fd, width, height); + + /* draw test pattern to buffer1 */ + for (y = 0; y < height; y++) { + uint32_t *p = buf1->ptr + buf1->pitch * y; + + for (x = 0; x < width; x++) { + if (x > y) + *p++ = (val++ & 0xffffff) + 0xff000000; + } + } + + err = process_fb(fd, buf1, 0, 0, width, height, buf2, 0, 0, width, + height, DRM_MODE_ROTATE_180); + if (!err) { + printf("Buffer processed, checking processed buffer... "); + + for (y = 0; y < height; y++) { + uint32_t *p1 = buf1->ptr + buf1->pitch * y; + uint32_t *p2 = buf2->ptr + buf1->pitch * (height - y - 1); + + for (x = 0; x < width; x++) + if (*(p1 + x) != *(p2 + width - x - 1)) { + printf("failed at (%d,%d) %06x != %06x.\n", + x, y, *(p1 + x), + *(p2 + width - x - 1)); + goto free; + } + } + printf("okay.\n"); + } + +free: + bo_destroy(fd, buf1); + bo_destroy(fd, buf2); + + return 0; +}