blob: 147b630c0b12ed68ec88eeb1e29e79d0c7d3467f [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älkki13f66502019-03-03 08:01:05 +020020#include <device/mmio.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
Kyösti Mälkki92b52962019-03-01 08:08:28 +020075/* Avoid name collisions as different stages have different signature
76 * for these functions. The _s_ stands for simple, fundamental IO or
77 * MMIO variant.
78 */
79
Kyösti Mälkki2d8aff32019-01-23 16:44:55 +020080static __always_inline
Kyösti Mälkki92b52962019-03-01 08:08:28 +020081uint8_t pci_s_read_config8(pci_devfn_t dev, unsigned int where)
Kyösti Mälkki2d8aff32019-01-23 16:44:55 +020082{
83 return pci_mmio_read_config8(dev, where);
84}
85
86static __always_inline
Kyösti Mälkki92b52962019-03-01 08:08:28 +020087uint16_t pci_s_read_config16(pci_devfn_t dev, unsigned int where)
Kyösti Mälkki2d8aff32019-01-23 16:44:55 +020088{
89 return pci_mmio_read_config16(dev, where);
90}
91
92static __always_inline
Kyösti Mälkki92b52962019-03-01 08:08:28 +020093uint32_t pci_s_read_config32(pci_devfn_t dev, unsigned int where)
Kyösti Mälkki2d8aff32019-01-23 16:44:55 +020094{
95 return pci_mmio_read_config32(dev, where);
96}
97
98static __always_inline
Kyösti Mälkki92b52962019-03-01 08:08:28 +020099void pci_s_write_config8(pci_devfn_t dev, unsigned int where, uint8_t value)
Kyösti Mälkki2d8aff32019-01-23 16:44:55 +0200100{
101 pci_mmio_write_config8(dev, where, value);
102}
103
104static __always_inline
Kyösti Mälkki92b52962019-03-01 08:08:28 +0200105void pci_s_write_config16(pci_devfn_t dev, unsigned int where, uint16_t value)
Kyösti Mälkki2d8aff32019-01-23 16:44:55 +0200106{
107 pci_mmio_write_config16(dev, where, value);
108}
109
110static __always_inline
Kyösti Mälkki92b52962019-03-01 08:08:28 +0200111void pci_s_write_config32(pci_devfn_t dev, unsigned int where, uint32_t value)
Kyösti Mälkki2d8aff32019-01-23 16:44:55 +0200112{
113 pci_mmio_write_config32(dev, where, value);
114}
Kyösti Mälkki2d8aff32019-01-23 16:44:55 +0200115
116#endif
117
Kyösti Mälkki54d6abd2013-06-19 23:05:00 +0300118#endif /* _PCI_MMIO_CFG_H */