Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (C) 2016 Red Hat
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors:
0023  * Rob Clark <robdclark@gmail.com>
0024  */
0025 
0026 #ifndef DRM_PRINT_H_
0027 #define DRM_PRINT_H_
0028 
0029 #include <linux/compiler.h>
0030 #include <linux/printk.h>
0031 #include <linux/seq_file.h>
0032 #include <linux/device.h>
0033 #include <linux/debugfs.h>
0034 
0035 #include <drm/drm.h>
0036 
0037 /* Do *not* use outside of drm_print.[ch]! */
0038 extern unsigned int __drm_debug;
0039 
0040 /**
0041  * DOC: print
0042  *
0043  * A simple wrapper for dev_printk(), seq_printf(), etc.  Allows same
0044  * debug code to be used for both debugfs and printk logging.
0045  *
0046  * For example::
0047  *
0048  *     void log_some_info(struct drm_printer *p)
0049  *     {
0050  *             drm_printf(p, "foo=%d\n", foo);
0051  *             drm_printf(p, "bar=%d\n", bar);
0052  *     }
0053  *
0054  *     #ifdef CONFIG_DEBUG_FS
0055  *     void debugfs_show(struct seq_file *f)
0056  *     {
0057  *             struct drm_printer p = drm_seq_file_printer(f);
0058  *             log_some_info(&p);
0059  *     }
0060  *     #endif
0061  *
0062  *     void some_other_function(...)
0063  *     {
0064  *             struct drm_printer p = drm_info_printer(drm->dev);
0065  *             log_some_info(&p);
0066  *     }
0067  */
0068 
0069 /**
0070  * struct drm_printer - drm output "stream"
0071  *
0072  * Do not use struct members directly.  Use drm_printer_seq_file(),
0073  * drm_printer_info(), etc to initialize.  And drm_printf() for output.
0074  */
0075 struct drm_printer {
0076     /* private: */
0077     void (*printfn)(struct drm_printer *p, struct va_format *vaf);
0078     void (*puts)(struct drm_printer *p, const char *str);
0079     void *arg;
0080     const char *prefix;
0081 };
0082 
0083 void __drm_printfn_coredump(struct drm_printer *p, struct va_format *vaf);
0084 void __drm_puts_coredump(struct drm_printer *p, const char *str);
0085 void __drm_printfn_seq_file(struct drm_printer *p, struct va_format *vaf);
0086 void __drm_puts_seq_file(struct drm_printer *p, const char *str);
0087 void __drm_printfn_info(struct drm_printer *p, struct va_format *vaf);
0088 void __drm_printfn_debug(struct drm_printer *p, struct va_format *vaf);
0089 void __drm_printfn_err(struct drm_printer *p, struct va_format *vaf);
0090 
0091 __printf(2, 3)
0092 void drm_printf(struct drm_printer *p, const char *f, ...);
0093 void drm_puts(struct drm_printer *p, const char *str);
0094 void drm_print_regset32(struct drm_printer *p, struct debugfs_regset32 *regset);
0095 void drm_print_bits(struct drm_printer *p, unsigned long value,
0096             const char * const bits[], unsigned int nbits);
0097 
0098 __printf(2, 0)
0099 /**
0100  * drm_vprintf - print to a &drm_printer stream
0101  * @p: the &drm_printer
0102  * @fmt: format string
0103  * @va: the va_list
0104  */
0105 static inline void
0106 drm_vprintf(struct drm_printer *p, const char *fmt, va_list *va)
0107 {
0108     struct va_format vaf = { .fmt = fmt, .va = va };
0109 
0110     p->printfn(p, &vaf);
0111 }
0112 
0113 /**
0114  * drm_printf_indent - Print to a &drm_printer stream with indentation
0115  * @printer: DRM printer
0116  * @indent: Tab indentation level (max 5)
0117  * @fmt: Format string
0118  */
0119 #define drm_printf_indent(printer, indent, fmt, ...) \
0120     drm_printf((printer), "%.*s" fmt, (indent), "\t\t\t\t\tX", ##__VA_ARGS__)
0121 
0122 /**
0123  * struct drm_print_iterator - local struct used with drm_printer_coredump
0124  * @data: Pointer to the devcoredump output buffer
0125  * @start: The offset within the buffer to start writing
0126  * @remain: The number of bytes to write for this iteration
0127  */
0128 struct drm_print_iterator {
0129     void *data;
0130     ssize_t start;
0131     ssize_t remain;
0132     /* private: */
0133     ssize_t offset;
0134 };
0135 
0136 /**
0137  * drm_coredump_printer - construct a &drm_printer that can output to a buffer
0138  * from the read function for devcoredump
0139  * @iter: A pointer to a struct drm_print_iterator for the read instance
0140  *
0141  * This wrapper extends drm_printf() to work with a dev_coredumpm() callback
0142  * function. The passed in drm_print_iterator struct contains the buffer
0143  * pointer, size and offset as passed in from devcoredump.
0144  *
0145  * For example::
0146  *
0147  *  void coredump_read(char *buffer, loff_t offset, size_t count,
0148  *      void *data, size_t datalen)
0149  *  {
0150  *      struct drm_print_iterator iter;
0151  *      struct drm_printer p;
0152  *
0153  *      iter.data = buffer;
0154  *      iter.start = offset;
0155  *      iter.remain = count;
0156  *
0157  *      p = drm_coredump_printer(&iter);
0158  *
0159  *      drm_printf(p, "foo=%d\n", foo);
0160  *  }
0161  *
0162  *  void makecoredump(...)
0163  *  {
0164  *      ...
0165  *      dev_coredumpm(dev, THIS_MODULE, data, 0, GFP_KERNEL,
0166  *          coredump_read, ...)
0167  *  }
0168  *
0169  * RETURNS:
0170  * The &drm_printer object
0171  */
0172 static inline struct drm_printer
0173 drm_coredump_printer(struct drm_print_iterator *iter)
0174 {
0175     struct drm_printer p = {
0176         .printfn = __drm_printfn_coredump,
0177         .puts = __drm_puts_coredump,
0178         .arg = iter,
0179     };
0180 
0181     /* Set the internal offset of the iterator to zero */
0182     iter->offset = 0;
0183 
0184     return p;
0185 }
0186 
0187 /**
0188  * drm_seq_file_printer - construct a &drm_printer that outputs to &seq_file
0189  * @f:  the &struct seq_file to output to
0190  *
0191  * RETURNS:
0192  * The &drm_printer object
0193  */
0194 static inline struct drm_printer drm_seq_file_printer(struct seq_file *f)
0195 {
0196     struct drm_printer p = {
0197         .printfn = __drm_printfn_seq_file,
0198         .puts = __drm_puts_seq_file,
0199         .arg = f,
0200     };
0201     return p;
0202 }
0203 
0204 /**
0205  * drm_info_printer - construct a &drm_printer that outputs to dev_printk()
0206  * @dev: the &struct device pointer
0207  *
0208  * RETURNS:
0209  * The &drm_printer object
0210  */
0211 static inline struct drm_printer drm_info_printer(struct device *dev)
0212 {
0213     struct drm_printer p = {
0214         .printfn = __drm_printfn_info,
0215         .arg = dev,
0216     };
0217     return p;
0218 }
0219 
0220 /**
0221  * drm_debug_printer - construct a &drm_printer that outputs to pr_debug()
0222  * @prefix: debug output prefix
0223  *
0224  * RETURNS:
0225  * The &drm_printer object
0226  */
0227 static inline struct drm_printer drm_debug_printer(const char *prefix)
0228 {
0229     struct drm_printer p = {
0230         .printfn = __drm_printfn_debug,
0231         .prefix = prefix
0232     };
0233     return p;
0234 }
0235 
0236 /**
0237  * drm_err_printer - construct a &drm_printer that outputs to pr_err()
0238  * @prefix: debug output prefix
0239  *
0240  * RETURNS:
0241  * The &drm_printer object
0242  */
0243 static inline struct drm_printer drm_err_printer(const char *prefix)
0244 {
0245     struct drm_printer p = {
0246         .printfn = __drm_printfn_err,
0247         .prefix = prefix
0248     };
0249     return p;
0250 }
0251 
0252 /**
0253  * enum drm_debug_category - The DRM debug categories
0254  *
0255  * Each of the DRM debug logging macros use a specific category, and the logging
0256  * is filtered by the drm.debug module parameter. This enum specifies the values
0257  * for the interface.
0258  *
0259  * Each DRM_DEBUG_<CATEGORY> macro logs to DRM_UT_<CATEGORY> category, except
0260  * DRM_DEBUG() logs to DRM_UT_CORE.
0261  *
0262  * Enabling verbose debug messages is done through the drm.debug parameter, each
0263  * category being enabled by a bit:
0264  *
0265  *  - drm.debug=0x1 will enable CORE messages
0266  *  - drm.debug=0x2 will enable DRIVER messages
0267  *  - drm.debug=0x3 will enable CORE and DRIVER messages
0268  *  - ...
0269  *  - drm.debug=0x1ff will enable all messages
0270  *
0271  * An interesting feature is that it's possible to enable verbose logging at
0272  * run-time by echoing the debug value in its sysfs node::
0273  *
0274  *   # echo 0xf > /sys/module/drm/parameters/debug
0275  *
0276  */
0277 enum drm_debug_category {
0278     /**
0279      * @DRM_UT_CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c,
0280      * drm_memory.c, ...
0281      */
0282     DRM_UT_CORE     = 0x01,
0283     /**
0284      * @DRM_UT_DRIVER: Used in the vendor specific part of the driver: i915,
0285      * radeon, ... macro.
0286      */
0287     DRM_UT_DRIVER       = 0x02,
0288     /**
0289      * @DRM_UT_KMS: Used in the modesetting code.
0290      */
0291     DRM_UT_KMS      = 0x04,
0292     /**
0293      * @DRM_UT_PRIME: Used in the prime code.
0294      */
0295     DRM_UT_PRIME        = 0x08,
0296     /**
0297      * @DRM_UT_ATOMIC: Used in the atomic code.
0298      */
0299     DRM_UT_ATOMIC       = 0x10,
0300     /**
0301      * @DRM_UT_VBL: Used for verbose debug message in the vblank code.
0302      */
0303     DRM_UT_VBL      = 0x20,
0304     /**
0305      * @DRM_UT_STATE: Used for verbose atomic state debugging.
0306      */
0307     DRM_UT_STATE        = 0x40,
0308     /**
0309      * @DRM_UT_LEASE: Used in the lease code.
0310      */
0311     DRM_UT_LEASE        = 0x80,
0312     /**
0313      * @DRM_UT_DP: Used in the DP code.
0314      */
0315     DRM_UT_DP       = 0x100,
0316     /**
0317      * @DRM_UT_DRMRES: Used in the drm managed resources code.
0318      */
0319     DRM_UT_DRMRES       = 0x200,
0320 };
0321 
0322 static inline bool drm_debug_enabled(enum drm_debug_category category)
0323 {
0324     return unlikely(__drm_debug & category);
0325 }
0326 
0327 /*
0328  * struct device based logging
0329  *
0330  * Prefer drm_device based logging over device or printk based logging.
0331  */
0332 
0333 __printf(3, 4)
0334 void drm_dev_printk(const struct device *dev, const char *level,
0335             const char *format, ...);
0336 __printf(3, 4)
0337 void drm_dev_dbg(const struct device *dev, enum drm_debug_category category,
0338          const char *format, ...);
0339 
0340 /**
0341  * DRM_DEV_ERROR() - Error output.
0342  *
0343  * NOTE: this is deprecated in favor of drm_err() or dev_err().
0344  *
0345  * @dev: device pointer
0346  * @fmt: printf() like format string.
0347  */
0348 #define DRM_DEV_ERROR(dev, fmt, ...)                    \
0349     drm_dev_printk(dev, KERN_ERR, "*ERROR* " fmt, ##__VA_ARGS__)
0350 
0351 /**
0352  * DRM_DEV_ERROR_RATELIMITED() - Rate limited error output.
0353  *
0354  * NOTE: this is deprecated in favor of drm_err_ratelimited() or
0355  * dev_err_ratelimited().
0356  *
0357  * @dev: device pointer
0358  * @fmt: printf() like format string.
0359  *
0360  * Like DRM_ERROR() but won't flood the log.
0361  */
0362 #define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...)            \
0363 ({                                  \
0364     static DEFINE_RATELIMIT_STATE(_rs,              \
0365                       DEFAULT_RATELIMIT_INTERVAL,   \
0366                       DEFAULT_RATELIMIT_BURST);     \
0367                                     \
0368     if (__ratelimit(&_rs))                      \
0369         DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__);         \
0370 })
0371 
0372 /* NOTE: this is deprecated in favor of drm_info() or dev_info(). */
0373 #define DRM_DEV_INFO(dev, fmt, ...)             \
0374     drm_dev_printk(dev, KERN_INFO, fmt, ##__VA_ARGS__)
0375 
0376 /* NOTE: this is deprecated in favor of drm_info_once() or dev_info_once(). */
0377 #define DRM_DEV_INFO_ONCE(dev, fmt, ...)                \
0378 ({                                  \
0379     static bool __print_once __read_mostly;             \
0380     if (!__print_once) {                        \
0381         __print_once = true;                    \
0382         DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__);          \
0383     }                               \
0384 })
0385 
0386 /**
0387  * DRM_DEV_DEBUG() - Debug output for generic drm code
0388  *
0389  * NOTE: this is deprecated in favor of drm_dbg_core().
0390  *
0391  * @dev: device pointer
0392  * @fmt: printf() like format string.
0393  */
0394 #define DRM_DEV_DEBUG(dev, fmt, ...)                    \
0395     drm_dev_dbg(dev, DRM_UT_CORE, fmt, ##__VA_ARGS__)
0396 /**
0397  * DRM_DEV_DEBUG_DRIVER() - Debug output for vendor specific part of the driver
0398  *
0399  * NOTE: this is deprecated in favor of drm_dbg() or dev_dbg().
0400  *
0401  * @dev: device pointer
0402  * @fmt: printf() like format string.
0403  */
0404 #define DRM_DEV_DEBUG_DRIVER(dev, fmt, ...)             \
0405     drm_dev_dbg(dev, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
0406 /**
0407  * DRM_DEV_DEBUG_KMS() - Debug output for modesetting code
0408  *
0409  * NOTE: this is deprecated in favor of drm_dbg_kms().
0410  *
0411  * @dev: device pointer
0412  * @fmt: printf() like format string.
0413  */
0414 #define DRM_DEV_DEBUG_KMS(dev, fmt, ...)                \
0415     drm_dev_dbg(dev, DRM_UT_KMS, fmt, ##__VA_ARGS__)
0416 
0417 /*
0418  * struct drm_device based logging
0419  *
0420  * Prefer drm_device based logging over device or prink based logging.
0421  */
0422 
0423 /* Helper for struct drm_device based logging. */
0424 #define __drm_printk(drm, level, type, fmt, ...)            \
0425     dev_##level##type((drm)->dev, "[drm] " fmt, ##__VA_ARGS__)
0426 
0427 
0428 #define drm_info(drm, fmt, ...)                 \
0429     __drm_printk((drm), info,, fmt, ##__VA_ARGS__)
0430 
0431 #define drm_notice(drm, fmt, ...)               \
0432     __drm_printk((drm), notice,, fmt, ##__VA_ARGS__)
0433 
0434 #define drm_warn(drm, fmt, ...)                 \
0435     __drm_printk((drm), warn,, fmt, ##__VA_ARGS__)
0436 
0437 #define drm_err(drm, fmt, ...)                  \
0438     __drm_printk((drm), err,, "*ERROR* " fmt, ##__VA_ARGS__)
0439 
0440 
0441 #define drm_info_once(drm, fmt, ...)                \
0442     __drm_printk((drm), info, _once, fmt, ##__VA_ARGS__)
0443 
0444 #define drm_notice_once(drm, fmt, ...)              \
0445     __drm_printk((drm), notice, _once, fmt, ##__VA_ARGS__)
0446 
0447 #define drm_warn_once(drm, fmt, ...)                \
0448     __drm_printk((drm), warn, _once, fmt, ##__VA_ARGS__)
0449 
0450 #define drm_err_once(drm, fmt, ...)             \
0451     __drm_printk((drm), err, _once, "*ERROR* " fmt, ##__VA_ARGS__)
0452 
0453 
0454 #define drm_err_ratelimited(drm, fmt, ...)              \
0455     __drm_printk((drm), err, _ratelimited, "*ERROR* " fmt, ##__VA_ARGS__)
0456 
0457 
0458 #define drm_dbg_core(drm, fmt, ...)                 \
0459     drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_CORE, fmt, ##__VA_ARGS__)
0460 #define drm_dbg(drm, fmt, ...)                      \
0461     drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
0462 #define drm_dbg_kms(drm, fmt, ...)                  \
0463     drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_KMS, fmt, ##__VA_ARGS__)
0464 #define drm_dbg_prime(drm, fmt, ...)                    \
0465     drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_PRIME, fmt, ##__VA_ARGS__)
0466 #define drm_dbg_atomic(drm, fmt, ...)                   \
0467     drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
0468 #define drm_dbg_vbl(drm, fmt, ...)                  \
0469     drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_VBL, fmt, ##__VA_ARGS__)
0470 #define drm_dbg_state(drm, fmt, ...)                    \
0471     drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_STATE, fmt, ##__VA_ARGS__)
0472 #define drm_dbg_lease(drm, fmt, ...)                    \
0473     drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_LEASE, fmt, ##__VA_ARGS__)
0474 #define drm_dbg_dp(drm, fmt, ...)                   \
0475     drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_DP, fmt, ##__VA_ARGS__)
0476 #define drm_dbg_drmres(drm, fmt, ...)                   \
0477     drm_dev_dbg((drm) ? (drm)->dev : NULL, DRM_UT_DRMRES, fmt, ##__VA_ARGS__)
0478 
0479 
0480 /*
0481  * printk based logging
0482  *
0483  * Prefer drm_device based logging over device or prink based logging.
0484  */
0485 
0486 __printf(2, 3)
0487 void __drm_dbg(enum drm_debug_category category, const char *format, ...);
0488 __printf(1, 2)
0489 void __drm_err(const char *format, ...);
0490 
0491 /* Macros to make printk easier */
0492 
0493 #define _DRM_PRINTK(once, level, fmt, ...)              \
0494     printk##once(KERN_##level "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
0495 
0496 /* NOTE: this is deprecated in favor of pr_info(). */
0497 #define DRM_INFO(fmt, ...)                      \
0498     _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
0499 /* NOTE: this is deprecated in favor of pr_notice(). */
0500 #define DRM_NOTE(fmt, ...)                      \
0501     _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
0502 /* NOTE: this is deprecated in favor of pr_warn(). */
0503 #define DRM_WARN(fmt, ...)                      \
0504     _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
0505 
0506 /* NOTE: this is deprecated in favor of pr_info_once(). */
0507 #define DRM_INFO_ONCE(fmt, ...)                     \
0508     _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
0509 /* NOTE: this is deprecated in favor of pr_notice_once(). */
0510 #define DRM_NOTE_ONCE(fmt, ...)                     \
0511     _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
0512 /* NOTE: this is deprecated in favor of pr_warn_once(). */
0513 #define DRM_WARN_ONCE(fmt, ...)                     \
0514     _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
0515 
0516 /* NOTE: this is deprecated in favor of pr_err(). */
0517 #define DRM_ERROR(fmt, ...)                     \
0518     __drm_err(fmt, ##__VA_ARGS__)
0519 
0520 /* NOTE: this is deprecated in favor of pr_err_ratelimited(). */
0521 #define DRM_ERROR_RATELIMITED(fmt, ...)                 \
0522     DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__)
0523 
0524 /* NOTE: this is deprecated in favor of drm_dbg_core(NULL, ...). */
0525 #define DRM_DEBUG(fmt, ...)                     \
0526     __drm_dbg(DRM_UT_CORE, fmt, ##__VA_ARGS__)
0527 
0528 /* NOTE: this is deprecated in favor of drm_dbg(NULL, ...). */
0529 #define DRM_DEBUG_DRIVER(fmt, ...)                  \
0530     __drm_dbg(DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
0531 
0532 /* NOTE: this is deprecated in favor of drm_dbg_kms(NULL, ...). */
0533 #define DRM_DEBUG_KMS(fmt, ...)                     \
0534     __drm_dbg(DRM_UT_KMS, fmt, ##__VA_ARGS__)
0535 
0536 /* NOTE: this is deprecated in favor of drm_dbg_prime(NULL, ...). */
0537 #define DRM_DEBUG_PRIME(fmt, ...)                   \
0538     __drm_dbg(DRM_UT_PRIME, fmt, ##__VA_ARGS__)
0539 
0540 /* NOTE: this is deprecated in favor of drm_dbg_atomic(NULL, ...). */
0541 #define DRM_DEBUG_ATOMIC(fmt, ...)                  \
0542     __drm_dbg(DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
0543 
0544 /* NOTE: this is deprecated in favor of drm_dbg_vbl(NULL, ...). */
0545 #define DRM_DEBUG_VBL(fmt, ...)                     \
0546     __drm_dbg(DRM_UT_VBL, fmt, ##__VA_ARGS__)
0547 
0548 /* NOTE: this is deprecated in favor of drm_dbg_lease(NULL, ...). */
0549 #define DRM_DEBUG_LEASE(fmt, ...)                   \
0550     __drm_dbg(DRM_UT_LEASE, fmt, ##__VA_ARGS__)
0551 
0552 /* NOTE: this is deprecated in favor of drm_dbg_dp(NULL, ...). */
0553 #define DRM_DEBUG_DP(fmt, ...)                      \
0554     __drm_dbg(DRM_UT_DP, fmt, ## __VA_ARGS__)
0555 
0556 #define __DRM_DEFINE_DBG_RATELIMITED(category, drm, fmt, ...)                   \
0557 ({                                              \
0558     static DEFINE_RATELIMIT_STATE(rs_, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST);\
0559     const struct drm_device *drm_ = (drm);                          \
0560                                                 \
0561     if (drm_debug_enabled(DRM_UT_ ## category) && __ratelimit(&rs_))            \
0562         drm_dev_printk(drm_ ? drm_->dev : NULL, KERN_DEBUG, fmt, ## __VA_ARGS__);   \
0563 })
0564 
0565 #define drm_dbg_kms_ratelimited(drm, fmt, ...) \
0566     __DRM_DEFINE_DBG_RATELIMITED(KMS, drm, fmt, ## __VA_ARGS__)
0567 
0568 /* NOTE: this is deprecated in favor of drm_dbg_kms_ratelimited(NULL, ...). */
0569 #define DRM_DEBUG_KMS_RATELIMITED(fmt, ...) drm_dbg_kms_ratelimited(NULL, fmt, ## __VA_ARGS__)
0570 
0571 /*
0572  * struct drm_device based WARNs
0573  *
0574  * drm_WARN*() acts like WARN*(), but with the key difference of
0575  * using device specific information so that we know from which device
0576  * warning is originating from.
0577  *
0578  * Prefer drm_device based drm_WARN* over regular WARN*
0579  */
0580 
0581 /* Helper for struct drm_device based WARNs */
0582 #define drm_WARN(drm, condition, format, arg...)            \
0583     WARN(condition, "%s %s: " format,               \
0584             dev_driver_string((drm)->dev),          \
0585             dev_name((drm)->dev), ## arg)
0586 
0587 #define drm_WARN_ONCE(drm, condition, format, arg...)           \
0588     WARN_ONCE(condition, "%s %s: " format,              \
0589             dev_driver_string((drm)->dev),          \
0590             dev_name((drm)->dev), ## arg)
0591 
0592 #define drm_WARN_ON(drm, x)                     \
0593     drm_WARN((drm), (x), "%s",                  \
0594          "drm_WARN_ON(" __stringify(x) ")")
0595 
0596 #define drm_WARN_ON_ONCE(drm, x)                    \
0597     drm_WARN_ONCE((drm), (x), "%s",                 \
0598               "drm_WARN_ON_ONCE(" __stringify(x) ")")
0599 
0600 #endif /* DRM_PRINT_H_ */