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