From patchwork Mon Aug 25 19:19:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 35929 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f197.google.com (mail-pd0-f197.google.com [209.85.192.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 15FC020565 for ; Mon, 25 Aug 2014 19:20:18 +0000 (UTC) Received: by mail-pd0-f197.google.com with SMTP id y10sf106850825pdj.0 for ; Mon, 25 Aug 2014 12:20:17 -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=aGIXDP/jV9uLVNCpli9JI+PDDQ7VVnxPrKxi+fneQAo=; b=Z+RWIoLNCkNHGLGOI6fOi/wAddna882gmnB7ITRw4guBQpCr6zBWd/UV0J4fp0KyGR jao3koNtFOGwlA7GZ2Kaf7eSAAKOAcLAibMz7o2EEBR2fTlTEVmAT/9C8TjstXWYPFcL BoSpzEG4+QXrkNgvXcwMPLzNOB8OS4hcdDsvSf/EaSLlLN1w8+nSuHT9iReNL81PMnUQ EG0XUQ8ziVxo6gYfX3LEOTg1ndDwTl/VD6GjTqE9DGe0mIYe2SHcMDpAPHuNVqfZIxpB J29DQk+/ayCLkcc+5pDOZ8CVN7IMtocAcClBsjvl3VPKwqzl6qfjIRAvwC2G98zuTtea mGCw== X-Gm-Message-State: ALoCoQnPbKOCSqV/KSs2XRqj6bngdBsto3PqgCTGBX9/VPer/OF0zbFx2q3+RH2inCEcOth6snKa X-Received: by 10.66.236.72 with SMTP id us8mr15152245pac.43.1408994417399; Mon, 25 Aug 2014 12:20:17 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.96.42 with SMTP id j39ls2287014qge.89.gmail; Mon, 25 Aug 2014 12:20:17 -0700 (PDT) X-Received: by 10.53.9.133 with SMTP id ds5mr5943174vdd.66.1408994417069; Mon, 25 Aug 2014 12:20:17 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id hq10si469542vdb.62.2014.08.25.12.20.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Aug 2014 12:20:17 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id im17so15870445vcb.3 for ; Mon, 25 Aug 2014 12:20:17 -0700 (PDT) X-Received: by 10.53.12.225 with SMTP id et1mr16782846vdd.5.1408994416975; Mon, 25 Aug 2014 12:20:16 -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 uj3csp141505vcb; Mon, 25 Aug 2014 12:20:16 -0700 (PDT) X-Received: by 10.50.93.74 with SMTP id cs10mr17372812igb.46.1408994416388; Mon, 25 Aug 2014 12:20:16 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id rs5si849228igb.52.2014.08.25.12.20.15 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 25 Aug 2014 12:20:16 -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-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XLzoG-0000Mr-1Q; Mon, 25 Aug 2014 19:20:08 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XLzoE-0000Mm-NC for edk2-devel@lists.sourceforge.net; Mon, 25 Aug 2014 19:20:06 +0000 Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of linaro.org designates 209.85.212.180 as permitted sender) client-ip=209.85.212.180; envelope-from=ard.biesheuvel@linaro.org; helo=mail-wi0-f180.google.com; Received: from mail-wi0-f180.google.com ([209.85.212.180]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1XLzoD-0003WM-FV for edk2-devel@lists.sourceforge.net; Mon, 25 Aug 2014 19:20:06 +0000 Received: by mail-wi0-f180.google.com with SMTP id n3so3044679wiv.7 for ; Mon, 25 Aug 2014 12:19:59 -0700 (PDT) X-Received: by 10.180.95.169 with SMTP id dl9mr11147187wib.51.1408994399076; Mon, 25 Aug 2014 12:19:59 -0700 (PDT) Received: from ards-macbook-pro.local ([193.77.13.198]) by mx.google.com with ESMTPSA id b3sm3476891wiw.22.2014.08.25.12.19.48 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Aug 2014 12:19:58 -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: Mon, 25 Aug 2014 21:19:20 +0200 Message-Id: <1408994367-11143-4-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1408994367-11143-1-git-send-email-ard.biesheuvel@linaro.org> References: <1408994367-11143-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: 1XLzoD-0003WM-FV Subject: [edk2] [PATCH 03/10] 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.172 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. Signed-off-by: Michael Casadevall Signed-off-by: Ard Biesheuvel --- ArmPkg/ArmPkg.dec | 5 ++ ArmPkg/Drivers/TimerDxe/TimerDxe.c | 6 +++ ArmPkg/Drivers/TimerDxe/TimerDxe.inf | 3 ++ ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c | 66 ++++++++++++++++++----- ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf | 2 + ArmPkg/Library/ArmLib/AArch64/AArch64LibPrePi.inf | 1 + ArmPkg/Library/ArmLib/AArch64/AArch64LibSec.inf | 1 + 7 files changed, 72 insertions(+), 12 deletions(-) diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec index 14f16b85169a..1d896892dafc 100644 --- a/ArmPkg/ArmPkg.dec +++ b/ArmPkg/ArmPkg.dec @@ -143,6 +143,11 @@ # ARM Architectural Timer Interrupt(GIC PPI) number gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum|29|UINT32|0x00000035 gArmTokenSpaceGuid.PcdArmArchTimerIntrNum|30|UINT32|0x00000036 + gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|27|UINT32|0x00000040 + gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum|26|UINT32|0x00000041 + + # MC: not really sure what the last value is except I think it needs to be unique + gArmTokenSpaceGuid.PcdArmArchTimerUseVirtual|FALSE|BOOLEAN|0x0000003F [PcdsFixedAtBuild.ARM] # diff --git a/ArmPkg/Drivers/TimerDxe/TimerDxe.c b/ArmPkg/Drivers/TimerDxe/TimerDxe.c index a43a10f48cee..be346bf89c51 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 061fcbc688d9..fa48e569a17d 100644 --- a/ArmPkg/Drivers/TimerDxe/TimerDxe.inf +++ b/ArmPkg/Drivers/TimerDxe/TimerDxe.inf @@ -52,6 +52,9 @@ gEmbeddedTokenSpaceGuid.PcdTimerPeriod gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum gArmTokenSpaceGuid.PcdArmArchTimerIntrNum + gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum + gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum + gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz [Depex] diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c b/ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c index fa4f7c741b15..232d745b3d06 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c @@ -175,9 +175,17 @@ ArmArchTimerEnableTimer ( { UINTN TimerCtrlReg; - ArmArchTimerReadReg (CntpCtl, (VOID *)&TimerCtrlReg); - TimerCtrlReg |= ARM_ARCH_TIMER_ENABLE; - ArmArchTimerWriteReg (CntpCtl, (VOID *)&TimerCtrlReg); + if (PcdGetBool(PcdArmArchTimerUseVirtual) == TRUE) { + ArmArchTimerReadReg (CntvCtl, (VOID *)&TimerCtrlReg); + /* FIXME: We need to clear IMASK when under KVM because KVM sets it. Unclear if this is a bug ... */ + TimerCtrlReg |= ARM_ARCH_TIMER_ENABLE; + 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 +196,15 @@ ArmArchTimerDisableTimer ( { UINTN TimerCtrlReg; - ArmArchTimerReadReg (CntpCtl, (VOID *)&TimerCtrlReg); - TimerCtrlReg &= ~ARM_ARCH_TIMER_ENABLE; - ArmArchTimerWriteReg (CntpCtl, (VOID *)&TimerCtrlReg); + if (PcdGetBool(PcdArmArchTimerUseVirtual) == TRUE) { + 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 +234,12 @@ ArmArchTimerGetTimerVal ( ) { UINTN ArchTimerVal; - ArmArchTimerReadReg (CntpTval, (VOID *)&ArchTimerVal); + if (PcdGetBool(PcdArmArchTimerUseVirtual) == TRUE) { + ArmArchTimerReadReg (CntvTval, (VOID *)&ArchTimerVal); + } else { + ArmArchTimerReadReg (CntpTval, (VOID *)&ArchTimerVal); + } + return ArchTimerVal; } @@ -231,7 +250,11 @@ ArmArchTimerSetTimerVal ( IN UINTN Val ) { - ArmArchTimerWriteReg (CntpTval, (VOID *)&Val); + if (PcdGetBool(PcdArmArchTimerUseVirtual) == TRUE) { + ArmArchTimerWriteReg (CntvTval, (VOID *)&Val); + } else { + ArmArchTimerWriteReg (CntpTval, (VOID *)&Val); + } } UINT64 @@ -241,7 +264,12 @@ ArmArchTimerGetSystemCount ( ) { UINT64 SystemCount; - ArmArchTimerReadReg (CntPct, (VOID *)&SystemCount); + if (PcdGetBool(PcdArmArchTimerUseVirtual) == TRUE) { + ArmArchTimerReadReg (CntvCt, (VOID *)&SystemCount); + } else { + ArmArchTimerReadReg (CntPct, (VOID *)&SystemCount); + } + return SystemCount; } @@ -252,7 +280,13 @@ ArmArchTimerGetTimerCtrlReg ( ) { UINTN Val; - ArmArchTimerReadReg (CntpCtl, (VOID *)&Val); + + if (PcdGetBool(PcdArmArchTimerUseVirtual) == TRUE) { + ArmArchTimerReadReg (CntvCtl, (VOID *)&Val); + } else { + ArmArchTimerReadReg (CntpCtl, (VOID *)&Val); + } + return Val; } @@ -262,7 +296,11 @@ ArmArchTimerSetTimerCtrlReg ( UINTN Val ) { - ArmArchTimerWriteReg (CntpCtl, (VOID *)&Val); + if (PcdGetBool(PcdArmArchTimerUseVirtual) == TRUE) { + ArmArchTimerWriteReg (CntvCtl, (VOID *)&Val); + } else { + ArmArchTimerWriteReg (CntpCtl, (VOID *)&Val); + } } VOID @@ -271,5 +309,9 @@ ArmArchTimerSetCompareVal ( IN UINT64 Val ) { - ArmArchTimerWriteReg (CntpCval, (VOID *)&Val); + if (PcdGetBool(PcdArmArchTimerUseVirtual) == TRUE) { + 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..f7d50b9bd54c 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf @@ -44,3 +44,5 @@ [FixedPcd] gArmTokenSpaceGuid.PcdArmCacheOperationThreshold + gArmTokenSpaceGuid.PcdArmArchTimerUseVirtual + diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64LibPrePi.inf b/ArmPkg/Library/ArmLib/AArch64/AArch64LibPrePi.inf index 3a99e1b713cc..698de2979f97 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64LibPrePi.inf +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64LibPrePi.inf @@ -46,3 +46,4 @@ [FixedPcd] gArmTokenSpaceGuid.PcdArmCacheOperationThreshold + gArmTokenSpaceGuid.PcdArmArchTimerUseVirtual diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64LibSec.inf b/ArmPkg/Library/ArmLib/AArch64/AArch64LibSec.inf index 57ac694cd733..0eba4c04d404 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64LibSec.inf +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64LibSec.inf @@ -41,3 +41,4 @@ [FixedPcd] gArmTokenSpaceGuid.PcdArmCacheOperationThreshold + gArmTokenSpaceGuid.PcdArmArchTimerUseVirtual