From patchwork Fri Feb 16 01:24:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 10223965 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 B60CA60325 for ; Fri, 16 Feb 2018 01:25:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A69D1294A3 for ; Fri, 16 Feb 2018 01:25:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9952329546; Fri, 16 Feb 2018 01:25:02 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0AC50294A3 for ; Fri, 16 Feb 2018 01:25:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3B3D46E58F; Fri, 16 Feb 2018 01:25:00 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-oi0-f67.google.com (mail-oi0-f67.google.com [209.85.218.67]) by gabe.freedesktop.org (Postfix) with ESMTPS id CDBA36E58F for ; Fri, 16 Feb 2018 01:24:59 +0000 (UTC) Received: by mail-oi0-f67.google.com with SMTP id a22so1275694oia.4 for ; Thu, 15 Feb 2018 17:24:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9WBd2SOxUoJp2dDxm1wYqvoPY+JfcP6yVHVMueMVdZk=; b=KezKwivqiHBONeG3qT5BUuzS/DNPi3cjgR0dOio/ksN9fSUMDYMDlJ/vVCfS76SW5J iHgSGCHXs+RuLN4I/xpTs61uSgF/b9eiQyZGzg0Z/FICKDGhLZEZbayRKDRKCisMbTvK 5GZ7ef3FqOOiqAnUQHGqRQ893SAViqzvZ1bmWS4mP5Kpb7nKCgmYbz5bpQLW296eMpZJ g0hk+eke43Q4iqYdUwbYOOdbD0wlzBb7rZnZsbNTfBO4qIOizSA9hAmRBipUStYl5HmC bYgfquYrWaoSzTzaz29w/+Eh6e0NyiZLTDzSOLgA4s5hFKPyLT3vWEQ3h94W9rEOBCQu SN7w== X-Gm-Message-State: APf1xPB/q3G3g2YiNWm92hb76kZhSOe1UxhahJicxA8PYFuNdB9X/X+k avbboIQCpDHYaXi5DcbqxJR3PQ== X-Google-Smtp-Source: AH8x226y8pel4GzJLYQSsTggUKi6cQdTEqRrbkYUKc8np6QDmFYRqLWu1UdCReeH/4upZhNNVtY75Q== X-Received: by 10.202.10.137 with SMTP id k9mr3397305oiy.147.1518744299035; Thu, 15 Feb 2018 17:24:59 -0800 (PST) Received: from labbott-redhat.redhat.com ([2601:602:9802:a8dc::f21a]) by smtp.gmail.com with ESMTPSA id 18sm9156443oty.64.2018.02.15.17.24.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 15 Feb 2018 17:24:57 -0800 (PST) From: Laura Abbott To: Sumit Semwal Subject: [PATCH 2/2] selftests: ion: Add simple test with the vgem driver Date: Thu, 15 Feb 2018 17:24:45 -0800 Message-Id: <20180216012445.17264-3-labbott@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180216012445.17264-1-labbott@redhat.com> References: <20180216012445.17264-1-labbott@redhat.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devel@driverdev.osuosl.org, Todd Kjos , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Liam Mark , linux-kselftest@vger.kernel.org, Shuah Khan MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Ion is designed to be a framework used by other clients who perform operations on the buffer. Use the DRM vgem client as a simple consumer. In conjunction with the dma-buf sync ioctls, this tests the full attach/map path for the system heap. Signed-off-by: Laura Abbott Reviewed-by: Daniel Vetter --- tools/testing/selftests/android/ion/Makefile | 3 +- tools/testing/selftests/android/ion/config | 1 + tools/testing/selftests/android/ion/ionmap_test.c | 136 ++++++++++++++++++++++ 3 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/android/ion/ionmap_test.c diff --git a/tools/testing/selftests/android/ion/Makefile b/tools/testing/selftests/android/ion/Makefile index 96e0c448b39d..d23b6d537d8b 100644 --- a/tools/testing/selftests/android/ion/Makefile +++ b/tools/testing/selftests/android/ion/Makefile @@ -2,7 +2,7 @@ INCLUDEDIR := -I. -I../../../../../drivers/staging/android/uapi/ CFLAGS := $(CFLAGS) $(INCLUDEDIR) -Wall -O2 -g -TEST_GEN_FILES := ionapp_export ionapp_import +TEST_GEN_FILES := ionapp_export ionapp_import ionmap_test all: $(TEST_GEN_FILES) @@ -14,3 +14,4 @@ include ../../lib.mk $(OUTPUT)/ionapp_export: ionapp_export.c ipcsocket.c ionutils.c $(OUTPUT)/ionapp_import: ionapp_import.c ipcsocket.c ionutils.c +$(OUTPUT)/ionmap_test: ionmap_test.c ionutils.c diff --git a/tools/testing/selftests/android/ion/config b/tools/testing/selftests/android/ion/config index 19db6ca9aa2b..b4ad748a9dd9 100644 --- a/tools/testing/selftests/android/ion/config +++ b/tools/testing/selftests/android/ion/config @@ -2,3 +2,4 @@ CONFIG_ANDROID=y CONFIG_STAGING=y CONFIG_ION=y CONFIG_ION_SYSTEM_HEAP=y +CONFIG_DRM_VGEM=y diff --git a/tools/testing/selftests/android/ion/ionmap_test.c b/tools/testing/selftests/android/ion/ionmap_test.c new file mode 100644 index 000000000000..dab36b06b37d --- /dev/null +++ b/tools/testing/selftests/android/ion/ionmap_test.c @@ -0,0 +1,136 @@ +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include + +#include "ion.h" +#include "ionutils.h" + +int check_vgem(int fd) +{ + drm_version_t version = { 0 }; + char name[5]; + int ret; + + version.name_len = 4; + version.name = name; + + ret = ioctl(fd, DRM_IOCTL_VERSION, &version); + if (ret) + return 1; + + return strcmp(name, "vgem"); +} + +int open_vgem(void) +{ + int i, fd; + const char *drmstr = "/dev/dri/card"; + + fd = -1; + for (i = 0; i < 16; i++) { + char name[80]; + + sprintf(name, "%s%u", drmstr, i); + + fd = open(name, O_RDWR); + if (fd < 0) + continue; + + if (check_vgem(fd)) { + close(fd); + continue; + } else { + break; + } + + } + return fd; +} + +int import_vgem_fd(int vgem_fd, int dma_buf_fd, uint32_t *handle) +{ + struct drm_prime_handle import_handle = { 0 }; + int ret; + + import_handle.fd = dma_buf_fd; + import_handle.flags = 0; + import_handle.handle = 0; + + ret = ioctl(vgem_fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &import_handle); + if (ret == 0) + *handle = import_handle.handle; + return ret; +} + +void close_handle(int vgem_fd, uint32_t handle) +{ + struct drm_gem_close close = { 0 }; + + close.handle = handle; + ioctl(vgem_fd, DRM_IOCTL_GEM_CLOSE, &close); +} + +int main() +{ + int ret, vgem_fd; + struct ion_buffer_info info; + uint32_t handle = 0; + struct dma_buf_sync sync = { 0 }; + + info.heap_type = ION_HEAP_TYPE_SYSTEM; + info.heap_size = 4096; + info.flag_type = ION_FLAG_CACHED; + + ret = ion_export_buffer_fd(&info); + if (ret < 0) { + printf("ion buffer alloc failed\n"); + return -1; + } + + vgem_fd = open_vgem(); + if (vgem_fd < 0) { + ret = vgem_fd; + printf("Failed to open vgem\n"); + goto out_ion; + } + + ret = import_vgem_fd(vgem_fd, info.buffd, &handle); + + if (ret < 0) { + printf("Failed to import buffer\n"); + goto out_vgem; + } + + sync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_RW; + ret = ioctl(info.buffd, DMA_BUF_IOCTL_SYNC, &sync); + if (ret) + printf("sync start failed %d\n", errno); + + memset(info.buffer, 0xff, 4096); + + sync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_RW; + ret = ioctl(info.buffd, DMA_BUF_IOCTL_SYNC, &sync); + if (ret) + printf("sync end failed %d\n", errno); + + close_handle(vgem_fd, handle); + ret = 0; + +out_vgem: + close(vgem_fd); +out_ion: + ion_close_buffer_fd(&info); + printf("done.\n"); + return ret; +}