File Index
Files and directories
Sign in
FILE

drm_print.h

File preview with syntax highlighting.

linux-6.19.14/include/drm/drm_print.h C
  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
 37struct debugfs_regset32;
 38struct drm_device;
 39struct seq_file;
 40
 41/* Do *not* use outside of drm_print.[ch]! */
 42extern 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 */
 98enum 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
144static 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 */
174struct 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
188void __drm_printfn_coredump(struct drm_printer *p, struct va_format *vaf);
189void __drm_puts_coredump(struct drm_printer *p, const char *str);
190void __drm_printfn_seq_file(struct drm_printer *p, struct va_format *vaf);
191void __drm_puts_seq_file(struct drm_printer *p, const char *str);
192void __drm_printfn_info(struct drm_printer *p, struct va_format *vaf);
193void __drm_printfn_dbg(struct drm_printer *p, struct va_format *vaf);
194void __drm_printfn_err(struct drm_printer *p, struct va_format *vaf);
195void __drm_printfn_line(struct drm_printer *p, struct va_format *vaf);
196
197__printf(2, 3)
198void drm_printf(struct drm_printer *p, const char *f, ...);
199void drm_puts(struct drm_printer *p, const char *str);
200void drm_print_regset32(struct drm_printer *p, struct debugfs_regset32 *regset);
201void drm_print_bits(struct drm_printer *p, unsigned long value,
202		    const char * const bits[], unsigned int nbits);
203void 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 */
213static inline void
214drm_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 */
237struct 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 */
332static inline struct drm_printer
333drm_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_coredump_printer_is_full() - DRM coredump printer output is full
349 * @p: DRM coredump printer
350 *
351 * DRM printer output is full, useful to short circuit coredump printing once
352 * printer is full.
353 *
354 * RETURNS:
355 * True if DRM coredump printer output buffer is full, False otherwise
356 */
357static inline bool drm_coredump_printer_is_full(struct drm_printer *p)
358{
359	struct drm_print_iterator *iterator = p->arg;
360
361	if (p->printfn != __drm_printfn_coredump)
362		return true;
363
364	return !iterator->remain;
365}
366
367/**
368 * drm_seq_file_printer - construct a &drm_printer that outputs to &seq_file
369 * @f:  the &struct seq_file to output to
370 *
371 * RETURNS:
372 * The &drm_printer object
373 */
374static inline struct drm_printer drm_seq_file_printer(struct seq_file *f)
375{
376	struct drm_printer p = {
377		.printfn = __drm_printfn_seq_file,
378		.puts = __drm_puts_seq_file,
379		.arg = f,
380	};
381	return p;
382}
383
384/**
385 * drm_info_printer - construct a &drm_printer that outputs to dev_printk()
386 * @dev: the &struct device pointer
387 *
388 * RETURNS:
389 * The &drm_printer object
390 */
391static inline struct drm_printer drm_info_printer(struct device *dev)
392{
393	struct drm_printer p = {
394		.printfn = __drm_printfn_info,
395		.arg = dev,
396	};
397	return p;
398}
399
400/**
401 * drm_dbg_printer - construct a &drm_printer for drm device specific output
402 * @drm: the &struct drm_device pointer, or NULL
403 * @category: the debug category to use
404 * @prefix: debug output prefix, or NULL for no prefix
405 *
406 * RETURNS:
407 * The &drm_printer object
408 */
409static inline struct drm_printer drm_dbg_printer(struct drm_device *drm,
410						 enum drm_debug_category category,
411						 const char *prefix)
412{
413	struct drm_printer p = {
414		.printfn = __drm_printfn_dbg,
415		.arg = drm,
416		.origin = (const void *)_THIS_IP_, /* it's fine as we will be inlined */
417		.prefix = prefix,
418		.category = category,
419	};
420	return p;
421}
422
423/**
424 * drm_err_printer - construct a &drm_printer that outputs to drm_err()
425 * @drm: the &struct drm_device pointer
426 * @prefix: debug output prefix, or NULL for no prefix
427 *
428 * RETURNS:
429 * The &drm_printer object
430 */
431static inline struct drm_printer drm_err_printer(struct drm_device *drm,
432						 const char *prefix)
433{
434	struct drm_printer p = {
435		.printfn = __drm_printfn_err,
436		.arg = drm,
437		.prefix = prefix
438	};
439	return p;
440}
441
442/**
443 * drm_line_printer - construct a &drm_printer that prefixes outputs with line numbers
444 * @p: the &struct drm_printer which actually generates the output
445 * @prefix: optional output prefix, or NULL for no prefix
446 * @series: optional unique series identifier, or 0 to omit identifier in the output
447 *
448 * This printer can be used to increase the robustness of the captured output
449 * to make sure we didn't lost any intermediate lines of the output. Helpful
450 * while capturing some crash data.
451 *
452 * Example 1::
453 *
454 *	void crash_dump(struct drm_device *drm)
455 *	{
456 *		static unsigned int id;
457 *		struct drm_printer p = drm_err_printer(drm, "crash");
458 *		struct drm_printer lp = drm_line_printer(&p, "dump", ++id);
459 *
460 *		drm_printf(&lp, "foo");
461 *		drm_printf(&lp, "bar");
462 *	}
463 *
464 * Above code will print into the dmesg something like::
465 *
466 *	[ ] 0000:00:00.0: [drm] *ERROR* crash dump 1.1: foo
467 *	[ ] 0000:00:00.0: [drm] *ERROR* crash dump 1.2: bar
468 *
469 * Example 2::
470 *
471 *	void line_dump(struct device *dev)
472 *	{
473 *		struct drm_printer p = drm_info_printer(dev);
474 *		struct drm_printer lp = drm_line_printer(&p, NULL, 0);
475 *
476 *		drm_printf(&lp, "foo");
477 *		drm_printf(&lp, "bar");
478 *	}
479 *
480 * Above code will print::
481 *
482 *	[ ] 0000:00:00.0: [drm] 1: foo
483 *	[ ] 0000:00:00.0: [drm] 2: bar
484 *
485 * RETURNS:
486 * The &drm_printer object
487 */
488static inline struct drm_printer drm_line_printer(struct drm_printer *p,
489						  const char *prefix,
490						  unsigned int series)
491{
492	struct drm_printer lp = {
493		.printfn = __drm_printfn_line,
494		.arg = p,
495		.prefix = prefix,
496		.line = { .series = series, },
497	};
498	return lp;
499}
500
501/*
502 * struct device based logging
503 *
504 * Prefer drm_device based logging over device or printk based logging.
505 */
506
507__printf(3, 4)
508void drm_dev_printk(const struct device *dev, const char *level,
509		    const char *format, ...);
510struct _ddebug;
511__printf(4, 5)
512void __drm_dev_dbg(struct _ddebug *desc, const struct device *dev,
513		   enum drm_debug_category category, const char *format, ...);
514
515/**
516 * DRM_DEV_ERROR() - Error output.
517 *
518 * NOTE: this is deprecated in favor of drm_err() or dev_err().
519 *
520 * @dev: device pointer
521 * @fmt: printf() like format string.
522 */
523#define DRM_DEV_ERROR(dev, fmt, ...)					\
524	drm_dev_printk(dev, KERN_ERR, "*ERROR* " fmt, ##__VA_ARGS__)
525
526/**
527 * DRM_DEV_ERROR_RATELIMITED() - Rate limited error output.
528 *
529 * NOTE: this is deprecated in favor of drm_err_ratelimited() or
530 * dev_err_ratelimited().
531 *
532 * @dev: device pointer
533 * @fmt: printf() like format string.
534 *
535 * Like DRM_ERROR() but won't flood the log.
536 */
537#define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...)			\
538({									\
539	static DEFINE_RATELIMIT_STATE(_rs,				\
540				      DEFAULT_RATELIMIT_INTERVAL,	\
541				      DEFAULT_RATELIMIT_BURST);		\
542									\
543	if (__ratelimit(&_rs))						\
544		DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__);			\
545})
546
547/* NOTE: this is deprecated in favor of drm_info() or dev_info(). */
548#define DRM_DEV_INFO(dev, fmt, ...)				\
549	drm_dev_printk(dev, KERN_INFO, fmt, ##__VA_ARGS__)
550
551/* NOTE: this is deprecated in favor of drm_info_once() or dev_info_once(). */
552#define DRM_DEV_INFO_ONCE(dev, fmt, ...)				\
553({									\
554	static bool __print_once __read_mostly;				\
555	if (!__print_once) {						\
556		__print_once = true;					\
557		DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__);			\
558	}								\
559})
560
561#if !defined(CONFIG_DRM_USE_DYNAMIC_DEBUG)
562#define drm_dev_dbg(dev, cat, fmt, ...)				\
563	__drm_dev_dbg(NULL, dev, cat, fmt, ##__VA_ARGS__)
564#else
565#define drm_dev_dbg(dev, cat, fmt, ...)				\
566	_dynamic_func_call_cls(cat, fmt, __drm_dev_dbg,		\
567			       dev, cat, fmt, ##__VA_ARGS__)
568#endif
569
570/**
571 * DRM_DEV_DEBUG() - Debug output for generic drm code
572 *
573 * NOTE: this is deprecated in favor of drm_dbg_core().
574 *
575 * @dev: device pointer
576 * @fmt: printf() like format string.
577 */
578#define DRM_DEV_DEBUG(dev, fmt, ...)					\
579	drm_dev_dbg(dev, DRM_UT_CORE, fmt, ##__VA_ARGS__)
580/**
581 * DRM_DEV_DEBUG_DRIVER() - Debug output for vendor specific part of the driver
582 *
583 * NOTE: this is deprecated in favor of drm_dbg() or dev_dbg().
584 *
585 * @dev: device pointer
586 * @fmt: printf() like format string.
587 */
588#define DRM_DEV_DEBUG_DRIVER(dev, fmt, ...)				\
589	drm_dev_dbg(dev, DRM_UT_DRIVER,	fmt, ##__VA_ARGS__)
590/**
591 * DRM_DEV_DEBUG_KMS() - Debug output for modesetting code
592 *
593 * NOTE: this is deprecated in favor of drm_dbg_kms().
594 *
595 * @dev: device pointer
596 * @fmt: printf() like format string.
597 */
598#define DRM_DEV_DEBUG_KMS(dev, fmt, ...)				\
599	drm_dev_dbg(dev, DRM_UT_KMS, fmt, ##__VA_ARGS__)
600
601/*
602 * struct drm_device based logging
603 *
604 * Prefer drm_device based logging over device or prink based logging.
605 */
606
607/* Helper to enforce struct drm_device type */
608static inline struct device *__drm_to_dev(const struct drm_device *drm)
609{
610	return drm ? drm->dev : NULL;
611}
612
613/* Helper for struct drm_device based logging. */
614#define __drm_printk(drm, level, type, fmt, ...)			\
615	dev_##level##type(__drm_to_dev(drm), "[drm] " fmt, ##__VA_ARGS__)
616
617
618#define drm_info(drm, fmt, ...)					\
619	__drm_printk((drm), info,, fmt, ##__VA_ARGS__)
620
621#define drm_notice(drm, fmt, ...)				\
622	__drm_printk((drm), notice,, fmt, ##__VA_ARGS__)
623
624#define drm_warn(drm, fmt, ...)					\
625	__drm_printk((drm), warn,, fmt, ##__VA_ARGS__)
626
627#define drm_err(drm, fmt, ...)					\
628	__drm_printk((drm), err,, "*ERROR* " fmt, ##__VA_ARGS__)
629
630
631#define drm_info_once(drm, fmt, ...)				\
632	__drm_printk((drm), info, _once, fmt, ##__VA_ARGS__)
633
634#define drm_notice_once(drm, fmt, ...)				\
635	__drm_printk((drm), notice, _once, fmt, ##__VA_ARGS__)
636
637#define drm_warn_once(drm, fmt, ...)				\
638	__drm_printk((drm), warn, _once, fmt, ##__VA_ARGS__)
639
640#define drm_err_once(drm, fmt, ...)				\
641	__drm_printk((drm), err, _once, "*ERROR* " fmt, ##__VA_ARGS__)
642
643
644#define drm_err_ratelimited(drm, fmt, ...)				\
645	__drm_printk((drm), err, _ratelimited, "*ERROR* " fmt, ##__VA_ARGS__)
646
647
648#define drm_dbg_core(drm, fmt, ...)					\
649	drm_dev_dbg(__drm_to_dev(drm), DRM_UT_CORE, fmt, ##__VA_ARGS__)
650#define drm_dbg_driver(drm, fmt, ...)					\
651	drm_dev_dbg(__drm_to_dev(drm), DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
652#define drm_dbg_kms(drm, fmt, ...)					\
653	drm_dev_dbg(__drm_to_dev(drm), DRM_UT_KMS, fmt, ##__VA_ARGS__)
654#define drm_dbg_prime(drm, fmt, ...)					\
655	drm_dev_dbg(__drm_to_dev(drm), DRM_UT_PRIME, fmt, ##__VA_ARGS__)
656#define drm_dbg_atomic(drm, fmt, ...)					\
657	drm_dev_dbg(__drm_to_dev(drm), DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
658#define drm_dbg_vbl(drm, fmt, ...)					\
659	drm_dev_dbg(__drm_to_dev(drm), DRM_UT_VBL, fmt, ##__VA_ARGS__)
660#define drm_dbg_state(drm, fmt, ...)					\
661	drm_dev_dbg(__drm_to_dev(drm), DRM_UT_STATE, fmt, ##__VA_ARGS__)
662#define drm_dbg_lease(drm, fmt, ...)					\
663	drm_dev_dbg(__drm_to_dev(drm), DRM_UT_LEASE, fmt, ##__VA_ARGS__)
664#define drm_dbg_dp(drm, fmt, ...)					\
665	drm_dev_dbg(__drm_to_dev(drm), DRM_UT_DP, fmt, ##__VA_ARGS__)
666#define drm_dbg_drmres(drm, fmt, ...)					\
667	drm_dev_dbg(__drm_to_dev(drm), DRM_UT_DRMRES, fmt, ##__VA_ARGS__)
668
669#define drm_dbg(drm, fmt, ...)	drm_dbg_driver(drm, fmt, ##__VA_ARGS__)
670
671/*
672 * printk based logging
673 *
674 * Prefer drm_device based logging over device or prink based logging.
675 */
676
677__printf(1, 2)
678void __drm_err(const char *format, ...);
679
680#if !defined(CONFIG_DRM_USE_DYNAMIC_DEBUG)
681#define __drm_dbg(cat, fmt, ...)	__drm_dev_dbg(NULL, NULL, cat, fmt, ##__VA_ARGS__)
682#else
683#define __drm_dbg(cat, fmt, ...)					\
684	_dynamic_func_call_cls(cat, fmt, __drm_dev_dbg,			\
685			       NULL, cat, fmt, ##__VA_ARGS__)
686#endif
687
688/* Macros to make printk easier */
689
690#define _DRM_PRINTK(once, level, fmt, ...)				\
691	printk##once(KERN_##level "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
692
693/* NOTE: this is deprecated in favor of pr_info(). */
694#define DRM_INFO(fmt, ...)						\
695	_DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
696/* NOTE: this is deprecated in favor of pr_notice(). */
697#define DRM_NOTE(fmt, ...)						\
698	_DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
699/* NOTE: this is deprecated in favor of pr_warn(). */
700#define DRM_WARN(fmt, ...)						\
701	_DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
702
703/* NOTE: this is deprecated in favor of pr_info_once(). */
704#define DRM_INFO_ONCE(fmt, ...)						\
705	_DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
706/* NOTE: this is deprecated in favor of pr_notice_once(). */
707#define DRM_NOTE_ONCE(fmt, ...)						\
708	_DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
709/* NOTE: this is deprecated in favor of pr_warn_once(). */
710#define DRM_WARN_ONCE(fmt, ...)						\
711	_DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
712
713/* NOTE: this is deprecated in favor of pr_err(). */
714#define DRM_ERROR(fmt, ...)						\
715	__drm_err(fmt, ##__VA_ARGS__)
716
717/* NOTE: this is deprecated in favor of pr_err_ratelimited(). */
718#define DRM_ERROR_RATELIMITED(fmt, ...)					\
719	DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__)
720
721/* NOTE: this is deprecated in favor of drm_dbg_core(NULL, ...). */
722#define DRM_DEBUG(fmt, ...)						\
723	__drm_dbg(DRM_UT_CORE, fmt, ##__VA_ARGS__)
724
725/* NOTE: this is deprecated in favor of drm_dbg(NULL, ...). */
726#define DRM_DEBUG_DRIVER(fmt, ...)					\
727	__drm_dbg(DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
728
729/* NOTE: this is deprecated in favor of drm_dbg_kms(NULL, ...). */
730#define DRM_DEBUG_KMS(fmt, ...)						\
731	__drm_dbg(DRM_UT_KMS, fmt, ##__VA_ARGS__)
732
733/* NOTE: this is deprecated in favor of drm_dbg_prime(NULL, ...). */
734#define DRM_DEBUG_PRIME(fmt, ...)					\
735	__drm_dbg(DRM_UT_PRIME, fmt, ##__VA_ARGS__)
736
737/* NOTE: this is deprecated in favor of drm_dbg_atomic(NULL, ...). */
738#define DRM_DEBUG_ATOMIC(fmt, ...)					\
739	__drm_dbg(DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
740
741/* NOTE: this is deprecated in favor of drm_dbg_vbl(NULL, ...). */
742#define DRM_DEBUG_VBL(fmt, ...)						\
743	__drm_dbg(DRM_UT_VBL, fmt, ##__VA_ARGS__)
744
745/* NOTE: this is deprecated in favor of drm_dbg_lease(NULL, ...). */
746#define DRM_DEBUG_LEASE(fmt, ...)					\
747	__drm_dbg(DRM_UT_LEASE, fmt, ##__VA_ARGS__)
748
749/* NOTE: this is deprecated in favor of drm_dbg_dp(NULL, ...). */
750#define DRM_DEBUG_DP(fmt, ...)						\
751	__drm_dbg(DRM_UT_DP, fmt, ## __VA_ARGS__)
752
753#define __DRM_DEFINE_DBG_RATELIMITED(category, drm, fmt, ...)					\
754({												\
755	static DEFINE_RATELIMIT_STATE(rs_, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST);\
756												\
757	if (drm_debug_enabled(DRM_UT_ ## category) && __ratelimit(&rs_))			\
758		drm_dev_printk(__drm_to_dev(drm), KERN_DEBUG, fmt, ## __VA_ARGS__);		\
759})
760
761#define drm_dbg_ratelimited(drm, fmt, ...) \
762	__DRM_DEFINE_DBG_RATELIMITED(DRIVER, drm, fmt, ## __VA_ARGS__)
763
764#define drm_dbg_kms_ratelimited(drm, fmt, ...) \
765	__DRM_DEFINE_DBG_RATELIMITED(KMS, drm, fmt, ## __VA_ARGS__)
766
767/*
768 * struct drm_device based WARNs
769 *
770 * drm_WARN*() acts like WARN*(), but with the key difference of
771 * using device specific information so that we know from which device
772 * warning is originating from.
773 *
774 * Prefer drm_device based drm_WARN* over regular WARN*
775 */
776
777/* Helper for struct drm_device based WARNs */
778#define drm_WARN(drm, condition, format, arg...)			\
779	WARN(condition, "%s %s: [drm] " format,				\
780			dev_driver_string(__drm_to_dev(drm)),		\
781			dev_name(__drm_to_dev(drm)), ## arg)
782
783#define drm_WARN_ONCE(drm, condition, format, arg...)			\
784	WARN_ONCE(condition, "%s %s: [drm] " format,			\
785			dev_driver_string(__drm_to_dev(drm)),		\
786			dev_name(__drm_to_dev(drm)), ## arg)
787
788#define drm_WARN_ON(drm, x)						\
789	drm_WARN((drm), (x), "%s",					\
790		 "drm_WARN_ON(" __stringify(x) ")")
791
792#define drm_WARN_ON_ONCE(drm, x)					\
793	drm_WARN_ONCE((drm), (x), "%s",					\
794		      "drm_WARN_ON_ONCE(" __stringify(x) ")")
795
796#endif /* DRM_PRINT_H_ */
~/ Read-only file preview.