8 #include <linux/types.h>
11 #define X86_IOC_RDMSR_REGS _IOWR('c', 0xA0, __u32[8])
12 #define X86_IOC_WRMSR_REGS _IOWR('c', 0xA1, __u32[8])
17 #include <asm/errno.h>
37 struct msr_regs_info {
42 static inline unsigned long long native_read_tscp(
unsigned int *
aux)
45 asm volatile(
".byte 0x0f,0x01,0xf9"
46 :
"=a" (
low),
"=d" (high),
"=c" (*aux));
47 return low | ((
u64)high << 32);
57 #define DECLARE_ARGS(val, low, high) unsigned low, high
58 #define EAX_EDX_VAL(val, low, high) ((low) | ((u64)(high) << 32))
59 #define EAX_EDX_ARGS(val, low, high) "a" (low), "d" (high)
60 #define EAX_EDX_RET(val, low, high) "=a" (low), "=d" (high)
62 #define DECLARE_ARGS(val, low, high) unsigned long long val
63 #define EAX_EDX_VAL(val, low, high) (val)
64 #define EAX_EDX_ARGS(val, low, high) "A" (val)
65 #define EAX_EDX_RET(val, low, high) "=A" (val)
68 static inline unsigned long long native_read_msr(
unsigned int msr)
70 DECLARE_ARGS(
val, low, high);
72 asm volatile(
"rdmsr" : EAX_EDX_RET(
val, low, high) :
"c" (msr));
73 return EAX_EDX_VAL(
val, low, high);
76 static inline unsigned long long native_read_msr_safe(
unsigned int msr,
79 DECLARE_ARGS(
val, low, high);
81 asm volatile(
"2: rdmsr ; xor %[err],%[err]\n"
83 ".section .fixup,\"ax\"\n\t"
84 "3: mov %[fault],%[err] ; jmp 1b\n\t"
87 : [err]
"=r" (*err), EAX_EDX_RET(
val, low, high)
89 return EAX_EDX_VAL(
val, low, high);
92 static inline void native_write_msr(
unsigned int msr,
93 unsigned low,
unsigned high)
95 asm volatile(
"wrmsr" : :
"c" (msr),
"a"(low),
"d" (
high) :
"memory");
99 notrace static inline int native_write_msr_safe(
unsigned int msr,
100 unsigned low,
unsigned high)
103 asm volatile(
"2: wrmsr ; xor %[err],%[err]\n"
105 ".section .fixup,\"ax\"\n\t"
106 "3: mov %[fault],%[err] ; jmp 1b\n\t"
110 :
"c" (msr),
"0" (low),
"d" (high),
118 extern int rdmsr_safe_regs(
u32 regs[8]);
119 extern int wrmsr_safe_regs(
u32 regs[8]);
123 DECLARE_ARGS(
val, low, high);
125 asm volatile(
"rdtsc" : EAX_EDX_RET(
val, low, high));
127 return EAX_EDX_VAL(
val, low, high);
130 static inline unsigned long long native_read_pmc(
int counter)
132 DECLARE_ARGS(
val, low, high);
134 asm volatile(
"rdpmc" : EAX_EDX_RET(
val, low, high) :
"c" (counter));
135 return EAX_EDX_VAL(
val, low, high);
138 #ifdef CONFIG_PARAVIRT
139 #include <asm/paravirt.h>
141 #include <linux/errno.h>
148 #define rdmsr(msr, val1, val2) \
150 u64 __val = native_read_msr((msr)); \
151 (void)((val1) = (u32)__val); \
152 (void)((val2) = (u32)(__val >> 32)); \
155 static inline void wrmsr(
unsigned msr,
unsigned low,
unsigned high)
157 native_write_msr(msr, low, high);
160 #define rdmsrl(msr, val) \
161 ((val) = native_read_msr((msr)))
163 #define wrmsrl(msr, val) \
164 native_write_msr((msr), (u32)((u64)(val)), (u32)((u64)(val) >> 32))
167 static inline int wrmsr_safe(
unsigned msr,
unsigned low,
unsigned high)
169 return native_write_msr_safe(msr, low, high);
173 #define rdmsr_safe(msr, p1, p2) \
176 u64 __val = native_read_msr_safe((msr), &__err); \
177 (*p1) = (u32)__val; \
178 (*p2) = (u32)(__val >> 32); \
182 static inline int rdmsrl_safe(
unsigned msr,
unsigned long long *
p)
186 *p = native_read_msr_safe(msr, &err);
190 #define rdtscl(low) \
191 ((low) = (u32)__native_read_tsc())
193 #define rdtscll(val) \
194 ((val) = __native_read_tsc())
196 #define rdpmc(counter, low, high) \
198 u64 _l = native_read_pmc((counter)); \
200 (high) = (u32)(_l >> 32); \
203 #define rdpmcl(counter, val) ((val) = native_read_pmc(counter))
205 #define rdtscp(low, high, aux) \
207 unsigned long long _val = native_read_tscp(&(aux)); \
209 (high) = (u32)(_val >> 32); \
212 #define rdtscpll(val, aux) (val) = native_read_tscp(&(aux))
216 #define wrmsrl_safe(msr, val) wrmsr_safe((msr), (u32)(val), \
219 #define write_tsc(val1, val2) wrmsr(MSR_IA32_TSC, (val1), (val2))
221 #define write_rdtscp_aux(val) wrmsr(MSR_TSC_AUX, (val), 0)
238 rdmsr(msr_no, *l, *h);
259 return rdmsr_safe(msr_no, l, h);
263 return wrmsr_safe(msr_no, l, h);
267 return rdmsr_safe_regs(regs);
271 return wrmsr_safe_regs(regs);