]> Joshua Wise's Git repositories - netwatch.git/blob - pci/pci-bother.c
First pass of 410watch UI code.
[netwatch.git] / pci / pci-bother.c
1 /* pci-bother.c
2  * PCI bothering code
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
11 #include <pci.h>
12 #include <pci-bother.h>
13
14 struct pci_bother {
15         int bus, dev, fn;
16         unsigned short origstate;
17         unsigned long origbars[6];
18 };
19
20 static struct pci_bother bothers[MAX_BOTHERS];
21 static int nbothers = 0;
22
23 int pci_bother_add(pci_dev_t *dev)
24 {
25         int i;
26         
27         if (nbothers == MAX_BOTHERS)
28                 return -1;
29         
30         bothers[nbothers].bus = dev->bus;
31         bothers[nbothers].dev = dev->dev;
32         bothers[nbothers].fn = dev->fn;
33         
34         bothers[nbothers].origstate = pci_read16(dev->bus, dev->dev, dev->fn, 0x04);
35         for (i = 0; i < 6; i++)
36                 bothers[nbothers].origbars[i] = pci_read32(dev->bus, dev->dev, dev->fn, 0x10 + i * 4);
37         
38         nbothers++;
39         
40         return 0;
41 }
42
43 void pci_bother_all()
44 {
45         int i, j;
46         
47         for (i = 0; i < nbothers; i++)
48         {
49                 pci_write16(bothers[i].bus, bothers[i].dev, bothers[i].fn, 0x04, 0x0);
50                 for (j = 0; j < 6; j++)
51                         pci_write32(bothers[i].bus, bothers[i].dev, bothers[i].fn, 0x10 + j * 4, 0);
52         }
53 }
54
55 void pci_unbother_all()
56 {
57         int i, j;
58         
59         for (i = 0; i < nbothers; i++)
60         {
61                 pci_write16(bothers[i].bus, bothers[i].dev, bothers[i].fn, 0x04, bothers[i].origstate);
62                 for (j = 0; j < 6; j++)
63                         pci_write32(bothers[i].bus, bothers[i].dev, bothers[i].fn, 0x10 + j * 4, bothers[i].origbars[j]);
64         }
65 }
This page took 0.032261 seconds and 4 git commands to generate.