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