Linux Audio

Check our new training course

Loading...
v5.9
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef __KERNEL_PRINTK__
  3#define __KERNEL_PRINTK__
  4
  5#include <stdarg.h>
  6#include <linux/init.h>
  7#include <linux/kern_levels.h>
  8#include <linux/linkage.h>
  9#include <linux/cache.h>
 10#include <linux/ratelimit_types.h>
 11
 12extern const char linux_banner[];
 13extern const char linux_proc_banner[];
 14
 15#define PRINTK_MAX_SINGLE_HEADER_LEN 2
 16
 17static inline int printk_get_level(const char *buffer)
 18{
 19	if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
 20		switch (buffer[1]) {
 21		case '0' ... '7':
 
 22		case 'c':	/* KERN_CONT */
 23			return buffer[1];
 24		}
 25	}
 26	return 0;
 27}
 28
 29static inline const char *printk_skip_level(const char *buffer)
 30{
 31	if (printk_get_level(buffer))
 32		return buffer + 2;
 33
 34	return buffer;
 35}
 36
 37static inline const char *printk_skip_headers(const char *buffer)
 38{
 39	while (printk_get_level(buffer))
 40		buffer = printk_skip_level(buffer);
 41
 42	return buffer;
 43}
 44
 45#define CONSOLE_EXT_LOG_MAX	8192
 46
 47/* printk's without a loglevel use this.. */
 48#define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
 49
 50/* We show everything that is MORE important than this.. */
 51#define CONSOLE_LOGLEVEL_SILENT  0 /* Mum's the word */
 52#define CONSOLE_LOGLEVEL_MIN	 1 /* Minimum loglevel we let people use */
 
 53#define CONSOLE_LOGLEVEL_DEBUG	10 /* issue debug messages */
 54#define CONSOLE_LOGLEVEL_MOTORMOUTH 15	/* You can't shut this one up */
 55
 56/*
 57 * Default used to be hard-coded at 7, quiet used to be hardcoded at 4,
 58 * we're now allowing both to be set from kernel config.
 59 */
 60#define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT
 61#define CONSOLE_LOGLEVEL_QUIET	 CONFIG_CONSOLE_LOGLEVEL_QUIET
 62
 63extern int console_printk[];
 64
 65#define console_loglevel (console_printk[0])
 66#define default_message_loglevel (console_printk[1])
 67#define minimum_console_loglevel (console_printk[2])
 68#define default_console_loglevel (console_printk[3])
 69
 70static inline void console_silent(void)
 71{
 72	console_loglevel = CONSOLE_LOGLEVEL_SILENT;
 73}
 74
 75static inline void console_verbose(void)
 76{
 77	if (console_loglevel)
 78		console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
 79}
 80
 81/* strlen("ratelimit") + 1 */
 82#define DEVKMSG_STR_MAX_SIZE 10
 83extern char devkmsg_log_str[];
 84struct ctl_table;
 85
 86extern int suppress_printk;
 87
 88struct va_format {
 89	const char *fmt;
 90	va_list *va;
 91};
 92
 93/*
 94 * FW_BUG
 95 * Add this to a message where you are sure the firmware is buggy or behaves
 96 * really stupid or out of spec. Be aware that the responsible BIOS developer
 97 * should be able to fix this issue or at least get a concrete idea of the
 98 * problem by reading your message without the need of looking at the kernel
 99 * code.
100 *
101 * Use it for definite and high priority BIOS bugs.
102 *
103 * FW_WARN
104 * Use it for not that clear (e.g. could the kernel messed up things already?)
105 * and medium priority BIOS bugs.
106 *
107 * FW_INFO
108 * Use this one if you want to tell the user or vendor about something
109 * suspicious, but generally harmless related to the firmware.
110 *
111 * Use it for information or very low priority BIOS bugs.
112 */
113#define FW_BUG		"[Firmware Bug]: "
114#define FW_WARN		"[Firmware Warn]: "
115#define FW_INFO		"[Firmware Info]: "
116
117/*
118 * HW_ERR
119 * Add this to a message for hardware errors, so that user can report
120 * it to hardware vendor instead of LKML or software vendor.
121 */
122#define HW_ERR		"[Hardware Error]: "
123
124/*
125 * DEPRECATED
126 * Add this to a message whenever you want to warn user space about the use
127 * of a deprecated aspect of an API so they can stop using it
128 */
129#define DEPRECATED	"[Deprecated]: "
130
131/*
132 * Dummy printk for disabled debugging statements to use whilst maintaining
133 * gcc's format checking.
134 */
135#define no_printk(fmt, ...)				\
136({							\
137	if (0)						\
138		printk(fmt, ##__VA_ARGS__);		\
 
 
139	0;						\
140})
141
142#ifdef CONFIG_EARLY_PRINTK
143extern asmlinkage __printf(1, 2)
144void early_printk(const char *fmt, ...);
145#else
146static inline __printf(1, 2) __cold
147void early_printk(const char *s, ...) { }
148#endif
149
150#ifdef CONFIG_PRINTK_NMI
 
151extern void printk_nmi_enter(void);
152extern void printk_nmi_exit(void);
153extern void printk_nmi_direct_enter(void);
154extern void printk_nmi_direct_exit(void);
155#else
 
156static inline void printk_nmi_enter(void) { }
157static inline void printk_nmi_exit(void) { }
158static inline void printk_nmi_direct_enter(void) { }
159static inline void printk_nmi_direct_exit(void) { }
160#endif /* PRINTK_NMI */
161
162#ifdef CONFIG_PRINTK
163asmlinkage __printf(5, 0)
164int vprintk_emit(int facility, int level,
165		 const char *dict, size_t dictlen,
166		 const char *fmt, va_list args);
167
168asmlinkage __printf(1, 0)
169int vprintk(const char *fmt, va_list args);
170
 
 
 
 
 
171asmlinkage __printf(1, 2) __cold
172int printk(const char *fmt, ...);
173
174/*
175 * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
176 */
177__printf(1, 2) __cold int printk_deferred(const char *fmt, ...);
178
179/*
180 * Please don't use printk_ratelimit(), because it shares ratelimiting state
181 * with all other unrelated printk_ratelimit() callsites.  Instead use
182 * printk_ratelimited() or plain old __ratelimit().
183 */
184extern int __printk_ratelimit(const char *func);
185#define printk_ratelimit() __printk_ratelimit(__func__)
186extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
187				   unsigned int interval_msec);
188
189extern int printk_delay_msec;
190extern int dmesg_restrict;
 
