serial: Clean up and abstract handling of serial ports
authorH. Peter Anvin <hpa@linux.intel.com>
Fri, 31 May 2013 15:05:57 +0000 (08:05 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Fri, 31 May 2013 15:08:36 +0000 (08:08 -0700)
The special handling of serial ports 0-3 meaning "look in a BIOS
table" is at least officially BIOS-specific, so create an inline
function and move it to bios.h.

While we are at it, make the function look slightly less like
converted assembly.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
com32/elflink/ldlinux/readconfig.c
core/include/bios.h

index 7ac216b..7701acf 100644 (file)
@@ -1,7 +1,7 @@
 /* ----------------------------------------------------------------------- *
  *
  *   Copyright 2004-2009 H. Peter Anvin - All Rights Reserved
- *   Copyright 2009 Intel Corporation; author: H. Peter Anvin
+ *   Copyright 2009-2013 Intel Corporation; author: H. Peter Anvin
  *
  *   This program is free software; you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
@@ -759,7 +759,6 @@ static uint8_t SerialNotice = 1;
 
 #define DEFAULT_BAUD   9600
 #define BAUD_DIVISOR   115200
-#define serial_base    0x0400
 
 extern void sirq_cleanup_nowipe(void);
 extern void sirq_install(void);
@@ -1279,18 +1278,7 @@ do_include:
                baud = BAUD_DIVISOR / baud;
                baud &= 0xffff;
                BaudDivisor = baud;
-
-               /*
-                * If port > 3 then port is I/O addr
-                */
-               if (port <= 3) {
-                       /* Get the I/O port from the BIOS */
-                       port <<= 1;
-                       port = *(volatile uint16_t *)(serial_base + port);
-               }
-
-               
-               SerialPort = port;
+               SerialPort = get_serial_port(port);
 
                /*
                 * Begin code to actually set up the serial port
index 889443a..6c3c815 100644 (file)
@@ -30,7 +30,7 @@
 #define fdctab1                fdctab
 #define fdctab2                (fdctab + 2)
 
-#define serial_base    0x0400  /* Base address for 4 serial ports */
+#define SERIAL_BASE    0x0400  /* Base address for 4 serial ports */
 #define BIOS_fbm       0x0413  /* Free Base Memory (kilobytes) */
 #define BIOS_page      0x0462  /* Current video page */
 #define BIOS_timer     0x046C  /* Timer ticks */
@@ -96,4 +96,19 @@ extern char *SerialTail;
 extern void bios_init(void);
 extern void bios_cleanup_hardware(void);
 
+static inline uint16_t get_serial_port(uint16_t port)
+{
+    /* Magic array in BIOS memory, contains four entries */
+    const uint16_t * const serial_ports = (const uint16_t *)SERIAL_BASE;
+
+    /*
+     * If port > 3 then the port is simply the I/O base address
+     */
+    if (port > 3)
+       return port;
+
+    /* Get the I/O port from the BIOS */
+    return serial_ports[port];
+}
+
 #endif /* _BIOS_H */