Add a silimar log mechanism as like drm. Classify GVT-g log messages
as different categories by differnt log functions.

Signed-off-by: Shuo Liu <[email protected]>
---
 drivers/gpu/drm/i915/Kconfig       |  8 +++++++
 drivers/gpu/drm/i915/gvt/Makefile  |  1 +
 drivers/gpu/drm/i915/gvt/debug.c   | 24 +++++++++++++++++++++
 drivers/gpu/drm/i915/gvt/debug.h   | 44 ++++++++++++++++++++++++++++----------
 drivers/gpu/drm/i915/i915_params.c | 13 +++++++++++
 drivers/gpu/drm/i915/i915_params.h |  1 +
 6 files changed, 80 insertions(+), 11 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/gvt/debug.c

diff --git a/drivers/gpu/drm/i915/Kconfig b/drivers/gpu/drm/i915/Kconfig
index a5cd5da..6282a2f 100644
--- a/drivers/gpu/drm/i915/Kconfig
+++ b/drivers/gpu/drm/i915/Kconfig
@@ -124,6 +124,14 @@ config DRM_I915_GVT_KVMGT
          Choose this option if you want to enable KVMGT support for
          Intel GVT-g.
 
+config DRM_I915_GVT_DEBUG
+       bool "Enable debug support for Intel GVT-g"
+       depends on DRM_I915_GVT
+       default n
+       help
+         Choose this option if you want to enable debug support for
+         Intel GVT-g.
+
 menu "drm/i915 Debugging"
 depends on DRM_I915
 depends on EXPERT
diff --git a/drivers/gpu/drm/i915/gvt/Makefile 
b/drivers/gpu/drm/i915/gvt/Makefile
index f5486cb9..b1826c2 100644
--- a/drivers/gpu/drm/i915/gvt/Makefile
+++ b/drivers/gpu/drm/i915/gvt/Makefile
@@ -5,4 +5,5 @@ GVT_SOURCE := gvt.o aperture_gm.o handlers.o vgpu.o 
trace_points.o firmware.o \
 
 ccflags-y                              += -I$(src) -I$(src)/$(GVT_DIR)
 i915-y                                 += $(addprefix $(GVT_DIR)/, 
$(GVT_SOURCE))
+i915-$(CONFIG_DRM_I915_GVT_DEBUG)      += $(GVT_DIR)/debug.o
 obj-$(CONFIG_DRM_I915_GVT_KVMGT)       += $(GVT_DIR)/kvmgt.o
diff --git a/drivers/gpu/drm/i915/gvt/debug.c b/drivers/gpu/drm/i915/gvt/debug.c
new file mode 100644
index 0000000..75b4d0c
--- /dev/null
+++ b/drivers/gpu/drm/i915/gvt/debug.c
@@ -0,0 +1,24 @@
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include "i915_drv.h"
+#include "debug.h"
+
+void gvt_printk(const char *level, unsigned int category,
+               const char *format, ...)
+{
+       struct va_format vaf;
+       va_list args;
+
+       if (category != GVT_MSG_NONE && !(i915.debug_gvt & category))
+               return;
+
+       va_start(args, format);
+       vaf.fmt = format;
+       vaf.va = &args;
+
+       printk("%s[gvt:%ps]%s %pV",
+               level, __builtin_return_address(0),
+               strcmp(level, KERN_ERR) == 0 ? " *ERROR*" : "", &vaf);
+
+       va_end(args);
+}
diff --git a/drivers/gpu/drm/i915/gvt/debug.h b/drivers/gpu/drm/i915/gvt/debug.h
index b0cff4d..7a54f82 100644
--- a/drivers/gpu/drm/i915/gvt/debug.h
+++ b/drivers/gpu/drm/i915/gvt/debug.h
@@ -24,42 +24,64 @@
 #ifndef __GVT_DEBUG_H__
 #define __GVT_DEBUG_H__
 
