nb/via/vx900: Ensure memory size and base are in range
[coreboot.git] / util / vgabios / pci-userspace.c
blob0390f7a494cb013d147fcaf6c9ad0bd2c158f045
1 /*
2 * This file is part of the coreboot project.
4 * Copyright (C) 2016 Google Inc
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <stdio.h>
17 #include <pci/pci.h>
18 #include "pci-userspace.h"
20 #define DEBUG_PCI 1
22 static struct pci_access *pacc;
24 int pci_initialize(void)
26 struct pci_dev *dev;
28 pacc = pci_alloc();
30 pci_init(pacc);
31 pci_scan_bus(pacc);
32 for (dev = pacc->devices; dev; dev = dev->next) {
33 pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES);
35 return 0;
38 int pci_exit(void)
40 pci_cleanup(pacc);
41 return 0;
44 u8 pci_read_config8(struct device *dev, unsigned int where)
46 struct pci_dev *d;
47 if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
48 return pci_read_byte(d, where);
49 #ifdef DEBUG_PCI
50 printf("PCI: device not found while read byte (%x:%x.%x)\n",
51 dev->busno, dev->slot, dev->func);
52 #endif
53 return 0;
56 u16 pci_read_config16(struct device *dev, unsigned int where)
58 struct pci_dev *d;
59 if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
60 return pci_read_word(d, where);
61 #ifdef DEBUG_PCI
62 printf("PCI: device not found while read word (%x:%x.%x)\n",
63 dev->busno, dev->slot, dev->func);
64 #endif
65 return 0;
68 u32 pci_read_config32(struct device *dev, unsigned int where)
70 struct pci_dev *d;
71 if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
72 return pci_read_long(d, where);
73 #ifdef DEBUG_PCI
74 printf("PCI: device not found while read dword (%x:%x.%x)\n",
75 dev->busno, dev->slot, dev->func);
76 #endif
77 return 0;
80 void pci_write_config8(struct device *dev, unsigned int where, u8 val)
82 struct pci_dev *d;
83 if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
84 pci_write_byte(d, where, val);
85 #ifdef DEBUG_PCI
86 else
87 printf("PCI: device not found while write byte (%x:%x.%x)\n",
88 dev->busno, dev->slot, dev->func);
89 #endif
92 void pci_write_config16(struct device *dev, unsigned int where, u16 val)
94 struct pci_dev *d;
95 if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
96 pci_write_word(d, where, val);
97 #ifdef DEBUG_PCI
98 else
99 printf("PCI: device not found while write word (%x:%x.%x)\n",
100 dev->busno, dev->slot, dev->func);
101 #endif
104 void pci_write_config32(struct device *dev, unsigned int where, u32 val)
106 struct pci_dev *d;
107 if ((d = pci_get_dev(pacc, 0, dev->busno, dev->slot, dev->func)))
108 pci_write_long(d, where, val);
109 #ifdef DEBUG_PCI
110 else
111 printf("PCI: device not found while write dword (%x:%x.%x)\n",
112 dev->busno, dev->slot, dev->func);
113 #endif