From mboxrd@z Thu Jan 1 00:00:00 1970 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 42D4139B4A1 for ; Thu, 23 Apr 2026 10:19:09 +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=1776939549; cv=none; b=U+sbNDe5h6fcbYuOlgu5B/ThcIbRcKLty/aPCjDEaOmaICl0l8fBHn0c4P2GlPfqFmxSQLN34un16xyeYFYwF2KWePSGYEgLm4GXLbhMMFnOzXV7eH8hhjCbAa2XB88koFO4P/I24rZ40yRJVgCPd4lSkh8Pp2oAcrR+HvUt9Js= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776939549; c=relaxed/simple; bh=1DSGsi22+NoY/S95xpA53bv2mm4Bkkh6VRAzt5Rmk/A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qAU0TCP9fAq96nNf1XjrrEREYFQPwFPAUx7E2CcVzsWX4TesjX+aaiWphSmTxkbL08zyctXcxYC0+r+sq/qA4lu00RlqR98U57x6JXow679Y7IpgZmi7varQ0xGLmTZh+Wdt8kf94lqfUtRk+9TOleyW6xXxlg5LXf/91ulkYcQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xxu8j77S; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Xxu8j77S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89803C2BCB2; Thu, 23 Apr 2026 10:19:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776939548; bh=1DSGsi22+NoY/S95xpA53bv2mm4Bkkh6VRAzt5Rmk/A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Xxu8j77S+LODXcTA9eqkkHPk9lhlGqEeYUlk9IxV3NYiuVr65u7HDo1Gc5bg5s2mM kW3ZGiy9PlJ9lIOZ5MDbk+OqFZe8EoxlT9SJe+MHpqrRjxMBVbuYOpmpML6Dq8YLBm faXxJgV4jpZgDe0u2qaRmAImg+AoYVUp9vW0H6PGtuOMSh2kOjIxLchZWrBlsKODPc rf0BQxBkRWQW2r43JCfQKi57t/m5hXSReYMGAWEBjv5RfE30Eiky5J68NSg8Mkg2Gk X6wPYxQGVtOvrH1J/lT4BMbd0OWIsnDGqvl2G8ROdtexomeJVN/Bh5U9vPlc12lBfc AyhpWSnG9DX4g== From: Maxime Ripard Date: Thu, 23 Apr 2026 12:18:26 +0200 Subject: [PATCH v2 13/28] drm/atomic_sro: Add function to install state into drm objects Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260423-drm-state-readout-v2-13-8549f87cb978@kernel.org> References: <20260423-drm-state-readout-v2-0-8549f87cb978@kernel.org> In-Reply-To: <20260423-drm-state-readout-v2-0-8549f87cb978@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Jyri Sarha , Tomi Valkeinen Cc: Devarsh Thakkar , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Maxime Ripard X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=10090; i=mripard@kernel.org; h=from:subject:message-id; bh=1DSGsi22+NoY/S95xpA53bv2mm4Bkkh6VRAzt5Rmk/A=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDJkvP74VvZ890STd/nTSxi8X+p5Xc9/YalATe/H5O5vH4 t8afZj5O6ayMAhzMsiKKbI8kQk7vbx9cZWD/cofMHNYmUCGMHBxCsBE9vky1oo5FEVt7dedKcHK xnnoX3SQWXzAJNZjfdL9//bJaud9ONml3XhFl9XwgeH+I3EXfq5dx1hn/ij+JM+Cj+0Vqd8uCH9 rOKX3omru9Mne/MGfT6hO2RNss2LzTucOn8e55m+P2+3ivJMCAA== X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D Once the SRO state has been built from hardware, it needs to be installed as the current state of each KMS object. Add drm_atomic_sro_install_state() which walks through the SRO state container and assigns each readout state to its object's state pointer. Before each assignment, it calls the optional atomic_sro_install_state hook to give drivers a chance to acquire the resources they need to keep the hardware state active. Also introduce the atomic_sro_install_state hook in the plane, CRTC, connector, and private object funcs vtables. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/drm_atomic_sro.c | 97 ++++++++++++++++++++++++++++++++++++++++ include/drm/drm_atomic.h | 18 ++++++++ include/drm/drm_atomic_sro.h | 2 + include/drm/drm_connector.h | 18 ++++++++ include/drm/drm_crtc.h | 18 ++++++++ include/drm/drm_plane.h | 18 ++++++++ 6 files changed, 171 insertions(+) diff --git a/drivers/gpu/drm/drm_atomic_sro.c b/drivers/gpu/drm/drm_atomic_sro.c index 3eb22c654973..7ff67c140ff2 100644 --- a/drivers/gpu/drm/drm_atomic_sro.c +++ b/drivers/gpu/drm/drm_atomic_sro.c @@ -515,5 +515,102 @@ void drm_atomic_sro_set_private_obj_state(struct drm_atomic_sro_state *state, drm_dbg_atomic(state->dev, "Added new private object %p state %p to readout state %p\n", obj, obj_state, state); } EXPORT_SYMBOL(drm_atomic_sro_set_private_obj_state); + +/** + * drm_atomic_sro_install_state - install readout state into DRM objects + * @state: SRO state to install + * + * Takes a &struct drm_atomic_sro_state built by + * drm_atomic_helper_sro_build_state() and installs its contents as the + * current state of each DRM object (setting &drm_crtc.state, + * &drm_plane.state, &drm_connector.state and &drm_private_obj.state). + * + * For each object, the optional atomic_sro_install_state hook is + * called before the state pointer is updated, allowing drivers to + * perform any needed action. + */ +void drm_atomic_sro_install_state(struct drm_atomic_sro_state *state) +{ + unsigned int i; + + for (i = 0; i < state->dev->mode_config.num_connector; i++) { + struct drm_connector *conn = state->connectors[i].ptr; + const struct drm_connector_funcs *conn_funcs = conn->funcs; + struct drm_connector_state *conn_state = + state->connectors[i].state; + + if (conn->state) { + conn_funcs->atomic_destroy_state(conn, conn->state); + conn->state = NULL; + } + + if (conn_funcs->atomic_sro_install_state) + conn_funcs->atomic_sro_install_state(conn, conn_state); + + conn->state = conn_state; + state->connectors[i].state = NULL; + state->connectors[i].ptr = NULL; + drm_connector_put(conn); + } + + for (i = 0; i < state->dev->mode_config.num_crtc; i++) { + struct drm_crtc *crtc = state->crtcs[i].ptr; + const struct drm_crtc_funcs *crtc_funcs = crtc->funcs; + struct drm_crtc_state *crtc_state = state->crtcs[i].state; + + if (crtc->state) { + crtc_funcs->atomic_destroy_state(crtc, crtc->state); + crtc->state = NULL; + } + + if (crtc_funcs->atomic_sro_install_state) + crtc_funcs->atomic_sro_install_state(crtc, crtc_state); + + crtc->state = crtc_state; + state->crtcs[i].state = NULL; + state->crtcs[i].ptr = NULL; + } + + for (i = 0; i < state->dev->mode_config.num_total_plane; i++) { + struct drm_plane *plane = state->planes[i].ptr; + const struct drm_plane_funcs *plane_funcs = plane->funcs; + struct drm_plane_state *plane_state = state->planes[i].state; + + if (plane->state) { + plane_funcs->atomic_destroy_state(plane, plane->state); + plane->state = NULL; + } + + if (plane_funcs->atomic_sro_install_state) + plane_funcs->atomic_sro_install_state(plane, + plane_state); + + plane->state = plane_state; + state->planes[i].state = NULL; + state->planes[i].ptr = NULL; + } + + for (i = 0; i < count_private_obj(state->dev); i++) { + struct drm_private_obj *obj = state->private_objs[i].ptr; + const struct drm_private_state_funcs *obj_funcs = obj->funcs; + struct drm_private_state *obj_state = + state->private_objs[i].state; + + if (obj->state) { + obj_funcs->atomic_destroy_state(obj, obj->state); + obj->state = NULL; + } + + if (obj_funcs->atomic_sro_install_state) + obj_funcs->atomic_sro_install_state(obj, + obj_state); + + obj->state = obj_state; + state->private_objs[i].state = NULL; + state->private_objs[i].ptr = NULL; + } + state->num_private_objs = 0; +} +EXPORT_SYMBOL(drm_atomic_sro_install_state); diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h index 554dde45b799..81290c4a5ad3 100644 --- a/include/drm/drm_atomic.h +++ b/include/drm/drm_atomic.h @@ -318,10 +318,28 @@ struct drm_private_state_funcs { */ int (*atomic_sro_readout_state)(struct drm_private_obj *obj, struct drm_atomic_sro_state *state, struct drm_private_state *obj_state); + /** + * @atomic_sro_install_state: + * + * This optional hook is called when a state read out from + * hardware is about to be installed as the private object's + * current state. + * + * It allows drivers to acquire the resources needed to keep + * the current hardware state active, such as power domains, + * clocks, or interrupts. + * + * This hook cannot fail. It is called during + * drm_atomic_sro_install_state(), which is part of the + * hardware state readout initialization sequence. + */ + void (*atomic_sro_install_state)(struct drm_private_obj *obj, + struct drm_private_state *obj_state); + /** * @atomic_print_state: * * If driver subclasses &struct drm_private_state, it should implement * this optional hook for printing additional driver specific state. diff --git a/include/drm/drm_atomic_sro.h b/include/drm/drm_atomic_sro.h index 6e5262384c71..195154850ab4 100644 --- a/include/drm/drm_atomic_sro.h +++ b/include/drm/drm_atomic_sro.h @@ -48,6 +48,8 @@ drm_atomic_sro_get_private_obj_state(struct drm_atomic_sro_state *state, struct drm_private_obj *private_obj); void drm_atomic_sro_set_private_obj_state(struct drm_atomic_sro_state *state, struct drm_private_obj *obj, struct drm_private_state *obj_state); +void drm_atomic_sro_install_state(struct drm_atomic_sro_state *state); + #endif /* DRM_ATOMIC_SRO_H_ */ diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h index db0d2bb80bd5..3cd20198a5e7 100644 --- a/include/drm/drm_connector.h +++ b/include/drm/drm_connector.h @@ -1608,10 +1608,28 @@ struct drm_connector_funcs { */ int (*atomic_sro_readout_state)(struct drm_connector *connector, struct drm_atomic_sro_state *state, struct drm_connector_state *conn_state); + /** + * @atomic_sro_install_state: + * + * This optional hook is called when a state read out from + * hardware is about to be installed as the connector's current + * state. + * + * It allows drivers to acquire the resources needed to keep + * the current hardware state active, such as power domains, + * clocks, or interrupts. + * + * This hook cannot fail. It is called during + * drm_atomic_sro_install_state(), which is part of the + * hardware state readout initialization sequence. + */ + void (*atomic_sro_install_state)(struct drm_connector *conn, + struct drm_connector_state *conn_state); + /** * @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 diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index b6d4a2341776..146da65448dc 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -675,10 +675,28 @@ struct drm_crtc_funcs { */ int (*atomic_sro_readout_state)(struct drm_crtc *crtc, struct drm_atomic_sro_state *state, struct drm_crtc_state *crtc_state); + /** + * @atomic_sro_install_state: + * + * This optional hook is called when a state read out from + * hardware is about to be installed as the CRTC's current + * state. + * + * It allows drivers to acquire the resources needed to keep + * the current hardware state active, such as power domains, + * clocks, or interrupts. + * + * This hook cannot fail. It is called during + * drm_atomic_sro_install_state(), which is part of the + * hardware state readout initialization sequence. + */ + void (*atomic_sro_install_state)(struct drm_crtc *crtc, + struct drm_crtc_state *crtc_state); + /** * @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 diff --git a/include/drm/drm_plane.h b/include/drm/drm_plane.h index 22a16bc63f3e..1e02728838e2 100644 --- a/include/drm/drm_plane.h +++ b/include/drm/drm_plane.h @@ -425,10 +425,28 @@ struct drm_plane_funcs { */ int (*atomic_sro_readout_state)(struct drm_plane *plane, struct drm_atomic_sro_state *state, struct drm_plane_state *plane_state); + /** + * @atomic_sro_install_state: + * + * This optional hook is called when a state read out from + * hardware is about to be installed as the plane's current + * state. + * + * It allows drivers to acquire the resources needed to keep + * the current hardware state active, such as power domains, + * clocks, or interrupts. + * + * This hook cannot fail. It is called during + * drm_atomic_sro_install_state(), which is part of the + * hardware state readout initialization sequence. + */ + void (*atomic_sro_install_state)(struct drm_plane *plane, + struct drm_plane_state *plane_state); + /** * @atomic_duplicate_state: * * Duplicate the current atomic state for this plane and return it. * The core and helpers guarantee that any atomic state duplicated with -- 2.53.0