]> Joshua Wise's Git repositories - netwatch.git/blame - tools/pci.c
more licensing
[netwatch.git] / tools / pci.c
CommitLineData
98e930a2
JP
1/* pci.c
2 * Arbitrary PCI space reader/writer utility
3 * NetWatch system management mode administration console
4 *
5 * Copyright (c) 2008 Jacob Potter and Joshua Wise. All rights reserved.
6 * This program is free software; you can redistribute and/or modify it under
7 * the terms found in the file LICENSE in the root of this source tree.
8 *
9 */
10
45096195
JW
11#include <pci.h>
12#include <string.h>
13
14int main(int argc, char **argv)
15{
16 unsigned int bus, dev, fn, addr;
17 unsigned char type = 'b';
18 unsigned int datum;
19
20 if (iopl(3) < 0)
21 {
22 perror("iopl");
23 return 1;
24 }
25
26 if ((argc < 5) || (argc > 7))
27 {
28 usage:
29 printf("usage: %s bus dev fn addr [b|w|l [datum]]\n", argv[0]);
30 return 2;
31 }
32
33 bus = strtoul(argv[1], NULL, 0);
34 dev = strtoul(argv[2], NULL, 0);
35 fn = strtoul(argv[3], NULL, 0);
36 addr = strtoul(argv[4], NULL, 0);
37
38 if (argc > 5)
39 type = *argv[5];
40
41 if (argc > 6)
42 {
43 datum = strtoul(argv[6], NULL, 0);
44 switch (type)
45 {
46 case 'b':
47 datum &= 0xFF;
48 pci_write8(bus, dev, fn, addr, datum);
49 printf("Wrote byte 0x%02x to %02x:%02x.%x[%02x]\n", datum, bus, dev, fn, addr);
50 break;
51 case 'w':
52 datum &= 0xFFFF;
53 pci_write16(bus, dev, fn, addr, datum);
54 printf("Wrote word 0x%04x to %02x:%02x.%x[%02x]\n", datum, bus, dev, fn, addr);
55 break;
56 case 'l':
57 pci_write32(bus, dev, fn, addr, datum);
58 printf("Wrote long 0x%08x to %02x:%02x.%x[%02x]\n", datum, bus, dev, fn, addr);
59 break;
60 default:
61 goto usage;
62 }
63 } else {
64 switch(type)
65 {
66 case 'b':
67 datum = pci_read8(bus, dev, fn, addr);
68 printf("Read byte 0x%02x from %02x:%02x.%x[%02x]\n", datum, bus, dev, fn, addr);
69 break;
70 case 'w':
71 datum = pci_read16(bus, dev, fn, addr);
72 printf("Read word 0x%04x from %02x:%02x.%x[%02x]\n", datum, bus, dev, fn, addr);
73 break;
74 case 'l':
75 datum = pci_read32(bus, dev, fn, addr);
76 printf("Read long 0x%08x from %02x:%02x.%x[%02x]\n", datum, bus, dev, fn, addr);
77 break;
78 default:
79 goto usage;
80 }
81 }
82}
This page took 0.028826 seconds and 4 git commands to generate.