[Skiboot] [PATCH v2 3/5] io: Add load_wait() helper

Benjamin Herrenschmidt benh at kernel.crashing.org
Tue Dec 12 16:22:53 AEDT 2017

This uses the standard form twi/isync pair to ensure a load
is consumed by the core before continuing. This can be necessary
under some circumstances for example when having the following

	- Store reg A
	- Load reg A (ensure above store pushed out)
	- delay loop
	- Store reg A

IE, a mandatory delay between 2 stores. In theory the first store
is only guaranteed to rach the device after the load from the same
location has completed. However the processor will start executing
the delay loop without waiting for the return value from the load.

This construct enforces that the delay loop isn't executed until
the load value has been returned.

Signed-off-by: Benjamin Herrenschmidt <benh at kernel.crashing.org>
 include/io.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/include/io.h b/include/io.h
index 45a385ed..c056c37e 100644
--- a/include/io.h
+++ b/include/io.h
@@ -170,6 +170,14 @@ static inline void out_le64(volatile uint64_t *addr, uint64_t val)
 #define in_le8	in_8
 #define out_le8	out_8
+/* Ensure completion of a load (ie, value returned to CPU)
+ * before continuing execution
+ */
+static inline void load_wait(uint64_t data)
+	asm volatile("twi 0,%0,0;isync" : : "r" (data) : "memory");
 #endif /* __ASSEMBLY__ */
 #endif /* __IO_H */

More information about the Skiboot mailing list