191
192extern int
193devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, void *buf,
194			  size_t *lenp, loff_t *ppos);
195
196extern void wake_up_klogd(void);
197
198char *log_buf_addr_get(void);
199u32 log_buf_len_get(void);
200void log_buf_vmcoreinfo_setup(void);
201void __init setup_log_buf(int early);
202__printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
203void dump_stack_print_info(const char *log_lvl);
204void show_regs_print_info(const char *log_lvl);
205extern asmlinkage void dump_stack(void) __cold;
206extern void printk_safe_flush(void);
207extern void printk_safe_flush_on_panic(void);
208#else
209static inline __printf(1, 0)
210int vprintk(const char *s, va_list args)
211{
212	return 0;
213}
214static inline __printf(1, 2) __cold
215int printk(const char *s, ...)
216{
217	return 0;
218}
219static inline __printf(1, 2) __cold
220int printk_deferred(const char *s, ...)
221{
222	return 0;
223}
224static inline int printk_ratelimit(void)
225{
226	return 0;
227}
228static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
229					  unsigned int interval_msec)
230{
231	return false;
232}
233
234static inline void wake_up_klogd(void)
235{
236}
237
238static inline char *log_buf_addr_get(void)
239{
240	return NULL;
241}
242
243static inline u32 log_buf_len_get(void)
244{
245	return 0;
246}
247
248static inline void log_buf_vmcoreinfo_setup(void)
249{
250}
251
252static inline void setup_log_buf(int early)
253{
254}
255
256static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...)
257{
258}
259
260static inline void dump_stack_print_info(const char *log_lvl)
261{
262}
263
264static inline void show_regs_print_info(const char *log_lvl)
265{
266}
267
268static inline void dump_stack(void)
269{
270}
271
272static inline void printk_safe_flush(void)
273{
274}
275
276static inline void printk_safe_flush_on_panic(void)
277{
278}
279#endif
280
281extern int kptr_restrict;
282
283/**
284 * pr_fmt - used by the pr_*() macros to generate the printk format string
285 * @fmt: format string passed from a pr_*() macro
286 *
287 * This macro can be used to generate a unified format string for pr_*()
288 * macros. A common use is to prefix all pr_*() messages in a file with a common
289 * string. For example, defining this at the top of a source file:
290 *
291 *        #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
292 *
293 * would prefix all pr_info, pr_emerg... messages in the file with the module
294 * name.
295 */
296#ifndef pr_fmt
297#define pr_fmt(fmt) fmt
298#endif
299
300/**
301 * pr_emerg - Print an emergency-level message
302 * @fmt: format string
303 * @...: arguments for the format string
304 *
305 * This macro expands to a printk with KERN_EMERG loglevel. It uses pr_fmt() to
306 * generate the format string.
307 */
308#define pr_emerg(fmt, ...) \
309	printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
310/**
311 * pr_alert - Print an alert-level message
312 * @fmt: format string
313 * @...: arguments for the format string
314 *
315 * This macro expands to a printk with KERN_ALERT loglevel. It uses pr_fmt() to
316 * generate the format string.
317 */
318#define pr_alert(fmt, ...) \
319	printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
320/**
321 * pr_crit - Print a critical-level message
322 * @fmt: format string
323 * @...: arguments for the format string
324 *
325 * This macro expands to a printk with KERN_CRIT loglevel. It uses pr_fmt() to
326 * generate the format string.
327 */
328#define pr_crit(fmt, ...) \
329	printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
330/**
331 * pr_err - Print an error-level message
332 * @fmt: format string
333 * @...: arguments for the format string
334 *
335 * This macro expands to a printk with KERN_ERR loglevel. It uses pr_fmt() to
336 * generate the format string.
337 */
338#define pr_err(fmt, ...) \
339	printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
340/**
341 * pr_warn - Print a warning-level message
342 * @fmt: format string
343 * @...: arguments for the format string
344 *
345 * This macro expands to a printk with KERN_WARNING loglevel. It uses pr_fmt()
346 * to generate the format string.
347 */
348#define pr_warn(fmt, ...) \
349	printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
350/**
351 * pr_notice - Print a notice-level message
352 * @fmt: format string
353 * @...: arguments for the format string
354 *
355 * This macro expands to a printk with KERN_NOTICE loglevel. It uses pr_fmt() to
356 * generate the format string.
357 */
358#define pr_notice(fmt, ...) \
359	printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
360/**
361 * pr_info - Print an info-level message
362 * @fmt: format string
363 * @...: arguments for the format string
364 *
365 * This macro expands to a printk with KERN_INFO loglevel. It uses pr_fmt() to
366 * generate the format string.
367 */
368#define pr_info(fmt, ...) \
369	printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
370
371/**
372 * pr_cont - Continues a previous log message in the same line.
373 * @fmt: format string
374 * @...: arguments for the format string
375 *
376 * This macro expands to a printk with KERN_CONT loglevel. It should only be
377 * used when continuing a log message with no newline ('\n') enclosed. Otherwise
378 * it defaults back to KERN_DEFAULT loglevel.
379 */
380#define pr_cont(fmt, ...) \
381	printk(KERN_CONT fmt, ##__VA_ARGS__)
382
383/**
384 * pr_devel - Print a debug-level message conditionally
385 * @fmt: format string
386 * @...: arguments for the format string
387 *
388 * This macro expands to a printk with KERN_DEBUG loglevel if DEBUG is
389 * defined. Otherwise it does nothing.
390 *
391 * It uses pr_fmt() to generate the format string.
392 */
393#ifdef DEBUG
394#define pr_devel(fmt, ...) \
395	printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
396#else
397#define pr_devel(fmt, ...) \
398	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
399#endif
400
401
402/* If you are writing a driver, please use dev_dbg instead */
403#if defined(CONFIG_DYNAMIC_DEBUG) || \
404	(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
405#include <linux/dynamic_debug.h>
406
407/**
408 * pr_debug - Print a debug-level message conditionally
409 * @fmt: format string
410 * @...: arguments for the format string
411 *
412 * This macro expands to dynamic_pr_debug() if CONFIG_DYNAMIC_DEBUG is
413 * set. Otherwise, if DEBUG is defined, it's equivalent to a printk with
414 * KERN_DEBUG loglevel. If DEBUG is not defined it does nothing.
415 *
416 * It uses pr_fmt() to generate the format string (dynamic_pr_debug() uses
417 * pr_fmt() internally).
418 */
419#define pr_debug(fmt, ...)			\
420	dynamic_pr_debug(fmt, ##__VA_ARGS__)
421#elif defined(DEBUG)
422#define pr_debug(fmt, ...) \
423	printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
424#else
425#define pr_debug(fmt, ...) \
426	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
427#endif
428
429/*
430 * Print a one-time message (analogous to WARN_ONCE() et al):
431 */
432
433#ifdef CONFIG_PRINTK
434#define printk_once(fmt, ...)					\
435({								\
436	static bool __section(.data.once) __print_once;		\
437	bool __ret_print_once = !__print_once;			\
438								\
439	if (!__print_once) {					\
440		__print_once = true;				\
441		printk(fmt, ##__VA_ARGS__);			\
442	}							\
443	unlikely(__ret_print_once);				\
444})
445#define printk_deferred_once(fmt, ...)				\
446({								\
447	static bool __section(.data.once) __print_once;		\
448	bool __ret_print_once = !__print_once;			\
449								\
450	if (!__print_once) {					\
451		__print_once = true;				\
452		printk_deferred(fmt, ##__VA_ARGS__);		\
453	}							\
454	unlikely(__ret_print_once);				\
455})
456#else
457#define printk_once(fmt, ...)					\
458	no_printk(fmt, ##__VA_ARGS__)
459#define printk_deferred_once(fmt, ...)				\
460	no_printk(fmt, ##__VA_ARGS__)
461#endif
462
463#define pr_emerg_once(fmt, ...)					\
464	printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
465#define pr_alert_once(fmt, ...)					\
466	printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
467#define pr_crit_once(fmt, ...)					\
468	printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
469#define pr_err_once(fmt, ...)					\
470	printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
471#define pr_warn_once(fmt, ...)					\
472	printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
473#define pr_notice_once(fmt, ...)				\
474	printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
475#define pr_info_once(fmt, ...)					\
476	printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
477/* no pr_cont_once, don't do that... */
 
478
479#if defined(DEBUG)
480#define pr_devel_once(fmt, ...)					\
481	printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
482#else
483#define pr_devel_once(fmt, ...)					\
484	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
485#endif
486
487/* If you are writing a driver, please use dev_dbg instead */
488#if defined(DEBUG)
489#define pr_debug_once(fmt, ...)					\
490	printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
491#else
492#define pr_debug_once(fmt, ...)					\
493	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
494#endif
495
496/*
497 * ratelimited messages with local ratelimit_state,
498 * no local ratelimit_state used in the !PRINTK case
499 */
500#ifdef CONFIG_PRINTK
501#define printk_ratelimited(fmt, ...)					\
502({									\
503	static DEFINE_RATELIMIT_STATE(_rs,				\
504				      DEFAULT_RATELIMIT_INTERVAL,	\
505				      DEFAULT_RATELIMIT_BURST);		\
506									\
507	if (__ratelimit(&_rs))						\
508		printk(fmt, ##__VA_ARGS__);				\
509})
510#else
511#define printk_ratelimited(fmt, ...)					\
512	no_printk(fmt, ##__VA_ARGS__)
513#endif
514
515#define pr_emerg_ratelimited(fmt, ...)					\
516	printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
517#define pr_alert_ratelimited(fmt, ...)					\
518	printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
519#define pr_crit_ratelimited(fmt, ...)					\
520	printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
521#define pr_err_ratelimited(fmt, ...)					\
522	printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
523#define pr_warn_ratelimited(fmt, ...)					\
524	printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
525#define pr_notice_ratelimited(fmt, ...)					\
526	printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
527#define pr_info_ratelimited(fmt, ...)					\
528	printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
529/* no pr_cont_ratelimited, don't do that... */
530
531#if defined(DEBUG)
532#define pr_devel_ratelimited(fmt, ...)					\
533	printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
534#else
535#define pr_devel_ratelimited(fmt, ...)					\
536	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
537#endif
538
539/* If you are writing a driver, please use dev_dbg instead */
540#if defined(CONFIG_DYNAMIC_DEBUG) || \
541	(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
542/* descriptor check is first to prevent flooding with "callbacks suppressed" */
543#define pr_debug_ratelimited(fmt, ...)					\
544do {									\
545	static DEFINE_RATELIMIT_STATE(_rs,				\
546				      DEFAULT_RATELIMIT_INTERVAL,	\
547				      DEFAULT_RATELIMIT_BURST);		\
548	DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt));		\
549	if (DYNAMIC_DEBUG_BRANCH(descriptor) &&				\
550	    __ratelimit(&_rs))						\
551		__dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__);	\
552} while (0)
553#elif defined(DEBUG)
554#define pr_debug_ratelimited(fmt, ...)					\
555	printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
556#else
557#define pr_debug_ratelimited(fmt, ...) \
558	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
559#endif
560
561extern const struct file_operations kmsg_fops;
562
563enum {
564	DUMP_PREFIX_NONE,
565	DUMP_PREFIX_ADDRESS,
566	DUMP_PREFIX_OFFSET
567};
568extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
569			      int groupsize, char *linebuf, size_t linebuflen,
570			      bool ascii);
571#ifdef CONFIG_PRINTK
572extern void print_hex_dump(const char *level, const char *prefix_str,
573			   int prefix_type, int rowsize, int groupsize,
574			   const void *buf, size_t len, bool ascii);
 
 
 
 
 
 
 
575#else
576static inline void print_hex_dump(const char *level, const char *prefix_str,
577				  int prefix_type, int rowsize, int groupsize,
578				  const void *buf, size_t len, bool ascii)
579{
580}
581static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
582					const void *buf, size_t len)
583{
584}
585
586#endif
587
588#if defined(CONFIG_DYNAMIC_DEBUG) || \
589	(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
590#define print_hex_dump_debug(prefix_str, prefix_type, rowsize,	\
591			     groupsize, buf, len, ascii)	\
592	dynamic_hex_dump(prefix_str, prefix_type, rowsize,	\
593			 groupsize, buf, len, ascii)
594#elif defined(DEBUG)
595#define print_hex_dump_debug(prefix_str, prefix_type, rowsize,		\
596			     groupsize, buf, len, ascii)		\
597	print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize,	\
598		       groupsize, buf, len, ascii)
599#else
600static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
601					int rowsize, int groupsize,
602					const void *buf, size_t len, bool ascii)
603{
604}
605#endif
606
607/**
608 * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params
609 * @prefix_str: string to prefix each line with;
610 *  caller supplies trailing spaces for alignment if desired
611 * @prefix_type: controls whether prefix of an offset, address, or none
612 *  is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
613 * @buf: data blob to dump
614 * @len: number of bytes in the @buf
615 *
616 * Calls print_hex_dump(), with log level of KERN_DEBUG,
617 * rowsize of 16, groupsize of 1, and ASCII output included.
618 */
619#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len)	\
620	print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true)
621
622#endif
v4.10.11
 
  1#ifndef __KERNEL_PRINTK__
  2#define __KERNEL_PRINTK__
  3
  4#include <stdarg.h>
  5#include <linux/init.h>
  6#include <linux/kern_levels.h>
  7#include <linux/linkage.h>
  8#include <linux/cache.h>
 
  9
 10extern const char linux_banner[];
 11extern const char linux_proc_banner[];
 12
 13#define PRINTK_MAX_SINGLE_HEADER_LEN 2
 14
 15static inline int printk_get_level(const char *buffer)
 16{
 17	if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
 18		switch (buffer[1]) {
 19		case '0' ... '7':
 20		case 'd':	/* KERN_DEFAULT */
 21		case 'c':	/* KERN_CONT */
 22			return buffer[1];
 23		}
 24	}
 25	return 0;
 26}
 27
 28static inline const char *printk_skip_level(const char *buffer)
 29{
 30	if (printk_get_level(buffer))
 31		return buffer + 2;
 32
 33	return buffer;
 34}
 35
 36static inline const char *printk_skip_headers(const char *buffer)
 37{
 38	while (printk_get_level(buffer))
 39		buffer = printk_skip_level(buffer);
 40
 41	return buffer;
 42}
 43
 44#define CONSOLE_EXT_LOG_MAX	8192
 45
 46/* printk's without a loglevel use this.. */
 47#define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
 48
 49/* We show everything that is MORE important than this.. */
 50#define CONSOLE_LOGLEVEL_SILENT  0 /* Mum's the word */
 51#define CONSOLE_LOGLEVEL_MIN	 1 /* Minimum loglevel we let people use */
 52#define CONSOLE_LOGLEVEL_QUIET	 4 /* Shhh ..., when booted with "quiet" */
 53#define CONSOLE_LOGLEVEL_DEBUG	10 /* issue debug messages */
 54#define CONSOLE_LOGLEVEL_MOTORMOUTH 15	/* You can't shut this one up */
 55
 56/*
 57 * Default used to be hard-coded at 7, we're now allowing it to be set from
 58 * kernel config.
 59 */
 60#define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT
 
 61
 62extern int console_printk[];
 63
 64#define console_loglevel (console_printk[0])
 65#define default_message_loglevel (console_printk[1])
 66#define minimum_console_loglevel (console_printk[2])
 67#define default_console_loglevel (console_printk[3])
 68
 69static inline void console_silent(void)
 70{
 71	console_loglevel = CONSOLE_LOGLEVEL_SILENT;
 72}
 73
 74static inline void console_verbose(void)
 75{
 76	if (console_loglevel)
 77		console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
 78}
 79
 80/* strlen("ratelimit") + 1 */
 81#define DEVKMSG_STR_MAX_SIZE 10
 82extern char devkmsg_log_str[];
 83struct ctl_table;
 84
 
 
 85struct va_format {
 86	const char *fmt;
 87	va_list *va;
 88};
 89
 90/*
 91 * FW_BUG
 92 * Add this to a message where you are sure the firmware is buggy or behaves
 93 * really stupid or out of spec. Be aware that the responsible BIOS developer
 94 * should be able to fix this issue or at least get a concrete idea of the
 95 * problem by reading your message without the need of looking at the kernel
 96 * code.
 97 *
 98 * Use it for definite and high priority BIOS bugs.
 99 *
100 * FW_WARN
101 * Use it for not that clear (e.g. could the kernel messed up things already?)
102 * and medium priority BIOS bugs.
103 *
104 * FW_INFO
105 * Use this one if you want to tell the user or vendor about something
106 * suspicious, but generally harmless related to the firmware.
107 *
108 * Use it for information or very low priority BIOS bugs.
109 */
110#define FW_BUG		"[Firmware Bug]: "
111#define FW_WARN		"[Firmware Warn]: "
112#define FW_INFO		"[Firmware Info]: "
113
114/*
115 * HW_ERR
116 * Add this to a message for hardware errors, so that user can report
117 * it to hardware vendor instead of LKML or software vendor.
118 */
119#define HW_ERR		"[Hardware Error]: "
120
121/*
122 * DEPRECATED
123 * Add this to a message whenever you want to warn user space about the use
124 * of a deprecated aspect of an API so they can stop using it
125 */
126#define DEPRECATED	"[Deprecated]: "
127
128/*
129 * Dummy printk for disabled debugging statements to use whilst maintaining
130 * gcc's format checking.
131 */
132#define no_printk(fmt, ...)				\
133({							\
134	do {						\
135		if (0)					\
136			printk(fmt, ##__VA_ARGS__);	\
137	} while (0);					\
138	0;						\
139})
140
141#ifdef CONFIG_EARLY_PRINTK
142extern asmlinkage __printf(1, 2)
143void early_printk(const char *fmt, ...);
144#else
145static inline __printf(1, 2) __cold
146void early_printk(const char *s, ...) { }
147#endif
148
149#ifdef CONFIG_PRINTK_NMI
150extern void printk_nmi_init(void);
151extern void printk_nmi_enter(void);
152extern void printk_nmi_exit(void);
153extern void printk_nmi_flush(void);
154extern void printk_nmi_flush_on_panic(void);
155#else
156static inline void printk_nmi_init(void) { }
157static inline void printk_nmi_enter(void) { }
158static inline void printk_nmi_exit(void) { }
159static inline void printk_nmi_flush(void) { }
160static inline void printk_nmi_flush_on_panic(void) { }
161#endif /* PRINTK_NMI */
162
163#ifdef CONFIG_PRINTK
164asmlinkage __printf(5, 0)
165int vprintk_emit(int facility, int level,
166		 const char *dict, size_t dictlen,
167		 const char *fmt, va_list args);
168
169asmlinkage __printf(1, 0)
170int vprintk(const char *fmt, va_list args);
171
172asmlinkage __printf(5, 6) __cold
173int printk_emit(int facility, int level,
174		const char *dict, size_t dictlen,
175		const char *fmt, ...);
176
177asmlinkage __printf(1, 2) __cold
178int printk(const char *fmt, ...);
179
180/*
181 * Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
182 */
183__printf(1, 2) __cold int printk_deferred(const char *fmt, ...);
184
185/*
186 * Please don't use printk_ratelimit(), because it shares ratelimiting state
187 * with all other unrelated printk_ratelimit() callsites.  Instead use
188 * printk_ratelimited() or plain old __ratelimit().
189 */
190extern int __printk_ratelimit(const char *func);
191#define printk_ratelimit() __printk_ratelimit(__func__)
192extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
193				   unsigned int interval_msec);
194
195extern int printk_delay_msec;
196extern int dmesg_restrict;
197extern int kptr_restrict;
198
199extern int
200devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, void __user *buf,
201			  size_t *lenp, loff_t *ppos);
202
203extern void wake_up_klogd(void);
204
205char *log_buf_addr_get(void);
206u32 log_buf_len_get(void);
207void log_buf_kexec_setup(void);
208void __init setup_log_buf(int early);
209__printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
210void dump_stack_print_info(const char *log_lvl);
211void show_regs_print_info(const char *log_lvl);
 
 
 
