summaryrefslogtreecommitdiff
path: root/src/include/cpu/x86
diff options
context:
space:
mode:
authorArthur Heymans <arthur@aheymans.xyz>2022-10-19 20:06:42 +0200
committerArthur Heymans <arthur@aheymans.xyz>2022-11-12 14:23:35 +0000
commit407e00dca06e36d2d9b11f998a278109ff330783 (patch)
tree17c3f52517b48bb37344872736f66baf510e1b24 /src/include/cpu/x86
parent0c9fa6f2ce6d556ec39444c0307c3c9e20053663 (diff)
include/cpu/msr.h: transform into an union
This makes it easier to get the content of an msr into a full 64bit variable. Change-Id: I1b026cd3807fd68d805051a74b3d31fcde1c5626 Signed-off-by: Arthur Heymans <arthur@aheymans.xyz> Reviewed-on: https://review.coreboot.org/c/coreboot/+/68572 Reviewed-by: Raul Rangel <rrangel@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Diffstat (limited to 'src/include/cpu/x86')
-rw-r--r--src/include/cpu/x86/msr.h13
-rw-r--r--src/include/cpu/x86/msr_access.h10
2 files changed, 11 insertions, 12 deletions
diff --git a/src/include/cpu/x86/msr.h b/src/include/cpu/x86/msr.h
index f4e39859cf..33eb457f1a 100644
--- a/src/include/cpu/x86/msr.h
+++ b/src/include/cpu/x86/msr.h
@@ -285,7 +285,7 @@ static inline enum mca_err_code_types mca_err_type(msr_t reg)
static inline uint64_t msr_read(unsigned int reg)
{
msr_t msr = rdmsr(reg);
- return (((uint64_t)msr.hi << 32) | msr.lo);
+ return msr.raw;
}
/**
@@ -296,10 +296,7 @@ static inline uint64_t msr_read(unsigned int reg)
*/
static inline void msr_write(unsigned int reg, uint64_t value)
{
- msr_t msr = {
- .lo = (unsigned int)value,
- .hi = (unsigned int)(value >> 32)
- };
+ msr_t msr = { .raw = value };
wrmsr(reg, msr);
}
@@ -315,10 +312,8 @@ static inline void msr_unset_and_set(unsigned int reg, uint64_t unset, uint64_t
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);
+ msr.raw &= ~unset;
+ msr.raw |= set;
wrmsr(reg, msr);
}
diff --git a/src/include/cpu/x86/msr_access.h b/src/include/cpu/x86/msr_access.h
index a7f72fd077..33029cc653 100644
--- a/src/include/cpu/x86/msr_access.h
+++ b/src/include/cpu/x86/msr_access.h
@@ -6,10 +6,14 @@
#ifndef __ASSEMBLER__
#include <types.h>
-typedef struct msr_struct {
- unsigned int lo;
- unsigned int hi;
+typedef union msr_union {
+ struct {
+ unsigned int lo;
+ unsigned int hi;
+ };
+ uint64_t raw;
} msr_t;
+_Static_assert(sizeof(msr_t) == sizeof(uint64_t), "Incorrect size for msr_t");
#if CONFIG(SOC_SETS_MSRS)
msr_t soc_msr_read(unsigned int index);