From patchwork Sat Nov 10 15:46:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 1724461 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 895A23FC8F for ; Sat, 10 Nov 2012 16:00:49 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TXDRg-0000t1-5J; Sat, 10 Nov 2012 15:58:08 +0000 Received: from mail-wi0-f171.google.com ([209.85.212.171]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TXDGA-0008Al-2D for linux-arm-kernel@lists.infradead.org; Sat, 10 Nov 2012 15:46:16 +0000 Received: by mail-wi0-f171.google.com with SMTP id c10so185451wiw.0 for ; Sat, 10 Nov 2012 07:46:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=subject:to:from:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-type:content-transfer-encoding :x-gm-message-state; bh=Rb7ilpstIIn8TRcE3gxzhi/4cefQpbSy0a8ykoKMjHI=; b=Av0dtVCdHLgYv6Ln4ogXr9GPIE7GboOLvixeklBpmEadhjcu58npiodFzWzYPPykly Jw0WeeNPIK+WPiDCcvHu1YDL7Zm4OFNZBnPs5MHIceVa2djzriSRcrenXB2a5A+PP6dU PE3mHTU4bq7LkKInqD7C18Su4dRShsBaan37RgsV2537r4OOcz4ahP363peYxeYOqiYf mrt3THTBkcGtmRKawdZ4gisd8TQxwXLcTUGu2g/JyX2/GqUdl8wUx0J/U7zkhAU2+iQH cxoNFKJbV1FTvknLfpNJ33UpO5Ta4PrdOX5BnsMDHDfpnMQ/iHPSgQLHlUvaqffXQRmG He9Q== Received: by 10.180.89.234 with SMTP id br10mr7634353wib.2.1352562373747; Sat, 10 Nov 2012 07:46:13 -0800 (PST) Received: from [127.0.1.1] (ip1.c116.obr91.cust.comxnet.dk. [87.72.8.103]) by mx.google.com with ESMTPS id eq2sm2817075wib.1.2012.11.10.07.46.12 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 10 Nov 2012 07:46:12 -0800 (PST) Subject: [PATCH v4 2/5] ARM: KVM: arch_timers: Add minimal infrastructure To: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu From: Christoffer Dall Date: Sat, 10 Nov 2012 16:46:12 +0100 Message-ID: <20121110154611.3274.87138.stgit@chazy-air> In-Reply-To: <20121110154554.3274.77777.stgit@chazy-air> References: <20121110154554.3274.77777.stgit@chazy-air> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQm9H/0Q/RgvamKOBsIFo7ELS+XDANFvxZhWZSDOQVvrI9Gp9UkinbXSd0pZEboZS55gy9pR X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121110_104615_310313_545CABFA X-CRM114-Status: GOOD ( 16.72 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.171 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Marc Zyngier X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Marc Zyngier Add some very minimal architected timer related infrastructure. For the moment, we just provide empty structures, and enable/disable access to the physical timer across world switch. Signed-off-by: Marc Zyngier Signed-off-by: Christoffer Dall --- arch/arm/include/asm/kvm_arch_timer.h | 45 +++++++++++++++++++++++++++++++++ arch/arm/include/asm/kvm_host.h | 5 ++++ arch/arm/kvm/interrupts.S | 2 + arch/arm/kvm/interrupts_head.S | 19 ++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 arch/arm/include/asm/kvm_arch_timer.h diff --git a/arch/arm/include/asm/kvm_arch_timer.h b/arch/arm/include/asm/kvm_arch_timer.h new file mode 100644 index 0000000..513b852 --- /dev/null +++ b/arch/arm/include/asm/kvm_arch_timer.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2012 ARM Ltd. + * Author: Marc Zyngier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __ASM_ARM_KVM_ARCH_TIMER_H +#define __ASM_ARM_KVM_ARCH_TIMER_H + +struct arch_timer_kvm { +}; + +struct arch_timer_cpu { +}; + +#ifndef CONFIG_KVM_ARM_TIMER +static inline int kvm_timer_hyp_init(void) +{ + return 0; +}; + +static inline int kvm_timer_init(struct kvm *kvm) +{ + return 0; +} + +static inline void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu) {} +static inline void kvm_timer_sync_to_cpu(struct kvm_vcpu *vcpu) {} +static inline void kvm_timer_sync_from_cpu(struct kvm_vcpu *vcpu) {} +static inline void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu) {} +#endif + +#endif diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index 49ba25a..41012ef 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -24,6 +24,7 @@ #include #include #include +#include #define KVM_MAX_VCPUS CONFIG_KVM_ARM_MAX_VCPUS #define KVM_MEMORY_SLOTS 32 @@ -48,6 +49,9 @@ struct kvm_arch { /* VTTBR value associated with below pgd and vmid */ u64 vttbr; + /* Timer */ + struct arch_timer_kvm timer; + /* * Anything that is not used directly from assembly code goes * here. @@ -98,6 +102,7 @@ struct kvm_vcpu_arch { /* VGIC state */ struct vgic_cpu vgic_cpu; + struct arch_timer_cpu timer_cpu; /* * Anything that is not used directly from assembly code goes diff --git a/arch/arm/kvm/interrupts.S b/arch/arm/kvm/interrupts.S index e418c9b..5a09e89 100644 --- a/arch/arm/kvm/interrupts.S +++ b/arch/arm/kvm/interrupts.S @@ -92,6 +92,7 @@ ENTRY(__kvm_vcpu_run) save_host_regs restore_vgic_state r0 + restore_timer_state r0 @ Store hardware CP15 state and load guest state read_cp15_state @@ -186,6 +187,7 @@ after_vfp_restore: read_cp15_state 1, r1 write_cp15_state + save_timer_state r1 save_vgic_state r1 restore_host_regs diff --git a/arch/arm/kvm/interrupts_head.S b/arch/arm/kvm/interrupts_head.S index c2423d8..0003aab 100644 --- a/arch/arm/kvm/interrupts_head.S +++ b/arch/arm/kvm/interrupts_head.S @@ -418,6 +418,25 @@ #endif .endm +#define CNTHCTL_PL1PCTEN (1 << 0) +#define CNTHCTL_PL1PCEN (1 << 1) + +.macro save_timer_state vcpup + @ Allow physical timer/counter access for the host + mrc p15, 4, r2, c14, c1, 0 @ CNTHCTL + orr r2, r2, #(CNTHCTL_PL1PCEN | CNTHCTL_PL1PCTEN) + mcr p15, 4, r2, c14, c1, 0 @ CNTHCTL +.endm + +.macro restore_timer_state vcpup + @ Disallow physical timer access for the guest + @ Physical counter access is allowed + mrc p15, 4, r2, c14, c1, 0 @ CNTHCTL + orr r2, r2, #CNTHCTL_PL1PCTEN + bic r2, r2, #CNTHCTL_PL1PCEN + mcr p15, 4, r2, c14, c1, 0 @ CNTHCTL +.endm + /* Configures the HSTR (Hyp System Trap Register) on entry/return * (hardware reset value is 0) */ .macro set_hstr entry