conn rcv_lock converted to spinlock, struct cor_sock created, kernel_packet skb_clone...
[cor_2_6_31.git] / arch / x86 / include / asm / msr.h
blob48ad9d29484a03ff9d95f30c0b38de00e11896db
1 #ifndef _ASM_X86_MSR_H
2 #define _ASM_X86_MSR_H
4 #include <asm/msr-index.h>
6 #ifdef __KERNEL__
7 #ifndef __ASSEMBLY__
9 #include <linux/types.h>
10 #include <asm/asm.h>
11 #include <asm/errno.h>
12 #include <asm/cpumask.h>
14 struct msr {
15 union {
16 struct {
17 u32 l;
18 u32 h;
20 u64 q;
24 static inline unsigned long long native_read_tscp(unsigned int *aux)
26 unsigned long low, high;
27 asm volatile(".byte 0x0f,0x01,0xf9"
28 : "=a" (low), "=d" (high), "=c" (*aux));
29 return low | ((u64)high << 32);
33 * both i386 and x86_64 returns 64-bit value in edx:eax, but gcc's "A"
34 * constraint has different meanings. For i386, "A" means exactly
35 * edx:eax, while for x86_64 it doesn't mean rdx:rax or edx:eax. Instead,
36 * it means rax *or* rdx.
38 #ifdef CONFIG_X86_64
39 #define DECLARE_ARGS(val, low, high) unsigned low, high
40 #define EAX_EDX_VAL(val, low, high) ((low) | ((u64)(high) << 32))
41 #define EAX_EDX_ARGS(val, low, high) "a" (low), "d" (high)
42 #define EAX_EDX_RET(val, low, high) "=a" (low), "=d" (high)
43 #else
44 #define DECLARE_ARGS(val, low, high) unsigned long long val
45 #define EAX_EDX_VAL(val, low, high) (val)
46 #define EAX_EDX_ARGS(val, low, high) "A" (val)
47 #define EAX_EDX_RET(val, low, high) "=A" (val)
48 #endif
50 static inline unsigned long long native_read_msr(unsigned int msr)
52 DECLARE_ARGS(val, low, high);
54 asm volatile("rdmsr" : EAX_EDX_RET(val, low, high) : "c" (msr));
55 return EAX_EDX_VAL(val, low, high);
58 static inline unsigned long long native_read_msr_safe(unsigned int msr,
59 int *err)
61 DECLARE_ARGS(val, low, high);
63 asm volatile("2: rdmsr ; xor %[err],%[err]\n"
64 "1:\n\t"
65 ".section .fixup,\"ax\"\n\t"
66 "3: mov %[fault],%[err] ; jmp 1b\n\t"
67 ".previous\n\t"
68 _ASM_EXTABLE(2b, 3b)
69 : [err] "=r" (*err), EAX_EDX_RET(val, low, high)
70 : "c" (msr), [fault] "i" (-EFAULT));
71 return EAX_EDX_VAL(val, low, high);
74 static inline unsigned long long native_read_msr_amd_safe(unsigned int msr,
75 int *err)
77 DECLARE_ARGS(val, low, high);
79 asm volatile("2: rdmsr ; xor %0,%0\n"
80 "1:\n\t"
81 ".section .fixup,\"ax\"\n\t"
82 "3: mov %3,%0 ; jmp 1b\n\t"
83 ".previous\n\t"
84 _ASM_EXTABLE(2b, 3b)
85 : "=r" (*err), EAX_EDX_RET(val, low, high)
86 : "c" (msr), "D" (0x9c5a203a), "i" (-EFAULT));
87 return EAX_EDX_VAL(val, low, high);
90 static inline void native_write_msr(unsigned int msr,
91 unsigned low, unsigned high)
93 asm volatile("wrmsr" : : "c" (msr), "a"(low), "d" (high) : "memory");
96 /* Can be uninlined because referenced by paravirt */
97 notrace static inline int native_write_msr_safe(unsigned int msr,
98 unsigned low, unsigned high)
100 int err;
101 asm volatile("2: wrmsr ; xor %[err],%[err]\n"
102 "1:\n\t"
103 ".section .fixup,\"ax\"\n\t"
104 "3: mov %[fault],%[err] ; jmp 1b\n\t"
105 ".previous\n\t"
106 _ASM_EXTABLE(2b, 3b)
107 : [err] "=a" (err)
108 : "c" (msr), "0" (low), "d" (high),
109 [fault] "i" (-EFAULT)
110 : "memory");
111 return err;
114 extern unsigned long long native_read_tsc(void);
116 static __always_inline unsigned long long __native_read_tsc(void)
118 DECLARE_ARGS(val, low, high);
120 asm volatile("rdtsc" : EAX_EDX_RET(val, low, high));
122 return EAX_EDX_VAL(val, low, high);
125 static inline unsigned long long native_read_pmc(int counter)
127 DECLARE_ARGS(val, low, high);
129 asm volatile("rdpmc" : EAX_EDX_RET(val, low, high) : "c" (counter));
130 return EAX_EDX_VAL(val, low, high);
133 #ifdef CONFIG_PARAVIRT
134 #include <asm/paravirt.h>
135 #else
136 #include <linux/errno.h>
138 * Access to machine-specific registers (available on 586 and better only)
139 * Note: the rd* operations modify the parameters directly (without using
140 * pointer indirection), this allows gcc to optimize better
143 #define rdmsr(msr, val1, val2) \
144 do { \
145 u64 __val = native_read_msr((msr)); \
146 (val1) = (u32)__val; \
147 (val2) = (u32)(__val >> 32); \
148 } while (0)
150 static inline void wrmsr(unsigned msr, unsigned low, unsigned high)
152 native_write_msr(msr, low, high);
155 #define rdmsrl(msr, val) \
156 ((val) = native_read_msr((msr)))
158 #define wrmsrl(msr, val) \
159 native_write_msr((msr), (u32)((u64)(val)), (u32)((u64)(val) >> 32))
161 /* wrmsr with exception handling */
162 static inline int wrmsr_safe(unsigned msr, unsigned low, unsigned high)
164 return native_write_msr_safe(msr, low, high);
167 /* rdmsr with exception handling */
168 #define rdmsr_safe(msr, p1, p2) \
169 ({ \
170 int __err; \
171 u64 __val = native_read_msr_safe((msr), &__err); \
172 (*p1) = (u32)__val; \
173 (*p2) = (u32)(__val >> 32); \
174 __err; \
177 static inline int rdmsrl_safe(unsigned msr, unsigned long long *p)
179 int err;
181 *p = native_read_msr_safe(msr, &err);
182 return err;
184 static inline int rdmsrl_amd_safe(unsigned msr, unsigned long long *p)
186 int err;
188 *p = native_read_msr_amd_safe(msr, &err);
189 return err;
192 #define rdtscl(low) \
193 ((low) = (u32)__native_read_tsc())
195 #define rdtscll(val) \
196 ((val) = __native_read_tsc())
198 #define rdpmc(counter, low, high) \
199 do { \
200 u64 _l = native_read_pmc((counter)); \
201 (low) = (u32)_l; \
202 (high) = (u32)(_l >> 32); \
203 } while (0)
205 #define rdtscp(low, high, aux) \
206 do { \
207 unsigned long long _val = native_read_tscp(&(aux)); \
208 (low) = (u32)_val; \
209 (high) = (u32)(_val >> 32); \
210 } while (0)
212 #define rdtscpll(val, aux) (val) = native_read_tscp(&(aux))
214 #endif /* !CONFIG_PARAVIRT */
217 #define checking_wrmsrl(msr, val) wrmsr_safe((msr), (u32)(val), \
218 (u32)((val) >> 32))
220 #define write_tsc(val1, val2) wrmsr(0x10, (val1), (val2))
222 #define write_rdtscp_aux(val) wrmsr(0xc0000103, (val), 0)
224 #ifdef CONFIG_SMP
225 int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h);
226 int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h);
227 void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs);
228 void wrmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs);
229 int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h);
230 int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h);
231 #else /* CONFIG_SMP */
232 static inline int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h)
234 rdmsr(msr_no, *l, *h);
235 return 0;
237 static inline int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h)
239 wrmsr(msr_no, l, h);
240 return 0;
242 static inline void rdmsr_on_cpus(const cpumask_t *m, u32 msr_no,
243 struct msr *msrs)
245 rdmsr_on_cpu(0, msr_no, &(msrs[0].l), &(msrs[0].h));
247 static inline void wrmsr_on_cpus(const cpumask_t *m, u32 msr_no,
248 struct msr *msrs)
250 wrmsr_on_cpu(0, msr_no, msrs[0].l, msrs[0].h);
252 static inline int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no,
253 u32 *l, u32 *h)
255 return rdmsr_safe(msr_no, l, h);
257 static inline int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h)
259 return wrmsr_safe(msr_no, l, h);
261 #endif /* CONFIG_SMP */
262 #endif /* __ASSEMBLY__ */
263 #endif /* __KERNEL__ */
264 #endif /* _ASM_X86_MSR_H */