Add constants for fast path resume copying
[coreboot.git] / src / arch / x86 / lib / pci_ops_conf2.c
1 #include <console/console.h>
2 #include <arch/io.h>
3 #include <arch/pciconf.h>
4 #include <device/pci.h>
5 #include <device/pci_ids.h>
6 #include <device/pci_ops.h>
7 /*
8  * Functions for accessing PCI configuration space with type 2 accesses
9  */
10
11 #define IOADDR(devfn, where)    ((0xC000 | ((devfn & 0x78) << 5)) + where)
12 #define FUNC(devfn)             (((devfn & 7) << 1) | 0xf0)
13 #define SET(bus,devfn)          outb(FUNC(devfn), 0xCF8); outb(bus, 0xCFA);
14
15 static uint8_t pci_conf2_read_config8(struct bus *pbus, int bus, int devfn,
16                                       int where)
17 {
18         uint8_t value;
19         SET(bus, devfn);
20         value = inb(IOADDR(devfn, where));
21         outb(0, 0xCF8);
22         return value;
23 }
24
25 static uint16_t pci_conf2_read_config16(struct bus *pbus, int bus, int devfn,
26                                         int where)
27 {
28         uint16_t value;
29         SET(bus, devfn);
30         value = inw(IOADDR(devfn, where));
31         outb(0, 0xCF8);
32         return value;
33 }
34
35 static uint32_t pci_conf2_read_config32(struct bus *pbus, int bus, int devfn,
36                                         int where)
37 {
38         uint32_t value;
39         SET(bus, devfn);
40         value = inl(IOADDR(devfn, where));
41         outb(0, 0xCF8);
42         return value;
43 }
44
45 static void pci_conf2_write_config8(struct bus *pbus, int bus, int devfn,
46                                     int where, uint8_t value)
47 {
48         SET(bus, devfn);
49         outb(value, IOADDR(devfn, where));
50         outb(0, 0xCF8);
51 }
52
53 static void pci_conf2_write_config16(struct bus *pbus, int bus, int devfn,
54                                      int where, uint16_t value)
55 {
56         SET(bus, devfn);
57         outw(value, IOADDR(devfn, where));
58         outb(0, 0xCF8);
59 }
60
61 static void pci_conf2_write_config32(struct bus *pbus, int bus, int devfn,
62                                      int where, uint32_t value)
63 {
64         SET(bus, devfn);
65         outl(value, IOADDR(devfn, where));
66         outb(0, 0xCF8);
67 }
68
69 #undef SET
70 #undef IOADDR
71 #undef FUNC
72
73 const struct pci_bus_operations pci_cf8_conf2 = {
74         .read8 = pci_conf2_read_config8,
75         .read16 = pci_conf2_read_config16,
76         .read32 = pci_conf2_read_config32,
77         .write8 = pci_conf2_write_config8,
78         .write16 = pci_conf2_write_config16,
79         .write32 = pci_conf2_write_config32,
80 };