libpci: merge BIOS read and BIOS write
authorH. Peter Anvin <hpa@zytor.com>
Sun, 21 Feb 2010 06:26:39 +0000 (22:26 -0800)
committerH. Peter Anvin <hpa@zytor.com>
Sun, 21 Feb 2010 06:27:28 +0000 (22:27 -0800)
Save a few bytes by merging the very similar BIOS read and BIOS write
functions.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
com32/lib/Makefile
com32/lib/pci/bios.c [moved from com32/lib/pci/readbios.c with 73% similarity]
com32/lib/pci/pci.h
com32/lib/pci/readx.c
com32/lib/pci/writebios.c [deleted file]
com32/lib/pci/writex.c

index 0daa157..250c396 100644 (file)
@@ -66,9 +66,9 @@ LIBOBJS = \
        sys/vesa/alphatbl.o sys/vesa/screencpy.o sys/vesa/fmtpixel.o    \
        sys/vesa/i915resolution.o                                       \
        \
-       pci/cfgtype.o pci/scan.o                                        \
-       pci/readb.o pci/readw.o pci/readl.o pci/readbios.o              \
-       pci/writeb.o pci/writew.o pci/writel.o pci/writebios.o          \
+       pci/cfgtype.o pci/scan.o pci/bios.o                             \
+       pci/readb.o pci/readw.o pci/readl.o                             \
+       pci/writeb.o pci/writew.o pci/writel.o                          \
        \
        zlib/adler32.o zlib/compress.o zlib/crc32.o                     \
        zlib/uncompr.o zlib/deflate.o zlib/trees.o zlib/zutil.o         \
similarity index 73%
rename from com32/lib/pci/readbios.c
rename to com32/lib/pci/bios.c
index f8ff3bf..b3c2c57 100644 (file)
@@ -2,13 +2,15 @@
 #include <string.h>
 #include "pci/pci.h"
 
-uint32_t __pci_read_bios(uint32_t call, pciaddr_t a)
+uint32_t __pci_read_write_bios(uint32_t call, uint32_t v, pciaddr_t a)
 {
     com32sys_t rs;
     memset(&rs, 0, sizeof rs);
     rs.eax.w[0] = call;
     rs.ebx.w[0] = a >> 8;      /* bus:device:function */
     rs.edi.b[0] = a;           /* address:reg */
+    rs.ecx.l    = v;
+    rs.eflags.l = EFLAGS_CF;
     __intcall(0x1a, &rs, &rs);
 
     return (rs.eflags.l & EFLAGS_CF) ? ~(uint32_t) 0 : rs.ecx.l;
index 66a1eb5..8d81b0e 100644 (file)
@@ -10,7 +10,6 @@
 #include <sys/cpu.h>
 
 extern enum pci_config_type __pci_cfg_type;
-extern uint32_t __pci_read_bios(uint32_t call, pciaddr_t a);
-extern void __pci_write_bios(uint32_t call, uint32_t v, pciaddr_t a);
+extern uint32_t __pci_read_write_bios(uint32_t call, uint32_t v, pciaddr_t a);
 
 #endif /* PCI_PCI_H */
index f073eaa..ed66d5b 100644 (file)
@@ -1,7 +1,7 @@
 #include "pci/pci.h"
-#include <string.h>
 
-TYPE BWL(pci_read) (pciaddr_t a) {
+TYPE BWL(pci_read) (pciaddr_t a)
+{
     TYPE r;
 
     for (;;) {
@@ -42,7 +42,7 @@ TYPE BWL(pci_read) (pciaddr_t a) {
            return r;
 
        case PCI_CFG_BIOS:
-           return (TYPE) __pci_read_bios(BIOSCALL, a);
+           return (TYPE) __pci_read_write_bios(BIOSCALL, 0, a);
 
        default:
            return (TYPE) ~ 0;
diff --git a/com32/lib/pci/writebios.c b/com32/lib/pci/writebios.c
deleted file mode 100644 (file)
index d367eee..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#include <com32.h>
-#include <string.h>
-#include "pci/pci.h"
-
-void __pci_write_bios(uint32_t call, uint32_t v, pciaddr_t a)
-{
-    com32sys_t rs;
-    memset(&rs, 0, sizeof rs);
-    rs.eax.w[0] = call;
-    rs.ebx.w[0] = a >> 8;      /* bus:device:function */
-    rs.edi.b[0] = a;           /* address:reg */
-    rs.ecx.l = v;
-    __intcall(0x1a, &rs, NULL);
-}
index 14b2038..d83a1ee 100644 (file)
@@ -1,6 +1,7 @@
 #include "pci/pci.h"
 
-void BWL(pci_write) (TYPE v, pciaddr_t a) {
+void BWL(pci_write)(TYPE v, pciaddr_t a)
+{
     for (;;) {
        switch (__pci_cfg_type) {
        case PCI_CFG_AUTO:
@@ -39,7 +40,7 @@ void BWL(pci_write) (TYPE v, pciaddr_t a) {
            return;
 
        case PCI_CFG_BIOS:
-           __pci_write_bios(BIOSCALL, v, a);
+           __pci_read_write_bios(BIOSCALL, v, a);
            return;
 
        default: