From nobody Fri Nov 1 04:43:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1524495682637555.3074403855533; Mon, 23 Apr 2018 08:01:22 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id DDF3B228392EA; Mon, 23 Apr 2018 08:01:19 -0700 (PDT) Received: from mail-wr0-x243.google.com (mail-wr0-x243.google.com [IPv6:2a00:1450:400c:c0c::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 22ABF2277AF25 for ; Mon, 23 Apr 2018 08:01:18 -0700 (PDT) Received: by mail-wr0-x243.google.com with SMTP id c14-v6so2089447wrd.4 for ; Mon, 23 Apr 2018 08:01:18 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:3995:5470:200:1aff:fe1b:b328]) by smtp.gmail.com with ESMTPSA id y101sm8955460wmh.10.2018.04.23.08.01.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Apr 2018 08:01:15 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::243; helo=mail-wr0-x243.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ub+puy3j8v+0jJyLiAroAUyuWABd2IsKZxuZW79p7J4=; b=PAnR+srSPY6STPH3OVTvfMOz46i49ytOz9jlDiBvMfYWm7qEquFhubjMCZHvGNz2LJ uwVkU+HR1kZBibvFDPxaYKhRH6r6EcWn/mSxeqFeUae928b01EdjoC44xtOPN0uNyiXV cdRzMRwphezofomcrIojPf0HpZFjXrJvgQ1ZI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ub+puy3j8v+0jJyLiAroAUyuWABd2IsKZxuZW79p7J4=; b=OhJE0llAg1IKbiLJSaOKTFX4I7E3C1jquKpwyOqFvD/zH5e9Cwl1YNhpTw4L+VFyY1 w0mpCgyp8fYi8G5oKpUyCVRvyQzFmVPpE6deaf636gseqIivEC4vMIzcWMbL5Afy1B9t Cu2ZSQCeAN2YB3jtxbkvIsfggu821WqmD33pvhns6EX165YCxZUTnRohq/2YRB866+jI 5fLPGJTDIKvKMp7vR0KQ+F5mFWH9QdruuYsRXFin49gZjQEwYgwrBvtJNUVoFXY0pueM nE270h512IbbgE2PIwTd/X1CLBaGsTv32lnJR1BHmvAMe1ASZ3rS5OenwhiQMjDuSYnP x1CQ== X-Gm-Message-State: ALQs6tA+ttI+wm0u1D3AqDrUitBp39M+mTr0kA3iLAjuhHgngmmgRcuo Zhr5p4JVI3/VuOSKwxGGdqyYa2y3TpQ= X-Google-Smtp-Source: AIpwx48VTIkhWMvr8N6MXTHnDEbPNvuOb9Fd44sn819jn72u3e3RSVieXLc5vFH2nAhHLVgbNgKbBg== X-Received: by 2002:adf:a98f:: with SMTP id b15-v6mr16883956wrd.48.1524495676341; Mon, 23 Apr 2018 08:01:16 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Mon, 23 Apr 2018 17:00:57 +0200 Message-Id: <20180423150057.13515-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180423150057.13515-1-ard.biesheuvel@linaro.org> References: <20180423150057.13515-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH 2/2] ArmVirtPkg: reinstate timer unmask quirk for Xen X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: julien.grall@arm.com, lersek@redhat.com, leif.lindholm@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Commit 411a373ed642 ("ArmPkg/TimerDxe: remove workaround for KVM timer handling") removed the virtual timer handling quirk that cleared the mask bit in the control register when enabling the timer, under the assumption that only ancient KVM host implementations required it. However, Julien reports that Xen also masks the timer interrupt in the guest view of the timer control register, and therefore needs the same quirk. So let's reinstate it, but using a Xen specific implementation of the timer support library, so that other virt platforms remain unchanged. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- ArmVirtPkg/ArmVirtXen.dsc = | 1 + ArmVirtPkg/Library/XenArmGenericTimerVirtCounterLib/XenArmGenericTimerVirt= CounterLib.c | 146 ++++++++++++++++++++ ArmVirtPkg/Library/XenArmGenericTimerVirtCounterLib/XenArmGenericTimerVirt= CounterLib.inf | 33 +++++ 3 files changed, 180 insertions(+) diff --git a/ArmVirtPkg/ArmVirtXen.dsc b/ArmVirtPkg/ArmVirtXen.dsc index 175b56d10c8f..8878912e6bef 100644 --- a/ArmVirtPkg/ArmVirtXen.dsc +++ b/ArmVirtPkg/ArmVirtXen.dsc @@ -36,6 +36,7 @@ [LibraryClasses] RealTimeClockLib|ArmVirtPkg/Library/XenRealTimeClockLib/XenRealTimeClock= Lib.inf XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf =20 + ArmGenericTimerCounterLib|ArmVirtPkg/Library/XenArmGenericTimerVirtCount= erLib/XenArmGenericTimerVirtCounterLib.inf ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf ArmMmuLib|ArmPkg/Library/ArmMmuLib/ArmMmuBaseLib.inf =20 diff --git a/ArmVirtPkg/Library/XenArmGenericTimerVirtCounterLib/XenArmGene= ricTimerVirtCounterLib.c b/ArmVirtPkg/Library/XenArmGenericTimerVirtCounter= Lib/XenArmGenericTimerVirtCounterLib.c new file mode 100644 index 000000000000..75c28168453e --- /dev/null +++ b/ArmVirtPkg/Library/XenArmGenericTimerVirtCounterLib/XenArmGenericTime= rVirtCounterLib.c @@ -0,0 +1,146 @@ +/** @file + + Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.
+ Copyright (c) 2014 - 2018, Linaro Ltd. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include +#include + +VOID +EFIAPI +ArmGenericTimerEnableTimer ( + VOID + ) +{ + UINTN TimerCtrlReg; + + TimerCtrlReg =3D ArmReadCntvCtl (); + TimerCtrlReg |=3D ARM_ARCH_TIMER_ENABLE; + ArmWriteCntvCtl (TimerCtrlReg); +} + +VOID +EFIAPI +ArmGenericTimerReenableTimer ( + VOID + ) +{ + UINTN TimerCtrlReg; + + TimerCtrlReg =3D ArmReadCntvCtl (); + TimerCtrlReg |=3D ARM_ARCH_TIMER_ENABLE; + + // + // When running under Xen, we need to unmask the interrupt on the timer = side + // as Xen will mask it when servicing the interrupt at the hypervisor le= vel + // and delivering the virtual timer interrupt to the guest. Otherwise, t= he + // interrupt will fire again, trapping into the hypervisor again, etc. e= tc. + // + TimerCtrlReg &=3D ~ARM_ARCH_TIMER_IMASK; + ArmWriteCntvCtl (TimerCtrlReg); +} + +VOID +EFIAPI +ArmGenericTimerDisableTimer ( + VOID + ) +{ + UINTN TimerCtrlReg; + + TimerCtrlReg =3D ArmReadCntvCtl (); + TimerCtrlReg &=3D ~ARM_ARCH_TIMER_ENABLE; + ArmWriteCntvCtl (TimerCtrlReg); +} + +VOID +EFIAPI +ArmGenericTimerSetTimerFreq ( + IN UINTN FreqInHz + ) +{ + ArmWriteCntFrq (FreqInHz); +} + +UINTN +EFIAPI +ArmGenericTimerGetTimerFreq ( + VOID + ) +{ + return ArmReadCntFrq (); +} + +UINTN +EFIAPI +ArmGenericTimerGetTimerVal ( + VOID + ) +{ + return ArmReadCntvTval (); +} + + +VOID +EFIAPI +ArmGenericTimerSetTimerVal ( + IN UINTN Value + ) +{ + ArmWriteCntvTval (Value); +} + +UINT64 +EFIAPI +ArmGenericTimerGetSystemCount ( + VOID + ) +{ + return ArmReadCntvCt (); +} + +UINTN +EFIAPI +ArmGenericTimerGetTimerCtrlReg ( + VOID + ) +{ + return ArmReadCntvCtl (); +} + +VOID +EFIAPI +ArmGenericTimerSetTimerCtrlReg ( + UINTN Value + ) +{ + ArmWriteCntvCtl (Value); +} + +UINT64 +EFIAPI +ArmGenericTimerGetCompareVal ( + VOID + ) +{ + return ArmReadCntvCval (); +} + +VOID +EFIAPI +ArmGenericTimerSetCompareVal ( + IN UINT64 Value + ) +{ + ArmWriteCntvCval (Value); +} diff --git a/ArmVirtPkg/Library/XenArmGenericTimerVirtCounterLib/XenArmGene= ricTimerVirtCounterLib.inf b/ArmVirtPkg/Library/XenArmGenericTimerVirtCount= erLib/XenArmGenericTimerVirtCounterLib.inf new file mode 100644 index 000000000000..bd6ac8039844 --- /dev/null +++ b/ArmVirtPkg/Library/XenArmGenericTimerVirtCounterLib/XenArmGenericTime= rVirtCounterLib.inf @@ -0,0 +1,33 @@ +#/** @file +# Implement ArmGenericTimerCounterLib for Xen using the virtual timer +# +# Copyright (c) 2014 - 2018, Linaro Ltd. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD License +# which accompanies this distribution. The full text of the license may b= e 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 IM= PLIED. +# +# +#**/ + +[Defines] + INF_VERSION =3D 0x0001001A + BASE_NAME =3D XenArmGenericTimerVirtCounterLib + FILE_GUID =3D e3913319-96ac-4ac0-808b-8edb8776a51c + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D ArmGenericTimerCounterLib + +[Sources] + XenArmGenericTimerVirtCounterLib.c + +[Packages] + MdePkg/MdePkg.dec + ArmPkg/ArmPkg.dec + +[LibraryClasses] + ArmLib + BaseLib --=20 2.17.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel