blob: 4f9d8265c16d4c1dd7b5740469daa5aa805e25df [file] [log] [blame]
Yinghai Lu5f9624d2006-10-04 22:56:21 +00001#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 Lu5f9624d2006-10-04 22:56:21 +00008/*
9 * Functions for accessing PCI configuration space with mmconf accesses
10 */
11
Vikram Narayanan26dd3612012-01-24 20:18:56 +053012#define PCI_MMIO_ADDR(SEGBUS, DEVFN, WHERE) \
13 (CONFIG_MMCONF_BASE_ADDRESS |\
14 (((SEGBUS) & 0xFFF) << 20) |\
15 (((DEVFN) & 0xFF) << 12) |\
16 ((WHERE) & 0xFFF))
Yinghai Lu5f9624d2006-10-04 22:56:21 +000017
18#include <arch/mmio_conf.h>
19
Vikram Narayanan26dd3612012-01-24 20:18:56 +053020static uint8_t pci_mmconf_read_config8(struct bus *pbus, int bus, int devfn,
21 int where)
Yinghai Lu5f9624d2006-10-04 22:56:21 +000022{
Vikram Narayanan26dd3612012-01-24 20:18:56 +053023 return (read8x(PCI_MMIO_ADDR(bus, devfn, where)));
Yinghai Lu5f9624d2006-10-04 22:56:21 +000024}
25
Vikram Narayanan26dd3612012-01-24 20:18:56 +053026static uint16_t pci_mmconf_read_config16(struct bus *pbus, int bus, int devfn,
27 int where)
Yinghai Lu5f9624d2006-10-04 22:56:21 +000028{
Vikram Narayanan26dd3612012-01-24 20:18:56 +053029 return (read16x(PCI_MMIO_ADDR(bus, devfn, where) & ~1));
Yinghai Lu5f9624d2006-10-04 22:56:21 +000030}
31
Vikram Narayanan26dd3612012-01-24 20:18:56 +053032static uint32_t pci_mmconf_read_config32(struct bus *pbus, int bus, int devfn,
33 int where)
Yinghai Lu5f9624d2006-10-04 22:56:21 +000034{
Vikram Narayanan26dd3612012-01-24 20:18:56 +053035 return (read32x(PCI_MMIO_ADDR(bus, devfn, where) & ~3));
Yinghai Lu5f9624d2006-10-04 22:56:21 +000036}
37
Vikram Narayanan26dd3612012-01-24 20:18:56 +053038static void pci_mmconf_write_config8(struct bus *pbus, int bus, int devfn,
39 int where, uint8_t value)
Yinghai Lu5f9624d2006-10-04 22:56:21 +000040{
Vikram Narayanan26dd3612012-01-24 20:18:56 +053041 write8x(PCI_MMIO_ADDR(bus, devfn, where), value);
Yinghai Lu5f9624d2006-10-04 22:56:21 +000042}
43
Vikram Narayanan26dd3612012-01-24 20:18:56 +053044static void pci_mmconf_write_config16(struct bus *pbus, int bus, int devfn,
45 int where, uint16_t value)
Yinghai Lu5f9624d2006-10-04 22:56:21 +000046{
Vikram Narayanan26dd3612012-01-24 20:18:56 +053047 write16x(PCI_MMIO_ADDR(bus, devfn, where) & ~1, value);
Yinghai Lu5f9624d2006-10-04 22:56:21 +000048}
49
Vikram Narayanan26dd3612012-01-24 20:18:56 +053050static void pci_mmconf_write_config32(struct bus *pbus, int bus, int devfn,
51 int where, uint32_t value)
Yinghai Lu5f9624d2006-10-04 22:56:21 +000052{
Vikram Narayanan26dd3612012-01-24 20:18:56 +053053 write32x(PCI_MMIO_ADDR(bus, devfn, where) & ~3, value);
Yinghai Lu5f9624d2006-10-04 22:56:21 +000054}
55
Vikram Narayanan26dd3612012-01-24 20:18:56 +053056const struct pci_bus_operations pci_ops_mmconf = {
57 .read8 = pci_mmconf_read_config8,
Yinghai Lu5f9624d2006-10-04 22:56:21 +000058 .read16 = pci_mmconf_read_config16,
59 .read32 = pci_mmconf_read_config32,
Vikram Narayanan26dd3612012-01-24 20:18:56 +053060 .write8 = pci_mmconf_write_config8,
Yinghai Lu5f9624d2006-10-04 22:56:21 +000061 .write16 = pci_mmconf_write_config16,
62 .write32 = pci_mmconf_write_config32,
63};