From patchwork Wed Nov 14 22:28:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Anholt X-Patchwork-Id: 10683209 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 874C617F3 for ; Wed, 14 Nov 2018 22:28:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7919829D13 for ; Wed, 14 Nov 2018 22:28:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D7E129D2A; Wed, 14 Nov 2018 22:28:49 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 CCA7D29D15 for ; Wed, 14 Nov 2018 22:28:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2405A6E585; Wed, 14 Nov 2018 22:28:48 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from anholt.net (anholt.net [50.246.234.109]) by gabe.freedesktop.org (Postfix) with ESMTP id D05B26E585 for ; Wed, 14 Nov 2018 22:28:46 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by anholt.net (Postfix) with ESMTP id 8ABB510A1311; Wed, 14 Nov 2018 14:28:46 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at anholt.net Received: from anholt.net ([127.0.0.1]) by localhost (kingsolver.anholt.net [127.0.0.1]) (amavisd-new, port 10024) with LMTP id GLTH3s9K9u_E; Wed, 14 Nov 2018 14:28:43 -0800 (PST) Received: from eliezer.anholt.net (localhost [127.0.0.1]) by anholt.net (Postfix) with ESMTP id 2ECED10A1363; Wed, 14 Nov 2018 14:28:34 -0800 (PST) Received: by eliezer.anholt.net (Postfix, from userid 1000) id C01D62FE3704; Wed, 14 Nov 2018 14:28:32 -0800 (PST) From: Eric Anholt To: intel-gfx@lists.freedesktop.org Date: Wed, 14 Nov 2018 14:28:31 -0800 Message-Id: <20181114222832.22839-3-eric@anholt.net> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181114222832.22839-1-eric@anholt.net> References: <20181114222832.22839-1-eric@anholt.net> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t 3/4] Add v3d helper library X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Just a few little ioctl wrappers that v3d tests will use. Signed-off-by: Eric Anholt Acked-by: Petri Latvala --- lib/Makefile.sources | 2 + lib/drmtest.c | 3 + lib/drmtest.h | 1 + lib/igt_v3d.c | 130 +++++++++++++++++++++++++++++++++++++++++++ lib/igt_v3d.h | 46 +++++++++++++++ lib/meson.build | 1 + 6 files changed, 183 insertions(+) create mode 100644 lib/igt_v3d.c create mode 100644 lib/igt_v3d.h diff --git a/lib/Makefile.sources b/lib/Makefile.sources index e98989ff8ed9..808b9617eca2 100644 --- a/lib/Makefile.sources +++ b/lib/Makefile.sources @@ -107,6 +107,8 @@ lib_source_list = \ igt_syncobj.h \ igt_psr.c \ igt_psr.h \ + igt_v3d.c \ + igt_v3d.h \ $(NULL) .PHONY: version.h.tmp diff --git a/lib/drmtest.c b/lib/drmtest.c index fee9d33ad2a5..d2aa1c19154f 100644 --- a/lib/drmtest.c +++ b/lib/drmtest.c @@ -202,6 +202,7 @@ static const struct module { } modules[] = { { DRIVER_AMDGPU, "amdgpu" }, { DRIVER_INTEL, "i915", modprobe_i915 }, + { DRIVER_V3D, "v3d" }, { DRIVER_VC4, "vc4" }, { DRIVER_VGEM, "vgem" }, { DRIVER_VIRTIO, "virtio-gpu" }, @@ -340,6 +341,8 @@ static const char *chipset_to_str(int chipset) switch (chipset) { case DRIVER_INTEL: return "intel"; + case DRIVER_V3D: + return "v3d"; case DRIVER_VC4: return "vc4"; case DRIVER_VGEM: diff --git a/lib/drmtest.h b/lib/drmtest.h index 949865ee54dd..96ee517e2ec1 100644 --- a/lib/drmtest.h +++ b/lib/drmtest.h @@ -43,6 +43,7 @@ #define DRIVER_VGEM (1 << 2) #define DRIVER_VIRTIO (1 << 3) #define DRIVER_AMDGPU (1 << 4) +#define DRIVER_V3D (1 << 5) /* * Exclude DRVER_VGEM from DRIVER_ANY since if you run on a system * with vgem as well as a supported driver, you can end up with a diff --git a/lib/igt_v3d.c b/lib/igt_v3d.c new file mode 100644 index 000000000000..1a5ede1bd5fc --- /dev/null +++ b/lib/igt_v3d.c @@ -0,0 +1,130 @@ +/* + * Copyright © 2016 Broadcom + * + * 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 (including the next + * paragraph) 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "drmtest.h" +#include "igt_aux.h" +#include "igt_core.h" +#include "igt_v3d.h" +#include "ioctl_wrappers.h" +#include "intel_reg.h" +#include "intel_chipset.h" +#include "v3d_drm.h" + +#if NEW_CONTEXT_PARAM_NO_ERROR_CAPTURE_API +#define LOCAL_CONTEXT_PARAM_NO_ERROR_CAPTURE 0x4 +#endif + +/** + * SECTION:igt_v3d + * @short_description: V3D support library + * @title: V3D + * @include: igt.h + * + * This library provides various auxiliary helper functions for writing V3D + * tests. + */ + +struct v3d_bo * +igt_v3d_create_bo(int fd, size_t size) +{ + struct v3d_bo *bo = calloc(1, sizeof(*bo)); + + struct drm_v3d_create_bo create = { + .size = size, + }; + + do_ioctl(fd, DRM_IOCTL_V3D_CREATE_BO, &create); + + bo->handle = create.handle; + bo->offset = create.offset; + bo->size = size; + + return bo; +} + +void +igt_v3d_free_bo(int fd, struct v3d_bo *bo) +{ + if (bo->map) + munmap(bo->map, bo->size); + gem_close(fd, bo->handle); + free(bo); +} + +uint32_t +igt_v3d_get_bo_offset(int fd, uint32_t handle) +{ + struct drm_v3d_get_bo_offset get = { + .handle = handle, + }; + + do_ioctl(fd, DRM_IOCTL_V3D_GET_BO_OFFSET, &get); + + return get.offset; +} + +uint32_t +igt_v3d_get_param(int fd, enum drm_v3d_param param) +{ + struct drm_v3d_get_param get = { + .param = param, + }; + + do_ioctl(fd, DRM_IOCTL_V3D_GET_PARAM, &get); + + return get.value; +} + +void * +igt_v3d_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned prot) +{ + struct drm_v3d_mmap_bo mmap_bo = { + .handle = handle, + }; + void *ptr; + + do_ioctl(fd, DRM_IOCTL_V3D_MMAP_BO, &mmap_bo); + + ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_bo.offset); + if (ptr == MAP_FAILED) + return NULL; + else + return ptr; +} + +void igt_v3d_bo_mmap(int fd, struct v3d_bo *bo) +{ + bo->map = igt_v3d_mmap_bo(fd, bo->handle, bo->size, + PROT_READ | PROT_WRITE); + igt_assert(bo->map); +} diff --git a/lib/igt_v3d.h b/lib/igt_v3d.h new file mode 100644 index 000000000000..bdbcb2dbc5cc --- /dev/null +++ b/lib/igt_v3d.h @@ -0,0 +1,46 @@ +/* + * Copyright © 2016 Broadcom + * + * 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 (including the next + * paragraph) 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. + */ + +#ifndef IGT_V3D_H +#define IGT_V3D_H + +#include "v3d_drm.h" + +struct v3d_bo *igt_v3d_create_bo(int fd, size_t size); +void igt_v3d_free_bo(int fd, struct v3d_bo *bo); + +/* IOCTL wrappers */ +uint32_t igt_v3d_get_bo_offset(int fd, uint32_t handle); +uint32_t igt_v3d_get_param(int fd, enum drm_v3d_param param); +void *igt_v3d_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned prot); + +void igt_v3d_bo_mmap(int fd, struct v3d_bo *bo); + +struct v3d_bo { + int handle; + uint32_t offset; + uint32_t size; + void *map; +}; + +#endif /* IGT_V3D_H */ diff --git a/lib/meson.build b/lib/meson.build index 8961ca494af8..19f5d51ceead 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -48,6 +48,7 @@ lib_sources = [ 'igt_dummyload.c', 'uwildmat/uwildmat.c', 'igt_kmod.c', + 'igt_v3d.c', 'igt_vc4.c', 'igt_psr.c', ]