blob: a3c58c941bdcfbdc0a96470d7d2c38afbf8c1b2a [file] [log] [blame]
Rob Clarkd81871772016-11-05 11:08:07 -04001/*
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
Joe Perches3c6d6e02017-02-15 15:33:18 -080029#include <linux/compiler.h>
30#include <linux/printk.h>
Rob Clarkd81871772016-11-05 11:08:07 -040031#include <linux/seq_file.h>
32#include <linux/device.h>
Eric Anholt5f513cc2019-02-20 13:03:37 -080033#include <linux/debugfs.h>
Rob Clarkd81871772016-11-05 11:08:07 -040034
Sam Ravnborg656600e2019-06-10 00:07:48 +020035#include <drm/drm.h>
36
Jani Nikula9f0ac022019-10-28 12:38:18 +020037/* Do *not* use outside of drm_print.[ch]! */
38extern unsigned int __drm_debug;
Jani Nikula959b0772019-09-24 15:58:57 +030039
Rob Clarkd81871772016-11-05 11:08:07 -040040/**
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"
Rob Clarkd81871772016-11-05 11:08:07 -040071 *
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 {
Daniel Vetter3d387d92016-12-28 17:42:09 +010076 /* private: */
Rob Clarkd81871772016-11-05 11:08:07 -040077 void (*printfn)(struct drm_printer *p, struct va_format *vaf);
Jordan Crouse63f4cc02018-07-24 10:33:21 -060078 void (*puts)(struct drm_printer *p, const char *str);
Rob Clarkd81871772016-11-05 11:08:07 -040079 void *arg;
Daniel Vetter3d387d92016-12-28 17:42:09 +010080 const char *prefix;
Rob Clarkd81871772016-11-05 11:08:07 -040081};
82
Jordan Crousecfc57a12018-07-24 10:33:20 -060083void __drm_printfn_coredump(struct drm_printer *p, struct va_format *vaf);
Jordan Crouse5dc634b2018-07-24 10:33:23 -060084void __drm_puts_coredump(struct drm_printer *p, const char *str);
Rob Clarkd81871772016-11-05 11:08:07 -040085void __drm_printfn_seq_file(struct drm_printer *p, struct va_format *vaf);
Jordan Crouse4538d732018-07-24 10:33:22 -060086void __drm_puts_seq_file(struct drm_printer *p, const char *str);
Rob Clarkd81871772016-11-05 11:08:07 -040087void __drm_printfn_info(struct drm_printer *p, struct va_format *vaf);
Daniel Vetter3d387d92016-12-28 17:42:09 +010088void __drm_printfn_debug(struct drm_printer *p, struct va_format *vaf);
Lyude Paul0de54fb22019-09-03 16:45:43 -040089void __drm_printfn_err(struct drm_printer *p, struct va_format *vaf);
Rob Clarkd81871772016-11-05 11:08:07 -040090
Joe Perches3c6d6e02017-02-15 15:33:18 -080091__printf(2, 3)
Rob Clarkd81871772016-11-05 11:08:07 -040092void drm_printf(struct drm_printer *p, const char *f, ...);
Jordan Crouse63f4cc02018-07-24 10:33:21 -060093void drm_puts(struct drm_printer *p, const char *str);
Eric Anholt5f513cc2019-02-20 13:03:37 -080094void drm_print_regset32(struct drm_printer *p, struct debugfs_regset32 *regset);
Gerd Hoffmann141f6352019-09-23 08:58:14 +020095void drm_print_bits(struct drm_printer *p, unsigned long value,
96 const char * const bits[], unsigned int nbits);
Rob Clarkd81871772016-11-05 11:08:07 -040097
Daniel Vetter42f1b312017-12-14 21:30:51 +010098__printf(2, 0)
Noralf Trønnesbf6234a2017-11-07 20:13:39 +010099/**
Chris Wilsone2b155e2017-11-23 08:40:46 +0000100 * drm_vprintf - print to a &drm_printer stream
101 * @p: the &drm_printer
102 * @fmt: format string
103 * @va: the va_list
104 */
Chris Wilsone2b155e2017-11-23 08:40:46 +0000105static 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/**
Noralf Trønnesbf6234a2017-11-07 20:13:39 +0100114 * 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__)
Rob Clarkd81871772016-11-05 11:08:07 -0400121
122/**
Jordan Crousecfc57a12018-07-24 10:33:20 -0600123 * 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,
Jordan Crouse5dc634b2018-07-24 10:33:23 -0600177 .puts = __drm_puts_coredump,
Jordan Crousecfc57a12018-07-24 10:33:20 -0600178 .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/**
Rob Clarkd81871772016-11-05 11:08:07 -0400188 * drm_seq_file_printer - construct a &drm_printer that outputs to &seq_file
Daniel Vetterea0dd852016-12-29 21:48:26 +0100189 * @f: the &struct seq_file to output to
Rob Clarkd81871772016-11-05 11:08:07 -0400190 *
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,
Jordan Crouse4538d732018-07-24 10:33:22 -0600198 .puts = __drm_puts_seq_file,
Rob Clarkd81871772016-11-05 11:08:07 -0400199 .arg = f,
200 };
201 return p;
202}
203
204/**
205 * drm_info_printer - construct a &drm_printer that outputs to dev_printk()
Daniel Vetterea0dd852016-12-29 21:48:26 +0100206 * @dev: the &struct device pointer
Rob Clarkd81871772016-11-05 11:08:07 -0400207 *
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
Daniel Vetter3d387d92016-12-28 17:42:09 +0100220/**
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}
Haneen Mohammed02c96562017-10-17 22:30:07 -0600235
Lyude Paul0de54fb22019-09-03 16:45:43 -0400236/**
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
Jani Nikula876905b2019-10-28 12:38:20 +0200252/**
253 * enum drm_debug_category - The DRM debug categories
Haneen Mohammed02c96562017-10-17 22:30:07 -0600254 *
Jani Nikula876905b2019-10-28 12:38:20 +0200255 * 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.
Haneen Mohammed02c96562017-10-17 22:30:07 -0600258 *
Jani Nikula876905b2019-10-28 12:38:20 +0200259 * Each DRM_DEBUG_<CATEGORY> macro logs to DRM_UT_<CATEGORY> category, except
260 * DRM_DEBUG() logs to DRM_UT_CORE.
Haneen Mohammed02c96562017-10-17 22:30:07 -0600261 *
Jani Nikula876905b2019-10-28 12:38:20 +0200262 * Enabling verbose debug messages is done through the drm.debug parameter, each
263 * category being enabled by a bit:
Haneen Mohammed02c96562017-10-17 22:30:07 -0600264 *
Jani Nikula876905b2019-10-28 12:38:20 +0200265 * - 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
Haneen Mohammed02c96562017-10-17 22:30:07 -0600270 *
271 * An interesting feature is that it's possible to enable verbose logging at
Jani Nikula876905b2019-10-28 12:38:20 +0200272 * run-time by echoing the debug value in its sysfs node::
273 *
Haneen Mohammed02c96562017-10-17 22:30:07 -0600274 * # echo 0xf > /sys/module/drm/parameters/debug
Jani Nikula876905b2019-10-28 12:38:20 +0200275 *
Haneen Mohammed02c96562017-10-17 22:30:07 -0600276 */
Jani Nikula876905b2019-10-28 12:38:20 +0200277enum 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,
Daniel Vetterc6603c72020-03-24 13:45:40 +0100316 /**
317 * @DRM_UT_DRMRES: Used in the drm managed resources code.
318 */
319 DRM_UT_DRMRES = 0x200,
Jani Nikula876905b2019-10-28 12:38:20 +0200320};
Haneen Mohammed02c96562017-10-17 22:30:07 -0600321
Jani Nikula876905b2019-10-28 12:38:20 +0200322static inline bool drm_debug_enabled(enum drm_debug_category category)
Jani Nikulaf0a8f532019-10-01 17:06:14 +0300323{
Jani Nikula9f0ac022019-10-28 12:38:18 +0200324 return unlikely(__drm_debug & category);
Jani Nikulaf0a8f532019-10-01 17:06:14 +0300325}
326
Jani Nikula3bf149b2019-10-28 12:38:21 +0200327/*
328 * struct device based logging
Jani Nikulafb6c7ab2019-12-10 14:30:43 +0200329 *
330 * Prefer drm_device based logging over device or prink based logging.
Jani Nikula3bf149b2019-10-28 12:38:21 +0200331 */
332
Joe Perchesdb870862018-03-16 13:56:27 -0700333__printf(3, 4)
Haneen Mohammed02c96562017-10-17 22:30:07 -0600334void drm_dev_printk(const struct device *dev, const char *level,
Joe Perchesdb870862018-03-16 13:56:27 -0700335 const char *format, ...);
336__printf(3, 4)
Jani Nikula876905b2019-10-28 12:38:20 +0200337void drm_dev_dbg(const struct device *dev, enum drm_debug_category category,
Joe Perchesdb870862018-03-16 13:56:27 -0700338 const char *format, ...);
339
Jani Nikula3bf149b2019-10-28 12:38:21 +0200340/**
Mauro Carvalho Chehabb52817e2020-10-27 10:51:35 +0100341 * DRM_DEV_ERROR() - Error output.
Jani Nikula3bf149b2019-10-28 12:38:21 +0200342 *
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/**
Mauro Carvalho Chehabb52817e2020-10-27 10:51:35 +0100350 * DRM_DEV_ERROR_RATELIMITED() - Rate limited error output.
Jani Nikula3bf149b2019-10-28 12:38:21 +0200351 *
352 * @dev: device pointer
353 * @fmt: printf() like format string.
Mauro Carvalho Chehabb52817e2020-10-27 10:51:35 +0100354 *
355 * Like DRM_ERROR() but won't flood the log.
Jani Nikula3bf149b2019-10-28 12:38:21 +0200356 */
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/**
Mauro Carvalho Chehabb52817e2020-10-27 10:51:35 +0100380 * DRM_DEV_DEBUG() - Debug output for generic drm code
Jani Nikula3bf149b2019-10-28 12:38:21 +0200381 *
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__)
Mauro Carvalho Chehabb52817e2020-10-27 10:51:35 +0100387/**
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 */
Jani Nikula3bf149b2019-10-28 12:38:21 +0200393#define DRM_DEV_DEBUG_DRIVER(dev, fmt, ...) \
394 drm_dev_dbg(dev, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
Mauro Carvalho Chehabb52817e2020-10-27 10:51:35 +0100395/**
396 * DRM_DEV_DEBUG_KMS() - Debug output for modesetting code
397 *
398 * @dev: device pointer
399 * @fmt: printf() like format string.
400 */
Jani Nikula3bf149b2019-10-28 12:38:21 +0200401#define DRM_DEV_DEBUG_KMS(dev, fmt, ...) \
402 drm_dev_dbg(dev, DRM_UT_KMS, fmt, ##__VA_ARGS__)
Jani Nikula3bf149b2019-10-28 12:38:21 +0200403
Jani Nikula3bf149b2019-10-28 12:38:21 +0200404/*
Jani Nikulafb6c7ab2019-12-10 14:30:43 +0200405 * 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)->dev, DRM_UT_CORE, fmt, ##__VA_ARGS__)
447#define drm_dbg(drm, fmt, ...) \
448 drm_dev_dbg((drm)->dev, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
449#define drm_dbg_kms(drm, fmt, ...) \
450 drm_dev_dbg((drm)->dev, DRM_UT_KMS, fmt, ##__VA_ARGS__)
451#define drm_dbg_prime(drm, fmt, ...) \
452 drm_dev_dbg((drm)->dev, DRM_UT_PRIME, fmt, ##__VA_ARGS__)
453#define drm_dbg_atomic(drm, fmt, ...) \
454 drm_dev_dbg((drm)->dev, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
455#define drm_dbg_vbl(drm, fmt, ...) \
456 drm_dev_dbg((drm)->dev, DRM_UT_VBL, fmt, ##__VA_ARGS__)
457#define drm_dbg_state(drm, fmt, ...) \
458 drm_dev_dbg((drm)->dev, DRM_UT_STATE, fmt, ##__VA_ARGS__)
459#define drm_dbg_lease(drm, fmt, ...) \
460 drm_dev_dbg((drm)->dev, DRM_UT_LEASE, fmt, ##__VA_ARGS__)
461#define drm_dbg_dp(drm, fmt, ...) \
462 drm_dev_dbg((drm)->dev, DRM_UT_DP, fmt, ##__VA_ARGS__)
Daniel Vetterc6603c72020-03-24 13:45:40 +0100463#define drm_dbg_drmres(drm, fmt, ...) \
464 drm_dev_dbg((drm)->dev, DRM_UT_DRMRES, fmt, ##__VA_ARGS__)
Jani Nikulafb6c7ab2019-12-10 14:30:43 +0200465
466
467/*
Jani Nikula3bf149b2019-10-28 12:38:21 +0200468 * printk based logging
Jani Nikulafb6c7ab2019-12-10 14:30:43 +0200469 *
470 * Prefer drm_device based logging over device or prink based logging.
Jani Nikula3bf149b2019-10-28 12:38:21 +0200471 */
472
Joe Perches99a95482018-03-13 15:02:15 -0700473__printf(2, 3)
Jani Nikula876905b2019-10-28 12:38:20 +0200474void __drm_dbg(enum drm_debug_category category, const char *format, ...);
Joe Perches99a95482018-03-13 15:02:15 -0700475__printf(1, 2)
Jani Nikula99acf472019-10-28 12:38:19 +0200476void __drm_err(const char *format, ...);
Haneen Mohammed091756b2017-10-17 22:31:22 -0600477
478/* Macros to make printk easier */
Haneen Mohammed02c96562017-10-17 22:30:07 -0600479
480#define _DRM_PRINTK(once, level, fmt, ...) \
Joe Perchesdb870862018-03-16 13:56:27 -0700481 printk##once(KERN_##level "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
Haneen Mohammed02c96562017-10-17 22:30:07 -0600482
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
Haneen Mohammed02c96562017-10-17 22:30:07 -0600497#define DRM_ERROR(fmt, ...) \
Jani Nikula99acf472019-10-28 12:38:19 +0200498 __drm_err(fmt, ##__VA_ARGS__)
Haneen Mohammed02c96562017-10-17 22:30:07 -0600499
Haneen Mohammed02c96562017-10-17 22:30:07 -0600500#define DRM_ERROR_RATELIMITED(fmt, ...) \
501 DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__)
502
Haneen Mohammed02c96562017-10-17 22:30:07 -0600503#define DRM_DEBUG(fmt, ...) \
Jani Nikula99acf472019-10-28 12:38:19 +0200504 __drm_dbg(DRM_UT_CORE, fmt, ##__VA_ARGS__)
Haneen Mohammed02c96562017-10-17 22:30:07 -0600505
Haneen Mohammed02c96562017-10-17 22:30:07 -0600506#define DRM_DEBUG_DRIVER(fmt, ...) \
Jani Nikula99acf472019-10-28 12:38:19 +0200507 __drm_dbg(DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
Haneen Mohammed02c96562017-10-17 22:30:07 -0600508
Joe Perches99a95482018-03-13 15:02:15 -0700509#define DRM_DEBUG_KMS(fmt, ...) \
Jani Nikula99acf472019-10-28 12:38:19 +0200510 __drm_dbg(DRM_UT_KMS, fmt, ##__VA_ARGS__)
Haneen Mohammed02c96562017-10-17 22:30:07 -0600511
Haneen Mohammed02c96562017-10-17 22:30:07 -0600512#define DRM_DEBUG_PRIME(fmt, ...) \
Jani Nikula99acf472019-10-28 12:38:19 +0200513 __drm_dbg(DRM_UT_PRIME, fmt, ##__VA_ARGS__)
Haneen Mohammed02c96562017-10-17 22:30:07 -0600514
Haneen Mohammed02c96562017-10-17 22:30:07 -0600515#define DRM_DEBUG_ATOMIC(fmt, ...) \
Jani Nikula99acf472019-10-28 12:38:19 +0200516 __drm_dbg(DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
Haneen Mohammed02c96562017-10-17 22:30:07 -0600517
Joe Perches99a95482018-03-13 15:02:15 -0700518#define DRM_DEBUG_VBL(fmt, ...) \
Jani Nikula99acf472019-10-28 12:38:19 +0200519 __drm_dbg(DRM_UT_VBL, fmt, ##__VA_ARGS__)
Haneen Mohammed02c96562017-10-17 22:30:07 -0600520
Daniel Vetter70c5f932017-11-21 11:33:10 +0100521#define DRM_DEBUG_LEASE(fmt, ...) \
Jani Nikula99acf472019-10-28 12:38:19 +0200522 __drm_dbg(DRM_UT_LEASE, fmt, ##__VA_ARGS__)
Daniel Vetter70c5f932017-11-21 11:33:10 +0100523
Lyude Paul106b6c32018-07-18 17:57:16 -0400524#define DRM_DEBUG_DP(fmt, ...) \
Jani Nikula99acf472019-10-28 12:38:19 +0200525 __drm_dbg(DRM_UT_DP, fmt, ## __VA_ARGS__)
Lyude Paula18b2192018-07-16 11:44:32 -0400526
Lyude Paulc5261e92021-03-26 16:37:54 -0400527#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__); \
Sam Ravnborgacce61b2020-02-14 18:54:42 +0100534})
Joe Perchesdb870862018-03-16 13:56:27 -0700535
Lyude Paulc5261e92021-03-26 16:37:54 -0400536#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
Pankaj Bharadiyadc1a73e2020-01-15 09:14:45 +0530541/*
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
Rob Clarkd81871772016-11-05 11:08:07 -0400570#endif /* DRM_PRINT_H_ */