Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] drm/tidss: -ENODEV in tidss_plane_atomic_readout_state() on
  partial commits
- [Medium] drm/tidss: tidss_plane_readout_fb() ignores vertical
  decimation
- [Medium] drm/tidss: false alpha state mismatch in
  tidss_plane_atomic_readout_state()
--

commit 3be74e07814475f76096d9b92a77584c340fd8f8
Author: Maxime Ripard <[email protected]>

drm/tidss: plane: Implement hardware state readout

This commit implements the atomic_sro_readout_state and
atomic_sro_compare_state hooks for tidss planes so that planes enabled by
firmware can be read out at boot and compared after atomic commits.

> diff --git a/drivers/gpu/drm/tidss/tidss_plane.c 
> b/drivers/gpu/drm/tidss/tidss_plane.c
> index b0d5d6959b885..a9b4005d1d603 100644
> --- a/drivers/gpu/drm/tidss/tidss_plane.c
> +++ b/drivers/gpu/drm/tidss/tidss_plane.c
[ ... ]
> @@ -176,11 +180,252 @@ 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)
> +{
[ ... ]
> +     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;

[Severity: Medium]
Does checking dispc_plane_get_pixel_inc() != 1 miss vertical decimation?

In dispc_vid_calc_scaling(), vertical decimation (scale.yinc > 1) can be
enabled while scale.xinc == 1.  In that case dispc_plane_setup() still
programs DISPC_VID_PIXEL_INC to 1, but writes the decimated height
(src_h >> 16) / scale.yinc into DISPC_VID_PICTURE_SIZE and multiplies
fb_width by scale.yinc in DISPC_VID_ROW_INC:

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

As a result, tidss_plane_readout_fb() reconstructs fb->pitches[0] as
scale.yinc times the actual pitch and fb->height (along with
plane_state->src_h) as 1 / scale.yinc of the actual height, causing state
comparison mismatches after blocking commits with vertical decimation or
corrupted framebuffer geometry if enabled by firmware at boot.

[ ... ]

> +static int tidss_plane_atomic_readout_state(struct drm_plane *plane,
> +                                         struct drm_atomic_sro_state *state,
> +                                         struct drm_plane_state *plane_state)
> +{
[ ... ]
> +     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;

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

Because tidss commits planes with DRM_PLANE_COMMIT_ACTIVE_ONLY, disabling
a CRTC (or detaching a plane after its CRTC was disabled) leaves
DISPC_VID_ATTRIBUTES_ENABLE_MASK set in hardware.  On K2G, where
dispc_ovr_get_plane() always returns hw_videoport 0 (or on K3 when
firmware left an overlay layer enabled on an inactive video port),
tidss_plane_readout_crtc() still returns that inactive CRTC.

When a later blocking commit updates a property on the unbound plane
without touching the inactive CRTC,
drm_atomic_helper_sro_readout_commit_crtcs_state() only populates
state->crtcs for CRTCs included in the commit.
drm_atomic_sro_get_crtc_state() then returns NULL and
tidss_plane_atomic_readout_state() fails post-commit readout verification
with -ENODEV instead of reporting the plane as disabled.

Also, on multi-videoport K3 SoCs, dispc_ovr_get_plane() scans video ports
from 0 upward without checking whether the video port is enabled, so an
overlay layer left enabled on a disabled lower-numbered video port can
shadow an active higher-numbered video port using the same plane.

[ ... ]

> +     /*
> +      * 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 alpha mismatches
whenever userspace commits an alpha value whose high and low bytes differ?

dispc_plane_setup() programs the 8-bit global alpha register from
state->alpha >> 8 while expected->alpha keeps the full 16-bit value from
userspace (for example, 0x8000 for 50% opacity).  Replicating the read-out
byte with * 0x0101 produces actual->alpha = 0x8080, which fails the exact
16-bit comparison in drm_atomic_helper_plane_compare_state().

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=30

Reply via email to