soc/amd/glinda: Update MCA banks
[coreboot2.git] / util / vgabios / pci-userspace.c
blob5d8a7fedf0b2aacc046d7642178a053e1be0589c
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <stdio.h>
4 #include <pci/pci.h>
5 #include "pci-userspace.h"
7 #define DEBUG_PCI 1
9 static struct pci_access *pacc;
11 int pci_initialize(void)
13 struct pci_dev *dev;
15 pacc = pci_alloc();
17 pci_init(pacc);
18 pci_scan_bus(pacc);
19 for (dev = pacc->devices; dev; dev = dev->next) {
20 pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES);
22 return 0;
25 int pci_exit(void)
27 pci_cleanup(pacc);
28 return 0;
31 u8 pci_read_config8(struct device *dev, unsigned int where)
33 struct pci_dev *d;
34 if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
35 return pci_read_byte(d, where);
36 #ifdef DEBUG_PCI
37 printf("PCI: device not found while read byte (%x:%x.%x)\n",
38 dev->busno, dev->slot, dev->func);
39 #endif
40 return 0;
43 u16 pci_read_config16(struct device *dev, unsigned int where)
45 struct pci_dev *d;
46 if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
47 return pci_read_word(d, where);
48 #ifdef DEBUG_PCI
49 printf("PCI: device not found while read word (%x:%x.%x)\n",
50 dev->busno, dev->slot, dev->func);
51 #endif
52 return 0;
55 u32 pci_read_config32(struct device *dev, unsigned int where)
57 struct pci_dev *d;
58 if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
59 return pci_read_long(d, where);
60 #ifdef DEBUG_PCI
61 printf("PCI: device not found while read dword (%x:%x.%x)\n",
62 dev->busno, dev->slot, dev->func);
63 #endif
64 return 0;
67 void pci_write_config8(struct device *dev, unsigned int where, u8 val)
69 struct pci_dev *d;
70 if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
71 pci_write_byte(d, where, val);
72 #ifdef DEBUG_PCI
73 else
74 printf("PCI: device not found while write byte (%x:%x.%x)\n",
75 dev->busno, dev->slot, dev->func);
76 #endif
79 void pci_write_config16(struct device *dev, unsigned int where, u16 val)
81 struct pci_dev *d;
82 if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
83 pci_write_word(d, where, val);
84 #ifdef DEBUG_PCI
85 else
86 printf("PCI: device not found while write word (%x:%x.%x)\n",
87 dev->busno, dev->slot, dev->func);
88 #endif
91 void pci_write_config32(struct device *dev, unsigned int where, u32 val)
93 struct pci_dev *d;
94 if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
95 pci_write_long(d, where, val);
96 #ifdef DEBUG_PCI
97 else
98 printf("PCI: device not found while write dword (%x:%x.%x)\n",
99 dev->busno, dev->slot, dev->func);
100 #endif