drm/i915: Ensure plane->state->fb stays in sync with plane->fb
[deliverable/linux.git] / drivers / gpu / drm / i915 / intel_display.c
index d94ab6eb07c531bc7eda9f8fa03c4307a8a59407..e5c057996353b452329a7f63fdd46c936576765c 100644 (file)
@@ -37,6 +37,7 @@
 #include <drm/i915_drm.h>
 #include "i915_drv.h"
 #include "i915_trace.h"
+#include <drm/drm_atomic_helper.h>
 #include <drm/drm_dp_helper.h>
 #include <drm/drm_crtc_helper.h>
 #include <drm/drm_plane_helper.h>
@@ -2316,7 +2317,7 @@ unsigned long intel_gen4_compute_page_offset(int *x, int *y,
        }
 }
 
-int intel_format_to_fourcc(int format)
+static int i9xx_format_to_fourcc(int format)
 {
        switch (format) {
        case DISPPLANE_8BPP:
@@ -2337,8 +2338,35 @@ int intel_format_to_fourcc(int format)
        }
 }
 
-static bool intel_alloc_plane_obj(struct intel_crtc *crtc,
-                                 struct intel_plane_config *plane_config)
+static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
+{
+       switch (format) {
+       case PLANE_CTL_FORMAT_RGB_565:
+               return DRM_FORMAT_RGB565;
+       default:
+       case PLANE_CTL_FORMAT_XRGB_8888:
+               if (rgb_order) {
+                       if (alpha)
+                               return DRM_FORMAT_ABGR8888;
+                       else
+                               return DRM_FORMAT_XBGR8888;
+               } else {
+                       if (alpha)
+                               return DRM_FORMAT_ARGB8888;
+                       else
+                               return DRM_FORMAT_XRGB8888;
+               }
+       case PLANE_CTL_FORMAT_XRGB_2101010:
+               if (rgb_order)
+                       return DRM_FORMAT_XBGR2101010;
+               else
+                       return DRM_FORMAT_XRGB2101010;
+       }
+}
+
+static bool
+intel_alloc_plane_obj(struct intel_crtc *crtc,
+                     struct intel_initial_plane_config *plane_config)
 {
        struct drm_device *dev = crtc->base.dev;
        struct drm_i915_gem_object *obj = NULL;
@@ -2382,8 +2410,23 @@ out_unref_obj:
        return false;
 }
 
-static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
-                                struct intel_plane_config *plane_config)
+/* Update plane->state->fb to match plane->fb after driver-internal updates */
+static void
+update_state_fb(struct drm_plane *plane)
+{
+       if (plane->fb == plane->state->fb)
+               return;
+
+       if (plane->state->fb)
+               drm_framebuffer_unreference(plane->state->fb);
+       plane->state->fb = plane->fb;
+       if (plane->state->fb)
+               drm_framebuffer_reference(plane->state->fb);
+}
+
+static void
+intel_find_plane_obj(struct intel_crtc *intel_crtc,
+                    struct intel_initial_plane_config *plane_config)
 {
        struct drm_device *dev = intel_crtc->base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
@@ -2427,6 +2470,8 @@ static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
                        break;
                }
        }
+
+       update_state_fb(intel_crtc->base.primary);
 }
 
 static void i9xx_update_primary_plane(struct drm_crtc *crtc,
@@ -2532,7 +2577,7 @@ static void i9xx_update_primary_plane(struct drm_crtc *crtc,
                intel_crtc->dspaddr_offset = linear_offset;
        }
 
-       if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) {
+       if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) {
                dspcntr |= DISPPLANE_ROTATE_180;
 
                x += (intel_crtc->config->pipe_src_w - 1);
@@ -2634,7 +2679,7 @@ static void ironlake_update_primary_plane(struct drm_crtc *crtc,
                                               pixel_size,
                                               fb->pitches[0]);
        linear_offset -= intel_crtc->dspaddr_offset;
-       if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) {
+       if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) {
                dspcntr |= DISPPLANE_ROTATE_180;
 
                if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
@@ -2731,7 +2776,7 @@ static void skylake_update_primary_plane(struct drm_crtc *crtc,
        }
 
        plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
-       if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180))
+       if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180))
                plane_ctl |= PLANE_CTL_ROTATE_180;
 
        I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl);
