7fcd88ae87b663b830ff73d5e67afd98371fc2f2
[coreboot.git] / src / arch / x86 / lib / pci_ops_mmconf.c
1 #if CONFIG_MMCONF_SUPPORT
2
3 #include <console/console.h>
4 #include <arch/io.h>
5 #include <arch/pciconf.h>
6 #include <device/pci.h>
7 #include <device/pci_ids.h>
8 #include <device/pci_ops.h>
9
10 /*
11  * Functions for accessing PCI configuration space with mmconf accesses
12  */
13
14 #define PCI_MMIO_ADDR(SEGBUS, DEVFN, WHERE)     \
15                                 (CONFIG_MMCONF_BASE_ADDRESS |\
16                                 (((SEGBUS) & 0xFFF) << 20) |\
17                                 (((DEVFN) & 0xFF) << 12) |\
18                                 ((WHERE) & 0xFFF))
19
20 #include <arch/mmio_conf.h>
21
22 static uint8_t pci_mmconf_read_config8(struct bus *pbus, int bus, int devfn,
23                                        int where)
24 {
25         return (read8x(PCI_MMIO_ADDR(bus, devfn, where)));
26 }
27
28 static uint16_t pci_mmconf_read_config16(struct bus *pbus, int bus, int devfn,
29                                          int where)
30 {
31         return (read16x(PCI_MMIO_ADDR(bus, devfn, where) & ~1));
32 }
33
34 static uint32_t pci_mmconf_read_config32(struct bus *pbus, int bus, int devfn,
35                                          int where)
36 {
37         return (read32x(PCI_MMIO_ADDR(bus, devfn, where) & ~3));
38 }
39
40 static void pci_mmconf_write_config8(struct bus *pbus, int bus, int devfn,
41                                      int where, uint8_t value)
42 {
43         write8x(PCI_MMIO_ADDR(bus, devfn, where), value);
44 }
45
46 static void pci_mmconf_write_config16(struct bus *pbus, int bus, int devfn,
47                                       int where, uint16_t value)
48 {
49         write16x(PCI_MMIO_ADDR(bus, devfn, where) & ~1, value);
50 }
51
52 static void pci_mmconf_write_config32(struct bus *pbus, int bus, int devfn,
53                                       int where, uint32_t value)
54 {
55         write32x(PCI_MMIO_ADDR(bus, devfn, where) & ~3, value);
56 }
57
58 const struct pci_bus_operations pci_ops_mmconf = {
59         .read8 = pci_mmconf_read_config8,
60         .read16 = pci_mmconf_read_config16,
61         .read32 = pci_mmconf_read_config32,
62         .write8 = pci_mmconf_write_config8,
63         .write16 = pci_mmconf_write_config16,
64         .write32 = pci_mmconf_write_config32,
65 };
66
67 #endif