From 2d686707df37b8752f31684db16b689637ba141d Mon Sep 17 00:00:00 2001
From: Xue Liu <liuxue@loongson.cn>
Date: Thu, 1 Dec 2022 18:37:21 +0800
Subject: [PATCH 1/3] barrier: LOONGARCH memory barriers

Implement memory barrier for LOONGARCH platforms.

Change-Id: I44f5e63e6eb3f8bf98e965a22fb86f94e727061d
Signed-off-by: Xue Liu <liuxue@loongson.cn>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16082
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
---
 include/spdk/barrier.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/include/spdk/barrier.h b/include/spdk/barrier.h
index acae360..1ee7240 100644
--- a/include/spdk/barrier.h
+++ b/include/spdk/barrier.h
@@ -97,6 +97,15 @@ extern "C" {
 #define _spdk_smp_mb()	__asm volatile("lock addl $0, -128(%%esp); " ::: "memory");
 #endif
 
+#elif defined(__loongarch__)
+
+#define _spdk_rmb()	__asm volatile("dbar 0" ::: "memory")
+#define _spdk_wmb()	__asm volatile("dbar 0" ::: "memory")
+#define _spdk_mb()	__asm volatile("dbar 0" ::: "memory")
+#define _spdk_smp_rmb()	__asm volatile("dbar 0" ::: "memory")
+#define _spdk_smp_wmb()	__asm volatile("dbar 0" ::: "memory")
+#define _spdk_smp_mb()	__asm volatile("dbar 0" ::: "memory")
+
 #else
 
 #define _spdk_rmb()
-- 
2.20.1

