blob: eec9d97a4c167c068f2f1b5859a010b25322519d [file] [log] [blame]
Stefan Reinauer00636b02012-04-04 00:08:51 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2009 coresystems GmbH
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010017 * Foundation, Inc.
Stefan Reinauer00636b02012-04-04 00:08:51 +020018 */
19
Kyösti Mälkki54d6abd2013-06-19 23:05:00 +030020#ifndef _PCI_MMIO_CFG_H
21#define _PCI_MMIO_CFG_H
22
23#include <arch/io.h>
24
25#if CONFIG_MMCONF_SUPPORT
26#define DEFAULT_PCIEXBAR CONFIG_MMCONF_BASE_ADDRESS
Stefan Reinauer00636b02012-04-04 00:08:51 +020027
28static inline __attribute__ ((always_inline))
Kyösti Mälkki3f9a62e2013-06-20 20:25:21 +030029u8 pcie_read_config8(pci_devfn_t dev, unsigned int where)
Stefan Reinauer00636b02012-04-04 00:08:51 +020030{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080031 void *addr;
Stefan Reinauerb0bb8a12015-06-17 16:12:17 -070032 addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | where);
Stefan Reinauer00636b02012-04-04 00:08:51 +020033 return read8(addr);
34}
35
36static inline __attribute__ ((always_inline))
Kyösti Mälkki3f9a62e2013-06-20 20:25:21 +030037u16 pcie_read_config16(pci_devfn_t dev, unsigned int where)
Stefan Reinauer00636b02012-04-04 00:08:51 +020038{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080039 void *addr;
Stefan Reinauerb0bb8a12015-06-17 16:12:17 -070040 addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~1));
Stefan Reinauer00636b02012-04-04 00:08:51 +020041 return read16(addr);
42}
43
44static inline __attribute__ ((always_inline))
Kyösti Mälkki3f9a62e2013-06-20 20:25:21 +030045u32 pcie_read_config32(pci_devfn_t dev, unsigned int where)
Stefan Reinauer00636b02012-04-04 00:08:51 +020046{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080047 void *addr;
Stefan Reinauerb0bb8a12015-06-17 16:12:17 -070048 addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~3));
Stefan Reinauer00636b02012-04-04 00:08:51 +020049 return read32(addr);
50}
51
52static inline __attribute__ ((always_inline))
Kyösti Mälkki3f9a62e2013-06-20 20:25:21 +030053void pcie_write_config8(pci_devfn_t dev, unsigned int where, u8 value)
Stefan Reinauer00636b02012-04-04 00:08:51 +020054{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080055 void *addr;
Stefan Reinauerb0bb8a12015-06-17 16:12:17 -070056 addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | where);
Stefan Reinauer00636b02012-04-04 00:08:51 +020057 write8(addr, value);
58}
59
60static inline __attribute__ ((always_inline))
Kyösti Mälkki3f9a62e2013-06-20 20:25:21 +030061void pcie_write_config16(pci_devfn_t dev, unsigned int where, u16 value)
Stefan Reinauer00636b02012-04-04 00:08:51 +020062{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080063 void *addr;
Stefan Reinauerb0bb8a12015-06-17 16:12:17 -070064 addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~1));
Stefan Reinauer00636b02012-04-04 00:08:51 +020065 write16(addr, value);
66}
67
68static inline __attribute__ ((always_inline))
Kyösti Mälkki3f9a62e2013-06-20 20:25:21 +030069void pcie_write_config32(pci_devfn_t dev, unsigned int where, u32 value)
Stefan Reinauer00636b02012-04-04 00:08:51 +020070{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080071 void *addr;
Stefan Reinauerb0bb8a12015-06-17 16:12:17 -070072 addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~3));
Stefan Reinauer00636b02012-04-04 00:08:51 +020073 write32(addr, value);
74}
75
76static inline __attribute__ ((always_inline))
Kyösti Mälkki3f9a62e2013-06-20 20:25:21 +030077void pcie_or_config8(pci_devfn_t dev, unsigned int where, u8 ormask)
Stefan Reinauer00636b02012-04-04 00:08:51 +020078{
79 u8 value = pcie_read_config8(dev, where);
80 pcie_write_config8(dev, where, value | ormask);
81}
82
83static inline __attribute__ ((always_inline))
Kyösti Mälkki3f9a62e2013-06-20 20:25:21 +030084void pcie_or_config16(pci_devfn_t dev, unsigned int where, u16 ormask)
Stefan Reinauer00636b02012-04-04 00:08:51 +020085{
86 u16 value = pcie_read_config16(dev, where);
87 pcie_write_config16(dev, where, value | ormask);
88}
89
90static inline __attribute__ ((always_inline))
Kyösti Mälkki3f9a62e2013-06-20 20:25:21 +030091void pcie_or_config32(pci_devfn_t dev, unsigned int where, u32 ormask)
Stefan Reinauer00636b02012-04-04 00:08:51 +020092{
93 u32 value = pcie_read_config32(dev, where);
94 pcie_write_config32(dev, where, value | ormask);
95}
Kyösti Mälkki54d6abd2013-06-19 23:05:00 +030096
Kyösti Mälkkib25a9da2013-06-26 08:19:14 +030097#define pci_mmio_read_config8 pcie_read_config8
98#define pci_mmio_read_config16 pcie_read_config16
99#define pci_mmio_read_config32 pcie_read_config32
100
101#define pci_mmio_write_config8 pcie_write_config8
102#define pci_mmio_write_config16 pcie_write_config16
103#define pci_mmio_write_config32 pcie_write_config32
104
105#if CONFIG_MMCONF_SUPPORT_DEFAULT
106#define pci_read_config8 pcie_read_config8
107#define pci_read_config16 pcie_read_config16
108#define pci_read_config32 pcie_read_config32
109
110#define pci_write_config8 pcie_write_config8
111#define pci_write_config16 pcie_write_config16
112#define pci_write_config32 pcie_write_config32
113#endif
114
Kyösti Mälkki54d6abd2013-06-19 23:05:00 +0300115#endif /* CONFIG_MMCONF_SUPPORT */
116#endif /* _PCI_MMIO_CFG_H */