From patchwork Mon Feb 12 13:12:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 13553353 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4CD8FC48297 for ; Mon, 12 Feb 2024 14:15:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8z+mrpexQuYpEjXvhLiv0N8/TeJUIMwTlWE5dKEUUWw=; b=PVNp9aXxxLrW2F uJUZLguePO5Ag4+42qxH3M7r+Laux7hwlK8oE6cZZ11D+gUjG1LNWkZktSmz2bfYZaHWyocIkRU5i L8o9MD9wUXHKgqt0rLOK9bmAC+2funmCNjXIDaoytQpntWzXT1YMNT6L75RMAngGcZaZrrCqFN+6U bhqGRvRAvboZ7c6Zps6eVZTXWllLbMpElNqtr63506C/n3UlY4C4nHbW6bxifcbY3ELyf+oWxDCLu kwLj7hiUukdUSg5wTK2nnvmWVqGk3rynu1HRr5Q/azt/FpsubZqHcm6QbEaIt1B+hFrguQKrFlSH9 pR/WWSdjyEP4vOh0E23g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZX5c-00000005kMf-2vXZ; Mon, 12 Feb 2024 14:15:20 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZW7x-00000005OV0-0WIz; Mon, 12 Feb 2024 13:13:43 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 56B0560FC5; Mon, 12 Feb 2024 13:13:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3DC8C433C7; Mon, 12 Feb 2024 13:13:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707743620; bh=EhwkazNlZ1kcicF1NryTZowdCh8r1uFd2Irf8ktLv6M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Sp7HV+bvdO68KCasoWvCWIRZsfKu8CHLwDit+uwjxPAAsxomz7i/dPxYsFTuY80nQ J0GRGAphZ7bLnRvmxBP5b8MfTpb18FODs4d8MZM1vakrVnJrWkBUgZ4G3sGmeJN6Uz lkJWvbekUOwBiGBOqx7aqOfuqc8vcv8oldVupj6eQv3mIf6tr66B14OT2QANuZ28Ub EQ9Kbk7zMEieijS8lKU0ljW01AjlSCMKLobOyqo+kRIGsjkV5qFUQpEqrjb7ck1J6v cQbU37KQy8VV1i0rgJinn8JnsSI/v+azOA3mZAwtK5Stq1KuuvRnYNJwWnYTYNCuxb 4hbxHrj8Wlhjw== From: Maxime Ripard Date: Mon, 12 Feb 2024 14:12:47 +0100 Subject: [PATCH v6 04/36] drm/tests: Add helper to create mock crtc MIME-Version: 1.0 Message-Id: <20240212-kms-hdmi-connector-state-v6-4-f4bcdc979e6f@kernel.org> References: <20240212-kms-hdmi-connector-state-v6-0-f4bcdc979e6f@kernel.org> In-Reply-To: <20240212-kms-hdmi-connector-state-v6-0-f4bcdc979e6f@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=EhwkazNlZ1kcicF1NryTZowdCh8r1uFd2Irf8ktLv6M=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKmnJBMe/uKeEc4pk5Hb8HD+pX8nM06eDFrFMPdNZ+rp4 D9X5B90dZSyMIhxMciKKbLECJsviTs163UnG988mDmsTCBDGLg4BWAibrcYGX4dPOTvOvGzbaqf oIzHvvaT86Q1vJbr9Kyxae/VFw9uWcPwV851KVMRC5u+yLIy1bnyPfXff5fKVnC+M+u5XWr1/4g xMwA= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240212_051341_443674_B381C44C X-CRM114-Status: GOOD ( 13.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 32dc8354641a..d5317d13d3fc 100644 --- a/drivers/gpu/drm/tests/drm_kunit_helpers.c +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c @@ -249,5 +249,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_