After this has been brought up many times before, rename src/arch/i386 to
[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, int where)
16 {
17         uint8_t value;
18         SET(bus, devfn);
19         value = inb(IOADDR(devfn, where));
20         outb(0, 0xCF8);
21         return value;
22 }
23
24 static uint16_t pci_conf2_read_config16(struct bus *pbus, int bus, int devfn, int where)
25 {
26         uint16_t value;
27         SET(bus, devfn);
28         value = inw(IOADDR(devfn, where));
29         outb(0, 0xCF8);
30         return value;
31 }
32
33 static uint32_t pci_conf2_read_config32(struct bus *pbus, int bus, int devfn, int where)
34 {
35         uint32_t value;
36         SET(bus, devfn);
37         value = inl(IOADDR(devfn, where));
38         outb(0, 0xCF8);
39         return value;
40 }
41
42 static void pci_conf2_write_config8(struct bus *pbus, int bus, int devfn, int where, uint8_t value)
43 {
44         SET(bus, devfn);
45         outb(value, IOADDR(devfn, where));
46         outb(0, 0xCF8);
47 }
48
49 static void pci_conf2_write_config16(struct bus *pbus, int bus, int devfn, int where, uint16_t value)
50 {
51         SET(bus, devfn);
52         outw(value, IOADDR(devfn, where));
53         outb(0, 0xCF8);
54 }
55
56 static void pci_conf2_write_config32(struct bus *pbus, int bus, int devfn, int where, uint32_t value)
57 {
58         SET(bus, devfn);
59         outl(value, IOADDR(devfn, where));
60         outb(0, 0xCF8);
61 }
62
63 #undef SET
64 #undef IOADDR
65 #undef FUNC
66
67 const struct pci_bus_operations pci_cf8_conf2 =
68 {
69         .read8  = pci_conf2_read_config8,
70         .read16 = pci_conf2_read_config16,
71         .read32 = pci_conf2_read_config32,
72         .write8  = pci_conf2_write_config8,
73         .write16 = pci_conf2_write_config16,
74         .write32 = pci_conf2_write_config32,
75 };
76