CBMEM CONSOLE: Add code using the new console driver.
[coreboot.git] / src / arch / x86 / lib / romstage_console.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; version 2 of
7  * the License.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
17  * MA 02110-1301 USA
18  */
19
20 #include <console/console.h>
21 #include <console/vtxprintf.h>
22 #if CONFIG_CONSOLE_SERIAL8250 || CONFIG_CONSOLE_SERIAL8250MEM
23 #include <uart8250.h>
24 #endif
25 #if CONFIG_USBDEBUG
26 #include <usbdebug.h>
27 #endif
28 #if CONFIG_CONSOLE_NE2K
29 #include <console/ne2k.h>
30 #endif
31
32 static void console_tx_byte(unsigned char byte)
33 {
34         if (byte == '\n')
35                 console_tx_byte('\r');
36
37 #if CONFIG_CONSOLE_SERIAL8250MEM
38         uart8250_mem_tx_byte(CONFIG_OXFORD_OXPCIE_BASE_ADDRESS + 0x1000, byte);
39 #endif
40 #if CONFIG_CONSOLE_SERIAL8250
41         uart8250_tx_byte(CONFIG_TTYS0_BASE, byte);
42 #endif
43 #if CONFIG_USBDEBUG
44         usbdebug_tx_byte(byte);
45 #endif
46 #if CONFIG_CONSOLE_NE2K
47         ne2k_append_data(&byte, 1, CONFIG_CONSOLE_NE2K_IO_PORT);
48 #endif
49 #if CONFIG_CONSOLE_CBMEM
50         cbmemc_tx_byte(byte);
51 #endif
52 }
53
54 static void console_tx_flush(void)
55 {
56 #if CONFIG_CONSOLE_SERIAL8250MEM
57         uart8250_mem_tx_flush(CONFIG_OXFORD_OXPCIE_BASE_ADDRESS + 0x1000);
58 #endif
59 #if CONFIG_CONSOLE_SERIAL8250
60         uart8250_tx_flush(CONFIG_TTYS0_BASE);
61 #endif
62 #if CONFIG_CONSOLE_NE2K
63         ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT);
64 #endif
65 }
66
67 int do_printk(int msg_level, const char *fmt, ...)
68 {
69         va_list args;
70         int i;
71
72         if (msg_level > console_loglevel) {
73                 return 0;
74         }
75
76         va_start(args, fmt);
77         i = vtxprintf(console_tx_byte, fmt, args);
78         va_end(args);
79
80         console_tx_flush();
81
82         return i;
83 }