Commit | Line | Data |
---|---|---|
d8187177 RC |
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 | ||
3c6d6e0f JP |
29 | #include <linux/compiler.h> |
30 | #include <linux/printk.h> | |
d8187177 RC |
31 | #include <linux/seq_file.h> |
32 | #include <linux/device.h> | |
5f513cc8 | 33 | #include <linux/debugfs.h> |
d8187177 | 34 | |
656600ef SR |
35 | #include <drm/drm.h> |
36 | ||
9f0ac028 JN |
37 | /* Do *not* use outside of drm_print.[ch]! */ |
38 | extern unsigned int __drm_debug; | |
959b077f | 39 | |
d8187177 RC |
40 | /** |
41 | * DOC: print | |
42 | * | |
43 | * A simple wrapper for dev_printk(), seq_printf(), etc. Allows same | |
44 | * debug code to be used for both debugfs and printk logging. | |
45 | * | |
46 | * For example:: | |
47 | * | |
48 | * void log_some_info(struct drm_printer *p) | |
49 | * { | |
50 | * drm_printf(p, "foo=%d\n", foo); | |
51 | * drm_printf(p, "bar=%d\n", bar); | |
52 | * } | |
53 | * | |
54 | * #ifdef CONFIG_DEBUG_FS | |
55 | * void debugfs_show(struct seq_file *f) | |
56 | * { | |
57 | * struct drm_printer p = drm_seq_file_printer(f); | |
58 | * log_some_info(&p); | |
59 | * } | |
60 | * #endif | |
61 | * | |
62 | * void some_other_function(...) | |
63 | * { | |
64 | * struct drm_printer p = drm_info_printer(drm->dev); | |
65 | * log_some_info(&p); | |
66 | * } | |
67 | */ | |
68 | ||
69 | /** | |
70 | * struct drm_printer - drm output "stream" | |
d8187177 RC |
71 | * |
72 | * Do not use struct members directly. Use drm_printer_seq_file(), | |
73 | * drm_printer_info(), etc to initialize. And drm_printf() for output. | |
74 | */ | |
75 | struct drm_printer { | |
3d387d92 | 76 | /* private: */ |
d8187177 | 77 | void (*printfn)(struct drm_printer *p, struct va_format *vaf); |
63f4cc01 | 78 | void (*puts)(struct drm_printer *p, const char *str); |
d8187177 | 79 | void *arg; |
3d387d92 | 80 | const char *prefix; |
d8187177 RC |
81 | }; |
82 | ||
cfc57a18 | 83 | void __drm_printfn_coredump(struct drm_printer *p, struct va_format *vaf); |
5dc634bd | 84 | void __drm_puts_coredump(struct drm_printer *p, const char *str); |
d8187177 | 85 | void __drm_printfn_seq_file(struct drm_printer *p, struct va_format *vaf); |
4538d732 | 86 | void __drm_puts_seq_file(struct drm_printer *p, const char *str); |
d8187177 | 87 | void __drm_printfn_info(struct drm_printer *p, struct va_format *vaf); |
3d387d92 | 88 | void __drm_printfn_debug(struct drm_printer *p, struct va_format *vaf); |
0de54fb2 | 89 | void __drm_printfn_err(struct drm_printer *p, struct va_format *vaf); |
d8187177 | 90 | |
3c6d6e0f | 91 | __printf(2, 3) |
d8187177 | 92 | void drm_printf(struct drm_printer *p, const char *f, ...); |
63f4cc01 | 93 | void drm_puts(struct drm_printer *p, const char *str); |
5f513cc8 | 94 | void drm_print_regset32(struct drm_printer *p, struct debugfs_regset32 *regset); |
141f6357 GH |
95 | void drm_print_bits(struct drm_printer *p, unsigned long value, |
96 | const char * const bits[], unsigned int nbits); | |
d8187177 | 97 | |
42f1b310 | 98 | __printf(2, 0) |
e2b155e9 CW |
99 | /** |
100 | * drm_vprintf - print to a &drm_printer stream | |
101 | * @p: the &drm_printer | |
102 | * @fmt: format string | |
103 | * @va: the va_list | |
104 | */ | |
e2b155e9 CW |
105 | static inline void |
106 | drm_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 | ||
bf6234a2 NT |
113 | /** |
114 | * drm_printf_indent - Print to a &drm_printer stream with indentation | |
115 | * @printer: DRM printer | |
116 | * @indent: Tab indentation level (max 5) | |
117 | * @fmt: Format string | |
118 | */ | |
119 | #define drm_printf_indent(printer, indent, fmt, ...) \ | |
120 | drm_printf((printer), "%.*s" fmt, (indent), "\t\t\t\t\tX", ##__VA_ARGS__) | |
d8187177 | 121 | |
cfc57a18 JC |
122 | /** |
123 | * struct drm_print_iterator - local struct used with drm_printer_coredump | |
124 | * @data: Pointer to the devcoredump output buffer | |
125 | * @start: The offset within the buffer to start writing | |
126 | * @remain: The number of bytes to write for this iteration | |
127 | */ | |
128 | struct 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 | */ | |
172 | static inline struct drm_printer | |
173 | drm_coredump_printer(struct drm_print_iterator *iter) | |
174 | { | |
175 | struct drm_printer p = { | |
176 | .printfn = __drm_printfn_coredump, | |
5dc634bd | 177 | .puts = __drm_puts_coredump, |
cfc57a18 JC |
178 | .arg = iter, |
179 | }; | |
180 | ||
181 | /* Set the internal offset of the iterator to zero */ | |
182 | iter->offset = 0; | |
183 | ||
184 | return p; | |
185 | } | |
186 | ||
d8187177 RC |
187 | /** |
188 | * drm_seq_file_printer - construct a &drm_printer that outputs to &seq_file | |
ea0dd85a | 189 | * @f: the &struct seq_file to output to |
d8187177 RC |
190 | * |
191 | * RETURNS: | |
192 | * The &drm_printer object | |
193 | */ | |
194 | static inline struct drm_printer drm_seq_file_printer(struct seq_file *f) | |
195 | { | |
196 | struct drm_printer p = { | |
197 | .printfn = __drm_printfn_seq_file, | |
4538d732 | 198 | .puts = __drm_puts_seq_file, |
d8187177 RC |
199 | .arg = f, |
200 | }; | |
201 | return p; | |
202 | } | |
203 | ||
204 | /** | |
205 | * drm_info_printer - construct a &drm_printer that outputs to dev_printk() | |
ea0dd85a | 206 | * @dev: the &struct device pointer |
d8187177 RC |
207 | * |
208 | * RETURNS: | |
209 | * The &drm_printer object | |
210 | */ | |
211 | static 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 | ||
3d387d92 DV |
220 | /** |
221 | * drm_debug_printer - construct a &drm_printer that outputs to pr_debug() | |
222 | * @prefix: debug output prefix | |
223 | * | |
224 | * RETURNS: | |
225 | * The &drm_printer object | |
226 | */ | |
227 | static 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 | } | |
02c9656b | 235 | |
0de54fb2 LP |
236 | /** |
237 | * drm_err_printer - construct a &drm_printer that outputs to pr_err() | |
238 | * @prefix: debug output prefix | |
239 | * | |
240 | * RETURNS: | |
241 | * The &drm_printer object | |
242 | */ | |
243 | static 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 | ||
876905b8 JN |
252 | /** |
253 | * enum drm_debug_category - The DRM debug categories | |
02c9656b | 254 | * |
876905b8 JN |
255 | * Each of the DRM debug logging macros use a specific category, and the logging |
256 | * is filtered by the drm.debug module parameter. This enum specifies the values | |
257 | * for the interface. | |
02c9656b | 258 | * |
876905b8 JN |
259 | * Each DRM_DEBUG_<CATEGORY> macro logs to DRM_UT_<CATEGORY> category, except |
260 | * DRM_DEBUG() logs to DRM_UT_CORE. | |
02c9656b | 261 | * |
876905b8 JN |
262 | * Enabling verbose debug messages is done through the drm.debug parameter, each |
263 | * category being enabled by a bit: | |
02c9656b | 264 | * |
876905b8 JN |
265 | * - drm.debug=0x1 will enable CORE messages |
266 | * - drm.debug=0x2 will enable DRIVER messages | |
267 | * - drm.debug=0x3 will enable CORE and DRIVER messages | |
268 | * - ... | |
269 | * - drm.debug=0x1ff will enable all messages | |
02c9656b HM |
270 | * |
271 | * An interesting feature is that it's possible to enable verbose logging at | |
876905b8 JN |
272 | * run-time by echoing the debug value in its sysfs node:: |
273 | * | |
02c9656b | 274 | * # echo 0xf > /sys/module/drm/parameters/debug |
876905b8 | 275 | * |
02c9656b | 276 | */ |
876905b8 JN |
277 | enum 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, | |
c6603c74 DV |
316 | /** |
317 | * @DRM_UT_DRMRES: Used in the drm managed resources code. | |
318 | */ | |
319 | DRM_UT_DRMRES = 0x200, | |
876905b8 | 320 | }; |
02c9656b | 321 | |
876905b8 | 322 | static inline bool drm_debug_enabled(enum drm_debug_category category) |
f0a8f533 | 323 | { |
9f0ac028 | 324 | return unlikely(__drm_debug & category); |
f0a8f533 JN |
325 | } |
326 | ||
3bf149bd JN |
327 | /* |
328 | * struct device based logging | |
fb6c7ab8 | 329 | * |
51fdf091 | 330 | * Prefer drm_device based logging over device or printk based logging. |
3bf149bd JN |
331 | */ |
332 | ||
db870864 | 333 | __printf(3, 4) |
02c9656b | 334 | void drm_dev_printk(const struct device *dev, const char *level, |
db870864 JP |
335 | const char *format, ...); |
336 | __printf(3, 4) | |
876905b8 | 337 | void drm_dev_dbg(const struct device *dev, enum drm_debug_category category, |
db870864 JP |
338 | const char *format, ...); |
339 | ||
02c9656b | 340 | /** |
b52817e9 | 341 | * DRM_DEV_ERROR() - Error output. |
02c9656b | 342 | * |
30658985 DA |
343 | * NOTE: this is deprecated in favor of drm_err() or dev_err(). |
344 | * | |
091756bb HM |
345 | * @dev: device pointer |
346 | * @fmt: printf() like format string. | |
02c9656b HM |
347 | */ |
348 | #define DRM_DEV_ERROR(dev, fmt, ...) \ | |
db870864 | 349 | drm_dev_printk(dev, KERN_ERR, "*ERROR* " fmt, ##__VA_ARGS__) |
02c9656b HM |
350 | |
351 | /** | |
b52817e9 | 352 | * DRM_DEV_ERROR_RATELIMITED() - Rate limited error output. |
02c9656b | 353 | * |
30658985 DA |
354 | * NOTE: this is deprecated in favor of drm_err_ratelimited() or |
355 | * dev_err_ratelimited(). | |
356 | * | |
091756bb HM |
357 | * @dev: device pointer |
358 | * @fmt: printf() like format string. | |
b52817e9 MCC |
359 | * |
360 | * Like DRM_ERROR() but won't flood the log. | |
02c9656b HM |
361 | */ |
362 | #define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...) \ | |
363 | ({ \ | |
364 | static DEFINE_RATELIMIT_STATE(_rs, \ | |
365 | DEFAULT_RATELIMIT_INTERVAL, \ | |
366 | DEFAULT_RATELIMIT_BURST); \ | |
367 | \ | |
368 | if (__ratelimit(&_rs)) \ | |
369 | DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__); \ | |
370 | }) | |
02c9656b | 371 | |
30658985 | 372 | /* NOTE: this is deprecated in favor of drm_info() or dev_info(). */ |
3bf149bd | 373 | #define DRM_DEV_INFO(dev, fmt, ...) \ |
db870864 | 374 | drm_dev_printk(dev, KERN_INFO, fmt, ##__VA_ARGS__) |
02c9656b | 375 | |
30658985 | 376 | /* NOTE: this is deprecated in favor of drm_info_once() or dev_info_once(). */ |
02c9656b HM |
377 | #define DRM_DEV_INFO_ONCE(dev, fmt, ...) \ |
378 | ({ \ | |
379 | static bool __print_once __read_mostly; \ | |
380 | if (!__print_once) { \ | |
381 | __print_once = true; \ | |
382 | DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__); \ | |
383 | } \ | |
384 | }) | |
385 | ||
386 | /** | |
b52817e9 | 387 | * DRM_DEV_DEBUG() - Debug output for generic drm code |
02c9656b | 388 | * |
30658985 DA |
389 | * NOTE: this is deprecated in favor of drm_dbg_core(). |
390 | * | |
091756bb HM |
391 | * @dev: device pointer |
392 | * @fmt: printf() like format string. | |
02c9656b | 393 | */ |
db870864 JP |
394 | #define DRM_DEV_DEBUG(dev, fmt, ...) \ |
395 | drm_dev_dbg(dev, DRM_UT_CORE, fmt, ##__VA_ARGS__) | |
b52817e9 MCC |
396 | /** |
397 | * DRM_DEV_DEBUG_DRIVER() - Debug output for vendor specific part of the driver | |
398 | * | |
30658985 DA |
399 | * NOTE: this is deprecated in favor of drm_dbg() or dev_dbg(). |
400 | * | |
b52817e9 MCC |
401 | * @dev: device pointer |
402 | * @fmt: printf() like format string. | |
403 | */ | |
db870864 JP |
404 | #define DRM_DEV_DEBUG_DRIVER(dev, fmt, ...) \ |
405 | drm_dev_dbg(dev, DRM_UT_DRIVER, fmt, ##__VA_ARGS__) | |
b52817e9 MCC |
406 | /** |
407 | * DRM_DEV_DEBUG_KMS() - Debug output for modesetting code | |
408 | * | |
30658985 DA |
409 | * NOTE: this is deprecated in favor of drm_dbg_kms(). |
410 | * | |
b52817e9 MCC |
411 | * @dev: device pointer |
412 | * @fmt: printf() like format string. | |
413 | */ | |
db870864 JP |
414 | #define DRM_DEV_DEBUG_KMS(dev, fmt, ...) \ |
415 | drm_dev_dbg(dev, DRM_UT_KMS, fmt, ##__VA_ARGS__) | |
a18b2192 | 416 | |
fb6c7ab8 JN |
417 | /* |
418 | * struct drm_device based logging | |
419 | * | |
420 | * Prefer drm_device based logging over device or prink based logging. | |
421 | */ | |
422 | ||
423 | /* Helper for struct drm_device based logging. */ | |
424 | #define __drm_printk(drm, level, type, fmt, ...) \ | |
425 | dev_##level##type((drm)->dev, "[drm] " fmt, ##__VA_ARGS__) | |
426 | ||
427 | ||
428 | #define drm_info(drm, fmt, ...) \ | |
429 | __drm_printk((drm), info,, fmt, ##__VA_ARGS__) | |
430 | ||
431 | #define drm_notice(drm, fmt, ...) \ | |
432 | __drm_printk((drm), notice,, fmt, ##__VA_ARGS__) | |
433 | ||
434 | #define drm_warn(drm, fmt, ...) \ | |
435 | __drm_printk((drm), warn,, fmt, ##__VA_ARGS__) | |
436 | ||
437 | #define drm_err(drm, fmt, ...) \ | |
438 | __drm_printk((drm), err,, "*ERROR* " fmt, ##__VA_ARGS__) | |
439 | ||
440 | ||
441 | #define drm_info_once(drm, fmt, ...) \ | |
442 | __drm_printk((drm), info, _once, fmt, ##__VA_ARGS__) | |
443 | ||
444 | #define drm_notice_once(drm, fmt, ...) \ | |
445 | __drm_printk((drm), notice, _once, fmt, ##__VA_ARGS__) | |
446 | ||
447 | #define drm_warn_once(drm, fmt, ...) \ | |
448 | __drm_printk((drm), warn, _once, fmt, ##__VA_ARGS__) | |
449 | ||
450 | #define drm_err_once(drm, fmt, ...) \ | |
451 | __drm_printk((drm), err, _once, "*ERROR* " fmt, ##__VA_ARGS__) | |
452 | ||
453 | ||
454 | #define drm_err_ratelimited(drm, fmt, ...) \ | |
455 | __drm_printk((drm), err, _ratelimited, "*ERROR* " fmt, ##__VA_ARGS__) | |
456 | ||
457 | ||
458 | #define drm_dbg_core(drm, fmt, ...) \ | |
79119021 | 459 | drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_CORE, fmt, ##__VA_ARGS__) |
fb6c7ab8 | 460 | #define drm_dbg(drm, fmt, ...) \ |
79119021 | 461 | drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_DRIVER, fmt, ##__VA_ARGS__) |
fb6c7ab8 | 462 | #define drm_dbg_kms(drm, fmt, ...) \ |
79119021 | 463 | drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_KMS, fmt, ##__VA_ARGS__) |
fb6c7ab8 | 464 | #define drm_dbg_prime(drm, fmt, ...) \ |
79119021 | 465 | drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_PRIME, fmt, ##__VA_ARGS__) |
fb6c7ab8 | 466 | #define drm_dbg_atomic(drm, fmt, ...) \ |
79119021 | 467 | drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__) |
fb6c7ab8 | 468 | #define drm_dbg_vbl(drm, fmt, ...) \ |
79119021 | 469 | drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_VBL, fmt, ##__VA_ARGS__) |
fb6c7ab8 | 470 | #define drm_dbg_state(drm, fmt, ...) \ |
79119021 | 471 | drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_STATE, fmt, ##__VA_ARGS__) |
fb6c7ab8 | 472 | #define drm_dbg_lease(drm, fmt, ...) \ |
79119021 | 473 | drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_LEASE, fmt, ##__VA_ARGS__) |
fb6c7ab8 | 474 | #define drm_dbg_dp(drm, fmt, ...) \ |
79119021 | 475 | drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_DP, fmt, ##__VA_ARGS__) |
c6603c74 | 476 | #define drm_dbg_drmres(drm, fmt, ...) \ |
79119021 | 477 | drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_DRMRES, fmt, ##__VA_ARGS__) |
fb6c7ab8 JN |
478 | |
479 | ||
3bf149bd JN |
480 | /* |
481 | * printk based logging | |
fb6c7ab8 JN |
482 | * |
483 | * Prefer drm_device based logging over device or prink based logging. | |
3bf149bd JN |
484 | */ |
485 | ||
486 | __printf(2, 3) | |
487 | void __drm_dbg(enum drm_debug_category category, const char *format, ...); | |
488 | __printf(1, 2) | |
489 | void __drm_err(const char *format, ...); | |
490 | ||
491 | /* Macros to make printk easier */ | |
492 | ||
493 | #define _DRM_PRINTK(once, level, fmt, ...) \ | |
494 | printk##once(KERN_##level "[" DRM_NAME "] " fmt, ##__VA_ARGS__) | |
495 | ||
30658985 | 496 | /* NOTE: this is deprecated in favor of pr_info(). */ |
3bf149bd JN |
497 | #define DRM_INFO(fmt, ...) \ |
498 | _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__) | |
30658985 | 499 | /* NOTE: this is deprecated in favor of pr_notice(). */ |
3bf149bd JN |
500 | #define DRM_NOTE(fmt, ...) \ |
501 | _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__) | |
30658985 | 502 | /* NOTE: this is deprecated in favor of pr_warn(). */ |
3bf149bd JN |
503 | #define DRM_WARN(fmt, ...) \ |
504 | _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__) | |
505 | ||
30658985 | 506 | /* NOTE: this is deprecated in favor of pr_info_once(). */ |
3bf149bd JN |
507 | #define DRM_INFO_ONCE(fmt, ...) \ |
508 | _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__) | |
30658985 | 509 | /* NOTE: this is deprecated in favor of pr_notice_once(). */ |
3bf149bd JN |
510 | #define DRM_NOTE_ONCE(fmt, ...) \ |
511 | _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__) | |
30658985 | 512 | /* NOTE: this is deprecated in favor of pr_warn_once(). */ |
3bf149bd JN |
513 | #define DRM_WARN_ONCE(fmt, ...) \ |
514 | _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__) | |
515 | ||
30658985 | 516 | /* NOTE: this is deprecated in favor of pr_err(). */ |
3bf149bd JN |
517 | #define DRM_ERROR(fmt, ...) \ |
518 | __drm_err(fmt, ##__VA_ARGS__) | |
519 | ||
30658985 | 520 | /* NOTE: this is deprecated in favor of pr_err_ratelimited(). */ |
3bf149bd JN |
521 | #define DRM_ERROR_RATELIMITED(fmt, ...) \ |
522 | DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__) | |
523 | ||
30658985 | 524 | /* NOTE: this is deprecated in favor of drm_dbg_core(NULL, ...). */ |
3bf149bd JN |
525 | #define DRM_DEBUG(fmt, ...) \ |
526 | __drm_dbg(DRM_UT_CORE, fmt, ##__VA_ARGS__) | |
527 | ||
30658985 | 528 | /* NOTE: this is deprecated in favor of drm_dbg(NULL, ...). */ |
3bf149bd JN |
529 | #define DRM_DEBUG_DRIVER(fmt, ...) \ |
530 | __drm_dbg(DRM_UT_DRIVER, fmt, ##__VA_ARGS__) | |
531 | ||
30658985 | 532 | /* NOTE: this is deprecated in favor of drm_dbg_kms(NULL, ...). */ |
3bf149bd JN |
533 | #define DRM_DEBUG_KMS(fmt, ...) \ |
534 | __drm_dbg(DRM_UT_KMS, fmt, ##__VA_ARGS__) | |
535 | ||
30658985 | 536 | /* NOTE: this is deprecated in favor of drm_dbg_prime(NULL, ...). */ |
3bf149bd JN |
537 | #define DRM_DEBUG_PRIME(fmt, ...) \ |
538 | __drm_dbg(DRM_UT_PRIME, fmt, ##__VA_ARGS__) | |
539 | ||
30658985 | 540 | /* NOTE: this is deprecated in favor of drm_dbg_atomic(NULL, ...). */ |
3bf149bd JN |
541 | #define DRM_DEBUG_ATOMIC(fmt, ...) \ |
542 | __drm_dbg(DRM_UT_ATOMIC, fmt, ##__VA_ARGS__) | |
543 | ||
30658985 | 544 | /* NOTE: this is deprecated in favor of drm_dbg_vbl(NULL, ...). */ |
3bf149bd JN |
545 | #define DRM_DEBUG_VBL(fmt, ...) \ |
546 | __drm_dbg(DRM_UT_VBL, fmt, ##__VA_ARGS__) | |
547 | ||
30658985 | 548 | /* NOTE: this is deprecated in favor of drm_dbg_lease(NULL, ...). */ |
3bf149bd JN |
549 | #define DRM_DEBUG_LEASE(fmt, ...) \ |
550 | __drm_dbg(DRM_UT_LEASE, fmt, ##__VA_ARGS__) | |
551 | ||
30658985 | 552 | /* NOTE: this is deprecated in favor of drm_dbg_dp(NULL, ...). */ |
3bf149bd JN |
553 | #define DRM_DEBUG_DP(fmt, ...) \ |
554 | __drm_dbg(DRM_UT_DP, fmt, ## __VA_ARGS__) | |
555 | ||
c5261e93 LP |
556 | #define __DRM_DEFINE_DBG_RATELIMITED(category, drm, fmt, ...) \ |
557 | ({ \ | |
558 | static DEFINE_RATELIMIT_STATE(rs_, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST);\ | |
559 | const struct drm_device *drm_ = (drm); \ | |
560 | \ | |
561 | if (drm_debug_enabled(DRM_UT_ ## category) && __ratelimit(&rs_)) \ | |
562 | drm_dev_printk(drm_ ? drm_->dev : NULL, KERN_DEBUG, fmt, ## __VA_ARGS__); \ | |
acce61bf | 563 | }) |
3bf149bd | 564 | |
c5261e93 LP |
565 | #define drm_dbg_kms_ratelimited(drm, fmt, ...) \ |
566 | __DRM_DEFINE_DBG_RATELIMITED(KMS, drm, fmt, ## __VA_ARGS__) | |
567 | ||
30658985 | 568 | /* NOTE: this is deprecated in favor of drm_dbg_kms_ratelimited(NULL, ...). */ |
c5261e93 LP |
569 | #define DRM_DEBUG_KMS_RATELIMITED(fmt, ...) drm_dbg_kms_ratelimited(NULL, fmt, ## __VA_ARGS__) |
570 | ||
dc1a73e5 PB |
571 | /* |
572 | * struct drm_device based WARNs | |
573 | * | |
574 | * drm_WARN*() acts like WARN*(), but with the key difference of | |
575 | * using device specific information so that we know from which device | |
576 | * warning is originating from. | |
577 | * | |
578 | * Prefer drm_device based drm_WARN* over regular WARN* | |
579 | */ | |
580 | ||
581 | /* Helper for struct drm_device based WARNs */ | |
582 | #define drm_WARN(drm, condition, format, arg...) \ | |
583 | WARN(condition, "%s %s: " format, \ | |
584 | dev_driver_string((drm)->dev), \ | |
585 | dev_name((drm)->dev), ## arg) | |
586 | ||
587 | #define drm_WARN_ONCE(drm, condition, format, arg...) \ | |
588 | WARN_ONCE(condition, "%s %s: " format, \ | |
589 | dev_driver_string((drm)->dev), \ | |
590 | dev_name((drm)->dev), ## arg) | |
591 | ||
592 | #define drm_WARN_ON(drm, x) \ | |
593 | drm_WARN((drm), (x), "%s", \ | |
594 | "drm_WARN_ON(" __stringify(x) ")") | |
595 | ||
596 | #define drm_WARN_ON_ONCE(drm, x) \ | |
597 | drm_WARN_ONCE((drm), (x), "%s", \ | |
598 | "drm_WARN_ON_ONCE(" __stringify(x) ")") | |
599 | ||
d8187177 | 600 | #endif /* DRM_PRINT_H_ */ |