From 4509619557e06ff851f93ddf1eaca7a898d46b2f Mon Sep 17 00:00:00 2001 From: Joshua Wise Date: Sat, 13 Sep 2008 19:58:51 -0400 Subject: [PATCH] Add pci utility --- tools/Makefile | 6 ++++- tools/pci.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 tools/pci.c 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; + } + } +} -- 2.43.0