From patchwork Sun Aug 30 17:44:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 11745253 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 6F9DD138A for ; Sun, 30 Aug 2020 17:45:10 +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 4F13F20707 for ; Sun, 30 Aug 2020 17:45:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qSgXLL0E" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4F13F20707 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9A44B6E0AB; Sun, 30 Aug 2020 17:45:09 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0B04F6E095; Sun, 30 Aug 2020 17:45:08 +0000 (UTC) Received: by mail-qk1-x742.google.com with SMTP id p4so4288575qkf.0; Sun, 30 Aug 2020 10:45:07 -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=yju5GRoEe8ZWAk/KDL7JArWZz8FoPxNyzJER8wQ5Su0=; b=qSgXLL0EjiMZFLUByt4ocP1/KgH+oFSFqSTD64wR5VwTiiUmSbl7iWv6O6YitRbZFC ZYD3w6QjXIuzcIzH7dO4H9iaZLwfc3qynsNL2+dRlOijNU3R7QFxxb5pgd1i8PK493Rj XznOeJsQ+yueWyDoVAxH8SaroN6C5VCS+Ao9ZvC2zkJOEnx+UjfluOtrmhhwmRFWbxZY P8Ik3q0aOLifyvx0ZgY7afhnggrwaDNSwdEKOTkIt8qb4846+HNIozW7cNs6IRUM+e8e XclFPW6cNoBHvwtCDA8yQfiAUOzLc7NPhxOU7VakWmQ7zJU/aTeFskl5TN5T8j/q0AQL kGxQ== 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=yju5GRoEe8ZWAk/KDL7JArWZz8FoPxNyzJER8wQ5Su0=; b=BnNNeDWQcjWoLXtEWSFGojqL6hTMWch/9BaUXwQyAZPatZdfQhYPRpVasK2ObXwLAq 0IOOPG5EFl6IxNKceW7x7YrqsPXW7S2i2ps78Fbqi4zKXnIsjjOOPHLWo3MnBQLmxFJs p2RWUN/yICHgAWXvgBxodnOA6CQoFGV11JVu4/mDg565NCTzBMsVGbWih/tVmeqyq1t1 ZatFhpOnVPpoTyYuF2kIARqKKi6SQOARIpmWx2fgjrZWHoQgWEOpKgIRU0XcOcBLjWa8 Q0zbAiH5XfCT8ynt3CCjkD9K8lGuuNMwvaWKdTAur48KmL/HylYWANnyzYXxdcg5HQ+U BDLg== X-Gm-Message-State: AOAM532oEQRl3p7oFQbcYD/H/pMje6agN+vd+7KCMWEMtgxEyA1Osehi r7i3/xd2Ri5DpjVJdGe6yOg27aSNw+r8xw== X-Google-Smtp-Source: ABdhPJxf94wdigToLr20gFuCiGnfU1sYX2NyEqu58BdcksxMb3OsGDfjhVCJjYDERMmEdgtCpc/sTw== X-Received: by 2002:a05:620a:13ee:: with SMTP id h14mr7682049qkl.44.1598809506818; Sun, 30 Aug 2020 10:45:06 -0700 (PDT) Received: from atma2.hitronhub.home ([2607:fea8:56e0:6d60::2db6]) by smtp.gmail.com with ESMTPSA id l1sm6797662qtp.96.2020.08.30.10.45.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Aug 2020 10:45:06 -0700 (PDT) From: Rodrigo Siqueira To: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, nd Date: Sun, 30 Aug 2020 13:44:07 -0400 Message-Id: <20200830174410.256533-2-rodrigosiqueiramelo@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200830174410.256533-1-rodrigosiqueiramelo@gmail.com> References: <20200830174410.256533-1-rodrigosiqueiramelo@gmail.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v9 1/4] lib/igt_kms: Add writeback support X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Simon Ser , Brian Starkey , Simon Ser , melissa.srw@gmail.com, Maxime Ripard Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Brian Starkey Add support in igt_kms for writeback connectors, with the ability to attach framebuffers. v8: Remove unnecessary fence cleanup on prepare commit. v5: Rebase and add DRM_CLIENT_CAP_WRITEBACK_CONNECTORS before drmModeGetResources() Signed-off-by: Brian Starkey [rebased and updated to the latest igt style] Signed-off-by: Liviu Dudau [rebased and updated to the latest igt style] Signed-off-by: Rodrigo Siqueira Reviewed-by: Liviu Dudau Reviewed-by: Simon Ser --- lib/igt_kms.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_kms.h | 6 ++++++ 2 files changed, 58 insertions(+) diff --git a/lib/igt_kms.c b/lib/igt_kms.c index f57972f1..7cf2008e 100644 --- a/lib/igt_kms.c +++ b/lib/igt_kms.c @@ -421,6 +421,9 @@ const char * const igt_connector_prop_names[IGT_NUM_CONNECTOR_PROPS] = { [IGT_CONNECTOR_LINK_STATUS] = "link-status", [IGT_CONNECTOR_MAX_BPC] = "max bpc", [IGT_CONNECTOR_HDR_OUTPUT_METADATA] = "HDR_OUTPUT_METADATA", + [IGT_CONNECTOR_WRITEBACK_PIXEL_FORMATS] = "WRITEBACK_PIXEL_FORMATS", + [IGT_CONNECTOR_WRITEBACK_FB_ID] = "WRITEBACK_FB_ID", + [IGT_CONNECTOR_WRITEBACK_OUT_FENCE_PTR] = "WRITEBACK_OUT_FENCE_PTR", }; /* @@ -653,6 +656,7 @@ static const struct type_name connector_type_names[] = { { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, { DRM_MODE_CONNECTOR_DSI, "DSI" }, { DRM_MODE_CONNECTOR_DPI, "DPI" }, + { DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" }, {} }; @@ -1813,6 +1817,14 @@ static void igt_output_reset(igt_output_t *output) if (igt_output_has_prop(output, IGT_CONNECTOR_HDR_OUTPUT_METADATA)) igt_output_set_prop_value(output, IGT_CONNECTOR_HDR_OUTPUT_METADATA, 0); + + if (igt_output_has_prop(output, IGT_CONNECTOR_WRITEBACK_FB_ID)) + igt_output_set_prop_value(output, IGT_CONNECTOR_WRITEBACK_FB_ID, 0); + if (igt_output_has_prop(output, IGT_CONNECTOR_WRITEBACK_OUT_FENCE_PTR)) { + igt_output_clear_prop_changed(output, IGT_CONNECTOR_WRITEBACK_OUT_FENCE_PTR); + output->writeback_out_fence_fd = -1; + } + } /** @@ -1930,6 +1942,8 @@ void igt_display_require(igt_display_t *display, int drm_fd) display->drm_fd = drm_fd; is_i915_dev = is_i915_device(drm_fd); + drmSetClientCap(drm_fd, DRM_CLIENT_CAP_WRITEBACK_CONNECTORS, 1); + resources = drmModeGetResources(display->drm_fd); if (!resources) goto out; @@ -2268,6 +2282,11 @@ static void igt_output_fini(igt_output_t *output) kmstest_free_connector_config(&output->config); free(output->name); output->name = NULL; + + if (output->writeback_out_fence_fd != -1) { + close(output->writeback_out_fence_fd); + output->writeback_out_fence_fd = -1; + } } /** @@ -3458,6 +3477,16 @@ display_commit_changed(igt_display_t *display, enum igt_commit_style s) else /* no modeset in universal commit, no change to crtc. */ output->changed &= 1 << IGT_CONNECTOR_CRTC_ID; + + if (s == COMMIT_ATOMIC) { + if (igt_output_is_prop_changed(output, IGT_CONNECTOR_WRITEBACK_OUT_FENCE_PTR)) + igt_assert(output->writeback_out_fence_fd >= 0); + + output->values[IGT_CONNECTOR_WRITEBACK_OUT_FENCE_PTR] = 0; + output->values[IGT_CONNECTOR_WRITEBACK_FB_ID] = 0; + igt_output_clear_prop_changed(output, IGT_CONNECTOR_WRITEBACK_FB_ID); + igt_output_clear_prop_changed(output, IGT_CONNECTOR_WRITEBACK_OUT_FENCE_PTR); + } } if (display->first_commit) { @@ -4130,6 +4159,29 @@ void igt_pipe_request_out_fence(igt_pipe_t *pipe) igt_pipe_obj_set_prop_value(pipe, IGT_CRTC_OUT_FENCE_PTR, (ptrdiff_t)&pipe->out_fence_fd); } +/** + * igt_output_set_writeback_fb: + * @output: Target output + * @fb: Target framebuffer + * + * This function sets the given @fb to be used as the target framebuffer for the + * writeback engine at the next atomic commit. It will also request a writeback + * out fence that will contain the fd number of the out fence created by KMS if + * the given @fb is valid. + */ +void igt_output_set_writeback_fb(igt_output_t *output, struct igt_fb *fb) +{ + igt_display_t *display = output->display; + + LOG(display, "%s: output_set_writeback_fb(%d)\n", output->name, fb ? fb->fb_id : 0); + + igt_output_set_prop_value(output, IGT_CONNECTOR_WRITEBACK_FB_ID, fb ? fb->fb_id : 0); + /* only request a writeback out fence if the framebuffer is valid */ + if (fb) + igt_output_set_prop_value(output, IGT_CONNECTOR_WRITEBACK_OUT_FENCE_PTR, + (ptrdiff_t)&output->writeback_out_fence_fd); +} + /** * igt_wait_for_vblank_count: * @drm_fd: A drm file descriptor diff --git a/lib/igt_kms.h b/lib/igt_kms.h index 26dc9f5f..45da6bf6 100644 --- a/lib/igt_kms.h +++ b/lib/igt_kms.h @@ -128,6 +128,9 @@ enum igt_atomic_connector_properties { IGT_CONNECTOR_LINK_STATUS, IGT_CONNECTOR_MAX_BPC, IGT_CONNECTOR_HDR_OUTPUT_METADATA, + IGT_CONNECTOR_WRITEBACK_PIXEL_FORMATS, + IGT_CONNECTOR_WRITEBACK_FB_ID, + IGT_CONNECTOR_WRITEBACK_OUT_FENCE_PTR, IGT_NUM_CONNECTOR_PROPS }; @@ -379,6 +382,8 @@ typedef struct { bool use_override_mode; drmModeModeInfo override_mode; + int32_t writeback_out_fence_fd; + /* bitmask of changed properties */ uint64_t changed; @@ -438,6 +443,7 @@ igt_output_t *igt_output_from_connector(igt_display_t *display, drmModeConnector *connector); void igt_output_refresh(igt_output_t *output); const drmModeModeInfo *igt_std_1024_mode_get(void); +void igt_output_set_writeback_fb(igt_output_t *output, struct igt_fb *fb); igt_plane_t *igt_pipe_get_plane_type(igt_pipe_t *pipe, int plane_type); int igt_pipe_count_plane_type(igt_pipe_t *pipe, int plane_type); From patchwork Sun Aug 30 17:44:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 11745255 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 73F7C14E5 for ; Sun, 30 Aug 2020 17:45:19 +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 53FE72078D for ; Sun, 30 Aug 2020 17:45:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gKarT9nd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 53FE72078D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E914F6E095; Sun, 30 Aug 2020 17:45:18 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by gabe.freedesktop.org (Postfix) with ESMTPS id EB7226E095; Sun, 30 Aug 2020 17:45:17 +0000 (UTC) Received: by mail-qk1-x72d.google.com with SMTP id o64so4215575qkb.10; Sun, 30 Aug 2020 10:45:17 -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=7qwbVyE/szLKsTRrl4rkeRmJ4QwVV9ZxcbDeaYEHz64=; b=gKarT9nd35c/QzoUOcUHYnBdKp7asjnkPjmyz1kzodBetPV5RMxqWHClw/s0kjmyUT Ap1KQjXAaus3OmnvzYtNqERLvDT6ycF8CV6xQa8zNvggM7FSpetGZBveOCOXyqLvakjl +9r4f22l48zb8astS5vhxRwF5DYtCGjmZrfcXHSljx05RWlM3vsMN+C841Br5XPSA+6W A+8nPyiBQIxjb6NoAkfu8ie8S7Xd4O6MmUWgrUK4egOCN0FXZ4DPDn3hW1nvh5pyIF0W n1gGVvztA5bczrQcC9afrOnAzCngAIXHXnFyoevO4xRENxbACJ6nXrmH0qa5eptfbW1I MEZg== 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=7qwbVyE/szLKsTRrl4rkeRmJ4QwVV9ZxcbDeaYEHz64=; b=s9Q18BM+AmGSLkjwAk8PSnPv63B+yDq6QW7AX9yNM2dzxS8KH30KuJ8jIkwd08ZN3W 7aqcyi4rgP6Gwypq7ZCRYXNvhwXG/2sJmfRCAmMB1MgE7gLvATP1VjPqjWRfn2zvKXLf zd3da9IHYNkEpbN2qHhi9eEtpFj8YFYslxx589PWaNI22u/oD/r8mVRr/cbv6G/unoD6 mPmSUCIp+Mnbn/x/epB1jL2zV1U7Gv1M9ouINd46FoPJ1vBWWw/UTmGzVA/ysqXOZKzn uvXCM4/bgDpU16GIVJGyXRrHt3huLZ0fIYd46g1JumwvixRX03oZ9T80UpwXkdhaWHGV TTXg== X-Gm-Message-State: AOAM530b6Oww7usT5cj7bUkUu/S3tmduC1ElhXJGiCdZIxzh/CMsOhEM FfWAD/Zjw9slDTcg0W1ilRpWqGujB+Xo4w== X-Google-Smtp-Source: ABdhPJyaQ090TKycfBw2ZLwEX4ihQ6+PdgOluXsSM6D/p2sin3mF/q5ZyLrvvGDNxGB3d6LRTg4qRA== X-Received: by 2002:a37:4811:: with SMTP id v17mr7833412qka.166.1598809516621; Sun, 30 Aug 2020 10:45:16 -0700 (PDT) Received: from atma2.hitronhub.home ([2607:fea8:56e0:6d60::2db6]) by smtp.gmail.com with ESMTPSA id l1sm6797662qtp.96.2020.08.30.10.45.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Aug 2020 10:45:16 -0700 (PDT) From: Rodrigo Siqueira To: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, nd Date: Sun, 30 Aug 2020 13:44:08 -0400 Message-Id: <20200830174410.256533-3-rodrigosiqueiramelo@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200830174410.256533-1-rodrigosiqueiramelo@gmail.com> References: <20200830174410.256533-1-rodrigosiqueiramelo@gmail.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v9 2/4] kms_writeback: Add initial writeback tests X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Brian Starkey , Simon Ser , melissa.srw@gmail.com, Maxime Ripard Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Brian Starkey Add tests for the WRITEBACK_PIXEL_FORMATS, WRITEBACK_OUT_FENCE_PTR and WRITEBACK_FB_ID properties on writeback connectors, ensuring their behaviour is correct. Changes since V8: * Remove unnecessary fence cleanup on prepare commit. Changes since V7 (Maxime Ripard and Petri Latvala): * Utilizes `to_user_pointer` to avoid cast compilation error on ARM 32 bits. Changes since V6 (Simon Ser): * Add igt_describe per sub-test * Remove kmstest_force_connector from kms_writeback_get_output, since userspace will not do this sort of operation * Add an igt_debug statement in case we don't use a specific writeback connector * Drop flag parameter from do_writeback_test * Rename invalid_out_fence to test_invalid_parameters * Drop invalid_fb from writeback_fb_id * Assert if plane is null on igt_fixture * Replace all occurrences of igt_fb_mod_to_tiling(0) by DRM_FORMAT_MOD_LINEAR * Rename invalid_fb to invalid_output_fb in the sub-test related to "writeback-invalid-out-fence" * Replace ret by fb_id in igt_main Reviewed-by: Liviu Dudau Signed-off-by: Brian Starkey [rebased and updated do_writeback_test() function to address feedback] Signed-off-by: Liviu Dudau Signed-off-by: Rodrigo Siqueira --- tests/Makefile.sources | 1 + tests/kms_writeback.c | 316 +++++++++++++++++++++++++++++++++++++++++ tests/meson.build | 1 + 3 files changed, 318 insertions(+) create mode 100644 tests/kms_writeback.c diff --git a/tests/Makefile.sources b/tests/Makefile.sources index 269b506d..6ae95155 100644 --- a/tests/Makefile.sources +++ b/tests/Makefile.sources @@ -89,6 +89,7 @@ TESTS_progs = \ kms_universal_plane \ kms_vblank \ kms_vrr \ + kms_writeback \ meta_test \ prime_busy \ prime_mmap \ diff --git a/tests/kms_writeback.c b/tests/kms_writeback.c new file mode 100644 index 00000000..f8025538 --- /dev/null +++ b/tests/kms_writeback.c @@ -0,0 +1,316 @@ +/* + * (C) COPYRIGHT 2017 ARM Limited. All rights reserved. + * + * 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 "igt.h" +#include "igt_core.h" +#include "igt_fb.h" + +static drmModePropertyBlobRes *get_writeback_formats_blob(igt_output_t *output) +{ + drmModePropertyBlobRes *blob = NULL; + uint64_t blob_id; + int ret; + + ret = kmstest_get_property(output->display->drm_fd, + output->config.connector->connector_id, + DRM_MODE_OBJECT_CONNECTOR, + igt_connector_prop_names[IGT_CONNECTOR_WRITEBACK_PIXEL_FORMATS], + NULL, &blob_id, NULL); + if (ret) + blob = drmModeGetPropertyBlob(output->display->drm_fd, blob_id); + + igt_assert(blob); + + return blob; +} + +static bool check_writeback_config(igt_display_t *display, igt_output_t *output) +{ + igt_fb_t input_fb, output_fb; + igt_plane_t *plane; + uint32_t writeback_format = DRM_FORMAT_XRGB8888; + uint64_t tiling = DRM_FORMAT_MOD_LINEAR; + int width, height, ret; + drmModeModeInfo override_mode = { + .clock = 25175, + .hdisplay = 640, + .hsync_start = 656, + .hsync_end = 752, + .htotal = 800, + .hskew = 0, + .vdisplay = 480, + .vsync_start = 490, + .vsync_end = 492, + .vtotal = 525, + .vscan = 0, + .vrefresh = 60, + .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC, + .name = {"640x480-60"}, + }; + igt_output_override_mode(output, &override_mode); + + width = override_mode.hdisplay; + height = override_mode.vdisplay; + + ret = igt_create_fb(display->drm_fd, width, height, DRM_FORMAT_XRGB8888, tiling, &input_fb); + igt_assert(ret >= 0); + + ret = igt_create_fb(display->drm_fd, width, height, writeback_format, tiling, &output_fb); + igt_assert(ret >= 0); + + plane = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY); + igt_plane_set_fb(plane, &input_fb); + igt_output_set_writeback_fb(output, &output_fb); + + ret = igt_display_try_commit_atomic(display, DRM_MODE_ATOMIC_TEST_ONLY | + DRM_MODE_ATOMIC_ALLOW_MODESET, NULL); + igt_plane_set_fb(plane, NULL); + igt_remove_fb(display->drm_fd, &input_fb); + igt_remove_fb(display->drm_fd, &output_fb); + + return !ret; +} + +static igt_output_t *kms_writeback_get_output(igt_display_t *display) +{ + int i; + + for (i = 0; i < display->n_outputs; i++) { + igt_output_t *output = &display->outputs[i]; + int j; + + if (output->config.connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK) + continue; + + for (j = 0; j < igt_display_get_n_pipes(display); j++) { + igt_output_set_pipe(output, j); + + if (check_writeback_config(display, output)) { + igt_debug("Using connector %u:%s on pipe %d\n", + output->config.connector->connector_id, + output->name, j); + return output; + } + } + + igt_debug("We found %u:%s, but this test will not be able to use it.\n", + output->config.connector->connector_id, output->name); + + /* Restore any connectors we don't use, so we don't trip on them later */ + kmstest_force_connector(display->drm_fd, output->config.connector, FORCE_CONNECTOR_UNSPECIFIED); + } + + return NULL; +} + +static void check_writeback_fb_id(igt_output_t *output) +{ + uint64_t check_fb_id; + + check_fb_id = igt_output_get_prop(output, IGT_CONNECTOR_WRITEBACK_FB_ID); + igt_assert(check_fb_id == 0); +} + +static int do_writeback_test(igt_output_t *output, uint32_t fb_id, + int32_t *out_fence_ptr, bool ptr_valid) +{ + int ret; + igt_display_t *display = output->display; + struct kmstest_connector_config *config = &output->config; + + igt_output_set_prop_value(output, IGT_CONNECTOR_CRTC_ID, config->crtc->crtc_id); + igt_output_set_prop_value(output, IGT_CONNECTOR_WRITEBACK_FB_ID, fb_id); + igt_output_set_prop_value(output, IGT_CONNECTOR_WRITEBACK_OUT_FENCE_PTR, to_user_pointer(out_fence_ptr)); + + if (ptr_valid) + *out_fence_ptr = 0; + + ret = igt_display_try_commit_atomic(display, DRM_MODE_ATOMIC_ALLOW_MODESET, NULL); + + if (ptr_valid) + igt_assert(*out_fence_ptr == -1); + + /* WRITEBACK_FB_ID must always read as zero */ + check_writeback_fb_id(output); + + return ret; +} + +static void test_invalid_parameters(igt_output_t *output, igt_fb_t *valid_fb, igt_fb_t *invalid_fb) +{ + int i, ret; + int32_t out_fence; + struct { + uint32_t fb_id; + bool ptr_valid; + int32_t *out_fence_ptr; + } invalid_tests[] = { + { + /* No output buffer, but the WRITEBACK_OUT_FENCE_PTR set. */ + .fb_id = 0, + .ptr_valid = true, + .out_fence_ptr = &out_fence, + }, + { + /* Invalid output buffer. */ + .fb_id = invalid_fb->fb_id, + .ptr_valid = true, + .out_fence_ptr = &out_fence, + }, + { + /* Invalid WRITEBACK_OUT_FENCE_PTR. */ + .fb_id = valid_fb->fb_id, + .ptr_valid = false, + .out_fence_ptr = (int32_t *)0x8, + }, + }; + + for (i = 0; i < ARRAY_SIZE(invalid_tests); i++) { + ret = do_writeback_test(output, invalid_tests[i].fb_id, + invalid_tests[i].out_fence_ptr, + invalid_tests[i].ptr_valid); + igt_assert(ret != 0); + } +} + +static void writeback_fb_id(igt_output_t *output, igt_fb_t *valid_fb, igt_fb_t *invalid_fb) +{ + + int ret; + + /* Invalid object for WRITEBACK_FB_ID */ + ret = do_writeback_test(output, output->id, NULL, false); + igt_assert(ret == -EINVAL); + + /* Zero WRITEBACK_FB_ID */ + ret = do_writeback_test(output, 0, NULL, false); + igt_assert(ret == 0); + + /* Valid output buffer */ + ret = do_writeback_test(output, valid_fb->fb_id, NULL, false); + igt_assert(ret == 0); +} + +igt_main +{ + igt_display_t display; + igt_output_t *output; + igt_plane_t *plane; + igt_fb_t input_fb; + drmModeModeInfo mode; + unsigned int fb_id; + + memset(&display, 0, sizeof(display)); + + igt_fixture { + display.drm_fd = drm_open_driver_master(DRIVER_ANY); + igt_display_require(&display, display.drm_fd); + + kmstest_set_vt_graphics_mode(); + + igt_display_require(&display, display.drm_fd); + + igt_require(display.is_atomic); + + output = kms_writeback_get_output(&display); + igt_require(output); + + if (output->use_override_mode) + memcpy(&mode, &output->override_mode, sizeof(mode)); + else + memcpy(&mode, &output->config.default_mode, sizeof(mode)); + + plane = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY); + igt_assert(plane); + + fb_id = igt_create_fb(display.drm_fd, mode.hdisplay, + mode.vdisplay, + DRM_FORMAT_XRGB8888, + DRM_FORMAT_MOD_LINEAR, + &input_fb); + igt_assert(fb_id >= 0); + igt_plane_set_fb(plane, &input_fb); + } + + igt_describe("Check the writeback format"); + igt_subtest("writeback-pixel-formats") { + drmModePropertyBlobRes *formats_blob = get_writeback_formats_blob(output); + const char *valid_chars = "0123456 ABCGNRUVXY"; + unsigned int i; + char *c; + + /* + * We don't have a comprehensive list of formats, so just check + * that the blob length is sensible and that it doesn't contain + * any outlandish characters + */ + igt_assert(!(formats_blob->length % 4)); + c = formats_blob->data; + for (i = 0; i < formats_blob->length; i++) + igt_assert_f(strchr(valid_chars, c[i]), + "Unexpected character %c\n", c[i]); + drmModeFreePropertyBlob(formats_blob); + } + + igt_describe("Writeback has a couple of parameters linked together" + "(output framebuffer and fence); this test goes through" + "the combination of possible bad options"); + igt_subtest("writeback-invalid-parameters") { + igt_fb_t invalid_output_fb; + fb_id = igt_create_fb(display.drm_fd, mode.hdisplay / 2, + mode.vdisplay / 2, + DRM_FORMAT_XRGB8888, + DRM_FORMAT_MOD_LINEAR, + &invalid_output_fb); + igt_require(fb_id > 0); + + test_invalid_parameters(output, &input_fb, &invalid_output_fb); + + igt_remove_fb(display.drm_fd, &invalid_output_fb); + } + + igt_describe("Validate WRITEBACK_FB_ID with valid and invalid options"); + igt_subtest("writeback-fb-id") { + igt_fb_t output_fb; + fb_id = igt_create_fb(display.drm_fd, mode.hdisplay, mode.vdisplay, + DRM_FORMAT_XRGB8888, + DRM_FORMAT_MOD_LINEAR, + &output_fb); + igt_require(fb_id > 0); + + writeback_fb_id(output, &input_fb, &output_fb); + + igt_remove_fb(display.drm_fd, &output_fb); + } + + igt_fixture { + igt_remove_fb(display.drm_fd, &input_fb); + igt_display_fini(&display); + } +} diff --git a/tests/meson.build b/tests/meson.build index 684de043..5eb2d2fc 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -73,6 +73,7 @@ test_progs = [ 'kms_universal_plane', 'kms_vblank', 'kms_vrr', + 'kms_writeback', 'meta_test', 'panfrost_get_param', 'panfrost_gem_new', From patchwork Sun Aug 30 17:44:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 11745257 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 3EC4514E5 for ; Sun, 30 Aug 2020 17:45:22 +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 1E8162078D for ; Sun, 30 Aug 2020 17:45:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZDxd1g0h" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1E8162078D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7B3206E0D7; Sun, 30 Aug 2020 17:45:21 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by gabe.freedesktop.org (Postfix) with ESMTPS id A4AD36E0D7; Sun, 30 Aug 2020 17:45:20 +0000 (UTC) Received: by mail-qk1-x742.google.com with SMTP id m7so4207004qki.12; Sun, 30 Aug 2020 10:45:20 -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=Ku6+xicRPIwzFPgdKexwIuePYKQBGLf4JoibsX0KXcg=; b=ZDxd1g0hfltAfVfILJBLlbZjCsUMhP7mDa8DKAR98Pu95vVVHbkZJE5FxdGzBH3/Zj kyjkAfk1G5GKYzNxqtDNxyyRVCgQSF965zIypBJ77rhkkbSE4Lgtn65I8ZpOWT7J7nbL yVCQuTIfoniKGU5mYFRtJ4OOK1meMWtaNMpkI0czWKt6CdOhgR7VdFdwU9PsGsnL3zsU fCnRlXgXvspqpl1DdD/qB83hfiTace1YdPgnbnIG0eLvCGdCAMo/zlNpAY1Q98O3e47z nT7AcJrrcW8U+fDa3FXjG2LGHYTw/A/ss+aT23aHYw4Rl5Jp/fFz4gPUpoBVChN9uSTm 62YA== 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=Ku6+xicRPIwzFPgdKexwIuePYKQBGLf4JoibsX0KXcg=; b=fkUa49yV9my2PD46XZDeOj/odtwrqx40Dn8Ac+HNkory4hLiGKVs9oCvVL8TD0n//d 0yQAsfnzupQ0N/PC2k6exf5czpIARziAGIoaX8EuhUBGEgqm4jYX3SINXhsqZ4H8R8LW KVQnA41eymW/KlOe4EK530keMxTlqh8AOzMSX27RzpqKFYYrVR5XrQf3YqEsAQIuHGm1 qxdeaAmATUvF0bwuXrZWoptaXDSDiVy/Dw234xFj1sleeaxh4s89hK2CaPu1Iaw61rb6 iI7Qwe45M61c/4uco2APYZu+9GVgkd1ziXejcTab4f35tH5RV3h0KBClR+Pkv3rNJflc STfg== X-Gm-Message-State: AOAM533GzhcjEO44FJgHdeIqZrEmC9wLefxhMs98uXbEPhbCOs1MQrgD iU6xOS88WzRaaHLJERNOjnrGpwDRW0EHyg== X-Google-Smtp-Source: ABdhPJye3Qn7IgxphdJTaFOsSUxOKpT95qYgaukeiq8jdqAs/QVt/huXoU4nertK83zk3qw0Xu0egQ== X-Received: by 2002:a37:e103:: with SMTP id c3mr2166066qkm.90.1598809519363; Sun, 30 Aug 2020 10:45:19 -0700 (PDT) Received: from atma2.hitronhub.home ([2607:fea8:56e0:6d60::2db6]) by smtp.gmail.com with ESMTPSA id l1sm6797662qtp.96.2020.08.30.10.45.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Aug 2020 10:45:18 -0700 (PDT) From: Rodrigo Siqueira To: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, nd Date: Sun, 30 Aug 2020 13:44:09 -0400 Message-Id: <20200830174410.256533-4-rodrigosiqueiramelo@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200830174410.256533-1-rodrigosiqueiramelo@gmail.com> References: <20200830174410.256533-1-rodrigosiqueiramelo@gmail.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v9 3/4] lib: Add function to hash a framebuffer X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Simon Ser , Brian Starkey , Simon Ser , melissa.srw@gmail.com, Maxime Ripard Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Brian Starkey To use writeback buffers as a CRC source, we need to be able to hash them. Implement a simple FVA-1a hashing routine for this purpose. Doing a bytewise hash on the framebuffer directly can be very slow if the memory is noncached. By making a copy of each line in the FB first (which can take advantage of word-access speedup), we can do the hash on a cached copy, which is much faster (10x speedup on my platform). Changes since V7 (Maxime Ripard): * Maxime Ripard: - Replace `gem_mmap__gtt` by `igt_fb_map_buffer` on `igt_fb_get_crc()` * Rodrigo Siqueira: - Rename igt_fb_get_crc to igt_fb_get_fnv1a_crc Changes since V6 (Simon Ser): * Use plain uint32_t for FNV1a_OFFSET_BIAS and FNV1a_PRIME * Return -EINVAL in case fb->num_planes != 1 * Just copy fb->width * cpp instead of copy the whole stride v5: use igt_memcpy_from_wc() instead of plain memcpy, as suggested by Chris Wilson Signed-off-by: Brian Starkey [rebased and updated to the most recent API] Signed-off-by: Liviu Dudau [rebased and updated] Signed-off-by: Rodrigo Siqueira Reviewed-by: Simon Ser Reviewed-by: Liviu Dudau --- lib/igt_fb.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_fb.h | 2 ++ 2 files changed, 65 insertions(+) diff --git a/lib/igt_fb.c b/lib/igt_fb.c index 3864b7a1..5e3706e9 100644 --- a/lib/igt_fb.c +++ b/lib/igt_fb.c @@ -3783,6 +3783,69 @@ bool igt_fb_supported_format(uint32_t drm_format) return true; } +/* + * This implements the FNV-1a hashing algorithm instead of CRC, for + * simplicity + * http://www.isthe.com/chongo/tech/comp/fnv/index.html + * + * hash = offset_basis + * for each octet_of_data to be hashed + * hash = hash xor octet_of_data + * hash = hash * FNV_prime + * return hash + * + * 32 bit offset_basis = 2166136261 + * 32 bit FNV_prime = 224 + 28 + 0x93 = 16777619 + */ +int igt_fb_get_fnv1a_crc(struct igt_fb *fb, igt_crc_t *crc) +{ + const uint32_t FNV1a_OFFSET_BIAS = 2166136261; + const uint32_t FNV1a_PRIME = 16777619; + uint32_t hash; + void *map; + char *ptr, *line = NULL; + int x, y, cpp = igt_drm_format_to_bpp(fb->drm_format) / 8; + uint32_t stride = calc_plane_stride(fb, 0); + + if (fb->num_planes != 1) + return -EINVAL; + + ptr = igt_fb_map_buffer(fb->fd, fb); + igt_assert(ptr); + map = ptr; + + /* + * Framebuffers are often uncached, which can make byte-wise accesses + * very slow. We copy each line of the FB into a local buffer to speed + * up the hashing. + */ + line = malloc(stride); + if (!line) { + munmap(map, fb->size); + return -ENOMEM; + } + + hash = FNV1a_OFFSET_BIAS; + + for (y = 0; y < fb->height; y++, ptr += stride) { + + igt_memcpy_from_wc(line, ptr, fb->width * cpp); + + for (x = 0; x < fb->width * cpp; x++) { + hash ^= line[x]; + hash *= FNV1a_PRIME; + } + } + + crc->n_words = 1; + crc->crc[0] = hash; + + free(line); + igt_fb_unmap_buffer(fb, map); + + return 0; +} + /** * igt_format_is_yuv: * @drm_format: drm fourcc diff --git a/lib/igt_fb.h b/lib/igt_fb.h index 5ec906b7..debfb5ad 100644 --- a/lib/igt_fb.h +++ b/lib/igt_fb.h @@ -207,5 +207,7 @@ int igt_format_plane_bpp(uint32_t drm_format, int plane); void igt_format_array_fill(uint32_t **formats_array, unsigned int *count, bool allow_yuv); +int igt_fb_get_fnv1a_crc(struct igt_fb *fb, igt_crc_t *crc); + #endif /* __IGT_FB_H__ */ From patchwork Sun Aug 30 17:44:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 11745259 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 26E15138A for ; Sun, 30 Aug 2020 17:45:29 +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 067A32071B for ; Sun, 30 Aug 2020 17:45:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M/FIK39I" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 067A32071B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 722D86E0EC; Sun, 30 Aug 2020 17:45:28 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by gabe.freedesktop.org (Postfix) with ESMTPS id C4F946E0EC; Sun, 30 Aug 2020 17:45:26 +0000 (UTC) Received: by mail-qk1-x742.google.com with SMTP id d20so1462824qka.5; Sun, 30 Aug 2020 10:45:26 -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=TWKfk6TyMGUJprXCU281A1XBtSXXty7ZC0YTVE+qYNk=; b=M/FIK39I42Shv3VKMYUkc/S4pKMPHjf3hOyQuyWA+fwzN/imME2LNewECwaJay2KfQ DGcc5Q768akH8+6bwGo+MMym4U7Wv7T5nUs7GGH5rJbr5pxWuKJ7+YhbRpb/lGYHTbFO 5WwLGz+rye8SUV8T1ppBn2+mqTG4hV0uGqZEuRqu7UtzBwo7mTYNo6mBEKAJ8WB16fU3 MgzHrAORN+a7/RMEbJAZbt2Og2l3L8GHpfO28k1URu/zU/oxU8Oke1uNWJP89gPypW3l L3WKf8ePmWaf/licfGZwajWzlyGxD4wEu0wXz007Mb8JpLMHOojprOZx5Lx97SHhbeDD CE3A== 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=TWKfk6TyMGUJprXCU281A1XBtSXXty7ZC0YTVE+qYNk=; b=J8HCYCJiT6p9aaEP9Y+7xwjSVB/wl85njPdzVbDST+DAkFC7bNj/sHC6pMJa/1jD1+ YkHXZvPYvV4y4QuqtjOiuE5EJAbdRCRbiPcApZ6HpBgteYwugF7dkEhKLbhubN80fnIC Ac+Cg2Ff2cqGuB7cE75mk4wPcyEp4Bg5CO4Znacd4OZhcCEN04uZVP4ZRdKwRcgsDpfa n29LldKHA8VLSWqEZ25JQzCdeOYOAaLOGCUVLvy4q1IvuZILYHWIMGVkj9Tf3l8Qrnx4 qAfsm8rxbDl/mUiPYuOYDJAUdh9QUiIOazxfIdiSH/0onx9O0Bt6VxZh5pDkAf0thQiZ uXPA== X-Gm-Message-State: AOAM532O0bJ6YIyiRS2r6BkTXPaNChLak1UsY46bcP9hXyFe0TWAJ51I SoasAM6mf/abiVFmYU8hERs3G5g/8wHT1w== X-Google-Smtp-Source: ABdhPJzDDpRHo4dPZ61Us3pe8d1uX23SbKfSH1el0c3FxjenoHfwiqgwwY+cs+qn6ccdJscb4G2brg== X-Received: by 2002:ae9:c007:: with SMTP id u7mr4426125qkk.450.1598809525634; Sun, 30 Aug 2020 10:45:25 -0700 (PDT) Received: from atma2.hitronhub.home ([2607:fea8:56e0:6d60::2db6]) by smtp.gmail.com with ESMTPSA id l1sm6797662qtp.96.2020.08.30.10.45.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Aug 2020 10:45:25 -0700 (PDT) From: Rodrigo Siqueira To: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, nd Date: Sun, 30 Aug 2020 13:44:10 -0400 Message-Id: <20200830174410.256533-5-rodrigosiqueiramelo@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200830174410.256533-1-rodrigosiqueiramelo@gmail.com> References: <20200830174410.256533-1-rodrigosiqueiramelo@gmail.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v9 4/4] kms_writeback: Add writeback-check-output X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Brian Starkey , Simon Ser , melissa.srw@gmail.com, Maxime Ripard Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Brian Starkey Add a test which makes commits using the writeback connector, and checks the output buffer hash to make sure it is/isn't written as appropriate. Changes since V8 (Arkadiusz Hiler): * Add short description Changes since V7 (Maxime Ripard): * Make fb_fill cross-platform Changes since v6 (Simon Ser): * Add a descriptive error message if sync_fence_wait fail * Drop color_idx variable * Compute expected CRC based on input framebuffer in writeback_sequence * Remove unnecessary parentheses * Replace int variable for unsigned int Signed-off-by: Brian Starkey [rebased and updated] Signed-off-by: Rodrigo Siqueira Reviewed-by: Liviu Dudau --- tests/kms_writeback.c | 134 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/tests/kms_writeback.c b/tests/kms_writeback.c index f8025538..60dbda2a 100644 --- a/tests/kms_writeback.c +++ b/tests/kms_writeback.c @@ -30,6 +30,14 @@ #include "igt.h" #include "igt_core.h" #include "igt_fb.h" +#include "sw_sync.h" + +IGT_TEST_DESCRIPTION( + "This test validates the expected behavior of the writeback connectors " + "feature by checking if the target device support writeback; it validates " + "bad and good combination, check color format, and check the output result " + "by using CRC." +); static drmModePropertyBlobRes *get_writeback_formats_blob(igt_output_t *output) { @@ -217,6 +225,118 @@ static void writeback_fb_id(igt_output_t *output, igt_fb_t *valid_fb, igt_fb_t * igt_assert(ret == 0); } +static void fill_fb(igt_fb_t *fb, uint32_t pixel) +{ + void *ptr; + + igt_assert(fb->drm_format == DRM_FORMAT_XRGB8888); + + ptr = igt_fb_map_buffer(fb->fd, fb); + igt_assert(ptr); + + memset(ptr, pixel, fb->strides[0] * fb->height); + + igt_fb_unmap_buffer(fb, ptr); +} + +static void get_and_wait_out_fence(igt_output_t *output) +{ + int ret; + + igt_assert(output->writeback_out_fence_fd >= 0); + + ret = sync_fence_wait(output->writeback_out_fence_fd, 1000); + igt_assert_f(ret == 0, "sync_fence_wait failed: %s\n", strerror(-ret)); + close(output->writeback_out_fence_fd); + output->writeback_out_fence_fd = -1; +} + +static void writeback_sequence(igt_output_t *output, igt_plane_t *plane, + igt_fb_t *in_fb, igt_fb_t *out_fbs[], int n_commits) +{ + int i = 0; + uint32_t in_fb_colors[2] = { 0xffff0000, 0xff00ff00 }; + uint32_t clear_color = 0xffffffff; + + igt_crc_t cleared_crc, out_expected; + + for (i = 0; i < n_commits; i++) { + /* Change the input color each time */ + fill_fb(in_fb, in_fb_colors[i % 2]); + + if (out_fbs[i]) { + igt_crc_t out_before; + + /* Get the expected CRC */ + igt_fb_get_fnv1a_crc(in_fb, &out_expected); + fill_fb(out_fbs[i], clear_color); + + if (i == 0) + igt_fb_get_fnv1a_crc(out_fbs[i], &cleared_crc); + igt_fb_get_fnv1a_crc(out_fbs[i], &out_before); + igt_assert_crc_equal(&cleared_crc, &out_before); + } + + /* Commit */ + igt_plane_set_fb(plane, in_fb); + igt_output_set_writeback_fb(output, out_fbs[i]); + + igt_display_commit_atomic(output->display, + DRM_MODE_ATOMIC_ALLOW_MODESET, + NULL); + if (out_fbs[i]) + get_and_wait_out_fence(output); + + /* Make sure the old output buffer is untouched */ + if (i > 0 && out_fbs[i - 1] && out_fbs[i] != out_fbs[i - 1]) { + igt_crc_t out_prev; + igt_fb_get_fnv1a_crc(out_fbs[i - 1], &out_prev); + igt_assert_crc_equal(&cleared_crc, &out_prev); + } + + /* Make sure this output buffer is written */ + if (out_fbs[i]) { + igt_crc_t out_after; + igt_fb_get_fnv1a_crc(out_fbs[i], &out_after); + igt_assert_crc_equal(&out_expected, &out_after); + + /* And clear it, for the next time */ + fill_fb(out_fbs[i], clear_color); + } + } +} + +static void writeback_check_output(igt_output_t *output, igt_plane_t *plane, + igt_fb_t *input_fb, igt_fb_t *output_fb) +{ + igt_fb_t *out_fbs[2] = { 0 }; + igt_fb_t second_out_fb; + unsigned int fb_id; + + /* One commit, with a writeback. */ + writeback_sequence(output, plane, input_fb, &output_fb, 1); + + /* Two commits, the second with no writeback */ + out_fbs[0] = output_fb; + writeback_sequence(output, plane, input_fb, out_fbs, 2); + + /* Two commits, both with writeback */ + out_fbs[1] = output_fb; + writeback_sequence(output, plane, input_fb, out_fbs, 2); + + fb_id = igt_create_fb(output_fb->fd, output_fb->width, output_fb->height, + DRM_FORMAT_XRGB8888, + igt_fb_mod_to_tiling(0), + &second_out_fb); + igt_require(fb_id > 0); + + /* Two commits, with different writeback buffers */ + out_fbs[1] = &second_out_fb; + writeback_sequence(output, plane, input_fb, out_fbs, 2); + + igt_remove_fb(output_fb->fd, &second_out_fb); +} + igt_main { igt_display_t display; @@ -309,6 +429,20 @@ igt_main igt_remove_fb(display.drm_fd, &output_fb); } + igt_describe("Check writeback output with CRC validation"); + igt_subtest("writeback-check-output") { + igt_fb_t output_fb; + fb_id = igt_create_fb(display.drm_fd, mode.hdisplay, mode.vdisplay, + DRM_FORMAT_XRGB8888, + igt_fb_mod_to_tiling(0), + &output_fb); + igt_require(fb_id > 0); + + writeback_check_output(output, plane, &input_fb, &output_fb); + + igt_remove_fb(display.drm_fd, &output_fb); + } + igt_fixture { igt_remove_fb(display.drm_fd, &input_fb); igt_display_fini(&display);