drm/i915: move printing and load error inject to i915_utils.[ch]
authorJani Nikula <jani.nikula@intel.com>
Thu, 8 Aug 2019 13:42:43 +0000 (16:42 +0300)
committerJani Nikula <jani.nikula@intel.com>
Fri, 9 Aug 2019 08:51:58 +0000 (11:51 +0300)
Seems like a better fit. Reduce clutter in i915_drv.[ch].

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/bc458fa5e62fc8dae46216666f64ed6976fafaee.1565271681.git.jani.nikula@intel.com
drivers/gpu/drm/i915/Makefile
drivers/gpu/drm/i915/i915_drv.c
drivers/gpu/drm/i915/i915_drv.h
drivers/gpu/drm/i915/i915_utils.c [new file with mode: 0644]
drivers/gpu/drm/i915/i915_utils.h

index 033121791f90b20d7b307b8f7528bf424ad2e10e..3b1fde735c910530e7ce43925d4760efeb548bd5 100644 (file)
@@ -48,6 +48,7 @@ i915-y += i915_drv.o \
          i915_scatterlist.o \
          i915_suspend.o \
          i915_sysfs.o \
+         i915_utils.o \
          intel_csr.o \
          intel_device_info.o \
          intel_pch.o \
index e4f63cfd528b6129d3c9aa8b3a3ea4dc4ee9daba..17e3338bd9128f79f16fa7ee5c5f85c0b59b378c 100644 (file)
 
 static struct drm_driver driver;
 
