Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 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 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 11 | #if !CONFIG_PCI_IO_CFG_EXT |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 12 | #define CONFIG_CMD(bus,devfn, where) (0x80000000 | (bus << 16) | \ |
| 13 | (devfn << 8) | (where & ~3)) |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 14 | #else |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 15 | #define CONFIG_CMD(bus,devfn, where) (0x80000000 | (bus << 16) | \ |
| 16 | (devfn << 8) | ((where & 0xff) & ~3) |\ |
| 17 | ((where & 0xf00)<<16)) |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 18 | #endif |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 19 | |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 20 | static uint8_t pci_conf1_read_config8(struct bus *pbus, int bus, int devfn, |
| 21 | int where) |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 22 | { |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 23 | outl(CONFIG_CMD(bus, devfn, where), 0xCF8); |
| 24 | return inb(0xCFC + (where & 3)); |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 25 | } |
| 26 | |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 27 | static uint16_t pci_conf1_read_config16(struct bus *pbus, int bus, int devfn, |
| 28 | int where) |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 29 | { |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 30 | outl(CONFIG_CMD(bus, devfn, where), 0xCF8); |
| 31 | return inw(0xCFC + (where & 2)); |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 34 | static uint32_t pci_conf1_read_config32(struct bus *pbus, int bus, int devfn, |
| 35 | int where) |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 36 | { |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 37 | outl(CONFIG_CMD(bus, devfn, where), 0xCF8); |
| 38 | return inl(0xCFC); |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 41 | static void pci_conf1_write_config8(struct bus *pbus, int bus, int devfn, |
| 42 | int where, uint8_t value) |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 43 | { |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 44 | outl(CONFIG_CMD(bus, devfn, where), 0xCF8); |
| 45 | outb(value, 0xCFC + (where & 3)); |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 48 | static void pci_conf1_write_config16(struct bus *pbus, int bus, int devfn, |
| 49 | int where, uint16_t value) |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 50 | { |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 51 | outl(CONFIG_CMD(bus, devfn, where), 0xCF8); |
| 52 | outw(value, 0xCFC + (where & 2)); |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 55 | static void pci_conf1_write_config32(struct bus *pbus, int bus, int devfn, |
| 56 | int where, uint32_t value) |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 57 | { |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 58 | outl(CONFIG_CMD(bus, devfn, where), 0xCF8); |
| 59 | outl(value, 0xCFC); |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | #undef CONFIG_CMD |
| 63 | |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 64 | const struct pci_bus_operations pci_cf8_conf1 = { |
| 65 | .read8 = pci_conf1_read_config8, |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 66 | .read16 = pci_conf1_read_config16, |
| 67 | .read32 = pci_conf1_read_config32, |
Vikram Narayanan | 31b680b | 2012-01-24 19:17:47 +0530 | [diff] [blame] | 68 | .write8 = pci_conf1_write_config8, |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 69 | .write16 = pci_conf1_write_config16, |
| 70 | .write32 = pci_conf1_write_config32, |
| 71 | }; |