From patchwork Wed Mar 19 15:43:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 26590 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yk0-f199.google.com (mail-yk0-f199.google.com [209.85.160.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E85BB203C3 for ; Wed, 19 Mar 2014 15:46:40 +0000 (UTC) Received: by mail-yk0-f199.google.com with SMTP id 200sf48051118ykr.2 for ; Wed, 19 Mar 2014 08:46:40 -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:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=PjwSXjRN5bFip6F0xFR+0NwD6c1h57PPNTwmf0Mqyyc=; b=R02A+cVrxoTOH7a5M9P81juColNMGsLPMdc8YXVD7FeDw8Ys325iDh5SGSYzMeQZV1 4dN7vtxU330XHXTDEBsf3G+vb7+4wTeVSusr7Zv5ibeK3EyFUshm0J5kHXDUohOZLOJT ianjH5KZVDmTkoPEv/m5O0xQVHHNRXyQbBBRO1kyoE6h0MLyLmQmz2TUJdRaC6hrncDm G+JT7s0vnWw5uQ3VN3TAO++z7KcAJE5xLVxA3DyaFgioOPAl8w4eJFLDYLyEhsNH4ENW DhHu1Q6vbZqM+mah8E/l8TNXwgunGq3NRh5yOYa2dES7c6iqvHF+bHbziGEySDRwb44g a14Q== X-Gm-Message-State: ALoCoQmfCMbX2whgiwlvgIbA3RZ3P1C8dnDIq0gmxqRwYcZdduqc7LBCCH1AK9xyrcD5LLq0/XW+ X-Received: by 10.236.179.66 with SMTP id g42mr13664074yhm.17.1395244000684; Wed, 19 Mar 2014 08:46:40 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.95.66 with SMTP id h60ls1136544qge.54.gmail; Wed, 19 Mar 2014 08:46:40 -0700 (PDT) X-Received: by 10.58.8.8 with SMTP id n8mr1881495vea.23.1395244000517; Wed, 19 Mar 2014 08:46:40 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id lz6si7836326vcb.31.2014.03.19.08.46.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Mar 2014 08:46:40 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id ks9so9495838vcb.13 for ; Wed, 19 Mar 2014 08:46:40 -0700 (PDT) X-Received: by 10.52.237.167 with SMTP id vd7mr109879vdc.54.1395244000429; Wed, 19 Mar 2014 08:46:40 -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.220.78.9 with SMTP id i9csp310881vck; Wed, 19 Mar 2014 08:46:39 -0700 (PDT) X-Received: by 10.229.136.135 with SMTP id r7mr20808013qct.17.1395243999671; Wed, 19 Mar 2014 08:46:39 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id eo2si5762919qcb.53.2014.03.19.08.46.39 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 19 Mar 2014 08:46:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xen.org designates 50.57.142.19 as permitted sender) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WQIf9-0002PK-Lu; Wed, 19 Mar 2014 15:44:15 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WQIf7-0002Om-UG for xen-devel@lists.xenproject.org; Wed, 19 Mar 2014 15:44:14 +0000 Received: from [193.109.254.147:40299] by server-13.bemta-14.messagelabs.com id 97/78-23211-D4BB9235; Wed, 19 Mar 2014 15:44:13 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-6.tower-27.messagelabs.com!1395243852!2794951!1 X-Originating-IP: [74.125.83.46] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 12367 invoked from network); 19 Mar 2014 15:44:12 -0000 Received: from mail-ee0-f46.google.com (HELO mail-ee0-f46.google.com) (74.125.83.46) by server-6.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 19 Mar 2014 15:44:12 -0000 Received: by mail-ee0-f46.google.com with SMTP id t10so6651582eei.5 for ; Wed, 19 Mar 2014 08:44:12 -0700 (PDT) X-Received: by 10.14.94.5 with SMTP id m5mr3795822eef.23.1395243851934; Wed, 19 Mar 2014 08:44:11 -0700 (PDT) Received: from belegaer.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id w6sm55426496eex.9.2014.03.19.08.44.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Mar 2014 08:44:11 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 19 Mar 2014 15:43:37 +0000 Message-Id: <1395243819-30380-2-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1395243819-30380-1-git-send-email-julien.grall@linaro.org> References: <1395243819-30380-1-git-send-email-julien.grall@linaro.org> Cc: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com Subject: [Xen-devel] [PATCH 1/3] xen/arm: Move p2m context save/restore in a separate function X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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 List-Archive: Introduce p2m_{save,restore}_state to save/restore p2m context. The both functions will take care of: - VTTBR: contains the pointer to the domain P2M - Update HCR_RW if the domain is 64 bit - SCTLR: contains bit to know if the MMU is enabled or not Signed-off-by: Julien Grall --- xen/arch/arm/domain.c | 21 +++------------------ xen/arch/arm/p2m.c | 28 ++++++++++++++++++++++++++++ xen/include/asm-arm/p2m.h | 4 ++++ 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 46ee486..b125857 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -59,11 +59,12 @@ void idle_loop(void) static void ctxt_switch_from(struct vcpu *p) { + p2m_save_state(p); + /* CP 15 */ p->arch.csselr = READ_SYSREG(CSSELR_EL1); /* Control Registers */ - p->arch.sctlr = READ_SYSREG(SCTLR_EL1); p->arch.cpacr = READ_SYSREG(CPACR_EL1); p->arch.contextidr = READ_SYSREG(CONTEXTIDR_EL1); @@ -134,14 +135,7 @@ static void ctxt_switch_from(struct vcpu *p) static void ctxt_switch_to(struct vcpu *n) { - register_t hcr; - - hcr = READ_SYSREG(HCR_EL2); - WRITE_SYSREG(hcr & ~HCR_VM, HCR_EL2); - isb(); - - p2m_load_VTTBR(n->domain); - isb(); + p2m_restore_state(n); WRITE_SYSREG32(n->domain->arch.vpidr, VPIDR_EL2); WRITE_SYSREG(n->arch.vmpidr, VMPIDR_EL2); @@ -189,7 +183,6 @@ static void ctxt_switch_to(struct vcpu *n) isb(); /* Control Registers */ - WRITE_SYSREG(n->arch.sctlr, SCTLR_EL1); WRITE_SYSREG(n->arch.cpacr, CPACR_EL1); WRITE_SYSREG(n->arch.contextidr, CONTEXTIDR_EL1); @@ -214,14 +207,6 @@ static void ctxt_switch_to(struct vcpu *n) isb(); - if ( is_32bit_domain(n->domain) ) - hcr &= ~HCR_RW; - else - hcr |= HCR_RW; - - WRITE_SYSREG(hcr, HCR_EL2); - isb(); - /* This is could trigger an hardware interrupt from the virtual * timer. The interrupt needs to be injected into the guest. */ virt_timer_restore(n); diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index b9d8ca6..979fe5b 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -44,6 +44,34 @@ void p2m_load_VTTBR(struct domain *d) isb(); /* Ensure update is visible */ } +void p2m_save_state(struct vcpu *p) +{ + p->arch.sctlr = READ_SYSREG(SCTLR_EL1); +} + +void p2m_restore_state(struct vcpu *n) +{ + register_t hcr; + + hcr = READ_SYSREG(HCR_EL2); + WRITE_SYSREG(hcr & ~HCR_VM, HCR_EL2); + isb(); + + p2m_load_VTTBR(n->domain); + isb(); + + if ( is_32bit_domain(n->domain) ) + hcr &= ~HCR_RW; + else + hcr |= HCR_RW; + + WRITE_SYSREG(n->arch.sctlr, SCTLR_EL1); + isb(); + + WRITE_SYSREG(hcr, HCR_EL2); + isb(); +} + static int p2m_first_level_index(paddr_t addr) { /* diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index 3b39c45..e1013c8 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -75,6 +75,10 @@ int p2m_alloc_table(struct domain *d); /* */ void p2m_load_VTTBR(struct domain *d); +/* Context switch */ +void p2m_save_state(struct vcpu *p); +void p2m_restore_state(struct vcpu *n); + /* Look up the MFN corresponding to a domain's PFN. */ paddr_t p2m_lookup(struct domain *d, paddr_t gpfn, p2m_type_t *t);