1 #ifndef __ASM_X86_MSR_H_
2 #define __ASM_X86_MSR_H_
4 #include <asm/msr-index.h>
11 #include <asm/errno.h>
13 static inline unsigned long long native_read_msr(unsigned int msr
)
15 unsigned long long val
;
17 asm volatile("rdmsr" : "=A" (val
) : "c" (msr
));
21 static inline unsigned long long native_read_msr_safe(unsigned int msr
,
24 unsigned long long val
;
26 asm volatile("2: rdmsr ; xorl %0,%0\n"
28 ".section .fixup,\"ax\"\n\t"
29 "3: movl %3,%0 ; jmp 1b\n\t"
31 ".section __ex_table,\"a\"\n"
35 : "=r" (*err
), "=A" (val
)
36 : "c" (msr
), "i" (-EFAULT
));
41 static inline void native_write_msr(unsigned int msr
, unsigned long long val
)
43 asm volatile("wrmsr" : : "c" (msr
), "A"(val
));
46 static inline int native_write_msr_safe(unsigned int msr
,
47 unsigned long long val
)
50 asm volatile("2: wrmsr ; xorl %0,%0\n"
52 ".section .fixup,\"ax\"\n\t"
53 "3: movl %4,%0 ; jmp 1b\n\t"
55 ".section __ex_table,\"a\"\n"
60 : "c" (msr
), "0" ((u32
)val
), "d" ((u32
)(val
>>32)),
65 static inline unsigned long long native_read_tsc(void)
67 unsigned long long val
;
68 asm volatile("rdtsc" : "=A" (val
));
72 static inline unsigned long long native_read_pmc(void)
74 unsigned long long val
;
75 asm volatile("rdpmc" : "=A" (val
));
79 #ifdef CONFIG_PARAVIRT
80 #include <asm/paravirt.h>
82 #include <linux/errno.h>
84 * Access to machine-specific registers (available on 586 and better only)
85 * Note: the rd* operations modify the parameters directly (without using
86 * pointer indirection), this allows gcc to optimize better
89 #define rdmsr(msr,val1,val2) \
91 u64 __val = native_read_msr(msr); \
92 (val1) = (u32)__val; \
93 (val2) = (u32)(__val >> 32); \
96 static inline void wrmsr(u32 __msr
, u32 __low
, u32 __high
)
98 native_write_msr(__msr
, ((u64
)__high
<< 32) | __low
);
101 #define rdmsrl(msr,val) \
102 ((val) = native_read_msr(msr))
104 #define wrmsrl(msr,val) native_write_msr(msr, val)
106 /* wrmsr with exception handling */
107 static inline int wrmsr_safe(u32 __msr
, u32 __low
, u32 __high
)
109 return native_write_msr_safe(__msr
, ((u64
)__high
<< 32) | __low
);
112 /* rdmsr with exception handling */
113 #define rdmsr_safe(msr,p1,p2) \
116 u64 __val = native_read_msr_safe(msr, &__err); \
117 (*p1) = (u32)__val; \
118 (*p2) = (u32)(__val >> 32); \
122 #define rdtscl(low) \
123 ((low) = (u32)native_read_tsc())
125 #define rdtscll(val) \
126 ((val) = native_read_tsc())
128 #define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
130 #define rdpmc(counter,low,high) \
132 u64 _l = native_read_pmc(); \
134 (high) = (u32)(_l >> 32); \
136 #endif /* !CONFIG_PARAVIRT */
139 void rdmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
);
140 void wrmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
);
141 int rdmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
);
142 int wrmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
);
143 #else /* CONFIG_SMP */
144 static inline void rdmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
)
146 rdmsr(msr_no
, *l
, *h
);
148 static inline void wrmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
)
152 static inline int rdmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
)
154 return rdmsr_safe(msr_no
, l
, h
);
156 static inline int wrmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
)
158 return wrmsr_safe(msr_no
, l
, h
);
160 #endif /* CONFIG_SMP */
161 #endif /* ! __ASSEMBLY__ */
162 #endif /* __KERNEL__ */
167 #include <linux/errno.h>
169 * Access to machine-specific registers (available on 586 and better only)
170 * Note: the rd* operations modify the parameters directly (without using
171 * pointer indirection), this allows gcc to optimize better
174 #define rdmsr(msr,val1,val2) \
175 __asm__ __volatile__("rdmsr" \
176 : "=a" (val1), "=d" (val2) \
180 #define rdmsrl(msr,val) do { unsigned long a__,b__; \
181 __asm__ __volatile__("rdmsr" \
182 : "=a" (a__), "=d" (b__) \
184 val = a__ | (b__<<32); \
187 #define wrmsr(msr,val1,val2) \
188 __asm__ __volatile__("wrmsr" \
190 : "c" (msr), "a" (val1), "d" (val2))
192 #define wrmsrl(msr,val) wrmsr(msr,(__u32)((__u64)(val)),((__u64)(val))>>32)
194 /* wrmsr with exception handling */
195 #define wrmsr_safe(msr,a,b) ({ int ret__; \
196 asm volatile("2: wrmsr ; xorl %0,%0\n" \
198 ".section .fixup,\"ax\"\n\t" \
199 "3: movl %4,%0 ; jmp 1b\n\t" \
201 ".section __ex_table,\"a\"\n" \
206 : "c" (msr), "0" (a), "d" (b), "i" (-EFAULT)); \
209 #define checking_wrmsrl(msr,val) wrmsr_safe(msr,(u32)(val),(u32)((val)>>32))
211 #define rdmsr_safe(msr,a,b) \
213 asm volatile ("1: rdmsr\n" \
215 ".section .fixup,\"ax\"\n" \
219 ".section __ex_table,\"a\"\n" \
222 ".previous":"=&bDS" (ret__), "=a"(*(a)), "=d"(*(b)) \
223 :"c"(msr), "i"(-EIO), "0"(0)); \
226 #define rdtsc(low,high) \
227 __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
229 #define rdtscl(low) \
230 __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
232 #define rdtscp(low,high,aux) \
233 asm volatile (".byte 0x0f,0x01,0xf9" : "=a" (low), "=d" (high), "=c" (aux))
235 #define rdtscll(val) do { \
236 unsigned int __a,__d; \
237 asm volatile("rdtsc" : "=a" (__a), "=d" (__d)); \
238 (val) = ((unsigned long)__a) | (((unsigned long)__d)<<32); \
241 #define rdtscpll(val, aux) do { \
242 unsigned long __a, __d; \
243 asm volatile (".byte 0x0f,0x01,0xf9" : "=a" (__a), "=d" (__d), "=c" (aux)); \
244 (val) = (__d << 32) | __a; \
247 #define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
249 #define write_rdtscp_aux(val) wrmsr(0xc0000103, val, 0)
251 #define rdpmc(counter,low,high) \
252 __asm__ __volatile__("rdpmc" \
253 : "=a" (low), "=d" (high) \
256 static inline void cpuid(int op
, unsigned int *eax
, unsigned int *ebx
,
257 unsigned int *ecx
, unsigned int *edx
)
267 /* Some CPUID calls want 'count' to be placed in ecx */
268 static inline void cpuid_count(int op
, int count
, int *eax
, int *ebx
, int *ecx
,
276 : "0" (op
), "c" (count
));
280 * CPUID functions returning a single datum
282 static inline unsigned int cpuid_eax(unsigned int op
)
292 static inline unsigned int cpuid_ebx(unsigned int op
)
294 unsigned int eax
, ebx
;
297 : "=a" (eax
), "=b" (ebx
)
302 static inline unsigned int cpuid_ecx(unsigned int op
)
304 unsigned int eax
, ecx
;
307 : "=a" (eax
), "=c" (ecx
)
312 static inline unsigned int cpuid_edx(unsigned int op
)
314 unsigned int eax
, edx
;
317 : "=a" (eax
), "=d" (edx
)
324 void rdmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
);
325 void wrmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
);
326 int rdmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
);
327 int wrmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
);
328 #else /* CONFIG_SMP */
329 static inline void rdmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
)
331 rdmsr(msr_no
, *l
, *h
);
333 static inline void wrmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
)
337 static inline int rdmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
)
339 return rdmsr_safe(msr_no
, l
, h
);
341 static inline int wrmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
)
343 return wrmsr_safe(msr_no
, l
, h
);
345 #endif /* CONFIG_SMP */
346 #endif /* __ASSEMBLY__ */
348 #endif /* !__i386__ */