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 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 5E0DBCD4851 for ; Tue, 12 May 2026 13:07:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type: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=KFy1xp1Ee/L5DKOofVeqTON2dx2CNLYNc5dYLRdcWes=; b=pgsytR9uIMAMqnM7h7DQE8K7K4 Y4kbPvlk7qnP+b0F0VxGisx+0p9qAxTBjDVVC7I55E9BxZ+CaHGGZX2l5W9l2eEcwefg+5vivb1VJ bgtH+XxajVIInqBi9/IQUoGAuf1VMBqCFySHW1Zoy9q/xloxgGsN5DjK88Lf9rCGzVT3flYyB9wRS 6h9mga0wpCTooPMWQsu2BvxM/FWru4cbG6+IgfEP+mrsTd3BERe8tqn/ZV8xeId/wmTNds+vYQR2W dCfPBA/E10BiOtK50Xppj6Ai/g6Uh8Gr14t14KX+eK8zmmTCtursgOkmuaMyTnnPSuMAKiTKjIoCl SAptbcwA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wMmp2-0000000GkxC-2zxN; Tue, 12 May 2026 13:06:52 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wMmoy-0000000GktA-2jMO for linux-arm-kernel@lists.infradead.org; Tue, 12 May 2026 13:06:49 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 4FDE141869; Tue, 12 May 2026 13:06:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9964AC2BCF7; Tue, 12 May 2026 13:06:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778591208; bh=qPK0h/dFSo293ccLyG7pv0Iwc28UYnE7zsHTmGqDLXg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=bgtl0qw0S1HtJHKjUo0l4BjRLEEPmoULtuacXVJUiPWcSRlg8Oat5gVXaTNdiSKLJ yhwrW/+O8ufgzEPmGcUFRHk9YMFXamfJZq4RZVJeBt1ZkO4ONxB+GCGs+k0Jo4uYr1 6FT6Nq+rw0xwLRCPS+0lgtJo49EfsAaTEApRN/kdZCzvRJLuHm9fW9NUCwmN4P1ByZ iLcLrKQnugL7LBrows7espk2H1s+UwghlWlWVEUwf4xObcHbxOR/7tWv8k3ov7SFHk llWjgXioyVCv8eHb1vVZixVXnVlPU10xwsdY/SGsFO5F9pbr+h7m/GrEC421wlBnug au0TnD6p79R+w== From: Maxime Ripard Date: Tue, 12 May 2026 15:06:10 +0200 Subject: [PATCH v4 12/20] drm/crtc: Add new atomic_create_state callback MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260512-drm-mode-config-init-v4-12-591dfdcc1bf9@kernel.org> References: <20260512-drm-mode-config-init-v4-0-591dfdcc1bf9@kernel.org> In-Reply-To: <20260512-drm-mode-config-init-v4-0-591dfdcc1bf9@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.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6826; i=mripard@kernel.org; h=from:subject:message-id; bh=qPK0h/dFSo293ccLyG7pv0Iwc28UYnE7zsHTmGqDLXg=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDFnMqgeK5OUcv5wXvLz3w5OfEXyu1Vw3Vj3/deyz3o/Oz Jk3Hyl975jKwiDMySArpsjyRCbs9PL2xVUO9it/wMxhZQIZwsDFKQAXWcpYZ+Fz/oT+wws9Rvyl 24yF7txoll/3fUGtzv+0IJfd5q97N2zvPymziN2v9cyxrWf3LJydwdjwQMxgQa2M/ZETTj4PElz 0PvpskUp3ipGSO9Bo4aa+1W9GueMXOfcmpglzjU2S/3x9vgUA X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260512_060648_754221_1788C3FA X-CRM114-Status: GOOD ( 22.53 ) 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 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 state, 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. reset() also isn't fallible, which makes it harder to handle initialization errors properly. This is only really relevant for some drivers though, 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. Continue the transition to the new pattern with CRTCs. Reviewed-by: Dmitry Baryshkov Signed-off-by: Maxime Ripard --- drivers/gpu/drm/drm_atomic_state_helper.c | 25 +++++++++++++++++++++++ drivers/gpu/drm/drm_mode_config.c | 34 ++++++++++++++++++++++++++++++- include/drm/drm_atomic_state_helper.h | 2 ++ include/drm/drm_crtc.h | 16 +++++++++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_atomic_state_helper.c b/drivers/gpu/drm/drm_atomic_state_helper.c index b277f92f4532..8762171c9432 100644 --- a/drivers/gpu/drm/drm_atomic_state_helper.c +++ b/drivers/gpu/drm/drm_atomic_state_helper.c @@ -122,10 +122,35 @@ void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc) __drm_atomic_helper_crtc_reset(crtc, crtc_state); } EXPORT_SYMBOL(drm_atomic_helper_crtc_reset); +/** + * drm_atomic_helper_crtc_create_state - default &drm_crtc_funcs.atomic_create_state hook for crtcs + * @crtc: crtc object + * + * Allocates and initializes pristine @drm_crtc_state. + * + * This is useful for drivers that don't subclass @drm_crtc_state. + * + * RETURNS: + * Pointer to new crtc state, or ERR_PTR on failure. + */ +struct drm_crtc_state *drm_atomic_helper_crtc_create_state(struct drm_crtc *crtc) +{ + struct drm_crtc_state *state; + + state = kzalloc_obj(*state); + if (!state) + return ERR_PTR(-ENOMEM); + + __drm_atomic_helper_crtc_state_init(state, crtc); + + return state; +} +EXPORT_SYMBOL(drm_atomic_helper_crtc_create_state); + /** * __drm_atomic_helper_crtc_duplicate_state - copy atomic CRTC state * @crtc: CRTC object * @state: atomic CRTC state * diff --git a/drivers/gpu/drm/drm_mode_config.c b/drivers/gpu/drm/drm_mode_config.c index fa609357858f..2e2cd18a14b4 100644 --- a/drivers/gpu/drm/drm_mode_config.c +++ b/drivers/gpu/drm/drm_mode_config.c @@ -206,10 +206,39 @@ static int drm_mode_config_plane_reset_with_create_state(struct drm_plane *plane } return drm_mode_config_plane_create_state(plane); } +static int drm_mode_config_crtc_create_state(struct drm_crtc *crtc) +{ + struct drm_crtc_state *crtc_state; + + if (!crtc->funcs->atomic_create_state) + return 0; + + crtc_state = crtc->funcs->atomic_create_state(crtc); + if (IS_ERR(crtc_state)) + return PTR_ERR(crtc_state); + + if (drm_dev_has_vblank(crtc->dev)) + drm_crtc_vblank_reset(crtc); + + crtc->state = crtc_state; + + return 0; +} + +static int drm_mode_config_crtc_reset_with_create_state(struct drm_crtc *crtc) +{ + if (crtc->state) { + crtc->funcs->atomic_destroy_state(crtc, crtc->state); + crtc->state = NULL; + } + + return drm_mode_config_crtc_create_state(crtc); +} + /** * drm_mode_config_reset - call ->reset callbacks * @dev: drm device * * This functions calls all the crtc's, encoder's and connector's ->reset @@ -237,13 +266,16 @@ void drm_mode_config_reset(struct drm_device *dev) plane->funcs->reset(plane); else if (plane->funcs->atomic_create_state) drm_mode_config_plane_reset_with_create_state(plane); } - drm_for_each_crtc(crtc, dev) + drm_for_each_crtc(crtc, dev) { if (crtc->funcs->reset) crtc->funcs->reset(crtc); + else if (crtc->funcs->atomic_create_state) + drm_mode_config_crtc_reset_with_create_state(crtc); + } drm_for_each_encoder(encoder, dev) if (encoder->funcs && encoder->funcs->reset) encoder->funcs->reset(encoder); diff --git a/include/drm/drm_atomic_state_helper.h b/include/drm/drm_atomic_state_helper.h index 0bb72453464a..213f7e298008 100644 --- a/include/drm/drm_atomic_state_helper.h +++ b/include/drm/drm_atomic_state_helper.h @@ -43,10 +43,12 @@ struct drm_device; void __drm_atomic_helper_crtc_state_init(struct drm_crtc_state *state, struct drm_crtc *crtc); void __drm_atomic_helper_crtc_reset(struct drm_crtc *crtc, struct drm_crtc_state *state); void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc); +struct drm_crtc_state * +drm_atomic_helper_crtc_create_state(struct drm_crtc *crtc); void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc, struct drm_crtc_state *state); struct drm_crtc_state * drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc); void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state); diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index c6dbe8b7db9e..152349f973e3 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -636,10 +636,26 @@ struct drm_crtc_funcs { * 0 on success or a negative error code on failure. */ int (*set_property)(struct drm_crtc *crtc, struct drm_property *property, uint64_t val); + /** + * @atomic_create_state: + * + * Allocate a pristine, initialized, state for the CRTC object + * and return it. This callback must have no side effects: in + * particular, the returned state must not be assigned to the + * object's state pointer and it must not affect the hardware + * state. + * + * RETURNS: + * + * A new, pristine, CRTC state instance or an error pointer + * on failure. + */ + struct drm_crtc_state *(*atomic_create_state)(struct drm_crtc *crtc); + /** * @atomic_duplicate_state: * * Duplicate the current atomic state for this CRTC and return it. * The core and helpers guarantee that any atomic state duplicated with -- 2.54.0