From patchwork Tue Oct 22 00:58:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 11203351 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 CE0E7139A for ; Tue, 22 Oct 2019 00:58:38 +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 B5CF320B7C for ; Tue, 22 Oct 2019 00:58:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B5CF320B7C 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 188246E2E4; Tue, 22 Oct 2019 00:58:37 +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 9735C6E08A; Tue, 22 Oct 2019 00:58:30 +0000 (UTC) Received: by mail-qt1-x842.google.com with SMTP id g50so10055534qtb.4; Mon, 21 Oct 2019 17:58:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=8DMGS7Js4evx3+TVdeBNp0RhSu1g7xkVMugD47v/Zx0=; b=GYqZRqoDtVTQi8Wx03mwe7IpIsNcLa/0/yGbpmY7sKjg1JC7Ua9dgS3yB5LqA3tRJq TKmY/g0xT/ndr0WXph61f5wC2bOkhMGpdlR9Ei6SCLdJufK7rdhc6O1lAcNjbEsaXJSR w6YkD4h9+QqiXusVNhsbO4lNGUlFZMBtYuNlVIdeuAAlppEAqy6uaIuKzVlqBtomPOJ3 Kc8ytJUIcWJKcaxn36URLM+Gjy9gKWO2xDxt5OD6mFMVtsJBpSAt8HKglgfveRhY8UjZ +zM/WdVujknMC5o3+HccXx3Y1OsV0G/f3/gUA28z1+mEHFhOpKqsQgtWjksJg1eW/yWN XhEw== X-Gm-Message-State: APjAAAULRISRfbfjPE116rcaNn7FGNrlOtoiGCKWokbYoEM4799QBx9E GnrVkqwEYi+ocPMJy2rbUU4= X-Google-Smtp-Source: APXvYqwxzdDvlCVy9oLV5FKt5x4DoiLYNnsUJWISGlEJf/JBqJn/gwtFM21n8LE1FDf5D+AyhY27Jg== X-Received: by 2002:ac8:2ce5:: with SMTP id 34mr269251qtx.308.1571705909429; Mon, 21 Oct 2019 17:58:29 -0700 (PDT) Received: from smtp.gmail.com (toroon12-3096782342.sdsl.bell.ca. [184.149.38.6]) by smtp.gmail.com with ESMTPSA id p4sm9577017qkf.112.2019.10.21.17.58.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 17:58:29 -0700 (PDT) From: Brian Starkey X-Google-Original-From: Brian Starkey Date: Mon, 21 Oct 2019 21:58:27 -0300 To: Simon Ser , Brian Starkey , Liviu Dudau , Petri Latvala , Arkadiusz Hiler , Daniel Vetter Message-ID: <20191022005820.4vniwm6wqw3ofk2p@smtp.gmail.com> MIME-Version: 1.0 User-Agent: NeoMutt/20180716 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=8DMGS7Js4evx3+TVdeBNp0RhSu1g7xkVMugD47v/Zx0=; b=kmBB4uL9V1zhSupQNliN7+OftdcTisXh8KQQ1ouviNCaaYpGGM2BOjTGo1qexfTP0/ 9m2TE6ngrC1Onda0+Q3DVLU6M9XtjZ9f0Hx6Txl/s0QGoRG64J5xKFzcNH+AZykAHbmi +jUvAHwDzfi8sxPjWR0dxQhqXI1bpdA2pJNfwJaVpxhioV59yW+2oXvWKxgrElrCwYcZ SeqveawIrL9k0UZOV4flpXWhl5fIU1n93e7b6DEmVvBK5PlpAM87ZuBloW2JcSESPgBz WE5/lQohX7kGIDBEAGUCSd6Asgrng5Z00LeNHp9TAn++sDv5PqVm2pDXXpCN+DYrWf39 yOdw== Subject: [Intel-gfx] [PATCH v7 i-g-t 1/4] lib/igt_kms: Add writeback support X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, nd Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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 Signed-off-by: Rodrigo Siqueira Reviewed-by: Simon Ser --- lib/igt_kms.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_kms.h | 6 ++++++ 2 files changed, 65 insertions(+) diff --git a/lib/igt_kms.c b/lib/igt_kms.c index e9b80b9b..2d7eabc6 100644 --- a/lib/igt_kms.c +++ b/lib/igt_kms.c @@ -412,6 +412,9 @@ const char * const igt_connector_prop_names[IGT_NUM_CONNECTOR_PROPS] = { [IGT_CONNECTOR_VRR_CAPABLE] = "vrr_capable", [IGT_CONNECTOR_HDCP_CONTENT_TYPE] = "HDCP Content Type", [IGT_CONNECTOR_LINK_STATUS] = "link-status", + [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", }; /* @@ -644,6 +647,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" }, {} }; @@ -1853,6 +1857,14 @@ static void igt_output_reset(igt_output_t *output) if (igt_output_has_prop(output, IGT_CONNECTOR_CONTENT_PROTECTION)) igt_output_set_prop_enum(output, IGT_CONNECTOR_CONTENT_PROTECTION, "Undesired"); + + 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; + } } /** @@ -1866,6 +1878,8 @@ static void igt_output_reset(igt_output_t *output) * - %IGT_CONNECTOR_CRTC_ID * - %IGT_CONNECTOR_BROADCAST_RGB (if applicable) * %IGT_CONNECTOR_CONTENT_PROTECTION (if applicable) + * - %IGT_CONNECTOR_WRITEBACK_FB_ID + * - %IGT_CONNECTOR_WRITEBACK_OUT_FENCE_PTR * - igt_output_override_mode() to default. * * For pipes: @@ -1935,6 +1949,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; @@ -2228,6 +2244,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; + } } /** @@ -3290,6 +3311,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; + } } /* @@ -3412,6 +3438,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) { @@ -4084,6 +4120,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 7193f9a5..9bf70acf 100644 --- a/lib/igt_kms.h +++ b/lib/igt_kms.h @@ -125,6 +125,9 @@ enum igt_atomic_connector_properties { IGT_CONNECTOR_VRR_CAPABLE, IGT_CONNECTOR_HDCP_CONTENT_TYPE, IGT_CONNECTOR_LINK_STATUS, + IGT_CONNECTOR_WRITEBACK_PIXEL_FORMATS, + IGT_CONNECTOR_WRITEBACK_FB_ID, + IGT_CONNECTOR_WRITEBACK_OUT_FENCE_PTR, IGT_NUM_CONNECTOR_PROPS }; @@ -365,6 +368,8 @@ typedef struct { bool use_override_mode; drmModeModeInfo override_mode; + int32_t writeback_out_fence_fd; + /* bitmask of changed properties */ uint64_t changed; @@ -423,6 +428,7 @@ igt_plane_t *igt_output_get_plane_type_index(igt_output_t *output, igt_output_t *igt_output_from_connector(igt_display_t *display, drmModeConnector *connector); 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 Tue Oct 22 00:59:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 11203353 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 59021112B for ; Tue, 22 Oct 2019 00:59:23 +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 4086320B7C for ; Tue, 22 Oct 2019 00:59:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4086320B7C 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 AE9026E2E9; Tue, 22 Oct 2019 00:59:22 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by gabe.freedesktop.org (Postfix) with ESMTPS id F33096E2E8; Tue, 22 Oct 2019 00:59:20 +0000 (UTC) Received: by mail-qk1-x744.google.com with SMTP id u184so14710520qkd.4; Mon, 21 Oct 2019 17:59:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=Jg95iJtxIZa7HU3v5x1RmN327X39QOODMIohn40TUIE=; b=NElHb5phCG6O+Sm6Dh9BHYEecTrnxw0mtW0F+x1QvLXx/w1loRB3RG4XyD/gCefIBK bf9lmQm97vIeWGlfs0vPM/nuGvHncpkBzC/h/61K0qM4MUW0hbuzdg777anYNphrYmr9 jm6/eCquQj1FNGXcXSYnoI95LM0lORQytL2m2Sb1Jiearr1dnhGQ/Fv4xieJpNxxhv9J DzAo146IuVf9Zc8NKCGnPNvcAbcEuIxTniSU0eCpYTBvgmdy496QyNu2lZRsZjupvhel HY9ZUS58kFKdwLG9/21BRp5JyggH9nIPCzT9e95b4+kGrNPKsmnPleh/c4IiGGMcIiNV sb+g== X-Gm-Message-State: APjAAAW26xv5KsR9YLeSnWAivCEqPMy1ma/mT+Pj99QZUj7dWthj/KQN 4tVQiMQb/jHDRq1806gXpLU= X-Google-Smtp-Source: APXvYqz5c23GYItohCnt25aZBk2khTcNou3BdigyxHNkFdegQZA4JF7gLJgtKU9F6RtyPo1kQFjOrA== X-Received: by 2002:a37:aa07:: with SMTP id t7mr653574qke.414.1571705959728; Mon, 21 Oct 2019 17:59:19 -0700 (PDT) Received: from smtp.gmail.com (toroon12-3096782342.sdsl.bell.ca. [184.149.38.6]) by smtp.gmail.com with ESMTPSA id n17sm9703117qke.103.2019.10.21.17.59.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 17:59:19 -0700 (PDT) From: Brian Starkey X-Google-Original-From: Brian Starkey Date: Mon, 21 Oct 2019 21:59:17 -0300 To: Simon Ser , Brian Starkey , Liviu Dudau , Petri Latvala , Arkadiusz Hiler , Daniel Vetter Message-ID: <20191022005910.siuiwfikmr76qpg3@smtp.gmail.com> MIME-Version: 1.0 User-Agent: NeoMutt/20180716 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=Jg95iJtxIZa7HU3v5x1RmN327X39QOODMIohn40TUIE=; b=AWebNrzdkYOP/ntW0OvEFU7h96H7ThDsKHRm2sRcFP5F8l0exqhM5Zr2CP76A4CtiO H4yOPllBTM6xPg3a/d27ggzC9xsRKLojO/bEjTWpvjbW7iiYMiRo9YZ7pQq7MHBKG37E iAvL6vJSY0SH8kWH4RfrX95yZrXRJahvUwQ+zFscDOKV240Q0+ugdA6muPToN90VLv7J fdE3XJdYb1lni08uteweJxQ8e/dLKnAdX2ZC9BciPiemWf6mgU9zsnC6pe7mW6CuPPU4 UBWOQsyDX7cx9pLbj/f+4nHMyQA1BZO/BDEVAQelBo9oFfW/taw2haRtcRg64NxS6UUx hFFw== Subject: [Intel-gfx] [PATCH v7 i-g-t 2/4] kms_writeback: Add initial writeback tests X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, nd Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Add tests for the WRITEBACK_PIXEL_FORMATS, WRITEBACK_OUT_FENCE_PTR and WRITEBACK_FB_ID properties on writeback connectors, ensuring their behaviour is correct. V6: Simon Ser - Add igt documentation with igt_describe and IGT_TEST_DESCRIPTION - Drop kmstest_force_connector with FORCE_CONNECTOR_ON in kms_writeback_get_output since userspace won't do this operation - Add an igt_debug statement in case we don't use writeback output - Drop flags parameter from do_writeback_test - Remove do_writeback_test "igt_assert(*out_fence_ptr == -1)" after igt_display_try_commit_atomic - Rename writeback_fb_id to writeback_test_fb - Rework writeback_test_fb for checking buffer - Move some tests from invalid_out_fence to writeback_test_fb - Replace ret != 0 checking by ret == -EINVAL after invoke do_writeback_test - Assert on igt_output_get_plane_type() - Replace igt_fb_mod_to_tiling to DRM_FORMAT_MOD_LINEAR - Rename tests - Replace int ret by unsigned int fd_id when calling igt_create_fb Signed-off-by: Brian Starkey [rebased and updated do_writeback_test() function to address feedback] Signed-off-by: Liviu Dudau [rebased and updated the patch to address feedback] Signed-off-by: Rodrigo Siqueira --- tests/Makefile.sources | 1 + tests/kms_writeback.c | 290 +++++++++++++++++++++++++++++++++++++++++ tests/meson.build | 1 + 3 files changed, 292 insertions(+) create mode 100644 tests/kms_writeback.c diff --git a/tests/Makefile.sources b/tests/Makefile.sources index 343be050..331270ae 100644 --- a/tests/Makefile.sources +++ b/tests/Makefile.sources @@ -81,6 +81,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..a373ec4d --- /dev/null +++ b/tests/kms_writeback.c @@ -0,0 +1,290 @@ +/* + * (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" + +IGT_TEST_DESCRIPTION("Exercise writeback feature."); + +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; + int width, height, ret; + unsigned int fb_id; + 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; + + fb_id = igt_create_fb(display->drm_fd, width, height, DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_LINEAR, &input_fb); + igt_assert(fb_id >= 0); + + fb_id = igt_create_fb(display->drm_fd, width, height, writeback_format, DRM_FORMAT_MOD_LINEAR, &output_fb); + igt_assert(fb_id >= 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; + } + } + + /* 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); + } + + igt_debug("The device does not enable writeback\n"); + + 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; + int flags = DRM_MODE_ATOMIC_ALLOW_MODESET; + 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, (uint64_t)out_fence_ptr); + + if (ptr_valid) + *out_fence_ptr = 0; + + ret = igt_display_try_commit_atomic(display, flags, NULL); + + /* WRITEBACK_FB_ID must always read as zero */ + check_writeback_fb_id(output); + + return ret; +} + +static void invalid_output_fence(igt_output_t *output, igt_fb_t *valid_fb) +{ + int ret; + + ret = do_writeback_test(output, valid_fb->fb_id, (int32_t *)0x8, false); + igt_assert(ret == -EFAULT); +} + +static void writeback_test_fb(igt_output_t *output, igt_fb_t *valid_fb, igt_fb_t *invalid_fb) +{ + + int ret; + int32_t out_fence; + + /* 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); + + /* No output buffer, but the WRITEBACK_OUT_FENCE_PTR set. */ + ret = do_writeback_test(output, 0, &out_fence, true); + igt_assert(ret == -EINVAL); + + /* Invalid output buffer. */ + ret = do_writeback_test(output, invalid_fb->fb_id, &out_fence, true); + igt_assert(ret == -EINVAL); +} + +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 writeback formats"); + igt_subtest("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]); + } + + igt_describe("This test validates if the writeback core identify an " + "invalid output"); + igt_subtest("invalid-output-fb") { + invalid_output_fence(output, &input_fb); + } + + igt_describe("Test writeback with valid and invalid framebuffer"); + igt_subtest("writeback-test-framebuffer") { + igt_fb_t output_fb, invalid_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); + + fb_id = igt_create_fb(display.drm_fd, mode.hdisplay / 2, + mode.vdisplay / 2, + DRM_FORMAT_XRGB8888, + DRM_FORMAT_MOD_LINEAR, + &invalid_fb); + igt_require(fb_id > 0); + + writeback_test_fb(output, &output_fb, &invalid_fb); + + igt_remove_fb(display.drm_fd, &output_fb); + igt_remove_fb(display.drm_fd, &invalid_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 7e3f9e0a..af601725 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -66,6 +66,7 @@ test_progs = [ 'kms_universal_plane', 'kms_vblank', 'kms_vrr', + 'kms_writeback', 'meta_test', 'panfrost_get_param', 'panfrost_gem_new', From patchwork Tue Oct 22 01:00:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 11203357 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 E984B1895 for ; Tue, 22 Oct 2019 01:00:04 +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 D029620B7C for ; Tue, 22 Oct 2019 01:00:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D029620B7C 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 1B0126E2E8; Tue, 22 Oct 2019 01:00:04 +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 0C0DE6E2E8; Tue, 22 Oct 2019 01:00:03 +0000 (UTC) Received: by mail-qk1-x742.google.com with SMTP id y189so14708804qkc.3; Mon, 21 Oct 2019 18:00:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=F2nIv1H2HDYLyeNUtb846D2apA8DKhE1syXPDRt8JTs=; b=mDm3UXAPyW6nV/X9BWgmtgjMRtZjrhO+kLE/gV7YCGur/AinB3dPuBwYL1MqN8IpuR aSviaReEM1GB/w4xYQtJpQbsb876sGur9fnFft4r8tuUk9jIi7f1mgiM7IEZkqSdxeiO NRhMJgSK3B7QJpPdj78eObkqxblwRunBEDMaXiIhnGtx5Ye/hf1WqI/KpjT43PN29UhC uO0qfKUNAvyQQa7143pSF8ztfA5rgNG/Wm/nslAhY931ZhFQxejFzmFo2e8i3cfczC0N jtkwyWOmx9ndUMuWz1jITN23vbrejCiALqrmbZERcdgTXOzPFIsYGaiCfzdpJJ6o9lPS 3DfQ== X-Gm-Message-State: APjAAAXk6pbvLFeIkl6gFll1ztTwlYDVUuJ/cOGq6vAZbjLcXA37s5G3 q0ng4TU45xfyOYooQleEhE0= X-Google-Smtp-Source: APXvYqynSJ6aiV3vbTPMb5R5/TtaSf4rVmdzu8WD15C4rhDllxaJ7DRdgxYcEkIKuDaOi2PGb4m2sA== X-Received: by 2002:a05:620a:204b:: with SMTP id d11mr652317qka.379.1571706001814; Mon, 21 Oct 2019 18:00:01 -0700 (PDT) Received: from smtp.gmail.com (toroon12-3096782342.sdsl.bell.ca. [184.149.38.6]) by smtp.gmail.com with ESMTPSA id f35sm487257qtd.35.2019.10.21.18.00.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 18:00:01 -0700 (PDT) From: Brian Starkey X-Google-Original-From: Brian Starkey Date: Mon, 21 Oct 2019 22:00:00 -0300 To: Simon Ser , Brian Starkey , Liviu Dudau , Petri Latvala , Arkadiusz Hiler , Daniel Vetter Message-ID: <20191022005952.tkdtftzbxk4b2lzk@smtp.gmail.com> MIME-Version: 1.0 User-Agent: NeoMutt/20180716 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=F2nIv1H2HDYLyeNUtb846D2apA8DKhE1syXPDRt8JTs=; b=NPTFELfecq+OwZotJzjI1MQjmaIh4d+x54bSf54bOVA4o6wlqrUEQM9VhQ71j+AxAg 2xpW1449dN/HO0SvtIx6uk0Hd5jVfz0iegK1VXn5S4v6/rgZ8StqMIqTa6SZcJrzUeQ5 CXSXGKOiQSNAi60NUmVsc4zYV04EraMA4ClFMM3HgroXt4pDFTaVhk6CjvERq3VjaPaE s6IP2ldnfO2yIB8WfMs9q2rLuGFSIcW1bNpuAMoihuq47E9L5Of3ei5+yXPSGwC7q7T2 YwVLi5Cn+oYbgoPLzOWGqQgeEVNkskUbJAZAVsByIqFhAz+Rb6iAbmmmiNJ2yhKFq/v8 txOg== Subject: [Intel-gfx] [PATCH v7 i-g-t 3/4] lib: Add function to hash a framebuffer X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, nd Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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). V6: Simon Sir - Replace #define by plain uint32_t variables - Return -EINVAL in case fb->num_planes != 1 - Directly assign the mmap result to ptr - No need to copy the whole stride, just copy fb->width * cpp since we're only going to read that 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 the patch to address feedback] Signed-off-by: Rodrigo Siqueira Reviewed-by: Simon Ser --- lib/igt_fb.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_fb.h | 2 ++ 2 files changed, 70 insertions(+) diff --git a/lib/igt_fb.c b/lib/igt_fb.c index 6b674c1b..64d52634 100644 --- a/lib/igt_fb.c +++ b/lib/igt_fb.c @@ -3491,6 +3491,74 @@ bool igt_fb_supported_format(uint32_t drm_format) return false; } +/* + * 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_crc(struct igt_fb *fb, igt_crc_t *crc) +{ + uint32_t FNV1a_OFFSET_BIAS = 2166136261; + 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; + + if (fb->is_dumb) + ptr = kmstest_dumb_map_buffer(fb->fd, fb->gem_handle, fb->size, + PROT_READ); + else + ptr = gem_mmap__gtt(fb->fd, fb->gem_handle, fb->size, + PROT_READ); + + /* + * 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); + munmap(map, fb->size); + + return 0; +#undef FNV1a_OFFSET_BIAS +#undef FNV1a_PRIME +} + /** * igt_format_is_yuv: * @drm_format: drm fourcc diff --git a/lib/igt_fb.h b/lib/igt_fb.h index 69132b41..d2394638 100644 --- a/lib/igt_fb.h +++ b/lib/igt_fb.h @@ -202,5 +202,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_crc(struct igt_fb *fb, igt_crc_t *crc); + #endif /* __IGT_FB_H__ */ From patchwork Tue Oct 22 01:00:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 11203359 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 3559B1895 for ; Tue, 22 Oct 2019 01:00:44 +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 1C98620B7C for ; Tue, 22 Oct 2019 01:00:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1C98620B7C 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 70CA76E2ED; Tue, 22 Oct 2019 01:00:43 +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 5BE876E2EC; Tue, 22 Oct 2019 01:00:42 +0000 (UTC) Received: by mail-qt1-x842.google.com with SMTP id d17so9618199qto.3; Mon, 21 Oct 2019 18:00:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=hPZfHaMMDlb1wqPqvBr8Gx2HzSXsopXZIOCoxineNIc=; b=K0Gm0j+hHbuwEV35Xil/3loa05qv5HXkVG2xqhf9AvJbDK4pG4jXORs13OXEEaEMjj BSnIMv4FSzgLmMbdHoSWf3FErbg/GiSM7m2LmwWuqYcCe4DmK2CYxLtc0QF1mv3PMKdA i9Iv6y0ITa93ydzsRFT7YDyWmjW8tVY6jP0LWHT//k+00BM4ofw1ftR19Gu4Q+NYm73F I/KI23c5/qkWzykwpffHYJ0YY41fBlG0LI/sRiWogXiT5+s8XZnDq2Y/utc43jVNVugk AuOOZp57bYALE1KfjBIY946AHac7moPa9P06GCp+GjFGjC7n9dG0QILcSdG8tL06S2Yo izcg== X-Gm-Message-State: APjAAAX6eABKAnd1BuV/ON04LQZSEXHf196uFcz1UxRVXENXcMaPFpH7 hT3rSBoKhOgH0lMdnrojddo= X-Google-Smtp-Source: APXvYqxJxfIoUqxBFVukWHpSkYW2/n52tQXQkXozHb1l2hdfpgiF6w0uZvv7wDq60XoLwh90N7X+MA== X-Received: by 2002:a0c:d2b4:: with SMTP id q49mr562940qvh.135.1571706041277; Mon, 21 Oct 2019 18:00:41 -0700 (PDT) Received: from smtp.gmail.com (toroon12-3096782342.sdsl.bell.ca. [184.149.38.6]) by smtp.gmail.com with ESMTPSA id h23sm8209043qkk.128.2019.10.21.18.00.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 18:00:40 -0700 (PDT) From: Brian Starkey X-Google-Original-From: Brian Starkey Date: Mon, 21 Oct 2019 22:00:39 -0300 To: Simon Ser , Brian Starkey , Liviu Dudau , Petri Latvala , Arkadiusz Hiler , Daniel Vetter Message-ID: <20191022010032.pgqop52v4gz5omlc@smtp.gmail.com> MIME-Version: 1.0 User-Agent: NeoMutt/20180716 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=hPZfHaMMDlb1wqPqvBr8Gx2HzSXsopXZIOCoxineNIc=; b=qPBxSY+8l19D9UfmcLnePlMiCZJJu+/reFOTJekk26sVVtleqlLkEwxjg72hzoFLbI ReVGPaFGycslI6SmTkCJNwPVXPjaJb6jUAeBPpyJbF1NCbTqh69Uo/nlF4XokSAvyNVy q+QCC9qJrcpvXC5URiIp7NvNrbR+PPDeixQ1DlL29L+G5favKb7llxZ/yTjl0EPpodPG s9XDP5xd5bzU/l3nDaNJ+SmLXsGzYHXcMBVTYkaKj6ix0/bYKJ304DllmHKtu2goDX3k uOs9oWMC7ikAxsjgFnGarjkMR/ckVxVyC/nUoC2loESuyjG8tsHWNQap9JL4CyovoqT0 74Tg== Subject: [Intel-gfx] [PATCH v7 i-g-t 4/4] kms_writeback: Add writeback-check-output X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, nd Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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. V6: Simon Ser - Add igt documentation with igt_describe - Replace int ret by unsigned int fd_id when calling igt_create_fb - Add a descriptive error message if sync_fence_wait fail - Replace color_idx variable by i - Use in_fb instead of out_fb for getting the expected CRC - Drop unnecessary parentheses - Replace igt_fb_mod_to_tiling to DRM_FORMAT_MOD_LINEAR Signed-off-by: Brian Starkey [rebased and updated the patch to address feedback] Signed-off-by: Rodrigo Siqueira --- tests/kms_writeback.c | 123 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/tests/kms_writeback.c b/tests/kms_writeback.c index a373ec4d..068595b9 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" IGT_TEST_DESCRIPTION("Exercise writeback feature."); @@ -196,6 +197,115 @@ static void writeback_test_fb(igt_output_t *output, igt_fb_t *valid_fb, igt_fb_t igt_assert(ret == -EINVAL); } +static void fill_fb(igt_fb_t *fb, double color[3]) +{ + cairo_t *cr = igt_get_cairo_ctx(fb->fd, fb); + igt_assert(cr); + + igt_paint_color(cr, 0, 0, fb->width, fb->height, + color[0], color[1], color[2]); +} + +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; + double in_fb_colors[2][3] = { + { 1.0, 0.0, 0.0 }, + { 0.0, 1.0, 0.0 }, + }; + double clear_color[3] = { 1.0, 1.0, 1.0 }; + 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_crc(in_fb, &out_expected); + + fill_fb(out_fbs[i], clear_color); + if (i == 0) + igt_fb_get_crc(out_fbs[i], &cleared_crc); + igt_fb_get_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_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_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, + DRM_FORMAT_MOD_LINEAR, &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; @@ -283,6 +393,19 @@ igt_main igt_remove_fb(display.drm_fd, &invalid_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, + DRM_FORMAT_MOD_LINEAR, &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);