1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * internal.h - printk internal definitions
4 */
5 #include <linux/percpu.h>
6
7 #if defined(CONFIG_PRINTK) && defined(CONFIG_SYSCTL)
8 void __init printk_sysctl_init(void);
9 int devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write,
10 void *buffer, size_t *lenp, loff_t *ppos);
11 #else
12 #define printk_sysctl_init() do { } while (0)
13 #endif
14
15 #ifdef CONFIG_PRINTK
16
17 #ifdef CONFIG_PRINTK_CALLER
18 #define PRINTK_PREFIX_MAX 48
19 #else
20 #define PRINTK_PREFIX_MAX 32
21 #endif
22
23 /*
24 * the maximum size of a formatted record (i.e. with prefix added
25 * per line and dropped messages or in extended message format)
26 */
27 #define PRINTK_MESSAGE_MAX 2048
28
29 /* the maximum size allowed to be reserved for a record */
30 #define PRINTKRB_RECORD_MAX 1024
31
32 /* Flags for a single printk record. */
33 enum printk_info_flags {
34 LOG_NEWLINE = 2, /* text ended with a newline */
35 LOG_CONT = 8, /* text is a fragment of a continuation line */
36 };
37
38 __printf(4, 0)
39 int vprintk_store(int facility, int level,
40 const struct dev_printk_info *dev_info,
41 const char *fmt, va_list args);
42
43 __printf(1, 0) int vprintk_default(const char *fmt, va_list args);
44 __printf(1, 0) int vprintk_deferred(const char *fmt, va_list args);
45
46 bool printk_percpu_data_ready(void);
47
48 #define printk_safe_enter_irqsave(flags) \
49 do { \
50 local_irq_save(flags); \
51 __printk_safe_enter(); \
52 } while (0)
53
54 #define printk_safe_exit_irqrestore(flags) \
55 do { \
56 __printk_safe_exit(); \
57 local_irq_restore(flags); \
58 } while (0)
59
60 void defer_console_output(void);
61
62 u16 printk_parse_prefix(const char *text, int *level,
63 enum printk_info_flags *flags);
64 #else
65
66 #define PRINTK_PREFIX_MAX 0
67 #define PRINTK_MESSAGE_MAX 0
68 #define PRINTKRB_RECORD_MAX 0
69
70 /*
71 * In !PRINTK builds we still export console_sem
72 * semaphore and some of console functions (console_unlock()/etc.), so
73 * printk-safe must preserve the existing local IRQ guarantees.
74 */
75 #define printk_safe_enter_irqsave(flags) local_irq_save(flags)
76 #define printk_safe_exit_irqrestore(flags) local_irq_restore(flags)
77
printk_percpu_data_ready(void)78 static inline bool printk_percpu_data_ready(void) { return false; }
79 #endif /* CONFIG_PRINTK */
80
81 /**
82 * struct printk_buffers - Buffers to read/format/output printk messages.
83 * @outbuf: After formatting, contains text to output.
84 * @scratchbuf: Used as temporary ringbuffer reading and string-print space.
85 */
86 struct printk_buffers {
87 char outbuf[PRINTK_MESSAGE_MAX];
88 char scratchbuf[PRINTKRB_RECORD_MAX];
89 };
90
91 /**
92 * struct printk_message - Container for a prepared printk message.
93 * @pbufs: printk buffers used to prepare the message.
94 * @outbuf_len: The length of prepared text in @pbufs->outbuf to output. This
95 * does not count the terminator. A value of 0 means there is
96 * nothing to output and this record should be skipped.
97 * @seq: The sequence number of the record used for @pbufs->outbuf.
98 * @dropped: The number of dropped records from reading @seq.
99 */
100 struct printk_message {
101 struct printk_buffers *pbufs;
102 unsigned int outbuf_len;
103 u64 seq;
104 unsigned long dropped;
105 };
106
107 bool other_cpu_in_panic(void);
108