From patchwork Thu Dec 7 15:49:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 175219 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4874212vqy; Thu, 7 Dec 2023 07:50:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IGbVCN3NruTBoBNPrXAhWZErSBMosz0H8JEilZ48zTWN5i7COi+zOfPkz+QVPZncdHMxfT+ X-Received: by 2002:a05:6a20:9184:b0:18f:97c:5b85 with SMTP id v4-20020a056a20918400b0018f097c5b85mr2594030pzd.83.1701964204301; Thu, 07 Dec 2023 07:50:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701964204; cv=none; d=google.com; s=arc-20160816; b=FvEtyz4prGQJvXRl0t5tVHcMelnrYsla3BOshIBwK4j5LXDoifNheJEOlufiOvD1x5 qz41hfL4GenytuLpp68WdZTs2a0v57BZH3Hhk/UKLbxmymUAIvx0znjw6gGdR3QS5vEF QDntcwok83/3H0Eqxn4TgORGM08OWREvgCOqSAoCVgq82wvnhb9u33jkLyPInwWJFo14 rAiNIcrwgTlbnpaVoVS2yFulXOoLlpyvY5gjNBj7mFxEIhay7X4EZQG71f1WUJRaH7b2 5o+F9ZHkcvIrOaVin2MQEzxusoL+jouowdWJqJ19hxM4KHlBZPSlVRtH4r4idmxb2l85 1Evg== 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=xxloOr2aoBptbZZLZjPd9jDIaKmifX0OEe060GPL/j0=; fh=e6/uyeFf2k7v8JUtB6fPyaAS5iN3eSA1hjtg35V2Rzw=; b=bJ9bqDkIY9fc9jVIq3JjEqCI3qGb4pm6IurS1qVsR1Ku8+0BTuw9O4nusuV4j33ZSz nu6RXdiXgeyVyD8/EvLiMG0tvXN73bbSev82q1hm8bnBEB0qUAGgwfrMTB/vvNuJy7UT dCJeNz+74iVK5UpkBAlNbS1fh26HiivArJoR1D3TFN88DyWseTOA3eKxrOMR/z2+KjAn oluipTvrkdrryNzQqrKDWMyy7Y4ZnKP/h0BWDPwG8ukiimidJdXhZz5MDmFpmWb/5gyn twwalm4/UeKW8ePSZBTh8Yo8OnckpOZ+GT0i0VfQw1bOv2q7nNLZDBQphi7VUd+JFwEq Y9Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XZqQ+ka+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id h14-20020a17090a604e00b0028679c85a9dsi1179775pjm.87.2023.12.07.07.50.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 07:50:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XZqQ+ka+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 75FFC80CB159; Thu, 7 Dec 2023 07:50:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443599AbjLGPtk (ORCPT + 99 others); Thu, 7 Dec 2023 10:49:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443596AbjLGPth (ORCPT ); Thu, 7 Dec 2023 10:49:37 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6A3B10F8 for ; Thu, 7 Dec 2023 07:49:42 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35047C433CA; Thu, 7 Dec 2023 15:49:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701964182; bh=o+4LyKPBmfDMs1sf7aMWTAE6JRxkm0AE05nsfg2fljw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XZqQ+ka+/MlIBjCY3EYHiMES5EhgKGNft2/dTIBPu2nBkophRfwKfoT1OGxqueaIe 8mGPxFSlXKfPXncPUhYaMQPz+47hGmB79XpkIciIgSM0987VxkQ6UCieNZ7UJtFMpx MNImHJbfcBxxiWqqnHi8t+EjngpAY8ryBGU9ItAILrPxkG+Rp+VE/G4O192OT+Hv7K pjS5+cZeCJXwO9VS5/oVkFSqIe2gkI2M9lj+Z2cULPwXSbbcsQ3vO16S+WTecMYdgw E8cfDOJ/3/Bv8V8ZDTrWOjzwrv9Db5wVtmHenh1vE4K0VZqfge+ImBiLgG+Nusndxm B38q0NcK0TDAw== From: Maxime Ripard Date: Thu, 07 Dec 2023 16:49:27 +0100 Subject: [PATCH v5 04/44] drm/tests: Add helper to create mock crtc MIME-Version: 1.0 Message-Id: <20231207-kms-hdmi-connector-state-v5-4-6538e19d634d@kernel.org> References: <20231207-kms-hdmi-connector-state-v5-0-6538e19d634d@kernel.org> In-Reply-To: <20231207-kms-hdmi-connector-state-v5-0-6538e19d634d@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=o+4LyKPBmfDMs1sf7aMWTAE6JRxkm0AE05nsfg2fljw=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKmFL1sszny8KnR1GddFp59bU0J2Gh+JfLaN61tH1O3w/ mBR3/0/O0pZGMS4GGTFFFlihM2XxJ2a9bqTjW8ezBxWJpAhDFycAjAR92yG/wXne76WJdYyzd7m OfGL/VPWRxvrOLWzHX6Xavb47GgJ5Wf47/LjSFLOYq7cSYyljWrL5TrvFm+a7X2zXnLrBVY196e pLAA= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Thu, 07 Dec 2023 07:50:00 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784638817271441017 X-GMAIL-MSGID: 1784638817271441017 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 e0778a7ec260..ca513235b5e2 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_