pci stuff: too much hax now, trying rd890 patch (not merged yet)
[coreboot.git] / src / arch / x86 / lib / pci_ops_conf1.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 1 accesses
9  */
10
11 #if CONFIG_PCI_IO_CFG_EXT == 0
12 #define CONFIG_CMD(bus,devfn, where)    (0x80000000 | (bus << 16) | \
13                                                                                 (devfn << 8) | (where & ~3))
14 #else
15 #define CONFIG_CMD(bus,devfn, where)    (0x80000000 | (bus << 16) | \
16                                                                                 (devfn << 8) | ((where & 0xff) & ~3) |\
17                                                                                 ((where & 0xf00)<<16))
18 #endif
19
20 static uint8_t pci_conf1_read_config8(struct bus *pbus, int bus, int devfn,
21                                       int where)
22 {
23         outl(CONFIG_CMD(bus, devfn, where), 0xCF8);
24         return inb(0xCFC + (where & 3));
25 }
26
27 static uint16_t pci_conf1_read_config16(struct bus *pbus, int bus, int devfn,
28                                         int where)
29 {
30         outl(CONFIG_CMD(bus, devfn, where), 0xCF8);
31         return inw(0xCFC + (where & 2));
32 }
33
34 static uint32_t pci_conf1_read_config32(struct bus *pbus, int bus, int devfn,
35                                         int where)
36 {
37         printk(BIOS_INFO, "%s: bus: 0x%2x, devfn: 0x%2x, where: 0x%2x\n", __func__, bus, devfn, where);
38         outl(CONFIG_CMD(bus, devfn, where), 0xCF8);
39         return inl(0xCFC);
40 }
41
42 static void pci_conf1_write_config8(struct bus *pbus, int bus, int devfn,
43                                     int where, uint8_t value)
44 {
45         outl(CONFIG_CMD(bus, devfn, where), 0xCF8);
46         outb(value, 0xCFC + (where & 3));
47 }
48
49 static void pci_conf1_write_config16(struct bus *pbus, int bus, int devfn,
50                                      int where, uint16_t value)
51 {
52         outl(CONFIG_CMD(bus, devfn, where), 0xCF8);
53         outw(value, 0xCFC + (where & 2));
54 }
55
56 static void pci_conf1_write_config32(struct bus *pbus, int bus, int devfn,
57                                      int where, uint32_t value)
58 {
59         outl(CONFIG_CMD(bus, devfn, where), 0xCF8);
60         outl(value, 0xCFC);
61 }
62
63 #undef CONFIG_CMD
64
65 const struct pci_bus_operations pci_cf8_conf1 = {
66         .read8 = pci_conf1_read_config8,
67         .read16 = pci_conf1_read_config16,
68         .read32 = pci_conf1_read_config32,
69         .write8 = pci_conf1_write_config8,
70         .write16 = pci_conf1_write_config16,
71         .write32 = pci_conf1_write_config32,
72 };