From patchwork Thu Oct 12 22:30:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniele Ceraolo Spurio X-Patchwork-Id: 10003045 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 C9A0C6028A for ; Thu, 12 Oct 2017 22:30:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB71628ED5 for ; Thu, 12 Oct 2017 22:30:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC03E28F18; Thu, 12 Oct 2017 22:30:57 +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 12C5F28F19 for ; Thu, 12 Oct 2017 22:30:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8AC2E6E993; Thu, 12 Oct 2017 22:30:56 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id 73A276E993 for ; Thu, 12 Oct 2017 22:30:55 +0000 (UTC) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Oct 2017 15:30:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,368,1503385200"; d="scan'208";a="137946031" Received: from relo-linux-1.fm.intel.com ([10.1.27.112]) by orsmga004.jf.intel.com with ESMTP; 12 Oct 2017 15:30:55 -0700 From: Daniele Ceraolo Spurio To: intel-gfx@lists.freedesktop.org Date: Thu, 12 Oct 2017 15:30:41 -0700 Message-Id: <1507847444-3593-2-git-send-email-daniele.ceraolospurio@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1507847444-3593-1-git-send-email-daniele.ceraolospurio@intel.com> References: <1507847444-3593-1-git-send-email-daniele.ceraolospurio@intel.com> Subject: [Intel-gfx] [PATCH i-g-t 1/4] lib/igt_vgem: extract vgem_create_and_import X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP The same code to create and import a vgem object is used in a couple of places and a couple more are coming up in the next patches so extract the code into a common function Signed-off-by: Daniele Ceraolo Spurio --- lib/igt_dummyload.c | 10 ++-------- lib/igt_vgem.c | 35 +++++++++++++++++++++++++++++++++ lib/igt_vgem.h | 2 ++ tests/prime_vgem.c | 56 +++++++++++++---------------------------------------- 4 files changed, 52 insertions(+), 51 deletions(-) diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c index 913cc93..03541f7 100644 --- a/lib/igt_dummyload.c +++ b/lib/igt_dummyload.c @@ -317,23 +317,17 @@ igt_cork_t *igt_cork_new(int fd) { igt_cork_t *cork; struct vgem_bo bo; - int dmabuf; cork = calloc(1, sizeof(igt_cork_t)); igt_assert(cork); cork->device = drm_open_driver(DRIVER_VGEM); - igt_require(vgem_has_fences(cork->device)); - bo.width = bo.height = 1; bo.bpp = 4; - vgem_create(cork->device, &bo); - cork->fence = vgem_fence_attach(cork->device, &bo, VGEM_FENCE_WRITE); - dmabuf = prime_handle_to_fd(cork->device, bo.handle); - cork->handle = prime_fd_to_handle(fd, dmabuf); - close(dmabuf); + cork->handle = vgem_create_and_import(cork->device, &bo, fd, + &cork->fence); return cork; } diff --git a/lib/igt_vgem.c b/lib/igt_vgem.c index 7f933b2..7fc62f2 100644 --- a/lib/igt_vgem.c +++ b/lib/igt_vgem.c @@ -66,6 +66,41 @@ void vgem_create(int fd, struct vgem_bo *bo) igt_assert_eq(__vgem_create(fd, bo), 0); } +/** + * vgem_create_and_import: + * @vgem_fd: open vgem file descriptor + * @bo: vgem_bo struct containing width, height and bpp of the object to open + * @import_fd: open drm file descriptor to be used to import the vgem bo + * @fence: optional return variable to store a fence attached to the vgem bo + * + * This function creates a vgem bo and imports it to the provided device. If + * the fence parameter if provided a fence is attached to the bo and returned. + * The provided vgem_bo struct is updated as in vgem_create. + * + * Returns: + * Handle of the imported bo. + */ +uint32_t vgem_create_and_import(int vgem_fd, struct vgem_bo *bo, int import_fd, + uint32_t *fence) +{ + int dmabuf; + uint32_t handle; + + vgem_create(vgem_fd, bo); + + if (fence) { + igt_require(vgem_has_fences(vgem_fd)); + *fence = vgem_fence_attach(vgem_fd, bo, VGEM_FENCE_WRITE); + } + + dmabuf = prime_handle_to_fd(vgem_fd, bo->handle); + handle = prime_fd_to_handle(import_fd, dmabuf); + igt_assert(handle); + close(dmabuf); + + return handle; +} + void *__vgem_mmap(int fd, struct vgem_bo *bo, unsigned prot) { struct drm_mode_map_dumb arg; diff --git a/lib/igt_vgem.h b/lib/igt_vgem.h index 92045f0..94b1186 100644 --- a/lib/igt_vgem.h +++ b/lib/igt_vgem.h @@ -36,6 +36,8 @@ struct vgem_bo { int __vgem_create(int fd, struct vgem_bo *bo); void vgem_create(int fd, struct vgem_bo *bo); +uint32_t vgem_create_and_import(int vgem_fd, struct vgem_bo *bo, int import_fd, + uint32_t *fence); void *__vgem_mmap(int fd, struct vgem_bo *bo, unsigned prot); void *vgem_mmap(int fd, struct vgem_bo *bo, unsigned prot); diff --git a/tests/prime_vgem.c b/tests/prime_vgem.c index 0ffaee9..489e9b6 100644 --- a/tests/prime_vgem.c +++ b/tests/prime_vgem.c @@ -35,16 +35,12 @@ static void test_read(int vgem, int i915) struct vgem_bo scratch; uint32_t handle; uint32_t *ptr; - int dmabuf, i; + int i; scratch.width = 1024; scratch.height = 1024; scratch.bpp = 32; - vgem_create(vgem, &scratch); - - dmabuf = prime_handle_to_fd(vgem, scratch.handle); - handle = prime_fd_to_handle(i915, dmabuf); - close(dmabuf); + handle = vgem_create_and_import(vgem, &scratch, i915, NULL); ptr = vgem_mmap(vgem, &scratch, PROT_WRITE); for (i = 0; i < 1024; i++) @@ -66,7 +62,7 @@ static void test_fence_read(int i915, int vgem) uint32_t handle; uint32_t *ptr; uint32_t fence; - int dmabuf, i; + int i; int master[2], slave[2]; igt_assert(pipe(master) == 0); @@ -75,11 +71,7 @@ static void test_fence_read(int i915, int vgem) scratch.width = 1024; scratch.height = 1024; scratch.bpp = 32; - vgem_create(vgem, &scratch); - - dmabuf = prime_handle_to_fd(vgem, scratch.handle); - handle = prime_fd_to_handle(i915, dmabuf); - close(dmabuf); + handle = vgem_create_and_import(vgem, &scratch, i915, NULL); igt_fork(child, 1) { for (i = 0; i < 1024; i++) { @@ -121,7 +113,7 @@ static void test_fence_mmap(int i915, int vgem) uint32_t handle; uint32_t *ptr; uint32_t fence; - int dmabuf, i; + int i; int master[2], slave[2]; igt_assert(pipe(master) == 0); @@ -130,11 +122,7 @@ static void test_fence_mmap(int i915, int vgem) scratch.width = 1024; scratch.height = 1024; scratch.bpp = 32; - vgem_create(vgem, &scratch); - - dmabuf = prime_handle_to_fd(vgem, scratch.handle); - handle = prime_fd_to_handle(i915, dmabuf); - close(dmabuf); + handle = vgem_create_and_import(vgem, &scratch, i915, NULL); igt_fork(child, 1) { ptr = gem_mmap__gtt(i915, handle, 4096*1024, PROT_READ); @@ -176,16 +164,12 @@ static void test_write(int vgem, int i915) struct vgem_bo scratch; uint32_t handle; uint32_t *ptr; - int dmabuf, i; + int i; scratch.width = 1024; scratch.height = 1024; scratch.bpp = 32; - vgem_create(vgem, &scratch); - - dmabuf = prime_handle_to_fd(vgem, scratch.handle); - handle = prime_fd_to_handle(i915, dmabuf); - close(dmabuf); + handle = vgem_create_and_import(vgem, &scratch, i915, NULL); ptr = vgem_mmap(vgem, &scratch, PROT_READ); gem_close(vgem, scratch.handle); @@ -204,16 +188,12 @@ static void test_gtt(int vgem, int i915) struct vgem_bo scratch; uint32_t handle; uint32_t *ptr; - int dmabuf, i; + int i; scratch.width = 1024; scratch.height = 1024; scratch.bpp = 32; - vgem_create(vgem, &scratch); - - dmabuf = prime_handle_to_fd(vgem, scratch.handle); - handle = prime_fd_to_handle(i915, dmabuf); - close(dmabuf); + handle = vgem_create_and_import(vgem, &scratch, i915, NULL); ptr = gem_mmap__gtt(i915, handle, scratch.size, PROT_WRITE); for (i = 0; i < 1024; i++) @@ -241,16 +221,12 @@ static void test_gtt_interleaved(int vgem, int i915) struct vgem_bo scratch; uint32_t handle; uint32_t *ptr, *gtt; - int dmabuf, i; + int i; scratch.width = 1024; scratch.height = 1024; scratch.bpp = 32; - vgem_create(vgem, &scratch); - - dmabuf = prime_handle_to_fd(vgem, scratch.handle); - handle = prime_fd_to_handle(i915, dmabuf); - close(dmabuf); + handle = vgem_create_and_import(vgem, &scratch, i915, NULL); /* This assumes that GTT is perfectedly coherent. On certain machines, * it is possible for a direct acces to bypass the GTT indirection. @@ -709,17 +685,11 @@ static void test_flip(int i915, int vgem, unsigned hang) signal(SIGHUP, sighandler); for (int i = 0; i < 2; i++) { - int fd; - bo[i].width = 1024; bo[i].height = 768; bo[i].bpp = 32; - vgem_create(vgem, &bo[i]); - fd = prime_handle_to_fd(vgem, bo[i].handle); - handle[i] = prime_fd_to_handle(i915, fd); - igt_assert(handle[i]); - close(fd); + handle[i] = vgem_create_and_import(vgem, &bo[i], i915, NULL); do_or_die(__kms_addfb(i915, handle[i], bo[i].width, bo[i].height, bo[i].pitch,