From patchwork Wed Sep 3 11:18:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 36570 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f69.google.com (mail-yh0-f69.google.com [209.85.213.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E8382202E4 for ; Wed, 3 Sep 2014 11:18:54 +0000 (UTC) Received: by mail-yh0-f69.google.com with SMTP id v1sf29681011yhn.4 for ; Wed, 03 Sep 2014 04:18:54 -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:cc: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=9gUKnn7hGQ1xAebmKROZQ768PErf1efz9CMASg3NJu0=; b=QU49MjCtuqWrggg4GN8QXw/2vsUREnq3f4Of+rqPPk5Ul3m2CgsjYv0uj+QQwu9GpO qPuaZGy7J7HmYOfSoOm5x7IfhZS+z9b2jXmoEm//NFq8FUHe1MF6XxUMX0aw/5tIuxnR aQr8+/mYfysY78vQVGf4g9M8Z/ZwyvsLEK06ZWlgxnvMkkc9Z/IRBhDbNJxJJ5iKgIn0 iFDnP1DwKFbL9TRlmvy9tKMZW6Z9yT3exvCWKJ203/oxx+4Gbb0TVGSspGanDUNYjAaT 4CY9Kmda5wdfXfn0LUkMY4fPxSxxCD4Q5QD0U9jy92CyHPzyXfs9h70gAtrxznGE4QvU M5/g== X-Gm-Message-State: ALoCoQlLf1R3lAkaUO1/j/XzDUeaxcubpy6blFjQsfPF6aYhx7vS+yYyaMm0PJCk4qWJRrBb8IlD X-Received: by 10.236.121.133 with SMTP id r5mr22363895yhh.28.1409743134777; Wed, 03 Sep 2014 04:18:54 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.51.51 with SMTP id t48ls2824145qga.67.gmail; Wed, 03 Sep 2014 04:18:54 -0700 (PDT) X-Received: by 10.52.89.211 with SMTP id bq19mr15988vdb.93.1409743134699; Wed, 03 Sep 2014 04:18:54 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id h9si3470654vcr.11.2014.09.03.04.18.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Sep 2014 04:18:54 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id la4so8748060vcb.9 for ; Wed, 03 Sep 2014 04:18:54 -0700 (PDT) X-Received: by 10.221.5.137 with SMTP id og9mr34911402vcb.18.1409743134615; Wed, 03 Sep 2014 04:18:54 -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 uj3csp663955vcb; Wed, 3 Sep 2014 04:18:54 -0700 (PDT) X-Received: by 10.50.164.167 with SMTP id yr7mr35387952igb.37.1409743134070; Wed, 03 Sep 2014 04:18:54 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id cr6si1674328igb.30.2014.09.03.04.18.53 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 03 Sep 2014 04:18:54 -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 1XP8aL-0003Xe-Rv; Wed, 03 Sep 2014 11:18:45 +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 1XP8aK-0003X3-9c for edk2-devel@lists.sourceforge.net; Wed, 03 Sep 2014 11:18:44 +0000 Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of linaro.org designates 74.125.82.46 as permitted sender) client-ip=74.125.82.46; envelope-from=ard.biesheuvel@linaro.org; helo=mail-wg0-f46.google.com; Received: from mail-wg0-f46.google.com ([74.125.82.46]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1XP8aJ-0001TB-1t for edk2-devel@lists.sourceforge.net; Wed, 03 Sep 2014 11:18:44 +0000 Received: by mail-wg0-f46.google.com with SMTP id x13so8313747wgg.5 for ; Wed, 03 Sep 2014 04:18:36 -0700 (PDT) X-Received: by 10.194.203.105 with SMTP id kp9mr46603051wjc.41.1409743116559; Wed, 03 Sep 2014 04:18:36 -0700 (PDT) Received: from ards-macbook-pro.local (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by mx.google.com with ESMTPSA id p1sm15258661wjy.22.2014.09.03.04.18.35 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Sep 2014 04:18:35 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.sourceforge.net, lersek@redhat.com, olivier.martin@arm.com Date: Wed, 3 Sep 2014 13:18:02 +0200 Message-Id: <1409743096-14919-10-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1409743096-14919-1-git-send-email-ard.biesheuvel@linaro.org> References: <1409743096-14919-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: 1XP8aJ-0001TB-1t Cc: peter.maydell@linaro.org, ilias.biris@linaro.org, christoffer.dall@linaro.org Subject: [edk2] [PATCH v6 09/23] ArmPkg/TimerDxe: respect layering of ARM timer libraries 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.178 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 Replace direct calls to the physical timer system registers with calls into ArmArchTimer.h functions so we can swap in the virtual timer later. Also, register the virt and hyp timer interrupts at init time. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- ArmPkg/Drivers/TimerDxe/TimerDxe.c | 18 ++++++++++++------ ArmPkg/Drivers/TimerDxe/TimerDxe.inf | 2 ++ ArmPkg/Include/Library/ArmArchTimer.h | 6 ++++++ ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c | 12 ++++++++++++ ArmPkg/Library/ArmLib/ArmV7/ArmV7ArchTimer.c | 12 ++++++++++++ 5 files changed, 44 insertions(+), 6 deletions(-) diff --git a/ArmPkg/Drivers/TimerDxe/TimerDxe.c b/ArmPkg/Drivers/TimerDxe/TimerDxe.c index 40ccf161be63..6c4494ed4ce6 100644 --- a/ArmPkg/Drivers/TimerDxe/TimerDxe.c +++ b/ArmPkg/Drivers/TimerDxe/TimerDxe.c @@ -163,10 +163,10 @@ TimerDriverSetTimerPeriod ( gBS->RestoreTPL (OriginalTPL); - // Get value of the current physical timer - CounterValue = ArmReadCntPct (); + // Get value of the current timer + CounterValue = ArmArchTimerGetSystemCount (); // Set the interrupt in Current Time + mTimerTick - ArmWriteCntpCval (CounterValue + mTimerTicks); + ArmArchTimerSetCompareVal (CounterValue + mTimerTicks); // Enable the timer ArmArchTimerEnableTimer (); @@ -321,9 +321,9 @@ TimerInterruptHandler ( // // Get current counter value - CurrentValue = ArmReadCntPct (); + CurrentValue = ArmArchTimerGetSystemCount (); // Get the counter value to compare with - CompareValue = ArmReadCntpCval (); + CompareValue = ArmArchTimerGetCompareVal (); // This loop is needed in case we missed interrupts (eg: case when the interrupt handling // has taken longer than mTickPeriod). @@ -335,7 +335,7 @@ TimerInterruptHandler ( } while (CompareValue < CurrentValue); // Set next compare value - ArmWriteCntpCval (CompareValue); + ArmArchTimerSetCompareVal (CompareValue); } // Enable timer interrupts @@ -390,6 +390,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..161d286d9c57 100644 --- a/ArmPkg/Drivers/TimerDxe/TimerDxe.inf +++ b/ArmPkg/Drivers/TimerDxe/TimerDxe.inf @@ -52,6 +52,8 @@ gEmbeddedTokenSpaceGuid.PcdTimerPeriod gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum gArmTokenSpaceGuid.PcdArmArchTimerIntrNum + gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum + gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz [Depex] diff --git a/ArmPkg/Include/Library/ArmArchTimer.h b/ArmPkg/Include/Library/ArmArchTimer.h index eb7e87d3c4fc..c41b53ee4143 100644 --- a/ArmPkg/Include/Library/ArmArchTimer.h +++ b/ArmPkg/Include/Library/ArmArchTimer.h @@ -106,6 +106,12 @@ ArmArchTimerSetTimerCtrlReg ( UINTN Val ); +UINT64 +EFIAPI +ArmArchTimerGetCompareVal ( + VOID + ); + VOID EFIAPI ArmArchTimerSetCompareVal ( diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c b/ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c index 6a461eb2e43e..66a979f7046a 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c @@ -265,6 +265,18 @@ ArmArchTimerSetTimerCtrlReg ( ArmArchTimerWriteReg (CntpCtl, (VOID *)&Val); } +UINT64 +EFIAPI +ArmArchTimerGetCompareVal ( + VOID + ) +{ + UINT64 Val; + ArmArchTimerReadReg (CntpCval, (VOID *)&Val); + + return Val; +} + VOID EFIAPI ArmArchTimerSetCompareVal ( diff --git a/ArmPkg/Library/ArmLib/ArmV7/ArmV7ArchTimer.c b/ArmPkg/Library/ArmLib/ArmV7/ArmV7ArchTimer.c index bebdafce7dba..836c27329eca 100644 --- a/ArmPkg/Library/ArmLib/ArmV7/ArmV7ArchTimer.c +++ b/ArmPkg/Library/ArmLib/ArmV7/ArmV7ArchTimer.c @@ -265,6 +265,18 @@ ArmArchTimerSetTimerCtrlReg ( ArmArchTimerWriteReg (CntpCtl, (VOID *)&Val); } +UINT64 +EFIAPI +ArmArchTimerGetCompareVal ( + VOID + ) +{ + UINT64 Val; + ArmArchTimerReadReg (CntpCval, (VOID *)&Val); + + return Val; +} + VOID EFIAPI ArmArchTimerSetCompareVal (