From patchwork Thu Aug 28 14:13:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 36208 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 232FF202DD for ; Thu, 28 Aug 2014 14:14:44 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id et14sf19756647pad.10 for ; Thu, 28 Aug 2014 07:14:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:reply-to:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=2tXDTlXLCuukxTgVGVmazLar+tKUWXRQ7ZPOJBRYqlo=; b=AAtA9LakLLZ5R4lINcOX6m+INUWuQCpZd07u25E1/lt5YNMQXVMNpgaiQ15kic2Lqx tuFxuOSe+uDRvaMDtrNEocj2blfUtqJyyxt3Wosd6wdn5oJCwzVpvmIuqooP+VFX3rh9 v4q5uajrYlNnyvjc32DsFQCpC1g3lrbYiACuXMKFe8QuZ5NFn5Nbggka2Nru4gEQG9p7 LwfxgBC/D5I1qux3XbP5BCTuRJ1b3nm6OjZcgDvcCVfEmJouUrkLVfA0JDXEC/p9pl/H aln02fn84+Jb+2Wy4O3oym8TfXKwNDiMexUyB+ymYZZWuEaEawsvMGYmyasdmBrsx2B9 nKJw== X-Gm-Message-State: ALoCoQkEbEKfaohKef8dQiwyqoexjAe57mWVvDnmlymRdJvTL7ASyCILCY5rVLPFZjjVLfnjFYOJ X-Received: by 10.66.119.174 with SMTP id kv14mr2183398pab.23.1409235283379; Thu, 28 Aug 2014 07:14:43 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.25.148 with SMTP id 20ls585478qgt.86.gmail; Thu, 28 Aug 2014 07:14:43 -0700 (PDT) X-Received: by 10.52.240.169 with SMTP id wb9mr785191vdc.81.1409235283263; Thu, 28 Aug 2014 07:14:43 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id w7si3571507vcn.49.2014.08.28.07.14.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 28 Aug 2014 07:14:43 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id ij19so857105vcb.40 for ; Thu, 28 Aug 2014 07:14:43 -0700 (PDT) X-Received: by 10.52.73.202 with SMTP id n10mr769998vdv.86.1409235283178; Thu, 28 Aug 2014 07:14:43 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp243450vcb; Thu, 28 Aug 2014 07:14:42 -0700 (PDT) X-Received: by 10.50.50.198 with SMTP id e6mr14422625igo.1.1409235282010; Thu, 28 Aug 2014 07:14:42 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id hh7si4225274icb.43.2014.08.28.07.14.41 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 28 Aug 2014 07:14:42 -0700 (PDT) Received-SPF: pass (google.com: domain of edk2-devel-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-4.v29.ch3.sourceforge.com) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XN0T6-0002Pb-7G; Thu, 28 Aug 2014 14:14:28 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XN0T4-0002PW-RB for edk2-devel@lists.sourceforge.net; Thu, 28 Aug 2014 14:14:26 +0000 Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of linaro.org designates 74.125.82.177 as permitted sender) client-ip=74.125.82.177; envelope-from=ard.biesheuvel@linaro.org; helo=mail-we0-f177.google.com; Received: from mail-we0-f177.google.com ([74.125.82.177]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1XN0T3-00054l-CG for edk2-devel@lists.sourceforge.net; Thu, 28 Aug 2014 14:14:26 +0000 Received: by mail-we0-f177.google.com with SMTP id u56so824576wes.8 for ; Thu, 28 Aug 2014 07:14:19 -0700 (PDT) X-Received: by 10.180.198.232 with SMTP id jf8mr36770400wic.37.1409235259076; Thu, 28 Aug 2014 07:14:19 -0700 (PDT) Received: from ards-macbook-pro.local (BSN-61-108-214.dial-up.dsl.siol.net. [86.61.108.214]) by mx.google.com with ESMTPSA id bk6sm10278657wjb.26.2014.08.28.07.14.16 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 28 Aug 2014 07:14:18 -0700 (PDT) From: Ard Biesheuvel To: lersek@redhat.com, olivier.martin@arm.com, edk2-devel@lists.sourceforge.net, peter.maydell@linaro.org, christoffer.dall@linaro.org, drjones@redhat.com, ilias.biris@linaro.org, leif.lindholm@linaro.org Date: Thu, 28 Aug 2014 16:13:49 +0200 Message-Id: <1409235244-25783-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1409235244-25783-1-git-send-email-ard.biesheuvel@linaro.org> References: <1409235244-25783-1-git-send-email-ard.biesheuvel@linaro.org> X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1XN0T3-00054l-CG Subject: [edk2] [PATCH v4 01/16] ArmPkg/TimerDxe: allow virtual timer to be selected X-BeenThere: edk2-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: edk2-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Michael Casadevall For virtual machines, the physical architected timer may not be available, so we need to allow the virtual timer to be used instead. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Michael Casadevall Acked-by: Laszlo Ersek Signed-off-by: Ard Biesheuvel --- ArmPkg/ArmPkg.dec | 3 + ArmPkg/Drivers/TimerDxe/TimerDxe.c | 6 ++ ArmPkg/Drivers/TimerDxe/TimerDxe.inf | 4 +- ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c | 74 +++++++++++++++++++---- ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf | 4 ++ ArmPkg/Library/ArmLib/AArch64/AArch64LibPrePi.inf | 3 + ArmPkg/Library/ArmLib/AArch64/AArch64LibSec.inf | 3 + ArmPkg/Library/ArmLib/ArmV7/ArmV7ArchTimer.c | 70 +++++++++++++++++---- ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf | 3 + ArmPkg/Library/ArmLib/ArmV7/ArmV7LibPrePi.inf | 3 + ArmPkg/Library/ArmLib/ArmV7/ArmV7LibSec.inf | 3 + 11 files changed, 151 insertions(+), 25 deletions(-) diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec index a8ca28fccc82..c2551d7c3307 100644 --- a/ArmPkg/ArmPkg.dec +++ b/ArmPkg/ArmPkg.dec @@ -69,6 +69,9 @@ # Linux (instead of PSCI) gArmTokenSpaceGuid.PcdArmLinuxSpinTable|FALSE|BOOLEAN|0x00000033 + # Whether to use the virtual rather than the physical architected timer + gArmTokenSpaceGuid.PcdArmArchTimerUseVirtual|FALSE|BOOLEAN|0x0000003F + [PcdsFixedAtBuild.common] gArmTokenSpaceGuid.PcdTrustzoneSupport|FALSE|BOOLEAN|0x00000006 diff --git a/ArmPkg/Drivers/TimerDxe/TimerDxe.c b/ArmPkg/Drivers/TimerDxe/TimerDxe.c index 633876bea6bd..9227be8326b0 100644 --- a/ArmPkg/Drivers/TimerDxe/TimerDxe.c +++ b/ArmPkg/Drivers/TimerDxe/TimerDxe.c @@ -347,6 +347,12 @@ TimerInitialize ( // Note: Because it is not possible to determine the security state of the // CPU dynamically, we just install interrupt handler for both sec and non-sec // timer PPI + Status = gInterrupt->RegisterInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerVirtIntrNum), TimerInterruptHandler); + ASSERT_EFI_ERROR (Status); + + Status = gInterrupt->RegisterInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerHypIntrNum), TimerInterruptHandler); + ASSERT_EFI_ERROR (Status); + Status = gInterrupt->RegisterInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerSecIntrNum), TimerInterruptHandler); ASSERT_EFI_ERROR (Status); diff --git a/ArmPkg/Drivers/TimerDxe/TimerDxe.inf b/ArmPkg/Drivers/TimerDxe/TimerDxe.inf index 50477ba42a7a..98b09ba8d203 100644 --- a/ArmPkg/Drivers/TimerDxe/TimerDxe.inf +++ b/ArmPkg/Drivers/TimerDxe/TimerDxe.inf @@ -52,7 +52,9 @@ gEmbeddedTokenSpaceGuid.PcdTimerPeriod gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum gArmTokenSpaceGuid.PcdArmArchTimerIntrNum - gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz + gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum + gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum + gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz [Depex] gHardwareInterruptProtocolGuid diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c b/ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c index fa4f7c741b15..f7ef69d5d4c1 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c @@ -175,9 +175,25 @@ ArmArchTimerEnableTimer ( { UINTN TimerCtrlReg; - ArmArchTimerReadReg (CntpCtl, (VOID *)&TimerCtrlReg); - TimerCtrlReg |= ARM_ARCH_TIMER_ENABLE; - ArmArchTimerWriteReg (CntpCtl, (VOID *)&TimerCtrlReg); + if (FeaturePcdGet (PcdArmArchTimerUseVirtual)) { + ArmArchTimerReadReg (CntvCtl, (VOID *)&TimerCtrlReg); + TimerCtrlReg |= ARM_ARCH_TIMER_ENABLE; + + /* + * When running under KVM, we need to unmask the interrupt on the timer side + * as KVM will mask it when servicing the interrupt at the hypervisor level + * and delivering the virtual timer interrupt to the guest. Otherwise, the + * interrupt will fire again, trapping into the hypervisor again, etc. etc. + * This is scheduled to be fixed on the KVM side, but there is no harm in + * leaving this in once KVM gets fixed. + */ + TimerCtrlReg &= ~ARM_ARCH_TIMER_IMASK; + ArmArchTimerWriteReg (CntvCtl, (VOID *)&TimerCtrlReg); + } else { + ArmArchTimerReadReg (CntpCtl, (VOID *)&TimerCtrlReg); + TimerCtrlReg |= ARM_ARCH_TIMER_ENABLE; + ArmArchTimerWriteReg (CntpCtl, (VOID *)&TimerCtrlReg); + } } VOID @@ -188,9 +204,15 @@ ArmArchTimerDisableTimer ( { UINTN TimerCtrlReg; - ArmArchTimerReadReg (CntpCtl, (VOID *)&TimerCtrlReg); - TimerCtrlReg &= ~ARM_ARCH_TIMER_ENABLE; - ArmArchTimerWriteReg (CntpCtl, (VOID *)&TimerCtrlReg); + if (FeaturePcdGet (PcdArmArchTimerUseVirtual)) { + ArmArchTimerReadReg (CntvCtl, (VOID *)&TimerCtrlReg); + TimerCtrlReg &= ~ARM_ARCH_TIMER_ENABLE; + ArmArchTimerWriteReg (CntvCtl, (VOID *)&TimerCtrlReg); + } else { + ArmArchTimerReadReg (CntpCtl, (VOID *)&TimerCtrlReg); + TimerCtrlReg &= ~ARM_ARCH_TIMER_ENABLE; + ArmArchTimerWriteReg (CntpCtl, (VOID *)&TimerCtrlReg); + } } VOID @@ -220,7 +242,12 @@ ArmArchTimerGetTimerVal ( ) { UINTN ArchTimerVal; - ArmArchTimerReadReg (CntpTval, (VOID *)&ArchTimerVal); + if (FeaturePcdGet (PcdArmArchTimerUseVirtual)) { + ArmArchTimerReadReg (CntvTval, (VOID *)&ArchTimerVal); + } else { + ArmArchTimerReadReg (CntpTval, (VOID *)&ArchTimerVal); + } + return ArchTimerVal; } @@ -231,7 +258,11 @@ ArmArchTimerSetTimerVal ( IN UINTN Val ) { - ArmArchTimerWriteReg (CntpTval, (VOID *)&Val); + if (FeaturePcdGet (PcdArmArchTimerUseVirtual)) { + ArmArchTimerWriteReg (CntvTval, (VOID *)&Val); + } else { + ArmArchTimerWriteReg (CntpTval, (VOID *)&Val); + } } UINT64 @@ -241,7 +272,12 @@ ArmArchTimerGetSystemCount ( ) { UINT64 SystemCount; - ArmArchTimerReadReg (CntPct, (VOID *)&SystemCount); + if (FeaturePcdGet (PcdArmArchTimerUseVirtual)) { + ArmArchTimerReadReg (CntvCt, (VOID *)&SystemCount); + } else { + ArmArchTimerReadReg (CntPct, (VOID *)&SystemCount); + } + return SystemCount; } @@ -252,7 +288,13 @@ ArmArchTimerGetTimerCtrlReg ( ) { UINTN Val; - ArmArchTimerReadReg (CntpCtl, (VOID *)&Val); + + if (FeaturePcdGet (PcdArmArchTimerUseVirtual)) { + ArmArchTimerReadReg (CntvCtl, (VOID *)&Val); + } else { + ArmArchTimerReadReg (CntpCtl, (VOID *)&Val); + } + return Val; } @@ -262,7 +304,11 @@ ArmArchTimerSetTimerCtrlReg ( UINTN Val ) { - ArmArchTimerWriteReg (CntpCtl, (VOID *)&Val); + if (FeaturePcdGet (PcdArmArchTimerUseVirtual)) { + ArmArchTimerWriteReg (CntvCtl, (VOID *)&Val); + } else { + ArmArchTimerWriteReg (CntpCtl, (VOID *)&Val); + } } VOID @@ -271,5 +317,9 @@ ArmArchTimerSetCompareVal ( IN UINT64 Val ) { - ArmArchTimerWriteReg (CntpCval, (VOID *)&Val); + if (FeaturePcdGet (PcdArmArchTimerUseVirtual)) { + ArmArchTimerWriteReg (CntvCval, (VOID *)&Val); + } else { + ArmArchTimerWriteReg (CntpCval, (VOID *)&Val); + } } diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf b/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf index e5247848b549..0dc2f26a21b5 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf @@ -42,5 +42,9 @@ [Protocols] gEfiCpuArchProtocolGuid +[FeaturePcd] + gArmTokenSpaceGuid.PcdArmArchTimerUseVirtual + [FixedPcd] gArmTokenSpaceGuid.PcdArmCacheOperationThreshold + diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64LibPrePi.inf b/ArmPkg/Library/ArmLib/AArch64/AArch64LibPrePi.inf index 3a99e1b713cc..081c6fb66cdc 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64LibPrePi.inf +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64LibPrePi.inf @@ -44,5 +44,8 @@ [Protocols] gEfiCpuArchProtocolGuid +[FeaturePcd] + gArmTokenSpaceGuid.PcdArmArchTimerUseVirtual + [FixedPcd] gArmTokenSpaceGuid.PcdArmCacheOperationThreshold diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64LibSec.inf b/ArmPkg/Library/ArmLib/AArch64/AArch64LibSec.inf index 57ac694cd733..1210b337b9c7 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64LibSec.inf +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64LibSec.inf @@ -39,5 +39,8 @@ [Protocols] gEfiCpuArchProtocolGuid +[FeaturePcd] + gArmTokenSpaceGuid.PcdArmArchTimerUseVirtual + [FixedPcd] gArmTokenSpaceGuid.PcdArmCacheOperationThreshold diff --git a/ArmPkg/Library/ArmLib/ArmV7/ArmV7ArchTimer.c b/ArmPkg/Library/ArmLib/ArmV7/ArmV7ArchTimer.c index 79083f56b708..150ae60272ca 100644 --- a/ArmPkg/Library/ArmLib/ArmV7/ArmV7ArchTimer.c +++ b/ArmPkg/Library/ArmLib/ArmV7/ArmV7ArchTimer.c @@ -175,9 +175,25 @@ ArmArchTimerEnableTimer ( { UINTN TimerCtrlReg; - ArmArchTimerReadReg (CntpCtl, (VOID *)&TimerCtrlReg); - TimerCtrlReg |= ARM_ARCH_TIMER_ENABLE; - ArmArchTimerWriteReg (CntpCtl, (VOID *)&TimerCtrlReg); + if (FeaturePcdGet (PcdArmArchTimerUseVirtual)) { + ArmArchTimerReadReg (CntvCtl, (VOID *)&TimerCtrlReg); + TimerCtrlReg |= ARM_ARCH_TIMER_ENABLE; + + /* + * When running under KVM, we need to unmask the interrupt on the timer side + * as KVM will mask it when servicing the interrupt at the hypervisor level + * and delivering the virtual timer interrupt to the guest. Otherwise, the + * interrupt will fire again, trapping into the hypervisor again, etc. etc. + * This is scheduled to be fixed on the KVM side, but there is no harm in + * leaving this in once KVM gets fixed. + */ + TimerCtrlReg &= ~ARM_ARCH_TIMER_IMASK; + ArmArchTimerWriteReg (CntvCtl, (VOID *)&TimerCtrlReg); + } else { + ArmArchTimerReadReg (CntpCtl, (VOID *)&TimerCtrlReg); + TimerCtrlReg |= ARM_ARCH_TIMER_ENABLE; + ArmArchTimerWriteReg (CntpCtl, (VOID *)&TimerCtrlReg); + } } VOID @@ -188,9 +204,15 @@ ArmArchTimerDisableTimer ( { UINTN TimerCtrlReg; - ArmArchTimerReadReg (CntpCtl, (VOID *)&TimerCtrlReg); - TimerCtrlReg &= ~ARM_ARCH_TIMER_ENABLE; - ArmArchTimerWriteReg (CntpCtl, (VOID *)&TimerCtrlReg); + if (FeaturePcdGet (PcdArmArchTimerUseVirtual)) { + ArmArchTimerReadReg (CntvCtl, (VOID *)&TimerCtrlReg); + TimerCtrlReg &= ~ARM_ARCH_TIMER_ENABLE; + ArmArchTimerWriteReg (CntvCtl, (VOID *)&TimerCtrlReg); + } else { + ArmArchTimerReadReg (CntpCtl, (VOID *)&TimerCtrlReg); + TimerCtrlReg &= ~ARM_ARCH_TIMER_ENABLE; + ArmArchTimerWriteReg (CntpCtl, (VOID *)&TimerCtrlReg); + } } VOID @@ -220,7 +242,11 @@ ArmArchTimerGetTimerVal ( ) { UINTN ArchTimerVal; - ArmArchTimerReadReg (CntpTval, (VOID *)&ArchTimerVal); + if (FeaturePcdGet (PcdArmArchTimerUseVirtual)) { + ArmArchTimerReadReg (CntvTval, (VOID *)&ArchTimerVal); + } else { + ArmArchTimerReadReg (CntpTval, (VOID *)&ArchTimerVal); + } return ArchTimerVal; } @@ -231,7 +257,11 @@ ArmArchTimerSetTimerVal ( IN UINTN Val ) { - ArmArchTimerWriteReg (CntpTval, (VOID *)&Val); + if (FeaturePcdGet (PcdArmArchTimerUseVirtual)) { + ArmArchTimerWriteReg (CntvTval, (VOID *)&Val); + } else { + ArmArchTimerWriteReg (CntpTval, (VOID *)&Val); + } } UINT64 @@ -241,7 +271,11 @@ ArmArchTimerGetSystemCount ( ) { UINT64 SystemCount; - ArmArchTimerReadReg (CntPct, (VOID *)&SystemCount); + if (FeaturePcdGet (PcdArmArchTimerUseVirtual)) { + ArmArchTimerReadReg (CntvCt, (VOID *)&SystemCount); + } else { + ArmArchTimerReadReg (CntPct, (VOID *)&SystemCount); + } return SystemCount; } @@ -252,7 +286,11 @@ ArmArchTimerGetTimerCtrlReg ( ) { UINTN Val; - ArmArchTimerReadReg (CntpCtl, (VOID *)&Val); + if (FeaturePcdGet (PcdArmArchTimerUseVirtual)) { + ArmArchTimerReadReg (CntvCtl, (VOID *)&Val); + } else { + ArmArchTimerReadReg (CntpCtl, (VOID *)&Val); + } return Val; } @@ -262,7 +300,11 @@ ArmArchTimerSetTimerCtrlReg ( UINTN Val ) { - ArmArchTimerWriteReg (CntpCtl, (VOID *)&Val); + if (FeaturePcdGet (PcdArmArchTimerUseVirtual)) { + ArmArchTimerWriteReg (CntvCtl, (VOID *)&Val); + } else { + ArmArchTimerWriteReg (CntpCtl, (VOID *)&Val); + } } VOID @@ -271,5 +313,9 @@ ArmArchTimerSetCompareVal ( IN UINT64 Val ) { - ArmArchTimerWriteReg (CntpCval, (VOID *)&Val); + if (FeaturePcdGet (PcdArmArchTimerUseVirtual)) { + ArmArchTimerWriteReg (CntvCval, (VOID *)&Val); + } else { + ArmArchTimerWriteReg (CntpCval, (VOID *)&Val); + } } diff --git a/ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf b/ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf index 55c0ec661a81..5fce083fc428 100644 --- a/ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf +++ b/ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf @@ -49,5 +49,8 @@ [Protocols] gEfiCpuArchProtocolGuid +[FeaturePcd] + gArmTokenSpaceGuid.PcdArmArchTimerUseVirtual + [FixedPcd] gArmTokenSpaceGuid.PcdArmCacheOperationThreshold diff --git a/ArmPkg/Library/ArmLib/ArmV7/ArmV7LibPrePi.inf b/ArmPkg/Library/ArmLib/ArmV7/ArmV7LibPrePi.inf index bc403d5613ca..bccd4b1f99bd 100644 --- a/ArmPkg/Library/ArmLib/ArmV7/ArmV7LibPrePi.inf +++ b/ArmPkg/Library/ArmLib/ArmV7/ArmV7LibPrePi.inf @@ -49,5 +49,8 @@ [Protocols] gEfiCpuArchProtocolGuid +[FeaturePcd] + gArmTokenSpaceGuid.PcdArmArchTimerUseVirtual + [FixedPcd] gArmTokenSpaceGuid.PcdArmCacheOperationThreshold diff --git a/ArmPkg/Library/ArmLib/ArmV7/ArmV7LibSec.inf b/ArmPkg/Library/ArmLib/ArmV7/ArmV7LibSec.inf index 4081d1a3e563..5a87b2bc080a 100644 --- a/ArmPkg/Library/ArmLib/ArmV7/ArmV7LibSec.inf +++ b/ArmPkg/Library/ArmLib/ArmV7/ArmV7LibSec.inf @@ -43,5 +43,8 @@ [Protocols] gEfiCpuArchProtocolGuid +[FeaturePcd] + gArmTokenSpaceGuid.PcdArmArchTimerUseVirtual + [FixedPcd] gArmTokenSpaceGuid.PcdArmCacheOperationThreshold