blob: e4fa128551a5e0275a2a288bb4c93c778a4abc95 [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
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080012#define PCI_MMIO_ADDR(SEGBUS, DEVFN, WHERE, MASK) \
Stefan Reinauer96938852015-06-18 01:23:48 -070013 ((void *)(((uintptr_t)CONFIG_MMCONF_BASE_ADDRESS |\
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080014 (((SEGBUS) & 0xFFF) << 20) |\
15 (((DEVFN) & 0xFF) << 12) |\
16 ((WHERE) & 0xFFF)) & ~MASK))
Yinghai Lu5f9624d2006-10-04 22:56:21 +000017
Vikram Narayanan26dd3612012-01-24 20:18:56 +053018static uint8_t pci_mmconf_read_config8(struct bus *pbus, int bus, int devfn,
19 int where)
Yinghai Lu5f9624d2006-10-04 22:56:21 +000020{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080021 return read8(PCI_MMIO_ADDR(bus, devfn, where, 0));
Yinghai Lu5f9624d2006-10-04 22:56:21 +000022}
23
Vikram Narayanan26dd3612012-01-24 20:18:56 +053024static uint16_t pci_mmconf_read_config16(struct bus *pbus, int bus, int devfn,
25 int where)
Yinghai Lu5f9624d2006-10-04 22:56:21 +000026{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080027 return read16(PCI_MMIO_ADDR(bus, devfn, where, 1));
Yinghai Lu5f9624d2006-10-04 22:56:21 +000028}
29
Vikram Narayanan26dd3612012-01-24 20:18:56 +053030static uint32_t pci_mmconf_read_config32(struct bus *pbus, int bus, int devfn,
31 int where)
Yinghai Lu5f9624d2006-10-04 22:56:21 +000032{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080033 return read32(PCI_MMIO_ADDR(bus, devfn, where, 3));
Yinghai Lu5f9624d2006-10-04 22:56:21 +000034}
35
Vikram Narayanan26dd3612012-01-24 20:18:56 +053036static void pci_mmconf_write_config8(struct bus *pbus, int bus, int devfn,
37 int where, uint8_t value)
Yinghai Lu5f9624d2006-10-04 22:56:21 +000038{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080039 write8(PCI_MMIO_ADDR(bus, devfn, where, 0), value);
Yinghai Lu5f9624d2006-10-04 22:56:21 +000040}
41
Vikram Narayanan26dd3612012-01-24 20:18:56 +053042static void pci_mmconf_write_config16(struct bus *pbus, int bus, int devfn,
43 int where, uint16_t value)
Yinghai Lu5f9624d2006-10-04 22:56:21 +000044{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080045 write16(PCI_MMIO_ADDR(bus, devfn, where, 1), value);
Yinghai Lu5f9624d2006-10-04 22:56:21 +000046}
47
Vikram Narayanan26dd3612012-01-24 20:18:56 +053048static void pci_mmconf_write_config32(struct bus *pbus, int bus, int devfn,
49 int where, uint32_t value)
Yinghai Lu5f9624d2006-10-04 22:56:21 +000050{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080051 write32(PCI_MMIO_ADDR(bus, devfn, where, 3), value);
Yinghai Lu5f9624d2006-10-04 22:56:21 +000052}
53
Vikram Narayanan26dd3612012-01-24 20:18:56 +053054const struct pci_bus_operations pci_ops_mmconf = {
55 .read8 = pci_mmconf_read_config8,
Yinghai Lu5f9624d2006-10-04 22:56:21 +000056 .read16 = pci_mmconf_read_config16,
57 .read32 = pci_mmconf_read_config32,
Vikram Narayanan26dd3612012-01-24 20:18:56 +053058 .write8 = pci_mmconf_write_config8,
Yinghai Lu5f9624d2006-10-04 22:56:21 +000059 .write16 = pci_mmconf_write_config16,
60 .write32 = pci_mmconf_write_config32,
61};