Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 1 | /* |
| 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 Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 17 | * Foundation, Inc. |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 18 | */ |
| 19 | |
Kyösti Mälkki | 54d6abd | 2013-06-19 23:05:00 +0300 | [diff] [blame] | 20 | #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 Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 27 | |
| 28 | static inline __attribute__ ((always_inline)) |
Kyösti Mälkki | 3f9a62e | 2013-06-20 20:25:21 +0300 | [diff] [blame] | 29 | u8 pcie_read_config8(pci_devfn_t dev, unsigned int where) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 30 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 31 | void *addr; |
Stefan Reinauer | b0bb8a1 | 2015-06-17 16:12:17 -0700 | [diff] [blame^] | 32 | addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | where); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 33 | return read8(addr); |
| 34 | } |
| 35 | |
| 36 | static inline __attribute__ ((always_inline)) |
Kyösti Mälkki | 3f9a62e | 2013-06-20 20:25:21 +0300 | [diff] [blame] | 37 | u16 pcie_read_config16(pci_devfn_t dev, unsigned int where) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 38 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 39 | void *addr; |
Stefan Reinauer | b0bb8a1 | 2015-06-17 16:12:17 -0700 | [diff] [blame^] | 40 | addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~1)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 41 | return read16(addr); |
| 42 | } |
| 43 | |
| 44 | static inline __attribute__ ((always_inline)) |
Kyösti Mälkki | 3f9a62e | 2013-06-20 20:25:21 +0300 | [diff] [blame] | 45 | u32 pcie_read_config32(pci_devfn_t dev, unsigned int where) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 46 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 47 | void *addr; |
Stefan Reinauer | b0bb8a1 | 2015-06-17 16:12:17 -0700 | [diff] [blame^] | 48 | addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~3)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 49 | return read32(addr); |
| 50 | } |
| 51 | |
| 52 | static inline __attribute__ ((always_inline)) |
Kyösti Mälkki | 3f9a62e | 2013-06-20 20:25:21 +0300 | [diff] [blame] | 53 | void pcie_write_config8(pci_devfn_t dev, unsigned int where, u8 value) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 54 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 55 | void *addr; |
Stefan Reinauer | b0bb8a1 | 2015-06-17 16:12:17 -0700 | [diff] [blame^] | 56 | addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | where); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 57 | write8(addr, value); |
| 58 | } |
| 59 | |
| 60 | static inline __attribute__ ((always_inline)) |
Kyösti Mälkki | 3f9a62e | 2013-06-20 20:25:21 +0300 | [diff] [blame] | 61 | void pcie_write_config16(pci_devfn_t dev, unsigned int where, u16 value) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 62 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 63 | void *addr; |
Stefan Reinauer | b0bb8a1 | 2015-06-17 16:12:17 -0700 | [diff] [blame^] | 64 | addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~1)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 65 | write16(addr, value); |
| 66 | } |
| 67 | |
| 68 | static inline __attribute__ ((always_inline)) |
Kyösti Mälkki | 3f9a62e | 2013-06-20 20:25:21 +0300 | [diff] [blame] | 69 | void pcie_write_config32(pci_devfn_t dev, unsigned int where, u32 value) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 70 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 71 | void *addr; |
Stefan Reinauer | b0bb8a1 | 2015-06-17 16:12:17 -0700 | [diff] [blame^] | 72 | addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~3)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 73 | write32(addr, value); |
| 74 | } |
| 75 | |
| 76 | static inline __attribute__ ((always_inline)) |
Kyösti Mälkki | 3f9a62e | 2013-06-20 20:25:21 +0300 | [diff] [blame] | 77 | void pcie_or_config8(pci_devfn_t dev, unsigned int where, u8 ormask) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 78 | { |
| 79 | u8 value = pcie_read_config8(dev, where); |
| 80 | pcie_write_config8(dev, where, value | ormask); |
| 81 | } |
| 82 | |
| 83 | static inline __attribute__ ((always_inline)) |
Kyösti Mälkki | 3f9a62e | 2013-06-20 20:25:21 +0300 | [diff] [blame] | 84 | void pcie_or_config16(pci_devfn_t dev, unsigned int where, u16 ormask) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 85 | { |
| 86 | u16 value = pcie_read_config16(dev, where); |
| 87 | pcie_write_config16(dev, where, value | ormask); |
| 88 | } |
| 89 | |
| 90 | static inline __attribute__ ((always_inline)) |
Kyösti Mälkki | 3f9a62e | 2013-06-20 20:25:21 +0300 | [diff] [blame] | 91 | void pcie_or_config32(pci_devfn_t dev, unsigned int where, u32 ormask) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 92 | { |
| 93 | u32 value = pcie_read_config32(dev, where); |
| 94 | pcie_write_config32(dev, where, value | ormask); |
| 95 | } |
Kyösti Mälkki | 54d6abd | 2013-06-19 23:05:00 +0300 | [diff] [blame] | 96 | |
Kyösti Mälkki | b25a9da | 2013-06-26 08:19:14 +0300 | [diff] [blame] | 97 | #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älkki | 54d6abd | 2013-06-19 23:05:00 +0300 | [diff] [blame] | 115 | #endif /* CONFIG_MMCONF_SUPPORT */ |
| 116 | #endif /* _PCI_MMIO_CFG_H */ |