drm/i915: Align dumb buffer stride to 4k to allow for gtt remapping
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Thu, 9 May 2019 12:21:57 +0000 (15:21 +0300)
committerVille Syrjälä <ville.syrjala@linux.intel.com>
Mon, 20 May 2019 15:04:48 +0000 (18:04 +0300)
Align dumb buffer stride to 4k if the fb will be big enough to
require gtt remapping.

v2: Leave the stride alone for buffers that look to be for the cursor
v3: Make it not a hack (Daniel)

Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190509122159.24376-7-ville.syrjala@linux.intel.com
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
drivers/gpu/drm/i915/i915_gem.c
drivers/gpu/drm/i915/intel_display.c
drivers/gpu/drm/i915/intel_display.h

index 4e474bcf4c227fd9c6d06b760753b676d8808189..7cafd5612f71471a29944d4a55ceeb979de984fc 100644 (file)
@@ -52,6 +52,7 @@
 #include "i915_trace.h"
 #include "i915_vgpu.h"
 
+#include "intel_display.h"
 #include "intel_drv.h"
 #include "intel_frontbuffer.h"
 #include "intel_pm.h"
@@ -560,8 +561,31 @@ i915_gem_dumb_create(struct drm_file *file,
                     struct drm_device *dev,
                     struct drm_mode_create_dumb *args)
 {
+       int cpp = DIV_ROUND_UP(args->bpp, 8);
+       u32 format;
+
+       switch (cpp) {
+       case 1:
+               format = DRM_FORMAT_C8;
+               break;
+       case 2:
+               format = DRM_FORMAT_RGB565;
+               break;
+       case 4:
+               format = DRM_FORMAT_XRGB8888;
+               break;
+       default:
+               return -EINVAL;
+       }
+
        /* have to work out size/pitch and return them */
-       args->pitch = ALIGN(args->width * DIV_ROUND_UP(args->bpp, 8), 64);
+       args->pitch = ALIGN(args->width * cpp, 64);
+
+       /* align stride to page size so that we can remap */
+       if (args->pitch > intel_plane_fb_max_stride(to_i915(dev), format,
+                                                   DRM_FORMAT_MOD_LINEAR))
+               args->pitch = ALIGN(args->pitch, 4096);
+
        args->size = args->pitch * args->height;
        return i915_gem_create(file, to_i915(dev),
                               &args->size, &args->handle);
index a9f8e52d4b6e8f9383062d016d7fad6f33a32643..2d78bd75c153c50d9d12a699edcd8e0650176909 100644 (file)
@@ -2498,7 +2498,6 @@ bool is_ccs_modifier(u64 modifier)
               modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
 }
 
-static
 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
                              u32 pixel_format, u64 modifier)
 {
index 2626a78e7601aedbd70a712c67b40e0a9db153a4..a43d54089be359caaa19ab0be9e0b85817d0b698 100644 (file)
@@ -436,6 +436,8 @@ void intel_link_compute_m_n(u16 bpp, int nlanes,
                            bool constant_n);
 bool is_ccs_modifier(u64 modifier);
 void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv);
+u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
+                             u32 pixel_format, u64 modifier);
 bool intel_plane_can_remap(const struct intel_plane_state *plane_state);
 
 #endif