From: Joshua Wise Date: Sat, 13 Sep 2008 23:58:51 +0000 (-0400) Subject: Add pci utility X-Git-Url: http://git.joshuawise.com/netwatch.git/commitdiff_plain/4509619557e06ff851f93ddf1eaca7a898d46b2f?ds=sidebyside;hp=--cc Add pci utility --- 4509619557e06ff851f93ddf1eaca7a898d46b2f diff --git a/tools/Makefile b/tools/Makefile index 7402d79..c53fd4a 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -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 index 0000000..abfb8a5 --- /dev/null +++ b/tools/pci.c @@ -0,0 +1,72 @@ +#include +#include + +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; + } + } +}