From patchwork Fri Apr 24 01:26:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 11506911 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 A7EAA92C for ; Fri, 24 Apr 2020 01:26:55 +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 860BF20728 for ; Fri, 24 Apr 2020 01:26:55 +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="isI9kYpN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 860BF20728 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 04BA76EA67; Fri, 24 Apr 2020 01:26:55 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by gabe.freedesktop.org (Postfix) with ESMTPS id C8D2A6E063; Fri, 24 Apr 2020 01:26:53 +0000 (UTC) Received: by mail-qv1-xf41.google.com with SMTP id di6so3940890qvb.10; Thu, 23 Apr 2020 18:26:53 -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=Qn3VaQJZ+KqjOis41AXRpAR0YiCD44gachr7QEG7uHo=; b=isI9kYpNgA7TzMqC2zPjYHqiSerDeltPmiKTc85rh028WUu66So9Uu6AUMM1+juwPK Zh8AHp0YNDRtWD9zU5fF6hwDiL0kZjSlGw7+i14gNz2aEJGVdDK4iIzZ0yYbc31hUKDL wkQ00NBiAAxv0rttXpUAnUpBWzpWiPy2zrqxIhl2BXoJtpBbIpBLr4qjylWBF1ceA27k ha29/mOaAmP+UI/290oQeN7UKhzo/5J8KXdUp91sLtsvr0aWbN6QOpefSEk859lp8Ozx yDpWMYQiIlH07GGBR+PB0SQbQfQOqH840KpxtWfH47mR6G+7MxcF5ed4qMep6lftOIMt BANw== 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=Qn3VaQJZ+KqjOis41AXRpAR0YiCD44gachr7QEG7uHo=; b=dPpLI+IOUkGuN10sSsavP/KVFjAjWatiGLYIC95Q/80pgBpx2g6D9yQ6skFgQ2jV/N zn1W88bYunltzhTq/JwQsdd3VdNNzcOOgrCm/pcUg34YrpJpbIX+1UXyUwyoRTUxFuY6 A4VxWmXfEwXNpKeffq3CDfBr/RROx7IyzFGeb4xqpydD/+feyD52zoWeCzq+6Z5HIbRt Jp6kPvXT+qSPyuVBTu7OiNN6A/JrO1mUQnXX/vOq9duao6zmmwKGioRrzWAEO4IZjDvH Piv1x1EZK4iJtnRcPgN79q/GowCxZwvmTm8+oW35uv4SOlqk+FHpwxBRBF/si64dnTmg 7Ufg== X-Gm-Message-State: AGi0PuYgO66N85a9CVBHLQD2giubN8ditqekYXSJwd/8l0g8RgyCXG4C Wp+27WLSqmIxt7vqboxqD3ogfWDY5Qg= X-Google-Smtp-Source: APiQypJf+xwF8b96LcXm5ssTQTp0WlY1PzjIqm2jnlBYfRfsNU4wC+I80Z9JIht6GJXMEYOdV+o9oA== X-Received: by 2002:a05:6214:287:: with SMTP id l7mr6992386qvv.38.1587691612497; Thu, 23 Apr 2020 18:26:52 -0700 (PDT) Received: from atma2.hitronhub.home ([2607:fea8:56a0:11a1::2]) by smtp.gmail.com with ESMTPSA id c41sm2997184qta.96.2020.04.23.18.26.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2020 18:26:52 -0700 (PDT) From: Rodrigo Siqueira To: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, nd Date: Thu, 23 Apr 2020 21:26:02 -0400 Message-Id: <20200424012605.2279679-2-rodrigosiqueiramelo@gmail.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200424012605.2279679-1-rodrigosiqueiramelo@gmail.com> References: <20200424012605.2279679-1-rodrigosiqueiramelo@gmail.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v8 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: Brian Starkey , Simon Ser , Simon Ser , 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. 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 | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_kms.h | 6 ++++++ 2 files changed, 63 insertions(+) diff --git a/lib/igt_kms.c b/lib/igt_kms.c index e9621e7e..67053d8b 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" }, {} }; @@ -1802,6 +1806,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; + } + } /** @@ -1885,6 +1897,8 @@ void igt_display_require(igt_display_t *display, int drm_fd) display->drm_fd = drm_fd; + drmSetClientCap(drm_fd, DRM_CLIENT_CAP_WRITEBACK_CONNECTORS, 1); + resources = drmModeGetResources(display->drm_fd); if (!resources) goto out; @@ -2193,6 +2207,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; + } } /** @@ -3255,6 +3274,11 @@ static void igt_atomic_prepare_connector_commit(igt_output_t *output, drmModeAto output->props[i], output->values[i])); } + + if (output->writeback_out_fence_fd != -1) { + close(output->writeback_out_fence_fd); + output->writeback_out_fence_fd = -1; + } } /* @@ -3377,6 +3401,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) { @@ -4049,6 +4083,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 adca59ac..aa082ef6 100644 --- a/lib/igt_kms.h +++ b/lib/igt_kms.h @@ -127,6 +127,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 }; @@ -366,6 +369,8 @@ typedef struct { bool use_override_mode; drmModeModeInfo override_mode; + int32_t writeback_out_fence_fd; + /* bitmask of changed properties */ uint64_t changed; @@ -425,6 +430,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 Fri Apr 24 01:26:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 11506913 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 E6A9B92C for ; Fri, 24 Apr 2020 01:26:58 +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 C53ED20728 for ; Fri, 24 Apr 2020 01:26:58 +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="tJ/H77Fv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C53ED20728 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 6175D6EA69; Fri, 24 Apr 2020 01:26:58 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by gabe.freedesktop.org (Postfix) with ESMTPS id 70C6D6EA68; Fri, 24 Apr 2020 01:26:57 +0000 (UTC) Received: by mail-qk1-x729.google.com with SMTP id j4so8637693qkc.11; Thu, 23 Apr 2020 18:26:57 -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=bdFsKK9ocSpGGiNxKCmNdcm6HxJR/nlHgHfbUqLhkH8=; b=tJ/H77FvFuBjvddHrsfrkPirU89vCRDbX9Hwse7tcminYxCe+xKiM8SKTpVeoh38kz eANMbgvkM7PKOsbtHG+9rzic36ssoMWQ4tQj9MrRGiGcoOUODZcLMgXNzDlKXVx32jC7 L11N3LXHzptPQkD0MCWeLm2R7ODHiVM8TjAHl8PNOGaNkooYXSpwvgLwmK2+35l+1pvz 06C5eoAKA/lk9XzYQmg8FFbhaP/SKxUDxa/7N66QQc++4c2wwUKd9kfvCLcHYs7/TKBb GXe/9vmseKH4Sk45Kq09Mm3lbpHrcZuTN6N+6ewbZT/Oj1+H36fhO0KUFs0J8cN+Ubkz Yp/g== 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=bdFsKK9ocSpGGiNxKCmNdcm6HxJR/nlHgHfbUqLhkH8=; b=FmkVTv4GyaBi3Dp1emvAFXeWRF5AcvwovWnQ3C0LC1bvril1JzSzR5MmInVgb5Dpiw DP3OUSKRn5pHAirvQP8Unc/G6qhNStXQbrHy+nw6JUfwHa7rM6ruzHgslInD2WMTRLmj nGUglIdJUoy4MpaRX4qBeEahMnPy1E0P2ZBAUn1WOC4HuP3mLgBkdfBoy6ODWZablZA0 KcZbZcEt9nGSTDmTbSRpD4DVAQWU6du49KIuZXPrV7ARNzD7ynI7vc7o7JDmDrB3nJPT S6UomiH77tNVVvxwXdpyxpNd8pSUDVKf77iJEL5qTHHxTBN/TL+Gv/0laQL+ewgjzBNK 35Yg== X-Gm-Message-State: AGi0PubjbUwUGA9CH6XOw25PERLO6rAFRa9RSrq3Ak6AORTZFXW0iTaG kziP/M+vpYAFvebY524tQVRyHaq5P0w= X-Google-Smtp-Source: APiQypJNLfqdFI6NwK1QwKZGOXKkcAFyBH/QXVtl9/+XuUTFDoKJ8vGL9SiemACOyeXnKuOZw6i4mg== X-Received: by 2002:a37:793:: with SMTP id 141mr6826415qkh.110.1587691616131; Thu, 23 Apr 2020 18:26:56 -0700 (PDT) Received: from atma2.hitronhub.home ([2607:fea8:56a0:11a1::2]) by smtp.gmail.com with ESMTPSA id c41sm2997184qta.96.2020.04.23.18.26.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2020 18:26:55 -0700 (PDT) From: Rodrigo Siqueira To: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, nd Date: Thu, 23 Apr 2020 21:26:03 -0400 Message-Id: <20200424012605.2279679-3-rodrigosiqueiramelo@gmail.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200424012605.2279679-1-rodrigosiqueiramelo@gmail.com> References: <20200424012605.2279679-1-rodrigosiqueiramelo@gmail.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v8 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 , 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 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 32cbbf4f..3e7afa4d 100644 --- a/tests/Makefile.sources +++ b/tests/Makefile.sources @@ -86,6 +86,7 @@ TESTS_progs = \ kms_universal_plane \ kms_vblank \ kms_vrr \ + kms_writeback \ meta_test \ perf \ perf_pmu \ diff --git a/tests/kms_writeback.c b/tests/kms_writeback.c new file mode 100644 index 00000000..e08eb611 --- /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; + + /* Valid output buffer */ + ret = do_writeback_test(output, valid_fb->fb_id, NULL, false); + igt_assert(ret == 0); + + /* 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); +} + +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 0bdcfbe4..1523668b 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -70,6 +70,7 @@ test_progs = [ 'kms_universal_plane', 'kms_vblank', 'kms_vrr', + 'kms_writeback', 'meta_test', 'panfrost_get_param', 'panfrost_gem_new', From patchwork Fri Apr 24 01:26:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 11506917 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 4D1B714DD for ; Fri, 24 Apr 2020 01:27:06 +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 2C3202074F for ; Fri, 24 Apr 2020 01:27:06 +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="c3x/SOux" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2C3202074F 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 B0B726EA6D; Fri, 24 Apr 2020 01:27:05 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6D5ED6EA6C; Fri, 24 Apr 2020 01:26:58 +0000 (UTC) Received: by mail-qt1-x842.google.com with SMTP id s30so6719307qth.2; Thu, 23 Apr 2020 18:26:58 -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=zwl3Lg29PG5SABcqM6mcSNiauB7jnBtogFQhsKqMwtc=; b=c3x/SOux3SVLhcm+0xQDPIHVbSKd65k2bfTOO2i6zcZF/CpqUvSjWWQwfs9xi2PNQX J9qP+tf+kn2NT19Ll1TaNdGWD+Nw7tshtRLC7VJ0h3zppkO8wApS07Fy/1aII+FFQLjm qU3u8Mg4FUKqEhllbWiExyRTGfatQAceB4CQfKDaico/0IJkF+3iDc5bPWdCvg19IJH5 sMzrpHFDhbdXEMj9Gcje2H3Az1hiFaxkDsTPtW62pEuMc/c2i++PEOrUPtEPNJNU5szH PCTzgqD6a3bXMMFnvPU98LWt1rhM5gYHbZXMAkWcjG/Y3QNdEcYJk6I7LfY5jCOC7P2k jjJg== 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=zwl3Lg29PG5SABcqM6mcSNiauB7jnBtogFQhsKqMwtc=; b=XE8ev7kRZcWtfYakXJHT2q5gHV+TWf31dSlsQs8Q/BcwPIQKkANLqtU5NY3e5+37sr hdN2TOGn52N+mWH60B0+Mj+PC7VOOh85TKlm3+frdY+THKZsLjqM69PGBzIjspKPVSaU 411hpcSEDkqsZPtcBDFSvASp2TIplsbMj/kAKfAqVMKJB25VNgA9Za4AwR6+0027DfE0 ZdHyRSioCK3E5PnTRXzhmYOMrDgsCc5l+PhNzprWT2VRfyYQJ+Ec7a83f05ekeuyx/a5 noO/IjMRDLSclovNUUbreoHSE7FgCu9AEMUjOk+L2Q/7iT++n2tzf++Gs2242z5NgG9h yj5g== X-Gm-Message-State: AGi0PuZTPf7OQzi5J2H8uSinNhohVtyvht/awxZ/zyiW5tdnKBdeQeGb IHmQ79KdVGviWZjP4YztKTgXt2+iJn0= X-Google-Smtp-Source: APiQypJZ62VSa2pRALtQMDsjYB2n4NGRa3VY82W8wXE4h+ZJAxyvkul/AxJCE1GqLKrmU1SS41graw== X-Received: by 2002:ac8:2224:: with SMTP id o33mr731291qto.45.1587691617320; Thu, 23 Apr 2020 18:26:57 -0700 (PDT) Received: from atma2.hitronhub.home ([2607:fea8:56a0:11a1::2]) by smtp.gmail.com with ESMTPSA id c41sm2997184qta.96.2020.04.23.18.26.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2020 18:26:56 -0700 (PDT) From: Rodrigo Siqueira To: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, nd Date: Thu, 23 Apr 2020 21:26:04 -0400 Message-Id: <20200424012605.2279679-4-rodrigosiqueiramelo@gmail.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200424012605.2279679-1-rodrigosiqueiramelo@gmail.com> References: <20200424012605.2279679-1-rodrigosiqueiramelo@gmail.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v8 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: Brian Starkey , Simon Ser , Simon Ser , 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 5ed586e7..562206b1 100644 --- a/lib/igt_fb.c +++ b/lib/igt_fb.c @@ -3785,6 +3785,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 587f7a44..4221d8b9 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 Fri Apr 24 01:26:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 11506915 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 95AB714DD for ; Fri, 24 Apr 2020 01:27:02 +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 73FE120715 for ; Fri, 24 Apr 2020 01:27:02 +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="KLSBJ1Rc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 73FE120715 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 1A0DC6EA70; Fri, 24 Apr 2020 01:27:02 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by gabe.freedesktop.org (Postfix) with ESMTPS id D06656EA6C; Fri, 24 Apr 2020 01:26:59 +0000 (UTC) Received: by mail-qt1-x841.google.com with SMTP id k12so6716576qtm.4; Thu, 23 Apr 2020 18:26:59 -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=idYIPddSRYaX7ZUu4Ro7ePoHBfw2dwCqkLfCNbKbI9g=; b=KLSBJ1RcuLAErWeCUVx/PtG74zK1FpuhZOeQc+bMY8UiT+4ci/rfCLAfpEbXjQdEEQ zYuRSPdVdKZG9dXdkvVJCsJiid/D2phpFUTtJW3xN7/S9vKGR7aC/joXE6bPoZLjpGOL 0RjC42SynXG9mbQzmSNF2QjuZ2DMM6+47mJ6IDcZ7t8BF531IQC3mDp9gAOYF3vEkYRK 5QwyLluLJkYt9JQf4FWw6Wj4Tk9alpmCR2q7SJeYyJzoCoVHavMizP71KaUw+cDQ1dwX l3ycDWOjyrJx3T1/L3d4BdasVIqpk1qmVr45k/roveGrIQ2o6CsDJP0bca8VVJE4QHfw cXiA== 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=idYIPddSRYaX7ZUu4Ro7ePoHBfw2dwCqkLfCNbKbI9g=; b=HJ+AykY1+R7Ph58yS7FLlybo7Zuz6oSEJ8Ym96liPe1XTw7aRb5szs8WTKzBMOjf5l yxkEsIuyPcvjMpoAX+yXx8odX7z2yfdlD8GyRLzDxugKAiRaRibUjJGAouFMm58ZTURh A8nMi+bmt35HCYQoZtOOnQ0iyhGhnRB3iABwDh9raazpWes2G4cizmHKcNxdLs+Fn4aV MO2b0WvYAdofRQYT/YH7rjvUKBVPjC4xjqasYWzUjCFJvPf9uM3xOSZdPIfmHYserXdh phrVJJSRNULLrkGX3R6z+L1NP76AvUjIPiFibzbpU2pHVrXsy8VjxoKdB3TWLjHuos2x gsGw== X-Gm-Message-State: AGi0PuZwI9Tpcxeg7ZcmBcJsrPGu3YqgCJVb8/9AU3pstgg/tR3pRF8p 4wA3cUx9OKz4NlTLdEpJAZO4HBl6FDQ= X-Google-Smtp-Source: APiQypIxx0sxHzVYja6jIc8Fw+ApXOd+O2RcQWcbA+0/owgVEoh3YCBPXxmlR3D5GCF1ks/MN3vRHA== X-Received: by 2002:ac8:5304:: with SMTP id t4mr7089706qtn.250.1587691618468; Thu, 23 Apr 2020 18:26:58 -0700 (PDT) Received: from atma2.hitronhub.home ([2607:fea8:56a0:11a1::2]) by smtp.gmail.com with ESMTPSA id c41sm2997184qta.96.2020.04.23.18.26.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2020 18:26:58 -0700 (PDT) From: Rodrigo Siqueira To: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, nd Date: Thu, 23 Apr 2020 21:26:05 -0400 Message-Id: <20200424012605.2279679-5-rodrigosiqueiramelo@gmail.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200424012605.2279679-1-rodrigosiqueiramelo@gmail.com> References: <20200424012605.2279679-1-rodrigosiqueiramelo@gmail.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v8 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 , 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 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 | 127 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/tests/kms_writeback.c b/tests/kms_writeback.c index e08eb611..bba1fb01 100644 --- a/tests/kms_writeback.c +++ b/tests/kms_writeback.c @@ -30,6 +30,7 @@ #include "igt.h" #include "igt_core.h" #include "igt_fb.h" +#include "sw_sync.h" static drmModePropertyBlobRes *get_writeback_formats_blob(igt_output_t *output) { @@ -217,6 +218,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 +422,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);