XenevaOS
Loading...
Searching...
No Matches
drm_print.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 Red Hat
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors:
23 * Rob Clark <robdclark@gmail.com>
24 */
25
26#ifndef DRM_PRINT_H_
27#define DRM_PRINT_H_
28
29#include <linux/compiler.h>
30#include <linux/printk.h>
31/*
32 * DCL delta: DRM_DEV_ERROR_RATELIMITED and friends below expand
33 * DEFINE_RATELIMIT_STATE, which mainline's printk.h chain happens to make
34 * visible and DCL's does not. virtgpu_vq.c:254 is the first reader in this
35 * tree (DRM_ERROR_RATELIMITED in the command-response reap).
36 */
37#include <linux/ratelimit.h>
38#include <linux/device.h>
39#include <linux/dynamic_debug.h>
40
41#include <drm/drm.h>
42#include <drm/drm_device.h>
43
44struct debugfs_regset32;
45struct drm_device;
46struct seq_file;
47
48/* Do *not* use outside of drm_print.[ch]! */
49extern unsigned long __drm_debug;
50
150
151static inline bool drm_debug_enabled_raw(enum drm_debug_category category)
152{
153 return unlikely(__drm_debug & BIT(category));
154}
155
156#define drm_debug_enabled_instrumented(category) \
157 ({ \
158 pr_debug("todo: is this frequent enough to optimize ?\n"); \
159 drm_debug_enabled_raw(category); \
160 })
161
162#if defined(CONFIG_DRM_USE_DYNAMIC_DEBUG)
163/*
164 * the drm.debug API uses dyndbg, so each drm_*dbg macro/callsite gets
165 * a descriptor, and only enabled callsites are reachable. They use
166 * the private macro to avoid re-testing the enable-bit.
167 */
168#define __drm_debug_enabled(category) true
169#define drm_debug_enabled(category) drm_debug_enabled_instrumented(category)
170#else
171#define __drm_debug_enabled(category) drm_debug_enabled_raw(category)
172#define drm_debug_enabled(category) drm_debug_enabled_raw(category)
173#endif
174
182 /* private: */
183 void (*printfn)(struct drm_printer *p, struct va_format *vaf);
184 void (*puts)(struct drm_printer *p, const char *str);
185 void *arg;
186 const void *origin;
187 const char *prefix;
188 struct {
189 unsigned int series;
190 unsigned int counter;
193};
194
195void __drm_printfn_coredump(struct drm_printer *p, struct va_format *vaf);
196void __drm_puts_coredump(struct drm_printer *p, const char *str);
197void __drm_printfn_seq_file(struct drm_printer *p, struct va_format *vaf);
198void __drm_puts_seq_file(struct drm_printer *p, const char *str);
199void __drm_printfn_info(struct drm_printer *p, struct va_format *vaf);
200void __drm_printfn_dbg(struct drm_printer *p, struct va_format *vaf);
201void __drm_printfn_err(struct drm_printer *p, struct va_format *vaf);
202void __drm_printfn_line(struct drm_printer *p, struct va_format *vaf);
203
205void drm_printf(struct drm_printer *p, const char *f, ...);
206void drm_puts(struct drm_printer *p, const char *str);
207void drm_print_regset32(struct drm_printer *p, struct debugfs_regset32 *regset);
208void drm_print_bits(struct drm_printer *p, unsigned long value,
209 const char * const bits[], unsigned int nbits);
210void drm_print_hex_dump(struct drm_printer *p, const char *prefix,
211 const u8 *buf, size_t len);
212
220static inline void
221drm_vprintf(struct drm_printer *p, const char *fmt, va_list *va)
222{
223 struct va_format vaf = { .fmt = fmt, .va = va };
224
225 p->printfn(p, &vaf);
226}
227
234#define drm_printf_indent(printer, indent, fmt, ...) \
235 drm_printf((printer), "%.*s" fmt, (indent), "\t\t\t\t\tX", ##__VA_ARGS__)
236
251
339static inline struct drm_printer
340drm_coredump_printer(struct drm_print_iterator *iter)
341{
342 struct drm_printer p = {
344 .puts = __drm_puts_coredump,
345 .arg = iter,
346 };
347
348 /* Set the internal offset of the iterator to zero */
349 iter->offset = 0;
350
351 return p;
352}
353
364static inline bool drm_coredump_printer_is_full(struct drm_printer *p)
365{
366 struct drm_print_iterator *iterator = p->arg;
367
369 return true;
370
371 return !iterator->remain;
372}
373
381static inline struct drm_printer drm_seq_file_printer(struct seq_file *f)
382{
383 struct drm_printer p = {
385 .puts = __drm_puts_seq_file,
386 .arg = f,
387 };
388 return p;
389}
390
398static inline struct drm_printer drm_info_printer(struct device *dev)
399{
400 struct drm_printer p = {
402 .arg = dev,
403 };
404 return p;
405}
406
416static inline struct drm_printer drm_dbg_printer(struct drm_device *drm,
418 const char *prefix)
419{
420 struct drm_printer p = {
422 .arg = drm,
423 .origin = (const void *)_THIS_IP_, /* it's fine as we will be inlined */
424 .prefix = prefix,
426 };
427 return p;
428}
429
438static inline struct drm_printer drm_err_printer(struct drm_device *drm,
439 const char *prefix)
440{
441 struct drm_printer p = {
443 .arg = drm,
444 .prefix = prefix
445 };
446 return p;
447}
448
495static inline struct drm_printer drm_line_printer(struct drm_printer *p,
496 const char *prefix,
497 unsigned int series)
498{
499 struct drm_printer lp = {
501 .arg = p,
502 .prefix = prefix,
503 .line = { .series = series, },
504 };
505 return lp;
506}
507
508/*
509 * struct device based logging
510 *
511 * Prefer drm_device based logging over device or printk based logging.
512 */
513
515void drm_dev_printk(const struct device *dev, const char *level,
516 const char *format, ...);
517struct _ddebug;
519void __drm_dev_dbg(struct _ddebug *desc, const struct device *dev,
520 enum drm_debug_category category, const char *format, ...);
521
530#define DRM_DEV_ERROR(dev, fmt, ...) \
531 drm_dev_printk(dev, KERN_ERR, "*ERROR* " fmt, ##__VA_ARGS__)
532
544#define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...) \
545({ \
546 static DEFINE_RATELIMIT_STATE(_rs, \
547 DEFAULT_RATELIMIT_INTERVAL, \
548 DEFAULT_RATELIMIT_BURST); \
549 \
550 if (__ratelimit(&_rs)) \
551 DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__); \
552})
553
554/* NOTE: this is deprecated in favor of drm_info() or dev_info(). */
555#define DRM_DEV_INFO(dev, fmt, ...) \
556 drm_dev_printk(dev, KERN_INFO, fmt, ##__VA_ARGS__)
557
558/* NOTE: this is deprecated in favor of drm_info_once() or dev_info_once(). */
559#define DRM_DEV_INFO_ONCE(dev, fmt, ...) \
560({ \
561 static bool __print_once __read_mostly; \
562 if (!__print_once) { \
563 __print_once = true; \
564 DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__); \
565 } \
566})
567
568#if !defined(CONFIG_DRM_USE_DYNAMIC_DEBUG)
569#define drm_dev_dbg(dev, cat, fmt, ...) \
570 __drm_dev_dbg(NULL, dev, cat, fmt, ##__VA_ARGS__)
571#else
572#define drm_dev_dbg(dev, cat, fmt, ...) \
573 _dynamic_func_call_cls(cat, fmt, __drm_dev_dbg, \
574 dev, cat, fmt, ##__VA_ARGS__)
575#endif
576
585#define DRM_DEV_DEBUG(dev, fmt, ...) \
586 drm_dev_dbg(dev, DRM_UT_CORE, fmt, ##__VA_ARGS__)
595#define DRM_DEV_DEBUG_DRIVER(dev, fmt, ...) \
596 drm_dev_dbg(dev, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
605#define DRM_DEV_DEBUG_KMS(dev, fmt, ...) \
606 drm_dev_dbg(dev, DRM_UT_KMS, fmt, ##__VA_ARGS__)
607
608/*
609 * struct drm_device based logging
610 *
611 * Prefer drm_device based logging over device or prink based logging.
612 */
613
614/* Helper to enforce struct drm_device type */
615static inline struct device *__drm_to_dev(const struct drm_device *drm)
616{
617 return drm ? drm->dev : NULL;
618}
619
620/* Helper for struct drm_device based logging. */
621#define __drm_printk(drm, level, type, fmt, ...) \
622 dev_##level##type(__drm_to_dev(drm), "[drm] " fmt, ##__VA_ARGS__)
623
624
625#define drm_info(drm, fmt, ...) \
626 __drm_printk((drm), info,, fmt, ##__VA_ARGS__)
627
628#define drm_notice(drm, fmt, ...) \
629 __drm_printk((drm), notice,, fmt, ##__VA_ARGS__)
630
631#define drm_warn(drm, fmt, ...) \
632 __drm_printk((drm), warn,, fmt, ##__VA_ARGS__)
633
634#define drm_err(drm, fmt, ...) \
635 __drm_printk((drm), err,, "*ERROR* " fmt, ##__VA_ARGS__)
636
637
638#define drm_info_once(drm, fmt, ...) \
639 __drm_printk((drm), info, _once, fmt, ##__VA_ARGS__)
640
641#define drm_notice_once(drm, fmt, ...) \
642 __drm_printk((drm), notice, _once, fmt, ##__VA_ARGS__)
643
644#define drm_warn_once(drm, fmt, ...) \
645 __drm_printk((drm), warn, _once, fmt, ##__VA_ARGS__)
646
647#define drm_err_once(drm, fmt, ...) \
648 __drm_printk((drm), err, _once, "*ERROR* " fmt, ##__VA_ARGS__)
649
650
651#define drm_err_ratelimited(drm, fmt, ...) \
652 __drm_printk((drm), err, _ratelimited, "*ERROR* " fmt, ##__VA_ARGS__)
653
654
655#define drm_dbg_core(drm, fmt, ...) \
656 drm_dev_dbg(__drm_to_dev(drm), DRM_UT_CORE, fmt, ##__VA_ARGS__)
657#define drm_dbg_driver(drm, fmt, ...) \
658 drm_dev_dbg(__drm_to_dev(drm), DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
659#define drm_dbg_kms(drm, fmt, ...) \
660 drm_dev_dbg(__drm_to_dev(drm), DRM_UT_KMS, fmt, ##__VA_ARGS__)
661#define drm_dbg_prime(drm, fmt, ...) \
662 drm_dev_dbg(__drm_to_dev(drm), DRM_UT_PRIME, fmt, ##__VA_ARGS__)
663#define drm_dbg_atomic(drm, fmt, ...) \
664 drm_dev_dbg(__drm_to_dev(drm), DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
665#define drm_dbg_vbl(drm, fmt, ...) \
666 drm_dev_dbg(__drm_to_dev(drm), DRM_UT_VBL, fmt, ##__VA_ARGS__)
667#define drm_dbg_state(drm, fmt, ...) \
668 drm_dev_dbg(__drm_to_dev(drm), DRM_UT_STATE, fmt, ##__VA_ARGS__)
669#define drm_dbg_lease(drm, fmt, ...) \
670 drm_dev_dbg(__drm_to_dev(drm), DRM_UT_LEASE, fmt, ##__VA_ARGS__)
671#define drm_dbg_dp(drm, fmt, ...) \
672 drm_dev_dbg(__drm_to_dev(drm), DRM_UT_DP, fmt, ##__VA_ARGS__)
673#define drm_dbg_drmres(drm, fmt, ...) \
674 drm_dev_dbg(__drm_to_dev(drm), DRM_UT_DRMRES, fmt, ##__VA_ARGS__)
675
676#define drm_dbg(drm, fmt, ...) drm_dbg_driver(drm, fmt, ##__VA_ARGS__)
677
678/*
679 * printk based logging
680 *
681 * Prefer drm_device based logging over device or prink based logging.
682 */
683
685void __drm_err(const char *format, ...);
686
687#if !defined(CONFIG_DRM_USE_DYNAMIC_DEBUG)
688#define __drm_dbg(cat, fmt, ...) __drm_dev_dbg(NULL, NULL, cat, fmt, ##__VA_ARGS__)
689#else
690#define __drm_dbg(cat, fmt, ...) \
691 _dynamic_func_call_cls(cat, fmt, __drm_dev_dbg, \
692 NULL, cat, fmt, ##__VA_ARGS__)
693#endif
694
695/* Macros to make printk easier */
696
697#define _DRM_PRINTK(once, level, fmt, ...) \
698 printk##once(KERN_##level "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
699
700/* NOTE: this is deprecated in favor of pr_info(). */
701#define DRM_INFO(fmt, ...) \
702 _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
703/* NOTE: this is deprecated in favor of pr_notice(). */
704#define DRM_NOTE(fmt, ...) \
705 _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
706/* NOTE: this is deprecated in favor of pr_warn(). */
707#define DRM_WARN(fmt, ...) \
708 _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
709
710/* NOTE: this is deprecated in favor of pr_info_once(). */
711#define DRM_INFO_ONCE(fmt, ...) \
712 _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
713/* NOTE: this is deprecated in favor of pr_notice_once(). */
714#define DRM_NOTE_ONCE(fmt, ...) \
715 _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
716/* NOTE: this is deprecated in favor of pr_warn_once(). */
717#define DRM_WARN_ONCE(fmt, ...) \
718 _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
719
720/* NOTE: this is deprecated in favor of pr_err(). */
721#define DRM_ERROR(fmt, ...) \
722 __drm_err(fmt, ##__VA_ARGS__)
723
724/* NOTE: this is deprecated in favor of pr_err_ratelimited(). */
725#define DRM_ERROR_RATELIMITED(fmt, ...) \
726 DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__)
727
728/* NOTE: this is deprecated in favor of drm_dbg_core(NULL, ...). */
729#define DRM_DEBUG(fmt, ...) \
730 __drm_dbg(DRM_UT_CORE, fmt, ##__VA_ARGS__)
731
732/* NOTE: this is deprecated in favor of drm_dbg(NULL, ...). */
733#define DRM_DEBUG_DRIVER(fmt, ...) \
734 __drm_dbg(DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
735
736/* NOTE: this is deprecated in favor of drm_dbg_kms(NULL, ...). */
737#define DRM_DEBUG_KMS(fmt, ...) \
738 __drm_dbg(DRM_UT_KMS, fmt, ##__VA_ARGS__)
739
740/* NOTE: this is deprecated in favor of drm_dbg_prime(NULL, ...). */
741#define DRM_DEBUG_PRIME(fmt, ...) \
742 __drm_dbg(DRM_UT_PRIME, fmt, ##__VA_ARGS__)
743
744/* NOTE: this is deprecated in favor of drm_dbg_atomic(NULL, ...). */
745#define DRM_DEBUG_ATOMIC(fmt, ...) \
746 __drm_dbg(DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
747
748/* NOTE: this is deprecated in favor of drm_dbg_vbl(NULL, ...). */
749#define DRM_DEBUG_VBL(fmt, ...) \
750 __drm_dbg(DRM_UT_VBL, fmt, ##__VA_ARGS__)
751
752/* NOTE: this is deprecated in favor of drm_dbg_lease(NULL, ...). */
753#define DRM_DEBUG_LEASE(fmt, ...) \
754 __drm_dbg(DRM_UT_LEASE, fmt, ##__VA_ARGS__)
755
756/* NOTE: this is deprecated in favor of drm_dbg_dp(NULL, ...). */
757#define DRM_DEBUG_DP(fmt, ...) \
758 __drm_dbg(DRM_UT_DP, fmt, ## __VA_ARGS__)
759
760#define __DRM_DEFINE_DBG_RATELIMITED(category, drm, fmt, ...) \
761({ \
762 static DEFINE_RATELIMIT_STATE(rs_, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST);\
763 \
764 if (drm_debug_enabled(DRM_UT_ ## category) && __ratelimit(&rs_)) \
765 drm_dev_printk(__drm_to_dev(drm), KERN_DEBUG, fmt, ## __VA_ARGS__); \
766})
767
768#define drm_dbg_ratelimited(drm, fmt, ...) \
769 __DRM_DEFINE_DBG_RATELIMITED(DRIVER, drm, fmt, ## __VA_ARGS__)
770
771#define drm_dbg_kms_ratelimited(drm, fmt, ...) \
772 __DRM_DEFINE_DBG_RATELIMITED(KMS, drm, fmt, ## __VA_ARGS__)
773
774/*
775 * struct drm_device based WARNs
776 *
777 * drm_WARN*() acts like WARN*(), but with the key difference of
778 * using device specific information so that we know from which device
779 * warning is originating from.
780 *
781 * Prefer drm_device based drm_WARN* over regular WARN*
782 */
783
784/* Helper for struct drm_device based WARNs */
785#define drm_WARN(drm, condition, format, arg...) \
786 WARN(condition, "%s %s: [drm] " format, \
787 dev_driver_string(__drm_to_dev(drm)), \
788 dev_name(__drm_to_dev(drm)), ## arg)
789
790#define drm_WARN_ONCE(drm, condition, format, arg...) \
791 WARN_ONCE(condition, "%s %s: [drm] " format, \
792 dev_driver_string(__drm_to_dev(drm)), \
793 dev_name(__drm_to_dev(drm)), ## arg)
794
795#define drm_WARN_ON(drm, x) \
796 drm_WARN((drm), (x), "%s", \
797 "drm_WARN_ON(" __stringify(x) ")")
798
799#define drm_WARN_ON_ONCE(drm, x) \
800 drm_WARN_ONCE((drm), (x), "%s", \
801 "drm_WARN_ON_ONCE(" __stringify(x) ")")
802
803#endif /* DRM_PRINT_H_ */
int64_t ssize_t
Definition stddef.h:38
char * va_list
Definition acmsvcex.h:186
#define NULL
Definition actypes.h:561
#define _THIS_IP_
Definition linkage.h:46
#define BIT(nr)
Definition bitops.h:112
#define __printf(fmt_idx, arg_idx)
Definition compiler.h:144
#define unlikely(x)
Definition compiler.h:30
const struct device * dev
Definition drm_print.h:519
const char const char * format
Definition drm_print.h:516
void __drm_printfn_err(struct drm_printer *p, struct va_format *vaf)
const char * fmt
Definition drm_print.h:221
void __drm_printfn_info(struct drm_printer *p, struct va_format *vaf)
const char void drm_puts(struct drm_printer *p, const char *str)
const char * level
Definition drm_print.h:515
void __drm_puts_coredump(struct drm_printer *p, const char *str)
void __drm_printfn_coredump(struct drm_printer *p, struct va_format *vaf)
void drm_print_hex_dump(struct drm_printer *p, const char *prefix, const u8 *buf, size_t len)
drm_debug_category
Definition drm_print.h:105
@ DRM_UT_PRIME
Definition drm_print.h:124
@ DRM_UT_VBL
Definition drm_print.h:132
@ DRM_UT_DRMRES
Definition drm_print.h:148
@ DRM_UT_DP
Definition drm_print.h:144
@ DRM_UT_CORE
Definition drm_print.h:111
@ DRM_UT_LEASE
Definition drm_print.h:140
@ DRM_UT_KMS
Definition drm_print.h:120
@ DRM_UT_ATOMIC
Definition drm_print.h:128
@ DRM_UT_DRIVER
Definition drm_print.h:116
@ DRM_UT_STATE
Definition drm_print.h:136
void drm_print_bits(struct drm_printer *p, unsigned long value, const char *const bits[], unsigned int nbits)
void drm_print_regset32(struct drm_printer *p, struct debugfs_regset32 *regset)
const char va_list * va
Definition drm_print.h:222
void __drm_puts_seq_file(struct drm_printer *p, const char *str)
void __drm_printfn_seq_file(struct drm_printer *p, struct va_format *vaf)
void __drm_printfn_line(struct drm_printer *p, struct va_format *vaf)
unsigned long __drm_debug
void __drm_printfn_dbg(struct drm_printer *p, struct va_format *vaf)
const char * f
Definition drm_print.h:205
size_t len
Definition initial.c:23
uint8_t u8
Definition kernel.h:14
Definition debugfs.h:44
Definition fs.h:255
Definition drm_device.h:75
struct device * dev
Definition drm_device.h:83
Definition drm_print.h:244
ssize_t offset
Definition drm_print.h:249
ssize_t remain
Definition drm_print.h:247
ssize_t start
Definition drm_print.h:246
void * data
Definition drm_print.h:245
Definition drm_print.h:181
void * arg
Definition drm_print.h:185
const void * origin
Definition drm_print.h:186
struct drm_printer::@52 line
const char * prefix
Definition drm_print.h:187
enum drm_debug_category category
Definition drm_print.h:192
unsigned int series
Definition drm_print.h:189
unsigned int counter
Definition drm_print.h:190
void(* puts)(struct drm_printer *p, const char *str)
Definition drm_print.h:184
void(* printfn)(struct drm_printer *p, struct va_format *vaf)
Definition drm_print.h:183
Definition seq_file.h:47
Definition printk.h:36
const char * fmt
Definition printk.h:37