coreboot/src/include/cpu/x86
Michael Niewöhner 1d9f8b0c42 cpu/x86/msr: introduce helpers msr_read, msr_write
The existing helpers for reading/writing MSRs (rdmsr, wrmsr) require use
of the struct `msr_t`, which splits the MSR value into two 32 bit parts.
In many cases, where simple 32 bit or 64 bit values are written, this
bloats the code by unnecessarly having to use that struct.

Thus, introduce the helpers `msr_read` and `msr_write`, which take or
return `uint64_t` values, so the code condenses to a single line or two,
without having to deal with `msr_t`.

Example 1:

~~~
msr_t msr = {
  .lo = read32((void *)(uintptr_t)0xfed30880),
  .hi = 0,
};

msr.lo |= 1;
wrmsr(0x123, msr);
~~~

becomes

~~~
uint32_t foo = read32((void *)(uintptr_t)0xfed30880);
msr_write(0x123, foo | 1)
~~~

Example 2:

~~~
msr_t msr = rdmsr(0xff);
uint64_t msr_val = (msr.hi << 32) | msr.lo;
~~~

becomes

~~~
uint64_t msr_val = msr_read(0xff);
~~~

Change-Id: I27333a4bdfe3c8cebfe49a16a4f1a066f558c4ce
Signed-off-by: Michael Niewöhner <foss@mniewoehner.de>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/52548
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2021-04-30 06:41:08 +00:00
..
bist.h src/include: Add missing includes 2020-07-26 21:37:35 +00:00
cache.h arch/x86/exit_car.S: Make sure _cbmem_top_ptr hits dram 2020-08-17 06:22:41 +00:00
cr.h treewide: Remove "this file is part of" lines 2020-05-11 17:11:40 +00:00
gdt.h treewide: Remove "this file is part of" lines 2020-05-11 17:11:40 +00:00
lapic.h *x86: Support x2apic mode 2021-04-15 10:56:13 +00:00
lapic_def.h *x86: Support x2apic mode 2021-04-15 10:56:13 +00:00
legacy_save_state.h treewide: Remove "this file is part of" lines 2020-05-11 17:11:40 +00:00
mp.h src/cpu/x86: Add helper mp_run_on_all_aps 2021-03-11 15:53:58 +00:00
msr.h cpu/x86/msr: introduce helpers msr_read, msr_write 2021-04-30 06:41:08 +00:00
mtrr.h cpu/x86/mtrr.h: Rename CORE2 alternative SMRR registers 2020-11-10 06:18:05 +00:00
name.h treewide: Remove "this file is part of" lines 2020-05-11 17:11:40 +00:00
pae.h treewide: Remove "this file is part of" lines 2020-05-11 17:11:40 +00:00
post_code.h src/include: Drop unneeded empty lines 2020-09-14 07:09:41 +00:00
save_state.h cpu/x86/smm: Add a common save state handling 2020-11-09 10:20:07 +00:00
smi_deprecated.h cpu/x86/smm/smmhandler.c: Get revision using C code 2020-09-29 05:59:37 +00:00
smm.h cpu/x86/smm_loaderv2: Use the permanent stack top during relocation 2021-04-19 06:36:05 +00:00
tsc.h include/cpu/x86/tsc: Fix rdtsc on x86_64 2020-09-28 09:36:00 +00:00