441b328e0ff6f235232e2641536b3f6a86591844
[coreboot.git] / src / devices / pci_ops.c
1 #include <console/console.h>
2 #include <arch/pciconf.h>
3 #include <device/pci.h>
4 #include <device/pci_ids.h>
5 #include <device/pci_ops.h>
6
7 static struct bus *get_pbus(device_t dev)
8 {
9         struct bus *pbus = dev->bus;
10         while(pbus && pbus->dev && !ops_pci_bus(pbus)) {
11                 pbus = pbus->dev->bus;
12         }
13         if (!pbus || !pbus->dev || !pbus->dev->ops || !pbus->dev->ops->ops_pci_bus) {
14                 printk_alert("%s Cannot find pci bus operations", dev_path(dev));
15                 die("");
16                 for(;;);
17         }
18         return pbus;
19 }
20
21 uint8_t pci_read_config8(device_t dev, unsigned where)
22 {
23         struct bus *pbus = get_pbus(dev);
24         return ops_pci_bus(pbus)->read8(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where);
25 }
26
27 uint16_t pci_read_config16(device_t dev, unsigned where)
28 {
29         struct bus *pbus = get_pbus(dev);
30         return ops_pci_bus(pbus)->read16(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where);
31 }
32
33 uint32_t pci_read_config32(device_t dev, unsigned where)
34 {
35         struct bus *pbus = get_pbus(dev);
36         return ops_pci_bus(pbus)->read32(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where);
37 }
38
39 void pci_write_config8(device_t dev, unsigned where, uint8_t val)
40 {
41         struct bus *pbus = get_pbus(dev);
42         ops_pci_bus(pbus)->write8(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where, val);
43 }
44
45 void pci_write_config16(device_t dev, unsigned where, uint16_t val)
46 {
47         struct bus *pbus = get_pbus(dev);
48         ops_pci_bus(pbus)->write16(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where, val);
49 }
50
51 void pci_write_config32(device_t dev, unsigned where, uint32_t val)
52 {
53         struct bus *pbus = get_pbus(dev);
54         ops_pci_bus(pbus)->write32(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where, val);
55 }