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 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame^] | 12 | #define PCI_MMIO_ADDR(SEGBUS, DEVFN, WHERE, MASK) \ |
| 13 | ((void *)((CONFIG_MMCONF_BASE_ADDRESS |\ |
| 14 | (((SEGBUS) & 0xFFF) << 20) |\ |
| 15 | (((DEVFN) & 0xFF) << 12) |\ |
| 16 | ((WHERE) & 0xFFF)) & ~MASK)) |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 17 | |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 18 | static uint8_t pci_mmconf_read_config8(struct bus *pbus, int bus, int devfn, |
| 19 | int where) |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 20 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame^] | 21 | return read8(PCI_MMIO_ADDR(bus, devfn, where, 0)); |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 22 | } |
| 23 | |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 24 | static uint16_t pci_mmconf_read_config16(struct bus *pbus, int bus, int devfn, |
| 25 | int where) |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 26 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame^] | 27 | return read16(PCI_MMIO_ADDR(bus, devfn, where, 1)); |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 30 | static uint32_t pci_mmconf_read_config32(struct bus *pbus, int bus, int devfn, |
| 31 | int where) |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 32 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame^] | 33 | return read32(PCI_MMIO_ADDR(bus, devfn, where, 3)); |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 36 | static void pci_mmconf_write_config8(struct bus *pbus, int bus, int devfn, |
| 37 | int where, uint8_t value) |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 38 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame^] | 39 | write8(PCI_MMIO_ADDR(bus, devfn, where, 0), value); |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 42 | static void pci_mmconf_write_config16(struct bus *pbus, int bus, int devfn, |
| 43 | int where, uint16_t value) |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 44 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame^] | 45 | write16(PCI_MMIO_ADDR(bus, devfn, where, 1), value); |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 48 | static void pci_mmconf_write_config32(struct bus *pbus, int bus, int devfn, |
| 49 | int where, uint32_t value) |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 50 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame^] | 51 | write32(PCI_MMIO_ADDR(bus, devfn, where, 3), value); |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 54 | const struct pci_bus_operations pci_ops_mmconf = { |
| 55 | .read8 = pci_mmconf_read_config8, |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 56 | .read16 = pci_mmconf_read_config16, |
| 57 | .read32 = pci_mmconf_read_config32, |
Vikram Narayanan | 26dd361 | 2012-01-24 20:18:56 +0530 | [diff] [blame] | 58 | .write8 = pci_mmconf_write_config8, |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 59 | .write16 = pci_mmconf_write_config16, |
| 60 | .write32 = pci_mmconf_write_config32, |
| 61 | }; |