From: Kevin O'Connor Date: Wed, 13 May 2009 02:59:41 +0000 (-0400) Subject: Improve serial port detection. X-Git-Tag: rel-0.4.1~79 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=c151b3bf755c7dcdadd38500138f66de8a731578;p=seabios.git Improve serial port detection. Add port names for serial port registers. When detecting serial port, ignore top two bits of IIR register. --- diff --git a/src/ioport.h b/src/ioport.h index 220f7f2..73cf8ad 100644 --- a/src/ioport.h +++ b/src/ioport.h @@ -34,11 +34,15 @@ #define PORT_DMA2_MODE_REG 0x00d6 #define PORT_DMA2_MASTER_CLEAR 0x00da #define PORT_MATH_CLEAR 0x00f0 +#define PORT_SERIAL4 0x02e8 +#define PORT_SERIAL2 0x02f8 +#define PORT_SERIAL3 0x03e8 #define PORT_FD_DOR 0x03f2 #define PORT_FD_STATUS 0x03f4 #define PORT_FD_DATA 0x03f5 #define PORT_HD_DATA 0x03f6 #define PORT_FD_DIR 0x03f7 +#define PORT_SERIAL1 0x03f8 #define PORT_PCI_CMD 0x0cf8 #define PORT_PCI_DATA 0x0cfc #define PORT_BIOS_DEBUG 0x0402 @@ -48,6 +52,16 @@ #define PORT_SMB_BASE 0xb100 #define PORT_BIOS_APM 0x8900 +// Serial port offsets +#define SEROFF_DATA 0 +#define SEROFF_DLL 0 +#define SEROFF_IER 1 +#define SEROFF_DLH 1 +#define SEROFF_IIR 2 +#define SEROFF_LCR 3 +#define SEROFF_LSR 5 +#define SEROFF_MSR 6 + // PORT_A20 bitdefs #define A20_ENABLE_BIT 0x02 diff --git a/src/output.c b/src/output.c index 518730a..96f444f 100644 --- a/src/output.c +++ b/src/output.c @@ -12,7 +12,7 @@ #include "config.h" // CONFIG_* #include "biosvar.h" // GET_GLOBAL -#define DEBUG_PORT 0x03f8 +#define DEBUG_PORT PORT_SERIAL1 #define DEBUG_TIMEOUT 100000 void @@ -22,12 +22,12 @@ debug_serial_setup() return; // setup for serial logging: 8N1 u8 oldparam, newparam = 0x03; - oldparam = inb(DEBUG_PORT+3); - outb(newparam, DEBUG_PORT+3); + oldparam = inb(DEBUG_PORT+SEROFF_LCR); + outb(newparam, DEBUG_PORT+SEROFF_LCR); // Disable irqs u8 oldier, newier = 0; - oldier = inb(DEBUG_PORT+1); - outb(newier, DEBUG_PORT+1); + oldier = inb(DEBUG_PORT+SEROFF_IER); + outb(newier, DEBUG_PORT+SEROFF_IER); if (oldparam != newparam || oldier != newier) dprintf(1, "Changing serial settings was %x/%x now %x/%x\n" @@ -39,11 +39,11 @@ static void debug_serial(char c) { int timeout = DEBUG_TIMEOUT; - while ((inb(DEBUG_PORT+5) & 0x60) != 0x60) + while ((inb(DEBUG_PORT+SEROFF_LSR) & 0x60) != 0x60) if (!timeout--) // Ran out of time. return; - outb(c, DEBUG_PORT); + outb(c, DEBUG_PORT+SEROFF_DATA); } // Show a character on the screen. diff --git a/src/serial.c b/src/serial.c index 1537f6d..550762e 100644 --- a/src/serial.c +++ b/src/serial.c @@ -17,12 +17,15 @@ static u16 detect_serial(u16 port, u8 timeout, u8 count) { - outb(0x02, port+1); - if (inb(port+1) != 0x02) + outb(0x02, port+SEROFF_IER); + u8 ier = inb(port+SEROFF_IER); + if (ier != 0x02) return 0; - if (inb(port+2) != 0x02) + u8 iir = inb(port+SEROFF_IIR); + if ((iir & 0x3f) != 0x02) return 0; - outb(0x00, port+1); + + outb(0x00, port+SEROFF_IER); SET_BDA(port_com[count], port); SET_BDA(com_timeout[count], timeout); return 1; @@ -36,10 +39,10 @@ serial_setup() dprintf(3, "init serial\n"); u16 count = 0; - count += detect_serial(0x3f8, 0x0a, count); - count += detect_serial(0x2f8, 0x0a, count); - count += detect_serial(0x3e8, 0x0a, count); - count += detect_serial(0x2e8, 0x0a, count); + count += detect_serial(PORT_SERIAL1, 0x0a, count); + count += detect_serial(PORT_SERIAL2, 0x0a, count); + count += detect_serial(PORT_SERIAL3, 0x0a, count); + count += detect_serial(PORT_SERIAL4, 0x0a, count); dprintf(1, "Found %d serial ports\n", count); // Equipment word bits 9..11 determing # serial ports @@ -67,18 +70,18 @@ handle_1400(struct bregs *regs) u16 addr = getComAddr(regs); if (!addr) return; - outb(inb(addr+3) | 0x80, addr+3); + outb(inb(addr+SEROFF_LCR) | 0x80, addr+SEROFF_LCR); if ((regs->al & 0xE0) == 0) { - outb(0x17, addr); - outb(0x04, addr+1); + outb(0x17, addr+SEROFF_DLL); + outb(0x04, addr+SEROFF_DLH); } else { u16 val16 = 0x600 >> ((regs->al & 0xE0) >> 5); - outb(val16 & 0xFF, addr); - outb(val16 >> 8, addr+1); + outb(val16 & 0xFF, addr+SEROFF_DLL); + outb(val16 >> 8, addr+SEROFF_DLH); } - outb(regs->al & 0x1F, addr+3); - regs->ah = inb(addr+5); - regs->al = inb(addr+6); + outb(regs->al & 0x1F, addr+SEROFF_LCR); + regs->ah = inb(addr+SEROFF_LSR); + regs->al = inb(addr+SEROFF_MSR); set_success(regs); } @@ -91,7 +94,7 @@ handle_1401(struct bregs *regs) return; u16 timer = GET_BDA(timer_counter); u16 timeout = GET_BDA(com_timeout[regs->dx]); - while (((inb(addr+5) & 0x60) != 0x60) && (timeout)) { + while (((inb(addr+SEROFF_LSR) & 0x60) != 0x60) && (timeout)) { u16 val16 = GET_BDA(timer_counter); if (val16 != timer) { timer = val16; @@ -99,8 +102,8 @@ handle_1401(struct bregs *regs) } } if (timeout) - outb(regs->al, addr); - regs->ah = inb(addr+5); + outb(regs->al, addr+SEROFF_DATA); + regs->ah = inb(addr+SEROFF_LSR); if (!timeout) regs->ah |= 0x80; set_success(regs); @@ -115,7 +118,7 @@ handle_1402(struct bregs *regs) return; u16 timer = GET_BDA(timer_counter); u16 timeout = GET_BDA(com_timeout[regs->dx]); - while (((inb(addr+5) & 0x01) == 0) && (timeout)) { + while (((inb(addr+SEROFF_LSR) & 0x01) == 0) && (timeout)) { u16 val16 = GET_BDA(timer_counter); if (val16 != timer) { timer = val16; @@ -124,9 +127,9 @@ handle_1402(struct bregs *regs) } if (timeout) { regs->ah = 0; - regs->al = inb(addr); + regs->al = inb(addr+SEROFF_DATA); } else { - regs->ah = inb(addr+5); + regs->ah = inb(addr+SEROFF_LSR); } set_success(regs); } @@ -138,8 +141,8 @@ handle_1403(struct bregs *regs) u16 addr = getComAddr(regs); if (!addr) return; - regs->ah = inb(addr+5); - regs->al = inb(addr+6); + regs->ah = inb(addr+SEROFF_LSR); + regs->al = inb(addr+SEROFF_MSR); set_success(regs); }