]> Joshua Wise's Git repositories - netwatch.git/blob - tools/pci.c
checksum_rect defaults to null
[netwatch.git] / tools / pci.c
1 #include <pci.h>
2 #include <string.h>
3
4 int main(int argc, char **argv)
5 {
6         unsigned int bus, dev, fn, addr;
7         unsigned char type = 'b';
8         unsigned int datum;
9         
10         if (iopl(3) < 0)
11         {
12                 perror("iopl");
13                 return 1;
14         }
15         
16         if ((argc < 5) || (argc > 7))
17         {
18         usage:
19                 printf("usage: %s bus dev fn addr [b|w|l [datum]]\n", argv[0]);
20                 return 2;
21         }
22         
23         bus = strtoul(argv[1], NULL, 0);
24         dev = strtoul(argv[2], NULL, 0);
25         fn = strtoul(argv[3], NULL, 0);
26         addr = strtoul(argv[4], NULL, 0);
27         
28         if (argc > 5)
29                 type = *argv[5];
30         
31         if (argc > 6)
32         {
33                 datum = strtoul(argv[6], NULL, 0);
34                 switch (type)
35                 {
36                 case 'b':
37                         datum &= 0xFF;
38                         pci_write8(bus, dev, fn, addr, datum);
39                         printf("Wrote byte 0x%02x to %02x:%02x.%x[%02x]\n", datum, bus, dev, fn, addr);
40                         break;
41                 case 'w':
42                         datum &= 0xFFFF;
43                         pci_write16(bus, dev, fn, addr, datum);
44                         printf("Wrote word 0x%04x to %02x:%02x.%x[%02x]\n", datum, bus, dev, fn, addr);
45                         break;
46                 case 'l':
47                         pci_write32(bus, dev, fn, addr, datum);
48                         printf("Wrote long 0x%08x to %02x:%02x.%x[%02x]\n", datum, bus, dev, fn, addr);
49                         break;
50                 default:
51                         goto usage;
52                 }
53         } else {
54                 switch(type)
55                 {
56                 case 'b':
57                         datum = pci_read8(bus, dev, fn, addr);
58                         printf("Read byte 0x%02x from %02x:%02x.%x[%02x]\n", datum, bus, dev, fn, addr);
59                         break;
60                 case 'w':
61                         datum = pci_read16(bus, dev, fn, addr);
62                         printf("Read word 0x%04x from %02x:%02x.%x[%02x]\n", datum, bus, dev, fn, addr);
63                         break;
64                 case 'l':
65                         datum = pci_read32(bus, dev, fn, addr);
66                         printf("Read long 0x%08x from %02x:%02x.%x[%02x]\n", datum, bus, dev, fn, addr);
67                         break;
68                 default:
69                         goto usage;
70                 }
71         }
72 }
This page took 0.028273 seconds and 4 git commands to generate.