cpu/x86/lapic: Add lapic_update32() helper
Change-Id: I57c5d85d3098f9d59f26f427fe16829e4e769194
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/55187
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Wonkyu Kim <wonkyu.kim@intel.com>
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/src/include/cpu/x86/lapic.h b/src/include/cpu/x86/lapic.h
index e19458f..cf048a8 100644
--- a/src/include/cpu/x86/lapic.h
+++ b/src/include/cpu/x86/lapic.h
@@ -92,6 +92,25 @@
xapic_write(reg, v);
}
+static __always_inline void lapic_update32(unsigned int reg, uint32_t mask, uint32_t or)
+{
+ if (is_x2apic_mode()) {
+ uint32_t index;
+ msr_t msr;
+ index = X2APIC_MSR_BASE_ADDRESS + (uint32_t)(reg >> 4);
+ msr = rdmsr(index);
+ msr.lo &= mask;
+ msr.lo |= or;
+ wrmsr(index, msr);
+ } else {
+ uint32_t value;
+ value = xapic_read(reg);
+ value &= mask;
+ value |= or;
+ xapic_write_atomic(reg, value);
+ }
+}
+
static __always_inline void lapic_wait_icr_idle(void)
{
do { } while (lapic_read(LAPIC_ICR) & LAPIC_ICR_BUSY);