xref: /openbmc/linux/kernel/printk/internal.h (revision 9659281c)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * internal.h - printk internal definitions
4  */
5 #include <linux/percpu.h>
6 
7 #ifdef CONFIG_PRINTK
8 
9 #define PRINTK_SAFE_CONTEXT_MASK	0x007ffffff
10 #define PRINTK_NMI_DIRECT_CONTEXT_MASK	0x008000000
11 #define PRINTK_NMI_CONTEXT_MASK		0xff0000000
12 
13 #define PRINTK_NMI_CONTEXT_OFFSET	0x010000000
14 
15 __printf(4, 0)
16 int vprintk_store(int facility, int level,
17 		  const struct dev_printk_info *dev_info,
18 		  const char *fmt, va_list args);
19 
20 __printf(1, 0) int vprintk_default(const char *fmt, va_list args);
21 __printf(1, 0) int vprintk_deferred(const char *fmt, va_list args);
22 void __printk_safe_enter(void);
23 void __printk_safe_exit(void);
24 
25 void printk_safe_init(void);
26 bool printk_percpu_data_ready(void);
27 
28 #define printk_safe_enter_irqsave(flags)	\
29 	do {					\
30 		local_irq_save(flags);		\
31 		__printk_safe_enter();		\
32 	} while (0)
33 
34 #define printk_safe_exit_irqrestore(flags)	\
35 	do {					\
36 		__printk_safe_exit();		\
37 		local_irq_restore(flags);	\
38 	} while (0)
39 
40 #define printk_safe_enter_irq()		\
41 	do {					\
42 		local_irq_disable();		\
43 		__printk_safe_enter();		\
44 	} while (0)
45 
46 #define printk_safe_exit_irq()			\
47 	do {					\
48 		__printk_safe_exit();		\
49 		local_irq_enable();		\
50 	} while (0)
51 
52 void defer_console_output(void);
53 
54 #else
55 
56 /*
57  * In !PRINTK builds we still export console_sem
58  * semaphore and some of console functions (console_unlock()/etc.), so
59  * printk-safe must preserve the existing local IRQ guarantees.
60  */
61 #define printk_safe_enter_irqsave(flags) local_irq_save(flags)
62 #define printk_safe_exit_irqrestore(flags) local_irq_restore(flags)
63 
64 #define printk_safe_enter_irq() local_irq_disable()
65 #define printk_safe_exit_irq() local_irq_enable()
66 
67 static inline void printk_safe_init(void) { }
68 static inline bool printk_percpu_data_ready(void) { return false; }
69 #endif /* CONFIG_PRINTK */
70