]>
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 crypto_alg { | |
34 | struct list_head cra_list; | |
35 | void (*cia_decrypt) (void); | |
36 | }; | |
37 | static __attribute__ ((always_inline)) __attribute__ ((pure)) | |
38 | int use_xsave(void) | |
39 | { | |
40 | return | |
41 | __builtin_constant_p(constant_test_bit | |
42 | (boot_cpu_data.x86_capability)) ? | |
43 | constant_test_bit( | |
44 | boot_cpu_data.x86_capability | |
45 | ) : | |
46 | __static_cpu_has(154); | |
47 | } | |
48 | ||
49 | static inline __attribute__ ((always_inline)) __attribute__ ((always_inline)) | |
50 | __attribute__ ((pure)) | |
51 | int use_fxsr(void) | |
52 | { | |
53 | return | |
54 | __builtin_constant_p(variable_test_bit | |
55 | (24, | |
56 | (unsigned long *)((&boot_cpu_data)-> | |
57 | x86_capability))) ? | |
58 | variable_test_bit(24, | |
59 | (unsigned long *)((&boot_cpu_data)-> | |
60 | x86_capability)) : | |
61 | __static_cpu_has(24); | |
62 | } | |
63 | ||
64 | static inline __attribute__ ((always_inline)) | |
65 | void fpu_save_init(struct fpu *fpu) | |
66 | { | |
67 | if (__builtin_constant_p(use_xsave())? use_xsave() : use_xsave()) { | |
68 | if (__builtin_constant_p | |
69 | (((!(fpu->state->xsave.xsave_hdr. | |
70 | xstate_bv & 0x1)))) ? ! !((!(fpu->state->xsave. | |
71 | xsave_hdr. | |
72 | xstate_bv & 0x1))) : ( { | |
73 | ! !((!(fpu->state->xsave.xsave_hdr.xstate_bv & 0x1)));} | |
74 | )) | |
75 | return; | |
76 | } else if (use_fxsr()) { | |
77 | } | |
78 | if (__builtin_constant_p | |
79 | ((((__builtin_constant_p(fpu->state->fxsave.swd & (1 << 7)) ? | |
80 | ! !(fpu->state->fxsave.swd & (1 << 7)) : ( { | |
81 | __builtin_expect(! ! | |
82 | (fpu-> | |
83 | state-> | |
84 | fxsave. | |
85 | swd | |
86 | & (1 | |
87 | << | |
88 | 7)), | |
89 | 1);} | |
90 | )))))? | |
91 | ! !(((__builtin_constant_p(fpu->state->fxsave.swd & (1 << 7)) ? | |
92 | ! !(fpu->state->fxsave.swd & (1 << 7)) : ( { | |
93 | __builtin_expect(! ! | |
94 | (fpu-> | |
95 | state-> | |
96 | fxsave. | |
97 | swd | |
98 | & | |
99 | (1 | |
100 | << | |
101 | 7)), | |
102 | 1);} | |
103 | )))): ( { | |
104 | int ______r; | |
105 | ______r = | |
106 | ! !(((__builtin_constant_p(fpu->state->fxsave.swd & (1 << 7)) | |
107 | ? ! !(fpu->state->fxsave.swd & (1 << 7)) : ( { | |
108 | ______r = | |
109 | __builtin_expect | |
110 | (! ! | |
111 | (fpu-> | |
112 | state-> | |
113 | fxsave. | |
114 | swd & (1 | |
115 | << | |
116 | 7)), | |
117 | 1);} | |
118 | ))));} | |
119 | )) | |
120 | asm volatile ("fnclex"); | |
121 | } | |
122 | ||
123 | static __attribute__ ((always_inline)) | |
124 | void __save_init_fpu(void) | |
125 | { | |
126 | fpu_save_init(0); | |
127 | } | |
128 | ||
129 | static __attribute__ ((always_inline)) | |
130 | void kernel_fpu_begin(void) | |
131 | { | |
132 | __save_init_fpu(); | |
133 | } | |
134 | ||
135 | static void aes_decrypt(void) | |
136 | { | |
137 | if (!irq_fpu_usable()) | |
138 | crypto_aes_decrypt_x86(0); | |
139 | else | |
140 | kernel_fpu_begin(); | |
141 | } | |
142 | ||
143 | static struct crypto_alg aesni_alg = { | |
144 | .cra_list = { &aesni_alg.cra_list }, | |
145 | .cia_decrypt = aes_decrypt | |
146 | }; | |
147 | ||
148 | static struct crypto_alg ablk_ecb_alg = { | |
149 | }; | |
150 | ||
151 | int aesni_init(void) | |
152 | { | |
153 | if (! !crypto_register_alg(&aesni_alg)) | |
154 | crypto_unregister_alg(&ablk_ecb_alg); | |
155 | } |