Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +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 | |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 8 | /* |
| 9 | * Functions for accessing PCI configuration space with mmconf accesses |
| 10 | */ |
| 11 | |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 12 | #define PCI_MMIO_ADDR(SEGBUS, DEVFN, WHERE) \ |
| 13 | (CONFIG_MMCONF_BASE_ADDRESS |\ |
| 14 | (((SEGBUS) & 0xFFF) << 20) |\ |
| 15 | (((DEVFN) & 0xFF) << 12) |\ |
| 16 | ((WHERE) & 0xFFF)) |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 17 | |
| 18 | #include <arch/mmio_conf.h> |
| 19 | |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 20 | static uint8_t pci_mmconf_read_config8(struct bus *pbus, int bus, int devfn, |
| 21 | int where) |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 22 | { |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 23 | return (read8x(PCI_MMIO_ADDR(bus, devfn, where))); |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 24 | } |
| 25 | |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 26 | static uint16_t pci_mmconf_read_config16(struct bus *pbus, int bus, int devfn, |
| 27 | int where) |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 28 | { |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 29 | return (read16x(PCI_MMIO_ADDR(bus, devfn, where) & ~1)); |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 32 | static uint32_t pci_mmconf_read_config32(struct bus *pbus, int bus, int devfn, |
| 33 | int where) |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 34 | { |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 35 | return (read32x(PCI_MMIO_ADDR(bus, devfn, where) & ~3)); |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 38 | static void pci_mmconf_write_config8(struct bus *pbus, int bus, int devfn, |
| 39 | int where, uint8_t value) |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 40 | { |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 41 | write8x(PCI_MMIO_ADDR(bus, devfn, where), value); |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 44 | static void pci_mmconf_write_config16(struct bus *pbus, int bus, int devfn, |
| 45 | int where, uint16_t value) |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 46 | { |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 47 | write16x(PCI_MMIO_ADDR(bus, devfn, where) & ~1, value); |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 50 | static void pci_mmconf_write_config32(struct bus *pbus, int bus, int devfn, |
| 51 | int where, uint32_t value) |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 52 | { |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 53 | write32x(PCI_MMIO_ADDR(bus, devfn, where) & ~3, value); |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 56 | const struct pci_bus_operations pci_ops_mmconf = { |
| 57 | .read8 = pci_mmconf_read_config8, |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 58 | .read16 = pci_mmconf_read_config16, |
| 59 | .read32 = pci_mmconf_read_config32, |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 60 | .write8 = pci_mmconf_write_config8, |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 61 | .write16 = pci_mmconf_write_config16, |
| 62 | .write32 = pci_mmconf_write_config32, |
| 63 | }; |