aboutsummaryrefslogtreecommitdiffstats
path: root/include/drm/drm_print.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/drm/drm_print.h')
-rw-r--r--include/drm/drm_print.h219
1 files changed, 219 insertions, 0 deletions
diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h
index ca4d7c6321f2..2a4a42e59a47 100644
--- a/include/drm/drm_print.h
+++ b/include/drm/drm_print.h
@@ -80,6 +80,29 @@ void __drm_printfn_debug(struct drm_printer *p, struct va_format *vaf);
80__printf(2, 3) 80__printf(2, 3)
81void drm_printf(struct drm_printer *p, const char *f, ...); 81void drm_printf(struct drm_printer *p, const char *f, ...);
82 82
83__printf(2, 0)
84/**
85 * drm_vprintf - print to a &drm_printer stream
86 * @p: the &drm_printer
87 * @fmt: format string
88 * @va: the va_list
89 */
90static inline void
91drm_vprintf(struct drm_printer *p, const char *fmt, va_list *va)
92{
93 struct va_format vaf = { .fmt = fmt, .va = va };
94
95 p->printfn(p, &vaf);
96}
97
98/**
99 * drm_printf_indent - Print to a &drm_printer stream with indentation
100 * @printer: DRM printer
101 * @indent: Tab indentation level (max 5)
102 * @fmt: Format string
103 */
104#define drm_printf_indent(printer, indent, fmt, ...) \
105 drm_printf((printer), "%.*s" fmt, (indent), "\t\t\t\t\tX", ##__VA_ARGS__)
83 106
84/** 107/**
85 * drm_seq_file_printer - construct a &drm_printer that outputs to &seq_file 108 * drm_seq_file_printer - construct a &drm_printer that outputs to &seq_file
@@ -128,4 +151,200 @@ static inline struct drm_printer drm_debug_printer(const char *prefix)
128 }; 151 };
129 return p; 152 return p;
130} 153}
154
155/*
156 * The following categories are defined:
157 *
158 * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
159 * This is the category used by the DRM_DEBUG() macro.
160 *
161 * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
162 * This is the category used by the DRM_DEBUG_DRIVER() macro.
163 *
164 * KMS: used in the modesetting code.
165 * This is the category used by the DRM_DEBUG_KMS() macro.
166 *
167 * PRIME: used in the prime code.
168 * This is the category used by the DRM_DEBUG_PRIME() macro.
169 *
170 * ATOMIC: used in the atomic code.
171 * This is the category used by the DRM_DEBUG_ATOMIC() macro.
172 *
173 * VBL: used for verbose debug message in the vblank code
174 * This is the category used by the DRM_DEBUG_VBL() macro.
175 *
176 * Enabling verbose debug messages is done through the drm.debug parameter,
177 * each category being enabled by a bit.
178 *
179 * drm.debug=0x1 will enable CORE messages
180 * drm.debug=0x2 will enable DRIVER messages
181 * drm.debug=0x3 will enable CORE and DRIVER messages
182 * ...
183 * drm.debug=0x3f will enable all messages
184 *
185 * An interesting feature is that it's possible to enable verbose logging at
186 * run-time by echoing the debug value in its sysfs node:
187 * # echo 0xf > /sys/module/drm/parameters/debug
188 */
189#define DRM_UT_NONE 0x00
190#define DRM_UT_CORE 0x01
191#define DRM_UT_DRIVER 0x02
192#define DRM_UT_KMS 0x04
193#define DRM_UT_PRIME 0x08
194#define DRM_UT_ATOMIC 0x10
195#define DRM_UT_VBL 0x20
196#define DRM_UT_STATE 0x40
197#define DRM_UT_LEASE 0x80
198
199__printf(6, 7)
200void drm_dev_printk(const struct device *dev, const char *level,
201 unsigned int category, const char *function_name,
202 const char *prefix, const char *format, ...);
203__printf(3, 4)
204void drm_printk(const char *level, unsigned int category,
205 const char *format, ...);
206
207/* Macros to make printk easier */
208
209#define _DRM_PRINTK(once, level, fmt, ...) \
210 do { \
211 printk##once(KERN_##level "[" DRM_NAME "] " fmt, \
212 ##__VA_ARGS__); \
213 } while (0)
214
215#define DRM_INFO(fmt, ...) \
216 _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
217#define DRM_NOTE(fmt, ...) \
218 _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
219#define DRM_WARN(fmt, ...) \
220 _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
221
222#define DRM_INFO_ONCE(fmt, ...) \
223 _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
224#define DRM_NOTE_ONCE(fmt, ...) \
225 _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
226#define DRM_WARN_ONCE(fmt, ...) \
227 _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
228
229/**
230 * Error output.
231 *
232 * @dev: device pointer
233 * @fmt: printf() like format string.
234 */
235#define DRM_DEV_ERROR(dev, fmt, ...) \
236 drm_dev_printk(dev, KERN_ERR, DRM_UT_NONE, __func__, " *ERROR*",\
237 fmt, ##__VA_ARGS__)
238#define DRM_ERROR(fmt, ...) \
239 drm_printk(KERN_ERR, DRM_UT_NONE, fmt, ##__VA_ARGS__)
240
241/**
242 * Rate limited error output. Like DRM_ERROR() but won't flood the log.
243 *
244 * @dev: device pointer
245 * @fmt: printf() like format string.
246 */
247#define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...) \
248({ \
249 static DEFINE_RATELIMIT_STATE(_rs, \
250 DEFAULT_RATELIMIT_INTERVAL, \
251 DEFAULT_RATELIMIT_BURST); \
252 \
253 if (__ratelimit(&_rs)) \
254 DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__); \
255})
256#define DRM_ERROR_RATELIMITED(fmt, ...) \
257 DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__)
258
259#define DRM_DEV_INFO(dev, fmt, ...) \
260 drm_dev_printk(dev, KERN_INFO, DRM_UT_NONE, __func__, "", fmt, \
261 ##__VA_ARGS__)
262
263#define DRM_DEV_INFO_ONCE(dev, fmt, ...) \
264({ \
265 static bool __print_once __read_mostly; \
266 if (!__print_once) { \
267 __print_once = true; \
268 DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__); \
269 } \
270})
271
272/**
273 * Debug output.
274 *
275 * @dev: device pointer
276 * @fmt: printf() like format string.
277 */
278#define DRM_DEV_DEBUG(dev, fmt, args...) \
279 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_CORE, __func__, "", fmt, \
280 ##args)
281#define DRM_DEBUG(fmt, ...) \
282 drm_printk(KERN_DEBUG, DRM_UT_CORE, fmt, ##__VA_ARGS__)
283
284#define DRM_DEV_DEBUG_DRIVER(dev, fmt, args...) \
285 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_DRIVER, __func__, "", \
286 fmt, ##args)
287#define DRM_DEBUG_DRIVER(fmt, ...) \
288 drm_printk(KERN_DEBUG, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
289
290#define DRM_DEV_DEBUG_KMS(dev, fmt, args...) \
291 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_KMS, __func__, "", fmt, \
292 ##args)
293#define DRM_DEBUG_KMS(fmt, ...) \
294 drm_printk(KERN_DEBUG, DRM_UT_KMS, fmt, ##__VA_ARGS__)
295
296#define DRM_DEV_DEBUG_PRIME(dev, fmt, args...) \
297 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_PRIME, __func__, "", \
298 fmt, ##args)
299#define DRM_DEBUG_PRIME(fmt, ...) \
300 drm_printk(KERN_DEBUG, DRM_UT_PRIME, fmt, ##__VA_ARGS__)
301
302#define DRM_DEV_DEBUG_ATOMIC(dev, fmt, args...) \
303 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ATOMIC, __func__, "", \
304 fmt, ##args)
305#define DRM_DEBUG_ATOMIC(fmt, ...) \
306 drm_printk(KERN_DEBUG, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
307
308#define DRM_DEV_DEBUG_VBL(dev, fmt, args...) \
309 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_VBL, __func__, "", fmt, \
310 ##args)
311#define DRM_DEBUG_VBL(fmt, ...) \
312 drm_printk(KERN_DEBUG, DRM_UT_VBL, fmt, ##__VA_ARGS__)
313
314#define DRM_DEBUG_LEASE(fmt, ...) \
315 drm_printk(KERN_DEBUG, DRM_UT_LEASE, fmt, ##__VA_ARGS__)
316
317#define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, level, fmt, args...) \
318({ \
319 static DEFINE_RATELIMIT_STATE(_rs, \
320 DEFAULT_RATELIMIT_INTERVAL, \
321 DEFAULT_RATELIMIT_BURST); \
322 if (__ratelimit(&_rs)) \
323 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ ## level, \
324 __func__, "", fmt, ##args); \
325})
326
327/**
328 * Rate limited debug output. Like DRM_DEBUG() but won't flood the log.
329 *
330 * @dev: device pointer
331 * @fmt: printf() like format string.
332 */
333#define DRM_DEV_DEBUG_RATELIMITED(dev, fmt, args...) \
334 DEV__DRM_DEFINE_DEBUG_RATELIMITED(dev, CORE, fmt, ##args)
335#define DRM_DEBUG_RATELIMITED(fmt, args...) \
336 DRM_DEV_DEBUG_RATELIMITED(NULL, fmt, ##args)
337#define DRM_DEV_DEBUG_DRIVER_RATELIMITED(dev, fmt, args...) \
338 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, DRIVER, fmt, ##args)
339#define DRM_DEBUG_DRIVER_RATELIMITED(fmt, args...) \
340 DRM_DEV_DEBUG_DRIVER_RATELIMITED(NULL, fmt, ##args)
341#define DRM_DEV_DEBUG_KMS_RATELIMITED(dev, fmt, args...) \
342 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, KMS, fmt, ##args)
343#define DRM_DEBUG_KMS_RATELIMITED(fmt, args...) \
344 DRM_DEV_DEBUG_KMS_RATELIMITED(NULL, fmt, ##args)
345#define DRM_DEV_DEBUG_PRIME_RATELIMITED(dev, fmt, args...) \
346 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, PRIME, fmt, ##args)
347#define DRM_DEBUG_PRIME_RATELIMITED(fmt, args...) \
348 DRM_DEV_DEBUG_PRIME_RATELIMITED(NULL, fmt, ##args)
349
131#endif /* DRM_PRINT_H_ */ 350#endif /* DRM_PRINT_H_ */