MA-12939: drm/imx/dcss: check source plane size
authorLaurentiu Palcu <laurentiu.palcu@nxp.com>
Fri, 23 Nov 2018 12:50:02 +0000 (14:50 +0200)
committerLeonard Crestez <leonard.crestez@nxp.com>
Wed, 17 Apr 2019 23:51:34 +0000 (02:51 +0300)
DCSS has some minimum requirements for the source buffer size that need
to be respected in order to not freeze DPR and/or scaler.

This patch will add the checks and return an error if source plane size
is not allowed. Userspace will need to gracefully handle this.

Signed-off-by: Laurentiu Palcu <laurentiu.palcu@nxp.com>
drivers/gpu/drm/imx/dcss/dcss-plane.c

index ab32943..64f18f7 100644 (file)
@@ -209,6 +209,20 @@ static bool dcss_plane_can_rotate(u32 pixel_format, bool mod_present,
        return !!(rotation & supported_rotation);
 }
 
+static bool dcss_plane_is_source_size_allowed(u16 src_w, u16 src_h, u32 pix_fmt)
+{
+       if (src_w < 64 &&
+           (pix_fmt == DRM_FORMAT_NV12 || pix_fmt == DRM_FORMAT_NV21 ||
+            pix_fmt == DRM_FORMAT_P010))
+               return false;
+       else if (src_w < 32 &&
+                (pix_fmt == DRM_FORMAT_UYVY || pix_fmt == DRM_FORMAT_VYUY ||
+                 pix_fmt == DRM_FORMAT_YUYV || pix_fmt == DRM_FORMAT_YVYU))
+               return false;
+
+       return src_w >= 16 && src_h >= 8;
+}
+
 static int dcss_plane_atomic_check(struct drm_plane *plane,
                                   struct drm_plane_state *state)
 {
@@ -241,6 +255,13 @@ static int dcss_plane_atomic_check(struct drm_plane *plane,
        disp_rect.x2 = hdisplay;
        disp_rect.y2 = vdisplay;
 
+       if (!dcss_plane_is_source_size_allowed(state->src_w >> 16,
+                                              state->src_h >> 16,
+                                              fb->format->format)) {
+               DRM_DEBUG_KMS("Source plane size is not allowed!\n");
+               return -EINVAL;
+       }
+
        /* make sure the crtc is visible */
        if (!drm_rect_intersect(&crtc_rect, &disp_rect)) {
                state->visible = false;