]>
Commit | Line | Data |
---|---|---|
bd3239d2 MF |
1 | struct list_head { |
2 | }; | |
3 | int __static_cpu_has(unsigned short bit) | |
4 | { | |
5 | asm goto ("1: jmp %l[t_no]\n" "2:\n" ".section .altinstructions,\"a\"\n" | |
6 | " " ".balign 4" " " "\n" " " ".long" " " "1b\n" " " ".long" | |
7 | " " "0\n" " .word %P0\n" " .byte 2b - 1b\n" " .byte 0\n" | |
8 | ".previous\n"::"i" (bit)::t_no); | |
9 | return 1; | |
10 | t_no:return 0; | |
11 | } | |
12 | ||
13 | struct cpuinfo_x86 { | |
14 | unsigned int x86_capability[10]; | |
15 | } __attribute__ ((__aligned__((1 << (6))))); | |
16 | extern struct cpuinfo_x86 boot_cpu_data; | |
17 | struct i387_fxsave_struct { | |
18 | unsigned short swd; | |
19 | } __attribute__ ((aligned(16))); | |
20 | struct xsave_hdr_struct { | |
21 | unsigned long long xstate_bv; | |
22 | } __attribute__ ((packed)); | |
23 | struct xsave_struct { | |
24 | struct xsave_hdr_struct xsave_hdr; | |
25 | } __attribute__ ((packed, aligned(64))); | |
26 | union thread_xstate { | |
27 | struct i387_fxsave_struct fxsave; | |
28 | struct xsave_struct xsave; | |
29 | }; | |
30 | struct fpu { | |
31 | union thread_xstate *state; | |
32 | }; | |
33 | struct cipher_alg { | |
34 | void (*cia_decrypt) (struct crypto_tfm * tfm, unsigned char *dst, | |
35 | const unsigned char *src); | |
36 | }; | |
37 | struct crypto_alg { | |
38 | struct list_head cra_list; | |
39 | union { | |
40 | struct cipher_alg cipher; | |
41 | } cra_u; | |
42 | }; | |
43 | static __attribute__ ((always_inline)) __attribute__ ((pure)) | |
44 | int use_xsave(void) | |
45 | { | |
46 | return __builtin_constant_p(constant_test_bit(154, (unsigned long *)((&boot_cpu_data)->x86_capability))) | |
47 | ? | |
48 | ( | |
49 | ( | |
50 | __builtin_constant_p(((154))) ? constant_test_bit(((154)), ((unsigned long *)((&boot_cpu_data)->x86_capability))) | |
51 | : variable_test_bit(((154)), ((unsigned long *)((&boot_cpu_data)->x86_capability))))) | |
52 | : __builtin_constant_p((154)) ? __static_cpu_has((154)) : (__builtin_constant_p((154)) && (((4) == 0 && (1UL << (26) & ((1 << (0 & 31)) | (1 << ((6) & 31)) | (1 << ((8) & 31)) | (1 << ((15) & 31)) | 0))) || ((4) == 1 && (1UL << (26) & 0)) || ((4) == 2 && (1UL << (26) & 0)) || ((4) == 3 && (1UL << (26) & 0)) || ((4) == 4 && (1UL << (26) & 0)) || ((4) == 5 && (1UL << (26) & 0)) || ((4) == 6 && (1UL << (26) & 0)) || ((4) == 7 && (1UL << (26) & 0)) || ((4) == 8 && (1UL << (26) & 0)) || ((4) == 9 && (1UL << (26) & 0))) ? 1 : (__builtin_constant_p(((154))) ? constant_test_bit(((154)), ((unsigned long *)((&boot_cpu_data)->x86_capability))) : variable_test_bit(((154)), ((unsigned long *)((&boot_cpu_data)->x86_capability)))) | |
53 | ); | |
54 | } | |
55 | ||
56 | static inline __attribute__ ((always_inline)) __attribute__ ((always_inline)) | |
57 | __attribute__ ((pure)) | |
58 | int use_fxsr(void) | |
59 | { | |
60 | return __builtin_constant_p | |
61 | (variable_test_bit(24, (unsigned long *)((&boot_cpu_data)->x86_capability))) | |
62 | ? | |
63 | variable_test_bit(24, (unsigned long *)((&boot_cpu_data)->x86_capability)) : | |
64 | __static_cpu_has(24) | |
65 | ; | |
66 | } | |
67 | ||
68 | static inline __attribute__ ((always_inline)) | |
69 | void fpu_save_init(struct fpu *fpu) | |
70 | { | |
71 | if (__builtin_constant_p(use_xsave())? use_xsave() : use_xsave()) { | |
72 | if (__builtin_constant_p | |
73 | (((!(fpu->state->xsave.xsave_hdr. | |
74 | xstate_bv & 0x1)))) ? ! !((!(fpu->state->xsave. | |
75 | xsave_hdr. | |
76 | xstate_bv & 0x1))) : ( { | |
77 | ! !((!(fpu->state->xsave.xsave_hdr.xstate_bv & 0x1)));} | |
78 | )) | |
79 | return; | |
80 | } else if (use_fxsr()) { | |
81 | } | |
82 | if (__builtin_constant_p | |
83 | ((((__builtin_constant_p(fpu->state->fxsave.swd & (1 << 7)) ? | |
84 | ! !(fpu->state->fxsave.swd & (1 << 7)) : ( { | |
85 | __builtin_expect(! ! | |
86 | (fpu-> | |
87 | state-> | |
88 | fxsave. | |
89 | swd | |
90 | & (1 | |
91 | << | |
92 | 7)), | |
93 | 1);} | |
94 | )))))? | |
95 | ! !(((__builtin_constant_p(fpu->state->fxsave.swd & (1 << 7)) ? | |
96 | ! !(fpu->state->fxsave.swd & (1 << 7)) : ( { | |
97 | __builtin_expect(! ! | |
98 | (fpu-> | |
99 | state-> | |
100 | fxsave. | |
101 | swd | |
102 | & | |
103 | (1 | |
104 | << | |
105 | 7)), | |
106 | 1);} | |
107 | )))): ( { | |
108 | int ______r; | |
109 | ______r = | |
110 | ! !(((__builtin_constant_p(fpu->state->fxsave.swd & (1 << 7)) | |
111 | ? ! !(fpu->state->fxsave.swd & (1 << 7)) : ( { | |
112 | ______r = | |
113 | __builtin_expect | |
114 | (! ! | |
115 | (fpu-> | |
116 | state-> | |
117 | fxsave. | |
118 | swd & (1 | |
119 | << | |
120 | 7)), | |
121 | 1);} | |
122 | ))));} | |
123 | )) | |
124 | asm volatile ("fnclex"); | |
125 | } | |
126 | ||
127 | static __attribute__ ((always_inline)) | |
128 | void __save_init_fpu(void) | |
129 | { | |
130 | fpu_save_init(0); | |
131 | } | |
132 | ||
133 | static __attribute__ ((always_inline)) | |
134 | void kernel_fpu_begin(void) | |
135 | { | |
136 | __save_init_fpu(); | |
137 | } | |
138 | ||
139 | static void aes_decrypt(void) | |
140 | { | |
141 | if (!irq_fpu_usable()) | |
142 | crypto_aes_decrypt_x86(0); | |
143 | else | |
144 | kernel_fpu_begin(); | |
145 | } | |
146 | ||
147 | static struct crypto_alg aesni_alg = { | |
148 | .cra_list = { | |
149 | &aesni_alg.cra_list, &aesni_alg.cra_list} | |
150 | ,.cra_u = { | |
151 | .cipher = { | |
152 | .cia_decrypt = aes_decrypt} | |
153 | } | |
154 | }; | |
155 | ||
156 | static struct crypto_alg ablk_ecb_alg = { | |
157 | }; | |
158 | ||
159 | int aesni_init(void) | |
160 | { | |
161 | if (! !crypto_register_alg(&aesni_alg)) | |
162 | crypto_unregister_alg(&ablk_ecb_alg); | |
163 | } |