+#define GVT_MSG_NONE           0x00
+#define GVT_MSG_CORE           0x01
+#define GVT_MSG_IRQ            0x02
+#define GVT_MSG_MM             0x04
+#define GVT_MSG_MMIO           0x08
+#define GVT_MSG_DPY            0x10
+#define GVT_MSG_EL             0x20
+#define GVT_MSG_SCHED          0x40
+#define GVT_MSG_RENDER         0x80
+#define GVT_MSG_CMD            0x100
+
+#if IS_ENABLED(CONFIG_DRM_I915_GVT_DEBUG)
+__printf(3, 4)
+void gvt_printk(const char *level, unsigned int category,
+               const char *format, ...);
+#else
+static inline __printf(3, 4)
+void gvt_printk(const char *level, unsigned int category,
+               const char *format, ...) {}
+#endif
+
 #define gvt_err(fmt, args...) \
        DRM_ERROR("gvt: "fmt, ##args)
 
 #define gvt_vgpu_err(fmt, args...)                                     \
 do {                                                                   \
        if (IS_ERR_OR_NULL(vgpu))                                       \
-               DRM_DEBUG_DRIVER("gvt: "fmt, ##args);                   \
+               gvt_printk(KERN_WARNING, GVT_MSG_CORE, fmt, ##args);    \
        else                                                            \
-               DRM_DEBUG_DRIVER("gvt: vgpu %d: "fmt, vgpu->id, ##args);\
+               gvt_printk(KERN_WARNING, GVT_MSG_CORE,                  \
+                               "vgpu %d: "fmt, vgpu->id, ##args);      \
 } while (0)
 
 #define gvt_dbg_core(fmt, args...) \
-       DRM_DEBUG_DRIVER("gvt: core: "fmt, ##args)
+       gvt_printk(KERN_DEBUG, GVT_MSG_CORE, "core: "fmt, ##args)
 
 #define gvt_dbg_irq(fmt, args...) \
-       DRM_DEBUG_DRIVER("gvt: irq: "fmt, ##args)
+       gvt_printk(KERN_DEBUG, GVT_MSG_IRQ, "irq: "fmt, ##args)
 
 #define gvt_dbg_mm(fmt, args...) \
-       DRM_DEBUG_DRIVER("gvt: mm: "fmt, ##args)
+       gvt_printk(KERN_DEBUG, GVT_MSG_MM, "mm: "fmt, ##args)
 
 #define gvt_dbg_mmio(fmt, args...) \
-       DRM_DEBUG_DRIVER("gvt: mmio: "fmt, ##args)
+       gvt_printk(KERN_DEBUG, GVT_MSG_MMIO, "mmio: "fmt, ##args)
 
 #define gvt_dbg_dpy(fmt, args...) \
-       DRM_DEBUG_DRIVER("gvt: dpy: "fmt, ##args)
+       gvt_printk(KERN_DEBUG, GVT_MSG_DPY, "dpy: "fmt, ##args)
 
 #define gvt_dbg_el(fmt, args...) \
-       DRM_DEBUG_DRIVER("gvt: el: "fmt, ##args)
+       gvt_printk(KERN_DEBUG, GVT_MSG_EL, "el: "fmt, ##args)
 
 #define gvt_dbg_sched(fmt, args...) \
-       DRM_DEBUG_DRIVER("gvt: sched: "fmt, ##args)
+       gvt_printk(KERN_DEBUG, GVT_MSG_SCHED, "sched: "fmt, ##args)
 
 #define gvt_dbg_render(fmt, args...) \
-       DRM_DEBUG_DRIVER("gvt: render: "fmt, ##args)
+       gvt_printk(KERN_DEBUG, GVT_MSG_RENDER, "render: "fmt, ##args)
 
 #define gvt_dbg_cmd(fmt, args...) \
-       DRM_DEBUG_DRIVER("gvt: cmd: "fmt, ##args)
+       gvt_printk(KERN_DEBUG, GVT_MSG_CMD, "cmd: "fmt, ##args)
 
 #endif
diff --git a/drivers/gpu/drm/i915/i915_params.c 
b/drivers/gpu/drm/i915/i915_params.c
index b6a7e36..7461829 100644
--- a/drivers/gpu/drm/i915/i915_params.c
+++ b/drivers/gpu/drm/i915/i915_params.c
@@ -65,6 +65,7 @@ struct i915_params i915 __read_mostly = {
        .inject_load_failure = 0,
        .enable_dpcd_backlight = false,
        .enable_gvt = false,
+       .debug_gvt = 0,
 };
 
 module_param_named(modeset, i915.modeset, int, 0400);
@@ -253,3 +254,15 @@ struct i915_params i915 __read_mostly = {
 module_param_named(enable_gvt, i915.enable_gvt, bool, 0400);
 MODULE_PARM_DESC(enable_gvt,
        "Enable support for Intel GVT-g graphics virtualization host 
support(default:false)");
+
+module_param_named(debug_gvt, i915.debug_gvt, int, 0600);
+MODULE_PARM_DESC(debug_gvt, "Enable GVT-g debug output, where each bit enables 
a category.\n"
+               "\t\tBit 0 (0x01) will enable CORE messages (GVT-g core 
message)\n"
+               "\t\tBit 1 (0x02) will enable IRQ messages (GVT-g interrupt 
message)\n"
+               "\t\tBit 2 (0x04) will enable MM messages (GVT-g memory 
management message)\n"
+               "\t\tBit 3 (0x08) will enable MMIO messages (GVT-g MMIO 
message)\n"
+               "\t\tBit 4 (0x10) will enable DPY messages (GVT-g display 
message)\n"
+               "\t\tBit 5 (0x20) will enable EL messages (GVT-g execlist 
message)\n"
+               "\t\tBit 6 (0x40) will enable SCHED messages (GVT-g schedule 
message)\n"
+               "\t\tBit 7 (0x80) will enable RENDER messages (GVT-g render 
message)\n"
+               "\t\tBit 8 (0x100) will enable CMD messages (GVT-g command 
message)");
diff --git a/drivers/gpu/drm/i915/i915_params.h 
b/drivers/gpu/drm/i915/i915_params.h
index 34148cc..71c7454 100644
--- a/drivers/gpu/drm/i915/i915_params.h
+++ b/drivers/gpu/drm/i915/i915_params.h
@@ -52,6 +52,7 @@
        func(int, mmio_debug); \
        func(int, edp_vswing); \
        func(unsigned int, inject_load_failure); \
+       func(int, debug_gvt); \
        /* leave bools at the end to not create holes */ \
        func(bool, alpha_support); \
        func(bool, enable_cmd_parser); \
-- 
1.9.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to