212#else
213static inline __printf(1, 0)
214int vprintk(const char *s, va_list args)
215{
216	return 0;
217}
218static inline __printf(1, 2) __cold
219int printk(const char *s, ...)
220{
221	return 0;
222}
223static inline __printf(1, 2) __cold
224int printk_deferred(const char *s, ...)
225{
226	return 0;
227}
228static inline int printk_ratelimit(void)
229{
230	return 0;
231}
232static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
233					  unsigned int interval_msec)
234{
235	return false;
236}
237
238static inline void wake_up_klogd(void)
239{
240}
241
242static inline char *log_buf_addr_get(void)
243{
244	return NULL;
245}
246
247static inline u32 log_buf_len_get(void)
248{
249	return 0;
250}
251
252static inline void log_buf_kexec_setup(void)
253{
254}
255
256static inline void setup_log_buf(int early)
257{
258}
259
260static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...)
261{
262}
263
264static inline void dump_stack_print_info(const char *log_lvl)
265{
266}
267
268static inline void show_regs_print_info(const char *log_lvl)
269{
270}
 
 
 
 
 
 
 
 
 
 
 
 
271#endif
272
273extern asmlinkage void dump_stack(void) __cold;
274
 
 
 
 
 
 
 
 
 
 
 
 
 
275#ifndef pr_fmt
276#define pr_fmt(fmt) fmt
277#endif
278
279/*
280 * These can be used to print at the various log levels.
281 * All of these will print unconditionally, although note that pr_debug()
282 * and other debug macros are compiled out unless either DEBUG is defined
283 * or CONFIG_DYNAMIC_DEBUG is set.
 
 
284 */
285#define pr_emerg(fmt, ...) \
286	printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
 
 
 
 
 
 
 
 
287#define pr_alert(fmt, ...) \
288	printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
 
 
 
 
 
 
 
 
289#define pr_crit(fmt, ...) \
290	printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
 
 
 
 
 
 
 
 
291#define pr_err(fmt, ...) \
292	printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
293#define pr_warning(fmt, ...) \
 
 
 
 
 
 
 
 
294	printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
295#define pr_warn pr_warning
 
 
 
 
 
 
 
