summaryrefslogtreecommitdiff
path: root/src/include/cpu/x86/msr.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/cpu/x86/msr.h')
-rw-r--r--src/include/cpu/x86/msr.h49
1 files changed, 36 insertions, 13 deletions
diff --git a/src/include/cpu/x86/msr.h b/src/include/cpu/x86/msr.h
index 3deb133240..058419fd1e 100644
--- a/src/include/cpu/x86/msr.h
+++ b/src/include/cpu/x86/msr.h
@@ -299,23 +299,46 @@ static inline enum mca_err_code_types mca_err_type(msr_t reg)
return MCA_ERRTYPE_UNKNOWN;
}
-/* Helper for setting single MSR bits */
-static inline void msr_set_bit(unsigned int reg, unsigned int bit)
+/**
+ * Helper for (un)setting MSR bitmasks
+ *
+ * @param[in] reg The MSR.
+ * @param[in] unset Bitmask with ones to the bits to unset from the MSR.
+ * @param[in] set Bitmask with ones to the bits to set from the MSR.
+ */
+static inline void msr_unset_and_set(unsigned int reg, uint64_t unset, uint64_t set)
{
- msr_t msr = rdmsr(reg);
-
- if (bit < 32) {
- if (msr.lo & (1 << bit))
- return;
- msr.lo |= 1 << bit;
- } else {
- if (msr.hi & (1 << (bit - 32)))
- return;
- msr.hi |= 1 << (bit - 32);
- }
+ msr_t msr;
+ msr = rdmsr(reg);
+ msr.lo &= (unsigned int)~unset;
+ msr.hi &= (unsigned int)~(unset >> 32);
+ msr.lo |= (unsigned int)set;
+ msr.hi |= (unsigned int)(set >> 32);
wrmsr(reg, msr);
}
+/**
+ * Helper for setting MSR bitmasks
+ *
+ * @param[in] reg The MSR.
+ * @param[in] set Bitmask with ones to the bits to set from the MSR.
+ */
+static inline void msr_set(unsigned int reg, uint64_t set)
+{
+ msr_unset_and_set(reg, 0, set);
+}
+
+/**
+ * Helper for unsetting MSR bitmasks
+ *
+ * @param[in] reg The MSR.
+ * @param[in] unset Bitmask with ones to the bits to unset from the MSR.
+ */
+static inline void msr_unset(unsigned int reg, uint64_t unset)
+{
+ msr_unset_and_set(reg, unset, 0);
+}
+
#endif /* __ASSEMBLER__ */
#endif /* CPU_X86_MSR_H */