drm_print.h 19 KB

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