drm_print.h 21 KB

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