From 5056b6e612569b202c96a8a54da90879f118b7d5 Mon Sep 17 00:00:00 2001 From: Dave Frodin Date: Sat, 15 Dec 2012 13:24:02 -0700 Subject: 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 Reviewed-on: http://review.coreboot.org/2040 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi Reviewed-by: Anton Kochkov --- payloads/libpayload/drivers/serial.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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); } -- cgit v1.2.3