Debian Codegraph @

include/linux-i386/sysdep.h

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 * Copyright (c) 2006-2012. QLogic Corporation. All rights reserved.
3 * Copyright (c) 2003-2006, PathScale, Inc. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34 #ifndef _IPATH_i386_SYSDEP_H
35 #define _IPATH_i386_SYSDEP_H
36
37 static __inline__ uint64_t get_cycles(void)
38 {
39 uint64_t v;
40 uint32_t a,d;
41
42 asm volatile("rdtsc" : "=a" (a), "=d" (d));
43 v = ((uint64_t)a) | (((uint64_t)d)<<32);
44
45 return v;
46 }
47
48 #ifndef LOCK_PREFIX
49 #define LOCK_PREFIX "lock "
50 #endif
51
52 static __inline__ void ips_mb()
53 {
54 #ifdef __MIC__
55 asm volatile("lock; addl $0,0(%%rsp)" ::: "memory");
56 #else
57 asm volatile("mfence" : : : "memory");
58 #endif
59 }
60
61 /* gcc-3.4 has a bug with this function body at -O0 */
62 static
63 #if defined(__GNUC__) && !defined(__PATHCC__) && __GNUC__==3 && __GNUC_MINOR__==4
64 #else
65 __inline__
66 #endif
67 void ips_rmb()
68 {
69 #ifdef __MIC__
70 asm volatile("lock; addl $0,0(%%rsp)" ::: "memory");
71 #else
72 asm volatile("" : : : "memory");
73 #endif
74 }
75
76 static __inline__ void ips_wmb()
77 {
78 #ifdef __MIC__
79 asm volatile("lock; addl $0,0(%%rsp)" ::: "memory");
80 #else
81 asm volatile("sfence" : : : "memory");
82 #endif
83 }
84
85 static __inline__ void ips_sync_writes()
86 {
87 #ifdef __MIC__
88 asm volatile("lock; addl $0,0(%%rsp)" ::: "memory");
89 #else
90 asm volatile("sfence" : : : "memory");
91 #endif
92 }
93
94 static __inline__ void ips_sync_reads()
95 {
96 #ifdef __MIC__
97 asm volatile("lock; addl $0,0(%%rsp)" ::: "memory");
98 #else
99 asm volatile("lfence" : : : "memory");
100 #endif
101 }
102
103 static __inline__ uint32_t ips_cmpxchg(volatile uint32_t *ptr,
104 uint32_t old, uint32_t new)
105 {
106 uint32_t prev;
107 struct xchg_dummy { uint32_t a[100]; };
108
109 asm volatile(LOCK_PREFIX "cmpxchgl %1,%2"
110 : "=a"(prev)
111 : "q"(new), "m"(*(struct xchg_dummy *)ptr), "0"(old)
112 : "memory");
113
114 return prev;
115 }
116
117 typedef struct { volatile int32_t counter; } ips_atomic_t;
118
119 #define ips_atomic_set(v,i) (((v)->counter) = (i))
120 #define ips_atomic_cmpxchg(p,oval,nval) \
121 ips_cmpxchg((volatile uint32_t *) &((p)->counter),oval,nval)
122
123 #if 0
124 static __inline__ int32_t
125 ips_cmpxchg(volatile int32_t *p, int32_t old_value, int32_t new_value)
126 {
127 asm volatile ("lock cmpxchg %2, %0" :
128 "+m" (*p), "+a" (old_value) :
129 "r" (new_value) :
130 "memory");
131 return old_value;
132 }
133 #endif
134
135 #endif /* _IPATH_i386_SYSDEP_H */