From: Maxime Ripard <mripard@kernel.org>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>,
Simona Vetter <simona@ffwll.ch>,
Andrzej Hajda <andrzej.hajda@intel.com>,
Neil Armstrong <neil.armstrong@linaro.org>,
Robert Foss <rfoss@kernel.org>,
Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
Jonas Karlman <jonas@kwiboo.se>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Jyri Sarha <jyri.sarha@iki.fi>,
Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Cc: Devarsh Thakkar <devarsht@ti.com>,
dri-devel@lists.freedesktop.org,
Maxime Ripard <mripard@kernel.org>
Subject: [PATCH v9 35/42] drm/tidss: plane: Implement hardware state readout
Date: Fri, 20 Nov 2026 13:55:27 +0100 [thread overview]
Message-ID: <20261120-drm-state-readout-v9-35-a67c2b45b8ec@kernel.org> (raw)
In-Reply-To: <20261120-drm-state-readout-v9-0-a67c2b45b8ec@kernel.org>
When the firmware leaves a video port running, the planes feeding it
have to be read out too, otherwise the first commit sees them as
disabled and has to reprogram the whole pipeline.
Implement the atomic_sro_readout_state hook for the tidss planes. A
plane is read out as disabled if its VID pipeline isn't enabled, if
it isn't routed to an overlay layer, or if its CRTC is inactive. The
latter two matter because tidss_crtc_atomic_disable() and a disabled
video port leave the VID pipeline of their planes enabled.
Otherwise, the CRTC, source and destination rectangles, zpos, alpha and
blend mode are read from the registers. The zpos is the index of the
overlay layer the plane is routed to, which is the normalized zpos it
was committed with. The alpha is the 8-bit global alpha replicated in
both bytes of the 16-bit property, the only inverse that maps full
opacity back to 0xffff.
The framebuffer is reconstructed from the format, picture size and
increments. It has no GEM object since the firmware allocated the
buffer, which drm_gem_plane_helper_prepare_fb() and
drm_fb_dma_get_scanout_buffer() cope with. It can only be rebuilt when
the planes aren't YUV, aren't multiplanar and don't use horizontal
decimation, and the readout fails otherwise so that the core falls back
to the regular initialization. The offset into the buffer, and thus the
source origin, isn't recovered yet.
Use drm_atomic_helper_plane_compare_state() to compare the readout
state with the committed one.
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
drivers/gpu/drm/tidss/tidss_plane.c | 224 ++++++++++++++++++++++++++++++++++++
1 file changed, 224 insertions(+)
diff --git a/drivers/gpu/drm/tidss/tidss_plane.c b/drivers/gpu/drm/tidss/tidss_plane.c
index b0d5d6959b88..88f415b5439f 100644
--- a/drivers/gpu/drm/tidss/tidss_plane.c
+++ b/drivers/gpu/drm/tidss/tidss_plane.c
@@ -4,16 +4,19 @@
* Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
*/
#include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h>
+#include <drm/drm_atomic_state_readout.h>
+#include <drm/drm_atomic_state_readout_helper.h>
#include <drm/drm_blend.h>
#include <drm/drm_crtc.h>
#include <drm/drm_fb_dma_helper.h>
#include <drm/drm_fourcc.h>
#include <drm/drm_framebuffer.h>
#include <drm/drm_gem_atomic_helper.h>
+#include <drm/drm_gem_framebuffer_helper.h>
#include <drm/drm_panic_helper.h>
#include "tidss_crtc.h"
#include "tidss_dispc.h"
#include "tidss_drv.h"
@@ -174,15 +177,236 @@ static const struct drm_plane_helper_funcs tidss_primary_plane_helper_funcs = {
.atomic_enable = tidss_plane_atomic_enable,
.atomic_disable = tidss_plane_atomic_disable,
.get_scanout_buffer = drm_fb_dma_get_scanout_buffer,
};
+static const struct drm_framebuffer_funcs tidss_plane_readout_fb_funcs = {
+ .destroy = drm_gem_fb_destroy,
+};
+
+static struct drm_framebuffer *tidss_plane_readout_fb(struct drm_plane *plane)
+{
+ struct drm_device *ddev = plane->dev;
+ struct tidss_device *tidss = to_tidss(ddev);
+ struct dispc_device *dispc = tidss->dispc;
+ struct tidss_plane *tplane = to_tidss_plane(plane);
+ const struct drm_format_info *info;
+ struct drm_framebuffer *fb;
+ int ret;
+
+ fb = kzalloc_obj(*fb);
+ if (!fb)
+ return ERR_PTR(-ENOMEM);
+
+ fb->dev = plane->dev;
+
+ info = dispc_plane_get_current_format(dispc, tplane->hw_plane_id);
+ if (IS_ERR(info)) {
+ ret = PTR_ERR(info);
+ goto err_free_fb;
+ }
+
+ // TODO: Figure out YUV and multiplanar formats, along with
+ // the color encoding and range
+ if (info->is_yuv) {
+ ret = -EINVAL;
+ goto err_free_fb;
+ }
+
+ fb->format = info;
+
+ dispc_plane_get_picture_size(dispc, tplane->hw_plane_id, &fb->width,
+ &fb->height);
+
+ /*
+ * A pixel increment of 1 means that the DMA engine fetches every
+ * pixel of the source buffer. Any other value means that
+ * horizontal decimation is enabled, and the buffer geometry
+ * cannot be reconstructed from the registers.
+ */
+ if (dispc_plane_get_pixel_inc(dispc, tplane->hw_plane_id) != 1) {
+ ret = -EINVAL;
+ goto err_free_fb;
+ }
+
+ /*
+ * The row increment register holds the extra bytes between the
+ * end of a row of the picture and the beginning of the next one,
+ * which includes any padding the firmware might have programmed.
+ */
+ fb->pitches[0] = fb->width * (drm_format_info_bpp(info, 0) / 8) +
+ dispc_plane_get_row_inc(dispc, tplane->hw_plane_id) - 1;
+
+ /*
+ * TODO: The DMA base address has the offsets baked in, and there
+ * is no backing buffer to recover them from.
+ */
+ fb->offsets[0] = 0;
+
+ ret = drm_framebuffer_init(plane->dev, fb, &tidss_plane_readout_fb_funcs);
+ if (ret) {
+ kfree(fb);
+ return ERR_PTR(ret);
+ }
+
+ return fb;
+
+err_free_fb:
+ kfree(fb);
+ return ERR_PTR(ret);
+}
+
+static struct drm_crtc *tidss_plane_readout_crtc(struct drm_plane *plane,
+ int *crtc_x, int *crtc_y,
+ u32 *normalized_zpos)
+{
+ struct drm_device *dev = plane->dev;
+ struct tidss_device *tidss = to_tidss(dev);
+ struct tidss_plane *tplane = to_tidss_plane(plane);
+ struct drm_crtc *crtc;
+ u32 hw_videoport, layer;
+ int ret;
+
+ ret = dispc_ovr_get_plane(tidss->dispc, tplane->hw_plane_id,
+ &hw_videoport, crtc_x, crtc_y, &layer);
+ if (ret)
+ return ERR_PTR(ret);
+
+ *normalized_zpos = layer;
+
+ drm_for_each_crtc(crtc, dev) {
+ if (to_tidss_crtc(crtc)->hw_videoport == hw_videoport)
+ return crtc;
+ }
+
+ return ERR_PTR(-ENODEV);
+}
+
+static int tidss_plane_atomic_readout_state(struct drm_plane *plane,
+ struct drm_atomic_sro_state *state,
+ struct drm_plane_state *plane_state)
+{
+ struct drm_device *ddev = plane->dev;
+ struct tidss_device *tidss = to_tidss(ddev);
+ struct dispc_device *dispc = tidss->dispc;
+ struct tidss_plane *tplane = to_tidss_plane(plane);
+ struct drm_crtc_state *crtc_state;
+ struct drm_framebuffer *fb;
+ struct drm_crtc *crtc;
+ unsigned int in_w, in_h;
+ int crtc_x, crtc_y;
+ u32 normalized_zpos;
+ int ret;
+
+ ret = tidss_runtime_get(tidss);
+ if (ret < 0)
+ return ret;
+
+ if (!dispc_plane_is_enabled(dispc, tplane->hw_plane_id))
+ goto out;
+
+ crtc = tidss_plane_readout_crtc(plane, &crtc_x, &crtc_y,
+ &normalized_zpos);
+ if (IS_ERR(crtc)) {
+ ret = PTR_ERR(crtc);
+
+ /*
+ * tidss_crtc_atomic_disable() disables the overlay layers of
+ * the video port, but the planes on a CRTC being disabled
+ * aren't disabled in the VID pipeline. A plane that isn't
+ * routed to any layer is thus disabled.
+ */
+ if (ret == -ENODEV)
+ goto out;
+
+ goto err_runtime_pm;
+ }
+
+ crtc_state = drm_atomic_sro_get_crtc_state(state, crtc);
+ if (!crtc_state) {
+ ret = -ENODEV;
+ goto err_runtime_pm;
+ }
+
+ /*
+ * K2G has no overlay manager to tell us whether the plane is
+ * routed, and the planes of a disabled video port are left
+ * enabled: a plane on an inactive CRTC isn't scanned out.
+ */
+ if (!crtc_state->active)
+ goto out;
+
+ fb = tidss_plane_readout_fb(plane);
+ if (IS_ERR(fb)) {
+ ret = PTR_ERR(fb);
+ goto err_runtime_pm;
+ }
+
+ plane_state->fb = fb;
+ plane_state->crtc = crtc;
+ plane_state->visible = true;
+
+ dispc_plane_get_picture_size(dispc, tplane->hw_plane_id, &in_w, &in_h);
+ plane_state->src_w = in_w << 16;
+ plane_state->src_h = in_h << 16;
+
+ dispc_plane_get_size(dispc, tplane->hw_plane_id, &plane_state->crtc_w,
+ &plane_state->crtc_h);
+
+ plane_state->crtc_x = crtc_x;
+ plane_state->crtc_y = crtc_y;
+
+ /*
+ * The overlay layer index a plane is routed to is its
+ * normalized zpos, as that is what the atomic update uses as
+ * the layer index. The raw zpos property userspace set
+ * cannot be recovered from the hardware.
+ */
+ plane_state->normalized_zpos = normalized_zpos;
+ plane_state->zpos = normalized_zpos;
+
+ // TODO: Handle src_x/src_y, see DISPC_VID_BA_0
+
+ plane_state->src.x1 = 0;
+ plane_state->src.x2 = plane_state->src_w;
+ plane_state->src.y1 = 0;
+ plane_state->src.y2 = plane_state->src_h;
+ plane_state->dst.x1 = crtc_x;
+ plane_state->dst.x2 = crtc_x + plane_state->crtc_w;
+ plane_state->dst.y1 = crtc_y;
+ plane_state->dst.y2 = crtc_y + plane_state->crtc_h;
+
+ /*
+ * The global alpha register is 8 bits wide and is programmed
+ * from the high byte of the 16 bits alpha property.
+ * Replicating the byte is the only inverse that preserves the
+ * fraction of full opacity (0x00 -> 0x0000, 0xff -> 0xffff)
+ * and round-trips through a program-then-readout cycle.
+ */
+ plane_state->alpha =
+ dispc_plane_get_global_alpha(dispc, tplane->hw_plane_id) * 0x0101;
+ plane_state->pixel_blend_mode =
+ dispc_plane_get_blend_mode(dispc, tplane->hw_plane_id);
+
+ crtc_state->plane_mask |= drm_plane_mask(plane);
+
+out:
+ tidss_runtime_put(tidss);
+ return 0;
+
+err_runtime_pm:
+ tidss_runtime_put(tidss);
+ return ret;
+}
+
static const struct drm_plane_funcs tidss_plane_funcs = {
.update_plane = drm_atomic_helper_update_plane,
.disable_plane = drm_atomic_helper_disable_plane,
.destroy = drm_plane_destroy,
.atomic_create_state = drm_atomic_helper_plane_create_state,
+ .atomic_sro_readout_state = tidss_plane_atomic_readout_state,
+ .atomic_sro_compare_state = drm_atomic_helper_plane_compare_state,
.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
DRM_PANIC_PLANE_FUNCS,
};
--
2.56.1
next prev parent reply other threads:[~2026-11-20 12:58 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 12:54 [PATCH v9 00/42] drm: Implement state readout support Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 01/42] drm/atomic: Add drm_atomic_get_connector_for_encoder_locked() Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 02/42] drm/bridge-helper: Don't unlock the connection mutex after a backoff Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 03/42] drm/tests: hdmi-state-helper: Handle EDEADLK in the 420-only test Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 04/42] drm/tests: hdmi-state-helper: Handle EDEADLK in the color format test Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 05/42] drm/colorop: Export drm_atomic_helper_colorop_create_state() Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 06/42] drm/atomic: Fix private obj error handling Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 07/42] drm/atomic: Add drm_private_obj name Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 08/42] drm/bridge: Switch print_state to use bridge name Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 09/42] drm/bridge: Add drm_private_obj_is_bridge() Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 10/42] drm/fb-dma-helper: Handle framebuffers without a GEM object Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 11/42] drm/gem-atomic-helper: " Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 12/42] drm/atomic: Export drm_atomic_*_print_state Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 13/42] drm/atomic_sro: Create drm_atomic_sro_state container Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 14/42] drm/atomic_sro: Create kernel parameter to force or disable readout Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 15/42] drm/atomic_sro: Add atomic state readout infrastructure Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 16/42] drm/atomic_sro: Create documentation Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 17/42] drm/bridge: Handle bridges with hardware state readout Maxime Ripard
2026-11-20 13:18 ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 18/42] drm/mode-config: Read out hardware state in drm_mode_config_create_initial_state Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 19/42] drm/atomic_sro: Provide helpers to implement hardware state readout Maxime Ripard
2026-11-20 13:17 ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 20/42] drm/mode-config: Introduce hw_reset hook Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 21/42] drm/modeset-helper: Add drm_mode_config_helper_hw_reset() Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 22/42] drm/atomic_helper: Compare actual and readout states once the commit is done Maxime Ripard
2026-11-20 13:17 ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 23/42] drm/atomic-state-helper: Provide comparison macros Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 24/42] drm/atomic-state-helper: Provide atomic_compare_state helpers Maxime Ripard
2026-11-20 13:14 ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 25/42] drm/atomic-helper: Document State Read-Out as a state initialization approach Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 26/42] drm/tests: kunit: Add a drm_printer helper Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 27/42] drm/tests: Add tests for the atomic state readout Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 28/42] drm/encoder: Create atomic_sro_get_current_crtc hook Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 29/42] drm/bridge: display-connector: Implement readout support Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 30/42] drm/bridge_connector: Implement hw readout for connector Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 31/42] drm/tidss: Implement hw_reset Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 32/42] drm/tidss: crtc: Implement hardware state readout Maxime Ripard
2026-11-20 13:14 ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 33/42] drm/tidss: encoder: " Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 34/42] drm/tidss: kms: Hook up " Maxime Ripard
2026-11-20 13:25 ` sashiko-bot
2026-11-20 12:55 ` Maxime Ripard [this message]
2026-11-20 13:28 ` [PATCH v9 35/42] drm/tidss: plane: Implement " sashiko-bot
2026-11-20 12:55 ` [PATCH v9 36/42] drm/tidss: dispc: Add hardware state readout helpers Maxime Ripard
2026-11-20 13:17 ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 37/42] drm/tidss: encoder: Implement atomic_sro_get_current_crtc Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 38/42] drm/bridge: sii902x: Implement hw state readout Maxime Ripard
2026-11-20 13:26 ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 39/42] drm/panel: Implement state readout support Maxime Ripard
2026-11-20 12:55 ` [PATCH DO NOT MERGE v9 40/42] fixup! drm/tidss: dispc: Add hardware state readout helpers Maxime Ripard
2026-11-20 12:55 ` [PATCH DO NOT MERGE v9 41/42] drm/tidss: oldi: Implement hardware state readout Maxime Ripard
2026-11-20 13:34 ` sashiko-bot
2026-11-20 12:55 ` [PATCH HACK v9 42/42] drm/panel: Prepare and enable panels read out as active Maxime Ripard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120-drm-state-readout-v9-35-a67c2b45b8ec@kernel.org \
--to=mripard@kernel.org \
--cc=Laurent.pinchart@ideasonboard.com \
--cc=airlied@gmail.com \
--cc=andrzej.hajda@intel.com \
--cc=devarsht@ti.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jernej.skrabec@gmail.com \
--cc=jonas@kwiboo.se \
--cc=jyri.sarha@iki.fi \
--cc=maarten.lankhorst@linux.intel.com \
--cc=neil.armstrong@linaro.org \
--cc=rfoss@kernel.org \
--cc=simona@ffwll.ch \
--cc=tomi.valkeinen@ideasonboard.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.