From patchwork Thu May 30 14:38:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 17304 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f198.google.com (mail-ve0-f198.google.com [209.85.128.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6581325C6D for ; Thu, 30 May 2013 14:39:08 +0000 (UTC) Received: by mail-ve0-f198.google.com with SMTP id jz10sf393803veb.1 for ; Thu, 30 May 2013 07:39:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=7QqHuiJt97p0WNAuQp7FynOpuSZFG86fytjQmNiTxI4=; b=kB5e2FmMRc+30T1kWI7xNKkeLHGiuPw6zN3kb+ZXIdTM6fBvw7PnKekn0JdE1arQE4 Fuzkr5DBXlsBh4hsyl/DoaelEd9Ep1UzN3+PA34M86S2GT2deBc8zEXwlDPQOFd5my5+ /sIpGhy9gXdaHcGlXNwxnlmGqHb3pym2T27mkIXVHcouTjH/jnbsAQSGtuk2psyBUq1b Mmp7OP76YkVzlCgOP+hbNaeV697QDTWfFyJnONBiuxQLOI5w0xugH4nQqpnWmTy+TsbV 7YaHaOGWAS8DSmgqRU6HD8Ajqfz1yEAI2+PE7sb4EuTGBFz5CdjNZzpIMBXDm2pjzZ3M WZrA== X-Received: by 10.224.42.141 with SMTP id s13mr4403996qae.3.1369924747842; Thu, 30 May 2013 07:39:07 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.119.129 with SMTP id ku1ls445717qeb.49.gmail; Thu, 30 May 2013 07:39:07 -0700 (PDT) X-Received: by 10.220.167.69 with SMTP id p5mr5714462vcy.57.1369924747598; Thu, 30 May 2013 07:39:07 -0700 (PDT) Received: from mail-ve0-x236.google.com (mail-ve0-x236.google.com [2607:f8b0:400c:c01::236]) by mx.google.com with ESMTPS id w7si25026352vci.49.2013.05.30.07.39.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 May 2013 07:39:07 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::236 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c01::236; Received: by mail-ve0-f182.google.com with SMTP id ox1so239693veb.27 for ; Thu, 30 May 2013 07:39:07 -0700 (PDT) X-Received: by 10.220.10.212 with SMTP id q20mr5875954vcq.9.1369924747459; Thu, 30 May 2013 07:39:07 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.229.199 with SMTP id jj7csp10780vcb; Thu, 30 May 2013 07:39:06 -0700 (PDT) X-Received: by 10.180.108.168 with SMTP id hl8mr4994442wib.23.1369924746315; Thu, 30 May 2013 07:39:06 -0700 (PDT) Received: from mail-wg0-x234.google.com (mail-wg0-x234.google.com [2a00:1450:400c:c00::234]) by mx.google.com with ESMTPS id l8si8477286wjb.16.2013.05.30.07.39.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 May 2013 07:39:06 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c00::234 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=2a00:1450:400c:c00::234; Received: by mail-wg0-f52.google.com with SMTP id z11so311433wgg.7 for ; Thu, 30 May 2013 07:39:06 -0700 (PDT) X-Received: by 10.180.37.133 with SMTP id y5mr5042309wij.20.1369924745914; Thu, 30 May 2013 07:39:05 -0700 (PDT) Received: from belegaer.uk.xensource.com. (firewall.ctxuk.citrix.com. [46.33.159.2]) by mx.google.com with ESMTPSA id ff10sm38403857wib.10.2013.05.30.07.39.04 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 May 2013 07:39:05 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Cc: Stefano.Stabellini@eu.citrix.com, ian.campbell@citrix.com, tim@xen.org, patches@linaro.org, Julien Grall Subject: [PATCH 1/2] xen/arm32: implement VFP context switch Date: Thu, 30 May 2013 15:38:52 +0100 Message-Id: <1369924733-18701-2-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1369924733-18701-1-git-send-email-julien.grall@linaro.org> References: <1369924733-18701-1-git-send-email-julien.grall@linaro.org> X-Gm-Message-State: ALoCoQnBsO68vt/hCEsRsVxkGrgEhlo+mrCGKKFIssHsUcTs+vQ4HdWEp8Ze3rnwJJNPAa5bKRkK X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::236 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 Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add support for VFP context switch on arm32 and a dummy support for arm64 Signed-off-by: Julien Grall --- xen/arch/arm/arm32/Makefile | 1 + xen/arch/arm/arm32/vfp.c | 71 +++++++++++++++++++++++++++++++++++++++ xen/arch/arm/arm64/Makefile | 1 + xen/arch/arm/arm64/vfp.c | 13 +++++++ xen/arch/arm/domain.c | 7 ++-- xen/include/asm-arm/arm32/vfp.h | 29 ++++++++++++++++ xen/include/asm-arm/arm64/vfp.h | 16 +++++++++ xen/include/asm-arm/cpregs.h | 7 ++++ xen/include/asm-arm/domain.h | 5 +++ xen/include/asm-arm/vfp.h | 10 ++++++ 10 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 xen/arch/arm/arm32/vfp.c create mode 100644 xen/arch/arm/arm64/vfp.c create mode 100644 xen/include/asm-arm/arm32/vfp.h create mode 100644 xen/include/asm-arm/arm64/vfp.h diff --git a/xen/arch/arm/arm32/Makefile b/xen/arch/arm/arm32/Makefile index aaf277a..b903803 100644 --- a/xen/arch/arm/arm32/Makefile +++ b/xen/arch/arm/arm32/Makefile @@ -6,5 +6,6 @@ obj-y += proc-ca15.o obj-y += traps.o obj-y += domain.o +obj-y += vfp.o obj-$(EARLY_PRINTK) += debug.o diff --git a/xen/arch/arm/arm32/vfp.c b/xen/arch/arm/arm32/vfp.c new file mode 100644 index 0000000..16f635a --- /dev/null +++ b/xen/arch/arm/arm32/vfp.c @@ -0,0 +1,71 @@ +#include +#include +#include + +void vfp_save_state(struct vcpu *v) +{ + uint32_t tmp; + + v->arch.vfp.fpexc = READ_CP32(FPEXC); + + WRITE_CP32(v->arch.vfp.fpexc | FPEXC_EN, FPEXC); + + v->arch.vfp.fpscr = READ_CP32(FPSCR); + + if ( v->arch.vfp.fpexc & FPEXC_EX ) /* Check for sub-architecture */ + { + v->arch.vfp.fpinst = READ_CP32(FPINST); + + if ( v->arch.vfp.fpexc & FPEXC_FP2V ) + v->arch.vfp.fpinst2 = READ_CP32(FPINST2); + /* Disable FPEXC_EX */ + WRITE_CP32((v->arch.vfp.fpexc | FPEXC_EN) & ~FPEXC_EX, FPEXC); + } + + /* Save {d0-d15} */ + asm volatile("stc p11, cr0, [%0], #32*4" : : "r" (v->arch.vfp.fpregs1)); + + tmp = READ_CP32(MVFR0); + if ( (tmp & MVFR0_A_SIMD_MASK) == 2 ) /* 32 x 64 bits registers */ + { + /* Save {d16-d31} */ + asm volatile("stcl p11, cr0, [%0], #32*4" : : "r" (v->arch.vfp.fpregs2)); + } + + WRITE_CP32(v->arch.vfp.fpexc & ~(FPEXC_EN), FPEXC); +} + +void vfp_restore_state(struct vcpu *v) +{ + uint32_t tmp = READ_CP32(FPEXC); + + WRITE_CP32(tmp | FPEXC_EN, FPEXC); + + /* Restore {d0-d15} */ + asm volatile("ldc p11, cr0, [%0], #32*4" : : "r" (v->arch.vfp.fpregs1)); + + tmp = READ_CP32(MVFR0); + if ( (tmp & MVFR0_A_SIMD_MASK) == 2 ) /* 32 x 64 bits registers */ + /* Restore {d16-d31} */ + asm volatile("ldcl p11, cr0, [%0], #32*4" : : "r" (v->arch.vfp.fpregs2)); + + if ( v->arch.vfp.fpexc & FPEXC_EX ) + { + WRITE_CP32(v->arch.vfp.fpinst, FPINST); + if ( v->arch.vfp.fpexc & FPEXC_FP2V ) + WRITE_CP32(v->arch.vfp.fpinst2, FPINST2); + } + + WRITE_CP32(v->arch.vfp.fpscr, FPSCR); + + WRITE_CP32(v->arch.vfp.fpexc, FPEXC); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/arm64/Makefile b/xen/arch/arm/arm64/Makefile index 9484548..e06a0a9 100644 --- a/xen/arch/arm/arm64/Makefile +++ b/xen/arch/arm/arm64/Makefile @@ -5,5 +5,6 @@ obj-y += mode_switch.o obj-y += traps.o obj-y += domain.o +obj-y += vfp.o obj-$(EARLY_PRINTK) += debug.o diff --git a/xen/arch/arm/arm64/vfp.c b/xen/arch/arm/arm64/vfp.c new file mode 100644 index 0000000..74e6a50 --- /dev/null +++ b/xen/arch/arm/arm64/vfp.c @@ -0,0 +1,13 @@ +#include +#include +#include + +void vfp_save_state(struct vcpu *v) +{ + /* TODO: implement it */ +} + +void vfp_restore_state(struct vcpu *v) +{ + /* TODO: implement it */ +} diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 4c434a1..f465ab7 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include "vtimer.h" @@ -117,7 +118,8 @@ static void ctxt_switch_from(struct vcpu *p) /* XXX MPU */ - /* XXX VFP */ + /* VFP */ + vfp_save_state(p); /* VGIC */ gic_save_state(p); @@ -143,7 +145,8 @@ static void ctxt_switch_to(struct vcpu *n) /* VGIC */ gic_restore_state(n); - /* XXX VFP */ + /* VFP */ + vfp_restore_state(n); /* XXX MPU */ diff --git a/xen/include/asm-arm/arm32/vfp.h b/xen/include/asm-arm/arm32/vfp.h new file mode 100644 index 0000000..c32296e --- /dev/null +++ b/xen/include/asm-arm/arm32/vfp.h @@ -0,0 +1,29 @@ +#ifndef _ARM_ARM32_VFP_H +#define _ARM_ARM32_VFP_H + +#define FPEXC_EX (1u << 31) +#define FPEXC_EN (1u << 30) +#define FPEXC_FP2V (1u << 28) + +#define MVFR0_A_SIMD_MASK (0xf << 0) + +struct vfp_state +{ + uint64_t fpregs1[16]; /* {d0-d15} */ + uint64_t fpregs2[16]; /* {d16-d31} */ + uint32_t fpexc; + uint32_t fpscr; + /* VFP implementation specific state */ + uint32_t fpinst; + uint32_t fpinst2; +}; + +#endif /* _ARM_ARM32_VFP_H */ +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/asm-arm/arm64/vfp.h b/xen/include/asm-arm/arm64/vfp.h new file mode 100644 index 0000000..34cd202 --- /dev/null +++ b/xen/include/asm-arm/arm64/vfp.h @@ -0,0 +1,16 @@ +#ifndef _ARM_ARM64_VFP_H +#define _ARM_ARM32_VFP_H + +struct vfp_state +{ +}; + +#endif /* _ARM_ARM32_VFP_H */ +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/asm-arm/cpregs.h b/xen/include/asm-arm/cpregs.h index f08d59a..d99ccfd 100644 --- a/xen/include/asm-arm/cpregs.h +++ b/xen/include/asm-arm/cpregs.h @@ -60,6 +60,12 @@ * arguments, which are cp,opc1,crn,crm,opc2. */ +#define FPSCR p10,7,c1,c0,0 /* Floating-Point Status and Control Register */ +#define MVFR0 p10,7,c7,c0,0 /* Media and VFP Feature Register 0 */ +#define FPEXC p10,7,c8,c0,0 /* Floating-Point Exception Control Register */ +#define FPINST p10,7,c9,c0,0 /* Floating-Point Instruction Register */ +#define FPINST2 p10,7,c10,c0,0 /* Floating-point Instruction Register 2 */ + /* Coprocessor 14 */ /* CP14 CR0: */ @@ -106,6 +112,7 @@ #define NSACR p15,0,c1,c1,2 /* Non-Secure Access Control Register */ #define HSCTLR p15,4,c1,c0,0 /* Hyp. System Control Register */ #define HCR p15,4,c1,c1,0 /* Hyp. Configuration Register */ +#define HCPTR p15,4,c1,c1,2 /* Hyp. Coprocessor Trap Register */ /* CP15 CR2: Translation Table Base and Control Registers */ #define TTBCR p15,0,c2,c0,2 /* Translatation Table Base Control Register */ diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index cb251cc..6b52b5e 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -1,11 +1,13 @@ #ifndef __ASM_DOMAIN_H__ #define __ASM_DOMAIN_H__ +#include #include #include #include #include #include +#include #include /* Represents state corresponding to a block of 32 interrupts */ @@ -188,6 +190,9 @@ struct arch_vcpu uint32_t joscr, jmcr; #endif + /* Float-pointer */ + struct vfp_state vfp; + /* CP 15 */ uint32_t csselr; diff --git a/xen/include/asm-arm/vfp.h b/xen/include/asm-arm/vfp.h index b800816..6ba3cd1 100644 --- a/xen/include/asm-arm/vfp.h +++ b/xen/include/asm-arm/vfp.h @@ -2,7 +2,14 @@ #define __ARM_VFP_H_ #include +#include +#if defined(CONFIG_ARM_32) +# include +#elif defined(CONFIG_ARM_64) +# include +# error "Unknown ARM variant" +#endif #ifdef CONFIG_ARM_32 @@ -32,6 +39,9 @@ static inline void enable_vfp(void) } #endif +void vfp_save_state(struct vcpu *v); +void vfp_restore_state(struct vcpu *v); + #endif /* * Local variables: