drm/i915: Add pretty printer for modparams
authorMichal Wajdeczko <michal.wajdeczko@intel.com>
Tue, 19 Dec 2017 11:43:46 +0000 (11:43 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Tue, 19 Dec 2017 15:07:08 +0000 (15:07 +0000)
We dump modparams in few places (debugfs, gpu_error) using different
functions. Lets add reusable function to avoid code duplication.

add/remove: 1/0 grow/shrink: 0/2 up/down: 1096/-2339 (-1243)
Function                                     old     new   delta
i915_params_dump                               -    1096   +1096
i915_capabilities                           1353     185   -1168
i915_error_state_to_str                     5507    4336   -1171
Total: Before=1285716, After=1284473, chg -0.10%

v2: use forward decl rather than include (Chris)

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Link: https://patchwork.freedesktop.org/patch/msgid/20171219114346.26308-3-michal.wajdeczko@intel.com
drivers/gpu/drm/i915/i915_debugfs.c
drivers/gpu/drm/i915/i915_gpu_error.c
drivers/gpu/drm/i915/i915_params.c
drivers/gpu/drm/i915/i915_params.h

index e384e288c1f207c373bfc14885c3b95a1f4a9abd..c4780f085428e287973a03e7ef80c62813299d53 100644 (file)
@@ -37,23 +37,6 @@ static inline struct drm_i915_private *node_to_i915(struct drm_info_node *node)
        return to_i915(node->minor->dev);
 }
 
-static __always_inline void seq_print_param(struct seq_file *m,
-                                           const char *name,
-                                           const char *type,
-                                           const void *x)
-{
-       if (!__builtin_strcmp(type, "bool"))
-               seq_printf(m, "i915.%s=%s\n", name, yesno(*(const bool *)x));
-       else if (!__builtin_strcmp(type, "int"))
-               seq_printf(m, "i915.%s=%d\n", name, *(const int *)x);
-       else if (!__builtin_strcmp(type, "unsigned int"))
-               seq_printf(m, "i915.%s=%u\n", name, *(const unsigned int *)x);
-       else if (!__builtin_strcmp(type, "char *"))
-               seq_printf(m, "i915.%s=%s\n", name, *(const char **)x);
-       else
-               BUILD_BUG();
-}
-
 static int i915_capabilities(struct seq_file *m, void *data)
 {
        struct drm_i915_private *dev_priv = node_to_i915(m->private);
@@ -67,9 +50,7 @@ static int i915_capabilities(struct seq_file *m, void *data)
        intel_device_info_dump_flags(info, &p);
 
        kernel_param_lock(THIS_MODULE);
-#define PRINT_PARAM(T, x, ...) seq_print_param(m, #x, #T, &i915_modparams.x);
-       I915_PARAMS_FOR_EACH(PRINT_PARAM);
-#undef PRINT_PARAM
+       i915_params_dump(&i915_modparams, &p);
        kernel_param_unlock(THIS_MODULE);
 
        return 0;
index 664f55c0545548c5d0a0ce09ed738dd7f2e2743e..84831e94eec87bd80550b4b0428570d5e12e8445 100644 (file)
@@ -569,29 +569,12 @@ static void err_print_capabilities(struct drm_i915_error_state_buf *m,
        intel_device_info_dump_flags(info, &p);
 }
 
-static __always_inline void err_print_param(struct drm_i915_error_state_buf *m,
-                                           const char *name,
-                                           const char *type,
-                                           const void *x)
-{
-       if (!__builtin_strcmp(type, "bool"))
-               err_printf(m, "i915.%s=%s\n", name, yesno(*(const bool *)x));
-       else if (!__builtin_strcmp(type, "int"))
-               err_printf(m, "i915.%s=%d\n", name, *(const int *)x);
-       else if (!__builtin_strcmp(type, "unsigned int"))
-               err_printf(m, "i915.%s=%u\n", name, *(const unsigned int *)x);
-       else if (!__builtin_strcmp(type, "char *"))
-               err_printf(m, "i915.%s=%s\n", name, *(const char **)x);
-       else
-               BUILD_BUG();
-}
-
 static void err_print_params(struct drm_i915_error_state_buf *m,
-                            const struct i915_params *p)
+                            const struct i915_params *params)
 {
-#define PRINT(T, x, ...) err_print_param(m, #x, #T, &p->x);
-       I915_PARAMS_FOR_EACH(PRINT);
-#undef PRINT
+       struct drm_printer p = i915_error_printer(m);
+
+       i915_params_dump(params, &p);
 }
 
 static void err_print_pciid(struct drm_i915_error_state_buf *m,
index 8dfea0320c2fffb451a538575499e50f86912c76..b5f3eb4fa8a34edd46d73e0abeb4401edbb6a12f 100644 (file)
@@ -22,6 +22,8 @@
  * IN THE SOFTWARE.
  */
 
+#include <drm/drm_print.h>
+
 #include "i915_params.h"
 #include "i915_drv.h"
 
@@ -172,3 +174,34 @@ i915_param_named(enable_dpcd_backlight, bool, 0600,
 
 i915_param_named(enable_gvt, bool, 0400,
        "Enable support for Intel GVT-g graphics virtualization host support(default:false)");
+
+static __always_inline void _print_param(struct drm_printer *p,
+                                        const char *name,
+                                        const char *type,
+                                        const void *x)
+{
+       if (!__builtin_strcmp(type, "bool"))
+               drm_printf(p, "i915.%s=%s\n", name, yesno(*(const bool *)x));
+       else if (!__builtin_strcmp(type, "int"))
+               drm_printf(p, "i915.%s=%d\n", name, *(const int *)x);
+       else if (!__builtin_strcmp(type, "unsigned int"))
+               drm_printf(p, "i915.%s=%u\n", name, *(const unsigned int *)x);
+       else if (!__builtin_strcmp(type, "char *"))
+               drm_printf(p, "i915.%s=%s\n", name, *(const char **)x);
+       else
+               BUILD_BUG();
+}
+
+/**
+ * i915_params_dump - dump i915 modparams
+ * @params: i915 modparams
+ * @p: the &drm_printer
+ *
+ * Pretty printer for i915 modparams.
+ */
+void i915_params_dump(const struct i915_params *params, struct drm_printer *p)
+{
+#define PRINT(T, x, ...) _print_param(p, #x, #T, &params->x);
+       I915_PARAMS_FOR_EACH(PRINT);
+#undef PRINT
+}
index 792ce26d744946d22e43d825f3c76820b4725da3..c9636039807219b0d5235270b614eda89e119ded 100644 (file)
@@ -28,6 +28,8 @@
 #include <linux/bitops.h>
 #include <linux/cache.h> /* for __read_mostly */
 
+struct drm_printer;
+
 #define ENABLE_GUC_SUBMISSION          BIT(0)
 #define ENABLE_GUC_LOAD_HUC            BIT(1)
 
@@ -77,5 +79,7 @@ struct i915_params {
 
 extern struct i915_params i915_modparams __read_mostly;
 
+void i915_params_dump(const struct i915_params *params, struct drm_printer *p);
+
 #endif