From patchwork Tue Nov 28 10:24:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 170682 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3813084vqx; Tue, 28 Nov 2023 02:24:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFikJzDhP2oPXfIM5txBdFUmI7aODMUXAVc6UFfo7rQcpfyuP9Vhp5jzEHcp38h7b3W11mx X-Received: by 2002:a05:6a21:192:b0:18b:5b7e:6b9 with SMTP id le18-20020a056a21019200b0018b5b7e06b9mr21691381pzb.2.1701167095955; Tue, 28 Nov 2023 02:24:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701167095; cv=none; d=google.com; s=arc-20160816; b=TmifMEjbrdHw5S2ZghUcMgP25fOrr1SMubA07FupiQVwQnjb0eX8D+V3iGCoa3x2JD 573PKnhDPwhEanIreJdDs92wkdMKJmz7lsy2bd3I/GiAiG0sSzurqRd/8XcwrW2PeqnQ ZeXjlJw3FeBq+eTFnw2BwhzAxlHXiQhIMvJPgXO/JiP1bVeVVH/5lF9NAIEXTMY1oiET Xf8xwpjmZVM1R5Wqf2O7w99/hsYSvCR3LgtEmNxpQkKNL3RhLXD1TN9p42J/vFHKkPky EIO+CZimwxulIF91Ma5iVH/9xWDvpienvfJGMB4gavq9cFgGEfA9d86O2cGRHA+8D0zh MUbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=eji+5YOPBjaKMuQtEEwRrNdzFLTSnRXdSFJmRraRvmI=; fh=e6/uyeFf2k7v8JUtB6fPyaAS5iN3eSA1hjtg35V2Rzw=; b=1E9sM+doS5++I5bUlDYTIcYnamrcyZsDphDwlDbbt3gaUtBNVpXonbP31lp+LAyVQp vU8gGlDyih1/DktwJMJsx4RRMy/AdACBweC9eTyLVtc/auRO+AiCS4ggQ6Hlt+Hy1Pgb HRqHPbvMS7EJYVbYEzf1KVn1n8zVkgijNRhGD8dygF0m5+dytW/SAI3ngEQkdOZro+gy oCXGo2A/tTCIQbXGc89qVmRANDRJ9QH04enDqn0xK+RSJrATAR3m5aGuqJPUXa+PsfkU 0ev/ri/4QsMTHxdRx/cS70BjiHXqnCZhJYWUYrU4DQGVOU+qzck7ht/ClbvWNYcc3y0e iUiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Y/JUpw11"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id ix21-20020a170902f81500b001cf5d324819si10774166plb.154.2023.11.28.02.24.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 02:24:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Y/JUpw11"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id DDC8380713D3; Tue, 28 Nov 2023 02:24:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234853AbjK1KYp (ORCPT + 99 others); Tue, 28 Nov 2023 05:24:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344155AbjK1KYe (ORCPT ); Tue, 28 Nov 2023 05:24:34 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE544D72 for ; Tue, 28 Nov 2023 02:24:33 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 417F5C433C7; Tue, 28 Nov 2023 10:24:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701167073; bh=G8HSSrdcKPJIlhvVxRehBG//p41ZlqdTJZFDrSgI9fQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Y/JUpw11OJsavB6K3RgNTVHwOySrfyn9/bRfQp7OUYl2Tfm5pYxeSuXnYIQT1Mc/C RKsn4r5MCXUdrO4JvpjJzjrn1BDMxB6cAl4efjmEwJP9IywxNcE9NH7D+Rnh8Xcj0Z wTqsvjpXqWwcn12Vub3lKF+pYBIqHCDwFBtqooDiidRbwWvn4H2n2kXQYsi5A5TT20 cn6SzRSR3+ElW4RnM2FMES/S64uJgmoHpMSCUwbyABOwXz3IOYc4tv9De/mgsgvcmc UEZmhDBg4rHgeDsIH3zhuLdjw60sEFjov+hVaj0lRvuQIDE5trwMteC4v4E4N7TSc+ 8c2mDHJ91+75g== From: Maxime Ripard Date: Tue, 28 Nov 2023 11:24:15 +0100 Subject: [PATCH v4 04/45] drm/tests: Add helper to create mock crtc MIME-Version: 1.0 Message-Id: <20231128-kms-hdmi-connector-state-v4-4-c7602158306e@kernel.org> References: <20231128-kms-hdmi-connector-state-v4-0-c7602158306e@kernel.org> In-Reply-To: <20231128-kms-hdmi-connector-state-v4-0-c7602158306e@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Emma Anholt , Jonathan Corbet , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Hans Verkuil , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, Maxime Ripard X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3793; i=mripard@kernel.org; h=from:subject:message-id; bh=G8HSSrdcKPJIlhvVxRehBG//p41ZlqdTJZFDrSgI9fQ=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKmp+y8uirozh3WrZG1yUeZZ1h1VoSc8WjN9e5i9ui8pd pafeBLSUcrCIMbFICumyBIjbL4k7tSs151sfPNg5rAygQxh4OIUgIm0BjP89zcqXWDVlnaibzXH TdOn6g7mF2UFT/kulNII3VOtXOt6n5Hhlej79EfLogz2a7zcvmfG+4mXz8jeL8jtuzrVaBlLUcV uLgA= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 28 Nov 2023 02:24:55 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783802988728014519 X-GMAIL-MSGID: 1783802988728014519 We're going to need a full-blown, functional, KMS device to test more components of the atomic modesetting infrastructure. Let's add a new helper to create a dumb, mocked, CRTC. By default it will create a CRTC relying only on the default helpers, but drivers are free to deviate from that. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/tests/drm_kunit_helpers.c | 62 +++++++++++++++++++++++++++++++ include/drm/drm_kunit_helpers.h | 10 +++++ 2 files changed, 72 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c b/drivers/gpu/drm/tests/drm_kunit_helpers.c index 4a1559424396..49c7b320679b 100644 --- a/drivers/gpu/drm/tests/drm_kunit_helpers.c +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c @@ -321,5 +321,67 @@ drm_kunit_helper_create_primary_plane(struct kunit *test, } EXPORT_SYMBOL_GPL(drm_kunit_helper_create_primary_plane); +static const struct drm_crtc_helper_funcs default_crtc_helper_funcs = { +}; + +static const struct drm_crtc_funcs default_crtc_funcs = { + .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, + .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, + .reset = drm_atomic_helper_crtc_reset, +}; + +/** + * drm_kunit_helper_create_crtc - Creates a mock CRTC for a KUnit test + * @test: The test context object + * @drm: The device to alloc the plane for + * @primary: Primary plane for CRTC + * @cursor: Cursor plane for CRTC. Optional. + * @funcs: Callbacks for the new plane. Optional. + * @helper_funcs: Helpers callbacks for the new plane. Optional. + * + * This allocates and initializes a mock struct &drm_crtc meant to be + * part of a mock device for a KUnit test. + * + * Resources will be cleaned up automatically. + * + * @funcs will default to the default helpers implementations. + * @helper_funcs will default to an empty implementation. + * + * Returns: + * A pointer to the new CRTC, or an ERR_PTR() otherwise. + */ +struct drm_crtc * +drm_kunit_helper_create_crtc(struct kunit *test, + struct drm_device *drm, + struct drm_plane *primary, + struct drm_plane *cursor, + const struct drm_crtc_funcs *funcs, + const struct drm_crtc_helper_funcs *helper_funcs) +{ + struct drm_crtc *crtc; + int ret; + + if (!funcs) + funcs = &default_crtc_funcs; + + if (!helper_funcs) + helper_funcs = &default_crtc_helper_funcs; + + crtc = drmm_kzalloc(drm, sizeof(*crtc), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, crtc); + + ret = drmm_crtc_init_with_planes(drm, crtc, + primary, + cursor, + funcs, + NULL); + KUNIT_ASSERT_EQ(test, ret, 0); + + drm_crtc_helper_add(crtc, helper_funcs); + + return crtc; +} +EXPORT_SYMBOL_GPL(drm_kunit_helper_create_crtc); + MODULE_AUTHOR("Maxime Ripard "); MODULE_LICENSE("GPL"); diff --git a/include/drm/drm_kunit_helpers.h b/include/drm/drm_kunit_helpers.h index 38667d624aa8..6e99627edf45 100644 --- a/include/drm/drm_kunit_helpers.h +++ b/include/drm/drm_kunit_helpers.h @@ -9,6 +9,8 @@ #include +struct drm_crtc_funcs; +struct drm_crtc_helper_funcs; struct drm_device; struct drm_plane_funcs; struct drm_plane_helper_funcs; @@ -110,4 +112,12 @@ drm_kunit_helper_create_primary_plane(struct kunit *test, unsigned int num_formats, const uint64_t *modifiers); +struct drm_crtc * +drm_kunit_helper_create_crtc(struct kunit *test, + struct drm_device *drm, + struct drm_plane *primary, + struct drm_plane *cursor, + const struct drm_crtc_funcs *funcs, + const struct drm_crtc_helper_funcs *helper_funcs); + #endif // DRM_KUNIT_HELPERS_H_