1 #ifndef __ASM_X86_MSR_H_
2 #define __ASM_X86_MSR_H_
4 #include <asm/msr-index.h>
7 # include <linux/types.h>
15 #include <asm/errno.h>
17 static inline unsigned long long native_read_msr(unsigned int msr
)
19 unsigned long long val
;
21 asm volatile("rdmsr" : "=A" (val
) : "c" (msr
));
25 static inline unsigned long long native_read_msr_safe(unsigned int msr
,
28 unsigned long long val
;
30 asm volatile("2: rdmsr ; xorl %0,%0\n"
32 ".section .fixup,\"ax\"\n\t"
33 "3: movl %3,%0 ; jmp 1b\n\t"
35 ".section __ex_table,\"a\"\n"
39 : "=r" (*err
), "=A" (val
)
40 : "c" (msr
), "i" (-EFAULT
));
45 static inline void native_write_msr(unsigned int msr
, unsigned long long val
)
47 asm volatile("wrmsr" : : "c" (msr
), "A"(val
));
50 static inline int native_write_msr_safe(unsigned int msr
,
51 unsigned long long val
)
54 asm volatile("2: wrmsr ; xorl %0,%0\n"
56 ".section .fixup,\"ax\"\n\t"
57 "3: movl %4,%0 ; jmp 1b\n\t"
59 ".section __ex_table,\"a\"\n"
64 : "c" (msr
), "0" ((u32
)val
), "d" ((u32
)(val
>>32)),
69 static inline unsigned long long native_read_tsc(void)
71 unsigned long long val
;
72 asm volatile("rdtsc" : "=A" (val
));
76 static inline unsigned long long native_read_pmc(void)
78 unsigned long long val
;
79 asm volatile("rdpmc" : "=A" (val
));
83 #ifdef CONFIG_PARAVIRT
84 #include <asm/paravirt.h>
86 #include <linux/errno.h>
88 * Access to machine-specific registers (available on 586 and better only)
89 * Note: the rd* operations modify the parameters directly (without using
90 * pointer indirection), this allows gcc to optimize better
93 #define rdmsr(msr,val1,val2) \
95 u64 __val = native_read_msr(msr); \
96 (val1) = (u32)__val; \
97 (val2) = (u32)(__val >> 32); \
100 static inline void wrmsr(u32 __msr
, u32 __low
, u32 __high
)
102 native_write_msr(__msr
, ((u64
)__high
<< 32) | __low
);
105 #define rdmsrl(msr,val) \
106 ((val) = native_read_msr(msr))
108 #define wrmsrl(msr,val) native_write_msr(msr, val)
110 /* wrmsr with exception handling */
111 static inline int wrmsr_safe(u32 __msr
, u32 __low
, u32 __high
)
113 return native_write_msr_safe(__msr
, ((u64
)__high
<< 32) | __low
);
116 /* rdmsr with exception handling */
117 #define rdmsr_safe(msr,p1,p2) \
120 u64 __val = native_read_msr_safe(msr, &__err); \
121 (*p1) = (u32)__val; \
122 (*p2) = (u32)(__val >> 32); \
126 #define rdtscl(low) \
127 ((low) = (u32)native_read_tsc())
129 #define rdtscll(val) \
130 ((val) = native_read_tsc())
132 #define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
134 #define rdpmc(counter,low,high) \
136 u64 _l = native_read_pmc(); \
138 (high) = (u32)(_l >> 32); \
140 #endif /* !CONFIG_PARAVIRT */
143 void rdmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
);
144 void wrmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
);
145 int rdmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
);
146 int wrmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
);
147 #else /* CONFIG_SMP */
148 static inline void rdmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
)
150 rdmsr(msr_no
, *l
, *h
);
152 static inline void wrmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
)
156 static inline int rdmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
)
158 return rdmsr_safe(msr_no
, l
, h
);
160 static inline int wrmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
)
162 return wrmsr_safe(msr_no
, l
, h
);
164 #endif /* CONFIG_SMP */
165 #endif /* ! __ASSEMBLY__ */
166 #endif /* __KERNEL__ */
171 #include <linux/errno.h>
173 * Access to machine-specific registers (available on 586 and better only)
174 * Note: the rd* operations modify the parameters directly (without using
175 * pointer indirection), this allows gcc to optimize better
178 #define rdmsr(msr,val1,val2) \
179 __asm__ __volatile__("rdmsr" \
180 : "=a" (val1), "=d" (val2) \
184 #define rdmsrl(msr,val) do { unsigned long a__,b__; \
185 __asm__ __volatile__("rdmsr" \
186 : "=a" (a__), "=d" (b__) \
188 val = a__ | (b__<<32); \
191 #define wrmsr(msr,val1,val2) \
192 __asm__ __volatile__("wrmsr" \
194 : "c" (msr), "a" (val1), "d" (val2))
196 #define wrmsrl(msr,val) wrmsr(msr,(__u32)((__u64)(val)),((__u64)(val))>>32)
198 #define rdtsc(low,high) \
199 __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
201 #define rdtscl(low) \
202 __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
204 #define rdtscp(low,high,aux) \
205 __asm__ __volatile__ (".byte 0x0f,0x01,0xf9" : "=a" (low), "=d" (high), "=c" (aux))
207 #define rdtscll(val) do { \
208 unsigned int __a,__d; \
209 __asm__ __volatile__("rdtsc" : "=a" (__a), "=d" (__d)); \
210 (val) = ((unsigned long)__a) | (((unsigned long)__d)<<32); \
213 #define rdtscpll(val, aux) do { \
214 unsigned long __a, __d; \
215 __asm__ __volatile__ (".byte 0x0f,0x01,0xf9" : "=a" (__a), "=d" (__d), "=c" (aux)); \
216 (val) = (__d << 32) | __a; \
219 #define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
221 #define write_rdtscp_aux(val) wrmsr(0xc0000103, val, 0)
223 #define rdpmc(counter,low,high) \
224 __asm__ __volatile__("rdpmc" \
225 : "=a" (low), "=d" (high) \
229 static inline void cpuid(int op
, unsigned int *eax
, unsigned int *ebx
,
230 unsigned int *ecx
, unsigned int *edx
)
240 /* Some CPUID calls want 'count' to be placed in ecx */
241 static inline void cpuid_count(int op
, int count
, int *eax
, int *ebx
, int *ecx
,
249 : "0" (op
), "c" (count
));
253 * CPUID functions returning a single datum
255 static inline unsigned int cpuid_eax(unsigned int op
)
265 static inline unsigned int cpuid_ebx(unsigned int op
)
267 unsigned int eax
, ebx
;
270 : "=a" (eax
), "=b" (ebx
)
275 static inline unsigned int cpuid_ecx(unsigned int op
)
277 unsigned int eax
, ecx
;
280 : "=a" (eax
), "=c" (ecx
)
285 static inline unsigned int cpuid_edx(unsigned int op
)
287 unsigned int eax
, edx
;
290 : "=a" (eax
), "=d" (edx
)
298 /* wrmsr with exception handling */
299 #define wrmsr_safe(msr,a,b) ({ int ret__; \
300 asm volatile("2: wrmsr ; xorl %0,%0\n" \
302 ".section .fixup,\"ax\"\n\t" \
303 "3: movl %4,%0 ; jmp 1b\n\t" \
305 ".section __ex_table,\"a\"\n" \
310 : "c" (msr), "0" (a), "d" (b), "i" (-EFAULT)); \
313 #define checking_wrmsrl(msr,val) wrmsr_safe(msr,(u32)(val),(u32)((val)>>32))
315 #define rdmsr_safe(msr,a,b) \
317 asm volatile ("1: rdmsr\n" \
319 ".section .fixup,\"ax\"\n" \
323 ".section __ex_table,\"a\"\n" \
326 ".previous":"=&bDS" (ret__), "=a"(*(a)), "=d"(*(b)) \
327 :"c"(msr), "i"(-EIO), "0"(0)); \
331 void rdmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
);
332 void wrmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
);
333 int rdmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
);
334 int wrmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
);
335 #else /* CONFIG_SMP */
336 static inline void rdmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
)
338 rdmsr(msr_no
, *l
, *h
);
340 static inline void wrmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
)
344 static inline int rdmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
)
346 return rdmsr_safe(msr_no
, l
, h
);
348 static inline int wrmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
)
350 return wrmsr_safe(msr_no
, l
, h
);
352 #endif /* CONFIG_SMP */
353 #endif /* __KERNEL__ */
354 #endif /* __ASSEMBLY__ */
356 #endif /* !__i386__ */