[PATCH 2/9] drm/print: add drm_dbg_printer() to print to drm_dev_dbg()
Jani Nikula
jani.nikula at intel.com
Thu Sep 21 11:18:46 UTC 2023
We've lacked a device specific debug printer. Add one. Take category
into account too.
The caller function debug logging may be inaccurate, depending on how
the compiler combines functions. It might be fine, but also might end up
being useless. This can be cleaned up later if needed. Adding the device
is the more important part here.
Signed-off-by: Jani Nikula <jani.nikula at intel.com>
---
drivers/gpu/drm/drm_print.c | 16 ++++++++++++++++
include/drm/drm_print.h | 26 ++++++++++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c
index 5b93c11895bb..590b1b8435f7 100644
--- a/drivers/gpu/drm/drm_print.c
+++ b/drivers/gpu/drm/drm_print.c
@@ -189,6 +189,22 @@ void __drm_printfn_debug(struct drm_printer *p, struct va_format *vaf)
}
EXPORT_SYMBOL(__drm_printfn_debug);
+void __drm_printfn_dbg(struct drm_printer *p, struct va_format *vaf)
+{
+ struct drm_device *drm = p->arg;
+ enum drm_debug_category category = p->category;
+
+ /*
+ * Note: Depending on the compiler optimizations, the emitted
+ * __builtin_return_address(0) may be useless.
+ */
+ if (p->prefix)
+ drm_dev_dbg(drm ? drm->dev : NULL, category, "%s %pV", p->prefix, vaf);
+ else
+ drm_dev_dbg(drm ? drm->dev : NULL, category, "%pV", vaf);
+}
+EXPORT_SYMBOL(__drm_printfn_dbg);
+
void __drm_printfn_err(struct drm_printer *p, struct va_format *vaf)
{
pr_err("*ERROR* %s %pV", p->prefix, vaf);
diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h
index 1c50a9437fe1..385d8aa559dc 100644
--- a/include/drm/drm_print.h
+++ b/include/drm/drm_print.h
@@ -35,6 +35,8 @@
#include <drm/drm.h>
+struct drm_device;
+
/* Do *not* use outside of drm_print.[ch]! */
extern unsigned long __drm_debug;
@@ -174,6 +176,7 @@ struct drm_printer {
void (*puts)(struct drm_printer *p, const char *str);
void *arg;
const char *prefix;
+ enum drm_debug_category category;
};
void __drm_printfn_coredump(struct drm_printer *p, struct va_format *vaf);
@@ -182,6 +185,7 @@ void __drm_printfn_seq_file(struct drm_printer *p, struct va_format *vaf);
void __drm_puts_seq_file(struct drm_printer *p, const char *str);
void __drm_printfn_info(struct drm_printer *p, struct va_format *vaf);
void __drm_printfn_debug(struct drm_printer *p, struct va_format *vaf);
+void __drm_printfn_dbg(struct drm_printer *p, struct va_format *vaf);
void __drm_printfn_err(struct drm_printer *p, struct va_format *vaf);
__printf(2, 3)
@@ -329,6 +333,28 @@ static inline struct drm_printer drm_debug_printer(const char *prefix)
return p;
}
+/**
+ * drm_dbg_printer - construct a &drm_printer that outputs to drm_dev_dbg()
+ * @drm: the &struct drm_device pointer
+ * @category: the debug category to use
+ * @prefix: debug output prefix, or NULL for no prefix
+ *
+ * RETURNS:
+ * The &drm_printer object
+ */
+static inline struct drm_printer drm_dbg_printer(struct drm_device *drm,
+ enum drm_debug_category category,
+ const char *prefix)
+{
+ struct drm_printer p = {
+ .printfn = __drm_printfn_dbg,
+ .arg = drm,
+ .prefix = prefix,
+ .category = category,
+ };
+ return p;
+}
+
/**
* drm_err_printer - construct a &drm_printer that outputs to pr_err()
* @prefix: debug output prefix
--
2.39.2
More information about the Intel-gfx-trybot
mailing list