coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
loglevel.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #ifndef LOGLEVEL_H
4 #define LOGLEVEL_H
5 
6 /**
7  * @file loglevel.h
8  *
9  * \brief Definitions of the log levels to be used in printk calls.
10  *
11  * Safe for inclusion in assembly.
12  *
13  */
14 
15 /**
16  * \brief BIOS_EMERG - Emergency / Fatal
17  *
18  * Log level for when the system is entirely unusable. To be used when execution
19  * is halting as a result of the failure. No further instructions should run.
20  *
21  * Example - End of all debug output / death notice.
22  *
23  * @{
24  */
25 #define BIOS_EMERG 0
26 /** @} */
27 
28 /**
29  * \brief BIOS_ALERT - Dying / Unrecoverable
30  *
31  * Log level for when the system is certainly in the process of dying.
32  * To be used when execution will eventually halt as a result of the
33  * failure, but the system can still output valuable debugging
34  * information.
35  *
36  * Example - Ram initialization fails, dumping relevant POST codes and
37  * information
38  *
39  * @{
40  */
41 #define BIOS_ALERT 1
42 /** @} */
43 
44 /**
45  * \brief BIOS_CRIT - Recovery unlikely
46  *
47  * Log level for when the system has experienced a dire issue in essential
48  * components. To be used when boot will probably be unsuccessful as a
49  * result of the failure, but recovery/retry can be attempted.
50  *
51  * Example - MSR failures, SMM/SMI failures.
52  * or
53  *
54  * @{
55  */
56 #define BIOS_CRIT 2
57 /** @} */
58 
59 /**
60  * \brief BIOS_ERR - System in incomplete state.
61  *
62  * Log level for when the system has experienced an issue that may not preclude
63  * a successful boot. To be used when coreboot execution may still succeed,
64  * but the error places some non-essential portion of the machine in a broken
65  * state that will be noticed downstream.
66  *
67  * Example - Payload could still load, but will be missing access to integral
68  * components such as drives.
69  *
70  * @{
71  */
72 #define BIOS_ERR 3
73 /** @} */
74 
75 /**
76  * \brief BIOS_WARNING - Bad configuration
77  *
78  * Log level for when the system has noticed an issue that most likely will
79  * not preclude a successful boot. To be used when something is wrong, and
80  * would likely be noticed by an end user.
81  *
82  * Example - Bad ME firmware, bad microcode, mis-clocked CPU
83  *
84  * @{
85  */
86 #define BIOS_WARNING 4
87 /** @} */
88 
89 /**
90  * \brief BIOS_NOTICE - Unexpected but relatively insignificant
91  *
92  * Log level for when the system has noticed an issue that is an edge case,
93  * but is handled and is recoverable. To be used when an end-user would likely
94  * not notice.
95  *
96  * Example - Hardware was misconfigured, but is promptly fixed.
97  *
98  * @{
99  */
100 #define BIOS_NOTICE 5
101 /** @} */
102 
103 /**
104  * \brief BIOS_INFO - Expected events.
105  *
106  * Log level for when the system has experienced some typical event.
107  * Messages should be superficial in nature.
108  *
109  * Example - Success messages. Status messages.
110  *
111  * @{
112  */
113 #define BIOS_INFO 6
114 /** @} */
115 
116 /**
117  * \brief BIOS_DEBUG - Verbose output
118  *
119  * Log level for details of a method. Messages may be dense,
120  * but should not be excessive. Messages should be detailed enough
121  * that this level provides sufficient details to diagnose a problem,
122  * but not necessarily enough to fix it.
123  *
124  * Example - Printing of important variables.
125  *
126  * @{
127  */
128 #define BIOS_DEBUG 7
129 /** @} */
130 
131 /**
132  * \brief BIOS_SPEW - Excessively verbose output
133  *
134  * Log level for intricacies of a method. Messages might contain raw
135  * data and will produce large logs. Developers should try to make sure
136  * that this level is not useful to anyone besides developers.
137  *
138  * Example - Data dumps.
139  *
140  * @{
141  */
142 #define BIOS_SPEW 8
143 /** @} */
144 
145 /**
146  * \brief BIOS_NEVER - Muted log level.
147  *
148  * Roughly equal to commenting out a printk statement. Because a user
149  * should not set their log level higher than 8, these statements
150  * are never printed.
151  *
152  * Example - A developer might locally define MY_LOGLEVEL to BIOS_SPEW,
153  * and later replace it with BIOS_NEVER as to mute their debug output.
154  *
155  * @{
156  */
157 #define BIOS_NEVER 9
158 /** @} */
159 
160 #ifndef __ASSEMBLER__
161 
162 /*
163  * When printing logs, lines should be printed with the following prefixes in
164  * front of them according to the BIOS_LOG_PREFIX_PATTERN printf() pattern.
165  */
166 #define BIOS_LOG_PREFIX_PATTERN "[%.5s] "
167 #define BIOS_LOG_PREFIX_MAX_LEVEL BIOS_SPEW
168 static const char bios_log_prefix[BIOS_LOG_PREFIX_MAX_LEVEL + 1][5] = {
169  /* Note: These strings are *not* null-terminated to save space. */
170  [BIOS_EMERG] = "EMERG",
171  [BIOS_ALERT] = "ALERT",
172  [BIOS_CRIT] = "CRIT ",
173  [BIOS_ERR] = "ERROR",
174  [BIOS_WARNING] = "WARN ",
175  [BIOS_NOTICE] = "NOTE ",
176  [BIOS_INFO] = "INFO ",
177  [BIOS_DEBUG] = "DEBUG",
178  [BIOS_SPEW] = "SPEW ",
179 };
180 
181 /*
182  * When printing to terminals supporting ANSI escape sequences, the following
183  * escape sequences can be printed to highlight the respective log levels
184  * according to the BIOS_LOG_ESCAPE_PATTERN printf() pattern. At the end of a
185  * line, highlighting should be reset with the BIOS_LOG_ESCAPE_RESET seqence.
186  *
187  * The escape sequences used here set flags with the following meanings:
188  * 1 = bold, 4 = underlined, 5 = blinking, 7 = inverted
189  */
190 #define BIOS_LOG_ESCAPE_PATTERN "\x1b[%sm"
191 #define BIOS_LOG_ESCAPE_RESET "\x1b[0m"
192 static const char bios_log_escape[BIOS_LOG_PREFIX_MAX_LEVEL + 1][8] = {
193  [BIOS_EMERG] = "1;4;5;7",
194  [BIOS_ALERT] = "1;4;7",
195  [BIOS_CRIT] = "1;7",
196  [BIOS_ERR] = "7",
197  [BIOS_WARNING] = "1;4",
198  [BIOS_NOTICE] = "1",
199  [BIOS_INFO] = "0",
200  [BIOS_DEBUG] = "0",
201  [BIOS_SPEW] = "0",
202 };
203 
204 /*
205  * When storing console logs somewhere for later retrieval, log level prefixes
206  * and escape sequences should not be stored raw to preserve space. Instead, a
207  * non-printable control character marker is inserted into the log to indicate
208  * the log level. Decoders reading this character should translate it back into
209  * the respective escape sequence and prefix. If a decoder doesn't support this
210  * feature, the non-printable character should usually be harmless.
211  */
212 #define BIOS_LOG_MARKER_START 0x10
213 #define BIOS_LOG_MARKER_END (BIOS_LOG_MARKER_START + BIOS_LOG_PREFIX_MAX_LEVEL)
214 #define BIOS_LOG_IS_MARKER(c) ((c) >= BIOS_LOG_MARKER_START && (c) <= BIOS_LOG_MARKER_END)
215 #define BIOS_LOG_LEVEL_TO_MARKER(level) (BIOS_LOG_MARKER_START + (level))
216 #define BIOS_LOG_MARKER_TO_LEVEL(c) ((c) - BIOS_LOG_MARKER_START)
217 
218 #endif /* __ASSEMBLER__ */
219 
220 #endif /* LOGLEVEL_H */
static const char bios_log_prefix[BIOS_LOG_PREFIX_MAX_LEVEL+1][5]
Definition: loglevel.h:168
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_CRIT
BIOS_CRIT - Recovery unlikely.
Definition: loglevel.h:56
#define BIOS_LOG_PREFIX_MAX_LEVEL
Definition: loglevel.h:167
#define BIOS_NOTICE
BIOS_NOTICE - Unexpected but relatively insignificant.
Definition: loglevel.h:100
#define BIOS_ALERT
BIOS_ALERT - Dying / Unrecoverable.
Definition: loglevel.h:41
#define BIOS_EMERG
BIOS_EMERG - Emergency / Fatal.
Definition: loglevel.h:25
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define BIOS_SPEW
BIOS_SPEW - Excessively verbose output.
Definition: loglevel.h:142
static const char bios_log_escape[BIOS_LOG_PREFIX_MAX_LEVEL+1][8]
Definition: loglevel.h:192
#define BIOS_WARNING
BIOS_WARNING - Bad configuration.
Definition: loglevel.h:86