1 /* 1 /* 2 * Copyright (C) 2016 Red Hat 2 * Copyright (C) 2016 Red Hat 3 * 3 * 4 * Permission is hereby granted, free of charg 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated docume 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, pub 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to 9 * Software is furnished to do so, subject to the following conditions: 10 * 10 * 11 * The above copyright notice and this permiss 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the S 12 * all copies or substantial portions of the Software. 13 * 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT W 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE W 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINF 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIA 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CO 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 20 * OTHER DEALINGS IN THE SOFTWARE. 21 * 21 * 22 * Authors: 22 * Authors: 23 * Rob Clark <robdclark@gmail.com> 23 * Rob Clark <robdclark@gmail.com> 24 */ 24 */ 25 25 26 #ifndef DRM_PRINT_H_ 26 #ifndef DRM_PRINT_H_ 27 #define DRM_PRINT_H_ 27 #define DRM_PRINT_H_ 28 28 29 #include <linux/compiler.h> 29 #include <linux/compiler.h> 30 #include <linux/printk.h> 30 #include <linux/printk.h> >> 31 #include <linux/seq_file.h> 31 #include <linux/device.h> 32 #include <linux/device.h> 32 #include <linux/dynamic_debug.h> !! 33 #include <linux/debugfs.h> 33 34 34 #include <drm/drm.h> 35 #include <drm/drm.h> 35 36 36 struct debugfs_regset32; << 37 struct drm_device; << 38 struct seq_file; << 39 << 40 /* Do *not* use outside of drm_print.[ch]! */ 37 /* Do *not* use outside of drm_print.[ch]! */ 41 extern unsigned long __drm_debug; !! 38 extern unsigned int __drm_debug; 42 39 43 /** 40 /** 44 * DOC: print 41 * DOC: print 45 * 42 * 46 * A simple wrapper for dev_printk(), seq_prin 43 * A simple wrapper for dev_printk(), seq_printf(), etc. Allows same 47 * debug code to be used for both debugfs and 44 * debug code to be used for both debugfs and printk logging. 48 * 45 * 49 * For example:: 46 * For example:: 50 * 47 * 51 * void log_some_info(struct drm_printer * 48 * void log_some_info(struct drm_printer *p) 52 * { 49 * { 53 * drm_printf(p, "foo=%d\n", foo); 50 * drm_printf(p, "foo=%d\n", foo); 54 * drm_printf(p, "bar=%d\n", bar); 51 * drm_printf(p, "bar=%d\n", bar); 55 * } 52 * } 56 * 53 * 57 * #ifdef CONFIG_DEBUG_FS 54 * #ifdef CONFIG_DEBUG_FS 58 * void debugfs_show(struct seq_file *f) 55 * void debugfs_show(struct seq_file *f) 59 * { 56 * { 60 * struct drm_printer p = drm_seq_ 57 * struct drm_printer p = drm_seq_file_printer(f); 61 * log_some_info(&p); 58 * log_some_info(&p); 62 * } 59 * } 63 * #endif 60 * #endif 64 * 61 * 65 * void some_other_function(...) 62 * void some_other_function(...) 66 * { 63 * { 67 * struct drm_printer p = drm_info 64 * struct drm_printer p = drm_info_printer(drm->dev); 68 * log_some_info(&p); 65 * log_some_info(&p); 69 * } 66 * } 70 */ 67 */ 71 68 72 /** 69 /** 73 * enum drm_debug_category - The DRM debug cat << 74 * << 75 * Each of the DRM debug logging macros use a << 76 * is filtered by the drm.debug module paramet << 77 * for the interface. << 78 * << 79 * Each DRM_DEBUG_<CATEGORY> macro logs to DRM << 80 * DRM_DEBUG() logs to DRM_UT_CORE. << 81 * << 82 * Enabling verbose debug messages is done thr << 83 * category being enabled by a bit: << 84 * << 85 * - drm.debug=0x1 will enable CORE messages << 86 * - drm.debug=0x2 will enable DRIVER message << 87 * - drm.debug=0x3 will enable CORE and DRIVE << 88 * - ... << 89 * - drm.debug=0x1ff will enable all messages << 90 * << 91 * An interesting feature is that it's possibl << 92 * run-time by echoing the debug value in its << 93 * << 94 * # echo 0xf > /sys/module/drm/parameters/d << 95 * << 96 */ << 97 enum drm_debug_category { << 98 /* These names must match those in DYN << 99 /** << 100 * @DRM_UT_CORE: Used in the generic d << 101 * drm_memory.c, ... << 102 */ << 103 DRM_UT_CORE, << 104 /** << 105 * @DRM_UT_DRIVER: Used in the vendor << 106 * radeon, ... macro. << 107 */ << 108 DRM_UT_DRIVER, << 109 /** << 110 * @DRM_UT_KMS: Used in the modesettin << 111 */ << 112 DRM_UT_KMS, << 113 /** << 114 * @DRM_UT_PRIME: Used in the prime co << 115 */ << 116 DRM_UT_PRIME, << 117 /** << 118 * @DRM_UT_ATOMIC: Used in the atomic << 119 */ << 120 DRM_UT_ATOMIC, << 121 /** << 122 * @DRM_UT_VBL: Used for verbose debug << 123 */ << 124 DRM_UT_VBL, << 125 /** << 126 * @DRM_UT_STATE: Used for verbose ato << 127 */ << 128 DRM_UT_STATE, << 129 /** << 130 * @DRM_UT_LEASE: Used in the lease co << 131 */ << 132 DRM_UT_LEASE, << 133 /** << 134 * @DRM_UT_DP: Used in the DP code. << 135 */ << 136 DRM_UT_DP, << 137 /** << 138 * @DRM_UT_DRMRES: Used in the drm man << 139 */ << 140 DRM_UT_DRMRES << 141 }; << 142 << 143 static inline bool drm_debug_enabled_raw(enum << 144 { << 145 return unlikely(__drm_debug & BIT(cate << 146 } << 147 << 148 #define drm_debug_enabled_instrumented(categor << 149 ({ << 150 pr_debug("todo: is this freque << 151 drm_debug_enabled_raw(category << 152 }) << 153 << 154 #if defined(CONFIG_DRM_USE_DYNAMIC_DEBUG) << 155 /* << 156 * the drm.debug API uses dyndbg, so each drm_ << 157 * a descriptor, and only enabled callsites ar << 158 * the private macro to avoid re-testing the e << 159 */ << 160 #define __drm_debug_enabled(category) true << 161 #define drm_debug_enabled(category) drm_de << 162 #else << 163 #define __drm_debug_enabled(category) drm_de << 164 #define drm_debug_enabled(category) drm_de << 165 #endif << 166 << 167 /** << 168 * struct drm_printer - drm output "stream" 70 * struct drm_printer - drm output "stream" 169 * 71 * 170 * Do not use struct members directly. Use dr 72 * Do not use struct members directly. Use drm_printer_seq_file(), 171 * drm_printer_info(), etc to initialize. And 73 * drm_printer_info(), etc to initialize. And drm_printf() for output. 172 */ 74 */ 173 struct drm_printer { 75 struct drm_printer { 174 /* private: */ 76 /* private: */ 175 void (*printfn)(struct drm_printer *p, 77 void (*printfn)(struct drm_printer *p, struct va_format *vaf); 176 void (*puts)(struct drm_printer *p, co 78 void (*puts)(struct drm_printer *p, const char *str); 177 void *arg; 79 void *arg; 178 const void *origin; << 179 const char *prefix; 80 const char *prefix; 180 enum drm_debug_category category; << 181 }; 81 }; 182 82 183 void __drm_printfn_coredump(struct drm_printer 83 void __drm_printfn_coredump(struct drm_printer *p, struct va_format *vaf); 184 void __drm_puts_coredump(struct drm_printer *p 84 void __drm_puts_coredump(struct drm_printer *p, const char *str); 185 void __drm_printfn_seq_file(struct drm_printer 85 void __drm_printfn_seq_file(struct drm_printer *p, struct va_format *vaf); 186 void __drm_puts_seq_file(struct drm_printer *p 86 void __drm_puts_seq_file(struct drm_printer *p, const char *str); 187 void __drm_printfn_info(struct drm_printer *p, 87 void __drm_printfn_info(struct drm_printer *p, struct va_format *vaf); 188 void __drm_printfn_dbg(struct drm_printer *p, !! 88 void __drm_printfn_debug(struct drm_printer *p, struct va_format *vaf); 189 void __drm_printfn_err(struct drm_printer *p, 89 void __drm_printfn_err(struct drm_printer *p, struct va_format *vaf); 190 90 191 __printf(2, 3) 91 __printf(2, 3) 192 void drm_printf(struct drm_printer *p, const c 92 void drm_printf(struct drm_printer *p, const char *f, ...); 193 void drm_puts(struct drm_printer *p, const cha 93 void drm_puts(struct drm_printer *p, const char *str); 194 void drm_print_regset32(struct drm_printer *p, 94 void drm_print_regset32(struct drm_printer *p, struct debugfs_regset32 *regset); 195 void drm_print_bits(struct drm_printer *p, uns 95 void drm_print_bits(struct drm_printer *p, unsigned long value, 196 const char * const bits[], 96 const char * const bits[], unsigned int nbits); 197 97 198 __printf(2, 0) 98 __printf(2, 0) 199 /** 99 /** 200 * drm_vprintf - print to a &drm_printer strea 100 * drm_vprintf - print to a &drm_printer stream 201 * @p: the &drm_printer 101 * @p: the &drm_printer 202 * @fmt: format string 102 * @fmt: format string 203 * @va: the va_list 103 * @va: the va_list 204 */ 104 */ 205 static inline void 105 static inline void 206 drm_vprintf(struct drm_printer *p, const char 106 drm_vprintf(struct drm_printer *p, const char *fmt, va_list *va) 207 { 107 { 208 struct va_format vaf = { .fmt = fmt, . 108 struct va_format vaf = { .fmt = fmt, .va = va }; 209 109 210 p->printfn(p, &vaf); 110 p->printfn(p, &vaf); 211 } 111 } 212 112 213 /** 113 /** 214 * drm_printf_indent - Print to a &drm_printer 114 * drm_printf_indent - Print to a &drm_printer stream with indentation 215 * @printer: DRM printer 115 * @printer: DRM printer 216 * @indent: Tab indentation level (max 5) 116 * @indent: Tab indentation level (max 5) 217 * @fmt: Format string 117 * @fmt: Format string 218 */ 118 */ 219 #define drm_printf_indent(printer, indent, fmt 119 #define drm_printf_indent(printer, indent, fmt, ...) \ 220 drm_printf((printer), "%.*s" fmt, (ind 120 drm_printf((printer), "%.*s" fmt, (indent), "\t\t\t\t\tX", ##__VA_ARGS__) 221 121 222 /** 122 /** 223 * struct drm_print_iterator - local struct us 123 * struct drm_print_iterator - local struct used with drm_printer_coredump 224 * @data: Pointer to the devcoredump output bu 124 * @data: Pointer to the devcoredump output buffer 225 * @start: The offset within the buffer to sta 125 * @start: The offset within the buffer to start writing 226 * @remain: The number of bytes to write for t 126 * @remain: The number of bytes to write for this iteration 227 */ 127 */ 228 struct drm_print_iterator { 128 struct drm_print_iterator { 229 void *data; 129 void *data; 230 ssize_t start; 130 ssize_t start; 231 ssize_t remain; 131 ssize_t remain; 232 /* private: */ 132 /* private: */ 233 ssize_t offset; 133 ssize_t offset; 234 }; 134 }; 235 135 236 /** 136 /** 237 * drm_coredump_printer - construct a &drm_pri 137 * drm_coredump_printer - construct a &drm_printer that can output to a buffer 238 * from the read function for devcoredump 138 * from the read function for devcoredump 239 * @iter: A pointer to a struct drm_print_iter 139 * @iter: A pointer to a struct drm_print_iterator for the read instance 240 * 140 * 241 * This wrapper extends drm_printf() to work w 141 * This wrapper extends drm_printf() to work with a dev_coredumpm() callback 242 * function. The passed in drm_print_iterator 142 * function. The passed in drm_print_iterator struct contains the buffer 243 * pointer, size and offset as passed in from 143 * pointer, size and offset as passed in from devcoredump. 244 * 144 * 245 * For example:: 145 * For example:: 246 * 146 * 247 * void coredump_read(char *buffer, loff_ 147 * void coredump_read(char *buffer, loff_t offset, size_t count, 248 * void *data, size_t datalen) 148 * void *data, size_t datalen) 249 * { 149 * { 250 * struct drm_print_iterator iter 150 * struct drm_print_iterator iter; 251 * struct drm_printer p; 151 * struct drm_printer p; 252 * 152 * 253 * iter.data = buffer; 153 * iter.data = buffer; 254 * iter.start = offset; 154 * iter.start = offset; 255 * iter.remain = count; 155 * iter.remain = count; 256 * 156 * 257 * p = drm_coredump_printer(&iter 157 * p = drm_coredump_printer(&iter); 258 * 158 * 259 * drm_printf(p, "foo=%d\n", foo) 159 * drm_printf(p, "foo=%d\n", foo); 260 * } 160 * } 261 * 161 * 262 * void makecoredump(...) 162 * void makecoredump(...) 263 * { 163 * { 264 * ... 164 * ... 265 * dev_coredumpm(dev, THIS_MODULE 165 * dev_coredumpm(dev, THIS_MODULE, data, 0, GFP_KERNEL, 266 * coredump_read, ...) 166 * coredump_read, ...) 267 * } 167 * } 268 * 168 * 269 * RETURNS: 169 * RETURNS: 270 * The &drm_printer object 170 * The &drm_printer object 271 */ 171 */ 272 static inline struct drm_printer 172 static inline struct drm_printer 273 drm_coredump_printer(struct drm_print_iterator 173 drm_coredump_printer(struct drm_print_iterator *iter) 274 { 174 { 275 struct drm_printer p = { 175 struct drm_printer p = { 276 .printfn = __drm_printfn_cored 176 .printfn = __drm_printfn_coredump, 277 .puts = __drm_puts_coredump, 177 .puts = __drm_puts_coredump, 278 .arg = iter, 178 .arg = iter, 279 }; 179 }; 280 180 281 /* Set the internal offset of the iter 181 /* Set the internal offset of the iterator to zero */ 282 iter->offset = 0; 182 iter->offset = 0; 283 183 284 return p; 184 return p; 285 } 185 } 286 186 287 /** 187 /** 288 * drm_seq_file_printer - construct a &drm_pri 188 * drm_seq_file_printer - construct a &drm_printer that outputs to &seq_file 289 * @f: the &struct seq_file to output to 189 * @f: the &struct seq_file to output to 290 * 190 * 291 * RETURNS: 191 * RETURNS: 292 * The &drm_printer object 192 * The &drm_printer object 293 */ 193 */ 294 static inline struct drm_printer drm_seq_file_ 194 static inline struct drm_printer drm_seq_file_printer(struct seq_file *f) 295 { 195 { 296 struct drm_printer p = { 196 struct drm_printer p = { 297 .printfn = __drm_printfn_seq_f 197 .printfn = __drm_printfn_seq_file, 298 .puts = __drm_puts_seq_file, 198 .puts = __drm_puts_seq_file, 299 .arg = f, 199 .arg = f, 300 }; 200 }; 301 return p; 201 return p; 302 } 202 } 303 203 304 /** 204 /** 305 * drm_info_printer - construct a &drm_printer 205 * drm_info_printer - construct a &drm_printer that outputs to dev_printk() 306 * @dev: the &struct device pointer 206 * @dev: the &struct device pointer 307 * 207 * 308 * RETURNS: 208 * RETURNS: 309 * The &drm_printer object 209 * The &drm_printer object 310 */ 210 */ 311 static inline struct drm_printer drm_info_prin 211 static inline struct drm_printer drm_info_printer(struct device *dev) 312 { 212 { 313 struct drm_printer p = { 213 struct drm_printer p = { 314 .printfn = __drm_printfn_info, 214 .printfn = __drm_printfn_info, 315 .arg = dev, 215 .arg = dev, 316 }; 216 }; 317 return p; 217 return p; 318 } 218 } 319 219 320 /** 220 /** 321 * drm_dbg_printer - construct a &drm_printer !! 221 * drm_debug_printer - construct a &drm_printer that outputs to pr_debug() 322 * @drm: the &struct drm_device pointer, or NU !! 222 * @prefix: debug output prefix 323 * @category: the debug category to use << 324 * @prefix: debug output prefix, or NULL for n << 325 * 223 * 326 * RETURNS: 224 * RETURNS: 327 * The &drm_printer object 225 * The &drm_printer object 328 */ 226 */ 329 static inline struct drm_printer drm_dbg_print !! 227 static inline struct drm_printer drm_debug_printer(const char *prefix) 330 << 331 << 332 { 228 { 333 struct drm_printer p = { 229 struct drm_printer p = { 334 .printfn = __drm_printfn_dbg, !! 230 .printfn = __drm_printfn_debug, 335 .arg = drm, !! 231 .prefix = prefix 336 .origin = (const void *)_THIS_ << 337 .prefix = prefix, << 338 .category = category, << 339 }; 232 }; 340 return p; 233 return p; 341 } 234 } 342 235 343 /** 236 /** 344 * drm_err_printer - construct a &drm_printer !! 237 * drm_err_printer - construct a &drm_printer that outputs to pr_err() 345 * @drm: the &struct drm_device pointer !! 238 * @prefix: debug output prefix 346 * @prefix: debug output prefix, or NULL for n << 347 * 239 * 348 * RETURNS: 240 * RETURNS: 349 * The &drm_printer object 241 * The &drm_printer object 350 */ 242 */ 351 static inline struct drm_printer drm_err_print !! 243 static inline struct drm_printer drm_err_printer(const char *prefix) 352 << 353 { 244 { 354 struct drm_printer p = { 245 struct drm_printer p = { 355 .printfn = __drm_printfn_err, 246 .printfn = __drm_printfn_err, 356 .arg = drm, << 357 .prefix = prefix 247 .prefix = prefix 358 }; 248 }; 359 return p; 249 return p; 360 } 250 } 361 251 >> 252 /** >> 253 * enum drm_debug_category - The DRM debug categories >> 254 * >> 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. >> 258 * >> 259 * Each DRM_DEBUG_<CATEGORY> macro logs to DRM_UT_<CATEGORY> category, except >> 260 * DRM_DEBUG() logs to DRM_UT_CORE. >> 261 * >> 262 * Enabling verbose debug messages is done through the drm.debug parameter, each >> 263 * category being enabled by a bit: >> 264 * >> 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 >> 270 * >> 271 * An interesting feature is that it's possible to enable verbose logging at >> 272 * run-time by echoing the debug value in its sysfs node:: >> 273 * >> 274 * # echo 0xf > /sys/module/drm/parameters/debug >> 275 * >> 276 */ >> 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 /** >> 317 * @DRM_UT_DRMRES: Used in the drm managed resources code. >> 318 */ >> 319 DRM_UT_DRMRES = 0x200, >> 320 }; >> 321 >> 322 static inline bool drm_debug_enabled(enum drm_debug_category category) >> 323 { >> 324 return unlikely(__drm_debug & category); >> 325 } >> 326 362 /* 327 /* 363 * struct device based logging 328 * struct device based logging 364 * 329 * 365 * Prefer drm_device based logging over device !! 330 * Prefer drm_device based logging over device or prink based logging. 366 */ 331 */ 367 332 368 __printf(3, 4) 333 __printf(3, 4) 369 void drm_dev_printk(const struct device *dev, 334 void drm_dev_printk(const struct device *dev, const char *level, 370 const char *format, ...); 335 const char *format, ...); 371 struct _ddebug; !! 336 __printf(3, 4) 372 __printf(4, 5) !! 337 void drm_dev_dbg(const struct device *dev, enum drm_debug_category category, 373 void __drm_dev_dbg(struct _ddebug *desc, const !! 338 const char *format, ...); 374 enum drm_debug_category cat << 375 339 376 /** 340 /** 377 * DRM_DEV_ERROR() - Error output. 341 * DRM_DEV_ERROR() - Error output. 378 * 342 * 379 * NOTE: this is deprecated in favor of drm_er << 380 * << 381 * @dev: device pointer 343 * @dev: device pointer 382 * @fmt: printf() like format string. 344 * @fmt: printf() like format string. 383 */ 345 */ 384 #define DRM_DEV_ERROR(dev, fmt, ...) 346 #define DRM_DEV_ERROR(dev, fmt, ...) \ 385 drm_dev_printk(dev, KERN_ERR, "*ERROR* 347 drm_dev_printk(dev, KERN_ERR, "*ERROR* " fmt, ##__VA_ARGS__) 386 348 387 /** 349 /** 388 * DRM_DEV_ERROR_RATELIMITED() - Rate limited 350 * DRM_DEV_ERROR_RATELIMITED() - Rate limited error output. 389 * 351 * 390 * NOTE: this is deprecated in favor of drm_er << 391 * dev_err_ratelimited(). << 392 * << 393 * @dev: device pointer 352 * @dev: device pointer 394 * @fmt: printf() like format string. 353 * @fmt: printf() like format string. 395 * 354 * 396 * Like DRM_ERROR() but won't flood the log. 355 * Like DRM_ERROR() but won't flood the log. 397 */ 356 */ 398 #define DRM_DEV_ERROR_RATELIMITED(dev, fmt, .. 357 #define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...) \ 399 ({ 358 ({ \ 400 static DEFINE_RATELIMIT_STATE(_rs, 359 static DEFINE_RATELIMIT_STATE(_rs, \ 401 DEFAULT_ 360 DEFAULT_RATELIMIT_INTERVAL, \ 402 DEFAULT_ 361 DEFAULT_RATELIMIT_BURST); \ 403 362 \ 404 if (__ratelimit(&_rs)) 363 if (__ratelimit(&_rs)) \ 405 DRM_DEV_ERROR(dev, fmt, ##__VA 364 DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__); \ 406 }) 365 }) 407 366 408 /* NOTE: this is deprecated in favor of drm_in << 409 #define DRM_DEV_INFO(dev, fmt, ...) 367 #define DRM_DEV_INFO(dev, fmt, ...) \ 410 drm_dev_printk(dev, KERN_INFO, fmt, ## 368 drm_dev_printk(dev, KERN_INFO, fmt, ##__VA_ARGS__) 411 369 412 /* NOTE: this is deprecated in favor of drm_in << 413 #define DRM_DEV_INFO_ONCE(dev, fmt, ...) 370 #define DRM_DEV_INFO_ONCE(dev, fmt, ...) \ 414 ({ 371 ({ \ 415 static bool __print_once __read_mostly 372 static bool __print_once __read_mostly; \ 416 if (!__print_once) { 373 if (!__print_once) { \ 417 __print_once = true; 374 __print_once = true; \ 418 DRM_DEV_INFO(dev, fmt, ##__VA_ 375 DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__); \ 419 } 376 } \ 420 }) 377 }) 421 378 422 #if !defined(CONFIG_DRM_USE_DYNAMIC_DEBUG) << 423 #define drm_dev_dbg(dev, cat, fmt, ...) << 424 __drm_dev_dbg(NULL, dev, cat, fmt, ##_ << 425 #else << 426 #define drm_dev_dbg(dev, cat, fmt, ...) << 427 _dynamic_func_call_cls(cat, fmt, __drm << 428 dev, cat, fmt, << 429 #endif << 430 << 431 /** 379 /** 432 * DRM_DEV_DEBUG() - Debug output for generic 380 * DRM_DEV_DEBUG() - Debug output for generic drm code 433 * 381 * 434 * NOTE: this is deprecated in favor of drm_db << 435 * << 436 * @dev: device pointer 382 * @dev: device pointer 437 * @fmt: printf() like format string. 383 * @fmt: printf() like format string. 438 */ 384 */ 439 #define DRM_DEV_DEBUG(dev, fmt, ...) 385 #define DRM_DEV_DEBUG(dev, fmt, ...) \ 440 drm_dev_dbg(dev, DRM_UT_CORE, fmt, ##_ 386 drm_dev_dbg(dev, DRM_UT_CORE, fmt, ##__VA_ARGS__) 441 /** 387 /** 442 * DRM_DEV_DEBUG_DRIVER() - Debug output for v 388 * DRM_DEV_DEBUG_DRIVER() - Debug output for vendor specific part of the driver 443 * 389 * 444 * NOTE: this is deprecated in favor of drm_db << 445 * << 446 * @dev: device pointer 390 * @dev: device pointer 447 * @fmt: printf() like format string. 391 * @fmt: printf() like format string. 448 */ 392 */ 449 #define DRM_DEV_DEBUG_DRIVER(dev, fmt, ...) 393 #define DRM_DEV_DEBUG_DRIVER(dev, fmt, ...) \ 450 drm_dev_dbg(dev, DRM_UT_DRIVER, fmt, # 394 drm_dev_dbg(dev, DRM_UT_DRIVER, fmt, ##__VA_ARGS__) 451 /** 395 /** 452 * DRM_DEV_DEBUG_KMS() - Debug output for mode 396 * DRM_DEV_DEBUG_KMS() - Debug output for modesetting code 453 * 397 * 454 * NOTE: this is deprecated in favor of drm_db << 455 * << 456 * @dev: device pointer 398 * @dev: device pointer 457 * @fmt: printf() like format string. 399 * @fmt: printf() like format string. 458 */ 400 */ 459 #define DRM_DEV_DEBUG_KMS(dev, fmt, ...) 401 #define DRM_DEV_DEBUG_KMS(dev, fmt, ...) \ 460 drm_dev_dbg(dev, DRM_UT_KMS, fmt, ##__ 402 drm_dev_dbg(dev, DRM_UT_KMS, fmt, ##__VA_ARGS__) 461 403 462 /* 404 /* 463 * struct drm_device based logging 405 * struct drm_device based logging 464 * 406 * 465 * Prefer drm_device based logging over device 407 * Prefer drm_device based logging over device or prink based logging. 466 */ 408 */ 467 409 468 /* Helper for struct drm_device based logging. 410 /* Helper for struct drm_device based logging. */ 469 #define __drm_printk(drm, level, type, fmt, .. 411 #define __drm_printk(drm, level, type, fmt, ...) \ 470 dev_##level##type((drm) ? (drm)->dev : !! 412 dev_##level##type((drm)->dev, "[drm] " fmt, ##__VA_ARGS__) 471 413 472 414 473 #define drm_info(drm, fmt, ...) 415 #define drm_info(drm, fmt, ...) \ 474 __drm_printk((drm), info,, fmt, ##__VA 416 __drm_printk((drm), info,, fmt, ##__VA_ARGS__) 475 417 476 #define drm_notice(drm, fmt, ...) 418 #define drm_notice(drm, fmt, ...) \ 477 __drm_printk((drm), notice,, fmt, ##__ 419 __drm_printk((drm), notice,, fmt, ##__VA_ARGS__) 478 420 479 #define drm_warn(drm, fmt, ...) 421 #define drm_warn(drm, fmt, ...) \ 480 __drm_printk((drm), warn,, fmt, ##__VA 422 __drm_printk((drm), warn,, fmt, ##__VA_ARGS__) 481 423 482 #define drm_err(drm, fmt, ...) 424 #define drm_err(drm, fmt, ...) \ 483 __drm_printk((drm), err,, "*ERROR* " f 425 __drm_printk((drm), err,, "*ERROR* " fmt, ##__VA_ARGS__) 484 426 485 427 486 #define drm_info_once(drm, fmt, ...) 428 #define drm_info_once(drm, fmt, ...) \ 487 __drm_printk((drm), info, _once, fmt, 429 __drm_printk((drm), info, _once, fmt, ##__VA_ARGS__) 488 430 489 #define drm_notice_once(drm, fmt, ...) 431 #define drm_notice_once(drm, fmt, ...) \ 490 __drm_printk((drm), notice, _once, fmt 432 __drm_printk((drm), notice, _once, fmt, ##__VA_ARGS__) 491 433 492 #define drm_warn_once(drm, fmt, ...) 434 #define drm_warn_once(drm, fmt, ...) \ 493 __drm_printk((drm), warn, _once, fmt, 435 __drm_printk((drm), warn, _once, fmt, ##__VA_ARGS__) 494 436 495 #define drm_err_once(drm, fmt, ...) 437 #define drm_err_once(drm, fmt, ...) \ 496 __drm_printk((drm), err, _once, "*ERRO 438 __drm_printk((drm), err, _once, "*ERROR* " fmt, ##__VA_ARGS__) 497 439 498 440 499 #define drm_err_ratelimited(drm, fmt, ...) 441 #define drm_err_ratelimited(drm, fmt, ...) \ 500 __drm_printk((drm), err, _ratelimited, 442 __drm_printk((drm), err, _ratelimited, "*ERROR* " fmt, ##__VA_ARGS__) 501 443 502 444 503 #define drm_dbg_core(drm, fmt, ...) 445 #define drm_dbg_core(drm, fmt, ...) \ 504 drm_dev_dbg((drm) ? (drm)->dev : NULL, !! 446 drm_dev_dbg((drm)->dev, DRM_UT_CORE, fmt, ##__VA_ARGS__) 505 #define drm_dbg_driver(drm, fmt, ...) !! 447 #define drm_dbg(drm, fmt, ...) \ 506 drm_dev_dbg((drm) ? (drm)->dev : NULL, !! 448 drm_dev_dbg((drm)->dev, DRM_UT_DRIVER, fmt, ##__VA_ARGS__) 507 #define drm_dbg_kms(drm, fmt, ...) 449 #define drm_dbg_kms(drm, fmt, ...) \ 508 drm_dev_dbg((drm) ? (drm)->dev : NULL, !! 450 drm_dev_dbg((drm)->dev, DRM_UT_KMS, fmt, ##__VA_ARGS__) 509 #define drm_dbg_prime(drm, fmt, ...) 451 #define drm_dbg_prime(drm, fmt, ...) \ 510 drm_dev_dbg((drm) ? (drm)->dev : NULL, !! 452 drm_dev_dbg((drm)->dev, DRM_UT_PRIME, fmt, ##__VA_ARGS__) 511 #define drm_dbg_atomic(drm, fmt, ...) 453 #define drm_dbg_atomic(drm, fmt, ...) \ 512 drm_dev_dbg((drm) ? (drm)->dev : NULL, !! 454 drm_dev_dbg((drm)->dev, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__) 513 #define drm_dbg_vbl(drm, fmt, ...) 455 #define drm_dbg_vbl(drm, fmt, ...) \ 514 drm_dev_dbg((drm) ? (drm)->dev : NULL, !! 456 drm_dev_dbg((drm)->dev, DRM_UT_VBL, fmt, ##__VA_ARGS__) 515 #define drm_dbg_state(drm, fmt, ...) 457 #define drm_dbg_state(drm, fmt, ...) \ 516 drm_dev_dbg((drm) ? (drm)->dev : NULL, !! 458 drm_dev_dbg((drm)->dev, DRM_UT_STATE, fmt, ##__VA_ARGS__) 517 #define drm_dbg_lease(drm, fmt, ...) 459 #define drm_dbg_lease(drm, fmt, ...) \ 518 drm_dev_dbg((drm) ? (drm)->dev : NULL, !! 460 drm_dev_dbg((drm)->dev, DRM_UT_LEASE, fmt, ##__VA_ARGS__) 519 #define drm_dbg_dp(drm, fmt, ...) 461 #define drm_dbg_dp(drm, fmt, ...) \ 520 drm_dev_dbg((drm) ? (drm)->dev : NULL, !! 462 drm_dev_dbg((drm)->dev, DRM_UT_DP, fmt, ##__VA_ARGS__) 521 #define drm_dbg_drmres(drm, fmt, ...) 463 #define drm_dbg_drmres(drm, fmt, ...) \ 522 drm_dev_dbg((drm) ? (drm)->dev : NULL, !! 464 drm_dev_dbg((drm)->dev, DRM_UT_DRMRES, fmt, ##__VA_ARGS__) 523 465 524 #define drm_dbg(drm, fmt, ...) drm_dbg_driver << 525 466 526 /* 467 /* 527 * printk based logging 468 * printk based logging 528 * 469 * 529 * Prefer drm_device based logging over device 470 * Prefer drm_device based logging over device or prink based logging. 530 */ 471 */ 531 472 >> 473 __printf(2, 3) >> 474 void __drm_dbg(enum drm_debug_category category, const char *format, ...); 532 __printf(1, 2) 475 __printf(1, 2) 533 void __drm_err(const char *format, ...); 476 void __drm_err(const char *format, ...); 534 477 535 #if !defined(CONFIG_DRM_USE_DYNAMIC_DEBUG) << 536 #define __drm_dbg(cat, fmt, ...) __drm_ << 537 #else << 538 #define __drm_dbg(cat, fmt, ...) << 539 _dynamic_func_call_cls(cat, fmt, __drm << 540 NULL, cat, fmt, << 541 #endif << 542 << 543 /* Macros to make printk easier */ 478 /* Macros to make printk easier */ 544 479 545 #define _DRM_PRINTK(once, level, fmt, ...) 480 #define _DRM_PRINTK(once, level, fmt, ...) \ 546 printk##once(KERN_##level "[" DRM_NAME 481 printk##once(KERN_##level "[" DRM_NAME "] " fmt, ##__VA_ARGS__) 547 482 548 /* NOTE: this is deprecated in favor of pr_inf << 549 #define DRM_INFO(fmt, ...) 483 #define DRM_INFO(fmt, ...) \ 550 _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__ 484 _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__) 551 /* NOTE: this is deprecated in favor of pr_not << 552 #define DRM_NOTE(fmt, ...) 485 #define DRM_NOTE(fmt, ...) \ 553 _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS 486 _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__) 554 /* NOTE: this is deprecated in favor of pr_war << 555 #define DRM_WARN(fmt, ...) 487 #define DRM_WARN(fmt, ...) \ 556 _DRM_PRINTK(, WARNING, fmt, ##__VA_ARG 488 _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__) 557 489 558 /* NOTE: this is deprecated in favor of pr_inf << 559 #define DRM_INFO_ONCE(fmt, ...) 490 #define DRM_INFO_ONCE(fmt, ...) \ 560 _DRM_PRINTK(_once, INFO, fmt, ##__VA_A 491 _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__) 561 /* NOTE: this is deprecated in favor of pr_not << 562 #define DRM_NOTE_ONCE(fmt, ...) 492 #define DRM_NOTE_ONCE(fmt, ...) \ 563 _DRM_PRINTK(_once, NOTICE, fmt, ##__VA 493 _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__) 564 /* NOTE: this is deprecated in favor of pr_war << 565 #define DRM_WARN_ONCE(fmt, ...) 494 #define DRM_WARN_ONCE(fmt, ...) \ 566 _DRM_PRINTK(_once, WARNING, fmt, ##__V 495 _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__) 567 496 568 /* NOTE: this is deprecated in favor of pr_err << 569 #define DRM_ERROR(fmt, ...) 497 #define DRM_ERROR(fmt, ...) \ 570 __drm_err(fmt, ##__VA_ARGS__) 498 __drm_err(fmt, ##__VA_ARGS__) 571 499 572 /* NOTE: this is deprecated in favor of pr_err << 573 #define DRM_ERROR_RATELIMITED(fmt, ...) 500 #define DRM_ERROR_RATELIMITED(fmt, ...) \ 574 DRM_DEV_ERROR_RATELIMITED(NULL, fmt, # 501 DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__) 575 502 576 /* NOTE: this is deprecated in favor of drm_db << 577 #define DRM_DEBUG(fmt, ...) 503 #define DRM_DEBUG(fmt, ...) \ 578 __drm_dbg(DRM_UT_CORE, fmt, ##__VA_ARG 504 __drm_dbg(DRM_UT_CORE, fmt, ##__VA_ARGS__) 579 505 580 /* NOTE: this is deprecated in favor of drm_db << 581 #define DRM_DEBUG_DRIVER(fmt, ...) 506 #define DRM_DEBUG_DRIVER(fmt, ...) \ 582 __drm_dbg(DRM_UT_DRIVER, fmt, ##__VA_A 507 __drm_dbg(DRM_UT_DRIVER, fmt, ##__VA_ARGS__) 583 508 584 /* NOTE: this is deprecated in favor of drm_db << 585 #define DRM_DEBUG_KMS(fmt, ...) 509 #define DRM_DEBUG_KMS(fmt, ...) \ 586 __drm_dbg(DRM_UT_KMS, fmt, ##__VA_ARGS 510 __drm_dbg(DRM_UT_KMS, fmt, ##__VA_ARGS__) 587 511 588 /* NOTE: this is deprecated in favor of drm_db << 589 #define DRM_DEBUG_PRIME(fmt, ...) 512 #define DRM_DEBUG_PRIME(fmt, ...) \ 590 __drm_dbg(DRM_UT_PRIME, fmt, ##__VA_AR 513 __drm_dbg(DRM_UT_PRIME, fmt, ##__VA_ARGS__) 591 514 592 /* NOTE: this is deprecated in favor of drm_db << 593 #define DRM_DEBUG_ATOMIC(fmt, ...) 515 #define DRM_DEBUG_ATOMIC(fmt, ...) \ 594 __drm_dbg(DRM_UT_ATOMIC, fmt, ##__VA_A 516 __drm_dbg(DRM_UT_ATOMIC, fmt, ##__VA_ARGS__) 595 517 596 /* NOTE: this is deprecated in favor of drm_db << 597 #define DRM_DEBUG_VBL(fmt, ...) 518 #define DRM_DEBUG_VBL(fmt, ...) \ 598 __drm_dbg(DRM_UT_VBL, fmt, ##__VA_ARGS 519 __drm_dbg(DRM_UT_VBL, fmt, ##__VA_ARGS__) 599 520 600 /* NOTE: this is deprecated in favor of drm_db << 601 #define DRM_DEBUG_LEASE(fmt, ...) 521 #define DRM_DEBUG_LEASE(fmt, ...) \ 602 __drm_dbg(DRM_UT_LEASE, fmt, ##__VA_AR 522 __drm_dbg(DRM_UT_LEASE, fmt, ##__VA_ARGS__) 603 523 604 /* NOTE: this is deprecated in favor of drm_db << 605 #define DRM_DEBUG_DP(fmt, ...) 524 #define DRM_DEBUG_DP(fmt, ...) \ 606 __drm_dbg(DRM_UT_DP, fmt, ## __VA_ARGS 525 __drm_dbg(DRM_UT_DP, fmt, ## __VA_ARGS__) 607 526 608 #define __DRM_DEFINE_DBG_RATELIMITED(category, << 609 ({ << 610 static DEFINE_RATELIMIT_STATE(rs_, DEF << 611 const struct drm_device *drm_ = (drm); << 612 << 613 if (drm_debug_enabled(DRM_UT_ ## categ << 614 drm_dev_printk(drm_ ? drm_->de << 615 }) << 616 << 617 #define drm_dbg_ratelimited(drm, fmt, ...) \ << 618 __DRM_DEFINE_DBG_RATELIMITED(DRIVER, d << 619 527 620 #define drm_dbg_kms_ratelimited(drm, fmt, ...) !! 528 #define DRM_DEBUG_KMS_RATELIMITED(fmt, ...) \ 621 __DRM_DEFINE_DBG_RATELIMITED(KMS, drm, !! 529 ({ \ >> 530 static DEFINE_RATELIMIT_STATE(_rs, \ >> 531 DEFAULT_RATELIMIT_INTERVAL, \ >> 532 DEFAULT_RATELIMIT_BURST); \ >> 533 if (__ratelimit(&_rs)) \ >> 534 drm_dev_dbg(NULL, DRM_UT_KMS, fmt, ##__VA_ARGS__); \ >> 535 }) 622 536 623 /* 537 /* 624 * struct drm_device based WARNs 538 * struct drm_device based WARNs 625 * 539 * 626 * drm_WARN*() acts like WARN*(), but with the 540 * drm_WARN*() acts like WARN*(), but with the key difference of 627 * using device specific information so that w 541 * using device specific information so that we know from which device 628 * warning is originating from. 542 * warning is originating from. 629 * 543 * 630 * Prefer drm_device based drm_WARN* over regu 544 * Prefer drm_device based drm_WARN* over regular WARN* 631 */ 545 */ 632 546 633 /* Helper for struct drm_device based WARNs */ 547 /* Helper for struct drm_device based WARNs */ 634 #define drm_WARN(drm, condition, format, arg.. 548 #define drm_WARN(drm, condition, format, arg...) \ 635 WARN(condition, "%s %s: [drm] " format !! 549 WARN(condition, "%s %s: " format, \ 636 dev_driver_string((drm 550 dev_driver_string((drm)->dev), \ 637 dev_name((drm)->dev), 551 dev_name((drm)->dev), ## arg) 638 552 639 #define drm_WARN_ONCE(drm, condition, format, 553 #define drm_WARN_ONCE(drm, condition, format, arg...) \ 640 WARN_ONCE(condition, "%s %s: [drm] " f !! 554 WARN_ONCE(condition, "%s %s: " format, \ 641 dev_driver_string((drm 555 dev_driver_string((drm)->dev), \ 642 dev_name((drm)->dev), 556 dev_name((drm)->dev), ## arg) 643 557 644 #define drm_WARN_ON(drm, x) 558 #define drm_WARN_ON(drm, x) \ 645 drm_WARN((drm), (x), "%s", 559 drm_WARN((drm), (x), "%s", \ 646 "drm_WARN_ON(" __stringify(x) 560 "drm_WARN_ON(" __stringify(x) ")") 647 561 648 #define drm_WARN_ON_ONCE(drm, x) 562 #define drm_WARN_ON_ONCE(drm, x) \ 649 drm_WARN_ONCE((drm), (x), "%s", 563 drm_WARN_ONCE((drm), (x), "%s", \ 650 "drm_WARN_ON_ONCE(" __st 564 "drm_WARN_ON_ONCE(" __stringify(x) ")") 651 565 652 #endif /* DRM_PRINT_H_ */ 566 #endif /* DRM_PRINT_H_ */ 653 567
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.