xref: /linux/include/drm/drm_print.h (revision 7ee983c850b40043ac4751836fbd9a2b4d0c5937)
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 #include <linux/device.h>
32 #include <linux/dynamic_debug.h>
33 
34 #include <drm/drm.h>
35 #include <drm/drm_device.h>
36 
37 struct debugfs_regset32;
38 struct drm_device;
39 struct seq_file;
40 
41 /* Do *not* use outside of drm_print.[ch]! */
42 extern unsigned long __drm_debug;
43 
44 /**
45  * DOC: print
46  *
47  * A simple wrapper for dev_printk(), seq_printf(), etc.  Allows same
48  * debug code to be used for both debugfs and printk logging.
49  *
50  * For example::
51  *
52  *     void log_some_info(struct drm_printer *p)
53  *     {
54  *             drm_printf(p, "foo=%d\n", foo);
55  *             drm_printf(p, "bar=%d\n", bar);
56  *     }
57  *
58  *     #ifdef CONFIG_DEBUG_FS
59  *     void debugfs_show(struct seq_file *f)
60  *     {
61  *             struct drm_printer p = drm_seq_file_printer(f);
62  *             log_some_info(&p);
63  *     }
64  *     #endif
65  *
66  *     void some_other_function(...)
67  *     {
68  *             struct drm_printer p = drm_info_printer(drm->dev);
69  *             log_some_info(&p);
70  *     }
71  */
72 
73 /**
74  * enum drm_debug_category - The DRM debug categories
75  *
76  * Each of the DRM debug logging macros use a specific category, and the logging
77  * is filtered by the drm.debug module parameter. This enum specifies the values
78  * for the interface.
79  *
80  * Each DRM_DEBUG_<CATEGORY> macro logs to DRM_UT_<CATEGORY> category, except
81  * DRM_DEBUG() logs to DRM_UT_CORE.
82  *
83  * Enabling verbose debug messages is done through the drm.debug parameter, each
84  * category being enabled by a bit:
85  *
86  *  - drm.debug=0x1 will enable CORE messages
87  *  - drm.debug=0x2 will enable DRIVER messages
88  *  - drm.debug=0x3 will enable CORE and DRIVER messages
89  *  - ...
90  *  - drm.debug=0x1ff will enable all messages
91  *
92  * An interesting feature is that it's possible to enable verbose logging at
93  * run-time by echoing the debug value in its sysfs node::
94  *
95  *   # echo 0xf > /sys/module/drm/parameters/debug
96  *
97  */
98 enum drm_debug_category {
99 	/* These names must match those in DYNAMIC_DEBUG_CLASSBITS */
100 	/**
101 	 * @DRM_UT_CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c,
102 	 * drm_memory.c, ...
103 	 */
104 	DRM_UT_CORE,
105 	/**
106 	 * @DRM_UT_DRIVER: Used in the vendor specific part of the driver: i915,
107 	 * radeon, ... macro.
108 	 */
109 	DRM_UT_DRIVER,
110 	/**
111 	 * @DRM_UT_KMS: Used in the modesetting code.
112 	 */
113 	DRM_UT_KMS,
114 	/**
115 	 * @DRM_UT_PRIME: Used in the prime code.
116 	 */
117 	DRM_UT_PRIME,
118 	/**
119 	 * @DRM_UT_ATOMIC: Used in the atomic code.
120 	 */
121 	DRM_UT_ATOMIC,
122 	/**
123 	 * @DRM_UT_VBL: Used for verbose debug message in the vblank code.
124 	 */
125 	DRM_UT_VBL,
126 	/**
127 	 * @DRM_UT_STATE: Used for verbose atomic state debugging.
128 	 */
129 	DRM_UT_STATE,
130 	/**
131 	 * @DRM_UT_LEASE: Used in the lease code.
132 	 */
133 	DRM_UT_LEASE,
134 	/**
135 	 * @DRM_UT_DP: Used in the DP code.
136 	 */
137 	DRM_UT_DP,
138 	/**
139 	 * @DRM_UT_DRMRES: Used in the drm managed resources code.
140 	 */
141 	DRM_UT_DRMRES
142 };
143 
drm_debug_enabled_raw(enum drm_debug_category category)144 static inline bool drm_debug_enabled_raw(enum drm_debug_category category)
145 {
146 	return unlikely(__drm_debug & BIT(category));
147 }
148 
149 #define drm_debug_enabled_instrumented(category)			\
150 	({								\
151 		pr_debug("todo: is this frequent enough to optimize ?\n"); \
152 		drm_debug_enabled_raw(category);			\
153 	})
154 
155 #if defined(CONFIG_DRM_USE_DYNAMIC_DEBUG)
156 /*
157  * the drm.debug API uses dyndbg, so each drm_*dbg macro/callsite gets
158  * a descriptor, and only enabled callsites are reachable.  They use
159  * the private macro to avoid re-testing the enable-bit.
160  */
161 #define __drm_debug_enabled(category)	true
162 #define drm_debug_enabled(category)	drm_debug_enabled_instrumented(category)
163 #else
164 #define __drm_debug_enabled(category)	drm_debug_enabled_raw(category)
165 #define drm_debug_enabled(category)	drm_debug_enabled_raw(category)
166 #endif
167 
168 /**
169  * struct drm_printer - drm output "stream"
170  *
171  * Do not use struct members directly.  Use drm_printer_seq_file(),
172  * drm_printer_info(), etc to initialize.  And drm_printf() for output.
173  */
174 struct drm_printer {
175 	/* private: */
176 	void (*printfn)(struct drm_printer *p, struct va_format *vaf);
177 	void (*puts)(struct drm_printer *p, const char *str);
178 	void *arg;
179 	const void *origin;
180 	const char *prefix;
181 	struct {
182 		unsigned int series;
183 		unsigned int counter;
184 	} line;
185 	enum drm_debug_category category;
186 };
187 
188 void __drm_printfn_coredump(struct drm_printer *p, struct va_format *vaf);
189 void __drm_puts_coredump(struct drm_printer *p, const char *str);
190 void __drm_printfn_seq_file(struct drm_printer *p, struct va_format *vaf);
191 void __drm_puts_seq_file(struct drm_printer *p, const char *str);
192 void __drm_printfn_info(struct drm_printer *p, struct va_format *vaf);
193 void __drm_printfn_dbg(struct drm_printer *p, struct va_format *vaf);
194 void __drm_printfn_err(struct drm_printer *p, struct va_format *vaf);
195 void __drm_printfn_line(struct drm_printer *p, struct va_format *vaf);
196 
197 __printf(2, 3)
198 void drm_printf(struct drm_printer *p, const char *f, ...);
199 void drm_puts(struct drm_printer *p, const char *str);
200 void drm_print_regset32(struct drm_printer *p, struct debugfs_regset32 *regset);
201 void drm_print_bits(struct drm_printer *p, unsigned long value,
202 		    const char * const bits[], unsigned int nbits);
203 void drm_print_hex_dump(struct drm_printer *p, const char *prefix,
204 			const u8 *buf, size_t len);
205 
206 __printf(2, 0)
207 /**
208  * drm_vprintf - print to a &drm_printer stream
209  * @p: the &drm_printer
210  * @fmt: format string
211  * @va: the va_list
212  */
213 static inline void
drm_vprintf(struct drm_printer * p,const char * fmt,va_list * va)214 drm_vprintf(struct drm_printer *p, const char *fmt, va_list *va)
215 {
216 	struct va_format vaf = { .fmt = fmt, .va = va };
217 
218 	p->printfn(p, &vaf);
219 }
220 
221 /**
222  * drm_printf_indent - Print to a &drm_printer stream with indentation
223  * @printer: DRM printer
224  * @indent: Tab indentation level (max 5)
225  * @fmt: Format string
226  */
227 #define drm_printf_indent(printer, indent, fmt, ...) \
228 	drm_printf((printer), "%.*s" fmt, (indent), "\t\t\t\t\tX", ##__VA_ARGS__)
229 
230 /**
231  * struct drm_print_iterator - local struct used with drm_printer_coredump
232  * @data: Pointer to the devcoredump output buffer, can be NULL if using
233  * drm_printer_coredump to determine size of devcoredump
234  * @start: The offset within the buffer to start writing
235  * @remain: The number of bytes to write for this iteration
236  */
237 struct drm_print_iterator {
238 	void *data;
239 	ssize_t start;
240 	ssize_t remain;
241 	/* private: */
242 	ssize_t offset;
243 };
244 
245 /**
246  * drm_coredump_printer - construct a &drm_printer that can output to a buffer
247  * from the read function for devcoredump
248  * @iter: A pointer to a struct drm_print_iterator for the read instance
249  *
250  * This wrapper extends drm_printf() to work with a dev_coredumpm() callback
251  * function. The passed in drm_print_iterator struct contains the buffer
252  * pointer, size and offset as passed in from devcoredump.
253  *
254  * For example::
255  *
256  *	void coredump_read(char *buffer, loff_t offset, size_t count,
257  *		void *data, size_t datalen)
258  *	{
259  *		struct drm_print_iterator iter;
260  *		struct drm_printer p;
261  *
262  *		iter.data = buffer;
263  *		iter.start = offset;
264  *		iter.remain = count;
265  *
266  *		p = drm_coredump_printer(&iter);
267  *
268  *		drm_printf(p, "foo=%d\n", foo);
269  *	}
270  *
271  *	void makecoredump(...)
272  *	{
273  *		...
274  *		dev_coredumpm(dev, THIS_MODULE, data, 0, GFP_KERNEL,
275  *			coredump_read, ...)
276  *	}
277  *
278  * The above example has a time complexity of O(N^2), where N is the size of the
279  * devcoredump. This is acceptable for small devcoredumps but scales poorly for
280  * larger ones.
281  *
282  * Another use case for drm_coredump_printer is to capture the devcoredump into
283  * a saved buffer before the dev_coredump() callback. This involves two passes:
284  * one to determine the size of the devcoredump and another to print it to a
285  * buffer. Then, in dev_coredump(), copy from the saved buffer into the
286  * devcoredump read buffer.
287  *
288  * For example::
289  *
290  *	char *devcoredump_saved_buffer;
291  *
292  *	ssize_t __coredump_print(char *buffer, ssize_t count, ...)
293  *	{
294  *		struct drm_print_iterator iter;
295  *		struct drm_printer p;
296  *
297  *		iter.data = buffer;
298  *		iter.start = 0;
299  *		iter.remain = count;
300  *
301  *		p = drm_coredump_printer(&iter);
302  *
303  *		drm_printf(p, "foo=%d\n", foo);
304  *		...
305  *		return count - iter.remain;
306  *	}
307  *
308  *	void coredump_print(...)
309  *	{
310  *		ssize_t count;
311  *
312  *		count = __coredump_print(NULL, INT_MAX, ...);
313  *		devcoredump_saved_buffer = kvmalloc(count, GFP_KERNEL);
314  *		__coredump_print(devcoredump_saved_buffer, count, ...);
315  *	}
316  *
317  *	void coredump_read(char *buffer, loff_t offset, size_t count,
318  *			   void *data, size_t datalen)
319  *	{
320  *		...
321  *		memcpy(buffer, devcoredump_saved_buffer + offset, count);
322  *		...
323  *	}
324  *
325  * The above example has a time complexity of O(N*2), where N is the size of the
326  * devcoredump. This scales better than the previous example for larger
327  * devcoredumps.
328  *
329  * RETURNS:
330  * The &drm_printer object
331  */
332 static inline struct drm_printer
drm_coredump_printer(struct drm_print_iterator * iter)333 drm_coredump_printer(struct drm_print_iterator *iter)
334 {
335 	struct drm_printer p = {
336 		.printfn = __drm_printfn_coredump,
337 		.puts = __drm_puts_coredump,
338 		.arg = iter,
339 	};
340 
341 	/* Set the internal offset of the iterator to zero */
342 	iter->offset = 0;
343 
344 	return p;
345 }
346 
347 /**
348  * drm_seq_file_printer - construct a &drm_printer that outputs to &seq_file
349  * @f:  the &struct seq_file to output to
350  *
351  * RETURNS:
352  * The &drm_printer object
353  */
drm_seq_file_printer(struct seq_file * f)354 static inline struct drm_printer drm_seq_file_printer(struct seq_file *f)
355 {
356 	struct drm_printer p = {
357 		.printfn = __drm_printfn_seq_file,
358 		.puts = __drm_puts_seq_file,
359 		.arg = f,
360 	};
361 	return p;
362 }
363 
364 /**
365  * drm_info_printer - construct a &drm_printer that outputs to dev_printk()
366  * @dev: the &struct device pointer
367  *
368  * RETURNS:
369  * The &drm_printer object
370  */
drm_info_printer(struct device * dev)371 static inline struct drm_printer drm_info_printer(struct device *dev)
372 {
373 	struct drm_printer p = {
374 		.printfn = __drm_printfn_info,
375 		.arg = dev,
376 	};
377 	return p;
378 }
379 
380 /**
381  * drm_dbg_printer - construct a &drm_printer for drm device specific output
382  * @drm: the &struct drm_device pointer, or NULL
383  * @category: the debug category to use
384  * @prefix: debug output prefix, or NULL for no prefix
385  *
386  * RETURNS:
387  * The &drm_printer object
388  */
drm_dbg_printer(struct drm_device * drm,enum drm_debug_category category,const char * prefix)389 static inline struct drm_printer drm_dbg_printer(struct drm_device *drm,
390 						 enum drm_debug_category category,
391 						 const char *prefix)
392 {
393 	struct drm_printer p = {
394 		.printfn = __drm_printfn_dbg,
395 		.arg = drm,
396 		.origin = (const void *)_THIS_IP_, /* it's fine as we will be inlined */
397 		.prefix = prefix,
398 		.category = category,
399 	};
400 	return p;
401 }
402 
403 /**
404  * drm_err_printer - construct a &drm_printer that outputs to drm_err()
405  * @drm: the &struct drm_device pointer
406  * @prefix: debug output prefix, or NULL for no prefix
407  *
408  * RETURNS:
409  * The &drm_printer object
410  */
drm_err_printer(struct drm_device * drm,const char * prefix)411 static inline struct drm_printer drm_err_printer(struct drm_device *drm,
412 						 const char *prefix)
413 {
414 	struct drm_printer p = {
415 		.printfn = __drm_printfn_err,
416 		.arg = drm,
417 		.prefix = prefix
418 	};
419 	return p;
420 }
421 
422 /**
423  * drm_line_printer - construct a &drm_printer that prefixes outputs with line numbers
424  * @p: the &struct drm_printer which actually generates the output
425  * @prefix: optional output prefix, or NULL for no prefix
426  * @series: optional unique series identifier, or 0 to omit identifier in the output
427  *
428  * This printer can be used to increase the robustness of the captured output
429  * to make sure we didn't lost any intermediate lines of the output. Helpful
430  * while capturing some crash data.
431  *
432  * Example 1::
433  *
434  *	void crash_dump(struct drm_device *drm)
435  *	{
436  *		static unsigned int id;
437  *		struct drm_printer p = drm_err_printer(drm, "crash");
438  *		struct drm_printer lp = drm_line_printer(&p, "dump", ++id);
439  *
440  *		drm_printf(&lp, "foo");
441  *		drm_printf(&lp, "bar");
442  *	}
443  *
444  * Above code will print into the dmesg something like::
445  *
446  *	[ ] 0000:00:00.0: [drm] *ERROR* crash dump 1.1: foo
447  *	[ ] 0000:00:00.0: [drm] *ERROR* crash dump 1.2: bar
448  *
449  * Example 2::
450  *
451  *	void line_dump(struct device *dev)
452  *	{
453  *		struct drm_printer p = drm_info_printer(dev);
454  *		struct drm_printer lp = drm_line_printer(&p, NULL, 0);
455  *
456  *		drm_printf(&lp, "foo");
457  *		drm_printf(&lp, "bar");
458  *	}
459  *
460  * Above code will print::
461  *
462  *	[ ] 0000:00:00.0: [drm] 1: foo
463  *	[ ] 0000:00:00.0: [drm] 2: bar
464  *
465  * RETURNS:
466  * The &drm_printer object
467  */
drm_line_printer(struct drm_printer * p,const char * prefix,unsigned int series)468 static inline struct drm_printer drm_line_printer(struct drm_printer *p,
469 						  const char *prefix,
470 						  unsigned int series)
471 {
472 	struct drm_printer lp = {
473 		.printfn = __drm_printfn_line,
474 		.arg = p,
475 		.prefix = prefix,
476 		.line = { .series = series, },
477 	};
478 	return lp;
479 }
480 
481 /*
482  * struct device based logging
483  *
484  * Prefer drm_device based logging over device or printk based logging.
485  */
486 
487 __printf(3, 4)
488 void drm_dev_printk(const struct device *dev, const char *level,
489 		    const char *format, ...);
490 struct _ddebug;
491 __printf(4, 5)
492 void __drm_dev_dbg(struct _ddebug *desc, const struct device *dev,
493 		   enum drm_debug_category category, const char *format, ...);
494 
495 /**
496  * DRM_DEV_ERROR() - Error output.
497  *
498  * NOTE: this is deprecated in favor of drm_err() or dev_err().
499  *
500  * @dev: device pointer
501  * @fmt: printf() like format string.
502  */
503 #define DRM_DEV_ERROR(dev, fmt, ...)					\
504 	drm_dev_printk(dev, KERN_ERR, "*ERROR* " fmt, ##__VA_ARGS__)
505 
506 /**
507  * DRM_DEV_ERROR_RATELIMITED() - Rate limited error output.
508  *
509  * NOTE: this is deprecated in favor of drm_err_ratelimited() or
510  * dev_err_ratelimited().
511  *
512  * @dev: device pointer
513  * @fmt: printf() like format string.
514  *
515  * Like DRM_ERROR() but won't flood the log.
516  */
517 #define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...)			\
518 ({									\
519 	static DEFINE_RATELIMIT_STATE(_rs,				\
520 				      DEFAULT_RATELIMIT_INTERVAL,	\
521 				      DEFAULT_RATELIMIT_BURST);		\
522 									\
523 	if (__ratelimit(&_rs))						\
524 		DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__);			\
525 })
526 
527 /* NOTE: this is deprecated in favor of drm_info() or dev_info(). */
528 #define DRM_DEV_INFO(dev, fmt, ...)				\
529 	drm_dev_printk(dev, KERN_INFO, fmt, ##__VA_ARGS__)
530 
531 /* NOTE: this is deprecated in favor of drm_info_once() or dev_info_once(). */
532 #define DRM_DEV_INFO_ONCE(dev, fmt, ...)				\
533 ({									\
534 	static bool __print_once __read_mostly;				\
535 	if (!__print_once) {						\
536 		__print_once = true;					\
537 		DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__);			\
538 	}								\
539 })
540 
541 #if !defined(CONFIG_DRM_USE_DYNAMIC_DEBUG)
542 #define drm_dev_dbg(dev, cat, fmt, ...)				\
543 	__drm_dev_dbg(NULL, dev, cat, fmt, ##__VA_ARGS__)
544 #else
545 #define drm_dev_dbg(dev, cat, fmt, ...)				\
546 	_dynamic_func_call_cls(cat, fmt, __drm_dev_dbg,		\
547 			       dev, cat, fmt, ##__VA_ARGS__)
548 #endif
549 
550 /**
551  * DRM_DEV_DEBUG() - Debug output for generic drm code
552  *
553  * NOTE: this is deprecated in favor of drm_dbg_core().
554  *
555  * @dev: device pointer
556  * @fmt: printf() like format string.
557  */
558 #define DRM_DEV_DEBUG(dev, fmt, ...)					\
559 	drm_dev_dbg(dev, DRM_UT_CORE, fmt, ##__VA_ARGS__)
560 /**
561  * DRM_DEV_DEBUG_DRIVER() - Debug output for vendor specific part of the driver
562  *
563  * NOTE: this is deprecated in favor of drm_dbg() or dev_dbg().
564  *
565  * @dev: device pointer
566  * @fmt: printf() like format string.
567  */
568 #define DRM_DEV_DEBUG_DRIVER(dev, fmt, ...)				\
569 	drm_dev_dbg(dev, DRM_UT_DRIVER,	fmt, ##__VA_ARGS__)
570 /**
571  * DRM_DEV_DEBUG_KMS() - Debug output for modesetting code
572  *
573  * NOTE: this is deprecated in favor of drm_dbg_kms().
574  *
575  * @dev: device pointer
576  * @fmt: printf() like format string.
577  */
578 #define DRM_DEV_DEBUG_KMS(dev, fmt, ...)				\
579 	drm_dev_dbg(dev, DRM_UT_KMS, fmt, ##__VA_ARGS__)
580 
581 /*
582  * struct drm_device based logging
583  *
584  * Prefer drm_device based logging over device or prink based logging.
585  */
586 
587 /* Helper for struct drm_device based logging. */
588 #define __drm_printk(drm, level, type, fmt, ...)			\
589 	dev_##level##type((drm) ? (drm)->dev : NULL, "[drm] " fmt, ##__VA_ARGS__)
590 
591 
592 #define drm_info(drm, fmt, ...)					\
593 	__drm_printk((drm), info,, fmt, ##__VA_ARGS__)
594 
595 #define drm_notice(drm, fmt, ...)				\
596 	__drm_printk((drm), notice,, fmt, ##__VA_ARGS__)
597 
598 #define drm_warn(drm, fmt, ...)					\
599 	__drm_printk((drm), warn,, fmt, ##__VA_ARGS__)
600 
601 #define drm_err(drm, fmt, ...)					\
602 	__drm_printk((drm), err,, "*ERROR* " fmt, ##__VA_ARGS__)
603 
604 
605 #define drm_info_once(drm, fmt, ...)				\
606 	__drm_printk((drm), info, _once, fmt, ##__VA_ARGS__)
607 
608 #define drm_notice_once(drm, fmt, ...)				\
609 	__drm_printk((drm), notice, _once, fmt, ##__VA_ARGS__)
610 
611 #define drm_warn_once(drm, fmt, ...)				\
612 	__drm_printk((drm), warn, _once, fmt, ##__VA_ARGS__)
613 
614 #define drm_err_once(drm, fmt, ...)				\
615 	__drm_printk((drm), err, _once, "*ERROR* " fmt, ##__VA_ARGS__)
616 
617 
618 #define drm_err_ratelimited(drm, fmt, ...)				\
619 	__drm_printk((drm), err, _ratelimited, "*ERROR* " fmt, ##__VA_ARGS__)
620 
621 
622 #define drm_dbg_core(drm, fmt, ...)					\
623 	drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_CORE, fmt, ##__VA_ARGS__)
624 #define drm_dbg_driver(drm, fmt, ...)						\
625 	drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
626 #define drm_dbg_kms(drm, fmt, ...)					\
627 	drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_KMS, fmt, ##__VA_ARGS__)
628 #define drm_dbg_prime(drm, fmt, ...)					\
629 	drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_PRIME, fmt, ##__VA_ARGS__)
630 #define drm_dbg_atomic(drm, fmt, ...)					\
631 	drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
632 #define drm_dbg_vbl(drm, fmt, ...)					\
633 	drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_VBL, fmt, ##__VA_ARGS__)
634 #define drm_dbg_state(drm, fmt, ...)					\
635 	drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_STATE, fmt, ##__VA_ARGS__)
636 #define drm_dbg_lease(drm, fmt, ...)					\
637 	drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_LEASE, fmt, ##__VA_ARGS__)
638 #define drm_dbg_dp(drm, fmt, ...)					\
639 	drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_DP, fmt, ##__VA_ARGS__)
640 #define drm_dbg_drmres(drm, fmt, ...)					\
641 	drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_DRMRES, fmt, ##__VA_ARGS__)
642 
643 #define drm_dbg(drm, fmt, ...)	drm_dbg_driver(drm, fmt, ##__VA_ARGS__)
644 
645 /*
646  * printk based logging
647  *
648  * Prefer drm_device based logging over device or prink based logging.
649  */
650 
651 __printf(1, 2)
652 void __drm_err(const char *format, ...);
653 
654 #if !defined(CONFIG_DRM_USE_DYNAMIC_DEBUG)
655 #define __drm_dbg(cat, fmt, ...)	__drm_dev_dbg(NULL, NULL, cat, fmt, ##__VA_ARGS__)
656 #else
657 #define __drm_dbg(cat, fmt, ...)					\
658 	_dynamic_func_call_cls(cat, fmt, __drm_dev_dbg,			\
659 			       NULL, cat, fmt, ##__VA_ARGS__)
660 #endif
661 
662 /* Macros to make printk easier */
663 
664 #define _DRM_PRINTK(once, level, fmt, ...)				\
665 	printk##once(KERN_##level "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
666 
667 /* NOTE: this is deprecated in favor of pr_info(). */
668 #define DRM_INFO(fmt, ...)						\
669 	_DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
670 /* NOTE: this is deprecated in favor of pr_notice(). */
671 #define DRM_NOTE(fmt, ...)						\
672 	_DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
673 /* NOTE: this is deprecated in favor of pr_warn(). */
674 #define DRM_WARN(fmt, ...)						\
675 	_DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
676 
677 /* NOTE: this is deprecated in favor of pr_info_once(). */
678 #define DRM_INFO_ONCE(fmt, ...)						\
679 	_DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
680 /* NOTE: this is deprecated in favor of pr_notice_once(). */
681 #define DRM_NOTE_ONCE(fmt, ...)						\
682 	_DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
683 /* NOTE: this is deprecated in favor of pr_warn_once(). */
684 #define DRM_WARN_ONCE(fmt, ...)						\
685 	_DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
686 
687 /* NOTE: this is deprecated in favor of pr_err(). */
688 #define DRM_ERROR(fmt, ...)						\
689 	__drm_err(fmt, ##__VA_ARGS__)
690 
691 /* NOTE: this is deprecated in favor of pr_err_ratelimited(). */
692 #define DRM_ERROR_RATELIMITED(fmt, ...)					\
693 	DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__)
694 
695 /* NOTE: this is deprecated in favor of drm_dbg_core(NULL, ...). */
696 #define DRM_DEBUG(fmt, ...)						\
697 	__drm_dbg(DRM_UT_CORE, fmt, ##__VA_ARGS__)
698 
699 /* NOTE: this is deprecated in favor of drm_dbg(NULL, ...). */
700 #define DRM_DEBUG_DRIVER(fmt, ...)					\
701 	__drm_dbg(DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
702 
703 /* NOTE: this is deprecated in favor of drm_dbg_kms(NULL, ...). */
704 #define DRM_DEBUG_KMS(fmt, ...)						\
705 	__drm_dbg(DRM_UT_KMS, fmt, ##__VA_ARGS__)
706 
707 /* NOTE: this is deprecated in favor of drm_dbg_prime(NULL, ...). */
708 #define DRM_DEBUG_PRIME(fmt, ...)					\
709 	__drm_dbg(DRM_UT_PRIME, fmt, ##__VA_ARGS__)
710 
711 /* NOTE: this is deprecated in favor of drm_dbg_atomic(NULL, ...). */
712 #define DRM_DEBUG_ATOMIC(fmt, ...)					\
713 	__drm_dbg(DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
714 
715 /* NOTE: this is deprecated in favor of drm_dbg_vbl(NULL, ...). */
716 #define DRM_DEBUG_VBL(fmt, ...)						\
717 	__drm_dbg(DRM_UT_VBL, fmt, ##__VA_ARGS__)
718 
719 /* NOTE: this is deprecated in favor of drm_dbg_lease(NULL, ...). */
720 #define DRM_DEBUG_LEASE(fmt, ...)					\
721 	__drm_dbg(DRM_UT_LEASE, fmt, ##__VA_ARGS__)
722 
723 /* NOTE: this is deprecated in favor of drm_dbg_dp(NULL, ...). */
724 #define DRM_DEBUG_DP(fmt, ...)						\
725 	__drm_dbg(DRM_UT_DP, fmt, ## __VA_ARGS__)
726 
727 #define __DRM_DEFINE_DBG_RATELIMITED(category, drm, fmt, ...)					\
728 ({												\
729 	static DEFINE_RATELIMIT_STATE(rs_, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST);\
730 	const struct drm_device *drm_ = (drm);							\
731 												\
732 	if (drm_debug_enabled(DRM_UT_ ## category) && __ratelimit(&rs_))			\
733 		drm_dev_printk(drm_ ? drm_->dev : NULL, KERN_DEBUG, fmt, ## __VA_ARGS__);	\
734 })
735 
736 #define drm_dbg_ratelimited(drm, fmt, ...) \
737 	__DRM_DEFINE_DBG_RATELIMITED(DRIVER, drm, fmt, ## __VA_ARGS__)
738 
739 #define drm_dbg_kms_ratelimited(drm, fmt, ...) \
740 	__DRM_DEFINE_DBG_RATELIMITED(KMS, drm, fmt, ## __VA_ARGS__)
741 
742 /*
743  * struct drm_device based WARNs
744  *
745  * drm_WARN*() acts like WARN*(), but with the key difference of
746  * using device specific information so that we know from which device
747  * warning is originating from.
748  *
749  * Prefer drm_device based drm_WARN* over regular WARN*
750  */
751 
752 /* Helper for struct drm_device based WARNs */
753 #define drm_WARN(drm, condition, format, arg...)			\
754 	WARN(condition, "%s %s: [drm] " format,				\
755 			dev_driver_string((drm)->dev),			\
756 			dev_name((drm)->dev), ## arg)
757 
758 #define drm_WARN_ONCE(drm, condition, format, arg...)			\
759 	WARN_ONCE(condition, "%s %s: [drm] " format,			\
760 			dev_driver_string((drm)->dev),			\
761 			dev_name((drm)->dev), ## arg)
762 
763 #define drm_WARN_ON(drm, x)						\
764 	drm_WARN((drm), (x), "%s",					\
765 		 "drm_WARN_ON(" __stringify(x) ")")
766 
767 #define drm_WARN_ON_ONCE(drm, x)					\
768 	drm_WARN_ONCE((drm), (x), "%s",					\
769 		      "drm_WARN_ON_ONCE(" __stringify(x) ")")
770 
771 #endif /* DRM_PRINT_H_ */
772