1 /*
2  * %CopyrightBegin%
3  *
4  * Copyright Ericsson AB 2011-2016. All Rights Reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * %CopyrightEnd%
19  */
20 
21 /*
22  * Description: Memory barriers for sparc-v9
23  * Author: Rickard Green
24  */
25 
26 #ifndef ETHR_SPARC_V9_MEMBAR_H__
27 #define ETHR_SPARC_V9_MEMBAR_H__
28 
29 #if defined(ETHR_SPARC_TSO)
30 /* --- Total Store Order ------------------------------------------------ */
31 
32 #define ETHR_LoadLoad	0
33 #define ETHR_LoadStore	0
34 #define ETHR_StoreLoad	1
35 #define ETHR_StoreStore	0
36 
37 static __inline__ void
ethr_cb__(void)38 ethr_cb__(void)
39 {
40     __asm__ __volatile__ ("" : : : "memory");
41 }
42 
43 static __inline__ void
ethr_StoreLoad__(void)44 ethr_StoreLoad__(void)
45 {
46     __asm__ __volatile__ ("membar #StoreLoad\n\t" : : : "memory");
47 }
48 
49 
50 #define ETHR_MEMBAR(B) \
51   ETHR_CHOOSE_EXPR((B), ethr_StoreLoad__(), ethr_cb__())
52 
53 #elif defined(ETHR_SPARC_PSO)
54 /* --- Partial Store Order ---------------------------------------------- */
55 
56 #define ETHR_LoadLoad	0
57 #define ETHR_LoadStore	0
58 #define ETHR_StoreLoad	(1 << 0)
59 #define ETHR_StoreStore	(1 << 1)
60 
61 static __inline__ void
ethr_cb__(void)62 ethr_cb__(void)
63 {
64     __asm__ __volatile__ ("" : : : "memory");
65 }
66 
67 static __inline__ void
ethr_StoreLoad__(void)68 ethr_StoreLoad__(void)
69 {
70     __asm__ __volatile__ ("membar #StoreLoad\n\t" : : : "memory");
71 }
72 
73 static __inline__ void
ethr_StoreStore__(void)74 ethr_StoreStore__(void)
75 {
76     __asm__ __volatile__ ("membar #StoreStore\n\t" : : : "memory");
77 }
78 
79 static __inline__ void
ethr_StoreLoad_StoreStore__(void)80 ethr_StoreLoad_StoreStore__(void)
81 {
82     __asm__ __volatile__ ("membar #StoreLoad|StoreStore\n\t" : : : "memory");
83 }
84 
85 #define ETHR_MEMBAR(B)					\
86   ETHR_CHOOSE_EXPR(					\
87       (B) == ETHR_StoreLoad,				\
88       ethr_StoreLoad__(),				\
89       ETHR_CHOOSE_EXPR(					\
90 	  (B) == ETHR_StoreStore,			\
91 	  ethr_StoreStore__(),				\
92 	  ETHR_CHOOSE_EXPR(				\
93 	      (B) == (ETHR_StoreLoad|ETHR_StoreStore),	\
94 	      ethr_StoreLoad_StoreStore__(),		\
95 	      ethr_cb__())))
96 
97 #elif defined(ETHR_SPARC_RMO)
98 /* --- Relaxed Memory Order --------------------------------------------- */
99 
100 #  define ETHR_LoadLoad #LoadLoad
101 #  define ETHR_LoadStore #LoadStore
102 #  define ETHR_StoreLoad #StoreLoad
103 #  define ETHR_StoreStore #StoreStore
104 
105 #  define ETHR_MEMBAR_AUX__(B) \
106      __asm__ __volatile__("membar " #B "\n\t" : : : "memory")
107 
108 #  define ETHR_MEMBAR(B) ETHR_MEMBAR_AUX__(B)
109 
110 #else
111 
112 #  error "No memory order defined"
113 
114 #endif
115 
116 #endif
117