]>
Commit | Line | Data |
---|---|---|
bd3239d2 MF |
1 | int cpu_has(unsigned short bit) |
2 | { | |
3 | asm goto ("1: jmp %l[t_no]\n" "2:\n" ".section .altinstructions,\"a\"\n" | |
4 | ".balign 4\n" ".long 1b\n" ".long 0\n" ".word %P0\n" ".byte 2b - 1b\n" ".byte 0\n" | |
5 | ".previous\n"::"i" (bit)::t_no); | |
6 | return 1; | |
7 | t_no:return 0; | |
8 | } | |
9 | ||
10 | struct cpuinfo_x86 { | |
11 | unsigned int x86_capability[10]; | |
12 | }; | |
13 | extern struct cpuinfo_x86 boot_cpu_data; | |
14 | struct i387_fxsave_struct { | |
15 | unsigned short swd; | |
16 | }; | |
17 | union thread_xstate { | |
18 | struct i387_fxsave_struct fxsave; | |
19 | int xstate_bv; | |
20 | }; | |
21 | struct fpu { | |
22 | union thread_xstate *state; | |
23 | }; | |
24 | __attribute__ ((always_inline)) __attribute__ ((pure)) | |
25 | int use_xsave(void) | |
26 | { | |
27 | return cpu_has(154); | |
28 | } | |
29 | ||
30 | __attribute__ ((always_inline)) __attribute__ ((pure)) | |
31 | int use_fxsr(void) | |
32 | { | |
33 | return cpu_has(24); | |
34 | } | |
35 | __attribute__ ((always_inline)) | |
36 | void fpu_save_init(struct fpu *fpu) | |
37 | { | |
38 | if (__builtin_constant_p(use_xsave())? use_xsave() : use_xsave()) { | |
39 | if (fpu->state-> | |
40 | xstate_bv) | |
41 | return; | |
42 | } else if (use_fxsr()) { | |
43 | } | |
44 | if (__builtin_constant_p( | |
45 | (((__builtin_constant_p(fpu->state->fxsave.swd & 1) ? | |
46 | ! !(fpu->state->fxsave.swd & 1) : | |
47 | __builtin_expect(! ! | |
48 | (fpu-> | |
49 | state-> | |
50 | fxsave. | |
51 | swd | |
52 | & (1 | |
53 | << | |
54 | 7)), | |
55 | 1) | |
56 | ))))? | |
57 | ! !(((__builtin_constant_p(fpu->state->fxsave.swd & 1) ? | |
58 | ! !(fpu->state->fxsave.swd & 1) : | |
59 | __builtin_expect(! ! | |
60 | (fpu-> | |
61 | state-> | |
62 | fxsave. | |
63 | swd | |
64 | & | |
65 | (1 | |
66 | << | |
67 | 7)), | |
68 | 1) | |
69 | ))): | |
70 | ||
71 | ! !(((__builtin_constant_p(fpu->state->fxsave.swd & 1) | |
72 | ? ! !(fpu->state->fxsave.swd & 1) : | |
73 | ||
74 | __builtin_expect | |
75 | (! ! | |
76 | (fpu-> | |
77 | state-> | |
78 | fxsave. | |
79 | swd & (1 | |
80 | << | |
81 | 7)), | |
82 | 1) | |
83 | ))) | |
84 | ) | |
85 | asm volatile ("fnclex"); | |
86 | } | |
87 | ||
88 | void aes_decrypt(void) | |
89 | { | |
90 | if (irq_fpu_usable()) | |
91 | crypto_aes_decrypt_x86(); | |
92 | else | |
93 | fpu_save_init(0); | |
94 | } | |
95 | ||
96 | void (*funcptr)(void) = aes_decrypt; | |
97 | ||
98 | int aesni_init(void) | |
99 | { | |
100 | if (crypto_register_alg()) | |
101 | crypto_unregister_alg(0); | |
102 | } |