Linux Audio

Check our new training course

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