[SeaBIOS] [PATCH 1/3] Introduce serial_out(), serial_in() macros in serialio.c

David Woodhouse dwmw2 at infradead.org
Fri Dec 6 15:21:31 CET 2013


This will make it easier to abstract out the MMIO serial access. Even if
that ends up in separate code which is a *copy* of this, at least they'll
match.

Signed-off-by: David Woodhouse <David.Woodhouse at intel.com>
---
 src/hw/serialio.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/hw/serialio.c b/src/hw/serialio.c
index 6486fc0..8ec36c2 100644
--- a/src/hw/serialio.c
+++ b/src/hw/serialio.c
@@ -1,6 +1,6 @@
 // Low-level serial (and serial-like) device access.
 //
-// Copyright (C) 2008-1013  Kevin O'Connor <kevin at koconnor.net>
+// Copyright (C) 2008-2013  Kevin O'Connor <kevin at koconnor.net>
 //
 // This file may be distributed under the terms of the GNU LGPLv3 license.
 
@@ -17,6 +17,9 @@
 
 #define DEBUG_TIMEOUT 100000
 
+#define serial_out(d, reg) outb(d, CONFIG_DEBUG_SERIAL_PORT+(reg))
+#define serial_in(reg) inb(CONFIG_DEBUG_SERIAL_PORT+(reg))
+
 // Setup the debug serial port for output.
 void
 serial_debug_preinit(void)
@@ -25,12 +28,12 @@ serial_debug_preinit(void)
         return;
     // setup for serial logging: 8N1
     u8 oldparam, newparam = 0x03;
-    oldparam = inb(CONFIG_DEBUG_SERIAL_PORT+SEROFF_LCR);
-    outb(newparam, CONFIG_DEBUG_SERIAL_PORT+SEROFF_LCR);
+    oldparam = serial_in(SEROFF_LCR);
+    serial_out(newparam, SEROFF_LCR);
     // Disable irqs
     u8 oldier, newier = 0;
-    oldier = inb(CONFIG_DEBUG_SERIAL_PORT+SEROFF_IER);
-    outb(newier, CONFIG_DEBUG_SERIAL_PORT+SEROFF_IER);
+    oldier = serial_in(SEROFF_IER);
+    serial_out(newier, SEROFF_IER);
 
     if (oldparam != newparam || oldier != newier)
         dprintf(1, "Changing serial settings was %x/%x now %x/%x\n"
@@ -44,11 +47,11 @@ serial_debug(char c)
     if (!CONFIG_DEBUG_SERIAL)
         return;
     int timeout = DEBUG_TIMEOUT;
-    while ((inb(CONFIG_DEBUG_SERIAL_PORT+SEROFF_LSR) & 0x20) != 0x20)
+    while ((serial_in(SEROFF_LSR) & 0x20) != 0x20)
         if (!timeout--)
             // Ran out of time.
             return;
-    outb(c, CONFIG_DEBUG_SERIAL_PORT+SEROFF_DATA);
+    serial_out(c, SEROFF_DATA);
 }
 
 void
@@ -66,7 +69,7 @@ serial_debug_flush(void)
     if (!CONFIG_DEBUG_SERIAL)
         return;
     int timeout = DEBUG_TIMEOUT;
-    while ((inb(CONFIG_DEBUG_SERIAL_PORT+SEROFF_LSR) & 0x60) != 0x60)
+    while ((serial_in(SEROFF_LSR) & 0x60) != 0x60)
         if (!timeout--)
             // Ran out of time.
             return;
-- 
1.8.3.1


-- 
David Woodhouse                            Open Source Technology Centre
David.Woodhouse at intel.com                              Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5745 bytes
Desc: not available
URL: <http://www.seabios.org/pipermail/seabios/attachments/20131206/0285cbbd/attachment.bin>


More information about the SeaBIOS mailing list