Since we now have a separate object, it is cleaner to have dedicated
functions working on the object to stop and restart the mmio debug.
Apart from the cosmetic changes, this patch introduces 2 functional
updates:

- All calls to check_for_unclaimed_mmio will now return false when
  the debug is suspended, not just the ones that are active only when
  i915_modparams.mmio_debug is set. If we don't trust the result of the
  check while a user is doing mmio access then we shouldn't attempt the
  check anywhere.

- i915_modparams.mmio_debug is not save/restored anymore around user
  access. The value is now never touched by the kernel while debug is
  disabled so no need for save/restore.

Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospu...@intel.com>
---
 drivers/gpu/drm/i915/i915_debugfs.c |  2 +-
 drivers/gpu/drm/i915/i915_drv.c     |  2 +-
 drivers/gpu/drm/i915/intel_uncore.c | 43 ++++++++++++++++++-----------
 drivers/gpu/drm/i915/intel_uncore.h |  9 ++----
 4 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c 
b/drivers/gpu/drm/i915/i915_debugfs.c
index eeecdad0e3ca..1eb72bd74ab9 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -1218,7 +1218,7 @@ static int i915_forcewake_domains(struct seq_file *m, 
void *data)
        unsigned int tmp;
 
        seq_printf(m, "user.bypass_count = %u\n",
-                  uncore->user_forcewake.count);
+                  uncore->user_forcewake_count);
 
        for_each_fw_domain(fw_domain, uncore, tmp)
                seq_printf(m, "%s.wake_count = %u\n",
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 1c4cfdb04867..2d6c643dde51 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -2204,7 +2204,7 @@ static int i915_drm_suspend_late(struct drm_device *dev, 
bool hibernation)
 
 out:
        enable_rpm_wakeref_asserts(rpm);
-       if (!dev_priv->uncore.user_forcewake.count)
+       if (!dev_priv->uncore.user_forcewake_count)
                intel_runtime_pm_cleanup(rpm);
 
        return ret;
diff --git a/drivers/gpu/drm/i915/intel_uncore.c 
b/drivers/gpu/drm/i915/intel_uncore.c
index f2dfaccd6614..1905fd94dd3c 100644
--- a/drivers/gpu/drm/i915/intel_uncore.c
+++ b/drivers/gpu/drm/i915/intel_uncore.c
@@ -41,6 +41,25 @@ intel_uncore_mmio_debug_init_early(struct 
intel_uncore_mmio_debug *mmio_debug)
        mmio_debug->unclaimed_mmio_check = 1;
 }
 
+void uncore_mmio_debug_suspend(struct intel_uncore_mmio_debug *mmio_debug)
+{
+       lockdep_assert_held(&mmio_debug->lock);
+
+       /* Save and disable mmio debugging for the user bypass */
+       if (!mmio_debug->suspend_count++) {
+               mmio_debug->saved_mmio_check = mmio_debug->unclaimed_mmio_check;
+               mmio_debug->unclaimed_mmio_check = 0;
+       }
+}
+
+void uncore_mmio_debug_resume(struct intel_uncore_mmio_debug *mmio_debug)
+{
+       lockdep_assert_held(&mmio_debug->lock);
+
+       if (!--mmio_debug->suspend_count)
+               mmio_debug->unclaimed_mmio_check = mmio_debug->saved_mmio_check;
+}
+
 static const char * const forcewake_domain_names[] = {
        "render",
        "blitter",
@@ -482,6 +501,9 @@ check_for_unclaimed_mmio(struct intel_uncore *uncore)
 
        lockdep_assert_held(&uncore->debug->lock);
 
+       if (uncore->debug->suspend_count)
+               return false;
+
        if (intel_uncore_has_fpga_dbg_unclaimed(uncore))
                ret |= fpga_check_for_unclaimed_mmio(uncore);
 
@@ -615,17 +637,9 @@ void intel_uncore_forcewake_user_get(struct intel_uncore 
*uncore)
 {
        spin_lock_irq(&uncore->lock);
        spin_lock(&uncore->debug->lock);
-       if (!uncore->user_forcewake.count++) {
+       if (!uncore->user_forcewake_count++) {
                intel_uncore_forcewake_get__locked(uncore, FORCEWAKE_ALL);
-
-               /* Save and disable mmio debugging for the user bypass */
-               uncore->user_forcewake.saved_mmio_check =
-                       uncore->debug->unclaimed_mmio_check;
-               uncore->user_forcewake.saved_mmio_debug =
-                       i915_modparams.mmio_debug;
-
-               uncore->debug->unclaimed_mmio_check = 0;
-               i915_modparams.mmio_debug = 0;
+               uncore_mmio_debug_suspend(uncore->debug);
        }
        spin_unlock(&uncore->debug->lock);
        spin_unlock_irq(&uncore->lock);
@@ -642,16 +656,13 @@ void intel_uncore_forcewake_user_put(struct intel_uncore 
*uncore)
 {
        spin_lock_irq(&uncore->lock);
        spin_lock(&uncore->debug->lock);
-       if (!--uncore->user_forcewake.count) {
+       if (!--uncore->user_forcewake_count) {
+               uncore_mmio_debug_resume(uncore->debug);
+
                if (check_for_unclaimed_mmio(uncore))
                        dev_info(uncore->i915->drm.dev,
                                 "Invalid mmio detected during user access\n");
 
-               uncore->debug->unclaimed_mmio_check =
-                       uncore->user_forcewake.saved_mmio_check;
-               i915_modparams.mmio_debug =
-                       uncore->user_forcewake.saved_mmio_debug;
-
                intel_uncore_forcewake_put__locked(uncore, FORCEWAKE_ALL);
        }
        spin_unlock(&uncore->debug->lock);
diff --git a/drivers/gpu/drm/i915/intel_uncore.h 
b/drivers/gpu/drm/i915/intel_uncore.h
index d1b12b3b8353..3969dd12208b 100644
--- a/drivers/gpu/drm/i915/intel_uncore.h
+++ b/drivers/gpu/drm/i915/intel_uncore.h
@@ -39,6 +39,8 @@ struct intel_uncore;
 struct intel_uncore_mmio_debug {
        spinlock_t lock; /** lock is also taken in irq contexts. */
        int unclaimed_mmio_check;
+       int saved_mmio_check;
+       u32 suspend_count;
 };
 
 enum forcewake_domain_id {
@@ -141,12 +143,7 @@ struct intel_uncore {
                u32 __iomem *reg_ack;
        } *fw_domain[FW_DOMAIN_ID_COUNT];
 
-       struct {
-               unsigned int count;
-
-               int saved_mmio_check;
-               int saved_mmio_debug;
-       } user_forcewake;
+       unsigned int user_forcewake_count;
 
        struct intel_uncore_mmio_debug *debug;
 };
-- 
2.20.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to