MLK-16927: drm: imx: dcss: Add basic plane checks
authorLaurentiu Palcu <laurentiu.palcu@nxp.com>
Tue, 21 Nov 2017 10:22:18 +0000 (12:22 +0200)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 20:47:06 +0000 (15:47 -0500)
Currently, there are no plane checks and the user can try set up a plane
with a CRTC size that is actually bigger than the current CRTC mode.
Because, currently, the driver does not support cropping, all planes
with CRTC sizes bigger than the actual CRTC mode will be rejected.

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

index 2a1d919..8b30839 100644 (file)
@@ -118,6 +118,8 @@ static int dcss_plane_atomic_check(struct drm_plane *plane,
 {
        struct drm_framebuffer *fb = state->fb;
        struct drm_gem_cma_object *cma_obj;
+       struct drm_crtc_state *crtc_state;
+       int hdisplay, vdisplay;
 
        if (!fb)
                return 0;
@@ -128,10 +130,17 @@ static int dcss_plane_atomic_check(struct drm_plane *plane,
        cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
        WARN_ON(!cma_obj);
 
-       /*
-        * TODO: more checks are probably needed here... I'll figure them
-        * out after I start testing.
-        */
+       crtc_state = drm_atomic_get_existing_crtc_state(state->state,
+                                                       state->crtc);
+
+       hdisplay = crtc_state->adjusted_mode.hdisplay;
+       vdisplay = crtc_state->adjusted_mode.vdisplay;
+
+       /* We don't support cropping yet */
+       if (state->crtc_x < 0 || state->crtc_y < 0 ||
+           state->crtc_x + state->crtc_w > hdisplay ||
+           state->crtc_y + state->crtc_h > vdisplay)
+               return -EINVAL;
 
        return 0;
 }