[coreboot-gerrit] New patch to review for coreboot: 8c32998 ARM and x86: Implement portable _read8 and _write8 functions

Kevin Paul Herbert (kph@meraki.net) gerrit at coreboot.org
Thu Dec 11 23:14:14 CET 2014


Kevin Paul Herbert (kph at meraki.net) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/7784

-gerrit

commit 8c32998b537e1b2d3f0a75a12d0cee06e1a3d304
Author: Kevin Paul Herbert <kph at meraki.net>
Date:   Wed Dec 10 17:32:19 2014 -0800

    ARM and x86: Implement portable _read8 and _write8 functions
    
    The primitives for doing accesses to memory mapped devices are defined
    differently on x86 and on ARM. The ARM definitions match Linux.
    Introduce _read8() and _write8() on both x86 and ARM to make it possible
    to write drivers which are portable.
    
    Change-Id: Ic26dd8a72d82828b69be3c04944710681b7bd330
    Signed-off-by: Kevin Paul Herbert <kph at meraki.net>
---
 src/arch/arm/include/arch/io.h |  9 +++++++++
 src/arch/x86/include/arch/io.h | 17 +++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/src/arch/arm/include/arch/io.h b/src/arch/arm/include/arch/io.h
index e537297..611c39c 100644
--- a/src/arch/arm/include/arch/io.h
+++ b/src/arch/arm/include/arch/io.h
@@ -37,6 +37,15 @@
 #define writel(v,a)	write32(v,a)
 
 /*
+ * Unfortunately the memory mapped I/O operators are defined differently
+ * on ARM and x86. Define _read8 and _write8 to work the same on ARM and x86.
+ * There should be a better way.
+ */
+
+#define _read8(a)	read8(a)
+#define _write8(v,a)	write8(v,a)
+
+/*
  * Clear and set bits in one shot. These macros can be used to clear and
  * set multiple bits in a register using a single call. These macros can
  * also be used to set a multiple-bit bit pattern using a mask, by
diff --git a/src/arch/x86/include/arch/io.h b/src/arch/x86/include/arch/io.h
index d5cdf35..ca54771 100644
--- a/src/arch/x86/include/arch/io.h
+++ b/src/arch/x86/include/arch/io.h
@@ -172,6 +172,23 @@ static inline __attribute__((always_inline)) void write32(unsigned long addr, ui
 	*((volatile uint32_t *)(addr)) = value;
 }
 
+/*
+ * Unfortunately ARM and x86 define the readN() and writeN() functions
+ * differently from each other. ARM does it like Linux. Make _read8 and
+ * _write8 functions which are portable. Better to clean this up later,
+ * and not add 16 and 32 bit variants now.
+ */
+
+static inline __attribute__((always_inline)) uint8_t _read8(const void *addr)
+{
+	return *((volatile uint8_t *)(addr));
+}
+
+static inline __attribute__((always_inline)) void _write8(uint8_t value, const void *addr)
+{
+	*((volatile uint8_t *)(addr)) = value;
+}
+
 /* Conflicts with definition in lib.h */
 #if defined(__ROMCC__) || defined(__SMM__)
 static inline int log2(int value)



More information about the coreboot-gerrit mailing list