From patchwork Wed Sep 3 11:18:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 36567 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f70.google.com (mail-yh0-f70.google.com [209.85.213.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id ADD3D202E4 for ; Wed, 3 Sep 2014 11:18:52 +0000 (UTC) Received: by mail-yh0-f70.google.com with SMTP id b6sf29669088yha.9 for ; Wed, 03 Sep 2014 04:18:52 -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=LBRlyFSPIZrS1uEgblmLy2y5wso8//84NXLwAhzwJq8=; b=lcwWShcCnOHQvY/zuEHxrji7pJ0Igk0f7O/pzPBp68f5uJcrBauCwHM/qV6pmzqd5t qrUVtEald8Jg3PPdgtglBLNvbyRhuphBrGWFA8BucX7HjmOCWWuhFrHt1oFpwwbZzhr3 ml4k5AHZcfkqfg0HjUgoBSFW8hZtQZKrELfwVzVMCQaCH6B1OadfzBWUoPdUn5tLjlEE +KHEBnb4Fb93O6X58Al+dsUS4itj+iIKs4mG3S1hcAdxyOomzYFyUcqb/vSG+bOENjf1 eLQSAsyhkkkUjpB1pp6PY5tWVo1fHu/6QUoLehxnw+cU4naCjBn11WCZCkqi8pV53LRZ YPZg== X-Gm-Message-State: ALoCoQnFD/s/H9bnHw9C5XiS+C52KoJe1Jz1KO/I1GZqGZc84j0TJjUXQvSv2CEZ4iYbsvmOJBYC X-Received: by 10.236.87.46 with SMTP id x34mr4440908yhe.49.1409743132543; Wed, 03 Sep 2014 04:18:52 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.101.210 with SMTP id u76ls2791906qge.62.gmail; Wed, 03 Sep 2014 04:18:52 -0700 (PDT) X-Received: by 10.52.179.161 with SMTP id dh1mr24356vdc.78.1409743132417; Wed, 03 Sep 2014 04:18:52 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id ee2si718056vdb.40.2014.09.03.04.18.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Sep 2014 04:18:52 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id hy4so8644493vcb.33 for ; Wed, 03 Sep 2014 04:18:52 -0700 (PDT) X-Received: by 10.220.97.5 with SMTP id j5mr34855181vcn.16.1409743132325; Wed, 03 Sep 2014 04:18:52 -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 uj3csp663952vcb; Wed, 3 Sep 2014 04:18:51 -0700 (PDT) X-Received: by 10.50.88.37 with SMTP id bd5mr44229581igb.1.1409743131781; Wed, 03 Sep 2014 04:18:51 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id eb20si11455271icb.21.2014.09.03.04.18.51 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 03 Sep 2014 04:18:51 -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 1XP8aJ-0003Ws-H1; Wed, 03 Sep 2014 11:18:43 +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 1XP8aI-0003Wm-O9 for edk2-devel@lists.sourceforge.net; Wed, 03 Sep 2014 11:18:42 +0000 Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of linaro.org designates 74.125.82.174 as permitted sender) client-ip=74.125.82.174; envelope-from=ard.biesheuvel@linaro.org; helo=mail-we0-f174.google.com; Received: from mail-we0-f174.google.com ([74.125.82.174]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1XP8aH-0001T8-FC for edk2-devel@lists.sourceforge.net; Wed, 03 Sep 2014 11:18:42 +0000 Received: by mail-we0-f174.google.com with SMTP id u57so8441683wes.33 for ; Wed, 03 Sep 2014 04:18:35 -0700 (PDT) X-Received: by 10.194.174.4 with SMTP id bo4mr21676927wjc.84.1409743115077; Wed, 03 Sep 2014 04:18:35 -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.33 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Sep 2014 04:18:34 -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:01 +0200 Message-Id: <1409743096-14919-9-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: 1XP8aH-0001T8-FC Cc: peter.maydell@linaro.org, ilias.biris@linaro.org, christoffer.dall@linaro.org Subject: [edk2] [PATCH v6 08/23] ArmPkg: add ArmGenericTimerCounterLib implementation using virtual timer 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.174 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 This adds an implementation of ArmGenericTimerCounterLib using the virtual architected generic timer. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- .../ArmGenericTimerVirtCounterLib.c | 150 +++++++++++++++++++++ .../ArmGenericTimerVirtCounterLib.inf | 33 +++++ 2 files changed, 183 insertions(+) create mode 100644 ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.c create mode 100644 ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.inf diff --git a/ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.c b/ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.c new file mode 100644 index 000000000000..a3828f6dff0f --- /dev/null +++ b/ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.c @@ -0,0 +1,150 @@ +/** @file + + Copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.
+ Copyright (c) 2014, Linaro Ltd. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include +#include + +VOID +EFIAPI +ArmArchTimerEnableTimer ( + VOID + ) +{ + UINTN TimerCtrlReg; + + 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); +} + +VOID +EFIAPI +ArmArchTimerDisableTimer ( + VOID + ) +{ + UINTN TimerCtrlReg; + + ArmArchTimerReadReg (CntvCtl, (VOID *)&TimerCtrlReg); + TimerCtrlReg &= ~ARM_ARCH_TIMER_ENABLE; + ArmArchTimerWriteReg (CntvCtl, (VOID *)&TimerCtrlReg); +} + +VOID +EFIAPI +ArmArchTimerSetTimerFreq ( + IN UINTN FreqInHz + ) +{ + ArmArchTimerWriteReg (CntFrq, (VOID *)&FreqInHz); +} + +UINTN +EFIAPI +ArmArchTimerGetTimerFreq ( + VOID + ) +{ + UINTN ArchTimerFreq = 0; + ArmArchTimerReadReg (CntFrq, (VOID *)&ArchTimerFreq); + return ArchTimerFreq; +} + +UINTN +EFIAPI +ArmArchTimerGetTimerVal ( + VOID + ) +{ + UINTN ArchTimerVal; + ArmArchTimerReadReg (CntvTval, (VOID *)&ArchTimerVal); + + return ArchTimerVal; +} + + +VOID +EFIAPI +ArmArchTimerSetTimerVal ( + IN UINTN Val + ) +{ + ArmArchTimerWriteReg (CntvTval, (VOID *)&Val); +} + +UINT64 +EFIAPI +ArmArchTimerGetSystemCount ( + VOID + ) +{ + UINT64 SystemCount; + ArmArchTimerReadReg (CntvCt, (VOID *)&SystemCount); + + return SystemCount; +} + +UINTN +EFIAPI +ArmArchTimerGetTimerCtrlReg ( + VOID + ) +{ + UINTN Val; + + ArmArchTimerReadReg (CntvCtl, (VOID *)&Val); + + return Val; +} + +VOID +EFIAPI +ArmArchTimerSetTimerCtrlReg ( + UINTN Val + ) +{ + ArmArchTimerWriteReg (CntvCtl, (VOID *)&Val); +} + +UINT64 +EFIAPI +ArmArchTimerGetCompareVal ( + VOID + ) +{ + UINT64 Val; + ArmArchTimerReadReg (CntvCval, (VOID *)&Val); + + return Val; +} + +VOID +EFIAPI +ArmArchTimerSetCompareVal ( + IN UINT64 Val + ) +{ + ArmArchTimerWriteReg (CntvCval, (VOID *)&Val); +} diff --git a/ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.inf b/ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.inf new file mode 100644 index 000000000000..f2c015de3cce --- /dev/null +++ b/ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.inf @@ -0,0 +1,33 @@ +#/** @file +# Implement ArmGenericTimerCounterLib using the virtual timer +# +# Copyright (c) 2014, Linaro Ltd. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = ArmGenericTimerVirtCounterLib + FILE_GUID = 3C0D77CC-4F27-49C8-B25C-2D01D81ED4D8 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = ArmGenericTimerCounterLib + +[Sources] + ArmGenericTimerVirtCounterLib.c + +[Packages] + MdePkg/MdePkg.dec + ArmPkg/ArmPkg.dec + +[LibraryClasses] + ArmLib + BaseLib