drm/i915: Try to relocate the BIOS fb to the start of ggtt
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Fri, 2 Feb 2024 22:43:39 +0000 (00:43 +0200)
committerVille Syrjälä <ville.syrjala@linux.intel.com>
Wed, 7 Feb 2024 00:01:49 +0000 (02:01 +0200)
On MTL the GOP (for whatever reason) likes to bind its framebuffer
high up in the ggtt address space. This can conflict with whatever
ggtt_reserve_guc_top() is trying to do, and the result is that
ggtt_reserve_guc_top() fails and then we proceed to explode when
trying to tear down the driver. Thus far I haven't analyzed what
causes the actual fireworks, but it's not super important as even
if it didn't explode we'd still fail the driver load and the user
would be left with an unusable GPU.

To remedy this (without having to figure out exactly what
ggtt_reserve_guc_top() is trying to achieve) we can attempt to
relocate the BIOS framebuffer to a lower ggtt address. We can do
this at this early point in driver init because nothing else is
supposed to be clobbering the ggtt yet. So we simply change where
in the ggtt we pin the vma, the original PTEs will be left as is,
and the new PTEs will get written with the same dma addresses.
The plane will keep on scanning out from the original PTEs until
we are done with the whole process, and at that point we rewrite
the plane's surface address register to point at the new ggtt
address.

Since we don't need a specific ggtt address for the plane
(apart from needing it to land in the mappable region for
normal stolen objects) we'll just try to pin it without a fixed
offset first. It should end up at the lowest available address
(which really should be 0 at this point in the driver init).
If that fails we'll fall back to just pinning it exactly to the
origianal address.

To make sure we don't accidentlally pin it partially over the
original ggtt range (as that would corrupt the original PTEs)
we reserve the original range temporarily during this process.

v2: Try to pin explicitly to ggtt offset 0 as otherwise DG2 puts it
    even higher (atm we have no PIN_LOW flag to force it low)
v3: "fix" xe

Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com>
Tested-by: Paz Zcharya <pazz@chromium.org>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240202224340.30647-16-ville.syrjala@linux.intel.com
Acked-by: Lucas De Marchi <lucas.demarchi@intel.com>
drivers/gpu/drm/i915/display/i9xx_plane.c
drivers/gpu/drm/i915/display/i9xx_plane.h
drivers/gpu/drm/i915/display/intel_display.c
drivers/gpu/drm/i915/display/intel_display_core.h
drivers/gpu/drm/i915/display/intel_plane_initial.c
drivers/gpu/drm/i915/display/skl_universal_plane.c
drivers/gpu/drm/i915/display/skl_universal_plane.h
drivers/gpu/drm/xe/display/xe_plane_initial.c

index 91f2bc405cbaf0aef44288969c939bd3aeee96fd..0279c8aabdd1f768d81abb01e2edae5b74679e44 100644 (file)
@@ -1060,3 +1060,33 @@ i9xx_get_initial_plane_config(struct intel_crtc *crtc,
 
        plane_config->fb = intel_fb;
 }
+
+bool i9xx_fixup_initial_plane_config(struct intel_crtc *crtc,
+                                    const struct intel_initial_plane_config *plane_config)
+{
+       struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
+       struct intel_plane *plane = to_intel_plane(crtc->base.primary);
+       const struct intel_plane_state *plane_state =
+               to_intel_plane_state(plane->base.state);
+       enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
+       u32 base;
+
+       if (!plane_state->uapi.visible)
+               return false;
+
+       base = intel_plane_ggtt_offset(plane_state);
+
+       /*
+        * We may have moved the surface to a different
+        * part of ggtt, make the plane aware of that.
+        */
+       if (plane_config->base == base)
+               return false;
+
+       if (DISPLAY_VER(dev_priv) >= 4)
+               intel_de_write(dev_priv, DSPSURF(i9xx_plane), base);
+       else
+               intel_de_write(dev_priv, DSPADDR(i9xx_plane), base);
+
+       return true;
+}
index b3d724a144cb9d2a624500a549b5f5f400c7117f..0ca12d1e683936d1075dc1a6c27180b73729989c 100644 (file)
@@ -26,6 +26,8 @@ intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe);
 
 void i9xx_get_initial_plane_config(struct intel_crtc *crtc,
                                   struct intel_initial_plane_config *plane_config);
