]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/gpu/drm/drm_print.c
drm: add drm_print_bits
[linux.git] / drivers / gpu / drm / drm_print.c
index f5cb0aabfe35ba1e295a2d706c6ae3b22d7f8707..dfa27367ebb8537ec8874616e0f0b5532de34121 100644 (file)
 #define DEBUG /* for pr_debug() */
 
 #include <stdarg.h>
+
+#include <linux/io.h>
 #include <linux/seq_file.h>
-#include <drm/drmP.h>
+#include <linux/slab.h>
+
+#include <drm/drm.h>
+#include <drm/drm_drv.h>
 #include <drm/drm_print.h>
 
 void __drm_puts_coredump(struct drm_printer *p, const char *str)
@@ -142,6 +147,12 @@ void __drm_printfn_debug(struct drm_printer *p, struct va_format *vaf)
 }
 EXPORT_SYMBOL(__drm_printfn_debug);
 
+void __drm_printfn_err(struct drm_printer *p, struct va_format *vaf)
+{
+       pr_err("*ERROR* %s %pV", p->prefix, vaf);
+}
+EXPORT_SYMBOL(__drm_printfn_err);
+
 /**
  * drm_puts - print a const string to a &drm_printer stream
  * @p: the &drm printer
@@ -174,6 +185,39 @@ void drm_printf(struct drm_printer *p, const char *f, ...)
 }
 EXPORT_SYMBOL(drm_printf);
 
+/**
+ * drm_print_bits - print bits to a &drm_printer stream
+ *
+ * Print bits (in flag fields for example) in human readable form.
+ * The first name in the @bits array is for the bit indexed by @from.
+ *
+ * @p: the &drm_printer
+ * @value: field value.
+ * @bits: Array with bit names.
+ * @from: start of bit range to print (inclusive).
+ * @to: end of bit range to print (exclusive).
+ */
+void drm_print_bits(struct drm_printer *p,
+                   unsigned long value, const char *bits[],
+                   unsigned int from, unsigned int to)
+{
+       bool first = true;
+       unsigned int i;
+
+       for (i = from; i < to; i++) {
+               if (!(value & (1 << i)))
+                       continue;
+               if (WARN_ON_ONCE(!bits[i-from]))
+                       continue;
+               drm_printf(p, "%s%s", first ? "" : ",",
+                          bits[i-from]);
+               first = false;
+       }
+       if (first)
+               drm_printf(p, "(none)");
+}
+EXPORT_SYMBOL(drm_print_bits);
+
 void drm_dev_printk(const struct device *dev, const char *level,
                    const char *format, ...)
 {