From 299c44cd4f53fe7493e7dad283f60e184f90b0b9 Mon Sep 17 00:00:00 2001 From: Min Xu Date: Mon, 29 Nov 2021 10:46:40 +0800 Subject: [PATCH] UefiCpuPkg: Setting initial-count register as the last step BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3711 Per SDM, changing the mode of APIC timer (from one-shot to periodic or vice versa) by writing to the timer LVT entry does not start the timer. To start the timer, it is necessary to write to the initial-count register. If initial-count is wrote before mode change, it's possible that timer expired before the mode change. Thus failing the periodic mode. Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Anthony Perard Cc: Julien Grall Cc: Eric Dong Cc: Ray Ni Acked-by: Gerd Hoffmann Reviewed-by: Ray Ni Reviewed-by: Jiewen Yao Signed-off-by: Min Xu --- .../Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c b/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c index 2d17177df1..f26d9c9389 100644 --- a/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c +++ b/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c @@ -967,11 +967,6 @@ InitializeApicTimer ( // InitializeLocalApicSoftwareEnable (TRUE); - // - // Program init-count register. - // - WriteLocalApicReg (XAPIC_TIMER_INIT_COUNT_OFFSET, InitCount); - if (DivideValue != 0) { ASSERT (DivideValue <= 128); ASSERT (DivideValue == GetPowerOfTwo32 ((UINT32)DivideValue)); @@ -996,6 +991,11 @@ InitializeApicTimer ( LvtTimer.Bits.Mask = 0; LvtTimer.Bits.Vector = Vector; WriteLocalApicReg (XAPIC_LVT_TIMER_OFFSET, LvtTimer.Uint32); + + // + // Program init-count register. + // + WriteLocalApicReg (XAPIC_TIMER_INIT_COUNT_OFFSET, InitCount); } /**