+bool i9xx_fixup_initial_plane_config(struct intel_crtc *crtc,
+                                    const struct intel_initial_plane_config *plane_config);
 #else
 static inline unsigned int i965_plane_max_stride(struct intel_plane *plane,
                                                 u32 pixel_format, u64 modifier,
@@ -46,6 +48,11 @@ static inline void i9xx_get_initial_plane_config(struct intel_crtc *crtc,
                                                 struct intel_initial_plane_config *plane_config)
 {
 }
+static inline bool i9xx_fixup_initial_plane_config(struct intel_crtc *crtc,
+                                                  const struct intel_initial_plane_config *plane_config)
+{
+       return false;
+}
 #endif
 
 #endif
index 7fb0f71652acf0960b046c703f028cd16aa8d930..1b844cac4c58b7b279b6ef4858841fb8cbad9745 100644 (file)
@@ -7850,6 +7850,7 @@ static const struct intel_display_funcs skl_display_funcs = {
        .crtc_disable = hsw_crtc_disable,
        .commit_modeset_enables = skl_commit_modeset_enables,
        .get_initial_plane_config = skl_get_initial_plane_config,
+       .fixup_initial_plane_config = skl_fixup_initial_plane_config,
 };
 
 static const struct intel_display_funcs ddi_display_funcs = {
@@ -7858,6 +7859,7 @@ static const struct intel_display_funcs ddi_display_funcs = {
        .crtc_disable = hsw_crtc_disable,
        .commit_modeset_enables = intel_commit_modeset_enables,
        .get_initial_plane_config = i9xx_get_initial_plane_config,
+       .fixup_initial_plane_config = i9xx_fixup_initial_plane_config,
 };
 
 static const struct intel_display_funcs pch_split_display_funcs = {
@@ -7866,6 +7868,7 @@ static const struct intel_display_funcs pch_split_display_funcs = {
        .crtc_disable = ilk_crtc_disable,
        .commit_modeset_enables = intel_commit_modeset_enables,
        .get_initial_plane_config = i9xx_get_initial_plane_config,
+       .fixup_initial_plane_config = i9xx_fixup_initial_plane_config,
 };
 
 static const struct intel_display_funcs vlv_display_funcs = {
@@ -7874,6 +7877,7 @@ static const struct intel_display_funcs vlv_display_funcs = {
        .crtc_disable = i9xx_crtc_disable,
        .commit_modeset_enables = intel_commit_modeset_enables,
        .get_initial_plane_config = i9xx_get_initial_plane_config,
+       .fixup_initial_plane_config = i9xx_fixup_initial_plane_config,
 };
 
 static const struct intel_display_funcs i9xx_display_funcs = {
@@ -7882,6 +7886,7 @@ static const struct intel_display_funcs i9xx_display_funcs = {
        .crtc_disable = i9xx_crtc_disable,
        .commit_modeset_enables = intel_commit_modeset_enables,
        .get_initial_plane_config = i9xx_get_initial_plane_config,
+       .fixup_initial_plane_config = i9xx_fixup_initial_plane_config,
 };
 
 /**
index a90f1aa201be8cf22770865bcf724b009d174575..fdeaac994e17bbf18fa1e303c12c5f68fdf5e72e 100644 (file)
@@ -67,6 +67,8 @@ struct intel_display_funcs {
                                struct intel_crtc_state *);
        void (*get_initial_plane_config)(struct intel_crtc *,
                                         struct intel_initial_plane_config *);
+       bool (*fixup_initial_plane_config)(struct intel_crtc *crtc,
+                                          const struct intel_initial_plane_config *plane_config);
        void (*crtc_enable)(struct intel_atomic_state *state,
                            struct intel_crtc *crtc);
        void (*crtc_disable)(struct intel_atomic_state *state,
index 8203c6dd6f7360f1b578330a135cedeeaf75f9a7..b43b8cf4680c09e97c8b93b911e78c38b84539f0 100644 (file)
@@ -3,9 +3,11 @@
  * Copyright © 2021 Intel Corporation
  */
 
+#include "gem/i915_gem_lmem.h"
 #include "gem/i915_gem_region.h"
 #include "i915_drv.h"
 #include "intel_atomic_plane.h"
+#include "intel_crtc.h"
 #include "intel_display.h"
 #include "intel_display_types.h"
 #include "intel_fb.h"
@@ -138,6 +140,7 @@ initial_plane_vma(struct drm_i915_private *i915,
 {
        struct intel_memory_region *mem;
        struct drm_i915_gem_object *obj;
+       struct drm_mm_node orig_mm = {};
        struct i915_vma *vma;
        resource_size_t phys_base;
        u32 base, size;
@@ -195,23 +198,66 @@ initial_plane_vma(struct drm_i915_private *i915,
                goto err_obj;
        }
 
+       /*
+        * MTL GOP likes to place the framebuffer high up in ggtt,
+        * which can cause problems for ggtt_reserve_guc_top().
+        * Try to pin it to a low ggtt address instead to avoid that.
+        */
+       base = 0;
+
+       if (base != plane_config->base) {
+               struct i915_ggtt *ggtt = to_gt(i915)->ggtt;
+               int ret;
+
+               /*
+                * Make sure the original and new locations
+                * can't overlap. That would corrupt the original
+                * PTEs which are still being used for scanout.
+                */
+               ret = i915_gem_gtt_reserve(&ggtt->vm, NULL, &orig_mm,
+                                          size, plane_config->base,
+                                          I915_COLOR_UNEVICTABLE, PIN_NOEVICT);
+               if (ret)
+                       goto err_obj;
+       }
+
        vma = i915_vma_instance(obj, &to_gt(i915)->ggtt->vm, NULL);
        if (IS_ERR(vma))
                goto err_obj;
 
+retry:
        pinctl = PIN_GLOBAL | PIN_OFFSET_FIXED | base;
-       if (HAS_GMCH(i915))
+       if (!i915_gem_object_is_lmem(obj))
                pinctl |= PIN_MAPPABLE;
-       if (i915_vma_pin(vma, 0, 0, pinctl))
+       if (i915_vma_pin(vma, 0, 0, pinctl)) {
+               if (drm_mm_node_allocated(&orig_mm)) {
+                       drm_mm_remove_node(&orig_mm);
+                       /*
+                        * Try again, but this time pin
+                        * it to its original location.
+                        */
+                       base = plane_config->base;
+                       goto retry;
+               }
                goto err_obj;
+       }
 
        if (i915_gem_object_is_tiled(obj) &&
            !i915_vma_is_map_and_fenceable(vma))
                goto err_obj;
 
+       if (drm_mm_node_allocated(&orig_mm))
+               drm_mm_remove_node(&orig_mm);
+
+       drm_dbg_kms(&i915->drm,
+                   "Initial plane fb bound to 0x%x in the ggtt (original 0x%x)\n",
+                   i915_ggtt_offset(vma), plane_config->base);
+
        return vma;
 
 err_obj:
+       if (drm_mm_node_allocated(&orig_mm))
+               drm_mm_remove_node(&orig_mm);
        i915_gem_object_put(obj);
        return NULL;
 }
@@ -386,6 +432,9 @@ void intel_initial_plane_config(struct drm_i915_private *i915)
                 */
                intel_find_initial_plane_obj(crtc, plane_configs);
 
+               if (i915->display.funcs.display->fixup_initial_plane_config(crtc, plane_config))
+                       intel_crtc_wait_for_next_vblank(crtc);
+
                plane_config_fini(plane_config);
        }
 }
index 511dc1544854f42aaa5176afca615b0a61ca4a4b..392d93e97bf8320db6706353ed6736a2ef82116e 100644 (file)
@@ -2624,3 +2624,31 @@ skl_get_initial_plane_config(struct intel_crtc *crtc,
 error:
        kfree(intel_fb);
 }
+
+bool skl_fixup_initial_plane_config(struct intel_crtc *crtc,
+                                   const struct intel_initial_plane_config *plane_config)
+{
+       struct drm_i915_private *i915 = to_i915(crtc->base.dev);
+       struct intel_plane *plane = to_intel_plane(crtc->base.primary);
+       const struct intel_plane_state *plane_state =
+               to_intel_plane_state(plane->base.state);
+       enum plane_id plane_id = plane->id;
+       enum pipe pipe = crtc->pipe;
+       u32 base;
+
+       if (!plane_state->uapi.visible)
+               return false;
+
+       base = intel_plane_ggtt_offset(plane_state);
+
+       /*
+        * We may have moved the surface to a different
+        * part of ggtt, make the plane aware of that.
+        */
+       if (plane_config->base == base)
+               return false;
+
+       intel_de_write(i915, PLANE_SURF(pipe, plane_id), base);
+
+       return true;
+}
index be64c201f9b3e7ffea371546ae08d649a86d7aa3..e92e00c01b29a91890ae428c6514810303c00ff8 100644 (file)
@@ -22,6 +22,8 @@ skl_universal_plane_create(struct drm_i915_private *dev_priv,
 
 void skl_get_initial_plane_config(struct intel_crtc *crtc,
                                  struct intel_initial_plane_config *plane_config);
+bool skl_fixup_initial_plane_config(struct intel_crtc *crtc,
+                                   const struct intel_initial_plane_config *plane_config);
 
 int skl_format_to_fourcc(int format, bool rgb_order, bool alpha);
 
index 01787181a1ac6cbf232b7752ed9c97235099c054..866d1dd6eeb4b40c890c132370e5687d799ea7fe 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "i915_drv.h"
 #include "intel_atomic_plane.h"
+#include "intel_crtc.h"
 #include "intel_display.h"
 #include "intel_display_types.h"
 #include "intel_fb.h"
@@ -295,6 +296,9 @@ void intel_initial_plane_config(struct drm_i915_private *i915)
                 */
                intel_find_initial_plane_obj(crtc, plane_configs);
 
+               if (i915->display.funcs.display->fixup_initial_plane_config(crtc, plane_config))
+                       intel_crtc_wait_for_next_vblank(crtc);
+
                plane_config_fini(plane_config);
        }
 }