1 // SPDX-License-Identifier: GPL-2.0
3 * dev_printk.h - printk messages helpers for devices
7 * Copyright (c) 2008-2009 Novell Inc.
11 #ifndef _DEVICE_PRINTK_H_
12 #define _DEVICE_PRINTK_H_
14 #include <linux/compiler.h>
15 #include <linux/types.h>
16 #include <linux/ratelimit.h>
19 #define dev_fmt(fmt) fmt
27 int dev_vprintk_emit(int level, const struct device *dev,
28 const char *fmt, va_list args);
30 int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...);
33 void dev_printk(const char *level, const struct device *dev,
34 const char *fmt, ...);
36 void _dev_emerg(const struct device *dev, const char *fmt, ...);
38 void _dev_alert(const struct device *dev, const char *fmt, ...);
40 void _dev_crit(const struct device *dev, const char *fmt, ...);
42 void _dev_err(const struct device *dev, const char *fmt, ...);
44 void _dev_warn(const struct device *dev, const char *fmt, ...);
46 void _dev_notice(const struct device *dev, const char *fmt, ...);
48 void _dev_info(const struct device *dev, const char *fmt, ...);
52 static inline __printf(3, 0)
53 int dev_vprintk_emit(int level, const struct device *dev,
54 const char *fmt, va_list args)
56 static inline __printf(3, 4)
57 int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...)
60 static inline void __dev_printk(const char *level, const struct device *dev,
61 struct va_format *vaf)
63 static inline __printf(3, 4)
64 void dev_printk(const char *level, const struct device *dev,
68 static inline __printf(2, 3)
69 void _dev_emerg(const struct device *dev, const char *fmt, ...)
71 static inline __printf(2, 3)
72 void _dev_crit(const struct device *dev, const char *fmt, ...)
74 static inline __printf(2, 3)
75 void _dev_alert(const struct device *dev, const char *fmt, ...)
77 static inline __printf(2, 3)
78 void _dev_err(const struct device *dev, const char *fmt, ...)
80 static inline __printf(2, 3)
81 void _dev_warn(const struct device *dev, const char *fmt, ...)
83 static inline __printf(2, 3)
84 void _dev_notice(const struct device *dev, const char *fmt, ...)
86 static inline __printf(2, 3)
87 void _dev_info(const struct device *dev, const char *fmt, ...)
93 * #defines for all the dev_<level> macros to prefix with whatever
94 * possible use of #define dev_fmt(fmt) ...
97 #define dev_emerg(dev, fmt, ...) \
98 _dev_emerg(dev, dev_fmt(fmt), ##__VA_ARGS__)
99 #define dev_crit(dev, fmt, ...) \
100 _dev_crit(dev, dev_fmt(fmt), ##__VA_ARGS__)
101 #define dev_alert(dev, fmt, ...) \
102 _dev_alert(dev, dev_fmt(fmt), ##__VA_ARGS__)
103 #define dev_err(dev, fmt, ...) \
104 _dev_err(dev, dev_fmt(fmt), ##__VA_ARGS__)
105 #define dev_warn(dev, fmt, ...) \
106 _dev_warn(dev, dev_fmt(fmt), ##__VA_ARGS__)
107 #define dev_notice(dev, fmt, ...) \
108 _dev_notice(dev, dev_fmt(fmt), ##__VA_ARGS__)
109 #define dev_info(dev, fmt, ...) \
110 _dev_info(dev, dev_fmt(fmt), ##__VA_ARGS__)
112 #if defined(CONFIG_DYNAMIC_DEBUG) || \
113 (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
114 #define dev_dbg(dev, fmt, ...) \
115 dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
117 #define dev_dbg(dev, fmt, ...) \
118 dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__)
120 #define dev_dbg(dev, fmt, ...) \
123 dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
128 #define dev_level_once(dev_level, dev, fmt, ...) \
130 static bool __print_once __read_mostly; \
132 if (!__print_once) { \
133 __print_once = true; \
134 dev_level(dev, fmt, ##__VA_ARGS__); \
138 #define dev_level_once(dev_level, dev, fmt, ...) \
141 dev_level(dev, fmt, ##__VA_ARGS__); \
145 #define dev_emerg_once(dev, fmt, ...) \
146 dev_level_once(dev_emerg, dev, fmt, ##__VA_ARGS__)
147 #define dev_alert_once(dev, fmt, ...) \
148 dev_level_once(dev_alert, dev, fmt, ##__VA_ARGS__)
149 #define dev_crit_once(dev, fmt, ...) \
150 dev_level_once(dev_crit, dev, fmt, ##__VA_ARGS__)
151 #define dev_err_once(dev, fmt, ...) \
152 dev_level_once(dev_err, dev, fmt, ##__VA_ARGS__)
153 #define dev_warn_once(dev, fmt, ...) \
154 dev_level_once(dev_warn, dev, fmt, ##__VA_ARGS__)
155 #define dev_notice_once(dev, fmt, ...) \
156 dev_level_once(dev_notice, dev, fmt, ##__VA_ARGS__)
157 #define dev_info_once(dev, fmt, ...) \
158 dev_level_once(dev_info, dev, fmt, ##__VA_ARGS__)
159 #define dev_dbg_once(dev, fmt, ...) \
160 dev_level_once(dev_dbg, dev, fmt, ##__VA_ARGS__)
162 #define dev_level_ratelimited(dev_level, dev, fmt, ...) \
164 static DEFINE_RATELIMIT_STATE(_rs, \
165 DEFAULT_RATELIMIT_INTERVAL, \
166 DEFAULT_RATELIMIT_BURST); \
167 if (__ratelimit(&_rs)) \
168 dev_level(dev, fmt, ##__VA_ARGS__); \
171 #define dev_emerg_ratelimited(dev, fmt, ...) \
172 dev_level_ratelimited(dev_emerg, dev, fmt, ##__VA_ARGS__)
173 #define dev_alert_ratelimited(dev, fmt, ...) \
174 dev_level_ratelimited(dev_alert, dev, fmt, ##__VA_ARGS__)
175 #define dev_crit_ratelimited(dev, fmt, ...) \
176 dev_level_ratelimited(dev_crit, dev, fmt, ##__VA_ARGS__)
177 #define dev_err_ratelimited(dev, fmt, ...) \
178 dev_level_ratelimited(dev_err, dev, fmt, ##__VA_ARGS__)
179 #define dev_warn_ratelimited(dev, fmt, ...) \
180 dev_level_ratelimited(dev_warn, dev, fmt, ##__VA_ARGS__)
181 #define dev_notice_ratelimited(dev, fmt, ...) \
182 dev_level_ratelimited(dev_notice, dev, fmt, ##__VA_ARGS__)
183 #define dev_info_ratelimited(dev, fmt, ...) \
184 dev_level_ratelimited(dev_info, dev, fmt, ##__VA_ARGS__)
185 #if defined(CONFIG_DYNAMIC_DEBUG) || \
186 (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
187 /* descriptor check is first to prevent flooding with "callbacks suppressed" */
188 #define dev_dbg_ratelimited(dev, fmt, ...) \
190 static DEFINE_RATELIMIT_STATE(_rs, \
191 DEFAULT_RATELIMIT_INTERVAL, \
192 DEFAULT_RATELIMIT_BURST); \
193 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
194 if (DYNAMIC_DEBUG_BRANCH(descriptor) && \
196 __dynamic_dev_dbg(&descriptor, dev, dev_fmt(fmt), \
200 #define dev_dbg_ratelimited(dev, fmt, ...) \
202 static DEFINE_RATELIMIT_STATE(_rs, \
203 DEFAULT_RATELIMIT_INTERVAL, \
204 DEFAULT_RATELIMIT_BURST); \
205 if (__ratelimit(&_rs)) \
206 dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
209 #define dev_dbg_ratelimited(dev, fmt, ...) \
212 dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
217 #define dev_vdbg dev_dbg
219 #define dev_vdbg(dev, fmt, ...) \
222 dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
227 * dev_WARN*() acts like dev_printk(), but with the key difference of
228 * using WARN/WARN_ONCE to include file/line information and a backtrace.
230 #define dev_WARN(dev, format, arg...) \
231 WARN(1, "%s %s: " format, dev_driver_string(dev), dev_name(dev), ## arg);
233 #define dev_WARN_ONCE(dev, condition, format, arg...) \
234 WARN_ONCE(condition, "%s %s: " format, \
235 dev_driver_string(dev), dev_name(dev), ## arg)
237 #endif /* _DEVICE_PRINTK_H_ */