These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / gpu / drm / exynos / exynos_drm_plane.c
index b1180fb..1793117 100644 (file)
 
 #include <drm/exynos_drm.h>
 #include <drm/drm_plane_helper.h>
+#include <drm/drm_atomic_helper.h>
 #include "exynos_drm_drv.h"
 #include "exynos_drm_crtc.h"
 #include "exynos_drm_fb.h"
 #include "exynos_drm_gem.h"
 #include "exynos_drm_plane.h"
 
-static const uint32_t formats[] = {
-       DRM_FORMAT_XRGB8888,
-       DRM_FORMAT_ARGB8888,
-       DRM_FORMAT_NV12,
-};
-
 /*
  * This function is to get X or Y size shown via screen. This needs length and
  * start position of CRTC.
@@ -61,42 +56,21 @@ static int exynos_plane_get_size(int start, unsigned length, unsigned last)
        return size;
 }
 
-int exynos_check_plane(struct drm_plane *plane, struct drm_framebuffer *fb)
-{
-       struct exynos_drm_plane *exynos_plane = to_exynos_plane(plane);
-       int nr;
-       int i;
-
-       nr = exynos_drm_fb_get_buf_cnt(fb);
-       for (i = 0; i < nr; i++) {
-               struct exynos_drm_gem_buf *buffer = exynos_drm_fb_buffer(fb, i);
-
-               if (!buffer) {
-                       DRM_DEBUG_KMS("buffer is null\n");
-                       return -EFAULT;
-               }
-
-               exynos_plane->dma_addr[i] = buffer->dma_addr + fb->offsets[i];
-
-               DRM_DEBUG_KMS("buffer: %d, dma_addr = 0x%lx\n",
-                               i, (unsigned long)exynos_plane->dma_addr[i]);
-       }
-
-       return 0;
-}
-
-void exynos_plane_mode_set(struct drm_plane *plane, struct drm_crtc *crtc,
-                         struct drm_framebuffer *fb, int crtc_x, int crtc_y,
-                         unsigned int crtc_w, unsigned int crtc_h,
-                         uint32_t src_x, uint32_t src_y,
-                         uint32_t src_w, uint32_t src_h)
+static void exynos_plane_mode_set(struct drm_plane *plane,
+                                 struct drm_crtc *crtc,
+                                 struct drm_framebuffer *fb,
+                                 int crtc_x, int crtc_y,
+                                 unsigned int crtc_w, unsigned int crtc_h,
+                                 uint32_t src_x, uint32_t src_y,
+                                 uint32_t src_w, uint32_t src_h)
 {
        struct exynos_drm_plane *exynos_plane = to_exynos_plane(plane);
+       struct drm_display_mode *mode = &crtc->state->adjusted_mode;
        unsigned int actual_w;
        unsigned int actual_h;
 
-       actual_w = exynos_plane_get_size(crtc_x, crtc_w, crtc->mode.hdisplay);
-       actual_h = exynos_plane_get_size(crtc_y, crtc_h, crtc->mode.vdisplay);
+       actual_w = exynos_plane_get_size(crtc_x, crtc_w, mode->hdisplay);
+       actual_h = exynos_plane_get_size(crtc_y, crtc_h, mode->vdisplay);
 
        if (crtc_x < 0) {
                if (actual_w)
@@ -117,75 +91,100 @@ void exynos_plane_mode_set(struct drm_plane *plane, struct drm_crtc *crtc,
        /* set drm framebuffer data. */
        exynos_plane->src_x = src_x;
        exynos_plane->src_y = src_y;
-       exynos_plane->src_width = (actual_w * exynos_plane->h_ratio) >> 16;
-       exynos_plane->src_height = (actual_h * exynos_plane->v_ratio) >> 16;
-       exynos_plane->fb_width = fb->width;
-       exynos_plane->fb_height = fb->height;
-       exynos_plane->bpp = fb->bits_per_pixel;
-       exynos_plane->pitch = fb->pitches[0];
-       exynos_plane->pixel_format = fb->pixel_format;
+       exynos_plane->src_w = (actual_w * exynos_plane->h_ratio) >> 16;
+       exynos_plane->src_h = (actual_h * exynos_plane->v_ratio) >> 16;
 
        /* set plane range to be displayed. */
        exynos_plane->crtc_x = crtc_x;
        exynos_plane->crtc_y = crtc_y;
-       exynos_plane->crtc_width = actual_w;
-       exynos_plane->crtc_height = actual_h;
-
-       /* set drm mode data. */
-       exynos_plane->mode_width = crtc->mode.hdisplay;
-       exynos_plane->mode_height = crtc->mode.vdisplay;
-       exynos_plane->refresh = crtc->mode.vrefresh;
-       exynos_plane->scan_flag = crtc->mode.flags;
+       exynos_plane->crtc_w = actual_w;
+       exynos_plane->crtc_h = actual_h;
 
        DRM_DEBUG_KMS("plane : offset_x/y(%d,%d), width/height(%d,%d)",
                        exynos_plane->crtc_x, exynos_plane->crtc_y,
-                       exynos_plane->crtc_width, exynos_plane->crtc_height);
+                       exynos_plane->crtc_w, exynos_plane->crtc_h);
 
        plane->crtc = crtc;
 }
 
