From patchwork Mon Feb 12 13:12:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 199746 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2418165dyd; Mon, 12 Feb 2024 05:15:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IHMMbA7CRlj1E/VASP/XtZJI2NY3llotIJSU0Wt1j6z+objqup/y6DT8IARRSY3606OGkcO X-Received: by 2002:a05:6808:200f:b0:3bf:f34f:ee3b with SMTP id q15-20020a056808200f00b003bff34fee3bmr8096810oiw.54.1707743707039; Mon, 12 Feb 2024 05:15:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707743707; cv=pass; d=google.com; s=arc-20160816; b=IiNGq9lykcI7a8W6YjvjSVa6T5VWvgTKtW+EKnNIZ4YX0WidPbwXZZPcye0Mg1h8YT DmpuqHWypogXNDdNQgn1+xwez52DIBsTFhVZR2fRkshcwtCluIL1mNpJt8wo1r0AstUq LjapzESDfdvL5EIH6rF1tb/bZtIlfjebmtpJbmEkDwxgfLggYcejvMdyQxLODgJuEL9g rn3QwL2r9u73o+5/HdbkCjzUjRJqeH2wRVg7GfkRhULo9vYW4F09XlJfhATUg1cuitvu tfpH5NjyWqyPhSOyoJNBhItC/9I3eEXe6PjDGkios5P353q4JeON77RcF3TarU0q/JJB AXSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=0gV+jP6leWaWc+XhZzAtpYCDDzH/l7RayXml18sQqZc=; fh=qxNhjtzPeuKpaJMSl1k9D9vZzsZ4vCexYQsTTlJ5yxk=; b=vQN5OL0HZnYFl6ImBKzymAT3VPKiXZToQaBJa79fVX2jGT8QGjabCQvDkkxyifuwq2 MZh+QLgkWThE78Y9PAwR+iI0zr8ORvXT1E/yUrkKcfggX+uChcT8wvgYzp6PRLpVjwXD Hy6JMYOi4brrBSjjBcjkvrkJXUf7empLGSQGrC38UKvdTFP2acXTjsKM4NJ1fbho0L+O 1MrlWEgTb5RUZGYKpIYvMgn39lw7BMYGB0fRXQIyuXT4AsL6Yiuvm3lCjGi84d7tpWXH Z7Axrl8+MPXvZ4mUn7jtlBjSUrgalqptiQtOCCE6uSmWdC0DjlNIbM7Q1WgCEsMCzfkw qAdA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OaehGzDH; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-61617-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61617-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCWxSJ3S1Mz6vw9e6mBWtzWqwUdS8uc5mCIa6OZEP/UA+6bs3D6tHZDAoxPqCS+3noUGnwEeKSzxOiMfFMcqgaIfgAs5MQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id i6-20020a05620a0a0600b0078715367700si304233qka.64.2024.02.12.05.15.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 05:15:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61617-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OaehGzDH; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-61617-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61617-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BEA591C21D12 for ; Mon, 12 Feb 2024 13:15:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B855E3BB4D; Mon, 12 Feb 2024 13:13:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OaehGzDH" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 941063BB27; Mon, 12 Feb 2024 13:13:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707743617; cv=none; b=r0QqQYcMdEgA0Fm6lAM4PlI4BcoizRR7VbaKvyUz0ARWMAvhnWKps9o8GN10e5nQVCDtbhPJKOKbO4n3URXubyWqwRF6jz4K2cCb0sdCoLd7Rhg/r81dnzBbkG6lYVrJ84MoqXNt+y0jXvYsgX6Ign8s20IvD7+AkwkpL5t0v/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707743617; c=relaxed/simple; bh=BT0Fi2BfGOtTeKlub/+OMF8A+xXJm9y8g7PRHJ/dxN4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Sr/WZbJDcjOPl8J5J3ejjNCyUN8annX3VXVzFi8VuKsillqlUIju+qVLqqgA+Fswprppc2nO1ha+xsKggZPshduKAqCNDlsGeRwIl9MAjcEn+5awV5MUsdlREFZDoSaERhaA2Cq1kxqiLVD1iu/JU2dFrjXo0T0kMhXxnpo9PHA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OaehGzDH; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C074BC433F1; Mon, 12 Feb 2024 13:13:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707743617; bh=BT0Fi2BfGOtTeKlub/+OMF8A+xXJm9y8g7PRHJ/dxN4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OaehGzDHObdd9hcC4BKvXyoxEk0UIpTOUWVu3luHU53yYOHIsHos9jxbQ9T5VAasN Yvw9bw5QANAjlkT+O6fKYoy86TotkEJaJOf1/shounD/fhGdg//LMarFks+OZY9cyh QhNl4R5/9ASMdCAwxYLMqrDU9vvoNS46TgA90DxdHeE9joSRzU2KKtArLrAxsrEZw8 xOancEyUJqNNZ8kN2T8oXWAwH7eHYYd1sH/mf35lsSXjZzWgdEVMJI6V3+oo5p5Mhs PjxLOjcTYTFZE44Q7CUDvLFsQskE/9/+9CZn0UBRDxZUlDvNgtfrmL8O8CJQ5mH8NF c40MMccOEPgDQ== From: Maxime Ripard Date: Mon, 12 Feb 2024 14:12:46 +0100 Subject: [PATCH v6 03/36] drm/tests: Add helper to create mock plane Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240212-kms-hdmi-connector-state-v6-3-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=4849; i=mripard@kernel.org; h=from:subject:message-id; bh=BT0Fi2BfGOtTeKlub/+OMF8A+xXJm9y8g7PRHJ/dxN4=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKmnJOMzC3cc3bXjevlzmwoR6wT5h7psCVG7jqql6SnUx a76lVPSUcrCIMbFICumyBIjbL4k7tSs151sfPNg5rAygQxh4OIUgImYTmT4K6u5qHehZ6Go6+nL M9YsZniwztNxtd0cm47CfVujmCN3vmdkaN81aaPbE61nvZNTHQUbT3dWfrwes3D6lQgvle4VPd3 zWQA= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790699065186052791 X-GMAIL-MSGID: 1790699065186052791 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 4fb11b938bc1..32dc8354641a 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 @@ -164,5 +165,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_