296#define pr_notice(fmt, ...) \
297	printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
 
 
 
 
 
 
 
 
298#define pr_info(fmt, ...) \
299	printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
300/*
301 * Like KERN_CONT, pr_cont() should only be used when continuing
302 * a line with no newline ('\n') enclosed. Otherwise it defaults
303 * back to KERN_DEFAULT.
 
 
 
 
 
304 */
305#define pr_cont(fmt, ...) \
306	printk(KERN_CONT fmt, ##__VA_ARGS__)
307
308/* pr_devel() should produce zero code unless DEBUG is defined */
 
 
 
 
 
 
 
 
 
309#ifdef DEBUG
310#define pr_devel(fmt, ...) \
311	printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
312#else
313#define pr_devel(fmt, ...) \
314	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
315#endif
316
317
318/* If you are writing a driver, please use dev_dbg instead */
319#if defined(CONFIG_DYNAMIC_DEBUG)
 
320#include <linux/dynamic_debug.h>
321
322/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
323#define pr_debug(fmt, ...) \
 
 
 
 
 
 
 
 
 
 
 
324	dynamic_pr_debug(fmt, ##__VA_ARGS__)
325#elif defined(DEBUG)
326#define pr_debug(fmt, ...) \
327	printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
328#else
329#define pr_debug(fmt, ...) \
330	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
331#endif
332
333/*
334 * Print a one-time message (analogous to WARN_ONCE() et al):
335 */
336
337#ifdef CONFIG_PRINTK
338#define printk_once(fmt, ...)					\
339({								\
340	static bool __print_once __read_mostly;			\
341	bool __ret_print_once = !__print_once;			\
342								\
343	if (!__print_once) {					\
344		__print_once = true;				\
345		printk(fmt, ##__VA_ARGS__);			\
346	}							\
347	unlikely(__ret_print_once);				\
348})
349#define printk_deferred_once(fmt, ...)				\
350({								\
351	static bool __print_once __read_mostly;			\
352	bool __ret_print_once = !__print_once;			\
353								\
354	if (!__print_once) {					\
355		__print_once = true;				\
356		printk_deferred(fmt, ##__VA_ARGS__);		\
357	}							\
358	unlikely(__ret_print_once);				\
359})
360#else
361#define printk_once(fmt, ...)					\
362	no_printk(fmt, ##__VA_ARGS__)
363#define printk_deferred_once(fmt, ...)				\
364	no_printk(fmt, ##__VA_ARGS__)
365#endif
366
367#define pr_emerg_once(fmt, ...)					\
368	printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
369#define pr_alert_once(fmt, ...)					\
370	printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
371#define pr_crit_once(fmt, ...)					\
372	printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
373#define pr_err_once(fmt, ...)					\
374	printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
375#define pr_warn_once(fmt, ...)					\
376	printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
377#define pr_notice_once(fmt, ...)				\
378	printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
379#define pr_info_once(fmt, ...)					\
380	printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
381#define pr_cont_once(fmt, ...)					\
382	printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
383
384#if defined(DEBUG)
385#define pr_devel_once(fmt, ...)					\
386	printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
387#else
388#define pr_devel_once(fmt, ...)					\
389	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
390#endif
391
392/* If you are writing a driver, please use dev_dbg instead */
393#if defined(DEBUG)
394#define pr_debug_once(fmt, ...)					\
395	printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
396#else
397#define pr_debug_once(fmt, ...)					\
398	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
399#endif
400
401/*
402 * ratelimited messages with local ratelimit_state,
403 * no local ratelimit_state used in the !PRINTK case
404 */
405#ifdef CONFIG_PRINTK
406#define printk_ratelimited(fmt, ...)					\
407({									\
408	static DEFINE_RATELIMIT_STATE(_rs,				\
409				      DEFAULT_RATELIMIT_INTERVAL,	\
410				      DEFAULT_RATELIMIT_BURST);		\
411									\
412	if (__ratelimit(&_rs))						\
413		printk(fmt, ##__VA_ARGS__);				\
414})
415#else
416#define printk_ratelimited(fmt, ...)					\
417	no_printk(fmt, ##__VA_ARGS__)
418#endif
419
420#define pr_emerg_ratelimited(fmt, ...)					\
421	printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
422#define pr_alert_ratelimited(fmt, ...)					\
423	printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
424#define pr_crit_ratelimited(fmt, ...)					\
425	printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
426#define pr_err_ratelimited(fmt, ...)					\
427	printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
428#define pr_warn_ratelimited(fmt, ...)					\
429	printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
430#define pr_notice_ratelimited(fmt, ...)					\
431	printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
432#define pr_info_ratelimited(fmt, ...)					\
433	printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
434/* no pr_cont_ratelimited, don't do that... */
435
436#if defined(DEBUG)
437#define pr_devel_ratelimited(fmt, ...)					\
438	printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
439#else
440#define pr_devel_ratelimited(fmt, ...)					\
441	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
442#endif
443
444/* If you are writing a driver, please use dev_dbg instead */
445#if defined(CONFIG_DYNAMIC_DEBUG)
 
446/* descriptor check is first to prevent flooding with "callbacks suppressed" */
447#define pr_debug_ratelimited(fmt, ...)					\
448do {									\
449	static DEFINE_RATELIMIT_STATE(_rs,				\
450				      DEFAULT_RATELIMIT_INTERVAL,	\
451				      DEFAULT_RATELIMIT_BURST);		\
452	DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt));		\
453	if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) &&	\
454	    __ratelimit(&_rs))						\
455		__dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__);	\
456} while (0)
457#elif defined(DEBUG)
458#define pr_debug_ratelimited(fmt, ...)					\
459	printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
460#else
461#define pr_debug_ratelimited(fmt, ...) \
462	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
463#endif
464
465extern const struct file_operations kmsg_fops;
466
467enum {
468	DUMP_PREFIX_NONE,
469	DUMP_PREFIX_ADDRESS,
470	DUMP_PREFIX_OFFSET
471};
472extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
473			      int groupsize, char *linebuf, size_t linebuflen,
474			      bool ascii);
475#ifdef CONFIG_PRINTK
476extern void print_hex_dump(const char *level, const char *prefix_str,
477			   int prefix_type, int rowsize, int groupsize,
478			   const void *buf, size_t len, bool ascii);
479#if defined(CONFIG_DYNAMIC_DEBUG)
480#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len)	\
481	dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
482#else
483extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
484				 const void *buf, size_t len);
485#endif /* defined(CONFIG_DYNAMIC_DEBUG) */
486#else
487static inline void print_hex_dump(const char *level, const char *prefix_str,
488				  int prefix_type, int rowsize, int groupsize,
489				  const void *buf, size_t len, bool ascii)
490{
491}
492static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
493					const void *buf, size_t len)
494{
495}
496
497#endif
498
499#if defined(CONFIG_DYNAMIC_DEBUG)
 
500#define print_hex_dump_debug(prefix_str, prefix_type, rowsize,	\
501			     groupsize, buf, len, ascii)	\
502	dynamic_hex_dump(prefix_str, prefix_type, rowsize,	\
503			 groupsize, buf, len, ascii)
504#elif defined(DEBUG)
505#define print_hex_dump_debug(prefix_str, prefix_type, rowsize,		\
506			     groupsize, buf, len, ascii)		\
507	print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize,	\
508		       groupsize, buf, len, ascii)
509#else
510static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
511					int rowsize, int groupsize,
512					const void *buf, size_t len, bool ascii)
513{
514}
515#endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
516
517#endif