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 <[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 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/[email protected]?part=35

Reply via email to