~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to xen/include/asm-x86/msr.h

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __ASM_MSR_H
 
2
#define __ASM_MSR_H
 
3
 
 
4
#include "msr-index.h"
 
5
 
 
6
#ifndef __ASSEMBLY__
 
7
 
 
8
#include <xen/smp.h>
 
9
#include <xen/percpu.h>
 
10
 
 
11
#define rdmsr(msr,val1,val2) \
 
12
     __asm__ __volatile__("rdmsr" \
 
13
                          : "=a" (val1), "=d" (val2) \
 
14
                          : "c" (msr))
 
15
 
 
16
#define rdmsrl(msr,val) do { unsigned long a__,b__; \
 
17
       __asm__ __volatile__("rdmsr" \
 
18
                            : "=a" (a__), "=d" (b__) \
 
19
                            : "c" (msr)); \
 
20
       val = a__ | ((u64)b__<<32); \
 
21
} while(0);
 
22
 
 
23
#define wrmsr(msr,val1,val2) \
 
24
     __asm__ __volatile__("wrmsr" \
 
25
                          : /* no outputs */ \
 
26
                          : "c" (msr), "a" (val1), "d" (val2))
 
27
 
 
28
static inline void wrmsrl(unsigned int msr, __u64 val)
 
29
{
 
30
        __u32 lo, hi;
 
31
        lo = (__u32)val;
 
32
        hi = (__u32)(val >> 32);
 
33
        wrmsr(msr, lo, hi);
 
34
}
 
35
 
 
36
/* rdmsr with exception handling */
 
37
#define rdmsr_safe(msr,val1,val2) ({\
 
38
    int _rc; \
 
39
    __asm__ __volatile__( \
 
40
        "1: rdmsr\n2:\n" \
 
41
        ".section .fixup,\"ax\"\n" \
 
42
        "3: movl %5,%2\n; jmp 2b\n" \
 
43
        ".previous\n" \
 
44
        ".section __ex_table,\"a\"\n" \
 
45
        "   "__FIXUP_ALIGN"\n" \
 
46
        "   "__FIXUP_WORD" 1b,3b\n" \
 
47
        ".previous\n" \
 
48
        : "=a" (val1), "=d" (val2), "=&r" (_rc) \
 
49
        : "c" (msr), "2" (0), "i" (-EFAULT)); \
 
50
    _rc; })
 
51
 
 
52
/* wrmsr with exception handling */
 
53
#define wrmsr_safe(msr,val1,val2) ({\
 
54
    int _rc; \
 
55
    __asm__ __volatile__( \
 
56
        "1: wrmsr\n2:\n" \
 
57
        ".section .fixup,\"ax\"\n" \
 
58
        "3: movl %5,%0\n; jmp 2b\n" \
 
59
        ".previous\n" \
 
60
        ".section __ex_table,\"a\"\n" \
 
61
        "   "__FIXUP_ALIGN"\n" \
 
62
        "   "__FIXUP_WORD" 1b,3b\n" \
 
63
        ".previous\n" \
 
64
        : "=&r" (_rc) \
 
65
        : "c" (msr), "a" (val1), "d" (val2), "0" (0), "i" (-EFAULT)); \
 
66
    _rc; })
 
67
 
 
68
#define rdtsc(low,high) \
 
69
     __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
 
70
 
 
71
#define rdtscl(low) \
 
72
     __asm__ __volatile__("rdtsc" : "=a" (low) : : "edx")
 
73
 
 
74
#if defined(__i386__)
 
75
#define rdtscll(val) \
 
76
     __asm__ __volatile__("rdtsc" : "=A" (val))
 
77
#elif defined(__x86_64__)
 
78
#define rdtscll(val) do { \
 
79
     unsigned int a,d; \
 
80
     asm volatile("rdtsc" : "=a" (a), "=d" (d)); \
 
81
     (val) = ((unsigned long)a) | (((unsigned long)d)<<32); \
 
82
} while(0)
 
83
#endif
 
84
 
 
85
#define write_tsc(val) wrmsrl(MSR_IA32_TSC, val)
 
86
 
 
87
#define write_rdtscp_aux(val) wrmsr(MSR_TSC_AUX, (val), 0)
 
88
 
 
89
#define rdpmc(counter,low,high) \
 
90
     __asm__ __volatile__("rdpmc" \
 
91
                          : "=a" (low), "=d" (high) \
 
92
                          : "c" (counter))
 
93
 
 
94
 
 
95
DECLARE_PER_CPU(u64, efer);
 
96
 
 
97
static inline u64 read_efer(void)
 
98
{
 
99
    return this_cpu(efer);
 
100
}
 
101
 
 
102
static inline void write_efer(u64 val)
 
103
{
 
104
    this_cpu(efer) = val;
 
105
    wrmsrl(MSR_EFER, val);
 
106
}
 
107
 
 
108
DECLARE_PER_CPU(u32, ler_msr);
 
109
 
 
110
static inline void ler_enable(void)
 
111
{
 
112
    u64 debugctl;
 
113
    
 
114
    if ( !this_cpu(ler_msr) )
 
115
        return;
 
116
 
 
117
    rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);
 
118
    wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctl | 1);
 
119
}
 
120
 
 
121
#endif /* !__ASSEMBLY__ */
 
122
 
 
123
#endif /* __ASM_MSR_H */