From patchwork Mon Aug 30 16:22:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 12465525 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBB9FC432BE for ; Mon, 30 Aug 2021 16:18:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A31E660F56 for ; Mon, 30 Aug 2021 16:18:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237741AbhH3QTD (ORCPT ); Mon, 30 Aug 2021 12:19:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231181AbhH3QTD (ORCPT ); Mon, 30 Aug 2021 12:19:03 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 664BDC061575 for ; Mon, 30 Aug 2021 09:18:09 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id g13-20020a17090a3c8d00b00196286963b9so7250413pjc.3 for ; Mon, 30 Aug 2021 09:18:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IzUUD53TRCina4FvQp5wgcW+VoUOyAwWBEy3HV4by8c=; b=MTpoUR2UzOgE1ufJQlJin/dJTVj/Mh5JuHlYs6fY85kV9qpTnCxrGLjI3Big/N6k79 VjN3CR6HychhR+Pkc7NKMY/O1hoL2jJe6x9PeKzZqIdN/jcr9mDyGY+VR4gB7sTrdGBW nyZD3Xo63c0FAODS38BRvv5koF7ZOiQ9pe4ZFr97I0LFDR/SEIgaZL8pH5X4H380J6mN CGZYdD4JBmcBAIGNUE5SUK/64RTLwMLZXbExvU1L3P9KbMxYhWj+65vZ3ytAClYxyp3u ks+SdNpv0tEzZlXKjsTBa7v/AqtfDcRelAhEYJ8/6at0/vQ4WMo9O87oc74YntNgZo1p XE7w== 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:mime-version:content-transfer-encoding; bh=IzUUD53TRCina4FvQp5wgcW+VoUOyAwWBEy3HV4by8c=; b=NhFEaXovFzKwZICQdnkU/3ctJoKvIYQuYzTpShc7TA4GQIvVq+AoczkMnpapw5UWfQ atlOT1NQwf7iUa8QPqtsOu5RhFnTN4X+70N7oSCt/P44Yipc0UX5Wyn4AwjShbAiIftz +LNYnhcHAk4gOAvCdfqExaA6AQebNK7R6U5Xo96SiodQ9lRNSDmj7qmxPKl32/7o+L/6 cv2VndApgb4yQjUGQ4ZLT5ckp1LIa2U5+NypDSV7fn+hXWasgRuHk5/gPtKWA0H5N//G K9vWgLgkyl3IcrS4pHl1+y0nW1DhVpEB0oH3oFPcHCNr/oH/jCsA9l3XnSOG/J4BSawn AHGQ== X-Gm-Message-State: AOAM5328O9j2yXlfEE6y0VxiCdcaQ8/2UhmrnC6A2WH7YyDFzF0DhSPc bq+aqOmg/L9CfV2ftNCvKoDMTff/QOY= X-Google-Smtp-Source: ABdhPJzN0V8nsuGnodaxmxJDjnSXCAsi7TAHI6LzeETI3H4E/lZ/Ovp6hI0Talsa/XJlAQstxF++Pg== X-Received: by 2002:a17:90a:64c1:: with SMTP id i1mr39754377pjm.111.1630340288903; Mon, 30 Aug 2021 09:18:08 -0700 (PDT) Received: from localhost (c-73-25-156-94.hsd1.or.comcast.net. [73.25.156.94]) by smtp.gmail.com with ESMTPSA id y67sm15251565pfg.218.2021.08.30.09.18.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Aug 2021 09:18:08 -0700 (PDT) From: Rob Clark To: igt-dev@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Jordan Crouse , Akhil P Oommen , Petri Latvala , Rob Clark Subject: [PATCH igt v3 1/3] drmtest: Add DRIVER_MSM support Date: Mon, 30 Aug 2021 09:22:30 -0700 Message-Id: <20210830162232.1328594-2-robdclark@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210830162232.1328594-1-robdclark@gmail.com> References: <20210830162232.1328594-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Rob Clark Signed-off-by: Rob Clark Reviewed-by: Petri Latvala --- lib/drmtest.c | 3 +++ lib/drmtest.h | 1 + 2 files changed, 4 insertions(+) diff --git a/lib/drmtest.c b/lib/drmtest.c index e1f9b115..29cb3f4c 100644 --- a/lib/drmtest.c +++ b/lib/drmtest.c @@ -179,6 +179,7 @@ static const struct module { } modules[] = { { DRIVER_AMDGPU, "amdgpu" }, { DRIVER_INTEL, "i915", modprobe_i915 }, + { DRIVER_MSM, "msm" }, { DRIVER_PANFROST, "panfrost" }, { DRIVER_V3D, "v3d" }, { DRIVER_VC4, "vc4" }, @@ -539,6 +540,8 @@ static const char *chipset_to_str(int chipset) return "amdgpu"; case DRIVER_PANFROST: return "panfrost"; + case DRIVER_MSM: + return "msm"; case DRIVER_ANY: return "any"; default: diff --git a/lib/drmtest.h b/lib/drmtest.h index 7d17a0f9..a6eb60c3 100644 --- a/lib/drmtest.h +++ b/lib/drmtest.h @@ -50,6 +50,7 @@ #define DRIVER_AMDGPU (1 << 3) #define DRIVER_V3D (1 << 4) #define DRIVER_PANFROST (1 << 5) +#define DRIVER_MSM (1 << 6) /* * Exclude DRVER_VGEM from DRIVER_ANY since if you run on a system From patchwork Mon Aug 30 16:22:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 12465527 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D18BBC432BE for ; Mon, 30 Aug 2021 16:18:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B717160F56 for ; Mon, 30 Aug 2021 16:18:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231181AbhH3QTF (ORCPT ); Mon, 30 Aug 2021 12:19:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237767AbhH3QTE (ORCPT ); Mon, 30 Aug 2021 12:19:04 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2918CC061575 for ; Mon, 30 Aug 2021 09:18:11 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id mw10-20020a17090b4d0a00b0017b59213831so14259684pjb.0 for ; Mon, 30 Aug 2021 09:18:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ta+t34lKnUrLQOsPGUBd9N3dkbds9Rs6YT2aBHaNSNY=; b=EzknnOj7tDEbruT3ZIdIgAGo9YsaE+f6liTiFB+eGgUEJ2K9s+MBqvorM69Aw6K7Oa YG71uGdRunoh4MALrrLUq1odBP9XP85RzpzbWm6R3LiS7YF7E27mnakwR9Q7/X1r65XE xFPbUN9G+cwDeDmr6yhgbWY/DA1iK+8Z0b8VU2TauW718ct3qhFGlROIDLdM2sVT1d4z g4gWgK19GT+5K1fjM3vOokjKDWmb78Yhkm3IkssERt5B+4YXzESb9Qa0Rv6tyghhN0uo sP3Fq0hj/rnAnP1oS+t+dEUZONVFovZ97rp75LCWv8W2m6gkKF+zZJX7bAFGU5zXLpD+ ocGw== 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:mime-version:content-transfer-encoding; bh=ta+t34lKnUrLQOsPGUBd9N3dkbds9Rs6YT2aBHaNSNY=; b=uLIvH97rohPBXU8XUe3qbJA4FBevZMh4Dq0jT1vCa18FKB+fApf9ANWeK249X+b3S9 qZRWk2iXZGdEzA3mDIJpZ7eKbH9Bcd3wGwlVeAi2uvRc6yr419RRxRbKpQEXOG8TF3By Sda5pQTVMhCQcnOF8Odfl/S3EOWy2ArFmOjVdRCADxge6Eygbeh9jBdMtTPf+dGSf5RT PmVbWQh37c5/1I/KWulK7WddlOGk03L0i+StNCRXtHKHa96th8Rcuas/uV3Us0B/SDWc 70wZ8hkJnQ8XqOTHglymXs7T6l/3CW7pWpxb6ArNR/jqbZnFc/2kC+1+rItalxF+cAmI coKQ== X-Gm-Message-State: AOAM533GlRfGIG2T8auzHS2hYGwm52GStQ7kmBqetXt/clmhZu/oa2SX PlNKP4OJ/QX/xwxvqDgku4Q= X-Google-Smtp-Source: ABdhPJx2wRX3Ew7evQZz6N9CfV4VCZTYHJe684ttMwqQ6E8AN5JT1bmE1orZoxXVQyJiBK3xhuW4VA== X-Received: by 2002:a17:902:a407:b0:138:849b:56f6 with SMTP id p7-20020a170902a40700b00138849b56f6mr433788plq.0.1630340290569; Mon, 30 Aug 2021 09:18:10 -0700 (PDT) Received: from localhost (c-73-25-156-94.hsd1.or.comcast.net. [73.25.156.94]) by smtp.gmail.com with ESMTPSA id r13sm18639395pgl.90.2021.08.30.09.18.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Aug 2021 09:18:09 -0700 (PDT) From: Rob Clark To: igt-dev@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Jordan Crouse , Akhil P Oommen , Petri Latvala , Rob Clark Subject: [PATCH igt v3 2/3] msm: Add helper library Date: Mon, 30 Aug 2021 09:22:31 -0700 Message-Id: <20210830162232.1328594-3-robdclark@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210830162232.1328594-1-robdclark@gmail.com> References: <20210830162232.1328594-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Rob Clark Handle some of the boilerplate for tests. v2: fix comment, drop unnecessary drm_open_driver_render() error handling, docs fixes, drop igt_msm_pipe_get_param() (for now), handle NULL in destructors Signed-off-by: Rob Clark Reviewed-by: Petri Latvala --- .../igt-gpu-tools/igt-gpu-tools-docs.xml | 1 + lib/igt_msm.c | 211 ++++++++++++++++++ lib/igt_msm.h | 142 ++++++++++++ lib/meson.build | 1 + 4 files changed, 355 insertions(+) create mode 100644 lib/igt_msm.c create mode 100644 lib/igt_msm.h diff --git a/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml b/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml index 0f49b4a3..189597c6 100644 --- a/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml +++ b/docs/reference/igt-gpu-tools/igt-gpu-tools-docs.xml @@ -34,6 +34,7 @@ + diff --git a/lib/igt_msm.c b/lib/igt_msm.c new file mode 100644 index 00000000..b9534164 --- /dev/null +++ b/lib/igt_msm.c @@ -0,0 +1,211 @@ +/* + * Copyright © 2021 Google, Inc. + * + * 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_msm.h" +#include "ioctl_wrappers.h" + +/** + * SECTION:igt_msm + * @short_description: msm support library + * @title: msm + * @include: igt_msm.h + * + * This library provides various auxiliary helper functions for writing msm + * tests. + */ + +static uint64_t +get_param(struct msm_device *dev, uint32_t pipe, uint32_t param) +{ + struct drm_msm_param req = { + .pipe = pipe, + .param = param, + }; + + do_ioctl(dev->fd, DRM_IOCTL_MSM_GET_PARAM, &req); + + return req.value; +} + +/** + * igt_msm_dev_open: + * + * Open the msm drm device. + */ +struct msm_device * +igt_msm_dev_open(void) +{ + struct msm_device *dev = calloc(1, sizeof(*dev)); + + dev->fd = drm_open_driver_render(DRIVER_MSM); + dev->gen = (get_param(dev, MSM_PIPE_3D0, MSM_PARAM_CHIP_ID) >> 24) & 0xff; + + return dev; +} + +/** + * igt_msm_dev_close: + * @dev: the device to close + * + * Close the msm drm device. + */ +void +igt_msm_dev_close(struct msm_device *dev) +{ + if (!dev) + return; + close(dev->fd); + free(dev); +} + +/** + * igt_msm_bo_new: + * @dev: the device to allocate the BO from + * @size: the requested BO size in bytes + * @flags: bitmask of MSM_BO_x + * + * Allocate a buffer object of the requested size. + */ +struct msm_bo * +igt_msm_bo_new(struct msm_device *dev, size_t size, uint32_t flags) +{ + struct msm_bo *bo = calloc(1, sizeof(*bo)); + + struct drm_msm_gem_new req = { + .size = size, + .flags = flags, + }; + + bo->dev = dev; + bo->size = size; + + do_ioctl(dev->fd, DRM_IOCTL_MSM_GEM_NEW, &req); + + bo->handle = req.handle; + + return bo; +} + +/** + * igt_msm_bo_free: + * @bo: the BO to free + * + * Free a buffer object + */ +void +igt_msm_bo_free(struct msm_bo *bo) +{ + if (!bo) + return; + if (bo->map) + munmap(bo->map, bo->size); + gem_close(bo->dev->fd, bo->handle); + free(bo); +} + +/** + * igt_msm_bo_map: + * @bo: the BO to map + * + * Returns a pointer to mmap'd buffer. + */ +void * +igt_msm_bo_map(struct msm_bo *bo) +{ + if (!bo->map) { + struct drm_msm_gem_info req = { + .handle = bo->handle, + .info = MSM_INFO_GET_OFFSET, + }; + void *ptr; + + do_ioctl(bo->dev->fd, DRM_IOCTL_MSM_GEM_INFO, &req); + + ptr = mmap(0, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED, + bo->dev->fd, req.value); + if (ptr == MAP_FAILED) + return NULL; + + bo->map = ptr; + } + return bo->map; +} + +/** + * igt_msm_pipe_open: + * @dev: the device to create a submitqueue/pipe against + * @prio: the requested priority, from 0 (highest) to MSM_PARAM_PRIORITIES-1 + * (lowest) + * + * Allocate a pipe/submitqueue against which cmdstream may be submitted. + */ +struct msm_pipe * +igt_msm_pipe_open(struct msm_device *dev, uint32_t prio) +{ + struct msm_pipe *pipe = calloc(1, sizeof(*pipe)); + struct drm_msm_submitqueue req = { + .flags = 0, + .prio = prio, + }; + + pipe->dev = dev; + pipe->pipe = MSM_PIPE_3D0; + + /* Note that kernels prior to v4.15 did not support submitqueues. + * Mesa maintains support for older kernels, but IGT does not need + * to. + */ + do_ioctl(dev->fd, DRM_IOCTL_MSM_SUBMITQUEUE_NEW, &req); + + pipe->submitqueue_id = req.id; + + return pipe; +} + +/** + * igt_msm_pipe_close: + * @pipe: the pipe to close + * + * Close a pipe + */ +void +igt_msm_pipe_close(struct msm_pipe *pipe) +{ + if (!pipe) + return; + do_ioctl(pipe->dev->fd, DRM_IOCTL_MSM_SUBMITQUEUE_CLOSE, &pipe->submitqueue_id); + free(pipe); +} diff --git a/lib/igt_msm.h b/lib/igt_msm.h new file mode 100644 index 00000000..99a099c1 --- /dev/null +++ b/lib/igt_msm.h @@ -0,0 +1,142 @@ +/* + * Copyright © 2021 Google, Inc. + * + * 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_MSM_H +#define IGT_MSM_H + +#include "msm_drm.h" + +/** + * msm_device: + * @fd: the drm device file descriptor + * @gen: the device major generation (ie. 2 for a2xx, etc) + * + * Helper container for device and device related parameters used by tests. + */ +struct msm_device { + int fd; + unsigned gen; +}; + +struct msm_device *igt_msm_dev_open(void); +void igt_msm_dev_close(struct msm_device *dev); + +/** + * msm_bo: + * @dev: the device the BO is allocated from + * @handle: the BO's GEM handle + * @size: the BO's size + * @map: the BO's memory mapping (if mapped) + * + * Helper wrapper for a GEM buffer object. + */ +struct msm_bo { + struct msm_device *dev; + int handle; + uint32_t size; + void *map; +}; + +struct msm_bo *igt_msm_bo_new(struct msm_device *dev, size_t size, uint32_t flags); +void igt_msm_bo_free(struct msm_bo *bo); +void *igt_msm_bo_map(struct msm_bo *bo); + +/** + * msm_pipe: + * @dev: the device the pipe is allocated from + * @pipe: the pipe id + * @submitqueue_id: the submitqueue id + * + * Helper wrapper for a submitqueue for cmdstream submission. + */ +struct msm_pipe { + struct msm_device *dev; + uint32_t pipe; + uint32_t submitqueue_id; +}; + +struct msm_pipe *igt_msm_pipe_open(struct msm_device *dev, uint32_t prio); +void igt_msm_pipe_close(struct msm_pipe *pipe); + +/* + * Helpers for cmdstream building: + */ + +enum adreno_pm4_packet_type { + CP_TYPE0_PKT = 0, + CP_TYPE1_PKT = 0x40000000, + CP_TYPE2_PKT = 0x80000000, + CP_TYPE3_PKT = 0xc0000000, + CP_TYPE4_PKT = 0x40000000, + CP_TYPE7_PKT = 0x70000000, +}; + +enum adreno_pm4_type3_packets { + CP_NOP = 16, +}; + +static inline unsigned +pm4_odd_parity_bit(unsigned val) +{ + /* See: http://graphics.stanford.edu/~seander/bithacks.html#ParityParallel + * note that we want odd parity so 0x6996 is inverted. + */ + val ^= val >> 16; + val ^= val >> 8; + val ^= val >> 4; + val &= 0xf; + return (~0x6996 >> val) & 1; +} + +static inline uint32_t +pm4_pkt0_hdr(uint16_t regindx, uint16_t cnt) +{ + return CP_TYPE0_PKT | ((cnt - 1) << 16) | (regindx & 0x7fff); +} + +static inline uint32_t +pm4_pkt3_hdr(uint8_t opcode, uint16_t cnt) +{ + return CP_TYPE3_PKT | ((cnt - 1) << 16) | ((opcode & 0xff) << 8); +} + +static inline uint32_t +pm4_pkt4_hdr(uint16_t regindx, uint16_t cnt) +{ + return CP_TYPE4_PKT | cnt | (pm4_odd_parity_bit(cnt) << 7) | + ((regindx & 0x3ffff) << 8) | + ((pm4_odd_parity_bit(regindx) << 27)); +} + +static inline uint32_t +pm4_pkt7_hdr(uint8_t opcode, uint16_t cnt) +{ + return CP_TYPE7_PKT | cnt | (pm4_odd_parity_bit(cnt) << 15) | + ((opcode & 0x7f) << 16) | + ((pm4_odd_parity_bit(opcode) << 23)); +} + +#define U642VOID(x) ((void *)(uintptr_t)(x)) +#define VOID2U64(x) ((uint64_t)(uintptr_t)(x)) + +#endif /* IGT_MSM_H */ diff --git a/lib/meson.build b/lib/meson.build index 67d40512..c3080fc8 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -82,6 +82,7 @@ lib_sources = [ 'igt_eld.c', 'igt_infoframe.c', 'veboxcopy_gen12.c', + 'igt_msm.c', ] lib_deps = [ From patchwork Mon Aug 30 16:22:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 12465529 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AE3AC432BE for ; Mon, 30 Aug 2021 16:18:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E7CB260F56 for ; Mon, 30 Aug 2021 16:18:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237892AbhH3QTO (ORCPT ); Mon, 30 Aug 2021 12:19:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232785AbhH3QTG (ORCPT ); Mon, 30 Aug 2021 12:19:06 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E78CC061575 for ; Mon, 30 Aug 2021 09:18:13 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id 18so12570583pfh.9 for ; Mon, 30 Aug 2021 09:18:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dZ5NLi48/ks2VduUDuem4YjEYmme2I11rheeBQgVCr0=; b=LNygbF14VAZrDgm2cJ+i3nalJeKl7fHbp+jwilR82k6V9pcO+o+OUgE4GwsM6eke90 8LNLIGvmspUXNlLY7Fo/hhdeeyxlw+tiAlIa5JibdzLGj+qU+lH/6vJ5xXF0e3MfhroZ d9pf5856e4vL4nwwUTC8k+bzJxRq+Eu0iDSD72vJz59aLivyX6IFlCDBHmuGjU/eZb2a v4BVaOrtQg6nBtsaDAvG3xOsYWImEdyrHWgbXd4FHMsDbBCqZsxUwcrps92ZBiQ57lNI gROI1Rm+xCQtXibbExKhFimCDynimxmVCgzviPRlYEVlpdoeAzJGTaYJNfwoGEdWPBIg u74g== 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:mime-version:content-transfer-encoding; bh=dZ5NLi48/ks2VduUDuem4YjEYmme2I11rheeBQgVCr0=; b=i28Tgr9UXMtnVHUNkph+hCJcyiWJcr2qZU2Y2fMh4tzj06dvzbz4vtJr6oOd/faive rkVTYA1AJcBOg1hM3NiFOko3ZAbORfOEwmsAVIfr0YwEnX2II9kwgTqSl+89VurgPB/c pjTbPAAXtwAqD3ddbmwf7h6WSmkYCN+sPotECJrAtJslJ9ZuMKeDmdQtcvzi/l1uJiy1 j7T1nEO/9SPy/6n0Idn7xLZH9OIrH8uJPB0XcDtF85O3poLkQ8EQCzriM+pjuc9FhZrq Nrlayh61lZ+exO/SXHgT0yH+1qCPbdbjs9XDkSk37qDOnImZYDexKBHONUz29UuuqH9K ID+g== X-Gm-Message-State: AOAM533lPH0a2FBrW9ZH/G8T5bW+ofJvPpVRsJYCDVc5iESAGt8UYM3G 87i2z6vxlcLCj5iEMDZ5AzI= X-Google-Smtp-Source: ABdhPJwnz5KiaxSjC+pvkwP5Enh7aPPMTmspW4YX3UvVn2eJHEnAb5c3m4eOopam4zD9RT3bhGEqWw== X-Received: by 2002:a63:f913:: with SMTP id h19mr21995697pgi.351.1630340292581; Mon, 30 Aug 2021 09:18:12 -0700 (PDT) Received: from localhost (c-73-25-156-94.hsd1.or.comcast.net. [73.25.156.94]) by smtp.gmail.com with ESMTPSA id h13sm16560284pgh.93.2021.08.30.09.18.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Aug 2021 09:18:11 -0700 (PDT) From: Rob Clark To: igt-dev@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Jordan Crouse , Akhil P Oommen , Petri Latvala , Rob Clark Subject: [PATCH igt v3 3/3] msm: Add submit ioctl tests Date: Mon, 30 Aug 2021 09:22:32 -0700 Message-Id: <20210830162232.1328594-4-robdclark@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210830162232.1328594-1-robdclark@gmail.com> References: <20210830162232.1328594-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Rob Clark Add an initial set of tests for the submit ioctl. v2: Add NULL inits, igt_describe() Signed-off-by: Rob Clark Acked-by: Petri Latvala --- tests/meson.build | 1 + tests/msm_submit.c | 194 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 195 insertions(+) create mode 100644 tests/msm_submit.c diff --git a/tests/meson.build b/tests/meson.build index 1bdfddbb..ff7c709a 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -107,6 +107,7 @@ test_progs = [ 'vc4_wait_seqno', 'vgem_basic', 'vgem_slow', + 'msm_submit', ] i915_progs = [ diff --git a/tests/msm_submit.c b/tests/msm_submit.c new file mode 100644 index 00000000..95f8318f --- /dev/null +++ b/tests/msm_submit.c @@ -0,0 +1,194 @@ +/* + * Copyright © 2021 Google, Inc. + * + * 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_msm.h" + +igt_main +{ + struct msm_device *dev = NULL; + struct msm_pipe *pipe = NULL; + struct msm_bo *a = NULL, *b = NULL; + + igt_fixture { + dev = igt_msm_dev_open(); + pipe = igt_msm_pipe_open(dev, 0); + a = igt_msm_bo_new(dev, 0x1000, MSM_BO_WC); + b = igt_msm_bo_new(dev, 0x1000, MSM_BO_WC); + } + + igt_describe("Check that a valid empty submit succeeds"); + igt_subtest("empty-submit") { + struct drm_msm_gem_submit req = { + .flags = pipe->pipe, + .queueid = pipe->submitqueue_id, + }; + do_ioctl(dev->fd, DRM_IOCTL_MSM_GEM_SUBMIT, &req); + } + + igt_describe("Check that submit with invalid submitqueue id fails"); + igt_subtest("invalid-queue-submit") { + struct drm_msm_gem_submit req = { + .flags = pipe->pipe, + .queueid = 0x1234, + }; + do_ioctl_err(dev->fd, DRM_IOCTL_MSM_GEM_SUBMIT, &req, ENOENT); + } + + igt_describe("Check that submit with invalid flags fails"); + igt_subtest("invalid-flags-submit") { + struct drm_msm_gem_submit req = { + .flags = 0x1234, + .queueid = pipe->submitqueue_id, + }; + do_ioctl_err(dev->fd, DRM_IOCTL_MSM_GEM_SUBMIT, &req, EINVAL); + } + + igt_describe("Check that submit with invalid in-fence fd fails"); + igt_subtest("invalid-in-fence-submit") { + struct drm_msm_gem_submit req = { + .flags = pipe->pipe | MSM_SUBMIT_FENCE_FD_IN, + .queueid = pipe->submitqueue_id, + .fence_fd = dev->fd, /* This is not a fence fd! */ + }; + do_ioctl_err(dev->fd, DRM_IOCTL_MSM_GEM_SUBMIT, &req, EINVAL); + } + + igt_describe("Check that submit with duplicate bo fails"); + igt_subtest("invalid-duplicate-bo-submit") { + struct drm_msm_gem_submit_bo bos[] = { + [0] = { + .handle = a->handle, + .flags = MSM_SUBMIT_BO_READ, + }, + [1] = { + .handle = b->handle, + .flags = MSM_SUBMIT_BO_READ, + }, + [2] = { + /* this is invalid.. there should not be two entries + * for the same bo, instead a single entry w/ all + * usage flags OR'd together should be used. Kernel + * should catch this, and return an error code after + * cleaning up properly (not leaking any bo's) + */ + .handle = a->handle, + .flags = MSM_SUBMIT_BO_WRITE, + }, + }; + struct drm_msm_gem_submit req = { + .flags = pipe->pipe, + .queueid = pipe->submitqueue_id, + .nr_bos = ARRAY_SIZE(bos), + .bos = VOID2U64(bos), + }; + do_ioctl_err(dev->fd, DRM_IOCTL_MSM_GEM_SUBMIT, &req, EINVAL); + } + + igt_describe("Check that submit with cmdstream referencing an invalid bo fails"); + igt_subtest("invalid-cmd-idx-submit") { + struct drm_msm_gem_submit_cmd cmds[] = { + [0] = { + .type = MSM_SUBMIT_CMD_BUF, + .submit_idx = 0, /* bos[0] does not exist */ + .size = 4 * 4, /* 4 dwords in cmdbuf */ + }, + }; + struct drm_msm_gem_submit req = { + .flags = pipe->pipe, + .queueid = pipe->submitqueue_id, + .nr_cmds = ARRAY_SIZE(cmds), + .cmds = VOID2U64(cmds), + }; + do_ioctl_err(dev->fd, DRM_IOCTL_MSM_GEM_SUBMIT, &req, EINVAL); + } + + igt_describe("Check that submit with invalid cmdstream type fails"); + igt_subtest("invalid-cmd-type-submit") { + struct drm_msm_gem_submit_bo bos[] = { + [0] = { + .handle = a->handle, + .flags = MSM_SUBMIT_BO_READ, + }, + }; + struct drm_msm_gem_submit_cmd cmds[] = { + [0] = { + .type = 0x1234, + .submit_idx = 0, + .size = 4 * 4, /* 4 dwords in cmdbuf */ + }, + }; + struct drm_msm_gem_submit req = { + .flags = pipe->pipe, + .queueid = pipe->submitqueue_id, + .nr_cmds = ARRAY_SIZE(cmds), + .cmds = VOID2U64(cmds), + .nr_bos = ARRAY_SIZE(bos), + .bos = VOID2U64(bos), + }; + do_ioctl_err(dev->fd, DRM_IOCTL_MSM_GEM_SUBMIT, &req, EINVAL); + } + + igt_describe("Check that a valid non-empty submit succeeds"); + igt_subtest("valid-submit") { + struct drm_msm_gem_submit_bo bos[] = { + [0] = { + .handle = a->handle, + .flags = MSM_SUBMIT_BO_READ, + }, + }; + struct drm_msm_gem_submit_cmd cmds[] = { + [0] = { + .type = MSM_SUBMIT_CMD_BUF, + .submit_idx = 0, + .size = 4 * 4, /* 4 dwords in cmdbuf */ + }, + }; + struct drm_msm_gem_submit req = { + .flags = pipe->pipe, + .queueid = pipe->submitqueue_id, + .nr_cmds = ARRAY_SIZE(cmds), + .cmds = VOID2U64(cmds), + .nr_bos = ARRAY_SIZE(bos), + .bos = VOID2U64(bos), + }; + uint32_t *cmdstream = igt_msm_bo_map(a); + if (dev->gen >= 5) { + *(cmdstream++) = pm4_pkt7_hdr(CP_NOP, 3); + } else { + *(cmdstream++) = pm4_pkt3_hdr(CP_NOP, 3); + } + *(cmdstream++) = 0; + *(cmdstream++) = 0; + *(cmdstream++) = 0; + + do_ioctl(dev->fd, DRM_IOCTL_MSM_GEM_SUBMIT, &req); + } + + igt_fixture { + igt_msm_bo_free(a); + igt_msm_bo_free(b); + igt_msm_pipe_close(pipe); + igt_msm_dev_close(dev); + } +}