drm/i915: Move rotation from intel_plane to drm_plane_state
[deliverable/linux.git] / drivers / gpu / drm / i915 / intel_display.c
index d94ab6eb07c531bc7eda9f8fa03c4307a8a59407..a3fd64370c2600ec913fc86e17aa8b2195db31c6 100644 (file)
@@ -2316,7 +2316,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 +2337,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 +2409,9 @@ out_unref_obj:
        return false;
 }
 
-static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
-                                struct intel_plane_config *plane_config)
+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;
@@ -2532,7 +2560,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 +2662,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 +2759,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 +6573,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 +6584,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 +6601,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;
 
@@ -7573,6 +7605,78 @@ 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;
+       return;
+
+error:
+       kfree(fb);
+}
+
 static void ironlake_get_pfit_config(struct intel_crtc *crtc,
                                     struct intel_crtc_state *pipe_config)
 {
@@ -7597,8 +7701,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 +7712,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 +7729,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;
 
@@ -8224,7 +8332,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 +8394,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;
        }
@@ -11738,7 +11846,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 +11879,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;
                }
 
@@ -11956,6 +12063,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 +12071,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)
@@ -12001,7 +12109,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);
@@ -12129,22 +12237,23 @@ 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;
 
@@ -12163,7 +12272,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);
@@ -12668,23 +12777,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 +12812,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 +12822,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 +13195,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
This page took 0.050919 seconds and 5 git commands to generate.