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 | |
| 19 | #include <arch/io.h> |
| 20 | |
Kyösti Mälkki | 54d6abd | 2013-06-19 23:05:00 +0300 | [diff] [blame] | 21 | #define DEFAULT_PCIEXBAR CONFIG_MMCONF_BASE_ADDRESS |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 22 | |
| 23 | static inline __attribute__ ((always_inline)) |
Kyösti Mälkki | d8d43ba | 2013-10-27 14:59:00 +0200 | [diff] [blame^] | 24 | u8 pci_mmio_read_config8(pci_devfn_t dev, unsigned int where) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 25 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 26 | void *addr; |
Stefan Reinauer | b0bb8a1 | 2015-06-17 16:12:17 -0700 | [diff] [blame] | 27 | addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | where); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 28 | return read8(addr); |
| 29 | } |
| 30 | |
| 31 | static inline __attribute__ ((always_inline)) |
Kyösti Mälkki | d8d43ba | 2013-10-27 14:59:00 +0200 | [diff] [blame^] | 32 | u16 pci_mmio_read_config16(pci_devfn_t dev, unsigned int where) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 33 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 34 | void *addr; |
Stefan Reinauer | b0bb8a1 | 2015-06-17 16:12:17 -0700 | [diff] [blame] | 35 | addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~1)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 36 | return read16(addr); |
| 37 | } |
| 38 | |
| 39 | static inline __attribute__ ((always_inline)) |
Kyösti Mälkki | d8d43ba | 2013-10-27 14:59:00 +0200 | [diff] [blame^] | 40 | u32 pci_mmio_read_config32(pci_devfn_t dev, unsigned int where) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 41 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 42 | void *addr; |
Stefan Reinauer | b0bb8a1 | 2015-06-17 16:12:17 -0700 | [diff] [blame] | 43 | addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~3)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 44 | return read32(addr); |
| 45 | } |
| 46 | |
| 47 | static inline __attribute__ ((always_inline)) |
Kyösti Mälkki | d8d43ba | 2013-10-27 14:59:00 +0200 | [diff] [blame^] | 48 | 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] | 49 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 50 | void *addr; |
Stefan Reinauer | b0bb8a1 | 2015-06-17 16:12:17 -0700 | [diff] [blame] | 51 | addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | where); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 52 | write8(addr, value); |
| 53 | } |
| 54 | |
| 55 | static inline __attribute__ ((always_inline)) |
Kyösti Mälkki | d8d43ba | 2013-10-27 14:59:00 +0200 | [diff] [blame^] | 56 | 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] | 57 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 58 | void *addr; |
Stefan Reinauer | b0bb8a1 | 2015-06-17 16:12:17 -0700 | [diff] [blame] | 59 | addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~1)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 60 | write16(addr, value); |
| 61 | } |
| 62 | |
| 63 | static inline __attribute__ ((always_inline)) |
Kyösti Mälkki | d8d43ba | 2013-10-27 14:59:00 +0200 | [diff] [blame^] | 64 | 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] | 65 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 66 | void *addr; |
Stefan Reinauer | b0bb8a1 | 2015-06-17 16:12:17 -0700 | [diff] [blame] | 67 | addr = (void *)(uintptr_t)(DEFAULT_PCIEXBAR | dev | (where & ~3)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 68 | write32(addr, value); |
| 69 | } |
| 70 | |
Kyösti Mälkki | 54d6abd | 2013-06-19 23:05:00 +0300 | [diff] [blame] | 71 | #endif /* _PCI_MMIO_CFG_H */ |