From eb485b6438f488db5300b56949d9dad460c9f2d4 Mon Sep 17 00:00:00 2001 From: Leif Lindholm Date: Tue, 19 Sep 2023 11:20:25 +0100 Subject: [PATCH] ArmVirtPkg: handle virtual EL2 timer in DT FEAT_VHE, introduced in ARMv8.1, adds a virtual EL2 timer. However, this library verifies that exactly 3 or 4 12-byte timer interrupts are provided in input DT, ASSERTing when the new timer is added. Change the assert to >= 36. Extend the current logic, also initializing PcdArmArchTimerHypVirtIntrNum if 5 interrupts are provided. Signed-off-by: Leif Lindholm Reported-by: Peter Maydell Cc: Ard Biesheuvel Cc: Sami Mujawar Reviewed-by: Ard Biesheuvel Tested-by: Peter Maydell --- ArmVirtPkg/ArmVirtCloudHv.dsc | 1 + ArmVirtPkg/ArmVirtKvmTool.dsc | 1 + ArmVirtPkg/ArmVirtQemu.dsc | 1 + ArmVirtPkg/ArmVirtQemuKernel.dsc | 1 + ArmVirtPkg/ArmVirtXen.dsc | 1 + .../ArmVirtTimerFdtClientLib.c | 11 ++++++++--- .../ArmVirtTimerFdtClientLib.inf | 1 + 7 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ArmVirtPkg/ArmVirtCloudHv.dsc b/ArmVirtPkg/ArmVirtCloudHv.dsc index c975e139a2..2cb89ce10c 100644 --- a/ArmVirtPkg/ArmVirtCloudHv.dsc +++ b/ArmVirtPkg/ArmVirtCloudHv.dsc @@ -178,6 +178,7 @@ gArmTokenSpaceGuid.PcdArmArchTimerIntrNum|0x0 gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|0x0 gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum|0x0 + gArmTokenSpaceGuid.PcdArmArchTimerHypVirtIntrNum|0x0 # # ARM General Interrupt Controller diff --git a/ArmVirtPkg/ArmVirtKvmTool.dsc b/ArmVirtPkg/ArmVirtKvmTool.dsc index 4541d03d23..00b6c64d1c 100644 --- a/ArmVirtPkg/ArmVirtKvmTool.dsc +++ b/ArmVirtPkg/ArmVirtKvmTool.dsc @@ -183,6 +183,7 @@ gArmTokenSpaceGuid.PcdArmArchTimerIntrNum|0x0 gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|0x0 gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum|0x0 + gArmTokenSpaceGuid.PcdArmArchTimerHypVirtIntrNum|0x0 # # ARM General Interrupt Controller diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index 1e0225951a..30e3cfc8b9 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -253,6 +253,7 @@ gArmTokenSpaceGuid.PcdArmArchTimerIntrNum|0x0 gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|0x0 gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum|0x0 + gArmTokenSpaceGuid.PcdArmArchTimerHypVirtIntrNum|0x0 # # ARM General Interrupt Controller diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc index 8ef5927b53..b50f8e84a3 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc @@ -214,6 +214,7 @@ gArmTokenSpaceGuid.PcdArmArchTimerIntrNum|0x0 gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|0x0 gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum|0x0 + gArmTokenSpaceGuid.PcdArmArchTimerHypVirtIntrNum|0x0 # # ARM General Interrupt Controller diff --git a/ArmVirtPkg/ArmVirtXen.dsc b/ArmVirtPkg/ArmVirtXen.dsc index a280ae203b..f44c1857c9 100644 --- a/ArmVirtPkg/ArmVirtXen.dsc +++ b/ArmVirtPkg/ArmVirtXen.dsc @@ -118,6 +118,7 @@ gArmTokenSpaceGuid.PcdArmArchTimerIntrNum|0x0 gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|0x0 gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum|0x0 + gArmTokenSpaceGuid.PcdArmArchTimerHypVirtIntrNum|0x0 # # ARM General Interrupt Controller diff --git a/ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.c b/ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.c index 38dd6c5333..c7732a2339 100644 --- a/ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.c +++ b/ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.c @@ -35,6 +35,7 @@ ArmVirtTimerFdtClientLibConstructor ( CONST INTERRUPT_PROPERTY *InterruptProp; UINT32 PropSize; INT32 SecIntrNum, IntrNum, VirtIntrNum, HypIntrNum; + INT32 HypVirtIntrNum; RETURN_STATUS PcdStatus; Status = gBS->LocateProtocol ( @@ -66,10 +67,10 @@ ArmVirtTimerFdtClientLibConstructor ( } // - // - interrupts : Interrupt list for secure, non-secure, virtual and - // hypervisor timers, in that order. + // - interrupts : Interrupt list for secure, non-secure, virtual, + // hypervisor and hypervisor virtual timers, in that order. // - ASSERT (PropSize == 36 || PropSize == 48); + ASSERT (PropSize >= 36); SecIntrNum = SwapBytes32 (InterruptProp[0].Number) + (InterruptProp[0].Type ? 16 : 0); @@ -79,6 +80,8 @@ ArmVirtTimerFdtClientLibConstructor ( + (InterruptProp[2].Type ? 16 : 0); HypIntrNum = PropSize < 48 ? 0 : SwapBytes32 (InterruptProp[3].Number) + (InterruptProp[3].Type ? 16 : 0); + HypVirtIntrNum = PropSize < 60 ? 0 : SwapBytes32 (InterruptProp[4].Number) + + (InterruptProp[4].Type ? 16 : 0); DEBUG (( DEBUG_INFO, @@ -97,6 +100,8 @@ ArmVirtTimerFdtClientLibConstructor ( ASSERT_RETURN_ERROR (PcdStatus); PcdStatus = PcdSet32S (PcdArmArchTimerHypIntrNum, HypIntrNum); ASSERT_RETURN_ERROR (PcdStatus); + PcdStatus = PcdSet32S (PcdArmArchTimerHypVirtIntrNum, HypVirtIntrNum); + ASSERT_RETURN_ERROR (PcdStatus); return EFI_SUCCESS; } diff --git a/ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.inf b/ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.inf index 9e6f6f63a5..f8fc013700 100644 --- a/ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.inf +++ b/ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.inf @@ -40,6 +40,7 @@ gArmTokenSpaceGuid.PcdArmArchTimerIntrNum gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum + gArmTokenSpaceGuid.PcdArmArchTimerHypVirtIntrNum [Depex] gFdtClientProtocolGuid