1 /* 2 * Copyright (C) 2016 Red Hat 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * Authors: 23 * Rob Clark <robdclark@gmail.com> 24 */ 25 26 #ifndef DRM_PRINT_H_ 27 #define DRM_PRINT_H_ 28 29 #include <linux/compiler.h> 30 #include <linux/printk.h> 31 #include <linux/device.h> 32 #include <linux/dynamic_debug.h> 33 34 #include <drm/drm.h> 35 36 struct debugfs_regset32; 37 struct drm_device; 38 struct seq_file; 39 40 /* Do *not* use outside of drm_print.[ch]! */ 41 extern unsigned long __drm_debug; 42 43 /** 44 * DOC: print 45 * 46 * A simple wrapper for dev_printk(), seq_printf(), etc. Allows same 47 * debug code to be used for both debugfs and printk logging. 48 * 49 * For example:: 50 * 51 * void log_some_info(struct drm_printer *p) 52 * { 53 * drm_printf(p, "foo=%d\n", foo); 54 * drm_printf(p, "bar=%d\n", bar); 55 * } 56 * 57 * #ifdef CONFIG_DEBUG_FS 58 * void debugfs_show(struct seq_file *f) 59 * { 60 * struct drm_printer p = drm_seq_file_printer(f); 61 * log_some_info(&p); 62 * } 63 * #endif 64 * 65 * void some_other_function(...) 66 * { 67 * struct drm_printer p = drm_info_printer(drm->dev); 68 * log_some_info(&p); 69 * } 70 */ 71 72 /** 73 * enum drm_debug_category - The DRM debug categories 74 * 75 * Each of the DRM debug logging macros use a specific category, and the logging 76 * is filtered by the drm.debug module parameter. This enum specifies the values 77 * for the interface. 78 * 79 * Each DRM_DEBUG_<CATEGORY> macro logs to DRM_UT_<CATEGORY> category, except 80 * DRM_DEBUG() logs to DRM_UT_CORE. 81 * 82 * Enabling verbose debug messages is done through the drm.debug parameter, each 83 * category being enabled by a bit: 84 * 85 * - drm.debug=0x1 will enable CORE messages 86 * - drm.debug=0x2 will enable DRIVER messages 87 * - drm.debug=0x3 will enable CORE and DRIVER messages 88 * - ... 89 * - drm.debug=0x1ff will enable all messages 90 * 91 * An interesting feature is that it's possible to enable verbose logging at 92 * run-time by echoing the debug value in its sysfs node:: 93 * 94 * # echo 0xf > /sys/module/drm/parameters/debug 95 * 96 */ 97 enum drm_debug_category { 98 /* These names must match those in DYNAMIC_DEBUG_CLASSBITS */ 99 /** 100 * @DRM_UT_CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, 101 * drm_memory.c, ... 102 */ 103 DRM_UT_CORE, 104 /** 105 * @DRM_UT_DRIVER: Used in the vendor specific part of the driver: i915, 106 * radeon, ... macro. 107 */ 108 DRM_UT_DRIVER, 109 /** 110 * @DRM_UT_KMS: Used in the modesetting code. 111 */ 112 DRM_UT_KMS, 113 /** 114 * @DRM_UT_PRIME: Used in the prime code. 115 */ 116 DRM_UT_PRIME, 117 /** 118 * @DRM_UT_ATOMIC: Used in the atomic code. 119 */ 120 DRM_UT_ATOMIC, 121 /** 122 * @DRM_UT_VBL: Used for verbose debug message in the vblank code. 123 */ 124 DRM_UT_VBL, 125 /** 126 * @DRM_UT_STATE: Used for verbose atomic state debugging. 127 */ 128 DRM_UT_STATE, 129 /** 130 * @DRM_UT_LEASE: Used in the lease code. 131 */ 132 DRM_UT_LEASE, 133 /** 134 * @DRM_UT_DP: Used in the DP code. 135 */ 136 DRM_UT_DP, 137 /** 138 * @DRM_UT_DRMRES: Used in the drm managed resources code. 139 */ 140 DRM_UT_DRMRES 141 }; 142 143 static inline bool drm_debug_enabled_raw(enum drm_debug_category category) 144 { 145 return unlikely(__drm_debug & BIT(category)); 146 } 147 148 #define drm_debug_enabled_instrumented(category) \ 149 ({ \ 150 pr_debug("todo: is this frequent enough to optimize ?\n"); \ 151 drm_debug_enabled_raw(category); \ 152 }) 153 154 #if defined(CONFIG_DRM_USE_DYNAMIC_DEBUG) 155 /* 156 * the drm.debug API uses dyndbg, so each drm_*dbg macro/callsite gets 157 * a descriptor, and only enabled callsites are reachable. They use 158 * the private macro to avoid re-testing the enable-bit. 159 */ 160 #define __drm_debug_enabled(category) true 161 #define drm_debug_enabled(category) drm_debug_enabled_instrumented(category) 162 #else 163 #define __drm_debug_enabled(category) drm_debug_enabled_raw(category) 164 #define drm_debug_enabled(category) drm_debug_enabled_raw(category) 165 #endif 166 167 /** 168 * struct drm_printer - drm output "stream" 169 * 170 * Do not use struct members directly. Use drm_printer_seq_file(), 171 * drm_printer_info(), etc to initialize. And drm_printf() for output. 172 */ 173 struct drm_printer { 174 /* private: */ 175 void (*printfn)(struct drm_printer *p, struct va_format *vaf); 176 void (*puts)(struct drm_printer *p, const char *str); 177 void *arg; 178 const void *origin; 179 const char *prefix; 180 struct { 181 unsigned int series; 182 unsigned int counter; 183 } line; 184 enum drm_debug_category category; 185 }; 186 187 void __drm_printfn_coredump(struct drm_printer *p, struct va_format *vaf); 188 void __drm_puts_coredump(struct drm_printer *p, const char *str); 189 void __drm_printfn_seq_file(struct drm_printer *p, struct va_format *vaf); 190 void __drm_puts_seq_file(struct drm_printer *p, const char *str); 191 void __drm_printfn_info(struct drm_printer *p, struct va_format *vaf); 192 void __drm_printfn_dbg(struct drm_printer *p, struct va_format *vaf); 193 void __drm_printfn_err(struct drm_printer *p, struct va_format *vaf); 194 void __drm_printfn_line(struct drm_printer *p, struct va_format *vaf); 195 196 __printf(2, 3) 197 void drm_printf(struct drm_printer *p, const char *f, ...); 198 void drm_puts(struct drm_printer *p, const char *str); 199 void drm_print_regset32(struct drm_printer *p, struct debugfs_regset32 *regset); 200 void drm_print_bits(struct drm_printer *p, unsigned long value, 201 const char * const bits[], unsigned int nbits); 202 void drm_print_hex_dump(struct drm_printer *p, const char *prefix, 203 const u8 *buf, size_t len); 204 205 __printf(2, 0) 206 /** 207 * drm_vprintf - print to a &drm_printer stream 208 * @p: the &drm_printer 209 * @fmt: format string 210 * @va: the va_list 211 */ 212 static inline void 213 drm_vprintf(struct drm_printer *p, const char *fmt, va_list *va) 214 { 215 struct va_format vaf = { .fmt = fmt, .va = va }; 216 217 p->printfn(p, &vaf); 218 } 219 220 /** 221 * drm_printf_indent - Print to a &drm_printer stream with indentation 222 * @printer: DRM printer 223 * @indent: Tab indentation level (max 5) 224 * @fmt: Format string 225 */ 226 #define drm_printf_indent(printer, indent, fmt, ...) \ 227 drm_printf((printer), "%.*s" fmt, (indent), "\t\t\t\t\tX", ##__VA_ARGS__) 228 229 /** 230 * struct drm_print_iterator - local struct used with drm_printer_coredump 231 * @data: Pointer to the devcoredump output buffer, can be NULL if using 232 * drm_printer_coredump to determine size of devcoredump 233 * @start: The offset within the buffer to start writing 234 * @remain: The number of bytes to write for this iteration 235 */ 236 struct drm_print_iterator { 237 void *data; 238 ssize_t start; 239 ssize_t remain; 240 /* private: */ 241 ssize_t offset; 242 }; 243 244 /** 245 * drm_coredump_printer - construct a &drm_printer that can output to a buffer 246 * from the read function for devcoredump 247 * @iter: A pointer to a struct drm_print_iterator for the read instance 248 * 249 * This wrapper extends drm_printf() to work with a dev_coredumpm() callback 250 * function. The passed in drm_print_iterator struct contains the buffer 251 * pointer, size and offset as passed in from devcoredump. 252 * 253 * For example:: 254 * 255 * void coredump_read(char *buffer, loff_t offset, size_t count, 256 * void *data, size_t datalen) 257 * { 258 * struct drm_print_iterator iter; 259 * struct drm_printer p; 260 * 261 * iter.data = buffer; 262 * iter.start = offset; 263 * iter.remain = count; 264 * 265 * p = drm_coredump_printer(&iter); 266 * 267 * drm_printf(p, "foo=%d\n", foo); 268 * } 269 * 270 * void makecoredump(...) 271 * { 272 * ... 273 * dev_coredumpm(dev, THIS_MODULE, data, 0, GFP_KERNEL, 274 * coredump_read, ...) 275 * } 276 * 277 * The above example has a time complexity of O(N^2), where N is the size of the 278 * devcoredump. This is acceptable for small devcoredumps but scales poorly for 279 * larger ones. 280 * 281 * Another use case for drm_coredump_printer is to capture the devcoredump into 282 * a saved buffer before the dev_coredump() callback. This involves two passes: 283 * one to determine the size of the devcoredump and another to print it to a 284 * buffer. Then, in dev_coredump(), copy from the saved buffer into the 285 * devcoredump read buffer. 286 * 287 * For example:: 288 * 289 * char *devcoredump_saved_buffer; 290 * 291 * ssize_t __coredump_print(char *buffer, ssize_t count, ...) 292 * { 293 * struct drm_print_iterator iter; 294 * struct drm_printer p; 295 * 296 * iter.data = buffer; 297 * iter.start = 0; 298 * iter.remain = count; 299 * 300 * p = drm_coredump_printer(&iter); 301 * 302 * drm_printf(p, "foo=%d\n", foo); 303 * ... 304 * return count - iter.remain; 305 * } 306 * 307 * void coredump_print(...) 308 * { 309 * ssize_t count; 310 * 311 * count = __coredump_print(NULL, INT_MAX, ...); 312 * devcoredump_saved_buffer = kvmalloc(count, GFP_KERNEL); 313 * __coredump_print(devcoredump_saved_buffer, count, ...); 314 * } 315 * 316 * void coredump_read(char *buffer, loff_t offset, size_t count, 317 * void *data, size_t datalen) 318 * { 319 * ... 320 * memcpy(buffer, devcoredump_saved_buffer + offset, count); 321 * ... 322 * } 323 * 324 * The above example has a time complexity of O(N*2), where N is the size of the 325 * devcoredump. This scales better than the previous example for larger 326 * devcoredumps. 327 * 328 * RETURNS: 329 * The &drm_printer object 330 */ 331 static inline struct drm_printer 332 drm_coredump_printer(struct drm_print_iterator *iter) 333 { 334 struct drm_printer p = { 335 .printfn = __drm_printfn_coredump, 336 .puts = __drm_puts_coredump, 337 .arg = iter, 338 }; 339 340 /* Set the internal offset of the iterator to zero */ 341 iter->offset = 0; 342 343 return p; 344 } 345 346 /** 347 * drm_seq_file_printer - construct a &drm_printer that outputs to &seq_file 348 * @f: the &struct seq_file to output to 349 * 350 * RETURNS: 351 * The &drm_printer object 352 */ 353 static inline struct drm_printer drm_seq_file_printer(struct seq_file *f) 354 { 355 struct drm_printer p = { 356 .printfn = __drm_printfn_seq_file, 357 .puts = __drm_puts_seq_file, 358 .arg = f, 359 }; 360 return p; 361 } 362 363 /** 364 * drm_info_printer - construct a &drm_printer that outputs to dev_printk() 365 * @dev: the &struct device pointer 366 * 367 * RETURNS: 368 * The &drm_printer object 369 */ 370 static inline struct drm_printer drm_info_printer(struct device *dev) 371 { 372 struct drm_printer p = { 373 .printfn = __drm_printfn_info, 374 .arg = dev, 375 }; 376 return p; 377 } 378 379 /** 380 * drm_dbg_printer - construct a &drm_printer for drm device specific output 381 * @drm: the &struct drm_device pointer, or NULL 382 * @category: the debug category to use 383 * @prefix: debug output prefix, or NULL for no prefix 384 * 385 * RETURNS: 386 * The &drm_printer object 387 */ 388 static inline struct drm_printer drm_dbg_printer(struct drm_device *drm, 389 enum drm_debug_category category, 390 const char *prefix) 391 { 392 struct drm_printer p = { 393 .printfn = __drm_printfn_dbg, 394 .arg = drm, 395 .origin = (const void *)_THIS_IP_, /* it's fine as we will be inlined */ 396 .prefix = prefix, 397 .category = category, 398 }; 399 return p; 400 } 401 402 /** 403 * drm_err_printer - construct a &drm_printer that outputs to drm_err() 404 * @drm: the &struct drm_device pointer 405 * @prefix: debug output prefix, or NULL for no prefix 406 * 407 * RETURNS: 408 * The &drm_printer object 409 */ 410 static inline struct drm_printer drm_err_printer(struct drm_device *drm, 411 const char *prefix) 412 { 413 struct drm_printer p = { 414 .printfn = __drm_printfn_err, 415 .arg = drm, 416 .prefix = prefix 417 }; 418 return p; 419 } 420 421 /** 422 * drm_line_printer - construct a &drm_printer that prefixes outputs with line numbers 423 * @p: the &struct drm_printer which actually generates the output 424 * @prefix: optional output prefix, or NULL for no prefix 425 * @series: optional unique series identifier, or 0 to omit identifier in the output 426 * 427 * This printer can be used to increase the robustness of the captured output 428 * to make sure we didn't lost any intermediate lines of the output. Helpful 429 * while capturing some crash data. 430 * 431 * Example 1:: 432 * 433 * void crash_dump(struct drm_device *drm) 434 * { 435 * static unsigned int id; 436 * struct drm_printer p = drm_err_printer(drm, "crash"); 437 * struct drm_printer lp = drm_line_printer(&p, "dump", ++id); 438 * 439 * drm_printf(&lp, "foo"); 440 * drm_printf(&lp, "bar"); 441 * } 442 * 443 * Above code will print into the dmesg something like:: 444 * 445 * [ ] 0000:00:00.0: [drm] *ERROR* crash dump 1.1: foo 446 * [ ] 0000:00:00.0: [drm] *ERROR* crash dump 1.2: bar 447 * 448 * Example 2:: 449 * 450 * void line_dump(struct device *dev) 451 * { 452 * struct drm_printer p = drm_info_printer(dev); 453 * struct drm_printer lp = drm_line_printer(&p, NULL, 0); 454 * 455 * drm_printf(&lp, "foo"); 456 * drm_printf(&lp, "bar"); 457 * } 458 * 459 * Above code will print:: 460 * 461 * [ ] 0000:00:00.0: [drm] 1: foo 462 * [ ] 0000:00:00.0: [drm] 2: bar 463 * 464 * RETURNS: 465 * The &drm_printer object 466 */ 467 static inline struct drm_printer drm_line_printer(struct drm_printer *p, 468 const char *prefix, 469 unsigned int series) 470 { 471 struct drm_printer lp = { 472 .printfn = __drm_printfn_line, 473 .arg = p, 474 .prefix = prefix, 475 .line = { .series = series, }, 476 }; 477 return lp; 478 } 479 480 /* 481 * struct device based logging 482 * 483 * Prefer drm_device based logging over device or printk based logging. 484 */ 485 486 __printf(3, 4) 487 void drm_dev_printk(const struct device *dev, const char *level, 488 const char *format, ...); 489 struct _ddebug; 490 __printf(4, 5) 491 void __drm_dev_dbg(struct _ddebug *desc, const struct device *dev, 492 enum drm_debug_category category, const char *format, ...); 493 494 /** 495 * DRM_DEV_ERROR() - Error output. 496 * 497 * NOTE: this is deprecated in favor of drm_err() or dev_err(). 498 * 499 * @dev: device pointer 500 * @fmt: printf() like format string. 501 */ 502 #define DRM_DEV_ERROR(dev, fmt, ...) \ 503 drm_dev_printk(dev, KERN_ERR, "*ERROR* " fmt, ##__VA_ARGS__) 504 505 /** 506 * DRM_DEV_ERROR_RATELIMITED() - Rate limited error output. 507 * 508 * NOTE: this is deprecated in favor of drm_err_ratelimited() or 509 * dev_err_ratelimited(). 510 * 511 * @dev: device pointer 512 * @fmt: printf() like format string. 513 * 514 * Like DRM_ERROR() but won't flood the log. 515 */ 516 #define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...) \ 517 ({ \ 518 static DEFINE_RATELIMIT_STATE(_rs, \ 519 DEFAULT_RATELIMIT_INTERVAL, \ 520 DEFAULT_RATELIMIT_BURST); \ 521 \ 522 if (__ratelimit(&_rs)) \ 523 DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__); \ 524 }) 525 526 /* NOTE: this is deprecated in favor of drm_info() or dev_info(). */ 527 #define DRM_DEV_INFO(dev, fmt, ...) \ 528 drm_dev_printk(dev, KERN_INFO, fmt, ##__VA_ARGS__) 529 530 /* NOTE: this is deprecated in favor of drm_info_once() or dev_info_once(). */ 531 #define DRM_DEV_INFO_ONCE(dev, fmt, ...) \ 532 ({ \ 533 static bool __print_once __read_mostly; \ 534 if (!__print_once) { \ 535 __print_once = true; \ 536 DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__); \ 537 } \ 538 }) 539 540 #if !defined(CONFIG_DRM_USE_DYNAMIC_DEBUG) 541 #define drm_dev_dbg(dev, cat, fmt, ...) \ 542 __drm_dev_dbg(NULL, dev, cat, fmt, ##__VA_ARGS__) 543 #else 544 #define drm_dev_dbg(dev, cat, fmt, ...) \ 545 _dynamic_func_call_cls(cat, fmt, __drm_dev_dbg, \ 546 dev, cat, fmt, ##__VA_ARGS__) 547 #endif 548 549 /** 550 * DRM_DEV_DEBUG() - Debug output for generic drm code 551 * 552 * NOTE: this is deprecated in favor of drm_dbg_core(). 553 * 554 * @dev: device pointer 555 * @fmt: printf() like format string. 556 */ 557 #define DRM_DEV_DEBUG(dev, fmt, ...) \ 558 drm_dev_dbg(dev, DRM_UT_CORE, fmt, ##__VA_ARGS__) 559 /** 560 * DRM_DEV_DEBUG_DRIVER() - Debug output for vendor specific part of the driver 561 * 562 * NOTE: this is deprecated in favor of drm_dbg() or dev_dbg(). 563 * 564 * @dev: device pointer 565 * @fmt: printf() like format string. 566 */ 567 #define DRM_DEV_DEBUG_DRIVER(dev, fmt, ...) \ 568 drm_dev_dbg(dev, DRM_UT_DRIVER, fmt, ##__VA_ARGS__) 569 /** 570 * DRM_DEV_DEBUG_KMS() - Debug output for modesetting code 571 * 572 * NOTE: this is deprecated in favor of drm_dbg_kms(). 573 * 574 * @dev: device pointer 575 * @fmt: printf() like format string. 576 */ 577 #define DRM_DEV_DEBUG_KMS(dev, fmt, ...) \ 578 drm_dev_dbg(dev, DRM_UT_KMS, fmt, ##__VA_ARGS__) 579 580 /* 581 * struct drm_device based logging 582 * 583 * Prefer drm_device based logging over device or prink based logging. 584 */ 585 586 /* Helper for struct drm_device based logging. */ 587 #define __drm_printk(drm, level, type, fmt, ...) \ 588 dev_##level##type((drm) ? (drm)->dev : NULL, "[drm] " fmt, ##__VA_ARGS__) 589 590 591 #define drm_info(drm, fmt, ...) \ 592 __drm_printk((drm), info,, fmt, ##__VA_ARGS__) 593 594 #define drm_notice(drm, fmt, ...) \ 595 __drm_printk((drm), notice,, fmt, ##__VA_ARGS__) 596 597 #define drm_warn(drm, fmt, ...) \ 598 __drm_printk((drm), warn,, fmt, ##__VA_ARGS__) 599 600 #define drm_err(drm, fmt, ...) \ 601 __drm_printk((drm), err,, "*ERROR* " fmt, ##__VA_ARGS__) 602 603 604 #define drm_info_once(drm, fmt, ...) \ 605 __drm_printk((drm), info, _once, fmt, ##__VA_ARGS__) 606 607 #define drm_notice_once(drm, fmt, ...) \ 608 __drm_printk((drm), notice, _once, fmt, ##__VA_ARGS__) 609 610 #define drm_warn_once(drm, fmt, ...) \ 611 __drm_printk((drm), warn, _once, fmt, ##__VA_ARGS__) 612 613 #define drm_err_once(drm, fmt, ...) \ 614 __drm_printk((drm), err, _once, "*ERROR* " fmt, ##__VA_ARGS__) 615 616 617 #define drm_err_ratelimited(drm, fmt, ...) \ 618 __drm_printk((drm), err, _ratelimited, "*ERROR* " fmt, ##__VA_ARGS__) 619 620 621 #define drm_dbg_core(drm, fmt, ...) \ 622 drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_CORE, fmt, ##__VA_ARGS__) 623 #define drm_dbg_driver(drm, fmt, ...) \ 624 drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_DRIVER, fmt, ##__VA_ARGS__) 625 #define drm_dbg_kms(drm, fmt, ...) \ 626 drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_KMS, fmt, ##__VA_ARGS__) 627 #define drm_dbg_prime(drm, fmt, ...) \ 628 drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_PRIME, fmt, ##__VA_ARGS__) 629 #define drm_dbg_atomic(drm, fmt, ...) \ 630 drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__) 631 #define drm_dbg_vbl(drm, fmt, ...) \ 632 drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_VBL, fmt, ##__VA_ARGS__) 633 #define drm_dbg_state(drm, fmt, ...) \ 634 drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_STATE, fmt, ##__VA_ARGS__) 635 #define drm_dbg_lease(drm, fmt, ...) \ 636 drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_LEASE, fmt, ##__VA_ARGS__) 637 #define drm_dbg_dp(drm, fmt, ...) \ 638 drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_DP, fmt, ##__VA_ARGS__) 639 #define drm_dbg_drmres(drm, fmt, ...) \ 640 drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_DRMRES, fmt, ##__VA_ARGS__) 641 642 #define drm_dbg(drm, fmt, ...) drm_dbg_driver(drm, fmt, ##__VA_ARGS__) 643 644 /* 645 * printk based logging 646 * 647 * Prefer drm_device based logging over device or prink based logging. 648 */ 649 650 __printf(1, 2) 651 void __drm_err(const char *format, ...); 652 653 #if !defined(CONFIG_DRM_USE_DYNAMIC_DEBUG) 654 #define __drm_dbg(cat, fmt, ...) __drm_dev_dbg(NULL, NULL, cat, fmt, ##__VA_ARGS__) 655 #else 656 #define __drm_dbg(cat, fmt, ...) \ 657 _dynamic_func_call_cls(cat, fmt, __drm_dev_dbg, \ 658 NULL, cat, fmt, ##__VA_ARGS__) 659 #endif 660 661 /* Macros to make printk easier */ 662 663 #define _DRM_PRINTK(once, level, fmt, ...) \ 664 printk##once(KERN_##level "[" DRM_NAME "] " fmt, ##__VA_ARGS__) 665 666 /* NOTE: this is deprecated in favor of pr_info(). */ 667 #define DRM_INFO(fmt, ...) \ 668 _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__) 669 /* NOTE: this is deprecated in favor of pr_notice(). */ 670 #define DRM_NOTE(fmt, ...) \ 671 _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__) 672 /* NOTE: this is deprecated in favor of pr_warn(). */ 673 #define DRM_WARN(fmt, ...) \ 674 _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__) 675 676 /* NOTE: this is deprecated in favor of pr_info_once(). */ 677 #define DRM_INFO_ONCE(fmt, ...) \ 678 _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__) 679 /* NOTE: this is deprecated in favor of pr_notice_once(). */ 680 #define DRM_NOTE_ONCE(fmt, ...) \ 681 _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__) 682 /* NOTE: this is deprecated in favor of pr_warn_once(). */ 683 #define DRM_WARN_ONCE(fmt, ...) \ 684 _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__) 685 686 /* NOTE: this is deprecated in favor of pr_err(). */ 687 #define DRM_ERROR(fmt, ...) \ 688 __drm_err(fmt, ##__VA_ARGS__) 689 690 /* NOTE: this is deprecated in favor of pr_err_ratelimited(). */ 691 #define DRM_ERROR_RATELIMITED(fmt, ...) \ 692 DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__) 693 694 /* NOTE: this is deprecated in favor of drm_dbg_core(NULL, ...). */ 695 #define DRM_DEBUG(fmt, ...) \ 696 __drm_dbg(DRM_UT_CORE, fmt, ##__VA_ARGS__) 697 698 /* NOTE: this is deprecated in favor of drm_dbg(NULL, ...). */ 699 #define DRM_DEBUG_DRIVER(fmt, ...) \ 700 __drm_dbg(DRM_UT_DRIVER, fmt, ##__VA_ARGS__) 701 702 /* NOTE: this is deprecated in favor of drm_dbg_kms(NULL, ...). */ 703 #define DRM_DEBUG_KMS(fmt, ...) \ 704 __drm_dbg(DRM_UT_KMS, fmt, ##__VA_ARGS__) 705 706 /* NOTE: this is deprecated in favor of drm_dbg_prime(NULL, ...). */ 707 #define DRM_DEBUG_PRIME(fmt, ...) \ 708 __drm_dbg(DRM_UT_PRIME, fmt, ##__VA_ARGS__) 709 710 /* NOTE: this is deprecated in favor of drm_dbg_atomic(NULL, ...). */ 711 #define DRM_DEBUG_ATOMIC(fmt, ...) \ 712 __drm_dbg(DRM_UT_ATOMIC, fmt, ##__VA_ARGS__) 713 714 /* NOTE: this is deprecated in favor of drm_dbg_vbl(NULL, ...). */ 715 #define DRM_DEBUG_VBL(fmt, ...) \ 716 __drm_dbg(DRM_UT_VBL, fmt, ##__VA_ARGS__) 717 718 /* NOTE: this is deprecated in favor of drm_dbg_lease(NULL, ...). */ 719 #define DRM_DEBUG_LEASE(fmt, ...) \ 720 __drm_dbg(DRM_UT_LEASE, fmt, ##__VA_ARGS__) 721 722 /* NOTE: this is deprecated in favor of drm_dbg_dp(NULL, ...). */ 723 #define DRM_DEBUG_DP(fmt, ...) \ 724 __drm_dbg(DRM_UT_DP, fmt, ## __VA_ARGS__) 725 726 #define __DRM_DEFINE_DBG_RATELIMITED(category, drm, fmt, ...) \ 727 ({ \ 728 static DEFINE_RATELIMIT_STATE(rs_, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST);\ 729 const struct drm_device *drm_ = (drm); \ 730 \ 731 if (drm_debug_enabled(DRM_UT_ ## category) && __ratelimit(&rs_)) \ 732 drm_dev_printk(drm_ ? drm_->dev : NULL, KERN_DEBUG, fmt, ## __VA_ARGS__); \ 733 }) 734 735 #define drm_dbg_ratelimited(drm, fmt, ...) \ 736 __DRM_DEFINE_DBG_RATELIMITED(DRIVER, drm, fmt, ## __VA_ARGS__) 737 738 #define drm_dbg_kms_ratelimited(drm, fmt, ...) \ 739 __DRM_DEFINE_DBG_RATELIMITED(KMS, drm, fmt, ## __VA_ARGS__) 740 741 /* 742 * struct drm_device based WARNs 743 * 744 * drm_WARN*() acts like WARN*(), but with the key difference of 745 * using device specific information so that we know from which device 746 * warning is originating from. 747 * 748 * Prefer drm_device based drm_WARN* over regular WARN* 749 */ 750 751 /* Helper for struct drm_device based WARNs */ 752 #define drm_WARN(drm, condition, format, arg...) \ 753 WARN(condition, "%s %s: [drm] " format, \ 754 dev_driver_string((drm)->dev), \ 755 dev_name((drm)->dev), ## arg) 756 757 #define drm_WARN_ONCE(drm, condition, format, arg...) \ 758 WARN_ONCE(condition, "%s %s: [drm] " format, \ 759 dev_driver_string((drm)->dev), \ 760 dev_name((drm)->dev), ## arg) 761 762 #define drm_WARN_ON(drm, x) \ 763 drm_WARN((drm), (x), "%s", \ 764 "drm_WARN_ON(" __stringify(x) ")") 765 766 #define drm_WARN_ON_ONCE(drm, x) \ 767 drm_WARN_ONCE((drm), (x), "%s", \ 768 "drm_WARN_ON_ONCE(" __stringify(x) ")") 769 770 #endif /* DRM_PRINT_H_ */ 771