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 PowerPC
23  * Author: Rickard Green
24  */
25 
26 #ifndef ETHR_PPC_MEMBAR_H__
27 #define ETHR_PPC_MEMBAR_H__
28 
29 #define ETHR_LoadLoad	(1 << 0)
30 #define ETHR_LoadStore	(1 << 1)
31 #define ETHR_StoreLoad	(1 << 2)
32 #define ETHR_StoreStore	(1 << 3)
33 
34 static __inline__ void
ethr_lwsync__(void)35 ethr_lwsync__(void)
36 {
37 #ifdef ETHR_PPC_HAVE_NO_LWSYNC
38     __asm__ __volatile__ ("sync\n\t" : : : "memory");
39 #else
40 #ifndef ETHR_PPC_HAVE_LWSYNC
41     if (ETHR_PPC_RUNTIME_CONF_HAVE_NO_LWSYNC__)
42 	__asm__ __volatile__ ("sync\n\t" : : : "memory");
43     else
44 #endif
45 	__asm__ __volatile__ ("lwsync\n\t" : : : "memory");
46 #endif
47 }
48 
49 static __inline__ void
ethr_sync__(void)50 ethr_sync__(void)
51 {
52     __asm__ __volatile__ ("sync\n\t" : : : "memory");
53 }
54 
55 /*
56  * According to the "memory barrier intstructions" section of
57  * http://www.ibm.com/developerworks/systems/articles/powerpc.html
58  * we want to use sync when a StoreLoad is needed and lwsync for
59  * everything else.
60  */
61 #define ETHR_MEMBAR(B) \
62   ETHR_CHOOSE_EXPR((B) & ETHR_StoreLoad, ethr_sync__(), ethr_lwsync__())
63 
64 #endif
65