@@ -6545,8 +6590,9 @@ static void vlv_crtc_clock_get(struct intel_crtc *crtc,
        pipe_config->port_clock = clock.dot / 5;
 }
 
-static void i9xx_get_plane_config(struct intel_crtc *crtc,
-                                 struct intel_plane_config *plane_config)
+static void
+i9xx_get_initial_plane_config(struct intel_crtc *crtc,
+                             struct intel_initial_plane_config *plane_config)
 {
        struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
@@ -6555,13 +6601,16 @@ static void i9xx_get_plane_config(struct intel_crtc *crtc,
        int fourcc, pixel_format;
        int aligned_height;
        struct drm_framebuffer *fb;
+       struct intel_framebuffer *intel_fb;
 
-       fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
-       if (!fb) {
+       intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
+       if (!intel_fb) {
                DRM_DEBUG_KMS("failed to alloc fb\n");
                return;
        }
 
+       fb = &intel_fb->base;
+
        val = I915_READ(DSPCNTR(plane));
 
        if (INTEL_INFO(dev)->gen >= 4)
@@ -6569,7 +6618,7 @@ static void i9xx_get_plane_config(struct intel_crtc *crtc,
                        plane_config->tiling = I915_TILING_X;
 
        pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
-       fourcc = intel_format_to_fourcc(pixel_format);
+       fourcc = i9xx_format_to_fourcc(pixel_format);
        fb->pixel_format = fourcc;
        fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8;
 
@@ -6602,6 +6651,7 @@ static void i9xx_get_plane_config(struct intel_crtc *crtc,
                      plane_config->size);
 
        crtc->base.primary->fb = fb;
+       update_state_fb(crtc->base.primary);
 }
 
 static void chv_crtc_clock_get(struct intel_crtc *crtc,
@@ -7573,6 +7623,79 @@ static void skylake_get_pfit_config(struct intel_crtc *crtc,
        }
 }
 
+static void
+skylake_get_initial_plane_config(struct intel_crtc *crtc,
+                                struct intel_initial_plane_config *plane_config)
+{
+       struct drm_device *dev = crtc->base.dev;
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       u32 val, base, offset, stride_mult;
+       int pipe = crtc->pipe;
+       int fourcc, pixel_format;
+       int aligned_height;
+       struct drm_framebuffer *fb;
+       struct intel_framebuffer *intel_fb;
+
+       intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
+       if (!intel_fb) {
+               DRM_DEBUG_KMS("failed to alloc fb\n");
+               return;
+       }
+
+       fb = &intel_fb->base;
+
+       val = I915_READ(PLANE_CTL(pipe, 0));
+       if (val & PLANE_CTL_TILED_MASK)
+               plane_config->tiling = I915_TILING_X;
+
+       pixel_format = val & PLANE_CTL_FORMAT_MASK;
+       fourcc = skl_format_to_fourcc(pixel_format,
+                                     val & PLANE_CTL_ORDER_RGBX,
+                                     val & PLANE_CTL_ALPHA_MASK);
+       fb->pixel_format = fourcc;
+       fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8;
+
+       base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000;
+       plane_config->base = base;
+
+       offset = I915_READ(PLANE_OFFSET(pipe, 0));
+
+       val = I915_READ(PLANE_SIZE(pipe, 0));
+       fb->height = ((val >> 16) & 0xfff) + 1;
+       fb->width = ((val >> 0) & 0x1fff) + 1;
+
+       val = I915_READ(PLANE_STRIDE(pipe, 0));
+       switch (plane_config->tiling) {
+       case I915_TILING_NONE:
+               stride_mult = 64;
+               break;
+       case I915_TILING_X:
+               stride_mult = 512;
+               break;
+       default:
+               MISSING_CASE(plane_config->tiling);
+               goto error;
+       }
+       fb->pitches[0] = (val & 0x3ff) * stride_mult;
+
+       aligned_height = intel_fb_align_height(dev, fb->height,
+                                              plane_config->tiling);
+
+       plane_config->size = ALIGN(fb->pitches[0] * aligned_height, PAGE_SIZE);
+
+       DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
+                     pipe_name(pipe), fb->width, fb->height,
+                     fb->bits_per_pixel, base, fb->pitches[0],
+                     plane_config->size);
+
+       crtc->base.primary->fb = fb;
+       update_state_fb(crtc->base.primary);
+       return;
+
+error:
+       kfree(fb);
+}
+
 static void ironlake_get_pfit_config(struct intel_crtc *crtc,
                                     struct intel_crtc_state *pipe_config)
 {
@@ -7597,8 +7720,9 @@ static void ironlake_get_pfit_config(struct intel_crtc *crtc,
        }
 }
 
-static void ironlake_get_plane_config(struct intel_crtc *crtc,
-                                     struct intel_plane_config *plane_config)
+static void
+ironlake_get_initial_plane_config(struct intel_crtc *crtc,
+                                 struct intel_initial_plane_config *plane_config)
 {
        struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
@@ -7607,13 +7731,16 @@ static void ironlake_get_plane_config(struct intel_crtc *crtc,
        int fourcc, pixel_format;
        int aligned_height;
        struct drm_framebuffer *fb;
+       struct intel_framebuffer *intel_fb;
 
-       fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
-       if (!fb) {
+       intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
+       if (!intel_fb) {
                DRM_DEBUG_KMS("failed to alloc fb\n");
                return;
        }
 
+       fb = &intel_fb->base;
+
        val = I915_READ(DSPCNTR(pipe));
 
        if (INTEL_INFO(dev)->gen >= 4)
@@ -7621,7 +7748,7 @@ static void ironlake_get_plane_config(struct intel_crtc *crtc,
                        plane_config->tiling = I915_TILING_X;
 
        pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
-       fourcc = intel_format_to_fourcc(pixel_format);
+       fourcc = i9xx_format_to_fourcc(pixel_format);
        fb->pixel_format = fourcc;
        fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8;
 
@@ -7654,6 +7781,7 @@ static void ironlake_get_plane_config(struct intel_crtc *crtc,
                      plane_config->size);
 
        crtc->base.primary->fb = fb;
+       update_state_fb(crtc->base.primary);
 }
 
 static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
@@ -8224,7 +8352,7 @@ static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
                        cntl |= CURSOR_PIPE_CSC_ENABLE;
        }
 
-       if (to_intel_plane(crtc->cursor)->rotation == BIT(DRM_ROTATE_180))
+       if (crtc->cursor->state->rotation == BIT(DRM_ROTATE_180))
                cntl |= CURSOR_ROTATE_180;
 
        if (intel_crtc->cursor_cntl != cntl) {
@@ -8286,7 +8414,7 @@ static void intel_crtc_update_cursor(struct drm_crtc *crtc,
 
        /* ILK+ do this automagically */
        if (HAS_GMCH_DISPLAY(dev) &&
-               to_intel_plane(crtc->cursor)->rotation == BIT(DRM_ROTATE_180)) {
+           crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) {
                base += (intel_crtc->cursor_height *
                        intel_crtc->cursor_width - 1) * 4;
        }
@@ -8946,9 +9074,9 @@ static void intel_unpin_work_fn(struct work_struct *__work)
        enum pipe pipe = to_intel_crtc(work->crtc)->pipe;
 
        mutex_lock(&dev->struct_mutex);
-       intel_unpin_fb_obj(work->old_fb_obj);
+       intel_unpin_fb_obj(intel_fb_obj(work->old_fb));
        drm_gem_object_unreference(&work->pending_flip_obj->base);
-       drm_gem_object_unreference(&work->old_fb_obj->base);
+       drm_framebuffer_unreference(work->old_fb);
 
        intel_fbc_update(dev);
 
@@ -9651,7 +9779,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
 
        work->event = event;
        work->crtc = crtc;
-       work->old_fb_obj = intel_fb_obj(old_fb);
+       work->old_fb = old_fb;
        INIT_WORK(&work->work, intel_unpin_work_fn);
 
        ret = drm_crtc_vblank_get(crtc);
@@ -9687,10 +9815,11 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
                goto cleanup;
 
        /* Reference the objects for the scheduled work. */
-       drm_gem_object_reference(&work->old_fb_obj->base);
+       drm_framebuffer_reference(work->old_fb);
        drm_gem_object_reference(&obj->base);
 
        crtc->primary->fb = fb;
+       update_state_fb(crtc->primary);
 
        work->pending_flip_obj = obj;
 
@@ -9702,7 +9831,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
 
        if (IS_VALLEYVIEW(dev)) {
                ring = &dev_priv->ring[BCS];
-               if (obj->tiling_mode != work->old_fb_obj->tiling_mode)
+               if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode)
                        /* vlv: DISPLAY_FLIP fails to change tiling */
                        ring = NULL;
        } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) {
@@ -9743,7 +9872,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
        work->flip_queued_vblank = drm_vblank_count(dev, intel_crtc->pipe);
        work->enable_stall_check = true;
 
-       i915_gem_track_fb(work->old_fb_obj, obj,
+       i915_gem_track_fb(intel_fb_obj(work->old_fb), obj,
                          INTEL_FRONTBUFFER_PRIMARY(pipe));
 
        intel_fbc_disable(dev);
@@ -9759,7 +9888,8 @@ cleanup_unpin:
 cleanup_pending:
        atomic_dec(&intel_crtc->unpin_work_count);
        crtc->primary->fb = old_fb;
-       drm_gem_object_unreference(&work->old_fb_obj->base);
+       update_state_fb(crtc->primary);
+       drm_framebuffer_unreference(work->old_fb);
        drm_gem_object_unreference(&obj->base);
        mutex_unlock(&dev->struct_mutex);
 
@@ -10912,6 +11042,36 @@ out:
        return pipe_config;
 }
 
+static int __intel_set_mode_setup_plls(struct drm_device *dev,
+                                      unsigned modeset_pipes,
+                                      unsigned disable_pipes)
+{
+       struct drm_i915_private *dev_priv = to_i915(dev);
+       unsigned clear_pipes = modeset_pipes | disable_pipes;
+       struct intel_crtc *intel_crtc;
+       int ret = 0;
+
+       if (!dev_priv->display.crtc_compute_clock)
+               return 0;
+
+       ret = intel_shared_dpll_start_config(dev_priv, clear_pipes);
+       if (ret)
+               goto done;
+
+       for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
+               struct intel_crtc_state *state = intel_crtc->new_config;
+               ret = dev_priv->display.crtc_compute_clock(intel_crtc,
+                                                          state);
+               if (ret) {
+                       intel_shared_dpll_abort_config(dev_priv);
+                       goto done;
+               }
+       }
+
+done:
+       return ret;
+}
+
 static int __intel_set_mode(struct drm_crtc *crtc,
                            struct drm_display_mode *mode,
                            int x, int y, struct drm_framebuffer *fb,
@@ -10949,23 +11109,9 @@ static int __intel_set_mode(struct drm_crtc *crtc,
                prepare_pipes &= ~disable_pipes;
        }
 
-       if (dev_priv->display.crtc_compute_clock) {
-               unsigned clear_pipes = modeset_pipes | disable_pipes;
-
-               ret = intel_shared_dpll_start_config(dev_priv, clear_pipes);
-               if (ret)
-                       goto done;
-
-               for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
-                       struct intel_crtc_state *state = intel_crtc->new_config;
-                       ret = dev_priv->display.crtc_compute_clock(intel_crtc,
-                                                                  state);
-                       if (ret) {
-                               intel_shared_dpll_abort_config(dev_priv);
-                               goto done;
-                       }
-               }
-       }
+       ret = __intel_set_mode_setup_plls(dev, modeset_pipes, disable_pipes);
+       if (ret)
+               goto done;
 
        for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
                intel_crtc_disable(&intel_crtc->base);
@@ -11544,6 +11690,8 @@ static const struct drm_crtc_funcs intel_crtc_funcs = {
        .set_config = intel_crtc_set_config,
        .destroy = intel_crtc_destroy,
        .page_flip = intel_crtc_page_flip,
+       .atomic_duplicate_state = intel_crtc_duplicate_state,
+       .atomic_destroy_state = intel_crtc_destroy_state,
 };
 
 static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv,
@@ -11738,7 +11886,6 @@ intel_check_primary_plane(struct drm_plane *plane,
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct drm_crtc *crtc = state->base.crtc;
        struct intel_crtc *intel_crtc;
-       struct intel_plane *intel_plane = to_intel_plane(plane);
        struct drm_framebuffer *fb = state->base.fb;
        struct drm_rect *dest = &state->dst;
        struct drm_rect *src = &state->src;
@@ -11772,7 +11919,7 @@ intel_check_primary_plane(struct drm_plane *plane,
                if (intel_crtc->primary_enabled &&
                    INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) &&
                    dev_priv->fbc.plane == intel_crtc->plane &&
-                   intel_plane->rotation != BIT(DRM_ROTATE_0)) {
+                   state->base.rotation != BIT(DRM_ROTATE_0)) {
                        intel_crtc->atomic.disable_fbc = true;
                }
 
@@ -11942,11 +12089,13 @@ void intel_plane_destroy(struct drm_plane *plane)
        kfree(intel_plane);
 }
 
-static const struct drm_plane_funcs intel_primary_plane_funcs = {
-       .update_plane = drm_plane_helper_update,
-       .disable_plane = drm_plane_helper_disable,
+const struct drm_plane_funcs intel_plane_funcs = {
+       .update_plane = drm_atomic_helper_update_plane,
+       .disable_plane = drm_atomic_helper_disable_plane,
        .destroy = intel_plane_destroy,
-       .set_property = intel_plane_set_property,
+       .set_property = drm_atomic_helper_plane_set_property,
+       .atomic_get_property = intel_plane_atomic_get_property,
+       .atomic_set_property = intel_plane_atomic_set_property,
        .atomic_duplicate_state = intel_plane_duplicate_state,
        .atomic_destroy_state = intel_plane_destroy_state,
 
@@ -11956,6 +12105,7 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
                                                    int pipe)
 {
        struct intel_plane *primary;
+       struct intel_plane_state *state;
        const uint32_t *intel_primary_formats;
        int num_formats;
 
@@ -11963,17 +12113,17 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
        if (primary == NULL)
                return NULL;
 
-       primary->base.state = intel_plane_duplicate_state(&primary->base);
-       if (primary->base.state == NULL) {
+       state = intel_create_plane_state(&primary->base);
+       if (!state) {
                kfree(primary);
                return NULL;
        }
+       primary->base.state = &state->base;
 
        primary->can_scale = false;
        primary->max_downscale = 1;
        primary->pipe = pipe;
        primary->plane = pipe;
-       primary->rotation = BIT(DRM_ROTATE_0);
        primary->check_plane = intel_check_primary_plane;
        primary->commit_plane = intel_commit_primary_plane;
        if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4)
@@ -11988,7 +12138,7 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
        }
 
        drm_universal_plane_init(dev, &primary->base, 0,
-                                &intel_primary_plane_funcs,
+                                &intel_plane_funcs,
                                 intel_primary_formats, num_formats,
                                 DRM_PLANE_TYPE_PRIMARY);
 
@@ -12001,7 +12151,7 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
                if (dev->mode_config.rotation_property)
                        drm_object_attach_property(&primary->base.base,
                                dev->mode_config.rotation_property,
-                               primary->rotation);
+                               state->base.rotation);
        }
 
        drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs);
@@ -12116,40 +12266,32 @@ update:
                intel_crtc_update_cursor(crtc, state->visible);
 }
 
-static const struct drm_plane_funcs intel_cursor_plane_funcs = {
-       .update_plane = drm_plane_helper_update,
-       .disable_plane = drm_plane_helper_disable,
-       .destroy = intel_plane_destroy,
-       .set_property = intel_plane_set_property,
-       .atomic_duplicate_state = intel_plane_duplicate_state,
-       .atomic_destroy_state = intel_plane_destroy_state,
-};
-
 static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
                                                   int pipe)
 {
        struct intel_plane *cursor;
+       struct intel_plane_state *state;
 
        cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
        if (cursor == NULL)
                return NULL;
 
-       cursor->base.state = intel_plane_duplicate_state(&cursor->base);
-       if (cursor->base.state == NULL) {
+       state = intel_create_plane_state(&cursor->base);
+       if (!state) {
                kfree(cursor);
                return NULL;
        }
+       cursor->base.state = &state->base;
 
        cursor->can_scale = false;
        cursor->max_downscale = 1;
        cursor->pipe = pipe;
        cursor->plane = pipe;
-       cursor->rotation = BIT(DRM_ROTATE_0);
        cursor->check_plane = intel_check_cursor_plane;
        cursor->commit_plane = intel_commit_cursor_plane;
 
        drm_universal_plane_init(dev, &cursor->base, 0,
-                                &intel_cursor_plane_funcs,
+                                &intel_plane_funcs,
                                 intel_cursor_formats,
                                 ARRAY_SIZE(intel_cursor_formats),
                                 DRM_PLANE_TYPE_CURSOR);
@@ -12163,7 +12305,7 @@ static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
                if (dev->mode_config.rotation_property)
                        drm_object_attach_property(&cursor->base.base,
                                dev->mode_config.rotation_property,
-                               cursor->rotation);
+                               state->base.rotation);
        }
 
        drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
