summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAngel Pons <th3fanbus@gmail.com>2021-03-27 19:35:27 +0100
committerPatrick Georgi <pgeorgi@google.com>2021-05-02 21:57:50 +0000
commit098cfd5287018ae71437d46ad5fe0272295e7377 (patch)
tree861bade9b1c74af6e2179738fef7895e714f60cb /src
parent6237175ed5ef29a0e9b82cc7268ca424c5bb44ea (diff)
nb/intel/common: Turn `*bar_{read,write}*` macros into functions
These accessors were defined as macros in order to allow verifying the patches that replaced the accessors using BUILD_TIMELESS=1. Now that all replacement is done, turn the new accessors into static functions to let the compiler perform overflow checks on the arguments. Change-Id: Iaa2ba208fba11c4a00f2b8a05eb1129a32c6c092 Signed-off-by: Angel Pons <th3fanbus@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/52816 Reviewed-by: Nico Huber <nico.h@gmx.de> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src')
-rw-r--r--src/northbridge/intel/common/fixed_bars.h126
1 files changed, 97 insertions, 29 deletions
diff --git a/src/northbridge/intel/common/fixed_bars.h b/src/northbridge/intel/common/fixed_bars.h
index 8a0d9dc1b6..ed7b403fb0 100644
--- a/src/northbridge/intel/common/fixed_bars.h
+++ b/src/northbridge/intel/common/fixed_bars.h
@@ -3,10 +3,7 @@
#ifndef NORTHBRIDGE_INTEL_COMMON_FIXED_BARS_H
#define NORTHBRIDGE_INTEL_COMMON_FIXED_BARS_H
-_Static_assert(CONFIG_FIXED_MCHBAR_MMIO_BASE != 0, "MCHBAR base address is zero");
-_Static_assert(CONFIG_FIXED_DMIBAR_MMIO_BASE != 0, "DMIBAR base address is zero");
-_Static_assert(CONFIG_FIXED_EPBAR_MMIO_BASE != 0, "EPBAR base address is zero");
-
+#include <device/mmio.h>
#include <stdint.h>
/* Deprecated in favor of the read/write accessors below */
@@ -32,19 +29,106 @@ _Static_assert(CONFIG_FIXED_EPBAR_MMIO_BASE != 0, "EPBAR base address is zero"
#define EPBAR16(x) (*((volatile u16 *)((uintptr_t)CONFIG_FIXED_EPBAR_MMIO_BASE + (x))))
#define EPBAR32(x) (*((volatile u32 *)((uintptr_t)CONFIG_FIXED_EPBAR_MMIO_BASE + (x))))
-/* The *bar_{read,write}X macros will be replaced with functions in follow-ups */
+_Static_assert(CONFIG_FIXED_MCHBAR_MMIO_BASE != 0, "MCHBAR base address is zero");
+
+static __always_inline uint8_t mchbar_read8(const uintptr_t offset)
+{
+ return read8p(CONFIG_FIXED_MCHBAR_MMIO_BASE + offset);
+}
+
+static __always_inline uint16_t mchbar_read16(const uintptr_t offset)
+{
+ return read16p(CONFIG_FIXED_MCHBAR_MMIO_BASE + offset);
+}
+
+static __always_inline uint32_t mchbar_read32(const uintptr_t offset)
+{
+ return read32p(CONFIG_FIXED_MCHBAR_MMIO_BASE + offset);
+}
+
+static __always_inline void mchbar_write8(const uintptr_t offset, const uint8_t value)
+{
+ write8p(CONFIG_FIXED_MCHBAR_MMIO_BASE + offset, value);
+}
+
+static __always_inline void mchbar_write16(const uintptr_t offset, const uint16_t value)
+{
+ write16p(CONFIG_FIXED_MCHBAR_MMIO_BASE + offset, value);
+}
+
+static __always_inline void mchbar_write32(const uintptr_t offset, const uint32_t value)
+{
+ write32p(CONFIG_FIXED_MCHBAR_MMIO_BASE + offset, value);
+}
+
+_Static_assert(CONFIG_FIXED_DMIBAR_MMIO_BASE != 0, "DMIBAR base address is zero");
+
+static __always_inline uint8_t dmibar_read8(const uintptr_t offset)
+{
+ return read8p(CONFIG_FIXED_DMIBAR_MMIO_BASE + offset);
+}
+
+static __always_inline uint16_t dmibar_read16(const uintptr_t offset)
+{
+ return read16p(CONFIG_FIXED_DMIBAR_MMIO_BASE + offset);
+}
+
+static __always_inline uint32_t dmibar_read32(const uintptr_t offset)
+{
+ return read32p(CONFIG_FIXED_DMIBAR_MMIO_BASE + offset);
+}
+
+static __always_inline void dmibar_write8(const uintptr_t offset, const uint8_t value)
+{
+ write8p(CONFIG_FIXED_DMIBAR_MMIO_BASE + offset, value);
+}
+
+static __always_inline void dmibar_write16(const uintptr_t offset, const uint16_t value)
+{
+ write16p(CONFIG_FIXED_DMIBAR_MMIO_BASE + offset, value);
+}
+
+static __always_inline void dmibar_write32(const uintptr_t offset, const uint32_t value)
+{
+ write32p(CONFIG_FIXED_DMIBAR_MMIO_BASE + offset, value);
+}
+
+_Static_assert(CONFIG_FIXED_EPBAR_MMIO_BASE != 0, "EPBAR base address is zero");
+
+static __always_inline uint8_t epbar_read8(const uintptr_t offset)
+{
+ return read8p(CONFIG_FIXED_EPBAR_MMIO_BASE + offset);
+}
+
+static __always_inline uint16_t epbar_read16(const uintptr_t offset)
+{
+ return read16p(CONFIG_FIXED_EPBAR_MMIO_BASE + offset);
+}
+
+static __always_inline uint32_t epbar_read32(const uintptr_t offset)
+{
+ return read32p(CONFIG_FIXED_EPBAR_MMIO_BASE + offset);
+}
+
+static __always_inline void epbar_write8(const uintptr_t offset, const uint8_t value)
+{
+ write8p(CONFIG_FIXED_EPBAR_MMIO_BASE + offset, value);
+}
+
+static __always_inline void epbar_write16(const uintptr_t offset, const uint16_t value)
+{
+ write16p(CONFIG_FIXED_EPBAR_MMIO_BASE + offset, value);
+}
+
+static __always_inline void epbar_write32(const uintptr_t offset, const uint32_t value)
+{
+ write32p(CONFIG_FIXED_EPBAR_MMIO_BASE + offset, value);
+}
+
#define _bar_clrsetbits_impl(base, addr, clear, set, bits) \
base##bar_write##bits(addr, \
(base##bar_read##bits(addr) & ~(uint##bits##_t)(clear)) | (set))
-#define mchbar_read8(addr) MCHBAR8(addr)
-#define mchbar_read16(addr) MCHBAR16(addr)
-#define mchbar_read32(addr) MCHBAR32(addr)
-
-#define mchbar_write8(addr, value) (MCHBAR8(addr) = (value))
-#define mchbar_write16(addr, value) (MCHBAR16(addr) = (value))
-#define mchbar_write32(addr, value) (MCHBAR32(addr) = (value))
-
#define mchbar_clrsetbits8(addr, clear, set) _bar_clrsetbits_impl(mch, addr, clear, set, 8)
#define mchbar_clrsetbits16(addr, clear, set) _bar_clrsetbits_impl(mch, addr, clear, set, 16)
#define mchbar_clrsetbits32(addr, clear, set) _bar_clrsetbits_impl(mch, addr, clear, set, 32)
@@ -57,14 +141,6 @@ _Static_assert(CONFIG_FIXED_EPBAR_MMIO_BASE != 0, "EPBAR base address is zero"
#define mchbar_clrbits16(addr, clear) mchbar_clrsetbits16(addr, clear, 0)
#define mchbar_clrbits32(addr, clear) mchbar_clrsetbits32(addr, clear, 0)
-#define dmibar_read8(addr) DMIBAR8(addr)
-#define dmibar_read16(addr) DMIBAR16(addr)
-#define dmibar_read32(addr) DMIBAR32(addr)
-
-#define dmibar_write8(addr, value) (DMIBAR8(addr) = (value))
-#define dmibar_write16(addr, value) (DMIBAR16(addr) = (value))
-#define dmibar_write32(addr, value) (DMIBAR32(addr) = (value))
-
#define dmibar_clrsetbits8(addr, clear, set) _bar_clrsetbits_impl(dmi, addr, clear, set, 8)
#define dmibar_clrsetbits16(addr, clear, set) _bar_clrsetbits_impl(dmi, addr, clear, set, 16)
#define dmibar_clrsetbits32(addr, clear, set) _bar_clrsetbits_impl(dmi, addr, clear, set, 32)
@@ -77,14 +153,6 @@ _Static_assert(CONFIG_FIXED_EPBAR_MMIO_BASE != 0, "EPBAR base address is zero"
#define dmibar_clrbits16(addr, clear) dmibar_clrsetbits16(addr, clear, 0)
#define dmibar_clrbits32(addr, clear) dmibar_clrsetbits32(addr, clear, 0)
-#define epbar_read8(addr) EPBAR8(addr)
-#define epbar_read16(addr) EPBAR16(addr)
-#define epbar_read32(addr) EPBAR32(addr)
-
-#define epbar_write8(addr, value) (EPBAR8(addr) = (value))
-#define epbar_write16(addr, value) (EPBAR16(addr) = (value))
-#define epbar_write32(addr, value) (EPBAR32(addr) = (value))
-
#define epbar_clrsetbits8(addr, clear, set) _bar_clrsetbits_impl(ep, addr, clear, set, 8)
#define epbar_clrsetbits16(addr, clear, set) _bar_clrsetbits_impl(ep, addr, clear, set, 16)
#define epbar_clrsetbits32(addr, clear, set) _bar_clrsetbits_impl(ep, addr, clear, set, 32)