CBMEM CONSOLE: Add code using the new console driver.
[coreboot.git] / src / console / console.c
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 #include <console/console.h>
21 #include <build.h>
22 #include <arch/hlt.h>
23 #include <arch/io.h>
24
25 #ifndef __PRE_RAM__
26 #include <string.h>
27 #include <pc80/mc146818rtc.h>
28
29 /* initialize the console */
30 void console_init(void)
31 {
32         struct console_driver *driver;
33         if(get_option(&console_loglevel, "debug_level"))
34                 console_loglevel=CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
35
36         for(driver = console_drivers; driver < econsole_drivers; driver++) {
37                 if (!driver->init)
38                         continue;
39                 driver->init();
40         }
41 }
42
43 void console_tx_flush(void)
44 {
45         struct console_driver *driver;
46         for(driver = console_drivers; driver < econsole_drivers; driver++) {
47                 if (!driver->tx_flush)
48                         continue;
49                 driver->tx_flush();
50         }
51 }
52
53 static void __console_tx_byte(unsigned char byte)
54 {
55         struct console_driver *driver;
56         for(driver = console_drivers; driver < econsole_drivers; driver++) {
57                 driver->tx_byte(byte);
58         }
59 }
60
61 void console_tx_byte(unsigned char byte)
62 {
63         if (byte == '\n')
64                 __console_tx_byte('\r');
65         __console_tx_byte(byte);
66 }
67
68 unsigned char console_rx_byte(void)
69 {
70         struct console_driver *driver;
71         for(driver = console_drivers; driver < econsole_drivers; driver++) {
72                 if (driver->tst_byte)
73                         break;
74         }
75         if (driver == econsole_drivers)
76                 return 0;
77         while (!driver->tst_byte());
78         return driver->rx_byte();
79 }
80
81 int console_tst_byte(void)
82 {
83         struct console_driver *driver;
84         for(driver = console_drivers; driver < econsole_drivers; driver++)
85                 if (driver->tst_byte)
86                         return driver->tst_byte();
87         return 0;
88 }
89
90 #else // __PRE_RAM__   ^^^ NOT defined   vvv defined
91
92 void console_init(void)
93 {
94 #if CONFIG_USBDEBUG
95         enable_usbdebug(CONFIG_USBDEBUG_DEFAULT_PORT);
96         early_usbdebug_init();
97 #endif
98 #if CONFIG_CONSOLE_SERIAL8250
99         uart_init();
100 #endif
101 #if CONFIG_DRIVERS_OXFORD_OXPCIE && CONFIG_CONSOLE_SERIAL8250MEM
102         oxford_init();
103 #endif
104 #if CONFIG_CONSOLE_NE2K
105         ne2k_init(CONFIG_CONSOLE_NE2K_IO_PORT);
106 #endif
107 #if CONFIG_CONSOLE_CBMEM
108         cbmemc_init();
109 #endif
110         static const char console_test[] =
111                 "\n\ncoreboot-"
112                 COREBOOT_VERSION
113                 COREBOOT_EXTRA_VERSION
114                 " "
115                 COREBOOT_BUILD
116                 " starting...\n";
117         print_info(console_test);
118 }
119 #endif