From patchwork Thu May 28 13:38:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rohan Garg X-Patchwork-Id: 11575853 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D517F1391 for ; Thu, 28 May 2020 13:38:50 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BD697206F1 for ; Thu, 28 May 2020 13:38:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BD697206F1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1985C89E0C; Thu, 28 May 2020 13:38:48 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2C68289E0C; Thu, 28 May 2020 13:38:47 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: shadeslayer) with ESMTPSA id 3215A2A3EB9 From: Rohan Garg To: igt-dev@lists.freedesktop.org Subject: [PATCH i-g-t] panfrost: Test labeling functionality Date: Thu, 28 May 2020 15:38:35 +0200 Message-Id: <20200528133835.5087-1-rohan.garg@collabora.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: emil.l.velikov@gmail.com, alyssa.rosenzweig@collabora.com, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Introduce tests to cover the new generic labeling ioctl's being reviewed here [1]. Signed-off-by: Rohan Garg [1] https://patchwork.freedesktop.org/series/77267/ Signed-off-by: Rohan Garg --- include/drm-uapi/drm.h | 23 ++++++- tests/meson.build | 1 + tests/panfrost_bo_label.c | 129 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 tests/panfrost_bo_label.c diff --git a/include/drm-uapi/drm.h b/include/drm-uapi/drm.h index c7fd2a35..87124882 100644 --- a/include/drm-uapi/drm.h +++ b/include/drm-uapi/drm.h @@ -620,6 +620,25 @@ struct drm_gem_open { __u64 size; }; +/** struct drm_handle_label - ioctl argument for labelling BOs. + * + * This label's a BO with a userspace label + * + */ +struct drm_handle_label { + /** Handle for the object being labelled. */ + __u32 handle; + + /** Label and label length (len includes the trailing NULL). + * Label lenght *MUST* be smaller than PAGE_SIZE. + */ + __u32 len; + __u64 label; + + /** Flags .. Currently no flags are defined */ + __u32 flags; +}; + #define DRM_CAP_DUMB_BUFFER 0x1 #define DRM_CAP_VBLANK_HIGH_CRTC 0x2 #define DRM_CAP_DUMB_PREFERRED_DEPTH 0x3 @@ -941,8 +960,10 @@ extern "C" { #define DRM_IOCTL_SYNCOBJ_QUERY DRM_IOWR(0xCB, struct drm_syncobj_timeline_array) #define DRM_IOCTL_SYNCOBJ_TRANSFER DRM_IOWR(0xCC, struct drm_syncobj_transfer) #define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL DRM_IOWR(0xCD, struct drm_syncobj_timeline_array) - #define DRM_IOCTL_MODE_GETFB2 DRM_IOWR(0xCE, struct drm_mode_fb_cmd2) +#define DRM_IOCTL_HANDLE_SET_LABEL DRM_IOWR(0xCF, struct drm_handle_label) +#define DRM_IOCTL_HANDLE_GET_LABEL DRM_IOWR(0xD0, struct drm_handle_label) + /** * Device specific ioctls should only be in their respective headers diff --git a/tests/meson.build b/tests/meson.build index e69bdb7d..ee91bf48 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -72,6 +72,7 @@ test_progs = [ 'kms_vblank', 'kms_vrr', 'meta_test', + 'panfrost_bo_label', 'panfrost_get_param', 'panfrost_gem_new', 'panfrost_prime', diff --git a/tests/panfrost_bo_label.c b/tests/panfrost_bo_label.c new file mode 100644 index 00000000..d3179458 --- /dev/null +++ b/tests/panfrost_bo_label.c @@ -0,0 +1,129 @@ +/* + * Copyright © 2020 Collabora Ltd. + * Author: Rohan Garg + * + * 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 "igt.h" +#include "igt_panfrost.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "vc4_drm.h" + +static int +set_label(int fd, int handle, const char *label) +{ + struct drm_handle_label args = { 0 }; + if (label) { + args.handle = handle; + args.len = strlen(label) + 1; + args.label= (uintptr_t)label; + } + + return drmIoctl(fd, DRM_IOCTL_HANDLE_SET_LABEL, &args); +} + +static const char* +get_label(int fd, int handle) +{ + struct drm_handle_label args = { + .handle = handle, + .len = 10, + .label = (uintptr_t) malloc(sizeof(char*) * 10) + }; + + drmIoctl(fd, DRM_IOCTL_HANDLE_GET_LABEL, &args); + + if (!args.label) + return NULL; + + igt_assert(args.label); + + args.label = (uintptr_t) realloc(args.label, args.len); + + drmIoctl(fd, DRM_IOCTL_HANDLE_GET_LABEL, &args); + + return args.label; +} + + +igt_main +{ + int fd; + + igt_fixture + fd = drm_open_driver(DRIVER_ANY); + + igt_subtest("set-label") { + struct panfrost_bo *bo = igt_panfrost_gem_new(fd, 4096); + int ret; + ret = set_label(fd, bo->handle, "a test label"); + igt_assert(ret == 0); + + ret = set_label(fd, bo->handle, "a new test label"); + igt_assert(ret == 0); + + igt_panfrost_free_bo(fd, bo); + } + + igt_subtest("get-label") { + struct panfrost_bo *bo = igt_panfrost_gem_new(fd, 4096); + set_label(fd, bo->handle, "a test label"); + const char* label = get_label(fd, bo->handle); + igt_assert(strcmp(label, "a test label") == 0); + free(label); + igt_panfrost_free_bo(fd, bo); + } + + igt_subtest("clear-label") { + struct panfrost_bo *bo = igt_panfrost_gem_new(fd, 4096); + set_label(fd, bo->handle, NULL); + igt_assert_eq(NULL, get_label(fd, bo->handle)); + igt_panfrost_free_bo(fd, bo); + } + + igt_subtest("label-too-long") { + char label[4096] = {[0 ... 4095] = 'a'}; + int ret; + struct panfrost_bo *bo = igt_panfrost_gem_new(fd, 4096); + ret = set_label(fd, bo->handle, label); + igt_assert_eq(-1, ret); + igt_assert_eq(EINVAL, errno); + igt_panfrost_free_bo(fd, bo); + } + + igt_subtest("set-bad-handle") { + int ret = set_label(fd, 0xd0d0d0d0, "bad handle"); + igt_assert_eq(-1, ret); + igt_assert_eq(ENOENT, errno); + } + + igt_fixture + close(fd); +}