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: 9948571 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 31B366038F for ; Tue, 12 Sep 2017 08:09:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FDB628EA1 for ; Tue, 12 Sep 2017 08:09:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1471F28EB2; Tue, 12 Sep 2017 08:09:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 309D028EA1 for ; Tue, 12 Sep 2017 08:09:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751089AbdILIJa (ORCPT ); Tue, 12 Sep 2017 04:09:30 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:35273 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751365AbdILIJQ (ORCPT ); Tue, 12 Sep 2017 04:09:16 -0400 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 Cc: Marek Szyprowski , Inki Dae , Seung-Woo Kim , Andrzej Hajda , Bartlomiej Zolnierkiewicz , Tobias Jakobi , Krzysztof Kozlowski , Sylwester Nawrocki 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+p7NYtL9CSwW589vYLeYcX4fk8XaI3fZLQ6/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AqtgEDCW63naxgdgiAm4S 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?B?TWFyZWsgU3p5cHJvd3NraRtTUlBPTC1LZXJuZWwgKFRQKRs=?= =?UTF-8?B?7IK87ISx7KCE7J6QG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Global-Sender: =?UTF-8?B?TWFyZWsgU3p5cHJvd3NraRtTUlBPTC1LZXJuZWwgKFRQKRtT?= =?UTF-8?B?YW1zdW5nIEVsZWN0cm9uaWNzG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjczOTI=?= CMS-TYPE: 201P X-CMS-RootMailID: 20170912080913eucas1p19d4abd204d3a7ab7a98848fe9e9df262 X-RootMTR: 20170912080913eucas1p19d4abd204d3a7ab7a98848fe9e9df262 References: <1505203739-29747-1-git-send-email-m.szyprowski@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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; +}