From patchwork Wed Sep 3 11:18:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 36573 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f198.google.com (mail-pd0-f198.google.com [209.85.192.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B3EE7202E4 for ; Wed, 3 Sep 2014 11:18:58 +0000 (UTC) Received: by mail-pd0-f198.google.com with SMTP id fp1sf48322460pdb.9 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=uTh/9DOFWkkKKYxKMcXnFSXnPgpqqXf4q+IBxojThrw=; b=YFeeZIqES4oSP6ASORLMEROXLO8KDcsYLQHW7E0isRIrd25XL0z6PagGKEEns1IXMO fM7v4L/r0Z9ByOUhlhnwqwt4vy2nGRY4ikqZaDKdmpfnxZISM5sPCHY/vmUxLob7Lfzc dgBV2QQ2oH8u8ikF/sXLxpwq3USrNJNSUpm2036dAYJq1bW8hMnSPouD3svVVsQ6S+hK xK5c4mg26kHwql/pr/2L86j1hPQ0/qnhYYuxjb+8OokZF8sjDuKGAI7Swmxp+FvyGYLh /BFACjY4kRVlY0DE4AogSh19IbrleUef5E5GA+rlVrFylAIUEd06+fQHKYlMQW5Fe3Hm O0zA== X-Gm-Message-State: ALoCoQl2ReCPajM/wvrsqO6m9mcO18ZM+iAUaXZEYQg6Rzc32q+PAijvFrejyQ2fmdVGZXCeToUq X-Received: by 10.66.168.197 with SMTP id zy5mr14452430pab.7.1409743133061; Wed, 03 Sep 2014 04:18:53 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.94.87 with SMTP id f81ls2941549qge.65.gmail; Wed, 03 Sep 2014 04:18:53 -0700 (PDT) X-Received: by 10.53.12.225 with SMTP id et1mr28561407vdd.5.1409743132971; Wed, 03 Sep 2014 04:18:52 -0700 (PDT) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id 16si740069vdf.0.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.177 as permitted sender) client-ip=209.85.220.177; Received: by mail-vc0-f177.google.com with SMTP id hq11so8453890vcb.22 for ; Wed, 03 Sep 2014 04:18:52 -0700 (PDT) X-Received: by 10.220.77.65 with SMTP id f1mr38216vck.48.1409743132886; 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 uj3csp663953vcb; Wed, 3 Sep 2014 04:18:52 -0700 (PDT) X-Received: by 10.43.77.135 with SMTP id zi7mr13895343icb.59.1409743131914; 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 lr1si1667806igb.37.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-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XP8aI-00087v-Ts; Wed, 03 Sep 2014 11:18:42 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XP8aG-00087i-V3 for edk2-devel@lists.sourceforge.net; Wed, 03 Sep 2014 11:18:41 +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 1XP8aF-0007Zq-Rj for edk2-devel@lists.sourceforge.net; Wed, 03 Sep 2014 11:18:40 +0000 Received: by mail-wi0-f182.google.com with SMTP id z2so9580968wiv.9 for ; Wed, 03 Sep 2014 04:18:33 -0700 (PDT) X-Received: by 10.194.86.34 with SMTP id m2mr46133326wjz.23.1409743113549; Wed, 03 Sep 2014 04:18:33 -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.32 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Sep 2014 04:18:32 -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:00 +0200 Message-Id: <1409743096-14919-8-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: 1XP8aF-0007Zq-Rj Cc: peter.maydell@linaro.org, ilias.biris@linaro.org, christoffer.dall@linaro.org Subject: [edk2] [PATCH v6 07/23] ArmPkg: add ArmGenericTimerCounterLib implementation using physical 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.177 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 physical architected generic timer. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- .../ArmGenericTimerPhyCounterLib.c | 139 +++++++++++++++++++++ .../ArmGenericTimerPhyCounterLib.inf | 33 +++++ 2 files changed, 172 insertions(+) create mode 100644 ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.c create mode 100644 ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.inf diff --git a/ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.c b/ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.c new file mode 100644 index 000000000000..568b8f55b164 --- /dev/null +++ b/ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.c @@ -0,0 +1,139 @@ +/** @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 (CntpCtl, (VOID *)&TimerCtrlReg); + TimerCtrlReg |= ARM_ARCH_TIMER_ENABLE; + ArmArchTimerWriteReg (CntpCtl, (VOID *)&TimerCtrlReg); +} + +VOID +EFIAPI +ArmArchTimerDisableTimer ( + VOID + ) +{ + UINTN TimerCtrlReg; + + ArmArchTimerReadReg (CntpCtl, (VOID *)&TimerCtrlReg); + TimerCtrlReg &= ~ARM_ARCH_TIMER_ENABLE; + ArmArchTimerWriteReg (CntpCtl, (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 (CntpTval, (VOID *)&ArchTimerVal); + + return ArchTimerVal; +} + + +VOID +EFIAPI +ArmArchTimerSetTimerVal ( + IN UINTN Val + ) +{ + ArmArchTimerWriteReg (CntpTval, (VOID *)&Val); +} + +UINT64 +EFIAPI +ArmArchTimerGetSystemCount ( + VOID + ) +{ + UINT64 SystemCount; + ArmArchTimerReadReg (CntPct, (VOID *)&SystemCount); + + return SystemCount; +} + +UINTN +EFIAPI +ArmArchTimerGetTimerCtrlReg ( + VOID + ) +{ + UINTN Val; + ArmArchTimerReadReg (CntpCtl, (VOID *)&Val); + + return Val; +} + +VOID +EFIAPI +ArmArchTimerSetTimerCtrlReg ( + UINTN Val + ) +{ + ArmArchTimerWriteReg (CntpCtl, (VOID *)&Val); +} + +UINT64 +EFIAPI +ArmArchTimerGetCompareVal ( + VOID + ) +{ + UINT64 Val; + ArmArchTimerReadReg (CntpCval, (VOID *)&Val); + + return Val; +} + +VOID +EFIAPI +ArmArchTimerSetCompareVal ( + IN UINT64 Val + ) +{ + ArmArchTimerWriteReg (CntpCval, (VOID *)&Val); +} diff --git a/ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.inf b/ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.inf new file mode 100644 index 000000000000..c962925cfa39 --- /dev/null +++ b/ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.inf @@ -0,0 +1,33 @@ +#/** @file +# Implement ArmGenericTimerCounterLib using the physical 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 = ArmGenericTimerPhyCounterLib + FILE_GUID = 7A07E61D-9967-407F-AE85-2EB0B50BEF2C + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = ArmGenericTimerCounterLib + +[Sources] + ArmGenericTimerPhyCounterLib.c + +[Packages] + MdePkg/MdePkg.dec + ArmPkg/ArmPkg.dec + +[LibraryClasses] + ArmLib + BaseLib