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