diff options
author | Dave Frodin <dave.frodin@se-eng.com> | 2012-12-15 13:24:02 -0700 |
---|---|---|
committer | Anton Kochkov <anton.kochkov@gmail.com> | 2012-12-18 19:59:59 +0100 |
commit | 5056b6e612569b202c96a8a54da90879f118b7d5 (patch) | |
tree | 838042e8fd30316ddb32bd5110973d424b5cf181 | |
parent | 6bf11cf50c2b682f8c09a53af774588123b250b6 (diff) |
libpayload: Check if serial console h/w is present before using
The serial_io_havechar() and serial_io_getchar() functions will
always see keystrokes available if the serial hardware isn't
actually there. We will still output chars to non-existant
hardware to allow virtual hardware to capture them.
Change-Id: I04e85157b6b7a185448abab352b5417a798a397a
Signed-off-by: Dave Frodin <dave.frodin@se-eng.com>
Reviewed-on: http://review.coreboot.org/2040
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <patrick@georgi-clan.de>
Reviewed-by: Anton Kochkov <anton.kochkov@gmail.com>
-rw-r--r-- | payloads/libpayload/drivers/serial.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/payloads/libpayload/drivers/serial.c b/payloads/libpayload/drivers/serial.c index c0200af00c..cd00a13204 100644 --- a/payloads/libpayload/drivers/serial.c +++ b/payloads/libpayload/drivers/serial.c @@ -35,6 +35,8 @@ #define MEMBASE (phys_to_virt(lib_sysinfo.serial->baseaddr)) #define DIVISOR(x) (115200 / x) +static int serial_io_hardware_is_present = 1; + #ifdef CONFIG_SERIAL_SET_SPEED static void serial_io_hardware_init(int port, int speed, int word_bits, int parity, int stop_bits) { @@ -107,6 +109,12 @@ void serial_init(void) #endif console_add_input_driver(&consin); console_add_output_driver(&consout); + + /* check to see if there's actually serial port h/w */ + if (lib_sysinfo.ser_ioport) { + if( (inb(IOBASE + 0x05)==0xFF) && (inb(IOBASE + 0x06)==0xFF) ) + serial_io_hardware_is_present = 0; + } } static void serial_io_putchar(unsigned int c) @@ -118,11 +126,15 @@ static void serial_io_putchar(unsigned int c) static int serial_io_havechar(void) { + if ( !serial_io_hardware_is_present ) + return 0; return inb(IOBASE + 0x05) & 0x01; } static int serial_io_getchar(void) { + if ( !serial_io_hardware_is_present ) + return -1; while (!serial_io_havechar()) ; return (int)inb(IOBASE); } |