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 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 23 | |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 24 | static __always_inline |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 25 | uint8_t pci_mmio_read_config8(pci_devfn_t dev, uint16_t reg) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 26 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 27 | void *addr; |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 28 | addr = (void *)(uintptr_t)(CONFIG_MMCONF_BASE_ADDRESS | dev | reg); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 29 | return read8(addr); |
| 30 | } |
| 31 | |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 32 | static __always_inline |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 33 | uint16_t pci_mmio_read_config16(pci_devfn_t dev, uint16_t reg) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 34 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 35 | void *addr; |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 36 | addr = (void *)(uintptr_t)(CONFIG_MMCONF_BASE_ADDRESS | dev | (reg & ~1)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 37 | return read16(addr); |
| 38 | } |
| 39 | |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 40 | static __always_inline |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 41 | uint32_t pci_mmio_read_config32(pci_devfn_t dev, uint16_t reg) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 42 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 43 | void *addr; |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 44 | addr = (void *)(uintptr_t)(CONFIG_MMCONF_BASE_ADDRESS | dev | (reg & ~3)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 45 | return read32(addr); |
| 46 | } |
| 47 | |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 48 | static __always_inline |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 49 | void pci_mmio_write_config8(pci_devfn_t dev, uint16_t reg, uint8_t value) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 50 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 51 | void *addr; |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 52 | addr = (void *)(uintptr_t)(CONFIG_MMCONF_BASE_ADDRESS | dev | reg); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 53 | write8(addr, value); |
| 54 | } |
| 55 | |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 56 | static __always_inline |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 57 | void pci_mmio_write_config16(pci_devfn_t dev, uint16_t reg, uint16_t value) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 58 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 59 | void *addr; |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 60 | addr = (void *)(uintptr_t)(CONFIG_MMCONF_BASE_ADDRESS | dev | (reg & ~1)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 61 | write16(addr, value); |
| 62 | } |
| 63 | |
Aaron Durbin | 75a62e7 | 2018-09-13 02:10:45 -0600 | [diff] [blame] | 64 | static __always_inline |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 65 | void pci_mmio_write_config32(pci_devfn_t dev, uint16_t reg, uint32_t value) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 66 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 67 | void *addr; |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 68 | addr = (void *)(uintptr_t)(CONFIG_MMCONF_BASE_ADDRESS | dev | (reg & ~3)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 69 | write32(addr, value); |
| 70 | } |
| 71 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 72 | #if CONFIG(MMCONF_SUPPORT) |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 73 | |
Kyösti Mälkki | 92b5296 | 2019-03-01 08:08:28 +0200 | [diff] [blame] | 74 | /* Avoid name collisions as different stages have different signature |
| 75 | * for these functions. The _s_ stands for simple, fundamental IO or |
| 76 | * MMIO variant. |
| 77 | */ |
| 78 | |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 79 | static __always_inline |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 80 | uint8_t pci_s_read_config8(pci_devfn_t dev, uint16_t reg) |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 81 | { |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 82 | return pci_mmio_read_config8(dev, reg); |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | static __always_inline |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 86 | uint16_t pci_s_read_config16(pci_devfn_t dev, uint16_t reg) |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 87 | { |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 88 | return pci_mmio_read_config16(dev, reg); |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static __always_inline |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 92 | uint32_t pci_s_read_config32(pci_devfn_t dev, uint16_t reg) |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 93 | { |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 94 | return pci_mmio_read_config32(dev, reg); |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | static __always_inline |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 98 | void pci_s_write_config8(pci_devfn_t dev, uint16_t reg, uint8_t value) |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 99 | { |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 100 | pci_mmio_write_config8(dev, reg, value); |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | static __always_inline |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 104 | void pci_s_write_config16(pci_devfn_t dev, uint16_t reg, uint16_t value) |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 105 | { |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 106 | pci_mmio_write_config16(dev, reg, value); |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | static __always_inline |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 110 | void pci_s_write_config32(pci_devfn_t dev, uint16_t reg, uint32_t value) |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 111 | { |
Kyösti Mälkki | b603fdc | 2019-03-11 20:33:01 +0200 | [diff] [blame] | 112 | pci_mmio_write_config32(dev, reg, value); |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 113 | } |
Kyösti Mälkki | 2d8aff3 | 2019-01-23 16:44:55 +0200 | [diff] [blame] | 114 | |
| 115 | #endif |
| 116 | |
Kyösti Mälkki | 54d6abd | 2013-06-19 23:05:00 +0300 | [diff] [blame] | 117 | #endif /* _PCI_MMIO_CFG_H */ |