From patchwork Thu Dec 7 15:49:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 175218 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4874077vqy; Thu, 7 Dec 2023 07:49:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IEIdumXnRAv1mUcIzYgcFCgOm2o/RlSawN/tTGX0YCey98KqO9pnHMJKJ/CxYT5rWZLFCew X-Received: by 2002:a05:6a00:1345:b0:6ce:7987:75fa with SMTP id k5-20020a056a00134500b006ce798775famr2522607pfu.14.1701964190113; Thu, 07 Dec 2023 07:49:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701964190; cv=none; d=google.com; s=arc-20160816; b=IbY/qEWDqHqKjJFeOff5cZKgDUNZOE31hGp46bgF+TbCjIUYgBoi4Xu5o4J2/KQkP6 LoLJFAoOOjnsNTbdcCtx9WYcyTIToerjn99mjXni3bC1ONmgrvjwrZr1663GWqt3Ky4N Tqdh1Cn4wEskzdyP5/V1Ey1dRJQhq3gkZd/r7YAFlh1ukT0V8Gqy5BfAR0aXuYQTqVOY 6DRRDdk4NzkMaNRkoaRtllUtf19RtQj17EKeo6K1J0DkBikWgdSkibymRD0+70fuHwtq sWBCWb8lZjoVkNDQaviYMwtwevl0eZF8N9d6U5mANXeJ5Bo3TaHYKQ5LHsnIoyUByP3V gieg== 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=BSbZakEjYlPJP97NSierl6cpMPfvPlo+TQpVRd3x1BQ=; fh=e6/uyeFf2k7v8JUtB6fPyaAS5iN3eSA1hjtg35V2Rzw=; b=kcyrTIiqVg8FR/8nP1HC0bhaX3E0yG/5qKFwQ91jsG738HsHf+iWMZvXa9Y+LaRQnI eO/Jg8aTezOqzADL/jUexJmLapdxm0PYnILdvjVHvRSwY7nlhQLO8eXG+ipuAyuuurz1 4fdRXqvYMNUTYNgoKECARt6wkiK9HTZycIHJB5mgBjo6NESMuTMyk3+Yf+8yLcgaN6Pq uvRI0QWZSMx36Lf8oYa1d60ln4BWuL9Ttw/UBTeSeSqeM6EKcZTWloOEB/SojiixqnBh am3VmlajknM0vDlu/3eVCxEosSbR3BU+ZLMQcgQ60qxBk5M+vGb6DrlRzhmfqPih47AB Sn9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Be8MtWZJ; 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 n20-20020a056a0007d400b006cb65cfde7fsi1414426pfu.91.2023.12.07.07.49.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 07:49:50 -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=Be8MtWZJ; 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 D8ECA8042585; Thu, 7 Dec 2023 07:49:48 -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 S1443592AbjLGPti (ORCPT + 99 others); Thu, 7 Dec 2023 10:49:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443591AbjLGPtd (ORCPT ); Thu, 7 Dec 2023 10:49:33 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A70410F3 for ; Thu, 7 Dec 2023 07:49:40 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A2D5C433C8; Thu, 7 Dec 2023 15:49:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701964179; bh=QsiPo+B04Y1hXaUVj9yAPd4DGQRLjHkQnobeAYrsDpM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Be8MtWZJrnQ1Dmcwkd96YSXsO2k9D9uiMPAS4D6bp1dTRLuTpA+ZpugEZXpfSk/+R G1nc+Qn9XXlSB7//TH0xr6Mrj+QrebFEpLKEd+UD6bBVBck3JHhpbuQDx+RP+ONw+H RFOtS/SnT7lOpwRKdfKrcI4RXIdf7rMhp9qTT3dkCh+6bs1/hgMghJYdl4oz9rD8Gv jKrudjL7UxelgndrurU+VmIetKJ7l8o5Twv9T5GEbZ9RkOzY8+hmiD86dBZxAbQTLb s3h80QFs3FpnsB0HJ+IeTzuL/Q+HNnhLOo/aUXciC2LfQTKDGWyJsH6nEdtL4IsQd/ kAl83OXflnL6A== From: Maxime Ripard Date: Thu, 07 Dec 2023 16:49:26 +0100 Subject: [PATCH v5 03/44] drm/tests: Add helper to create mock plane MIME-Version: 1.0 Message-Id: <20231207-kms-hdmi-connector-state-v5-3-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=4849; i=mripard@kernel.org; h=from:subject:message-id; bh=QsiPo+B04Y1hXaUVj9yAPd4DGQRLjHkQnobeAYrsDpM=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKmFL1t4trsEqOaufaWhZar1aMP0FY2iovpLAsWO7/jif //Z2UbmjlIWBjEuBlkxRZYYYfMlcadmve5k45sHM4eVCWQIAxenAEzkgBvD/7Avqxt3iclcOK+V eih0vZVm2xaJLed/aYvONxd8raTPspyRYY6mblIvl/ffxSyRbf/j2Xi2Hww5WeL087ssr258YdE XXgA= 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]); Thu, 07 Dec 2023 07:49:49 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784638802493480680 X-GMAIL-MSGID: 1784638802493480680 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, primary plane. By default, it will create a linear XRGB8888 plane, using the default helpers. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/tests/drm_kunit_helpers.c | 85 +++++++++++++++++++++++++++++++ include/drm/drm_kunit_helpers.h | 11 ++++ 2 files changed, 96 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c b/drivers/gpu/drm/tests/drm_kunit_helpers.c index 272a3ba46d60..e0778a7ec260 100644 --- a/drivers/gpu/drm/tests/drm_kunit_helpers.c +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -236,5 +237,89 @@ drm_kunit_helper_atomic_state_alloc(struct kunit *test, } EXPORT_SYMBOL_GPL(drm_kunit_helper_atomic_state_alloc); +static const uint32_t default_plane_formats[] = { + DRM_FORMAT_XRGB8888, +}; + +static const uint64_t default_plane_modifiers[] = { + DRM_FORMAT_MOD_LINEAR, + DRM_FORMAT_MOD_INVALID +}; + +static const struct drm_plane_helper_funcs default_plane_helper_funcs = { +}; + +static const struct drm_plane_funcs default_plane_funcs = { + .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, + .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, + .reset = drm_atomic_helper_plane_reset, +}; + +/** + * drm_kunit_helper_create_primary_plane - Creates a mock primary plane for a KUnit test + * @test: The test context object + * @drm: The device to alloc the plane for + * @funcs: Callbacks for the new plane. Optional. + * @helper_funcs: Helpers callbacks for the new plane. Optional. + * @formats: array of supported formats (DRM_FORMAT\_\*). Optional. + * @num_formats: number of elements in @formats + * @modifiers: array of struct drm_format modifiers terminated by + * DRM_FORMAT_MOD_INVALID. Optional. + * + * This allocates and initializes a mock struct &drm_plane 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. @formats will + * default to XRGB8888 only. @modifiers will default to a linear + * modifier only. + * + * Returns: + * A pointer to the new plane, or an ERR_PTR() otherwise. + */ +struct drm_plane * +drm_kunit_helper_create_primary_plane(struct kunit *test, + struct drm_device *drm, + const struct drm_plane_funcs *funcs, + const struct drm_plane_helper_funcs *helper_funcs, + const uint32_t *formats, + unsigned int num_formats, + const uint64_t *modifiers) +{ + struct drm_plane *plane; + + if (!funcs) + funcs = &default_plane_funcs; + + if (!helper_funcs) + helper_funcs = &default_plane_helper_funcs; + + if (!formats || !num_formats) { + formats = default_plane_formats; + num_formats = ARRAY_SIZE(default_plane_formats); + } + + if (!modifiers) + modifiers = default_plane_modifiers; + + plane = __drmm_universal_plane_alloc(drm, + sizeof(struct drm_plane), 0, + 0, + funcs, + formats, + num_formats, + default_plane_modifiers, + DRM_PLANE_TYPE_PRIMARY, + NULL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, plane); + + drm_plane_helper_add(plane, helper_funcs); + + return plane; +} +EXPORT_SYMBOL_GPL(drm_kunit_helper_create_primary_plane); + MODULE_AUTHOR("Maxime Ripard "); MODULE_LICENSE("GPL"); diff --git a/include/drm/drm_kunit_helpers.h b/include/drm/drm_kunit_helpers.h index 3ae19892229d..38667d624aa8 100644 --- a/include/drm/drm_kunit_helpers.h +++ b/include/drm/drm_kunit_helpers.h @@ -10,6 +10,8 @@ #include struct drm_device; +struct drm_plane_funcs; +struct drm_plane_helper_funcs; struct kunit; struct device *drm_kunit_helper_alloc_device(struct kunit *test); @@ -99,4 +101,13 @@ drm_kunit_helper_atomic_state_alloc(struct kunit *test, struct drm_device *drm, struct drm_modeset_acquire_ctx *ctx); +struct drm_plane * +drm_kunit_helper_create_primary_plane(struct kunit *test, + struct drm_device *drm, + const struct drm_plane_funcs *funcs, + const struct drm_plane_helper_funcs *helper_funcs, + const uint32_t *formats, + unsigned int num_formats, + const uint64_t *modifiers); + #endif // DRM_KUNIT_HELPERS_H_