]> Joshua Wise's Git repositories - netwatch.git/commitdiff
Add pci utility
authorJoshua Wise <joshua@rebirth.joshuawise.com>
Sat, 13 Sep 2008 23:58:51 +0000 (19:58 -0400)
committerJoshua Wise <joshua@rebirth.joshuawise.com>
Sat, 13 Sep 2008 23:58:51 +0000 (19:58 -0400)
tools/Makefile
tools/pci.c [new file with mode: 0644]

index 7402d797f6adfd47640927cfcea6687aa9fc4347..c53fd4a28ea5eda3adee65f5b13e83a2ec6bfa1b 100644 (file)
@@ -1,8 +1,9 @@
 CFLAGS=-I../include
 CC=gcc
 SMRAM_ICH2_OBJS=smram-linux-tool.o ../pci/pci-linux.o ../ich2/smram-ich2.noraw.o
+PCI_OBJS=pci.o ../pci/pci-linux.o
 
-all: smram-ich2 port
+all: smram-ich2 port pci
 
 %.noraw.o: %.c
        gcc $(CFLAGS) -c -o $@ $<
@@ -13,5 +14,8 @@ smram-ich2: $(SMRAM_ICH2_OBJS)
 port: port.o
        gcc -o port port.o
 
+pci: $(PCI_OBJS)
+       gcc $(CFLAGS) -o pci $(PCI_OBJS)
+
 clean:
        rm -f $(SMRAM_ICH2_OBJS) smram-ich2
diff --git a/tools/pci.c b/tools/pci.c
new file mode 100644 (file)
index 0000000..abfb8a5
--- /dev/null
@@ -0,0 +1,72 @@
+#include <pci.h>
+#include <string.h>
+
+int main(int argc, char **argv)
+{
+       unsigned int bus, dev, fn, addr;
+       unsigned char type = 'b';
+       unsigned int datum;
+       
+       if (iopl(3) < 0)
+       {
+               perror("iopl");
+               return 1;
+       }
+       
+       if ((argc < 5) || (argc > 7))
+       {
+       usage:
+               printf("usage: %s bus dev fn addr [b|w|l [datum]]\n", argv[0]);
+               return 2;
+       }
+       
+       bus = strtoul(argv[1], NULL, 0);
+       dev = strtoul(argv[2], NULL, 0);
+       fn = strtoul(argv[3], NULL, 0);
+       addr = strtoul(argv[4], NULL, 0);
+       
+       if (argc > 5)
+               type = *argv[5];
+       
+       if (argc > 6)
+       {
+               datum = strtoul(argv[6], NULL, 0);
+               switch (type)
+               {
+               case 'b':
+                       datum &= 0xFF;
+                       pci_write8(bus, dev, fn, addr, datum);
+                       printf("Wrote byte 0x%02x to %02x:%02x.%x[%02x]\n", datum, bus, dev, fn, addr);
+                       break;
+               case 'w':
+                       datum &= 0xFFFF;
+                       pci_write16(bus, dev, fn, addr, datum);
+                       printf("Wrote word 0x%04x to %02x:%02x.%x[%02x]\n", datum, bus, dev, fn, addr);
+                       break;
+               case 'l':
+                       pci_write32(bus, dev, fn, addr, datum);
+                       printf("Wrote long 0x%08x to %02x:%02x.%x[%02x]\n", datum, bus, dev, fn, addr);
+                       break;
+               default:
+                       goto usage;
+               }
+       } else {
+               switch(type)
+               {
+               case 'b':
+                       datum = pci_read8(bus, dev, fn, addr);
+                       printf("Read byte 0x%02x from %02x:%02x.%x[%02x]\n", datum, bus, dev, fn, addr);
+                       break;
+               case 'w':
+                       datum = pci_read16(bus, dev, fn, addr);
+                       printf("Read word 0x%04x from %02x:%02x.%x[%02x]\n", datum, bus, dev, fn, addr);
+                       break;
+               case 'l':
+                       datum = pci_read32(bus, dev, fn, addr);
+                       printf("Read long 0x%08x from %02x:%02x.%x[%02x]\n", datum, bus, dev, fn, addr);
+                       break;
+               default:
+                       goto usage;
+               }
+       }
+}
This page took 0.033743 seconds and 4 git commands to generate.