1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
38extern unsigned int __drm_debug;
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75struct drm_printer {
76
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
101
102
103
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
115
116
117
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
124
125
126
127
128struct drm_print_iterator {
129 void *data;
130 ssize_t start;
131 ssize_t remain;
132
133 ssize_t offset;
134};
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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
182 iter->offset = 0;
183
184 return p;
185}
186
187
188
189
190
191
192
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
206
207
208
209
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
222
223
224
225
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
238
239
240
241
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277enum drm_debug_category {
278
279
280
281
282 DRM_UT_CORE = 0x01,
283
284
285
286
287 DRM_UT_DRIVER = 0x02,
288
289
290
291 DRM_UT_KMS = 0x04,
292
293
294
295 DRM_UT_PRIME = 0x08,
296
297
298
299 DRM_UT_ATOMIC = 0x10,
300
301
302
303 DRM_UT_VBL = 0x20,
304
305
306
307 DRM_UT_STATE = 0x40,
308
309
310
311 DRM_UT_LEASE = 0x80,
312
313
314
315 DRM_UT_DP = 0x100,
316
317
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
329
330
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
342
343
344
345
346#define DRM_DEV_ERROR(dev, fmt, ...) \
347 drm_dev_printk(dev, KERN_ERR, "*ERROR* " fmt, ##__VA_ARGS__)
348
349
350
351
352
353
354
355
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
381
382
383
384
385#define DRM_DEV_DEBUG(dev, fmt, ...) \
386 drm_dev_dbg(dev, DRM_UT_CORE, fmt, ##__VA_ARGS__)
387
388
389
390
391
392
393#define DRM_DEV_DEBUG_DRIVER(dev, fmt, ...) \
394 drm_dev_dbg(dev, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
395
396
397
398
399
400
401#define DRM_DEV_DEBUG_KMS(dev, fmt, ...) \
402 drm_dev_dbg(dev, DRM_UT_KMS, fmt, ##__VA_ARGS__)
403
404
405
406
407
408
409
410
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
469
470
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
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
543
544
545
546
547
548
549
550
551
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
571