diff options
author | Wei Huang <wei.huang2@amd.com> | 2011-05-09 11:37:36 +0100 |
---|---|---|
committer | Wei Huang <wei.huang2@amd.com> | 2011-05-09 11:37:36 +0100 |
commit | fb48379fc38ea90ccf58b126c8817baa17eea661 (patch) | |
tree | 2a9827a0ee0f252ffd6e7d13d0dee0cb7ace9984 | |
parent | e39609c4502b7abab4133f77587084047a6c3e79 (diff) | |
download | xen-fb48379fc38ea90ccf58b126c8817baa17eea661.tar.gz xen-fb48379fc38ea90ccf58b126c8817baa17eea661.tar.bz2 xen-fb48379fc38ea90ccf58b126c8817baa17eea661.zip |
x86/fpu: create FPU init and destroy functions
Extract FPU initialization and destroy code into two functions. These
functions handle memory allocation/deallocation for FPU context.
Signed-off-by: Wei Huang <wei.huang2@amd.com>
-rw-r--r-- | xen/arch/x86/domain.c | 25 | ||||
-rw-r--r-- | xen/arch/x86/i387.c | 41 | ||||
-rw-r--r-- | xen/include/asm-x86/i387.h | 2 |
3 files changed, 47 insertions, 21 deletions
diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 56031c3db4..538d497306 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -420,20 +420,8 @@ int vcpu_initialise(struct vcpu *v) v->arch.perdomain_ptes = perdomain_ptes(d, v); - if ( (rc = xstate_alloc_save_area(v)) != 0 ) + if ( (rc = vcpu_init_fpu(v)) != 0 ) return rc; - if ( v->arch.xsave_area ) - v->arch.fpu_ctxt = &v->arch.xsave_area->fpu_sse; - else if ( !is_idle_domain(d) ) - { - v->arch.fpu_ctxt = _xmalloc(sizeof(v->arch.xsave_area->fpu_sse), 16); - if ( !v->arch.fpu_ctxt ) - { - rc = -ENOMEM; - goto done; - } - memset(v->arch.fpu_ctxt, 0, sizeof(v->arch.xsave_area->fpu_sse)); - } if ( is_hvm_domain(d) ) { @@ -485,10 +473,8 @@ int vcpu_initialise(struct vcpu *v) done: if ( rc ) { - if ( v->arch.xsave_area ) - xstate_free_save_area(v); - else - xfree(v->arch.fpu_ctxt); + vcpu_destroy_fpu(v); + if ( !is_hvm_domain(d) && standalone_trap_ctxt(v) ) free_xenheap_page(v->arch.pv_vcpu.trap_ctxt); } @@ -501,10 +487,7 @@ void vcpu_destroy(struct vcpu *v) if ( is_pv_32on64_vcpu(v) ) release_compat_l4(v); - if ( v->arch.xsave_area ) - xstate_free_save_area(v); - else - xfree(v->arch.fpu_ctxt); + vcpu_destroy_fpu(v); if ( is_hvm_vcpu(v) ) hvm_vcpu_destroy(v); diff --git a/xen/arch/x86/i387.c b/xen/arch/x86/i387.c index c04eadc721..255e1e51dd 100644 --- a/xen/arch/x86/i387.c +++ b/xen/arch/x86/i387.c @@ -184,6 +184,47 @@ static void restore_fpu(struct vcpu *v) } } +/*******************************/ +/* VCPU FPU Functions */ +/*******************************/ +/* Initialize FPU's context save area */ +int vcpu_init_fpu(struct vcpu *v) +{ + int rc = 0; + + /* Idle domain doesn't have FPU state allocated */ + if ( is_idle_vcpu(v) ) + goto done; + + if ( (rc = xstate_alloc_save_area(v)) != 0 ) + return rc; + + if ( v->arch.xsave_area ) + v->arch.fpu_ctxt = &v->arch.xsave_area->fpu_sse; + else + { + v->arch.fpu_ctxt = _xmalloc(sizeof(v->arch.xsave_area->fpu_sse), 16); + if ( !v->arch.fpu_ctxt ) + { + rc = -ENOMEM; + goto done; + } + memset(v->arch.fpu_ctxt, 0, sizeof(v->arch.xsave_area->fpu_sse)); + } + +done: + return rc; +} + +/* Free FPU's context save area */ +void vcpu_destroy_fpu(struct vcpu *v) +{ + if ( v->arch.xsave_area ) + xstate_free_save_area(v); + else + xfree(v->arch.fpu_ctxt); +} + /* * Local variables: * mode: C diff --git a/xen/include/asm-x86/i387.h b/xen/include/asm-x86/i387.h index f94cdad6f6..f2bd78d680 100644 --- a/xen/include/asm-x86/i387.h +++ b/xen/include/asm-x86/i387.h @@ -17,4 +17,6 @@ void setup_fpu(struct vcpu *v); void save_init_fpu(struct vcpu *v); +int vcpu_init_fpu(struct vcpu *v); +void vcpu_destroy_fpu(struct vcpu *v); #endif /* __ASM_I386_I387_H */ |