blob: 05450011024ffb65974e4f1a1ee24cdf00574f78 [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.
Stefan Reinauer00636b02012-04-04 00:08:51 +020014 */
15
Kyösti Mälkki54d6abd2013-06-19 23:05:00 +030016#ifndef _PCI_MMIO_CFG_H
17#define _PCI_MMIO_CFG_H
18
Kyösti Mälkki8fd78a62019-01-23 15:59:38 +020019#include <stdint.h>
Kyösti Mälkki54d6abd2013-06-19 23:05:00 +030020#include <arch/io.h>
Kyösti Mälkki8fd78a62019-01-23 15:59:38 +020021#include <device/pci_type.h>
Kyösti Mälkki54d6abd2013-06-19 23:05:00 +030022
Kyösti Mälkki54d6abd2013-06-19 23:05:00 +030023#define DEFAULT_PCIEXBAR CONFIG_MMCONF_BASE_ADDRESS
Stefan Reinauer00636b02012-04-04 00:08:51 +020024
Aaron Durbin75a62e72018-09-13 02:10:45 -060025static __always_inline
Kyösti Mälkkid8d43ba2013-10-27 14:59:00 +020026u8 pci_mmio_read_config8(pci_devfn_t dev, unsigned int where)
Stefan Reinauer00636b02012-04-04 00:08:51 +020027{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080028 void *addr;
Stefan Reinauerb0bb8a12015-06-17 16:12:17 -070029 addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | where);
Stefan Reinauer00636b02012-04-04 00:08:51 +020030 return read8(addr);
31}
32
Aaron Durbin75a62e72018-09-13 02:10:45 -060033static __always_inline
Kyösti Mälkkid8d43ba2013-10-27 14:59:00 +020034u16 pci_mmio_read_config16(pci_devfn_t dev, unsigned int where)
Stefan Reinauer00636b02012-04-04 00:08:51 +020035{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080036 void *addr;
Stefan Reinauerb0bb8a12015-06-17 16:12:17 -070037 addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~1));
Stefan Reinauer00636b02012-04-04 00:08:51 +020038 return read16(addr);
39}
40
Aaron Durbin75a62e72018-09-13 02:10:45 -060041static __always_inline
Kyösti Mälkkid8d43ba2013-10-27 14:59:00 +020042u32 pci_mmio_read_config32(pci_devfn_t dev, unsigned int where)
Stefan Reinauer00636b02012-04-04 00:08:51 +020043{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080044 void *addr;
Stefan Reinauerb0bb8a12015-06-17 16:12:17 -070045 addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~3));
Stefan Reinauer00636b02012-04-04 00:08:51 +020046 return read32(addr);
47}
48
Aaron Durbin75a62e72018-09-13 02:10:45 -060049static __always_inline
Kyösti Mälkkid8d43ba2013-10-27 14:59:00 +020050void pci_mmio_write_config8(pci_devfn_t dev, unsigned int where, u8 value)
Stefan Reinauer00636b02012-04-04 00:08:51 +020051{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080052 void *addr;
Stefan Reinauerb0bb8a12015-06-17 16:12:17 -070053 addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | where);
Stefan Reinauer00636b02012-04-04 00:08:51 +020054 write8(addr, value);
55}
56
Aaron Durbin75a62e72018-09-13 02:10:45 -060057static __always_inline
Kyösti Mälkkid8d43ba2013-10-27 14:59:00 +020058void pci_mmio_write_config16(pci_devfn_t dev, unsigned int where, u16 value)
Stefan Reinauer00636b02012-04-04 00:08:51 +020059{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080060 void *addr;
Stefan Reinauerb0bb8a12015-06-17 16:12:17 -070061 addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~1));
Stefan Reinauer00636b02012-04-04 00:08:51 +020062 write16(addr, value);
63}
64
Aaron Durbin75a62e72018-09-13 02:10:45 -060065static __always_inline
Kyösti Mälkkid8d43ba2013-10-27 14:59:00 +020066void pci_mmio_write_config32(pci_devfn_t dev, unsigned int where, u32 value)
Stefan Reinauer00636b02012-04-04 00:08:51 +020067{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080068 void *addr;
Stefan Reinauerb0bb8a12015-06-17 16:12:17 -070069 addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~3));
Stefan Reinauer00636b02012-04-04 00:08:51 +020070 write32(addr, value);
71}
72
Kyösti Mälkki2d8aff32019-01-23 16:44:55 +020073#if IS_ENABLED(CONFIG_MMCONF_SUPPORT)
74
75#ifdef __SIMPLE_DEVICE__
76static __always_inline
77uint8_t pci_read_config8(pci_devfn_t dev, unsigned int where)
78{
79 return pci_mmio_read_config8(dev, where);
80}
81
82static __always_inline
83uint16_t pci_read_config16(pci_devfn_t dev, unsigned int where)
84{
85 return pci_mmio_read_config16(dev, where);
86}
87
88static __always_inline
89uint32_t pci_read_config32(pci_devfn_t dev, unsigned int where)
90{
91 return pci_mmio_read_config32(dev, where);
92}
93
94static __always_inline
95void pci_write_config8(pci_devfn_t dev, unsigned int where, uint8_t value)
96{
97 pci_mmio_write_config8(dev, where, value);
98}
99
100static __always_inline
101void pci_write_config16(pci_devfn_t dev, unsigned int where, uint16_t value)
102{
103 pci_mmio_write_config16(dev, where, value);
104}
105
106static __always_inline
107void pci_write_config32(pci_devfn_t dev, unsigned int where, uint32_t value)
108{
109 pci_mmio_write_config32(dev, where, value);
110}
111#endif /* __SIMPLE_DEVICE__ */
112
113#endif
114
Kyösti Mälkki54d6abd2013-06-19 23:05:00 +0300115#endif /* _PCI_MMIO_CFG_H */