-#if IS_ENABLED(CONFIG_DRM_I915_DEBUG)
-static unsigned int i915_probe_fail_count;
-
-int __i915_inject_load_error(struct drm_i915_private *i915, int err,
-                            const char *func, int line)
-{
-       if (i915_probe_fail_count >= i915_modparams.inject_load_failure)
-               return 0;
-
-       if (++i915_probe_fail_count < i915_modparams.inject_load_failure)
-               return 0;
-
-       __i915_printk(i915, KERN_INFO,
-                     "Injecting failure %d at checkpoint %u [%s:%d]\n",
-                     err, i915_modparams.inject_load_failure, func, line);
-       i915_modparams.inject_load_failure = 0;
-       return err;
-}
-
-bool i915_error_injected(void)
-{
-       return i915_probe_fail_count && !i915_modparams.inject_load_failure;
-}
-
-#endif
-
-#define FDO_BUG_URL "https://bugs.freedesktop.org/enter_bug.cgi?product=DRI"
-#define FDO_BUG_MSG "Please file a bug at " FDO_BUG_URL " against DRM/Intel " \
-                   "providing the dmesg log by booting with drm.debug=0xf"
-
-void
-__i915_printk(struct drm_i915_private *dev_priv, const char *level,
-             const char *fmt, ...)
-{
-       static bool shown_bug_once;
-       struct device *kdev = dev_priv->drm.dev;
-       bool is_error = level[1] <= KERN_ERR[1];
-       bool is_debug = level[1] == KERN_DEBUG[1];
-       struct va_format vaf;
-       va_list args;
-
-       if (is_debug && !(drm_debug & DRM_UT_DRIVER))
-               return;
-
-       va_start(args, fmt);
-
-       vaf.fmt = fmt;
-       vaf.va = &args;
-
-       if (is_error)
-               dev_printk(level, kdev, "%pV", &vaf);
-       else
-               dev_printk(level, kdev, "[" DRM_NAME ":%ps] %pV",
-                          __builtin_return_address(0), &vaf);
-
-       va_end(args);
-
-       if (is_error && !shown_bug_once) {
-               /*
-                * Ask the user to file a bug report for the error, except
-                * if they may have caused the bug by fiddling with unsafe
-                * module parameters.
-                */
-               if (!test_taint(TAINT_USER))
-                       dev_notice(kdev, "%s", FDO_BUG_MSG);
-               shown_bug_once = true;
-       }
-}
-
 static int i915_get_bridge_dev(struct drm_i915_private *dev_priv)
 {
        int domain = pci_domain_nr(dev_priv->drm.pdev->bus);
index a3e0d97414e31bb61c1d51e7c2b1389aa1662bad..4e6210c335c962c307400219e6a6b940e6aa8c96 100644 (file)
 #define DRIVER_DATE            "20190730"
 #define DRIVER_TIMESTAMP       1564512624
 
-#if IS_ENABLED(CONFIG_DRM_I915_DEBUG)
-
-int __i915_inject_load_error(struct drm_i915_private *i915, int err,
-                            const char *func, int line);
-#define i915_inject_load_error(_i915, _err) \
-       __i915_inject_load_error((_i915), (_err), __func__, __LINE__)
-bool i915_error_injected(void);
-
-#else
-
-#define i915_inject_load_error(_i915, _err) 0
-#define i915_error_injected() false
-
-#endif
-
-#define i915_inject_probe_failure(i915) i915_inject_load_error((i915), -ENODEV)
-
-#define i915_probe_error(i915, fmt, ...)                                  \
-       __i915_printk(i915, i915_error_injected() ? KERN_DEBUG : KERN_ERR, \
-                     fmt, ##__VA_ARGS__)
-
 struct drm_i915_gem_object;
 
 enum hpd_pin {
@@ -2278,13 +2257,6 @@ intel_ggtt_update_needs_vtd_wa(struct drm_i915_private *dev_priv)
 }
 
 /* i915_drv.c */
-void __printf(3, 4)
-__i915_printk(struct drm_i915_private *dev_priv, const char *level,
-             const char *fmt, ...);
-
-#define i915_report_error(dev_priv, fmt, ...)                             \
-       __i915_printk(dev_priv, KERN_ERR, fmt, ##__VA_ARGS__)
-
 #ifdef CONFIG_COMPAT
 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
 #else
diff --git a/drivers/gpu/drm/i915/i915_utils.c b/drivers/gpu/drm/i915/i915_utils.c
new file mode 100644 (file)
index 0000000..16acdf7
--- /dev/null
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2019 Intel Corporation
+ */
+
+#include <drm/drm_drv.h>
+
+#include "i915_drv.h"
+#include "i915_utils.h"
+
+#define FDO_BUG_URL "https://bugs.freedesktop.org/enter_bug.cgi?product=DRI"
+#define FDO_BUG_MSG "Please file a bug at " FDO_BUG_URL " against DRM/Intel " \
+                   "providing the dmesg log by booting with drm.debug=0xf"
+
+void
+__i915_printk(struct drm_i915_private *dev_priv, const char *level,
+             const char *fmt, ...)
+{
+       static bool shown_bug_once;
+       struct device *kdev = dev_priv->drm.dev;
+       bool is_error = level[1] <= KERN_ERR[1];
+       bool is_debug = level[1] == KERN_DEBUG[1];
+       struct va_format vaf;
+       va_list args;
+
+       if (is_debug && !(drm_debug & DRM_UT_DRIVER))
+               return;
+
+       va_start(args, fmt);
+
+       vaf.fmt = fmt;
+       vaf.va = &args;
+
+       if (is_error)
+               dev_printk(level, kdev, "%pV", &vaf);
+       else
+               dev_printk(level, kdev, "[" DRM_NAME ":%ps] %pV",
+                          __builtin_return_address(0), &vaf);
+
+       va_end(args);
+
+       if (is_error && !shown_bug_once) {
+               /*
+                * Ask the user to file a bug report for the error, except
+                * if they may have caused the bug by fiddling with unsafe
+                * module parameters.
+                */
+               if (!test_taint(TAINT_USER))
+                       dev_notice(kdev, "%s", FDO_BUG_MSG);
+               shown_bug_once = true;
+       }
+}
+
+#if IS_ENABLED(CONFIG_DRM_I915_DEBUG)
+static unsigned int i915_probe_fail_count;
+
+int __i915_inject_load_error(struct drm_i915_private *i915, int err,
+                            const char *func, int line)
+{
+       if (i915_probe_fail_count >= i915_modparams.inject_load_failure)
+               return 0;
+
+       if (++i915_probe_fail_count < i915_modparams.inject_load_failure)
+               return 0;
+
+       __i915_printk(i915, KERN_INFO,
+                     "Injecting failure %d at checkpoint %u [%s:%d]\n",
+                     err, i915_modparams.inject_load_failure, func, line);
+       i915_modparams.inject_load_failure = 0;
+       return err;
+}
+
+bool i915_error_injected(void)
+{
+       return i915_probe_fail_count && !i915_modparams.inject_load_failure;
+}
+
+#endif
index 0c0fda36334d575bcba74554d851da074257de3a..d652ba5d2320a2c9336c10953e96c788611e1f45 100644 (file)
@@ -31,6 +31,8 @@
 #include <linux/types.h>
 #include <linux/workqueue.h>
 
+struct drm_i915_private;
+
 #undef WARN_ON
 /* Many gcc seem to no see through this and fall over :( */
 #if 0
 #define MISSING_CASE(x) WARN(1, "Missing case (%s == %ld)\n", \
                             __stringify(x), (long)(x))
 
+void __printf(3, 4)
+__i915_printk(struct drm_i915_private *dev_priv, const char *level,
+             const char *fmt, ...);
+
+#define i915_report_error(dev_priv, fmt, ...)                             \
+       __i915_printk(dev_priv, KERN_ERR, fmt, ##__VA_ARGS__)
+
+#if IS_ENABLED(CONFIG_DRM_I915_DEBUG)
+
+int __i915_inject_load_error(struct drm_i915_private *i915, int err,
+                            const char *func, int line);
+#define i915_inject_load_error(_i915, _err) \
+       __i915_inject_load_error((_i915), (_err), __func__, __LINE__)
+bool i915_error_injected(void);
+
+#else
+
+#define i915_inject_load_error(_i915, _err) 0
+#define i915_error_injected() false
+
+#endif
+
+#define i915_inject_probe_failure(i915) i915_inject_load_error((i915), -ENODEV)
+
+#define i915_probe_error(i915, fmt, ...)                                  \
+       __i915_printk(i915, i915_error_injected() ? KERN_DEBUG : KERN_ERR, \
+                     fmt, ##__VA_ARGS__)
+
 #if defined(GCC_VERSION) && GCC_VERSION >= 70000
 #define add_overflows_t(T, A, B) \
        __builtin_add_overflow_p((A), (B), (T)0)