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. |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 14 | */ |
| 15 | |
Kyösti Mälkki | 54d6abd | 2013-06-19 23:05:00 +0300 | [diff] [blame] | 16 | #ifndef _PCI_MMIO_CFG_H |
| 17 | #define _PCI_MMIO_CFG_H |
| 18 | |
Kyösti Mälkki | 8fd78a6 | 2019-01-23 15:59:38 +0200 | [diff] [blame] | 19 | #include <stdint.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame^] | 20 | #include <device/mmio.h> |
Kyösti Mälkki | 8fd78a6 | 2019-01-23 15:59:38 +0200 | [diff] [blame] | 21 | #include <device/pci_type.h> |
Kyösti Mälkki | 54d6abd | 2013-06-19 23:05:00 +0300 | [diff] [blame] | 22 | |
Kyösti Mälkki | 54d6abd | 2013-06-19 23:05:00 +0300 | [diff] [blame] | 23 | #define DEFAULT_PCIEXBAR CONFIG_MMCONF_BASE_ADDRESS |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 24 | |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 25 | static __always_inline |
Kyösti Mälkki | d8d43ba | 2013-10-27 14:59:00 +0200 | [diff] [blame] | 26 | u8 pci_mmio_read_config8(pci_devfn_t dev, unsigned int where) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 27 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 28 | void *addr; |
Stefan Reinauer | b0bb8a1 | 2015-06-17 16:12:17 -0700 | [diff] [blame] | 29 | addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | where); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 30 | return read8(addr); |
| 31 | } |
| 32 | |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 33 | static __always_inline |
Kyösti Mälkki | d8d43ba | 2013-10-27 14:59:00 +0200 | [diff] [blame] | 34 | u16 pci_mmio_read_config16(pci_devfn_t dev, unsigned int where) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 35 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 36 | void *addr; |
Stefan Reinauer | b0bb8a1 | 2015-06-17 16:12:17 -0700 | [diff] [blame] | 37 | addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~1)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 38 | return read16(addr); |
| 39 | } |
| 40 | |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 41 | static __always_inline |
Kyösti Mälkki | d8d43ba | 2013-10-27 14:59:00 +0200 | [diff] [blame] | 42 | u32 pci_mmio_read_config32(pci_devfn_t dev, unsigned int where) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 43 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 44 | void *addr; |
Stefan Reinauer | b0bb8a1 | 2015-06-17 16:12:17 -0700 | [diff] [blame] | 45 | addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~3)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 46 | return read32(addr); |
| 47 | } |
| 48 | |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 49 | static __always_inline |
Kyösti Mälkki | d8d43ba | 2013-10-27 14:59:00 +0200 | [diff] [blame] | 50 | void pci_mmio_write_config8(pci_devfn_t dev, unsigned int where, u8 value) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 51 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 52 | void *addr; |
Stefan Reinauer | b0bb8a1 | 2015-06-17 16:12:17 -0700 | [diff] [blame] | 53 | addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | where); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 54 | write8(addr, value); |
| 55 | } |
| 56 | |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 57 | static __always_inline |
Kyösti Mälkki | d8d43ba | 2013-10-27 14:59:00 +0200 | [diff] [blame] | 58 | void pci_mmio_write_config16(pci_devfn_t dev, unsigned int where, u16 value) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 59 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 60 | void *addr; |
Stefan Reinauer | b0bb8a1 | 2015-06-17 16:12:17 -0700 | [diff] [blame] | 61 | addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~1)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 62 | write16(addr, value); |
| 63 | } |
| 64 | |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 65 | static __always_inline |
Kyösti Mälkki | d8d43ba | 2013-10-27 14:59:00 +0200 | [diff] [blame] | 66 | void pci_mmio_write_config32(pci_devfn_t dev, unsigned int where, u32 value) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 67 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 68 | void *addr; |
Stefan Reinauer | b0bb8a1 | 2015-06-17 16:12:17 -0700 | [diff] [blame] | 69 | addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~3)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 70 | write32(addr, value); |
| 71 | } |
| 72 | |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 73 | #if IS_ENABLED(CONFIG_MMCONF_SUPPORT) |
| 74 | |
Kyösti Mälkki | 92b5296 | 2019-03-01 08:08:28 +0200 | [diff] [blame] | 75 | /* 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älkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 80 | static __always_inline |
Kyösti Mälkki | 92b5296 | 2019-03-01 08:08:28 +0200 | [diff] [blame] | 81 | uint8_t pci_s_read_config8(pci_devfn_t dev, unsigned int where) |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 82 | { |
| 83 | return pci_mmio_read_config8(dev, where); |
| 84 | } |
| 85 | |
| 86 | static __always_inline |
Kyösti Mälkki | 92b5296 | 2019-03-01 08:08:28 +0200 | [diff] [blame] | 87 | uint16_t pci_s_read_config16(pci_devfn_t dev, unsigned int where) |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 88 | { |
| 89 | return pci_mmio_read_config16(dev, where); |
| 90 | } |
| 91 | |
| 92 | static __always_inline |
Kyösti Mälkki | 92b5296 | 2019-03-01 08:08:28 +0200 | [diff] [blame] | 93 | uint32_t pci_s_read_config32(pci_devfn_t dev, unsigned int where) |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 94 | { |
| 95 | return pci_mmio_read_config32(dev, where); |
| 96 | } |
| 97 | |
| 98 | static __always_inline |
Kyösti Mälkki | 92b5296 | 2019-03-01 08:08:28 +0200 | [diff] [blame] | 99 | void pci_s_write_config8(pci_devfn_t dev, unsigned int where, uint8_t value) |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 100 | { |
| 101 | pci_mmio_write_config8(dev, where, value); |
| 102 | } |
| 103 | |
| 104 | static __always_inline |
Kyösti Mälkki | 92b5296 | 2019-03-01 08:08:28 +0200 | [diff] [blame] | 105 | void pci_s_write_config16(pci_devfn_t dev, unsigned int where, uint16_t value) |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 106 | { |
| 107 | pci_mmio_write_config16(dev, where, value); |
| 108 | } |
| 109 | |
| 110 | static __always_inline |
Kyösti Mälkki | 92b5296 | 2019-03-01 08:08:28 +0200 | [diff] [blame] | 111 | void pci_s_write_config32(pci_devfn_t dev, unsigned int where, uint32_t value) |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 112 | { |
| 113 | pci_mmio_write_config32(dev, where, value); |
| 114 | } |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 115 | |
| 116 | #endif |
| 117 | |
Kyösti Mälkki | 54d6abd | 2013-06-19 23:05:00 +0300 | [diff] [blame] | 118 | #endif /* _PCI_MMIO_CFG_H */ |