1 #include <linux/module.h>
2 #include <linux/preempt.h>
14 static void __rdmsr_on_cpu(void *info
)
16 struct msr_info
*rv
= info
;
18 int this_cpu
= raw_smp_processor_id();
21 reg
= &rv
->msrs
[this_cpu
- rv
->off
];
25 rdmsr(rv
->msr_no
, reg
->l
, reg
->h
);
28 static void __wrmsr_on_cpu(void *info
)
30 struct msr_info
*rv
= info
;
32 int this_cpu
= raw_smp_processor_id();
35 reg
= &rv
->msrs
[this_cpu
- rv
->off
];
39 wrmsr(rv
->msr_no
, reg
->l
, reg
->h
);
42 int rdmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
)
47 memset(&rv
, 0, sizeof(rv
));
50 err
= smp_call_function_single(cpu
, __rdmsr_on_cpu
, &rv
, 1);
56 EXPORT_SYMBOL(rdmsr_on_cpu
);
58 int wrmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
)
63 memset(&rv
, 0, sizeof(rv
));
68 err
= smp_call_function_single(cpu
, __wrmsr_on_cpu
, &rv
, 1);
72 EXPORT_SYMBOL(wrmsr_on_cpu
);
74 /* rdmsr on a bunch of CPUs
78 * @msrs: array of MSR values
81 void rdmsr_on_cpus(const cpumask_t
*mask
, u32 msr_no
, struct msr
*msrs
)
86 memset(&rv
, 0, sizeof(rv
));
88 rv
.off
= cpumask_first(mask
);
94 * FIXME: handle the CPU we're executing on separately for now until
95 * smp_call_function_many has been fixed to not skip it.
97 this_cpu
= raw_smp_processor_id();
98 smp_call_function_single(this_cpu
, __rdmsr_on_cpu
, &rv
, 1);
100 smp_call_function_many(mask
, __rdmsr_on_cpu
, &rv
, 1);
103 EXPORT_SYMBOL(rdmsr_on_cpus
);
106 * wrmsr on a bunch of CPUs
110 * @msrs: array of MSR values
113 void wrmsr_on_cpus(const cpumask_t
*mask
, u32 msr_no
, struct msr
*msrs
)
118 memset(&rv
, 0, sizeof(rv
));
120 rv
.off
= cpumask_first(mask
);
126 * FIXME: handle the CPU we're executing on separately for now until
127 * smp_call_function_many has been fixed to not skip it.
129 this_cpu
= raw_smp_processor_id();
130 smp_call_function_single(this_cpu
, __wrmsr_on_cpu
, &rv
, 1);
132 smp_call_function_many(mask
, __wrmsr_on_cpu
, &rv
, 1);
135 EXPORT_SYMBOL(wrmsr_on_cpus
);
137 /* These "safe" variants are slower and should be used when the target MSR
138 may not actually exist. */
139 static void __rdmsr_safe_on_cpu(void *info
)
141 struct msr_info
*rv
= info
;
143 rv
->err
= rdmsr_safe(rv
->msr_no
, &rv
->reg
.l
, &rv
->reg
.h
);
146 static void __wrmsr_safe_on_cpu(void *info
)
148 struct msr_info
*rv
= info
;
150 rv
->err
= wrmsr_safe(rv
->msr_no
, rv
->reg
.l
, rv
->reg
.h
);
153 int rdmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
)
158 memset(&rv
, 0, sizeof(rv
));
161 err
= smp_call_function_single(cpu
, __rdmsr_safe_on_cpu
, &rv
, 1);
165 return err
? err
: rv
.err
;
167 EXPORT_SYMBOL(rdmsr_safe_on_cpu
);
169 int wrmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
)
174 memset(&rv
, 0, sizeof(rv
));
179 err
= smp_call_function_single(cpu
, __wrmsr_safe_on_cpu
, &rv
, 1);
181 return err
? err
: rv
.err
;
183 EXPORT_SYMBOL(wrmsr_safe_on_cpu
);