From mboxrd@z Thu Jan 1 00:00:00 1970 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 B6A7EFD4F03 for ; Tue, 10 Mar 2026 16:07:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0C13A10E73A; Tue, 10 Mar 2026 16:07:34 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="skU8WFdu"; dkim-atps=neutral Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id D89E310E726 for ; Tue, 10 Mar 2026 16:07:32 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id BC9CA44207; Tue, 10 Mar 2026 16:07:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B150C19425; Tue, 10 Mar 2026 16:07:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773158852; bh=CsVIwHX+p0j2dU0X8ERUlyY3x8L8Ul+2z/qAN1xRluo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=skU8WFduYo/6yp0LBTgpx8wNU1y1Ck2VasfE6wz0shvwAGT3jxNGq1s2H4zI1k8PY YHNn5MV9k1fd/Z73kiWuKyYK+5fhN3C9AeCVY9QaAXOjRRZ0PflPjFhAfheP0xYIw7 yxwzjURt3C0MxFOvYYevWByGpNYw07Y1UdAIKyMRxI+koKbiuvz+TCvdvLVM/LB+GO DXQwTe7A3XNpHfhK4Z9xCW3QLB2Q6ngdIy+4aIkaZXKy9gGU6ztYTwNH69sAaL3Zit kvS1c0wSVjwwvNNfEmyD0gzLUSH1CrHTIb6BwoCggO3DjUg6ETz424mVaPyz7ZuitZ YKT74ih5F8aow== From: Maxime Ripard Date: Tue, 10 Mar 2026 17:07:00 +0100 Subject: [PATCH 08/14] drm/mode-config: Create drm_mode_config_create_state() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260310-drm-mode-config-init-v1-8-de7397c8e1cf@kernel.org> References: <20260310-drm-mode-config-init-v1-0-de7397c8e1cf@kernel.org> In-Reply-To: <20260310-drm-mode-config-init-v1-0-de7397c8e1cf@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , Jonathan Corbet , Shuah Khan , Dmitry Baryshkov , Jyri Sarha , Tomi Valkeinen , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec Cc: dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Maxime Ripard X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6059; i=mripard@kernel.org; h=from:subject:message-id; bh=CsVIwHX+p0j2dU0X8ERUlyY3x8L8Ul+2z/qAN1xRluo=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDJkbHJe/3qXRarXwUuIly8PH8pd633FTeJWX0vwlYY+2+ OqX8y4t6ZjKwiDMySArpsjyRCbs9PL2xVUO9it/wMxhZQIZwsDFKQATeWzC2LBO1rjLZUIgU/+N bfrbs56tnfhm8uSvXz6s9q9tK+JqUNpvc3dDWszLpFfbdNWvPgx6NJ2x3tdKecOPsNqHbOIWr3R nJ0ues/g/75iXa06+bmmuomiKd+mJ7AuzrN47HHk0R+LhXP1jAA== X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" drm_mode_config_reset() can be used to create the initial state, but also to return to the initial state, when doing a suspend/resume cycle for example. It also affects both the software and the hardware, and drivers can either choose to reset the hardware as well. Most will just create an empty state and the synchronisation between hardware and software states will effectively be done when the first commit is done. That dual role can be harmful, since some objects do need to be initialized but also need to be preserved across a suspend/resume cycle. drm_private_obj are such objects for example. Thus, let's create another helper for drivers to call to initialize their state when the driver is loaded, so we can make drm_mode_config_reset() only about handling suspend/resume and similar. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/drm_atomic.c | 12 +++++- drivers/gpu/drm/drm_mode_config.c | 83 +++++++++++++++++++++++++++++++++++++++ include/drm/drm_mode_config.h | 1 + 3 files changed, 94 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index 92c6afc8f22c8307a59dc266aacdb8e03351409d..d1885f895cce78725419b6291f4dbe5563e3b240 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -58,12 +58,20 @@ * checking or doing the update, while object states are allocated while * the state will be, or is active in the hardware. * * Their respective lifetimes are: * - * - at reset time, the object reset implementation will allocate a new, - * default, state and will store it in the object state pointer. + * - at driver initialization time, the driver will allocate an initial, + * pristine, state and will store it using + * drm_mode_config_create_state(). Historically, this was one of + * drm_mode_config_reset() job, so one might still encounter it in a + * driver. + * + * - at reset time, for example during suspend/resume, + * drm_mode_config_reset() will reset the software and hardware state + * to a known default and will store it in the object state pointer. + * Not all objects are affected by drm_mode_config_reset() though. * * - whenever a new update is needed: * * + we allocate a new &struct drm_atomic_state using drm_atomic_state_alloc(). * diff --git a/drivers/gpu/drm/drm_mode_config.c b/drivers/gpu/drm/drm_mode_config.c index 95759a4b5176ff17032a9a267ec9de6980be0abc..1a84ac063d381014eb8afd7116e1e8b7a8fc92ca 100644 --- a/drivers/gpu/drm/drm_mode_config.c +++ b/drivers/gpu/drm/drm_mode_config.c @@ -21,10 +21,11 @@ */ #include #include +#include #include #include #include #include #include @@ -278,10 +279,92 @@ void drm_mode_config_reset(struct drm_device *dev) drm_mode_config_connector_create_state(connector); drm_connector_list_iter_end(&conn_iter); } EXPORT_SYMBOL(drm_mode_config_reset); +/** + * drm_mode_config_create_state - Allocates the initial state + * @dev: drm device + * + * This functions creates the initial state for all the objects. Drivers + * can use this in e.g. their driver load to initialize its software + * state. + * + * It has two main differences with drm_mode_config_reset(): the reset() + * hooks aren't called and thus the hardware will be left untouched, but + * also the @drm_private_obj structures will be initialized as opposed + * to drm_mode_config_reset() that skips them. + * + * Returns: 0 on success, negative error value on failure. + */ +int drm_mode_config_create_state(struct drm_device *dev) +{ + struct drm_crtc *crtc; + struct drm_colorop *colorop; + struct drm_plane *plane; + struct drm_connector *connector; + struct drm_connector_list_iter conn_iter; + struct drm_private_obj *privobj; + int ret; + + drm_for_each_privobj(privobj, dev) { + struct drm_private_state *privobj_state; + + if (privobj->state) + continue; + + if (!privobj->funcs->atomic_create_state) + continue; + + privobj_state = privobj->funcs->atomic_create_state(privobj); + if (IS_ERR(privobj_state)) + return PTR_ERR(privobj_state); + + privobj->state = privobj_state; + } + + drm_for_each_colorop(colorop, dev) { + if (colorop->state) + continue; + + // TODO: Implement atomic_create_state for colorop. + drm_colorop_reset(colorop); + } + + drm_for_each_plane(plane, dev) { + if (plane->state) + continue; + + ret = drm_mode_config_plane_create_state(plane); + if (ret) + return ret; + } + + drm_for_each_crtc(crtc, dev) { + if (crtc->state) + continue; + + ret = drm_mode_config_crtc_create_state(crtc); + if (ret) + return ret; + } + + drm_connector_list_iter_begin(dev, &conn_iter); + drm_for_each_connector_iter(connector, &conn_iter) { + if (connector->state) + continue; + + ret = drm_mode_config_connector_create_state(connector); + if (ret) + return ret; + } + drm_connector_list_iter_end(&conn_iter); + + return 0; +} +EXPORT_SYMBOL(drm_mode_config_create_state); + /* * Global properties */ static const struct drm_prop_enum_list drm_plane_type_enum_list[] = { { DRM_PLANE_TYPE_OVERLAY, "Overlay" }, diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_config.h index 5e1dd0cfccde2d2bc00a09e98e4adc65833dad08..428ae75b7c4f193dfbd49c15a2f2ef32209a6cef 100644 --- a/include/drm/drm_mode_config.h +++ b/include/drm/drm_mode_config.h @@ -1000,9 +1000,10 @@ int __must_check drmm_mode_config_init(struct drm_device *dev); static inline int drm_mode_config_init(struct drm_device *dev) { return drmm_mode_config_init(dev); } +int drm_mode_config_create_state(struct drm_device *dev); void drm_mode_config_reset(struct drm_device *dev); void drm_mode_config_cleanup(struct drm_device *dev); #endif -- 2.53.0