From 7f505e7f7991de7a43dc874880d8cfcb11b99647 Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Thu, 12 Mar 2020 06:45:08 +0000 Subject: [PATCH] test if port does exist via using scratch register The SCR, scratch register was not present on the 8250 and 8250B UART, so we can use to test if we actually do have serial port. We need this test because some systems will get long delays while attempting to write to non-existing port and this will slow down the console IO to extreme. MFC after: 1 week --- stand/i386/libi386/comconsole.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/stand/i386/libi386/comconsole.c b/stand/i386/libi386/comconsole.c index 20b3076ecae7..ed1f1aa08ed7 100644 --- a/stand/i386/libi386/comconsole.c +++ b/stand/i386/libi386/comconsole.c @@ -330,6 +330,16 @@ comc_setup(int speed, int port) if ((comconsole.c_flags & (C_ACTIVEIN | C_ACTIVEOUT)) == 0) return; +#define COMC_TEST 0xbb + /* + * Write byte to scratch register and read it out. + */ + outb(comc_port + com_scr, COMC_TEST); + if (inb(comc_port + com_scr) != COMC_TEST) { + comconsole.c_flags &= ~(C_PRESENTIN | C_PRESENTOUT); + return; + } + outb(comc_port + com_cfcr, CFCR_DLAB | COMC_FMT); outb(comc_port + com_dlbl, COMC_BPS(speed) & 0xff); outb(comc_port + com_dlbh, COMC_BPS(speed) >> 8);