11ccea77eSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
242a0bb3fSPetr Mladek /*
342a0bb3fSPetr Mladek * internal.h - printk internal definitions
442a0bb3fSPetr Mladek */
542a0bb3fSPetr Mladek #include <linux/percpu.h>
642a0bb3fSPetr Mladek
7faaa357aSXiaoming Ni #if defined(CONFIG_PRINTK) && defined(CONFIG_SYSCTL)
8faaa357aSXiaoming Ni void __init printk_sysctl_init(void);
9fdcd4073SXiaoming Ni int devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write,
10fdcd4073SXiaoming Ni void *buffer, size_t *lenp, loff_t *ppos);
11faaa357aSXiaoming Ni #else
12faaa357aSXiaoming Ni #define printk_sysctl_init() do { } while (0)
13faaa357aSXiaoming Ni #endif
14faaa357aSXiaoming Ni
15099f1c84SSergey Senozhatsky #ifdef CONFIG_PRINTK
16099f1c84SSergey Senozhatsky
172364b406SJohn Ogness #ifdef CONFIG_PRINTK_CALLER
18b0975c47SJohn Ogness #define PRINTK_PREFIX_MAX 48
192364b406SJohn Ogness #else
20b0975c47SJohn Ogness #define PRINTK_PREFIX_MAX 32
212364b406SJohn Ogness #endif
222364b406SJohn Ogness
23b0975c47SJohn Ogness /*
24b0975c47SJohn Ogness * the maximum size of a formatted record (i.e. with prefix added
25b0975c47SJohn Ogness * per line and dropped messages or in extended message format)
26b0975c47SJohn Ogness */
27b0975c47SJohn Ogness #define PRINTK_MESSAGE_MAX 2048
282364b406SJohn Ogness
292364b406SJohn Ogness /* the maximum size allowed to be reserved for a record */
30b0975c47SJohn Ogness #define PRINTKRB_RECORD_MAX 1024
312364b406SJohn Ogness
32a1ad4b8aSChris Down /* Flags for a single printk record. */
33a1ad4b8aSChris Down enum printk_info_flags {
34a1ad4b8aSChris Down LOG_NEWLINE = 2, /* text ended with a newline */
35a1ad4b8aSChris Down LOG_CONT = 8, /* text is a fragment of a continuation line */
36a1ad4b8aSChris Down };
37a1ad4b8aSChris Down
3874caba7fSJohn Ogness __printf(4, 0)
3903fc7f9cSPetr Mladek int vprintk_store(int facility, int level,
4074caba7fSJohn Ogness const struct dev_printk_info *dev_info,
4103fc7f9cSPetr Mladek const char *fmt, va_list args);
4203fc7f9cSPetr Mladek
43099f1c84SSergey Senozhatsky __printf(1, 0) int vprintk_default(const char *fmt, va_list args);
44719f6a70SPetr Mladek __printf(1, 0) int vprintk_deferred(const char *fmt, va_list args);
45099f1c84SSergey Senozhatsky
46ab6f762fSSergey Senozhatsky bool printk_percpu_data_ready(void);
47ab6f762fSSergey Senozhatsky
48099f1c84SSergey Senozhatsky #define printk_safe_enter_irqsave(flags) \
49099f1c84SSergey Senozhatsky do { \
50099f1c84SSergey Senozhatsky local_irq_save(flags); \
51099f1c84SSergey Senozhatsky __printk_safe_enter(); \
52099f1c84SSergey Senozhatsky } while (0)
53099f1c84SSergey Senozhatsky
54099f1c84SSergey Senozhatsky #define printk_safe_exit_irqrestore(flags) \
55099f1c84SSergey Senozhatsky do { \
56099f1c84SSergey Senozhatsky __printk_safe_exit(); \
57099f1c84SSergey Senozhatsky local_irq_restore(flags); \
58099f1c84SSergey Senozhatsky } while (0)
59099f1c84SSergey Senozhatsky
6003fc7f9cSPetr Mladek void defer_console_output(void);
6103fc7f9cSPetr Mladek
62f3d75cf5SChris Down u16 printk_parse_prefix(const char *text, int *level,
63f3d75cf5SChris Down enum printk_info_flags *flags);
64099f1c84SSergey Senozhatsky #else
65099f1c84SSergey Senozhatsky
66b0975c47SJohn Ogness #define PRINTK_PREFIX_MAX 0
67b0975c47SJohn Ogness #define PRINTK_MESSAGE_MAX 0
68b0975c47SJohn Ogness #define PRINTKRB_RECORD_MAX 0
692364b406SJohn Ogness
70099f1c84SSergey Senozhatsky /*
71996e9666SJohn Ogness * In !PRINTK builds we still export console_sem
72099f1c84SSergey Senozhatsky * semaphore and some of console functions (console_unlock()/etc.), so
73099f1c84SSergey Senozhatsky * printk-safe must preserve the existing local IRQ guarantees.
74099f1c84SSergey Senozhatsky */
75099f1c84SSergey Senozhatsky #define printk_safe_enter_irqsave(flags) local_irq_save(flags)
76099f1c84SSergey Senozhatsky #define printk_safe_exit_irqrestore(flags) local_irq_restore(flags)
77099f1c84SSergey Senozhatsky
printk_percpu_data_ready(void)78ab6f762fSSergey Senozhatsky static inline bool printk_percpu_data_ready(void) { return false; }
79099f1c84SSergey Senozhatsky #endif /* CONFIG_PRINTK */
80daaab5b5SJohn Ogness
81daaab5b5SJohn Ogness /**
82daaab5b5SJohn Ogness * struct printk_buffers - Buffers to read/format/output printk messages.
83daaab5b5SJohn Ogness * @outbuf: After formatting, contains text to output.
84daaab5b5SJohn Ogness * @scratchbuf: Used as temporary ringbuffer reading and string-print space.
85daaab5b5SJohn Ogness */
86daaab5b5SJohn Ogness struct printk_buffers {
87b0975c47SJohn Ogness char outbuf[PRINTK_MESSAGE_MAX];
88b0975c47SJohn Ogness char scratchbuf[PRINTKRB_RECORD_MAX];
89daaab5b5SJohn Ogness };
902830eec1SJohn Ogness
912830eec1SJohn Ogness /**
922830eec1SJohn Ogness * struct printk_message - Container for a prepared printk message.
932830eec1SJohn Ogness * @pbufs: printk buffers used to prepare the message.
942830eec1SJohn Ogness * @outbuf_len: The length of prepared text in @pbufs->outbuf to output. This
952830eec1SJohn Ogness * does not count the terminator. A value of 0 means there is
962830eec1SJohn Ogness * nothing to output and this record should be skipped.
972830eec1SJohn Ogness * @seq: The sequence number of the record used for @pbufs->outbuf.
982830eec1SJohn Ogness * @dropped: The number of dropped records from reading @seq.
992830eec1SJohn Ogness */
1002830eec1SJohn Ogness struct printk_message {
1012830eec1SJohn Ogness struct printk_buffers *pbufs;
1022830eec1SJohn Ogness unsigned int outbuf_len;
1032830eec1SJohn Ogness u64 seq;
1042830eec1SJohn Ogness unsigned long dropped;
1052830eec1SJohn Ogness };
106*132a90d1SJohn Ogness
107*132a90d1SJohn Ogness bool other_cpu_in_panic(void);
108