-int
-exynos_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
-                    struct drm_framebuffer *fb, int crtc_x, int crtc_y,
-                    unsigned int crtc_w, unsigned int crtc_h,
-                    uint32_t src_x, uint32_t src_y,
-                    uint32_t src_w, uint32_t src_h)
-{
+static struct drm_plane_funcs exynos_plane_funcs = {
+       .update_plane   = drm_atomic_helper_update_plane,
+       .disable_plane  = drm_atomic_helper_disable_plane,
+       .destroy        = drm_plane_cleanup,
+       .reset = drm_atomic_helper_plane_reset,
+       .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
+       .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
+};
 
-       struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
+static int exynos_plane_atomic_check(struct drm_plane *plane,
+                                    struct drm_plane_state *state)
+{
        struct exynos_drm_plane *exynos_plane = to_exynos_plane(plane);
-       int ret;
+       int nr;
+       int i;
 
-       ret = exynos_check_plane(plane, fb);
-       if (ret < 0)
-               return ret;
+       if (!state->fb)
+               return 0;
 
-       exynos_plane_mode_set(plane, crtc, fb, crtc_x, crtc_y,
-                             crtc_w, crtc_h, src_x >> 16, src_y >> 16,
-                             src_w >> 16, src_h >> 16);
+       nr = drm_format_num_planes(state->fb->pixel_format);
+       for (i = 0; i < nr; i++) {
+               struct exynos_drm_gem *exynos_gem =
+                                       exynos_drm_fb_gem(state->fb, i);
+               if (!exynos_gem) {
+                       DRM_DEBUG_KMS("gem object is null\n");
+                       return -EFAULT;
+               }
 
-       if (exynos_crtc->ops->win_commit)
-               exynos_crtc->ops->win_commit(exynos_crtc, exynos_plane->zpos);
+               exynos_plane->dma_addr[i] = exynos_gem->dma_addr +
+                                           state->fb->offsets[i];
+
+               DRM_DEBUG_KMS("buffer: %d, dma_addr = 0x%lx\n",
+                               i, (unsigned long)exynos_plane->dma_addr[i]);
+       }
 
        return 0;
 }
 
-static int exynos_disable_plane(struct drm_plane *plane)
+static void exynos_plane_atomic_update(struct drm_plane *plane,
+                                      struct drm_plane_state *old_state)
 {
+       struct drm_plane_state *state = plane->state;
+       struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(state->crtc);
        struct exynos_drm_plane *exynos_plane = to_exynos_plane(plane);
-       struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(plane->crtc);
 
-       if (exynos_crtc && exynos_crtc->ops->win_disable)
-               exynos_crtc->ops->win_disable(exynos_crtc,
-                                             exynos_plane->zpos);
+       if (!state->crtc)
+               return;
 
-       return 0;
+       exynos_plane_mode_set(plane, state->crtc, state->fb,
+                             state->crtc_x, state->crtc_y,
+                             state->crtc_w, state->crtc_h,
+                             state->src_x >> 16, state->src_y >> 16,
+                             state->src_w >> 16, state->src_h >> 16);
+
+       exynos_plane->pending_fb = state->fb;
+
+       if (exynos_crtc->ops->update_plane)
+               exynos_crtc->ops->update_plane(exynos_crtc, exynos_plane);
 }
 
-static struct drm_plane_funcs exynos_plane_funcs = {
-       .update_plane   = exynos_update_plane,
-       .disable_plane  = exynos_disable_plane,
-       .destroy        = drm_plane_cleanup,
+static void exynos_plane_atomic_disable(struct drm_plane *plane,
+                                       struct drm_plane_state *old_state)
+{
+       struct exynos_drm_plane *exynos_plane = to_exynos_plane(plane);
+       struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(old_state->crtc);
+
+       if (!old_state->crtc)
+               return;
+
+       if (exynos_crtc->ops->disable_plane)
+               exynos_crtc->ops->disable_plane(exynos_crtc,
+                                               exynos_plane);
+}
+
+static const struct drm_plane_helper_funcs plane_helper_funcs = {
+       .atomic_check = exynos_plane_atomic_check,
+       .atomic_update = exynos_plane_atomic_update,
+       .atomic_disable = exynos_plane_atomic_disable,
 };
 
 static void exynos_plane_attach_zpos_property(struct drm_plane *plane,
@@ -208,21 +207,35 @@ static void exynos_plane_attach_zpos_property(struct drm_plane *plane,
        drm_object_attach_property(&plane->base, prop, zpos);
 }
 
+enum drm_plane_type exynos_plane_get_type(unsigned int zpos,
+                                         unsigned int cursor_win)
+{
+               if (zpos == DEFAULT_WIN)
+                       return DRM_PLANE_TYPE_PRIMARY;
+               else if (zpos == cursor_win)
+                       return DRM_PLANE_TYPE_CURSOR;
+               else
+                       return DRM_PLANE_TYPE_OVERLAY;
+}
+
 int exynos_plane_init(struct drm_device *dev,
                      struct exynos_drm_plane *exynos_plane,
                      unsigned long possible_crtcs, enum drm_plane_type type,
+                     const uint32_t *formats, unsigned int fcount,
                      unsigned int zpos)
 {
        int err;
 
        err = drm_universal_plane_init(dev, &exynos_plane->base, possible_crtcs,
-                                      &exynos_plane_funcs, formats,
-                                      ARRAY_SIZE(formats), type);
+                                      &exynos_plane_funcs, formats, fcount,
+                                      type);
        if (err) {
                DRM_ERROR("failed to initialize plane\n");
                return err;
        }
 
+       drm_plane_helper_add(&exynos_plane->base, &plane_helper_funcs);
+
        exynos_plane->zpos = zpos;
 
        if (type == DRM_PLANE_TYPE_OVERLAY)