]>
Commit | Line | Data |
---|---|---|
d8187177 RC |
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 | ||
3c6d6e0f JP |
29 | #include <linux/compiler.h> |
30 | #include <linux/printk.h> | |
d8187177 RC |
31 | #include <linux/seq_file.h> |
32 | #include <linux/device.h> | |
33 | ||
34 | /** | |
35 | * DOC: print | |
36 | * | |
37 | * A simple wrapper for dev_printk(), seq_printf(), etc. Allows same | |
38 | * debug code to be used for both debugfs and printk logging. | |
39 | * | |
40 | * For example:: | |
41 | * | |
42 | * void log_some_info(struct drm_printer *p) | |
43 | * { | |
44 | * drm_printf(p, "foo=%d\n", foo); | |
45 | * drm_printf(p, "bar=%d\n", bar); | |
46 | * } | |
47 | * | |
48 | * #ifdef CONFIG_DEBUG_FS | |
49 | * void debugfs_show(struct seq_file *f) | |
50 | * { | |
51 | * struct drm_printer p = drm_seq_file_printer(f); | |
52 | * log_some_info(&p); | |
53 | * } | |
54 | * #endif | |
55 | * | |
56 | * void some_other_function(...) | |
57 | * { | |
58 | * struct drm_printer p = drm_info_printer(drm->dev); | |
59 | * log_some_info(&p); | |
60 | * } | |
61 | */ | |
62 | ||
63 | /** | |
64 | * struct drm_printer - drm output "stream" | |
d8187177 RC |
65 | * |
66 | * Do not use struct members directly. Use drm_printer_seq_file(), | |
67 | * drm_printer_info(), etc to initialize. And drm_printf() for output. | |
68 | */ | |
69 | struct drm_printer { | |
3d387d92 | 70 | /* private: */ |
d8187177 RC |
71 | void (*printfn)(struct drm_printer *p, struct va_format *vaf); |
72 | void *arg; | |
3d387d92 | 73 | const char *prefix; |
d8187177 RC |
74 | }; |
75 | ||
76 | void __drm_printfn_seq_file(struct drm_printer *p, struct va_format *vaf); | |
77 | void __drm_printfn_info(struct drm_printer *p, struct va_format *vaf); | |
3d387d92 | 78 | void __drm_printfn_debug(struct drm_printer *p, struct va_format *vaf); |
d8187177 | 79 | |
3c6d6e0f | 80 | __printf(2, 3) |
d8187177 RC |
81 | void drm_printf(struct drm_printer *p, const char *f, ...); |
82 | ||
bf6234a2 NT |
83 | /** |
84 | * drm_printf_indent - Print to a &drm_printer stream with indentation | |
85 | * @printer: DRM printer | |
86 | * @indent: Tab indentation level (max 5) | |
87 | * @fmt: Format string | |
88 | */ | |
89 | #define drm_printf_indent(printer, indent, fmt, ...) \ | |
90 | drm_printf((printer), "%.*s" fmt, (indent), "\t\t\t\t\tX", ##__VA_ARGS__) | |
d8187177 RC |
91 | |
92 | /** | |
93 | * drm_seq_file_printer - construct a &drm_printer that outputs to &seq_file | |
ea0dd85a | 94 | * @f: the &struct seq_file to output to |
d8187177 RC |
95 | * |
96 | * RETURNS: | |
97 | * The &drm_printer object | |
98 | */ | |
99 | static inline struct drm_printer drm_seq_file_printer(struct seq_file *f) | |
100 | { | |
101 | struct drm_printer p = { | |
102 | .printfn = __drm_printfn_seq_file, | |
103 | .arg = f, | |
104 | }; | |
105 | return p; | |
106 | } | |
107 | ||
108 | /** | |
109 | * drm_info_printer - construct a &drm_printer that outputs to dev_printk() | |
ea0dd85a | 110 | * @dev: the &struct device pointer |
d8187177 RC |
111 | * |
112 | * RETURNS: | |
113 | * The &drm_printer object | |
114 | */ | |
115 | static inline struct drm_printer drm_info_printer(struct device *dev) | |
116 | { | |
117 | struct drm_printer p = { | |
118 | .printfn = __drm_printfn_info, | |
119 | .arg = dev, | |
120 | }; | |
121 | return p; | |
122 | } | |
123 | ||
3d387d92 DV |
124 | /** |
125 | * drm_debug_printer - construct a &drm_printer that outputs to pr_debug() | |
126 | * @prefix: debug output prefix | |
127 | * | |
128 | * RETURNS: | |
129 | * The &drm_printer object | |
130 | */ | |
131 | static inline struct drm_printer drm_debug_printer(const char *prefix) | |
132 | { | |
133 | struct drm_printer p = { | |
134 | .printfn = __drm_printfn_debug, | |
135 | .prefix = prefix | |
136 | }; | |
137 | return p; | |
138 | } | |
02c9656b HM |
139 | |
140 | /* | |
141 | * The following categories are defined: | |
142 | * | |
143 | * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ... | |
144 | * This is the category used by the DRM_DEBUG() macro. | |
145 | * | |
146 | * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ... | |
147 | * This is the category used by the DRM_DEBUG_DRIVER() macro. | |
148 | * | |
149 | * KMS: used in the modesetting code. | |
150 | * This is the category used by the DRM_DEBUG_KMS() macro. | |
151 | * | |
152 | * PRIME: used in the prime code. | |
153 | * This is the category used by the DRM_DEBUG_PRIME() macro. | |
154 | * | |
155 | * ATOMIC: used in the atomic code. | |
156 | * This is the category used by the DRM_DEBUG_ATOMIC() macro. | |
157 | * | |
158 | * VBL: used for verbose debug message in the vblank code | |
159 | * This is the category used by the DRM_DEBUG_VBL() macro. | |
160 | * | |
161 | * Enabling verbose debug messages is done through the drm.debug parameter, | |
162 | * each category being enabled by a bit. | |
163 | * | |
164 | * drm.debug=0x1 will enable CORE messages | |
165 | * drm.debug=0x2 will enable DRIVER messages | |
166 | * drm.debug=0x3 will enable CORE and DRIVER messages | |
167 | * ... | |
168 | * drm.debug=0x3f will enable all messages | |
169 | * | |
170 | * An interesting feature is that it's possible to enable verbose logging at | |
171 | * run-time by echoing the debug value in its sysfs node: | |
172 | * # echo 0xf > /sys/module/drm/parameters/debug | |
173 | */ | |
174 | #define DRM_UT_NONE 0x00 | |
175 | #define DRM_UT_CORE 0x01 | |
176 | #define DRM_UT_DRIVER 0x02 | |
177 | #define DRM_UT_KMS 0x04 | |
178 | #define DRM_UT_PRIME 0x08 | |
179 | #define DRM_UT_ATOMIC 0x10 | |
180 | #define DRM_UT_VBL 0x20 | |
181 | #define DRM_UT_STATE 0x40 | |
182 | ||
183 | __printf(6, 7) | |
184 | void drm_dev_printk(const struct device *dev, const char *level, | |
185 | unsigned int category, const char *function_name, | |
186 | const char *prefix, const char *format, ...); | |
187 | __printf(3, 4) | |
188 | void drm_printk(const char *level, unsigned int category, | |
189 | const char *format, ...); | |
091756bb HM |
190 | |
191 | /* Macros to make printk easier */ | |
02c9656b HM |
192 | |
193 | #define _DRM_PRINTK(once, level, fmt, ...) \ | |
194 | do { \ | |
195 | printk##once(KERN_##level "[" DRM_NAME "] " fmt, \ | |
196 | ##__VA_ARGS__); \ | |
197 | } while (0) | |
198 | ||
199 | #define DRM_INFO(fmt, ...) \ | |
200 | _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__) | |
201 | #define DRM_NOTE(fmt, ...) \ | |
202 | _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__) | |
203 | #define DRM_WARN(fmt, ...) \ | |
204 | _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__) | |
205 | ||
206 | #define DRM_INFO_ONCE(fmt, ...) \ | |
207 | _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__) | |
208 | #define DRM_NOTE_ONCE(fmt, ...) \ | |
209 | _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__) | |
210 | #define DRM_WARN_ONCE(fmt, ...) \ | |
211 | _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__) | |
212 | ||
213 | /** | |
214 | * Error output. | |
215 | * | |
091756bb HM |
216 | * @dev: device pointer |
217 | * @fmt: printf() like format string. | |
02c9656b HM |
218 | */ |
219 | #define DRM_DEV_ERROR(dev, fmt, ...) \ | |
220 | drm_dev_printk(dev, KERN_ERR, DRM_UT_NONE, __func__, " *ERROR*",\ | |
221 | fmt, ##__VA_ARGS__) | |
222 | #define DRM_ERROR(fmt, ...) \ | |
223 | drm_printk(KERN_ERR, DRM_UT_NONE, fmt, ##__VA_ARGS__) | |
224 | ||
225 | /** | |
226 | * Rate limited error output. Like DRM_ERROR() but won't flood the log. | |
227 | * | |
091756bb HM |
228 | * @dev: device pointer |
229 | * @fmt: printf() like format string. | |
02c9656b HM |
230 | */ |
231 | #define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...) \ | |
232 | ({ \ | |
233 | static DEFINE_RATELIMIT_STATE(_rs, \ | |
234 | DEFAULT_RATELIMIT_INTERVAL, \ | |
235 | DEFAULT_RATELIMIT_BURST); \ | |
236 | \ | |
237 | if (__ratelimit(&_rs)) \ | |
238 | DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__); \ | |
239 | }) | |
240 | #define DRM_ERROR_RATELIMITED(fmt, ...) \ | |
241 | DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__) | |
242 | ||
243 | #define DRM_DEV_INFO(dev, fmt, ...) \ | |
244 | drm_dev_printk(dev, KERN_INFO, DRM_UT_NONE, __func__, "", fmt, \ | |
245 | ##__VA_ARGS__) | |
246 | ||
247 | #define DRM_DEV_INFO_ONCE(dev, fmt, ...) \ | |
248 | ({ \ | |
249 | static bool __print_once __read_mostly; \ | |
250 | if (!__print_once) { \ | |
251 | __print_once = true; \ | |
252 | DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__); \ | |
253 | } \ | |
254 | }) | |
255 | ||
256 | /** | |
257 | * Debug output. | |
258 | * | |
091756bb HM |
259 | * @dev: device pointer |
260 | * @fmt: printf() like format string. | |
02c9656b HM |
261 | */ |
262 | #define DRM_DEV_DEBUG(dev, fmt, args...) \ | |
263 | drm_dev_printk(dev, KERN_DEBUG, DRM_UT_CORE, __func__, "", fmt, \ | |
264 | ##args) | |
265 | #define DRM_DEBUG(fmt, ...) \ | |
266 | drm_printk(KERN_DEBUG, DRM_UT_CORE, fmt, ##__VA_ARGS__) | |
267 | ||
268 | #define DRM_DEV_DEBUG_DRIVER(dev, fmt, args...) \ | |
269 | drm_dev_printk(dev, KERN_DEBUG, DRM_UT_DRIVER, __func__, "", \ | |
270 | fmt, ##args) | |
271 | #define DRM_DEBUG_DRIVER(fmt, ...) \ | |
272 | drm_printk(KERN_DEBUG, DRM_UT_DRIVER, fmt, ##__VA_ARGS__) | |
273 | ||
274 | #define DRM_DEV_DEBUG_KMS(dev, fmt, args...) \ | |
275 | drm_dev_printk(dev, KERN_DEBUG, DRM_UT_KMS, __func__, "", fmt, \ | |
276 | ##args) | |
277 | #define DRM_DEBUG_KMS(fmt, ...) \ | |
278 | drm_printk(KERN_DEBUG, DRM_UT_KMS, fmt, ##__VA_ARGS__) | |
279 | ||
280 | #define DRM_DEV_DEBUG_PRIME(dev, fmt, args...) \ | |
281 | drm_dev_printk(dev, KERN_DEBUG, DRM_UT_PRIME, __func__, "", \ | |
282 | fmt, ##args) | |
283 | #define DRM_DEBUG_PRIME(fmt, ...) \ | |
284 | drm_printk(KERN_DEBUG, DRM_UT_PRIME, fmt, ##__VA_ARGS__) | |
285 | ||
286 | #define DRM_DEV_DEBUG_ATOMIC(dev, fmt, args...) \ | |
287 | drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ATOMIC, __func__, "", \ | |
288 | fmt, ##args) | |
289 | #define DRM_DEBUG_ATOMIC(fmt, ...) \ | |
290 | drm_printk(KERN_DEBUG, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__) | |
291 | ||
292 | #define DRM_DEV_DEBUG_VBL(dev, fmt, args...) \ | |
293 | drm_dev_printk(dev, KERN_DEBUG, DRM_UT_VBL, __func__, "", fmt, \ | |
294 | ##args) | |
295 | #define DRM_DEBUG_VBL(fmt, ...) \ | |
296 | drm_printk(KERN_DEBUG, DRM_UT_VBL, fmt, ##__VA_ARGS__) | |
297 | ||
298 | #define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, level, fmt, args...) \ | |
299 | ({ \ | |
300 | static DEFINE_RATELIMIT_STATE(_rs, \ | |
301 | DEFAULT_RATELIMIT_INTERVAL, \ | |
302 | DEFAULT_RATELIMIT_BURST); \ | |
303 | if (__ratelimit(&_rs)) \ | |
304 | drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ ## level, \ | |
305 | __func__, "", fmt, ##args); \ | |
306 | }) | |
307 | ||
308 | /** | |
309 | * Rate limited debug output. Like DRM_DEBUG() but won't flood the log. | |
310 | * | |
091756bb HM |
311 | * @dev: device pointer |
312 | * @fmt: printf() like format string. | |
02c9656b HM |
313 | */ |
314 | #define DRM_DEV_DEBUG_RATELIMITED(dev, fmt, args...) \ | |
315 | DEV__DRM_DEFINE_DEBUG_RATELIMITED(dev, CORE, fmt, ##args) | |
316 | #define DRM_DEBUG_RATELIMITED(fmt, args...) \ | |
317 | DRM_DEV_DEBUG_RATELIMITED(NULL, fmt, ##args) | |
318 | #define DRM_DEV_DEBUG_DRIVER_RATELIMITED(dev, fmt, args...) \ | |
319 | _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, DRIVER, fmt, ##args) | |
320 | #define DRM_DEBUG_DRIVER_RATELIMITED(fmt, args...) \ | |
321 | DRM_DEV_DEBUG_DRIVER_RATELIMITED(NULL, fmt, ##args) | |
322 | #define DRM_DEV_DEBUG_KMS_RATELIMITED(dev, fmt, args...) \ | |
323 | _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, KMS, fmt, ##args) | |
324 | #define DRM_DEBUG_KMS_RATELIMITED(fmt, args...) \ | |
325 | DRM_DEV_DEBUG_KMS_RATELIMITED(NULL, fmt, ##args) | |
326 | #define DRM_DEV_DEBUG_PRIME_RATELIMITED(dev, fmt, args...) \ | |
327 | _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, PRIME, fmt, ##args) | |
328 | #define DRM_DEBUG_PRIME_RATELIMITED(fmt, args...) \ | |
329 | DRM_DEV_DEBUG_PRIME_RATELIMITED(NULL, fmt, ##args) | |
330 | ||
d8187177 | 331 | #endif /* DRM_PRINT_H_ */ |