@@ -12337,6 +12479,7 @@ static void intel_setup_outputs(struct drm_device *dev)
 {
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct intel_encoder *encoder;
+       struct drm_connector *connector;
        bool dpd_is_edp = false;
 
        intel_lvds_init(dev);
@@ -12467,6 +12610,37 @@ static void intel_setup_outputs(struct drm_device *dev)
        if (SUPPORTS_TV(dev))
                intel_tv_init(dev);
 
+       /*
+        * FIXME:  We don't have full atomic support yet, but we want to be
+        * able to enable/test plane updates via the atomic interface in the
+        * meantime.  However as soon as we flip DRIVER_ATOMIC on, the DRM core
+        * will take some atomic codepaths to lookup properties during
+        * drmModeGetConnector() that unconditionally dereference
+        * connector->state.
+        *
+        * We create a dummy connector state here for each connector to ensure
+        * the DRM core doesn't try to dereference a NULL connector->state.
+        * The actual connector properties will never be updated or contain
+        * useful information, but since we're doing this specifically for
+        * testing/debug of the plane operations (and only when a specific
+        * kernel module option is given), that shouldn't really matter.
+        *
+        * Once atomic support for crtc's + connectors lands, this loop should
+        * be removed since we'll be setting up real connector state, which
+        * will contain Intel-specific properties.
+        */
+       if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
+               list_for_each_entry(connector,
+                                   &dev->mode_config.connector_list,
+                                   head) {
+                       if (!WARN_ON(connector->state)) {
+                               connector->state =
+                                       kzalloc(sizeof(*connector->state),
+                                               GFP_KERNEL);
+                       }
+               }
+       }
+
        intel_psr_init(dev);
 
        for_each_intel_encoder(dev, encoder) {
@@ -12650,6 +12824,8 @@ static inline void intel_fbdev_output_poll_changed(struct drm_device *dev)
 static const struct drm_mode_config_funcs intel_mode_funcs = {
        .fb_create = intel_user_framebuffer_create,
        .output_poll_changed = intel_fbdev_output_poll_changed,
+       .atomic_check = intel_atomic_check,
+       .atomic_commit = intel_atomic_commit,
 };
 
 /* Set up chip specific display functions */
@@ -12668,23 +12844,32 @@ static void intel_init_display(struct drm_device *dev)
        else
                dev_priv->display.find_dpll = i9xx_find_best_dpll;
 
-       if (HAS_DDI(dev)) {
+       if (INTEL_INFO(dev)->gen >= 9) {
                dev_priv->display.get_pipe_config = haswell_get_pipe_config;
-               dev_priv->display.get_plane_config = ironlake_get_plane_config;
+               dev_priv->display.get_initial_plane_config =
+                       skylake_get_initial_plane_config;
                dev_priv->display.crtc_compute_clock =
                        haswell_crtc_compute_clock;
                dev_priv->display.crtc_enable = haswell_crtc_enable;
                dev_priv->display.crtc_disable = haswell_crtc_disable;
                dev_priv->display.off = ironlake_crtc_off;
-               if (INTEL_INFO(dev)->gen >= 9)
-                       dev_priv->display.update_primary_plane =
-                               skylake_update_primary_plane;
-               else
-                       dev_priv->display.update_primary_plane =
-                               ironlake_update_primary_plane;
+               dev_priv->display.update_primary_plane =
+                       skylake_update_primary_plane;
+       } else if (HAS_DDI(dev)) {
+               dev_priv->display.get_pipe_config = haswell_get_pipe_config;
+               dev_priv->display.get_initial_plane_config =
+                       ironlake_get_initial_plane_config;
+               dev_priv->display.crtc_compute_clock =
+                       haswell_crtc_compute_clock;
+               dev_priv->display.crtc_enable = haswell_crtc_enable;
+               dev_priv->display.crtc_disable = haswell_crtc_disable;
+               dev_priv->display.off = ironlake_crtc_off;
+               dev_priv->display.update_primary_plane =
+                       ironlake_update_primary_plane;
        } else if (HAS_PCH_SPLIT(dev)) {
                dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
-               dev_priv->display.get_plane_config = ironlake_get_plane_config;
+               dev_priv->display.get_initial_plane_config =
+                       ironlake_get_initial_plane_config;
                dev_priv->display.crtc_compute_clock =
                        ironlake_crtc_compute_clock;
                dev_priv->display.crtc_enable = ironlake_crtc_enable;
@@ -12694,7 +12879,8 @@ static void intel_init_display(struct drm_device *dev)
                        ironlake_update_primary_plane;
        } else if (IS_VALLEYVIEW(dev)) {
                dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
-               dev_priv->display.get_plane_config = i9xx_get_plane_config;
+               dev_priv->display.get_initial_plane_config =
+                       i9xx_get_initial_plane_config;
                dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
                dev_priv->display.crtc_enable = valleyview_crtc_enable;
                dev_priv->display.crtc_disable = i9xx_crtc_disable;
@@ -12703,7 +12889,8 @@ static void intel_init_display(struct drm_device *dev)
                        i9xx_update_primary_plane;
        } else {
                dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
-               dev_priv->display.get_plane_config = i9xx_get_plane_config;
+               dev_priv->display.get_initial_plane_config =
+                       i9xx_get_initial_plane_config;
                dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
                dev_priv->display.crtc_enable = i9xx_crtc_enable;
                dev_priv->display.crtc_disable = i9xx_crtc_disable;
@@ -13075,8 +13262,8 @@ void intel_modeset_init(struct drm_device *dev)
                 * can even allow for smooth boot transitions if the BIOS
                 * fb is large enough for the active pipe configuration.
                 */
-               if (dev_priv->display.get_plane_config) {
-                       dev_priv->display.get_plane_config(crtc,
+               if (dev_priv->display.get_initial_plane_config) {
+                       dev_priv->display.get_initial_plane_config(crtc,
                                                           &crtc->plane_config);
                        /*
                         * If the fb is shared between multiple heads, we'll
@@ -13536,6 +13723,7 @@ void intel_modeset_gem_init(struct drm_device *dev)
                                  to_intel_crtc(c)->pipe);
                        drm_framebuffer_unreference(c->primary->fb);
                        c->primary->fb = NULL;
+                       update_state_fb(c->primary);
                }
        }
        mutex_unlock(&dev->struct_mutex);
This page took 0.043851 seconds and 5 git commands to generate.