dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Maxime Ripard" <mripard@kernel.org>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v9 35/42] drm/tidss: plane: Implement hardware state readout
Date: Fri, 20 Nov 2026 13:28:35 +0000	[thread overview]
Message-ID: <sashiko-outbox-225240@kernel.org> (raw)
In-Reply-To: <20261120-drm-state-readout-v9-35-a67c2b45b8ec@kernel.org>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] drm/tidss: build failure from calling dispc readout helpers
  before definition
- [Medium] drm/tidss: plane readout miscalculates pitch and height on
  vertical decimation
- [Medium] drm/tidss: unhandled NULL crtc_state in
  tidss_plane_atomic_readout_state()
- [Medium] drm/tidss: false state mismatch in
  tidss_plane_atomic_readout_state()
--

commit 06a115c7e84f276955999ca7175b2ba65fbac981
Author: Maxime Ripard <mripard@kernel.org>

drm/tidss: plane: Implement hardware state readout

This commit implements the atomic_sro_readout_state and
atomic_sro_compare_state hooks for tidss planes to reconstruct plane and
framebuffer state from the hardware registers.

> diff --git a/drivers/gpu/drm/tidss/tidss_plane.c b/drivers/gpu/drm/tidss/tidss_plane.c
> index b0d5d6959b885..88f415b5439f4 100644
> --- a/drivers/gpu/drm/tidss/tidss_plane.c
> +++ b/drivers/gpu/drm/tidss/tidss_plane.c
[ ... ]
> @@ -176,11 +179,232 @@ static const struct drm_plane_helper_funcs tidss_primary_plane_helper_funcs = {
>  	.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);

[Severity: High]
Does this fail to build at this commit in the series?

tidss_plane_readout_fb(), tidss_plane_readout_crtc(), and
tidss_plane_atomic_readout_state() call dispc_plane_get_current_format(),
dispc_plane_get_picture_size(), dispc_plane_get_pixel_inc(),
dispc_plane_get_row_inc(), dispc_ovr_get_plane(),
dispc_plane_is_enabled(), dispc_plane_get_size(),
dispc_plane_get_global_alpha(), and dispc_plane_get_blend_mode(), which
are only declared and defined in the subsequent commit "drm/tidss: dispc:
Add hardware state readout helpers".  Reordering that patch before this
one would keep the series bisectable.

[ ... ]

> +	/*
> +	 * 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;

[Severity: Medium]
Can vertical decimation without horizontal decimation cause
tidss_plane_readout_fb() and tidss_plane_atomic_readout_state() to
miscalculate fb->pitches[0], fb->height, plane_state->src_h, and
plane_state->src.y2?

In dispc_vid_calc_scaling(), vertical decimation (scale.yinc > 1) is
computed independently of horizontal decimation (scale.xinc):

drivers/gpu/drm/tidss/tidss_dispc.c:dispc_plane_setup() {
    ...
	dispc_vid_write(dispc, hw_plane, DISPC_VID_PICTURE_SIZE,
			FIELD_PREP(DISPC_VID_PICTURE_SIZE_MEMSIZEY_MASK, scale.in_h - 1) |
			FIELD_PREP(DISPC_VID_PICTURE_SIZE_MEMSIZEX_MASK, scale.in_w - 1));
    ...
	dispc_vid_write(dispc, hw_plane, DISPC_VID_ROW_INC,
			pixinc(1 + (scale.yinc * fb_width -
				    scale.xinc * scale.in_w),
			       cpp));
    ...
}

When a plane downscales vertically with scale.xinc == 1 and
scale.yinc > 1, DISPC_VID_PIXEL_INC remains 1, so readout succeeds but
computes fb->pitches[0] as scale.yinc * pitches[0] and reads back the
decimated height (src_h >> 16) / scale.yinc from DISPC_VID_PICTURE_SIZE.
This triggers post-commit state mismatch warnings in
drm_atomic_sro_readout_and_compare() and reconstructs bogus geometry if
firmware leaves vertical decimation enabled at boot.

[ ... ]

> +	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;

[Severity: Medium]
Should a NULL crtc_state jump to out instead of returning -ENODEV?

Because tidss_atomic_commit_tail() commits planes with
DRM_PLANE_COMMIT_ACTIVE_ONLY, disabling a CRTC leaves
DISPC_VID_ATTRIBUTES_ENABLE set on its planes, and on K2G (which has no
overlay manager) or when firmware leaves a plane routed to a disabled
video port, tidss_plane_readout_crtc() still returns that inactive CRTC.
If a later blocking commit updates a property on that unbound plane
without touching the inactive CRTC,
drm_atomic_helper_sro_readout_commit_crtcs_state() does not populate that
CRTC in state, so drm_atomic_sro_get_crtc_state() returns NULL and aborts
post-commit state readout with -ENODEV instead of treating the plane as
disabled.

[ ... ]

> +	// 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,

[Severity: Medium]
Will drm_atomic_helper_plane_compare_state() report false state mismatches
whenever a plane is committed with non-zero src_x/src_y or a 16-bit alpha
whose high and low bytes differ?

drm_atomic_helper_check_plane_state() sets expected->src to
(src_x, src_y) .. (src_x + src_w, src_y + src_h), whereas
tidss_plane_atomic_readout_state() hardcodes actual->src.x1 and
actual->src.y1 to 0, causing the src.{x1,x2,y1,y2} checks in
drm_atomic_helper_plane_compare_state() to fail on any cropped or panned
plane.  Similarly, dispc_plane_setup() programs DISPC_VID_GLOBAL_ALPHA
with state->alpha >> 8, so comparing expected->alpha against the
replicated actual->alpha fails whenever (alpha >> 8) != (alpha & 0xff)
(for example, 0x8000).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-drm-state-readout-v9-0-a67c2b45b8ec@kernel.org?part=35

  reply	other threads:[~2026-11-20 13:28 UTC|newest]

Thread overview: 51+ 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 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 ` [PATCH v9 35/42] drm/tidss: plane: Implement " Maxime Ripard
2026-11-20 13:28   ` sashiko-bot [this message]
2026-11-20 12:55 ` [PATCH v9 36/42] drm/tidss: dispc: Add hardware state readout helpers Maxime Ripard
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=sashiko-outbox-225240@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=mripard@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox