]>
Commit | Line | Data |
---|---|---|
1 | #include <pci.h> | |
2 | #include <pci-bother.h> | |
3 | ||
4 | struct pci_bother { | |
5 | int bus, dev, fn; | |
6 | unsigned short origstate; | |
7 | unsigned long origbars[6]; | |
8 | }; | |
9 | ||
10 | static struct pci_bother bothers[MAX_BOTHERS]; | |
11 | static int nbothers = 0; | |
12 | ||
13 | int pci_bother_add(pci_dev_t *dev) | |
14 | { | |
15 | int i; | |
16 | ||
17 | if (nbothers == MAX_BOTHERS) | |
18 | return -1; | |
19 | ||
20 | bothers[nbothers].bus = dev->bus; | |
21 | bothers[nbothers].dev = dev->dev; | |
22 | bothers[nbothers].fn = dev->fn; | |
23 | ||
24 | bothers[nbothers].origstate = pci_read16(dev->bus, dev->dev, dev->fn, 0x04); | |
25 | for (i = 0; i < 6; i++) | |
26 | bothers[nbothers].origbars[i] = pci_read32(dev->bus, dev->dev, dev->fn, 0x10 + i * 4); | |
27 | ||
28 | nbothers++; | |
29 | ||
30 | return 0; | |
31 | } | |
32 | ||
33 | void pci_bother_all() | |
34 | { | |
35 | int i, j; | |
36 | ||
37 | for (i = 0; i < nbothers; i++) | |
38 | { | |
39 | pci_write16(bothers[i].bus, bothers[i].dev, bothers[i].fn, 0x04, 0x0); | |
40 | for (j = 0; j < 6; j++) | |
41 | pci_write32(bothers[i].bus, bothers[i].dev, bothers[i].fn, 0x10 + j * 4, 0); | |
42 | } | |
43 | } | |
44 | ||
45 | void pci_unbother_all() | |
46 | { | |
47 | int i, j; | |
48 | ||
49 | for (i = 0; i < nbothers; i++) | |
50 | { | |
51 | pci_write16(bothers[i].bus, bothers[i].dev, bothers[i].fn, 0x04, bothers[i].origstate); | |
52 | for (j = 0; j < 6; j++) | |
53 | pci_write32(bothers[i].bus, bothers[i].dev, bothers[i].fn, 0x10 + j * 4, bothers[i].origbars[j]); | |
54 | } | |
55 | } |