xref: /dragonfly/sys/dev/drm/include/linux/printk.h (revision 6ab64ab6)
1 /*
2  * Copyright (c) 2015 François Tigeot
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice unmodified, this list of conditions, and the following
10  *    disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef _LINUX_PRINTK_H_
28 #define _LINUX_PRINTK_H_
29 
30 #include <sys/types.h>
31 #include <sys/systm.h>
32 
33 #define printk(X...)	kprintf(X)
34 
35 #define KERN_CONT	""
36 #define KERN_EMERG	"<0>"
37 #define KERN_ALERT	"<1>"
38 #define KERN_CRIT	"<2>"
39 #define KERN_ERR	"<3>"
40 #define KERN_WARNING	"<4>"
41 #define KERN_NOTICE	"<5>"
42 #define KERN_INFO	"<6>"
43 #define KERN_DEBUG	"<7>"
44 
45 #ifndef pr_fmt
46 #define pr_fmt(fmt) fmt
47 #endif
48 
49 #define pr_emerg(fmt, ...) \
50 	printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
51 #define pr_alert(fmt, ...) \
52 	printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
53 #define pr_crit(fmt, ...) \
54 	printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
55 #define pr_err(fmt, ...) \
56 	printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
57 #define pr_warning(fmt, ...) \
58 	printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
59 #define pr_warn pr_warning
60 #define pr_notice(fmt, ...) \
61 	printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
62 #define pr_info(fmt, ...) \
63 	printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
64 #define pr_cont(fmt, ...) \
65 	printk(KERN_CONT fmt, ##__VA_ARGS__)
66 
67 /* pr_devel() should produce zero code unless DEBUG is defined */
68 #ifdef DEBUG
69 #define pr_devel(fmt, ...) \
70 	printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
71 #else
72 #define pr_devel(fmt, ...) \
73 	({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
74 #endif
75 
76 #define pr_debug(fmt, ...)	printk(KERN_DEBUG # fmt, ##__VA_ARGS__)
77 
78 /*
79  * Print a one-time message (analogous to WARN_ONCE() et al):
80  */
81 #define printk_once(x...)			\
82 ({						\
83 	static bool __print_once;		\
84 						\
85 	if (!__print_once) {			\
86 		__print_once = true;		\
87 		printk(x);			\
88 	}					\
89 })
90 
91 #define pr_info_once(fmt, ...) do {		\
92 	static bool __printed_once;		\
93 						\
94 	if (!__printed_once) {			\
95 		__printed_once = true;		\
96 		kprintf(fmt, ##__VA_ARGS__);	\
97 	}					\
98 } while (0)
99 
100 enum {
101 	DUMP_PREFIX_NONE,
102 	DUMP_PREFIX_ADDRESS,
103 	DUMP_PREFIX_OFFSET
104 };
105 
106 #endif	/* _LINUX_PRINTK_H_ */
107