[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [PATCH v2 13/47] arm64: add the basic helpers for arm64



This patch adds the basic helpers in headers for arm64:
    0.) add isb/dmb/dsb
    1.) mb/rmb/wmb
    2.) local_irq_disable/local_irq_enable
    3.) local_irq_save/local_irq_restore/local_save_flags
    4.) simplify the __ffs
    5.) add BUG().

This patch refers to Chen Baozi's patch:
     "Initial codes for arm64"
And this patch also refers to FreeBSD code:
     sys/arm64/include/atomic.h

Signed-off-by: Huang Shijie <shijie.huang@xxxxxxx>
---
 include/arm/arm64/os.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/arm/os.h       | 27 +++-----------------------
 2 files changed, 55 insertions(+), 24 deletions(-)
 create mode 100644 include/arm/arm64/os.h

diff --git a/include/arm/arm64/os.h b/include/arm/arm64/os.h
new file mode 100644
index 0000000..ae8340b
--- /dev/null
+++ b/include/arm/arm64/os.h
@@ -0,0 +1,52 @@
+#ifndef _ARM64_OS_H_
+#define _ARM64_OS_H_
+
+#define BUG()           __asm__ __volatile("wfi" ::: "memory")
+
+static inline void local_irq_disable(void)
+{
+    __asm__ __volatile__("msr daifset, #2":::"memory");
+}
+
+static inline void local_irq_enable(void)
+{
+    __asm__ __volatile__("msr daifclr, #2":::"memory");
+}
+
+#define local_irq_save(x) { \
+    __asm__ __volatile__("mrs %0, daif; msr daifset, #2":"=r"(x)::"memory"); \
+}
+
+#define local_irq_restore(x) { \
+    __asm__ __volatile__("msr daif, %0"::"r"(x):"memory"); \
+}
+
+#define local_save_flags(x) { \
+    __asm__ __volatile__("mrs %0, daif":"=r"(x)::"memory"); \
+}
+
+#define isb()           __asm__ __volatile("isb" ::: "memory")
+
+/*
+ * Options for DMB and DSB:
+ *     oshld   Outer Shareable, load
+ *     oshst   Outer Shareable, store
+ *     osh     Outer Shareable, all
+ *     nshld   Non-shareable, load
+ *     nshst   Non-shareable, store
+ *     nsh     Non-shareable, all
+ *     ishld   Inner Shareable, load
+ *     ishst   Inner Shareable, store
+ *     ish     Inner Shareable, all
+ *     ld      Full system, load
+ *     st      Full system, store
+ *     sy      Full system, all
+ */
+#define dmb(opt)        __asm__ __volatile("dmb " #opt ::: "memory")
+#define dsb(opt)        __asm__ __volatile("dsb " #opt ::: "memory")
+
+#define mb()            dsb(sy) /* Full system memory barrier all */
+#define wmb()           dsb(st) /* Full system memory barrier store */
+#define rmb()           dsb(ld) /* Full system memory barrier load */
+
+#endif
diff --git a/include/arm/os.h b/include/arm/os.h
index 89b072d..ac641ae 100644
--- a/include/arm/os.h
+++ b/include/arm/os.h
@@ -22,6 +22,8 @@ extern shared_info_t *HYPERVISOR_shared_info;
 
 #if defined (__arm__)
 #include <arm32/os.h>
+#elif defined(__aarch64__)
+#include <arm64/os.h>
 #endif
 
 static inline int irqs_disabled(void) {
@@ -32,7 +34,6 @@ static inline int irqs_disabled(void) {
 
 /************************** arm *******************************/
 #ifdef __INSIDE_MINIOS__
-#if defined (__arm__)
 #define xchg(ptr,v) __atomic_exchange_n(ptr, v, __ATOMIC_SEQ_CST)
 
 /**
@@ -104,31 +105,9 @@ static __inline__ void clear_bit(int nr, volatile unsigned 
long *addr)
  */
 static __inline__ unsigned long __ffs(unsigned long word)
 {
-    int clz;
-
-    /* xxxxx10000 = word
-     * xxxxx01111 = word - 1
-     * 0000011111 = word ^ (word - 1)
-     *      4     = 31 - clz(word ^ (word - 1))
-     */
-
-    __asm__ (
-        "sub r0, %[word], #1\n"
-        "eor r0, r0, %[word]\n"
-        "clz %[clz], r0\n":
-        /* Outputs: */
-        [clz] "=r"(clz):
-        /* Inputs: */
-        [word] "r"(word):
-        /* Clobbers: */
-        "r0");
-
-    return 31 - clz;
+    return __builtin_ctzl(word);
 }
 
-#else /* ifdef __arm__ */
-#error "Unsupported architecture"
-#endif
 #endif /* ifdef __INSIDE_MINIOS */
 
 /********************* common arm32 and arm64  ****************************/
-- 
2.7.4


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.