AUTHORS, util/: Drop individual copyright notices
[coreboot.git] / util / vgabios / pci-userspace.c
blob2a57f487660e7de6f421dc6b6dca8bfd5743a92f
1 /* This file is part of the coreboot project. */
2 /*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; version 2 of the License.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
13 #include <stdio.h>
14 #include <pci/pci.h>
15 #include "pci-userspace.h"
17 #define DEBUG_PCI 1
19 static struct pci_access *pacc;
21 int pci_initialize(void)
23 struct pci_dev *dev;
25 pacc = pci_alloc();
27 pci_init(pacc);
28 pci_scan_bus(pacc);
29 for (dev = pacc->devices; dev; dev = dev->next) {
30 pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES);
32 return 0;
35 int pci_exit(void)
37 pci_cleanup(pacc);
38 return 0;
41 u8 pci_read_config8(struct device *dev, unsigned int where)
43 struct pci_dev *d;
44 if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
45 return pci_read_byte(d, where);
46 #ifdef DEBUG_PCI
47 printf("PCI: device not found while read byte (%x:%x.%x)\n",
48 dev->busno, dev->slot, dev->func);
49 #endif
50 return 0;
53 u16 pci_read_config16(struct device *dev, unsigned int where)
55 struct pci_dev *d;
56 if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
57 return pci_read_word(d, where);
58 #ifdef DEBUG_PCI
59 printf("PCI: device not found while read word (%x:%x.%x)\n",
60 dev->busno, dev->slot, dev->func);
61 #endif
62 return 0;
65 u32 pci_read_config32(struct device *dev, unsigned int where)
67 struct pci_dev *d;
68 if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
69 return pci_read_long(d, where);
70 #ifdef DEBUG_PCI
71 printf("PCI: device not found while read dword (%x:%x.%x)\n",
72 dev->busno, dev->slot, dev->func);
73 #endif
74 return 0;
77 void pci_write_config8(struct device *dev, unsigned int where, u8 val)
79 struct pci_dev *d;
80 if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
81 pci_write_byte(d, where, val);
82 #ifdef DEBUG_PCI
83 else
84 printf("PCI: device not found while write byte (%x:%x.%x)\n",
85 dev->busno, dev->slot, dev->func);
86 #endif
89 void pci_write_config16(struct device *dev, unsigned int where, u16 val)
91 struct pci_dev *d;
92 if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
93 pci_write_word(d, where, val);
94 #ifdef DEBUG_PCI
95 else
96 printf("PCI: device not found while write word (%x:%x.%x)\n",
97 dev->busno, dev->slot, dev->func);
98 #endif
101 void pci_write_config32(struct device *dev, unsigned int where, u32 val)
103 struct pci_dev *d;
104 if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
105 pci_write_long(d, where, val);
106 #ifdef DEBUG_PCI
107 else
108 printf("PCI: device not found while write dword (%x:%x.%x)\n",
109 dev->busno, dev->slot, dev->func);
110 #endif