CBMEM CONSOLE: Add CBMEM console driver implementation.
[coreboot.git] / src / include / console / console.h
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2003 Eric Biederman
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19
20 #ifndef CONSOLE_CONSOLE_H_
21 #define CONSOLE_CONSOLE_H_
22
23 #include <stdint.h>
24 #include <console/loglevel.h>
25 #include <console/post_codes.h>
26
27 #if CONFIG_CONSOLE_SERIAL8250 || CONFIG_CONSOLE_SERIAL8250MEM
28 #include <uart8250.h>
29 #endif
30 #if CONFIG_USBDEBUG
31 #include <usbdebug.h>
32 #endif
33 #if CONFIG_CONSOLE_NE2K
34 #include <console/ne2k.h>
35 #endif
36 #if CONFIG_CONSOLE_CBMEM
37 #include <console/cbmem_console.h>
38 #endif
39
40 #ifndef __PRE_RAM__
41 void console_tx_byte(unsigned char byte);
42 void console_tx_flush(void);
43 unsigned char console_rx_byte(void);
44 int console_tst_byte(void);
45 struct console_driver {
46         void (*init)(void);
47         void (*tx_byte)(unsigned char byte);
48         void (*tx_flush)(void);
49         unsigned char (*rx_byte)(void);
50         int (*tst_byte)(void);
51 };
52
53 #define __console       __attribute__((used, __section__ (".rodata.console_drivers")))
54
55 /* Defined by the linker... */
56 extern struct console_driver console_drivers[];
57 extern struct console_driver econsole_drivers[];
58
59 extern int console_loglevel;
60 #else
61 /* __PRE_RAM__ */
62 /* Using a global varible can cause problems when we reset the stack
63  * from cache as ram to ram. If we make this a define USE_SHARED_STACK
64  * we could use the same code on all architectures.
65  */
66 #define console_loglevel CONFIG_DEFAULT_CONSOLE_LOGLEVEL
67 #endif
68
69 #ifndef __ROMCC__
70 void console_init(void);
71 void post_code(u8 value);
72 void __attribute__ ((noreturn)) die(const char *msg);
73 int do_printk(int msg_level, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
74
75 #undef WE_CLEANED_UP_ALL_SIDE_EFFECTS
76 /* We saw some strange effects in the past like coreboot crashing while
77  * disabling cache as ram for a maximum console log level of 6 and above while
78  * it worked fine without. In order to catch such issues reliably we are
79  * always doing a function call to do_printk with the full number of arguments.
80  * Our favorite reason to do it this way was:
81  *   disable_car();
82  *   printk(BIOS_DEBUG, "CAR disabled\n"); // oops, garbage stack pointer
83  *   move_stack();
84  * This slightly increases the code size and some unprinted strings will end
85  * up in the final coreboot binary (most of them compressed). If you want to
86  * avoid this, do a
87  * #define WE_CLEANED_UP_ALL_SIDE_EFFECTS
88  */
89 #ifdef WE_CLEANED_UP_ALL_SIDE_EFFECTS
90
91 #define printk(LEVEL, fmt, args...)                             \
92         do {                                                    \
93                 if (CONFIG_MAXIMUM_CONSOLE_LOGLEVEL >= LEVEL) { \
94                         do_printk(LEVEL, fmt, ##args);          \
95                 }                                               \
96         } while(0)
97
98 #else
99
100 #define printk(LEVEL, fmt, args...)                             \
101         do {                                                    \
102                 if (CONFIG_MAXIMUM_CONSOLE_LOGLEVEL >= LEVEL) { \
103                         do_printk(LEVEL, fmt, ##args);          \
104                 } else {                                        \
105                         do_printk(BIOS_NEVER, fmt, ##args);     \
106                 }                                               \
107         } while(0)
108 #endif
109
110 #define print_emerg(STR)         printk(BIOS_EMERG,  "%s", (STR))
111 #define print_alert(STR)         printk(BIOS_ALERT,  "%s", (STR))
112 #define print_crit(STR)          printk(BIOS_CRIT,   "%s", (STR))
113 #define print_err(STR)           printk(BIOS_ERR,    "%s", (STR))
114 #define print_warning(STR)       printk(BIOS_WARNING,"%s", (STR))
115 #define print_notice(STR)        printk(BIOS_NOTICE, "%s", (STR))
116 #define print_info(STR)          printk(BIOS_INFO,   "%s", (STR))
117 #define print_debug(STR)         printk(BIOS_DEBUG,  "%s", (STR))
118 #define print_spew(STR)          printk(BIOS_SPEW,   "%s", (STR))
119
120 #define print_emerg_char(CH)     printk(BIOS_EMERG,  "%c", (CH))
121 #define print_alert_char(CH)     printk(BIOS_ALERT,  "%c", (CH))
122 #define print_crit_char(CH)      printk(BIOS_CRIT,   "%c", (CH))
123 #define print_err_char(CH)       printk(BIOS_ERR,    "%c", (CH))
124 #define print_warning_char(CH)   printk(BIOS_WARNING,"%c", (CH))
125 #define print_notice_char(CH)    printk(BIOS_NOTICE, "%c", (CH))
126 #define print_info_char(CH)      printk(BIOS_INFO,   "%c", (CH))
127 #define print_debug_char(CH)     printk(BIOS_DEBUG,  "%c", (CH))
128 #define print_spew_char(CH)      printk(BIOS_SPEW,   "%c", (CH))
129
130 #define print_emerg_hex8(HEX)    printk(BIOS_EMERG,  "%02x",  (HEX))
131 #define print_alert_hex8(HEX)    printk(BIOS_ALERT,  "%02x",  (HEX))
132 #define print_crit_hex8(HEX)     printk(BIOS_CRIT,   "%02x",  (HEX))
133 #define print_err_hex8(HEX)      printk(BIOS_ERR,    "%02x",  (HEX))
134 #define print_warning_hex8(HEX)  printk(BIOS_WARNING,"%02x",  (HEX))
135 #define print_notice_hex8(HEX)   printk(BIOS_NOTICE, "%02x",  (HEX))
136 #define print_info_hex8(HEX)     printk(BIOS_INFO,   "%02x",  (HEX))
137 #define print_debug_hex8(HEX)    printk(BIOS_DEBUG,  "%02x",  (HEX))
138 #define print_spew_hex8(HEX)     printk(BIOS_SPEW,   "%02x",  (HEX))
139
140 #define print_emerg_hex16(HEX)   printk(BIOS_EMERG,  "%04x", (HEX))
141 #define print_alert_hex16(HEX)   printk(BIOS_ALERT,  "%04x", (HEX))
142 #define print_crit_hex16(HEX)    printk(BIOS_CRIT,   "%04x", (HEX))
143 #define print_err_hex16(HEX)     printk(BIOS_ERR,    "%04x", (HEX))
144 #define print_warning_hex16(HEX) printk(BIOS_WARNING,"%04x", (HEX))
145 #define print_notice_hex16(HEX)  printk(BIOS_NOTICE, "%04x", (HEX))
146 #define print_info_hex16(HEX)    printk(BIOS_INFO,   "%04x", (HEX))
147 #define print_debug_hex16(HEX)   printk(BIOS_DEBUG,  "%04x", (HEX))
148 #define print_spew_hex16(HEX)    printk(BIOS_SPEW,   "%04x", (HEX))
149
150 #define print_emerg_hex32(HEX)   printk(BIOS_EMERG,  "%08x", (HEX))
151 #define print_alert_hex32(HEX)   printk(BIOS_ALERT,  "%08x", (HEX))
152 #define print_crit_hex32(HEX)    printk(BIOS_CRIT,   "%08x", (HEX))
153 #define print_err_hex32(HEX)     printk(BIOS_ERR,    "%08x", (HEX))
154 #define print_warning_hex32(HEX) printk(BIOS_WARNING,"%08x", (HEX))
155 #define print_notice_hex32(HEX)  printk(BIOS_NOTICE, "%08x", (HEX))
156 #define print_info_hex32(HEX)    printk(BIOS_INFO,   "%08x", (HEX))
157 #define print_debug_hex32(HEX)   printk(BIOS_DEBUG,  "%08x", (HEX))
158 #define print_spew_hex32(HEX)    printk(BIOS_SPEW,   "%08x", (HEX))
159
160 #else
161
162 /* __ROMCC__ */
163
164 #define print_emerg(STR)         __console_tx_string(BIOS_EMERG, STR)
165 #define print_alert(STR)         __console_tx_string(BIOS_ALERT, STR)
166 #define print_crit(STR)          __console_tx_string(BIOS_CRIT, STR)
167 #define print_err(STR)           __console_tx_string(BIOS_ERR, STR)
168 #define print_warning(STR)       __console_tx_string(BIOS_WARNING, STR)
169 #define print_notice(STR)        __console_tx_string(BIOS_NOTICE, STR)
170 #define print_info(STR)          __console_tx_string(BIOS_INFO, STR)
171 #define print_debug(STR)         __console_tx_string(BIOS_DEBUG, STR)
172 #define print_spew(STR)          __console_tx_string(BIOS_SPEW, STR)
173
174 #define print_emerg_char(CH)     __console_tx_char(BIOS_EMERG, CH)
175 #define print_alert_char(CH)     __console_tx_char(BIOS_ALERT, CH)
176 #define print_crit_char(CH)      __console_tx_char(BIOS_CRIT, CH)
177 #define print_err_char(CH)       __console_tx_char(BIOS_ERR, CH)
178 #define print_warning_char(CH)   __console_tx_char(BIOS_WARNING, CH)
179 #define print_notice_char(CH)    __console_tx_char(BIOS_NOTICE, CH)
180 #define print_info_char(CH)      __console_tx_char(BIOS_INFO, CH)
181 #define print_debug_char(CH)     __console_tx_char(BIOS_DEBUG, CH)
182 #define print_spew_char(CH)      __console_tx_char(BIOS_SPEW, CH)
183
184 #define print_emerg_hex8(HEX)    __console_tx_hex8(BIOS_EMERG, HEX)
185 #define print_alert_hex8(HEX)    __console_tx_hex8(BIOS_ALERT, HEX)
186 #define print_crit_hex8(HEX)     __console_tx_hex8(BIOS_CRIT, HEX)
187 #define print_err_hex8(HEX)      __console_tx_hex8(BIOS_ERR, HEX)
188 #define print_warning_hex8(HEX)  __console_tx_hex8(BIOS_WARNING, HEX)
189 #define print_notice_hex8(HEX)   __console_tx_hex8(BIOS_NOTICE, HEX)
190 #define print_info_hex8(HEX)     __console_tx_hex8(BIOS_INFO, HEX)
191 #define print_debug_hex8(HEX)    __console_tx_hex8(BIOS_DEBUG, HEX)
192 #define print_spew_hex8(HEX)     __console_tx_hex8(BIOS_SPEW, HEX)
193
194 #define print_emerg_hex16(HEX)   __console_tx_hex16(BIOS_EMERG, HEX)
195 #define print_alert_hex16(HEX)   __console_tx_hex16(BIOS_ALERT, HEX)
196 #define print_crit_hex16(HEX)    __console_tx_hex16(BIOS_CRIT, HEX)
197 #define print_err_hex16(HEX)     __console_tx_hex16(BIOS_ERR, HEX)
198 #define print_warning_hex16(HEX) __console_tx_hex16(BIOS_WARNING, HEX)
199 #define print_notice_hex16(HEX)  __console_tx_hex16(BIOS_NOTICE, HEX)
200 #define print_info_hex16(HEX)    __console_tx_hex16(BIOS_INFO, HEX)
201 #define print_debug_hex16(HEX)   __console_tx_hex16(BIOS_DEBUG, HEX)
202 #define print_spew_hex16(HEX)    __console_tx_hex16(BIOS_SPEW, HEX)
203
204 #define print_emerg_hex32(HEX)   __console_tx_hex32(BIOS_EMERG, HEX)
205 #define print_alert_hex32(HEX)   __console_tx_hex32(BIOS_ALERT, HEX)
206 #define print_crit_hex32(HEX)    __console_tx_hex32(BIOS_CRIT, HEX)
207 #define print_err_hex32(HEX)     __console_tx_hex32(BIOS_ERR, HEX)
208 #define print_warning_hex32(HEX) __console_tx_hex32(BIOS_WARNING, HEX)
209 #define print_notice_hex32(HEX)  __console_tx_hex32(BIOS_NOTICE, HEX)
210 #define print_info_hex32(HEX)    __console_tx_hex32(BIOS_INFO, HEX)
211 #define print_debug_hex32(HEX)   __console_tx_hex32(BIOS_DEBUG, HEX)
212 #define print_spew_hex32(HEX)    __console_tx_hex32(BIOS_SPEW, HEX)
213
214 #include "arch/x86/lib/romcc_console.c"
215
216 #endif /* __ROMCC__ */
217
218 #endif /* CONSOLE_CONSOLE_H_ */