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 0ABEA10987A4 for ; Fri, 20 Mar 2026 16:28:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6880310EB54; Fri, 20 Mar 2026 16:28:06 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="sBN427Sf"; dkim-atps=neutral Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1931010EB54; Fri, 20 Mar 2026 16:28:05 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 8A8D461118; Fri, 20 Mar 2026 16:28:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5B4FC4CEF7; Fri, 20 Mar 2026 16:28:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774024084; bh=/prMPgtxbxwKDnFBz1MDqeN5/Do3sH3oc7KVgPrpIzI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=sBN427SfpWezemyIM1apotxIQAvf0HvkMAlByBkuBZwIZHsqboETLUiDifnyFdBQD 5WIMtn9MXojRYgOR/aj+DpyUk0LuMEjwslGQRxHK8k5pjE3lOsWSL0zzxd/pu0ciMo qDi3+RZNHDTH1sCC6ueb0DgT/ywDOEuy63LQHBFQSTaIZtMQW0ZCWyBkgBrzroaTIU 9ffsl2rTimcNTXdtb0JM9+pKH9bIi1viQP11UuT7N5dROHdEchVhXX2xFY6nYjRdgy 8mZdSqXfRjudidyxDJ8bGK2VMrZVp9x/l5hK79SWt59ke2mNNxE9aT0RMeDJZVjZ8K Y7tr6UBW7EI4g== From: Maxime Ripard Date: Fri, 20 Mar 2026 17:27:20 +0100 Subject: [PATCH v2 13/20] drm/connector: Add new atomic_create_state callback MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260320-drm-mode-config-init-v2-13-c63f1134e76c@kernel.org> References: <20260320-drm-mode-config-init-v2-0-c63f1134e76c@kernel.org> In-Reply-To: <20260320-drm-mode-config-init-v2-0-c63f1134e76c@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 , Simon Ser , Harry Wentland , Melissa Wen , Sebastian Wick , Alex Hung , Jani Nikula , Rodrigo Vivi , Joonas Lahtinen , Tvrtko Ursulin , Chen-Yu Tsai , Samuel Holland , Dave Stevenson , =?utf-8?q?Ma=C3=ADra_Canal?= , Raspberry Pi Kernel Maintenance Cc: dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Daniel Stone , intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, Maxime Ripard X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=8108; i=mripard@kernel.org; h=from:subject:message-id; bh=/prMPgtxbxwKDnFBz1MDqeN5/Do3sH3oc7KVgPrpIzI=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDJl7SzNZuz1CUrSPt3huvTR1eksbs/HB6ZwbPCetedOw+ qlOQdzLjqksDMKcDLJiiixPZMJOL29fXOVgv/IHzBxWJpAhDFycAjARgRWM1Sy8MuFPHjp1iWxd avL045OeBNXUojIWpR1BTMeszzq2zMsTP8levFXDd/m0b0ceFbyexlgftpHdkZvx2dJ/l6c+Mjp 46GF4+GtD/h6WE/2/1jXMNJI3mTgv6oe3QWdThOTCu3LLWWMA 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" Commit 47b5ac7daa46 ("drm/atomic: Add new atomic_create_state callback to drm_private_obj") introduced a new pattern for allocating drm object states. Instead of relying on the reset() callback, it created a new atomic_create_state hook. This is helpful because reset is a bit overloaded: it's used to create the initial software tate, reset it, but also reset the hardware. It can also be used either at probe time, to create the initial state and possibly reset the hardware to an expected default, but also during suspend/resume. Both these cases come with different expectations too: during the initialization, we want to initialize all states, but during suspend/resume, drm_private_states for example are expected to be kept around. And reset() isn't fallible, which makes it harder to handle initialization errors properly. And this is only really relevant for some drivers, since all the helpers for reset only create a new state, and don't touch the hardware at all. It was thus decided to create a new hook that would allocate and initialize a pristine state without any side effect: atomic_create_state to untangle a bit some of it, and to separate the initialization with the actual reset one might need during a suspend/resume. Let's continue the transition to the new pattern with connectors. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/drm_atomic_state_helper.c | 45 +++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_mode_config.c | 21 ++++++++++++++- include/drm/drm_atomic_state_helper.h | 4 +++ include/drm/drm_connector.h | 13 +++++++++ 4 files changed, 82 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_atomic_state_helper.c b/drivers/gpu/drm/drm_atomic_state_helper.c index 8ed8cb8a9048e8fd89fa22d20985c84af1672135..c7eb3ce8c282a0d1099bdb840653baa9f2005db5 100644 --- a/drivers/gpu/drm/drm_atomic_state_helper.c +++ b/drivers/gpu/drm/drm_atomic_state_helper.c @@ -553,10 +553,29 @@ __drm_atomic_helper_connector_reset(struct drm_connector *connector, connector->state = conn_state; } EXPORT_SYMBOL(__drm_atomic_helper_connector_reset); +/** + * __drm_atomic_helper_connector_create_state - initializes connector state + * @connector: connector object + * @state: new state to initialize + * + * Initializes the newly allocated @state, usually required when + * initializing the drivers. + * + * @state is assumed to be zeroed. + * + * This is useful for drivers that subclass @drm_connector_state. + */ +void __drm_atomic_helper_connector_create_state(struct drm_connector *connector, + struct drm_connector_state *state) +{ + __drm_atomic_helper_connector_state_init(state, connector); +} +EXPORT_SYMBOL(__drm_atomic_helper_connector_create_state); + /** * drm_atomic_helper_connector_reset - default &drm_connector_funcs.reset hook for connectors * @connector: drm connector * * Resets the atomic state for @connector by freeing the state pointer (which @@ -573,10 +592,36 @@ void drm_atomic_helper_connector_reset(struct drm_connector *connector) kfree(connector->state); __drm_atomic_helper_connector_reset(connector, conn_state); } EXPORT_SYMBOL(drm_atomic_helper_connector_reset); +/** + * drm_atomic_helper_connector_create_state - default &drm_connector_funcs.atomic_create_state hook for connectors + * @connector: connector object + * + * Initializes a pristine @drm_connector_state. + * + * This is useful for drivers that don't subclass @drm_connector_state. + * + * RETURNS: + * Pointer to new connector state, or ERR_PTR on failure. + */ +struct drm_connector_state * +drm_atomic_helper_connector_create_state(struct drm_connector *connector) +{ + struct drm_connector_state *state; + + state = kzalloc_obj(*state); + if (!state) + return ERR_PTR(-ENOMEM); + + __drm_atomic_helper_connector_create_state(connector, state); + + return state; +} +EXPORT_SYMBOL(drm_atomic_helper_connector_create_state); + /** * drm_atomic_helper_connector_tv_margins_reset - Resets TV connector properties * @connector: DRM connector * * Resets the TV-related properties attached to a connector. diff --git a/drivers/gpu/drm/drm_mode_config.c b/drivers/gpu/drm/drm_mode_config.c index f5092d03b168bb114a199b1dbcaeb770983c9749..124cef8f0c6eb15c9fde4cf7cee2936cbf2b902f 100644 --- a/drivers/gpu/drm/drm_mode_config.c +++ b/drivers/gpu/drm/drm_mode_config.c @@ -212,10 +212,26 @@ static int drm_mode_config_crtc_create_state(struct drm_crtc *crtc) crtc->state = crtc_state; return 0; } +static int drm_mode_config_connector_create_state(struct drm_connector *connector) +{ + struct drm_connector_state *conn_state; + + if (!connector->funcs->atomic_create_state) + return 0; + + conn_state = connector->funcs->atomic_create_state(connector); + if (IS_ERR(conn_state)) + return PTR_ERR(conn_state); + + connector->state = conn_state; + + return 0; +} + /** * drm_mode_config_reset - call ->reset callbacks * @dev: drm device * * This functions calls all the crtc's, encoder's and connector's ->reset @@ -255,13 +271,16 @@ void drm_mode_config_reset(struct drm_device *dev) drm_for_each_encoder(encoder, dev) if (encoder->funcs && encoder->funcs->reset) encoder->funcs->reset(encoder); drm_connector_list_iter_begin(dev, &conn_iter); - drm_for_each_connector_iter(connector, &conn_iter) + drm_for_each_connector_iter(connector, &conn_iter) { if (connector->funcs->reset) connector->funcs->reset(connector); + else if (connector->funcs->atomic_create_state) + drm_mode_config_connector_create_state(connector); + } drm_connector_list_iter_end(&conn_iter); } EXPORT_SYMBOL(drm_mode_config_reset); /* diff --git a/include/drm/drm_atomic_state_helper.h b/include/drm/drm_atomic_state_helper.h index 259a39a0f41ddb2b7d6c1fe7c1a2b0b51774254c..96a058ba698203c023e54c2b3d908c13cfa2d23b 100644 --- a/include/drm/drm_atomic_state_helper.h +++ b/include/drm/drm_atomic_state_helper.h @@ -76,11 +76,15 @@ void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane, void __drm_atomic_helper_connector_state_init(struct drm_connector_state *conn_state, struct drm_connector *connector); void __drm_atomic_helper_connector_reset(struct drm_connector *connector, struct drm_connector_state *conn_state); +void __drm_atomic_helper_connector_create_state(struct drm_connector *connector, + struct drm_connector_state *state); void drm_atomic_helper_connector_reset(struct drm_connector *connector); +struct drm_connector_state * +drm_atomic_helper_connector_create_state(struct drm_connector *connector); void drm_atomic_helper_connector_tv_reset(struct drm_connector *connector); int drm_atomic_helper_connector_tv_check(struct drm_connector *connector, struct drm_atomic_state *state); void drm_atomic_helper_connector_tv_margins_reset(struct drm_connector *connector); void diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h index c18be8c19de0ab1e02e7d7b1fcd9f2ab5ef1dd15..6d73068de157144770931c64ce3f91e6f15ef0e4 100644 --- a/include/drm/drm_connector.h +++ b/include/drm/drm_connector.h @@ -1509,10 +1509,23 @@ struct drm_connector_funcs { * when a connector is being hot-unplugged for drivers that support * connector hotplugging (e.g. DisplayPort MST). */ void (*destroy)(struct drm_connector *connector); + /** + * @atomic_create_state: + * + * Allocates a pristine, initialized, state for the connector object + * and returns it. + * + * RETURNS: + * + * A new, pristine, connector state instance or an error pointer + * on failure. + */ + struct drm_connector_state *(*atomic_create_state)(struct drm_connector *connector); + /** * @atomic_duplicate_state: * * Duplicate the current atomic state for this connector and return it. * The core and helpers guarantee that any atomic state duplicated with -- 2.53.0