1
2
3
4
5
6
7
8
9
10#ifndef _ASM_S390_CPACF_H
11#define _ASM_S390_CPACF_H
12
13#include <asm/facility.h>
14
15
16
17
18#define CPACF_KMAC 0xb91e
19#define CPACF_KM 0xb92e
20#define CPACF_KMC 0xb92f
21#define CPACF_KIMD 0xb93e
22#define CPACF_KLMD 0xb93f
23#define CPACF_PCKMO 0xb928
24#define CPACF_KMF 0xb92a
25#define CPACF_KMO 0xb92b
26#define CPACF_PCC 0xb92c
27#define CPACF_KMCTR 0xb92d
28#define CPACF_PPNO 0xb93c
29
30
31
32
33#define CPACF_ENCRYPT 0x00
34#define CPACF_DECRYPT 0x80
35
36
37
38
39#define CPACF_KM_QUERY 0x00
40#define CPACF_KM_DEA 0x01
41#define CPACF_KM_TDEA_128 0x02
42#define CPACF_KM_TDEA_192 0x03
43#define CPACF_KM_AES_128 0x12
44#define CPACF_KM_AES_192 0x13
45#define CPACF_KM_AES_256 0x14
46#define CPACF_KM_PAES_128 0x1a
47#define CPACF_KM_PAES_192 0x1b
48#define CPACF_KM_PAES_256 0x1c
49#define CPACF_KM_XTS_128 0x32
50#define CPACF_KM_XTS_256 0x34
51#define CPACF_KM_PXTS_128 0x3a
52#define CPACF_KM_PXTS_256 0x3c
53
54
55
56
57
58#define CPACF_KMC_QUERY 0x00
59#define CPACF_KMC_DEA 0x01
60#define CPACF_KMC_TDEA_128 0x02
61#define CPACF_KMC_TDEA_192 0x03
62#define CPACF_KMC_AES_128 0x12
63#define CPACF_KMC_AES_192 0x13
64#define CPACF_KMC_AES_256 0x14
65#define CPACF_KMC_PAES_128 0x1a
66#define CPACF_KMC_PAES_192 0x1b
67#define CPACF_KMC_PAES_256 0x1c
68#define CPACF_KMC_PRNG 0x43
69
70
71
72
73
74#define CPACF_KMCTR_QUERY 0x00
75#define CPACF_KMCTR_DEA 0x01
76#define CPACF_KMCTR_TDEA_128 0x02
77#define CPACF_KMCTR_TDEA_192 0x03
78#define CPACF_KMCTR_AES_128 0x12
79#define CPACF_KMCTR_AES_192 0x13
80#define CPACF_KMCTR_AES_256 0x14
81#define CPACF_KMCTR_PAES_128 0x1a
82#define CPACF_KMCTR_PAES_192 0x1b
83#define CPACF_KMCTR_PAES_256 0x1c
84
85
86
87
88
89#define CPACF_KIMD_QUERY 0x00
90#define CPACF_KIMD_SHA_1 0x01
91#define CPACF_KIMD_SHA_256 0x02
92#define CPACF_KIMD_SHA_512 0x03
93#define CPACF_KIMD_GHASH 0x41
94
95
96
97
98
99#define CPACF_KLMD_QUERY 0x00
100#define CPACF_KLMD_SHA_1 0x01
101#define CPACF_KLMD_SHA_256 0x02
102#define CPACF_KLMD_SHA_512 0x03
103
104
105
106
107
108#define CPACF_KMAC_QUERY 0x00
109#define CPACF_KMAC_DEA 0x01
110#define CPACF_KMAC_TDEA_128 0x02
111#define CPACF_KMAC_TDEA_192 0x03
112
113
114
115
116
117#define CPACF_PCKMO_QUERY 0x00
118#define CPACF_PCKMO_ENC_DES_KEY 0x01
119#define CPACF_PCKMO_ENC_TDES_128_KEY 0x02
120#define CPACF_PCKMO_ENC_TDES_192_KEY 0x03
121#define CPACF_PCKMO_ENC_AES_128_KEY 0x12
122#define CPACF_PCKMO_ENC_AES_192_KEY 0x13
123#define CPACF_PCKMO_ENC_AES_256_KEY 0x14
124
125
126
127
128
129#define CPACF_PPNO_QUERY 0x00
130#define CPACF_PPNO_SHA512_DRNG_GEN 0x03
131#define CPACF_PPNO_SHA512_DRNG_SEED 0x83
132
133typedef struct { unsigned char bytes[16]; } cpacf_mask_t;
134
135
136
137
138
139
140
141
142
143
144
145static inline void __cpacf_query(unsigned int opcode, cpacf_mask_t *mask)
146{
147 register unsigned long r0 asm("0") = 0;
148 register unsigned long r1 asm("1") = (unsigned long) mask;
149
150 asm volatile(
151 " spm 0\n"
152
153 "0: .insn rrf,%[opc] << 16,2,2,2,0\n"
154 " brc 1,0b\n"
155 : "=m" (*mask)
156 : [fc] "d" (r0), [pba] "a" (r1), [opc] "i" (opcode)
157 : "cc");
158}
159
160static inline int __cpacf_check_opcode(unsigned int opcode)
161{
162 switch (opcode) {
163 case CPACF_KMAC:
164 case CPACF_KM:
165 case CPACF_KMC:
166 case CPACF_KIMD:
167 case CPACF_KLMD:
168 return test_facility(17);
169 case CPACF_PCKMO:
170 return test_facility(76);
171 case CPACF_KMF:
172 case CPACF_KMO:
173 case CPACF_PCC:
174 case CPACF_KMCTR:
175 return test_facility(77);
176 case CPACF_PPNO:
177 return test_facility(57);
178 default:
179 BUG();
180 }
181}
182
183static inline int cpacf_query(unsigned int opcode, cpacf_mask_t *mask)
184{
185 if (__cpacf_check_opcode(opcode)) {
186 __cpacf_query(opcode, mask);
187 return 1;
188 }
189 memset(mask, 0, sizeof(*mask));
190 return 0;
191}
192
193static inline int cpacf_test_func(cpacf_mask_t *mask, unsigned int func)
194{
195 return (mask->bytes[func >> 3] & (0x80 >> (func & 7))) != 0;
196}
197
198static inline int cpacf_query_func(unsigned int opcode, unsigned int func)
199{
200 cpacf_mask_t mask;
201
202 if (cpacf_query(opcode, &mask))
203 return cpacf_test_func(&mask, func);
204 return 0;
205}
206
207
208
209
210
211
212
213
214
215
216
217
218static inline int cpacf_km(unsigned long func, void *param,
219 u8 *dest, const u8 *src, long src_len)
220{
221 register unsigned long r0 asm("0") = (unsigned long) func;
222 register unsigned long r1 asm("1") = (unsigned long) param;
223 register unsigned long r2 asm("2") = (unsigned long) src;
224 register unsigned long r3 asm("3") = (unsigned long) src_len;
225 register unsigned long r4 asm("4") = (unsigned long) dest;
226
227 asm volatile(
228 "0: .insn rre,%[opc] << 16,%[dst],%[src]\n"
229 " brc 1,0b\n"
230 : [src] "+a" (r2), [len] "+d" (r3), [dst] "+a" (r4)
231 : [fc] "d" (r0), [pba] "a" (r1), [opc] "i" (CPACF_KM)
232 : "cc", "memory");
233
234 return src_len - r3;
235}
236
237
238
239
240
241
242
243
244
245
246
247
248static inline int cpacf_kmc(unsigned long func, void *param,
249 u8 *dest, const u8 *src, long src_len)
250{
251 register unsigned long r0 asm("0") = (unsigned long) func;
252 register unsigned long r1 asm("1") = (unsigned long) param;
253 register unsigned long r2 asm("2") = (unsigned long) src;
254 register unsigned long r3 asm("3") = (unsigned long) src_len;
255 register unsigned long r4 asm("4") = (unsigned long) dest;
256
257 asm volatile(
258 "0: .insn rre,%[opc] << 16,%[dst],%[src]\n"
259 " brc 1,0b\n"
260 : [src] "+a" (r2), [len] "+d" (r3), [dst] "+a" (r4)
261 : [fc] "d" (r0), [pba] "a" (r1), [opc] "i" (CPACF_KMC)
262 : "cc", "memory");
263
264 return src_len - r3;
265}
266
267
268
269
270
271
272
273
274
275static inline void cpacf_kimd(unsigned long func, void *param,
276 const u8 *src, long src_len)
277{
278 register unsigned long r0 asm("0") = (unsigned long) func;
279 register unsigned long r1 asm("1") = (unsigned long) param;
280 register unsigned long r2 asm("2") = (unsigned long) src;
281 register unsigned long r3 asm("3") = (unsigned long) src_len;
282
283 asm volatile(
284 "0: .insn rre,%[opc] << 16,0,%[src]\n"
285 " brc 1,0b\n"
286 : [src] "+a" (r2), [len] "+d" (r3)
287 : [fc] "d" (r0), [pba] "a" (r1), [opc] "i" (CPACF_KIMD)
288 : "cc", "memory");
289}
290
291
292
293
294
295
296
297
298static inline void cpacf_klmd(unsigned long func, void *param,
299 const u8 *src, long src_len)
300{
301 register unsigned long r0 asm("0") = (unsigned long) func;
302 register unsigned long r1 asm("1") = (unsigned long) param;
303 register unsigned long r2 asm("2") = (unsigned long) src;
304 register unsigned long r3 asm("3") = (unsigned long) src_len;
305
306 asm volatile(
307 "0: .insn rre,%[opc] << 16,0,%[src]\n"
308 " brc 1,0b\n"
309 : [src] "+a" (r2), [len] "+d" (r3)
310 : [fc] "d" (r0), [pba] "a" (r1), [opc] "i" (CPACF_KLMD)
311 : "cc", "memory");
312}
313
314
315
316
317
318
319
320
321
322
323
324static inline int cpacf_kmac(unsigned long func, void *param,
325 const u8 *src, long src_len)
326{
327 register unsigned long r0 asm("0") = (unsigned long) func;
328 register unsigned long r1 asm("1") = (unsigned long) param;
329 register unsigned long r2 asm("2") = (unsigned long) src;
330 register unsigned long r3 asm("3") = (unsigned long) src_len;
331
332 asm volatile(
333 "0: .insn rre,%[opc] << 16,0,%[src]\n"
334 " brc 1,0b\n"
335 : [src] "+a" (r2), [len] "+d" (r3)
336 : [fc] "d" (r0), [pba] "a" (r1), [opc] "i" (CPACF_KMAC)
337 : "cc", "memory");
338
339 return src_len - r3;
340}
341
342
343
344
345
346
347
348
349
350
351
352
353
354static inline int cpacf_kmctr(unsigned long func, void *param, u8 *dest,
355 const u8 *src, long src_len, u8 *counter)
356{
357 register unsigned long r0 asm("0") = (unsigned long) func;
358 register unsigned long r1 asm("1") = (unsigned long) param;
359 register unsigned long r2 asm("2") = (unsigned long) src;
360 register unsigned long r3 asm("3") = (unsigned long) src_len;
361 register unsigned long r4 asm("4") = (unsigned long) dest;
362 register unsigned long r6 asm("6") = (unsigned long) counter;
363
364 asm volatile(
365 "0: .insn rrf,%[opc] << 16,%[dst],%[src],%[ctr],0\n"
366 " brc 1,0b\n"
367 : [src] "+a" (r2), [len] "+d" (r3),
368 [dst] "+a" (r4), [ctr] "+a" (r6)
369 : [fc] "d" (r0), [pba] "a" (r1), [opc] "i" (CPACF_KMCTR)
370 : "cc", "memory");
371
372 return src_len - r3;
373}
374
375
376
377
378
379
380
381
382
383
384
385static inline void cpacf_ppno(unsigned long func, void *param,
386 u8 *dest, long dest_len,
387 const u8 *seed, long seed_len)
388{
389 register unsigned long r0 asm("0") = (unsigned long) func;
390 register unsigned long r1 asm("1") = (unsigned long) param;
391 register unsigned long r2 asm("2") = (unsigned long) dest;
392 register unsigned long r3 asm("3") = (unsigned long) dest_len;
393 register unsigned long r4 asm("4") = (unsigned long) seed;
394 register unsigned long r5 asm("5") = (unsigned long) seed_len;
395
396 asm volatile (
397 "0: .insn rre,%[opc] << 16,%[dst],%[seed]\n"
398 " brc 1,0b\n"
399 : [dst] "+a" (r2), [dlen] "+d" (r3)
400 : [fc] "d" (r0), [pba] "a" (r1),
401 [seed] "a" (r4), [slen] "d" (r5), [opc] "i" (CPACF_PPNO)
402 : "cc", "memory");
403}
404
405
406
407
408
409
410
411static inline void cpacf_pcc(unsigned long func, void *param)
412{
413 register unsigned long r0 asm("0") = (unsigned long) func;
414 register unsigned long r1 asm("1") = (unsigned long) param;
415
416 asm volatile(
417 "0: .insn rre,%[opc] << 16,0,0\n"
418 " brc 1,0b\n"
419 :
420 : [fc] "d" (r0), [pba] "a" (r1), [opc] "i" (CPACF_PCC)
421 : "cc", "memory");
422}
423
424
425
426
427
428
429
430
431
432static inline void cpacf_pckmo(long func, void *param)
433{
434 register unsigned long r0 asm("0") = (unsigned long) func;
435 register unsigned long r1 asm("1") = (unsigned long) param;
436
437 asm volatile(
438 " .insn rre,%[opc] << 16,0,0\n"
439 :
440 : [fc] "d" (r0), [pba] "a" (r1), [opc] "i" (CPACF_PCKMO)
441 : "cc", "memory");
442}
443
444#endif
445