From patchwork Fri Sep 5 11:56:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 36821 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f200.google.com (mail-ob0-f200.google.com [209.85.214.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 99D78202E4 for ; Fri, 5 Sep 2014 11:57:29 +0000 (UTC) Received: by mail-ob0-f200.google.com with SMTP id va2sf59132994obc.11 for ; Fri, 05 Sep 2014 04:57:29 -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=BOqrbie4lQwedC/lsyiNGE7V4LFDYmwgy9YjWuUsgG+4MghHtlbR/Z4w/6wkzJnukC cAmlG9PPGmUPVGpUV3fbxXd16Cv6juNeF8Z/XOqzgNCGL0yDk4dJXB2ZahPAZpFkpVUE SpAf70wnkkP1wUgFJYpmG/IHYaqm8uzmFSxm7ni/s4G0J2lstFdzUVP5nwsXPn9NDZwH O2iOuoLY9xa1VExxC6XuG3vCkaN6z89l/UV2A5iit9IyXMSO5doYiHyh+IxIfmQ94Hga GBprcy1vh+ujFjF31e13PAzg2SqbB7ofw7M9Ri8C/0/6VVfWxsFHFt37uE0OGBtrIoa0 3ksQ== X-Gm-Message-State: ALoCoQn3cwQROGD7LJIGhUvnF3LdKuZwapi+kAsJcXh7ff6k5/nOifjzVYNFBqBwBgDW8OuxKESE X-Received: by 10.42.28.6 with SMTP id l6mr5997892icc.23.1409918249232; Fri, 05 Sep 2014 04:57:29 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.21.50 with SMTP id 47ls663756qgk.6.gmail; Fri, 05 Sep 2014 04:57:29 -0700 (PDT) X-Received: by 10.52.145.204 with SMTP id sw12mr140562vdb.79.1409918249057; Fri, 05 Sep 2014 04:57:29 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id h4si1010249vdx.8.2014.09.05.04.57.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 05 Sep 2014 04:57:29 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id lf12so11867592vcb.25 for ; Fri, 05 Sep 2014 04:57:29 -0700 (PDT) X-Received: by 10.52.138.210 with SMTP id qs18mr8201774vdb.18.1409918248965; Fri, 05 Sep 2014 04:57:28 -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 uj3csp71045vcb; Fri, 5 Sep 2014 04:57:28 -0700 (PDT) X-Received: by 10.42.227.10 with SMTP id iy10mr13852946icb.3.1409918247994; Fri, 05 Sep 2014 04:57:27 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id qo6si1918919igb.23.2014.09.05.04.57.27 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 05 Sep 2014 04:57:27 -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-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XPs8l-0007Vy-O5; Fri, 05 Sep 2014 11:57:19 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XPs8k-0007Ve-KF for edk2-devel@lists.sourceforge.net; Fri, 05 Sep 2014 11:57:18 +0000 Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of linaro.org designates 209.85.212.182 as permitted sender) client-ip=209.85.212.182; envelope-from=ard.biesheuvel@linaro.org; helo=mail-wi0-f182.google.com; Received: from mail-wi0-f182.google.com ([209.85.212.182]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1XPs8j-00013m-LE for edk2-devel@lists.sourceforge.net; Fri, 05 Sep 2014 11:57:18 +0000 Received: by mail-wi0-f182.google.com with SMTP id z2so2805927wiv.9 for ; Fri, 05 Sep 2014 04:57:11 -0700 (PDT) X-Received: by 10.180.20.6 with SMTP id j6mr3156648wie.64.1409918231151; Fri, 05 Sep 2014 04:57:11 -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 dc9sm1758798wib.5.2014.09.05.04.57.09 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 05 Sep 2014 04:57:10 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.sourceforge.net, lersek@redhat.com, olivier.martin@arm.com Date: Fri, 5 Sep 2014 13:56:39 +0200 Message-Id: <1409918214-29584-10-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1409918214-29584-1-git-send-email-ard.biesheuvel@linaro.org> References: <1409918214-29584-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: 1XPs8j-00013m-LE Cc: peter.maydell@linaro.org, ilias.biris@linaro.org, christoffer.dall@linaro.org Subject: [edk2] [PATCH v7 09/24] 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.180 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 (