Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __KERNEL_PRINTK__
0003 #define __KERNEL_PRINTK__
0004 
0005 #include <linux/stdarg.h>
0006 #include <linux/init.h>
0007 #include <linux/kern_levels.h>
0008 #include <linux/linkage.h>
0009 #include <linux/ratelimit_types.h>
0010 #include <linux/once_lite.h>
0011 
0012 extern const char linux_banner[];
0013 extern const char linux_proc_banner[];
0014 
0015 extern int oops_in_progress;    /* If set, an oops, panic(), BUG() or die() is in progress */
0016 
0017 #define PRINTK_MAX_SINGLE_HEADER_LEN 2
0018 
0019 static inline int printk_get_level(const char *buffer)
0020 {
0021     if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
0022         switch (buffer[1]) {
0023         case '0' ... '7':
0024         case 'c':   /* KERN_CONT */
0025             return buffer[1];
0026         }
0027     }
0028     return 0;
0029 }
0030 
0031 static inline const char *printk_skip_level(const char *buffer)
0032 {
0033     if (printk_get_level(buffer))
0034         return buffer + 2;
0035 
0036     return buffer;
0037 }
0038 
0039 static inline const char *printk_skip_headers(const char *buffer)
0040 {
0041     while (printk_get_level(buffer))
0042         buffer = printk_skip_level(buffer);
0043 
0044     return buffer;
0045 }
0046 
0047 #define CONSOLE_EXT_LOG_MAX 8192
0048 
0049 /* printk's without a loglevel use this.. */
0050 #define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
0051 
0052 /* We show everything that is MORE important than this.. */
0053 #define CONSOLE_LOGLEVEL_SILENT  0 /* Mum's the word */
0054 #define CONSOLE_LOGLEVEL_MIN     1 /* Minimum loglevel we let people use */
0055 #define CONSOLE_LOGLEVEL_DEBUG  10 /* issue debug messages */
0056 #define CONSOLE_LOGLEVEL_MOTORMOUTH 15  /* You can't shut this one up */
0057 
0058 /*
0059  * Default used to be hard-coded at 7, quiet used to be hardcoded at 4,
0060  * we're now allowing both to be set from kernel config.
0061  */
0062 #define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT
0063 #define CONSOLE_LOGLEVEL_QUIET   CONFIG_CONSOLE_LOGLEVEL_QUIET
0064 
0065 extern int console_printk[];
0066 
0067 #define console_loglevel (console_printk[0])
0068 #define default_message_loglevel (console_printk[1])
0069 #define minimum_console_loglevel (console_printk[2])
0070 #define default_console_loglevel (console_printk[3])
0071 
0072 extern void console_verbose(void);
0073 
0074 /* strlen("ratelimit") + 1 */
0075 #define DEVKMSG_STR_MAX_SIZE 10
0076 extern char devkmsg_log_str[];
0077 struct ctl_table;
0078 
0079 extern int suppress_printk;
0080 
0081 struct va_format {
0082     const char *fmt;
0083     va_list *va;
0084 };
0085 
0086 /*
0087  * FW_BUG
0088  * Add this to a message where you are sure the firmware is buggy or behaves
0089  * really stupid or out of spec. Be aware that the responsible BIOS developer
0090  * should be able to fix this issue or at least get a concrete idea of the
0091  * problem by reading your message without the need of looking at the kernel
0092  * code.
0093  *
0094  * Use it for definite and high priority BIOS bugs.
0095  *
0096  * FW_WARN
0097  * Use it for not that clear (e.g. could the kernel messed up things already?)
0098  * and medium priority BIOS bugs.
0099  *
0100  * FW_INFO
0101  * Use this one if you want to tell the user or vendor about something
0102  * suspicious, but generally harmless related to the firmware.
0103  *
0104  * Use it for information or very low priority BIOS bugs.
0105  */
0106 #define FW_BUG      "[Firmware Bug]: "
0107 #define FW_WARN     "[Firmware Warn]: "
0108 #define FW_INFO     "[Firmware Info]: "
0109 
0110 /*
0111  * HW_ERR
0112  * Add this to a message for hardware errors, so that user can report
0113  * it to hardware vendor instead of LKML or software vendor.
0114  */
0115 #define HW_ERR      "[Hardware Error]: "
0116 
0117 /*
0118  * DEPRECATED
0119  * Add this to a message whenever you want to warn user space about the use
0120  * of a deprecated aspect of an API so they can stop using it
0121  */
0122 #define DEPRECATED  "[Deprecated]: "
0123 
0124 /*
0125  * Dummy printk for disabled debugging statements to use whilst maintaining
0126  * gcc's format checking.
0127  */
0128 #define no_printk(fmt, ...)             \
0129 ({                          \
0130     if (0)                      \
0131         printk(fmt, ##__VA_ARGS__);     \
0132     0;                      \
0133 })
0134 
0135 #ifdef CONFIG_EARLY_PRINTK
0136 extern asmlinkage __printf(1, 2)
0137 void early_printk(const char *fmt, ...);
0138 #else
0139 static inline __printf(1, 2) __cold
0140 void early_printk(const char *s, ...) { }
0141 #endif
0142 
0143 struct dev_printk_info;
0144 
0145 #ifdef CONFIG_PRINTK
0146 asmlinkage __printf(4, 0)
0147 int vprintk_emit(int facility, int level,
0148          const struct dev_printk_info *dev_info,
0149          const char *fmt, va_list args);
0150 
0151 asmlinkage __printf(1, 0)
0152 int vprintk(const char *fmt, va_list args);
0153 
0154 asmlinkage __printf(1, 2) __cold
0155 int _printk(const char *fmt, ...);
0156 
0157 /*
0158  * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
0159  */
0160 __printf(1, 2) __cold int _printk_deferred(const char *fmt, ...);
0161 
0162 extern void __printk_safe_enter(void);
0163 extern void __printk_safe_exit(void);
0164 /*
0165  * The printk_deferred_enter/exit macros are available only as a hack for
0166  * some code paths that need to defer all printk console printing. Interrupts
0167  * must be disabled for the deferred duration.
0168  */
0169 #define printk_deferred_enter __printk_safe_enter
0170 #define printk_deferred_exit __printk_safe_exit
0171 
0172 extern bool pr_flush(int timeout_ms, bool reset_on_progress);
0173 
0174 /*
0175  * Please don't use printk_ratelimit(), because it shares ratelimiting state
0176  * with all other unrelated printk_ratelimit() callsites.  Instead use
0177  * printk_ratelimited() or plain old __ratelimit().
0178  */
0179 extern int __printk_ratelimit(const char *func);
0180 #define printk_ratelimit() __printk_ratelimit(__func__)
0181 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
0182                    unsigned int interval_msec);
0183 
0184 extern int printk_delay_msec;
0185 extern int dmesg_restrict;
0186 
0187 extern void wake_up_klogd(void);
0188 
0189 char *log_buf_addr_get(void);
0190 u32 log_buf_len_get(void);
0191 void log_buf_vmcoreinfo_setup(void);
0192 void __init setup_log_buf(int early);
0193 __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
0194 void dump_stack_print_info(const char *log_lvl);
0195 void show_regs_print_info(const char *log_lvl);
0196 extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold;
0197 extern asmlinkage void dump_stack(void) __cold;
0198 void printk_trigger_flush(void);
0199 #else
0200 static inline __printf(1, 0)
0201 int vprintk(const char *s, va_list args)
0202 {
0203     return 0;
0204 }
0205 static inline __printf(1, 2) __cold
0206 int _printk(const char *s, ...)
0207 {
0208     return 0;
0209 }
0210 static inline __printf(1, 2) __cold
0211 int _printk_deferred(const char *s, ...)
0212 {
0213     return 0;
0214 }
0215 
0216 static inline void printk_deferred_enter(void)
0217 {
0218 }
0219 
0220 static inline void printk_deferred_exit(void)
0221 {
0222 }
0223 
0224 static inline bool pr_flush(int timeout_ms, bool reset_on_progress)
0225 {
0226     return true;
0227 }
0228 
0229 static inline int printk_ratelimit(void)
0230 {
0231     return 0;
0232 }
0233 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
0234                       unsigned int interval_msec)
0235 {
0236     return false;
0237 }
0238 
0239 static inline void wake_up_klogd(void)
0240 {
0241 }
0242 
0243 static inline char *log_buf_addr_get(void)
0244 {
0245     return NULL;
0246 }
0247 
0248 static inline u32 log_buf_len_get(void)
0249 {
0250     return 0;
0251 }
0252 
0253 static inline void log_buf_vmcoreinfo_setup(void)
0254 {
0255 }
0256 
0257 static inline void setup_log_buf(int early)
0258 {
0259 }
0260 
0261 static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...)
0262 {
0263 }
0264 
0265 static inline void dump_stack_print_info(const char *log_lvl)
0266 {
0267 }
0268 
0269 static inline void show_regs_print_info(const char *log_lvl)
0270 {
0271 }
0272 
0273 static inline void dump_stack_lvl(const char *log_lvl)
0274 {
0275 }
0276 
0277 static inline void dump_stack(void)
0278 {
0279 }
0280 static inline void printk_trigger_flush(void)
0281 {
0282 }
0283 #endif
0284 
0285 #ifdef CONFIG_SMP
0286 extern int __printk_cpu_sync_try_get(void);
0287 extern void __printk_cpu_sync_wait(void);
0288 extern void __printk_cpu_sync_put(void);
0289 
0290 #else
0291 
0292 #define __printk_cpu_sync_try_get() true
0293 #define __printk_cpu_sync_wait()
0294 #define __printk_cpu_sync_put()
0295 #endif /* CONFIG_SMP */
0296 
0297 /**
0298  * printk_cpu_sync_get_irqsave() - Disable interrupts and acquire the printk
0299  *                                 cpu-reentrant spinning lock.
0300  * @flags: Stack-allocated storage for saving local interrupt state,
0301  *         to be passed to printk_cpu_sync_put_irqrestore().
0302  *
0303  * If the lock is owned by another CPU, spin until it becomes available.
0304  * Interrupts are restored while spinning.
0305  *
0306  * CAUTION: This function must be used carefully. It does not behave like a
0307  * typical lock. Here are important things to watch out for...
0308  *
0309  *     * This function is reentrant on the same CPU. Therefore the calling
0310  *       code must not assume exclusive access to data if code accessing the
0311  *       data can run reentrant or within NMI context on the same CPU.
0312  *
0313  *     * If there exists usage of this function from NMI context, it becomes
0314  *       unsafe to perform any type of locking or spinning to wait for other
0315  *       CPUs after calling this function from any context. This includes
0316  *       using spinlocks or any other busy-waiting synchronization methods.
0317  */
0318 #define printk_cpu_sync_get_irqsave(flags)      \
0319     for (;;) {                  \
0320         local_irq_save(flags);          \
0321         if (__printk_cpu_sync_try_get())    \
0322             break;              \
0323         local_irq_restore(flags);       \
0324         __printk_cpu_sync_wait();       \
0325     }
0326 
0327 /**
0328  * printk_cpu_sync_put_irqrestore() - Release the printk cpu-reentrant spinning
0329  *                                    lock and restore interrupts.
0330  * @flags: Caller's saved interrupt state, from printk_cpu_sync_get_irqsave().
0331  */
0332 #define printk_cpu_sync_put_irqrestore(flags)   \
0333     do {                    \
0334         __printk_cpu_sync_put();    \
0335         local_irq_restore(flags);   \
0336     } while (0)
0337 
0338 extern int kptr_restrict;
0339 
0340 /**
0341  * pr_fmt - used by the pr_*() macros to generate the printk format string
0342  * @fmt: format string passed from a pr_*() macro
0343  *
0344  * This macro can be used to generate a unified format string for pr_*()
0345  * macros. A common use is to prefix all pr_*() messages in a file with a common
0346  * string. For example, defining this at the top of a source file:
0347  *
0348  *        #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0349  *
0350  * would prefix all pr_info, pr_emerg... messages in the file with the module
0351  * name.
0352  */
0353 #ifndef pr_fmt
0354 #define pr_fmt(fmt) fmt
0355 #endif
0356 
0357 struct module;
0358 
0359 #ifdef CONFIG_PRINTK_INDEX
0360 struct pi_entry {
0361     const char *fmt;
0362     const char *func;
0363     const char *file;
0364     unsigned int line;
0365 
0366     /*
0367      * While printk and pr_* have the level stored in the string at compile
0368      * time, some subsystems dynamically add it at runtime through the
0369      * format string. For these dynamic cases, we allow the subsystem to
0370      * tell us the level at compile time.
0371      *
0372      * NULL indicates that the level, if any, is stored in fmt.
0373      */
0374     const char *level;
0375 
0376     /*
0377      * The format string used by various subsystem specific printk()
0378      * wrappers to prefix the message.
0379      *
0380      * Note that the static prefix defined by the pr_fmt() macro is stored
0381      * directly in the message format (@fmt), not here.
0382      */
0383     const char *subsys_fmt_prefix;
0384 } __packed;
0385 
0386 #define __printk_index_emit(_fmt, _level, _subsys_fmt_prefix)       \
0387     do {                                \
0388         if (__builtin_constant_p(_fmt) && __builtin_constant_p(_level)) { \
0389             /*
0390              * We check __builtin_constant_p multiple times here
0391              * for the same input because GCC will produce an error
0392              * if we try to assign a static variable to fmt if it
0393              * is not a constant, even with the outer if statement.
0394              */                     \
0395             static const struct pi_entry _entry     \
0396             __used = {                  \
0397                 .fmt = __builtin_constant_p(_fmt) ? (_fmt) : NULL, \
0398                 .func = __func__,           \
0399                 .file = __FILE__,           \
0400                 .line = __LINE__,           \
0401                 .level = __builtin_constant_p(_level) ? (_level) : NULL, \
0402                 .subsys_fmt_prefix = _subsys_fmt_prefix,\
0403             };                      \
0404             static const struct pi_entry *_entry_ptr    \
0405             __used __section(".printk_index") = &_entry;    \
0406         }                           \
0407     } while (0)
0408 
0409 #else /* !CONFIG_PRINTK_INDEX */
0410 #define __printk_index_emit(...) do {} while (0)
0411 #endif /* CONFIG_PRINTK_INDEX */
0412 
0413 /*
0414  * Some subsystems have their own custom printk that applies a va_format to a
0415  * generic format, for example, to include a device number or other metadata
0416  * alongside the format supplied by the caller.
0417  *
0418  * In order to store these in the way they would be emitted by the printk
0419  * infrastructure, the subsystem provides us with the start, fixed string, and
0420  * any subsequent text in the format string.
0421  *
0422  * We take a variable argument list as pr_fmt/dev_fmt/etc are sometimes passed
0423  * as multiple arguments (eg: `"%s: ", "blah"`), and we must only take the
0424  * first one.
0425  *
0426  * subsys_fmt_prefix must be known at compile time, or compilation will fail
0427  * (since this is a mistake). If fmt or level is not known at compile time, no
0428  * index entry will be made (since this can legitimately happen).
0429  */
0430 #define printk_index_subsys_emit(subsys_fmt_prefix, level, fmt, ...) \
0431     __printk_index_emit(fmt, level, subsys_fmt_prefix)
0432 
0433 #define printk_index_wrap(_p_func, _fmt, ...)               \
0434     ({                              \
0435         __printk_index_emit(_fmt, NULL, NULL);          \
0436         _p_func(_fmt, ##__VA_ARGS__);               \
0437     })
0438 
0439 
0440 /**
0441  * printk - print a kernel message
0442  * @fmt: format string
0443  *
0444  * This is printk(). It can be called from any context. We want it to work.
0445  *
0446  * If printk indexing is enabled, _printk() is called from printk_index_wrap.
0447  * Otherwise, printk is simply #defined to _printk.
0448  *
0449  * We try to grab the console_lock. If we succeed, it's easy - we log the
0450  * output and call the console drivers.  If we fail to get the semaphore, we
0451  * place the output into the log buffer and return. The current holder of
0452  * the console_sem will notice the new output in console_unlock(); and will
0453  * send it to the consoles before releasing the lock.
0454  *
0455  * One effect of this deferred printing is that code which calls printk() and
0456  * then changes console_loglevel may break. This is because console_loglevel
0457  * is inspected when the actual printing occurs.
0458  *
0459  * See also:
0460  * printf(3)
0461  *
0462  * See the vsnprintf() documentation for format string extensions over C99.
0463  */
0464 #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
0465 #define printk_deferred(fmt, ...)                   \
0466     printk_index_wrap(_printk_deferred, fmt, ##__VA_ARGS__)
0467 
0468 /**
0469  * pr_emerg - Print an emergency-level message
0470  * @fmt: format string
0471  * @...: arguments for the format string
0472  *
0473  * This macro expands to a printk with KERN_EMERG loglevel. It uses pr_fmt() to
0474  * generate the format string.
0475  */
0476 #define pr_emerg(fmt, ...) \
0477     printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
0478 /**
0479  * pr_alert - Print an alert-level message
0480  * @fmt: format string
0481  * @...: arguments for the format string
0482  *
0483  * This macro expands to a printk with KERN_ALERT loglevel. It uses pr_fmt() to
0484  * generate the format string.
0485  */
0486 #define pr_alert(fmt, ...) \
0487     printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
0488 /**
0489  * pr_crit - Print a critical-level message
0490  * @fmt: format string
0491  * @...: arguments for the format string
0492  *
0493  * This macro expands to a printk with KERN_CRIT loglevel. It uses pr_fmt() to
0494  * generate the format string.
0495  */
0496 #define pr_crit(fmt, ...) \
0497     printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
0498 /**
0499  * pr_err - Print an error-level message
0500  * @fmt: format string
0501  * @...: arguments for the format string
0502  *
0503  * This macro expands to a printk with KERN_ERR loglevel. It uses pr_fmt() to
0504  * generate the format string.
0505  */
0506 #define pr_err(fmt, ...) \
0507     printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
0508 /**
0509  * pr_warn - Print a warning-level message
0510  * @fmt: format string
0511  * @...: arguments for the format string
0512  *
0513  * This macro expands to a printk with KERN_WARNING loglevel. It uses pr_fmt()
0514  * to generate the format string.
0515  */
0516 #define pr_warn(fmt, ...) \
0517     printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
0518 /**
0519  * pr_notice - Print a notice-level message
0520  * @fmt: format string
0521  * @...: arguments for the format string
0522  *
0523  * This macro expands to a printk with KERN_NOTICE loglevel. It uses pr_fmt() to
0524  * generate the format string.
0525  */
0526 #define pr_notice(fmt, ...) \
0527     printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
0528 /**
0529  * pr_info - Print an info-level message
0530  * @fmt: format string
0531  * @...: arguments for the format string
0532  *
0533  * This macro expands to a printk with KERN_INFO loglevel. It uses pr_fmt() to
0534  * generate the format string.
0535  */
0536 #define pr_info(fmt, ...) \
0537     printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
0538 
0539 /**
0540  * pr_cont - Continues a previous log message in the same line.
0541  * @fmt: format string
0542  * @...: arguments for the format string
0543  *
0544  * This macro expands to a printk with KERN_CONT loglevel. It should only be
0545  * used when continuing a log message with no newline ('\n') enclosed. Otherwise
0546  * it defaults back to KERN_DEFAULT loglevel.
0547  */
0548 #define pr_cont(fmt, ...) \
0549     printk(KERN_CONT fmt, ##__VA_ARGS__)
0550 
0551 /**
0552  * pr_devel - Print a debug-level message conditionally
0553  * @fmt: format string
0554  * @...: arguments for the format string
0555  *
0556  * This macro expands to a printk with KERN_DEBUG loglevel if DEBUG is
0557  * defined. Otherwise it does nothing.
0558  *
0559  * It uses pr_fmt() to generate the format string.
0560  */
0561 #ifdef DEBUG
0562 #define pr_devel(fmt, ...) \
0563     printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
0564 #else
0565 #define pr_devel(fmt, ...) \
0566     no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
0567 #endif
0568 
0569 
0570 /* If you are writing a driver, please use dev_dbg instead */
0571 #if defined(CONFIG_DYNAMIC_DEBUG) || \
0572     (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
0573 #include <linux/dynamic_debug.h>
0574 
0575 /**
0576  * pr_debug - Print a debug-level message conditionally
0577  * @fmt: format string
0578  * @...: arguments for the format string
0579  *
0580  * This macro expands to dynamic_pr_debug() if CONFIG_DYNAMIC_DEBUG is
0581  * set. Otherwise, if DEBUG is defined, it's equivalent to a printk with
0582  * KERN_DEBUG loglevel. If DEBUG is not defined it does nothing.
0583  *
0584  * It uses pr_fmt() to generate the format string (dynamic_pr_debug() uses
0585  * pr_fmt() internally).
0586  */
0587 #define pr_debug(fmt, ...)          \
0588     dynamic_pr_debug(fmt, ##__VA_ARGS__)
0589 #elif defined(DEBUG)
0590 #define pr_debug(fmt, ...) \
0591     printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
0592 #else
0593 #define pr_debug(fmt, ...) \
0594     no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
0595 #endif
0596 
0597 /*
0598  * Print a one-time message (analogous to WARN_ONCE() et al):
0599  */
0600 
0601 #ifdef CONFIG_PRINTK
0602 #define printk_once(fmt, ...)                   \
0603     DO_ONCE_LITE(printk, fmt, ##__VA_ARGS__)
0604 #define printk_deferred_once(fmt, ...)              \
0605     DO_ONCE_LITE(printk_deferred, fmt, ##__VA_ARGS__)
0606 #else
0607 #define printk_once(fmt, ...)                   \
0608     no_printk(fmt, ##__VA_ARGS__)
0609 #define printk_deferred_once(fmt, ...)              \
0610     no_printk(fmt, ##__VA_ARGS__)
0611 #endif
0612 
0613 #define pr_emerg_once(fmt, ...)                 \
0614     printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
0615 #define pr_alert_once(fmt, ...)                 \
0616     printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
0617 #define pr_crit_once(fmt, ...)                  \
0618     printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
0619 #define pr_err_once(fmt, ...)                   \
0620     printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
0621 #define pr_warn_once(fmt, ...)                  \
0622     printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
0623 #define pr_notice_once(fmt, ...)                \
0624     printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
0625 #define pr_info_once(fmt, ...)                  \
0626     printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
0627 /* no pr_cont_once, don't do that... */
0628 
0629 #if defined(DEBUG)
0630 #define pr_devel_once(fmt, ...)                 \
0631     printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
0632 #else
0633 #define pr_devel_once(fmt, ...)                 \
0634     no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
0635 #endif
0636 
0637 /* If you are writing a driver, please use dev_dbg instead */
0638 #if defined(DEBUG)
0639 #define pr_debug_once(fmt, ...)                 \
0640     printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
0641 #else
0642 #define pr_debug_once(fmt, ...)                 \
0643     no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
0644 #endif
0645 
0646 /*
0647  * ratelimited messages with local ratelimit_state,
0648  * no local ratelimit_state used in the !PRINTK case
0649  */
0650 #ifdef CONFIG_PRINTK
0651 #define printk_ratelimited(fmt, ...)                    \
0652 ({                                  \
0653     static DEFINE_RATELIMIT_STATE(_rs,              \
0654                       DEFAULT_RATELIMIT_INTERVAL,   \
0655                       DEFAULT_RATELIMIT_BURST);     \
0656                                     \
0657     if (__ratelimit(&_rs))                      \
0658         printk(fmt, ##__VA_ARGS__);             \
0659 })
0660 #else
0661 #define printk_ratelimited(fmt, ...)                    \
0662     no_printk(fmt, ##__VA_ARGS__)
0663 #endif
0664 
0665 #define pr_emerg_ratelimited(fmt, ...)                  \
0666     printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
0667 #define pr_alert_ratelimited(fmt, ...)                  \
0668     printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
0669 #define pr_crit_ratelimited(fmt, ...)                   \
0670     printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
0671 #define pr_err_ratelimited(fmt, ...)                    \
0672     printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
0673 #define pr_warn_ratelimited(fmt, ...)                   \
0674     printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
0675 #define pr_notice_ratelimited(fmt, ...)                 \
0676     printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
0677 #define pr_info_ratelimited(fmt, ...)                   \
0678     printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
0679 /* no pr_cont_ratelimited, don't do that... */
0680 
0681 #if defined(DEBUG)
0682 #define pr_devel_ratelimited(fmt, ...)                  \
0683     printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
0684 #else
0685 #define pr_devel_ratelimited(fmt, ...)                  \
0686     no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
0687 #endif
0688 
0689 /* If you are writing a driver, please use dev_dbg instead */
0690 #if defined(CONFIG_DYNAMIC_DEBUG) || \
0691     (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
0692 /* descriptor check is first to prevent flooding with "callbacks suppressed" */
0693 #define pr_debug_ratelimited(fmt, ...)                  \
0694 do {                                    \
0695     static DEFINE_RATELIMIT_STATE(_rs,              \
0696                       DEFAULT_RATELIMIT_INTERVAL,   \
0697                       DEFAULT_RATELIMIT_BURST);     \
0698     DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt));     \
0699     if (DYNAMIC_DEBUG_BRANCH(descriptor) &&             \
0700         __ratelimit(&_rs))                      \
0701         __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__);    \
0702 } while (0)
0703 #elif defined(DEBUG)
0704 #define pr_debug_ratelimited(fmt, ...)                  \
0705     printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
0706 #else
0707 #define pr_debug_ratelimited(fmt, ...) \
0708     no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
0709 #endif
0710 
0711 extern const struct file_operations kmsg_fops;
0712 
0713 enum {
0714     DUMP_PREFIX_NONE,
0715     DUMP_PREFIX_ADDRESS,
0716     DUMP_PREFIX_OFFSET
0717 };
0718 extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
0719                   int groupsize, char *linebuf, size_t linebuflen,
0720                   bool ascii);
0721 #ifdef CONFIG_PRINTK
0722 extern void print_hex_dump(const char *level, const char *prefix_str,
0723                int prefix_type, int rowsize, int groupsize,
0724                const void *buf, size_t len, bool ascii);
0725 #else
0726 static inline void print_hex_dump(const char *level, const char *prefix_str,
0727                   int prefix_type, int rowsize, int groupsize,
0728                   const void *buf, size_t len, bool ascii)
0729 {
0730 }
0731 static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
0732                     const void *buf, size_t len)
0733 {
0734 }
0735 
0736 #endif
0737 
0738 #if defined(CONFIG_DYNAMIC_DEBUG) || \
0739     (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
0740 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize,  \
0741                  groupsize, buf, len, ascii)    \
0742     dynamic_hex_dump(prefix_str, prefix_type, rowsize,  \
0743              groupsize, buf, len, ascii)
0744 #elif defined(DEBUG)
0745 #define print_hex_dump_debug(prefix_str, prefix_type, rowsize,      \
0746                  groupsize, buf, len, ascii)        \
0747     print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize,    \
0748                groupsize, buf, len, ascii)
0749 #else
0750 static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
0751                     int rowsize, int groupsize,
0752                     const void *buf, size_t len, bool ascii)
0753 {
0754 }
0755 #endif
0756 
0757 /**
0758  * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params
0759  * @prefix_str: string to prefix each line with;
0760  *  caller supplies trailing spaces for alignment if desired
0761  * @prefix_type: controls whether prefix of an offset, address, or none
0762  *  is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
0763  * @buf: data blob to dump
0764  * @len: number of bytes in the @buf
0765  *
0766  * Calls print_hex_dump(), with log level of KERN_DEBUG,
0767  * rowsize of 16, groupsize of 1, and ASCII output included.
0768  */
0769 #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
0770     print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true)
0771 
0772 #endif