Linux Audio

Check our new training course

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