-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
x86, xsave: enable xsave/xrstor on cpus with xsave support
Enables xsave/xrstor by turning on cr4.osxsave on cpu's which have the xsave support. For now, features that OS supports/enabled are FP and SSE. Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com> Signed-off-by: H. Peter Anvin <hpa@zytor.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
- Loading branch information
Suresh Siddha
authored and
Ingo Molnar
committed
Jul 30, 2008
1 parent
a648bf4
commit dc1e35c
Showing
10 changed files
with
148 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* xsave/xrstor support. | ||
* | ||
* Author: Suresh Siddha <suresh.b.siddha@intel.com> | ||
*/ | ||
#include <linux/bootmem.h> | ||
#include <linux/compat.h> | ||
#include <asm/i387.h> | ||
|
||
/* | ||
* Supported feature mask by the CPU and the kernel. | ||
*/ | ||
unsigned int pcntxt_hmask, pcntxt_lmask; | ||
|
||
/* | ||
* Represents init state for the supported extended state. | ||
*/ | ||
struct xsave_struct *init_xstate_buf; | ||
|
||
/* | ||
* Enable the extended processor state save/restore feature | ||
*/ | ||
void __cpuinit xsave_init(void) | ||
{ | ||
if (!cpu_has_xsave) | ||
return; | ||
|
||
set_in_cr4(X86_CR4_OSXSAVE); | ||
|
||
/* | ||
* Enable all the features that the HW is capable of | ||
* and the Linux kernel is aware of. | ||
* | ||
* xsetbv(); | ||
*/ | ||
asm volatile(".byte 0x0f,0x01,0xd1" : : "c" (0), | ||
"a" (pcntxt_lmask), "d" (pcntxt_hmask)); | ||
} | ||
|
||
/* | ||
* setup the xstate image representing the init state | ||
*/ | ||
void setup_xstate_init(void) | ||
{ | ||
init_xstate_buf = alloc_bootmem(xstate_size); | ||
init_xstate_buf->i387.mxcsr = MXCSR_DEFAULT; | ||
} | ||
|
||
/* | ||
* Enable and initialize the xsave feature. | ||
*/ | ||
void __init xsave_cntxt_init(void) | ||
{ | ||
unsigned int eax, ebx, ecx, edx; | ||
|
||
cpuid_count(0xd, 0, &eax, &ebx, &ecx, &edx); | ||
|
||
pcntxt_lmask = eax; | ||
pcntxt_hmask = edx; | ||
|
||
if ((pcntxt_lmask & XSTATE_FPSSE) != XSTATE_FPSSE) { | ||
printk(KERN_ERR "FP/SSE not shown under xsave features %x\n", | ||
pcntxt_lmask); | ||
BUG(); | ||
} | ||
|
||
/* | ||
* for now OS knows only about FP/SSE | ||
*/ | ||
pcntxt_lmask = pcntxt_lmask & XCNTXT_LMASK; | ||
pcntxt_hmask = pcntxt_hmask & XCNTXT_HMASK; | ||
|
||
xsave_init(); | ||
|
||
/* | ||
* Recompute the context size for enabled features | ||
*/ | ||
cpuid_count(0xd, 0, &eax, &ebx, &ecx, &edx); | ||
|
||
xstate_size = ebx; | ||
|
||
setup_xstate_init(); | ||
|
||
printk(KERN_INFO "xsave/xrstor: enabled xstate_bv 0x%Lx, " | ||
"cntxt size 0x%x\n", | ||
(pcntxt_lmask | ((u64) pcntxt_hmask << 32)), xstate_size); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef __ASM_X86_XSAVE_H | ||
#define __ASM_X86_XSAVE_H | ||
|
||
#include <asm/processor.h> | ||
#include <asm/i387.h> | ||
|
||
#define XSTATE_FP 0x1 | ||
#define XSTATE_SSE 0x2 | ||
|
||
#define XSTATE_FPSSE (XSTATE_FP | XSTATE_SSE) | ||
|
||
#define FXSAVE_SIZE 512 | ||
|
||
/* | ||
* These are the features that the OS can handle currently. | ||
*/ | ||
#define XCNTXT_LMASK (XSTATE_FP | XSTATE_SSE) | ||
#define XCNTXT_HMASK 0x0 | ||
|
||
extern unsigned int xstate_size, pcntxt_hmask, pcntxt_lmask; | ||
extern struct xsave_struct *init_xstate_buf; | ||
|
||
extern void xsave_cntxt_init(void); | ||
extern void xsave_init(void); | ||
|
||
#endif |