Subversion Repositories Kolibri OS

Rev

Rev 5270 | Rev 6934 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5270 Rev 6082
Line 1... Line 1...
1
#ifndef _ASM_X86_MSR_H
1
#ifndef _ASM_X86_MSR_H
2
#define _ASM_X86_MSR_H
2
#define _ASM_X86_MSR_H
Line 3... Line 3...
3
 
3
 
Line 4... Line 4...
4
#include 
4
#include "msr-index.h"
Line 5... Line 5...
5
 
5
 
6
#ifndef __ASSEMBLY__
6
#ifndef __ASSEMBLY__
7
 
7
 
-
 
8
#include 
Line 8... Line 9...
8
#include 
9
#include 
9
#include 
10
#include 
10
#include 
11
#include 
11
 
12
 
Line 44... Line 45...
44
 * constraint has different meanings. For i386, "A" means exactly
45
 * constraint has different meanings. For i386, "A" means exactly
45
 * edx:eax, while for x86_64 it doesn't mean rdx:rax or edx:eax. Instead,
46
 * edx:eax, while for x86_64 it doesn't mean rdx:rax or edx:eax. Instead,
46
 * it means rax *or* rdx.
47
 * it means rax *or* rdx.
47
 */
48
 */
48
#ifdef CONFIG_X86_64
49
#ifdef CONFIG_X86_64
-
 
50
/* Using 64-bit values saves one instruction clearing the high half of low */
49
#define DECLARE_ARGS(val, low, high)	unsigned low, high
51
#define DECLARE_ARGS(val, low, high)	unsigned long low, high
50
#define EAX_EDX_VAL(val, low, high)	((low) | ((u64)(high) << 32))
52
#define EAX_EDX_VAL(val, low, high)	((low) | (high) << 32)
51
#define EAX_EDX_ARGS(val, low, high)	"a" (low), "d" (high)
-
 
52
#define EAX_EDX_RET(val, low, high)	"=a" (low), "=d" (high)
53
#define EAX_EDX_RET(val, low, high)	"=a" (low), "=d" (high)
53
#else
54
#else
54
#define DECLARE_ARGS(val, low, high)	unsigned long long val
55
#define DECLARE_ARGS(val, low, high)	unsigned long long val
55
#define EAX_EDX_VAL(val, low, high)	(val)
56
#define EAX_EDX_VAL(val, low, high)	(val)
56
#define EAX_EDX_ARGS(val, low, high)	"A" (val)
-
 
57
#define EAX_EDX_RET(val, low, high)	"=A" (val)
57
#define EAX_EDX_RET(val, low, high)	"=A" (val)
58
#endif
58
#endif
Line 59... Line 59...
59
 
59
 
60
static inline unsigned long long native_read_msr(unsigned int msr)
60
static inline unsigned long long native_read_msr(unsigned int msr)
Line 103... Line 103...
103
		       [fault] "i" (-EIO)
103
		       [fault] "i" (-EIO)
104
		     : "memory");
104
		     : "memory");
105
	return err;
105
	return err;
106
}
106
}
Line 107... Line -...
107
 
-
 
108
extern unsigned long long native_read_tsc(void);
-
 
109
 
107
 
110
extern int rdmsr_safe_regs(u32 regs[8]);
108
extern int rdmsr_safe_regs(u32 regs[8]);
Line -... Line 109...
-
 
109
extern int wrmsr_safe_regs(u32 regs[8]);
-
 
110
 
-
 
111
/**
-
 
112
 * rdtsc() - returns the current TSC without ordering constraints
-
 
113
 *
-
 
114
 * rdtsc() returns the result of RDTSC as a 64-bit integer.  The
-
 
115
 * only ordering constraint it supplies is the ordering implied by
-
 
116
 * "asm volatile": it will put the RDTSC in the place you expect.  The
-
 
117
 * CPU can and will speculatively execute that RDTSC, though, so the
111
extern int wrmsr_safe_regs(u32 regs[8]);
118
 * results can be non-monotonic if compared on different CPUs.
112
 
119
 */
113
static __always_inline unsigned long long __native_read_tsc(void)
120
static __always_inline unsigned long long rdtsc(void)
Line 114... Line 121...
114
{
121
{
Line 150... Line 157...
150
}
157
}
Line 151... Line 158...
151
 
158
 
152
#define rdmsrl(msr, val)			\
159
#define rdmsrl(msr, val)			\
Line 153... Line 160...
153
	((val) = native_read_msr((msr)))
160
	((val) = native_read_msr((msr)))
-
 
161
 
154
 
162
static inline void wrmsrl(unsigned msr, u64 val)
-
 
163
{
Line 155... Line 164...
155
#define wrmsrl(msr, val)						\
164
	native_write_msr(msr, (u32)val, (u32)(val >> 32));
156
	native_write_msr((msr), (u32)((u64)(val)), (u32)((u64)(val) >> 32))
165
}
157
 
166
 
158
/* wrmsr with exception handling */
167
/* wrmsr with exception handling */
Line 177... Line 186...
177
 
186
 
178
	*p = native_read_msr_safe(msr, &err);
187
	*p = native_read_msr_safe(msr, &err);
179
	return err;
188
	return err;
Line 180... Line -...
180
}
-
 
181
 
-
 
182
#define rdtscl(low)						\
-
 
183
	((low) = (u32)__native_read_tsc())
-
 
184
 
-
 
185
#define rdtscll(val)						\
-
 
186
	((val) = __native_read_tsc())
189
}
187
 
190
 
188
#define rdpmc(counter, low, high)			\
191
#define rdpmc(counter, low, high)			\
189
do {							\
192
do {							\
190
	u64 _l = native_read_pmc((counter));		\
193
	u64 _l = native_read_pmc((counter));		\
191
	(low)  = (u32)_l;				\
194
	(low)  = (u32)_l;				\
Line 192... Line 195...
192
	(high) = (u32)(_l >> 32);			\
195
	(high) = (u32)(_l >> 32);			\
Line 193... Line -...
193
} while (0)
-
 
194
 
-
 
195
#define rdpmcl(counter, val) ((val) = native_read_pmc(counter))
-
 
196
 
-
 
197
#define rdtscp(low, high, aux)					\
-
 
198
do {                                                            \
-
 
199
	unsigned long long _val = native_read_tscp(&(aux));     \
-
 
200
	(low) = (u32)_val;                                      \
-
 
201
	(high) = (u32)(_val >> 32);                             \
-
 
202
} while (0)
196
} while (0)
Line -... Line 197...
-
 
197
 
-
 
198
#define rdpmcl(counter, val) ((val) = native_read_pmc(counter))
-
 
199
 
203
 
200
#endif	/* !CONFIG_PARAVIRT */
-
 
201
 
204
#define rdtscpll(val, aux) (val) = native_read_tscp(&(aux))
202
/*
-
 
203
 * 64-bit version of wrmsr_safe():
Line 205... Line 204...
205
 
204
 */
Line 206... Line 205...
206
#endif	/* !CONFIG_PARAVIRT */
205
static inline int wrmsrl_safe(u32 msr, u64 val)