xref: /openbmc/qemu/target/s390x/gen-features.c (revision 0b1183e3)
1 /*
2  * S390 feature list generator
3  *
4  * Copyright 2016 IBM Corp.
5  *
6  * Author(s): Michael Mueller <mimu@linux.vnet.ibm.com>
7  *            David Hildenbrand <dahi@linux.vnet.ibm.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2 or (at
10  * your option) any later version. See the COPYING file in the top-level
11  * directory.
12  *
13  */
14 
15 
16 #include "inttypes.h"
17 #include "stdio.h"
18 #include "cpu_features_def.h"
19 
20 #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
21 
22 /***** BEGIN FEATURE DEFS *****/
23 
24 #define S390_FEAT_GROUP_PLO \
25     S390_FEAT_PLO_CL, \
26     S390_FEAT_PLO_CLG, \
27     S390_FEAT_PLO_CLGR, \
28     S390_FEAT_PLO_CLX, \
29     S390_FEAT_PLO_CS, \
30     S390_FEAT_PLO_CSG, \
31     S390_FEAT_PLO_CSGR, \
32     S390_FEAT_PLO_CSX, \
33     S390_FEAT_PLO_DCS, \
34     S390_FEAT_PLO_DCSG, \
35     S390_FEAT_PLO_DCSGR, \
36     S390_FEAT_PLO_DCSX, \
37     S390_FEAT_PLO_CSST, \
38     S390_FEAT_PLO_CSSTG, \
39     S390_FEAT_PLO_CSSTGR, \
40     S390_FEAT_PLO_CSSTX, \
41     S390_FEAT_PLO_CSDST, \
42     S390_FEAT_PLO_CSDSTG, \
43     S390_FEAT_PLO_CSDSTGR, \
44     S390_FEAT_PLO_CSDSTX, \
45     S390_FEAT_PLO_CSTST, \
46     S390_FEAT_PLO_CSTSTG, \
47     S390_FEAT_PLO_CSTSTGR, \
48     S390_FEAT_PLO_CSTSTX
49 
50 #define S390_FEAT_GROUP_TOD_CLOCK_STEERING \
51     S390_FEAT_TOD_CLOCK_STEERING, \
52     S390_FEAT_PTFF_QTO, \
53     S390_FEAT_PTFF_QSI, \
54     S390_FEAT_PTFF_QPT, \
55     S390_FEAT_PTFF_STO
56 
57 #define S390_FEAT_GROUP_GEN13_PTFF \
58     S390_FEAT_PTFF_QUI, \
59     S390_FEAT_PTFF_QTOU, \
60     S390_FEAT_PTFF_STOU
61 
62 #define S390_FEAT_GROUP_MSA \
63     S390_FEAT_MSA, \
64     S390_FEAT_KMAC_DEA, \
65     S390_FEAT_KMAC_TDEA_128, \
66     S390_FEAT_KMAC_TDEA_192, \
67     S390_FEAT_KMC_DEA, \
68     S390_FEAT_KMC_TDEA_128, \
69     S390_FEAT_KMC_TDEA_192, \
70     S390_FEAT_KM_DEA, \
71     S390_FEAT_KM_TDEA_128, \
72     S390_FEAT_KM_TDEA_192, \
73     S390_FEAT_KIMD_SHA_1, \
74     S390_FEAT_KLMD_SHA_1
75 
76 #define S390_FEAT_GROUP_MSA_EXT_1 \
77     S390_FEAT_KMC_AES_128, \
78     S390_FEAT_KM_AES_128, \
79     S390_FEAT_KIMD_SHA_256, \
80     S390_FEAT_KLMD_SHA_256
81 
82 #define S390_FEAT_GROUP_MSA_EXT_2 \
83     S390_FEAT_KMC_AES_192, \
84     S390_FEAT_KMC_AES_256, \
85     S390_FEAT_KMC_PRNG, \
86     S390_FEAT_KM_AES_192, \
87     S390_FEAT_KM_AES_256, \
88     S390_FEAT_KIMD_SHA_512, \
89     S390_FEAT_KLMD_SHA_512
90 
91 #define S390_FEAT_GROUP_MSA_EXT_3 \
92     S390_FEAT_MSA_EXT_3, \
93     S390_FEAT_KMAC_EDEA, \
94     S390_FEAT_KMAC_ETDEA_128, \
95     S390_FEAT_KMAC_ETDEA_192, \
96     S390_FEAT_KMC_EAES_128, \
97     S390_FEAT_KMC_EAES_192, \
98     S390_FEAT_KMC_EAES_256, \
99     S390_FEAT_KMC_EDEA, \
100     S390_FEAT_KMC_ETDEA_128, \
101     S390_FEAT_KMC_ETDEA_192, \
102     S390_FEAT_KM_EDEA, \
103     S390_FEAT_KM_ETDEA_128, \
104     S390_FEAT_KM_ETDEA_192, \
105     S390_FEAT_KM_EAES_128, \
106     S390_FEAT_KM_EAES_192, \
107     S390_FEAT_KM_EAES_256, \
108     S390_FEAT_PCKMO_EDEA, \
109     S390_FEAT_PCKMO_ETDEA_128, \
110     S390_FEAT_PCKMO_ETDEA_256, \
111     S390_FEAT_PCKMO_AES_128, \
112     S390_FEAT_PCKMO_AES_192, \
113     S390_FEAT_PCKMO_AES_256
114 
115 #define S390_FEAT_GROUP_MSA_EXT_4 \
116     S390_FEAT_MSA_EXT_4, \
117     S390_FEAT_KMAC_AES_128, \
118     S390_FEAT_KMAC_AES_192, \
119     S390_FEAT_KMAC_AES_256, \
120     S390_FEAT_KMAC_EAES_128, \
121     S390_FEAT_KMAC_EAES_192, \
122     S390_FEAT_KMAC_EAES_256, \
123     S390_FEAT_KM_XTS_AES_128, \
124     S390_FEAT_KM_XTS_AES_256, \
125     S390_FEAT_KM_XTS_EAES_128, \
126     S390_FEAT_KM_XTS_EAES_256, \
127     S390_FEAT_KIMD_GHASH, \
128     S390_FEAT_KMCTR_DEA, \
129     S390_FEAT_KMCTR_TDEA_128, \
130     S390_FEAT_KMCTR_TDEA_192, \
131     S390_FEAT_KMCTR_EDEA, \
132     S390_FEAT_KMCTR_ETDEA_128, \
133     S390_FEAT_KMCTR_ETDEA_192, \
134     S390_FEAT_KMCTR_AES_128, \
135     S390_FEAT_KMCTR_AES_192, \
136     S390_FEAT_KMCTR_AES_256, \
137     S390_FEAT_KMCTR_EAES_128, \
138     S390_FEAT_KMCTR_EAES_192, \
139     S390_FEAT_KMCTR_EAES_256, \
140     S390_FEAT_KMF_DEA, \
141     S390_FEAT_KMF_TDEA_128, \
142     S390_FEAT_KMF_TDEA_192, \
143     S390_FEAT_KMF_EDEA, \
144     S390_FEAT_KMF_ETDEA_128, \
145     S390_FEAT_KMF_ETDEA_192, \
146     S390_FEAT_KMF_AES_128, \
147     S390_FEAT_KMF_AES_192, \
148     S390_FEAT_KMF_AES_256, \
149     S390_FEAT_KMF_EAES_128, \
150     S390_FEAT_KMF_EAES_192, \
151     S390_FEAT_KMF_EAES_256, \
152     S390_FEAT_KMO_DEA, \
153     S390_FEAT_KMO_TDEA_128, \
154     S390_FEAT_KMO_TDEA_192, \
155     S390_FEAT_KMO_EDEA, \
156     S390_FEAT_KMO_ETDEA_128, \
157     S390_FEAT_KMO_ETDEA_192, \
158     S390_FEAT_KMO_AES_128, \
159     S390_FEAT_KMO_AES_192, \
160     S390_FEAT_KMO_AES_256, \
161     S390_FEAT_KMO_EAES_128, \
162     S390_FEAT_KMO_EAES_192, \
163     S390_FEAT_KMO_EAES_256, \
164     S390_FEAT_PCC_CMAC_DEA, \
165     S390_FEAT_PCC_CMAC_TDEA_128, \
166     S390_FEAT_PCC_CMAC_TDEA_192, \
167     S390_FEAT_PCC_CMAC_ETDEA_128, \
168     S390_FEAT_PCC_CMAC_ETDEA_192, \
169     S390_FEAT_PCC_CMAC_TDEA, \
170     S390_FEAT_PCC_CMAC_AES_128, \
171     S390_FEAT_PCC_CMAC_AES_192, \
172     S390_FEAT_PCC_CMAC_AES_256, \
173     S390_FEAT_PCC_CMAC_EAES_128, \
174     S390_FEAT_PCC_CMAC_EAES_192, \
175     S390_FEAT_PCC_CMAC_EAES_256, \
176     S390_FEAT_PCC_XTS_AES_128, \
177     S390_FEAT_PCC_XTS_AES_256, \
178     S390_FEAT_PCC_XTS_EAES_128, \
179     S390_FEAT_PCC_XTS_EAES_256
180 
181 #define S390_FEAT_GROUP_MSA_EXT_5 \
182     S390_FEAT_MSA_EXT_5, \
183     S390_FEAT_PPNO_SHA_512_DRNG
184 
185 #define S390_FEAT_GROUP_MSA_EXT_6 \
186     S390_FEAT_KIMD_SHA3_224, \
187     S390_FEAT_KIMD_SHA3_256, \
188     S390_FEAT_KIMD_SHA3_384, \
189     S390_FEAT_KIMD_SHA3_512, \
190     S390_FEAT_KIMD_SHAKE_128, \
191     S390_FEAT_KIMD_SHAKE_256, \
192     S390_FEAT_KLMD_SHA3_224, \
193     S390_FEAT_KLMD_SHA3_256, \
194     S390_FEAT_KLMD_SHA3_384, \
195     S390_FEAT_KLMD_SHA3_512, \
196     S390_FEAT_KLMD_SHAKE_128, \
197     S390_FEAT_KLMD_SHAKE_256
198 
199 #define S390_FEAT_GROUP_MSA_EXT_7 \
200     S390_FEAT_PRNO_TRNG_QRTCR, \
201     S390_FEAT_PRNO_TRNG
202 
203 #define S390_FEAT_GROUP_MSA_EXT_8 \
204     S390_FEAT_MSA_EXT_8, \
205     S390_FEAT_KMA_GCM_AES_128, \
206     S390_FEAT_KMA_GCM_AES_192, \
207     S390_FEAT_KMA_GCM_AES_256 , \
208     S390_FEAT_KMA_GCM_EAES_128, \
209     S390_FEAT_KMA_GCM_EAES_192, \
210     S390_FEAT_KMA_GCM_EAES_256
211 
212 /* cpu feature groups */
213 static uint16_t group_PLO[] = {
214     S390_FEAT_GROUP_PLO,
215 };
216 static uint16_t group_TOD_CLOCK_STEERING[] = {
217     S390_FEAT_GROUP_TOD_CLOCK_STEERING,
218 };
219 static uint16_t group_GEN13_PTFF[] = {
220     S390_FEAT_GROUP_GEN13_PTFF,
221 };
222 static uint16_t group_MSA[] = {
223     S390_FEAT_GROUP_MSA,
224 };
225 static uint16_t group_MSA_EXT_1[] = {
226     S390_FEAT_GROUP_MSA_EXT_1,
227 };
228 static uint16_t group_MSA_EXT_2[] = {
229     S390_FEAT_GROUP_MSA_EXT_2,
230 };
231 static uint16_t group_MSA_EXT_3[] = {
232     S390_FEAT_GROUP_MSA_EXT_3,
233 };
234 static uint16_t group_MSA_EXT_4[] = {
235     S390_FEAT_GROUP_MSA_EXT_4,
236 };
237 static uint16_t group_MSA_EXT_5[] = {
238     S390_FEAT_GROUP_MSA_EXT_5,
239 };
240 static uint16_t group_MSA_EXT_6[] = {
241     S390_FEAT_GROUP_MSA_EXT_6,
242 };
243 static uint16_t group_MSA_EXT_7[] = {
244     S390_FEAT_GROUP_MSA_EXT_7,
245 };
246 static uint16_t group_MSA_EXT_8[] = {
247     S390_FEAT_GROUP_MSA_EXT_8,
248 };
249 
250 /* Base features (in order of release)
251  * Only non-hypervisor managed features belong here.
252  * Base feature sets are static meaning they do not change in future QEMU
253  * releases.
254  */
255 static uint16_t base_GEN7_GA1[] = {
256     S390_FEAT_GROUP_PLO,
257     S390_FEAT_ESAN3,
258     S390_FEAT_ZARCH,
259 };
260 
261 #define base_GEN7_GA2 EmptyFeat
262 #define base_GEN7_GA3 EmptyFeat
263 
264 static uint16_t base_GEN8_GA1[] = {
265     S390_FEAT_DAT_ENH,
266     S390_FEAT_EXTENDED_TRANSLATION_2,
267     S390_FEAT_GROUP_MSA,
268     S390_FEAT_LONG_DISPLACEMENT,
269     S390_FEAT_LONG_DISPLACEMENT_FAST,
270     S390_FEAT_HFP_MADDSUB,
271 };
272 
273 #define base_GEN8_GA2 EmptyFeat
274 #define base_GEN8_GA3 EmptyFeat
275 #define base_GEN8_GA4 EmptyFeat
276 #define base_GEN8_GA5 EmptyFeat
277 
278 static uint16_t base_GEN9_GA1[] = {
279     S390_FEAT_IDTE_SEGMENT,
280     S390_FEAT_ASN_LX_REUSE,
281     S390_FEAT_STFLE,
282     S390_FEAT_SENSE_RUNNING_STATUS,
283     S390_FEAT_EXTENDED_IMMEDIATE,
284     S390_FEAT_EXTENDED_TRANSLATION_3,
285     S390_FEAT_HFP_UNNORMALIZED_EXT,
286     S390_FEAT_ETF2_ENH,
287     S390_FEAT_STORE_CLOCK_FAST,
288     S390_FEAT_GROUP_TOD_CLOCK_STEERING,
289     S390_FEAT_ETF3_ENH,
290     S390_FEAT_DAT_ENH_2,
291 };
292 
293 #define base_GEN9_GA2 EmptyFeat
294 #define base_GEN9_GA3 EmptyFeat
295 
296 static uint16_t base_GEN10_GA1[] = {
297     S390_FEAT_CONDITIONAL_SSKE,
298     S390_FEAT_PARSING_ENH,
299     S390_FEAT_MOVE_WITH_OPTIONAL_SPEC,
300     S390_FEAT_EXTRACT_CPU_TIME,
301     S390_FEAT_COMPARE_AND_SWAP_AND_STORE,
302     S390_FEAT_COMPARE_AND_SWAP_AND_STORE_2,
303     S390_FEAT_GENERAL_INSTRUCTIONS_EXT,
304     S390_FEAT_EXECUTE_EXT,
305     S390_FEAT_FLOATING_POINT_SUPPPORT_ENH,
306     S390_FEAT_DFP,
307     S390_FEAT_DFP_FAST,
308     S390_FEAT_PFPO,
309 };
310 #define base_GEN10_GA2 EmptyFeat
311 #define base_GEN10_GA3 EmptyFeat
312 
313 static uint16_t base_GEN11_GA1[] = {
314     S390_FEAT_NONQ_KEY_SETTING,
315     S390_FEAT_ENHANCED_MONITOR,
316     S390_FEAT_FLOATING_POINT_EXT,
317     S390_FEAT_SET_PROGRAM_PARAMETERS,
318     S390_FEAT_STFLE_45,
319     S390_FEAT_CMPSC_ENH,
320     S390_FEAT_INTERLOCKED_ACCESS_2,
321 };
322 
323 #define base_GEN11_GA2 EmptyFeat
324 
325 static uint16_t base_GEN12_GA1[] = {
326     S390_FEAT_DFP_ZONED_CONVERSION,
327     S390_FEAT_STFLE_49,
328     S390_FEAT_LOCAL_TLB_CLEARING,
329 };
330 
331 #define base_GEN12_GA2 EmptyFeat
332 
333 static uint16_t base_GEN13_GA1[] = {
334     S390_FEAT_STFLE_53,
335     S390_FEAT_DFP_PACKED_CONVERSION,
336     S390_FEAT_GROUP_GEN13_PTFF,
337 };
338 
339 #define base_GEN13_GA2 EmptyFeat
340 
341 static uint16_t base_GEN14_GA1[] = {
342     S390_FEAT_ENTROPY_ENC_COMP,
343     S390_FEAT_MISC_INSTRUCTION_EXT,
344     S390_FEAT_SEMAPHORE_ASSIST,
345     S390_FEAT_TIME_SLICE_INSTRUMENTATION,
346     S390_FEAT_ORDER_PRESERVING_COMPRESSION,
347 };
348 
349 /* Full features (in order of release)
350  * Automatically includes corresponding base features.
351  * Full features are all features this hardware supports even if kvm/QEMU do not
352  * support these features yet.
353  */
354 static uint16_t full_GEN7_GA1[] = {
355     S390_FEAT_SIE_F2,
356     S390_FEAT_SIE_SKEY,
357     S390_FEAT_SIE_GPERE,
358     S390_FEAT_SIE_IB,
359     S390_FEAT_SIE_CEI,
360 };
361 
362 static uint16_t full_GEN7_GA2[] = {
363     S390_FEAT_EXTENDED_TRANSLATION_2,
364 };
365 
366 static uint16_t full_GEN7_GA3[] = {
367     S390_FEAT_LONG_DISPLACEMENT,
368     S390_FEAT_SIE_SIIF,
369 };
370 
371 static uint16_t full_GEN8_GA1[] = {
372     S390_FEAT_SIE_GSLS,
373     S390_FEAT_SIE_64BSCAO,
374 };
375 
376 #define full_GEN8_GA2 EmptyFeat
377 
378 static uint16_t full_GEN8_GA3[] = {
379     S390_FEAT_ASN_LX_REUSE,
380     S390_FEAT_EXTENDED_TRANSLATION_3,
381 };
382 
383 #define full_GEN8_GA4 EmptyFeat
384 #define full_GEN8_GA5 EmptyFeat
385 
386 static uint16_t full_GEN9_GA1[] = {
387     S390_FEAT_STORE_HYPERVISOR_INFO,
388     S390_FEAT_GROUP_MSA_EXT_1,
389     S390_FEAT_CMM,
390     S390_FEAT_SIE_CMMA,
391 };
392 
393 static uint16_t full_GEN9_GA2[] = {
394     S390_FEAT_MOVE_WITH_OPTIONAL_SPEC,
395     S390_FEAT_EXTRACT_CPU_TIME,
396     S390_FEAT_COMPARE_AND_SWAP_AND_STORE,
397     S390_FEAT_FLOATING_POINT_SUPPPORT_ENH,
398     S390_FEAT_DFP,
399 };
400 
401 static uint16_t full_GEN9_GA3[] = {
402     S390_FEAT_CONDITIONAL_SSKE,
403     S390_FEAT_PFPO,
404 };
405 
406 static uint16_t full_GEN10_GA1[] = {
407     S390_FEAT_EDAT,
408     S390_FEAT_CONFIGURATION_TOPOLOGY,
409     S390_FEAT_GROUP_MSA_EXT_2,
410     S390_FEAT_ESOP,
411     S390_FEAT_SIE_PFMFI,
412     S390_FEAT_SIE_SIGPIF,
413 };
414 
415 static uint16_t full_GEN10_GA2[] = {
416     S390_FEAT_SET_PROGRAM_PARAMETERS,
417     S390_FEAT_SIE_IBS,
418 };
419 
420 static uint16_t full_GEN10_GA3[] = {
421     S390_FEAT_GROUP_MSA_EXT_3,
422 };
423 
424 static uint16_t full_GEN11_GA1[] = {
425     S390_FEAT_IPTE_RANGE,
426     S390_FEAT_ACCESS_EXCEPTION_FS_INDICATION,
427     S390_FEAT_GROUP_MSA_EXT_4,
428 };
429 
430 #define full_GEN11_GA2 EmptyFeat
431 
432 static uint16_t full_GEN12_GA1[] = {
433     S390_FEAT_CONSTRAINT_TRANSACTIONAL_EXE,
434     S390_FEAT_TRANSACTIONAL_EXE,
435     S390_FEAT_RUNTIME_INSTRUMENTATION,
436     S390_FEAT_ZPCI,
437     S390_FEAT_ADAPTER_EVENT_NOTIFICATION,
438     S390_FEAT_ADAPTER_INT_SUPPRESSION,
439     S390_FEAT_EDAT_2,
440     S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2,
441 };
442 
443 static uint16_t full_GEN12_GA2[] = {
444     S390_FEAT_GROUP_MSA_EXT_5,
445 };
446 
447 static uint16_t full_GEN13_GA1[] = {
448     S390_FEAT_VECTOR,
449 };
450 
451 #define full_GEN13_GA2 EmptyFeat
452 
453 static uint16_t full_GEN14_GA1[] = {
454     S390_FEAT_INSTRUCTION_EXEC_PROT,
455     S390_FEAT_GUARDED_STORAGE,
456     S390_FEAT_VECTOR_PACKED_DECIMAL,
457     S390_FEAT_VECTOR_ENH,
458     S390_FEAT_MULTIPLE_EPOCH,
459     S390_FEAT_TEST_PENDING_EXT_INTERRUPTION,
460     S390_FEAT_INSERT_REFERENCE_BITS_MULT,
461     S390_FEAT_GROUP_MSA_EXT_6,
462     S390_FEAT_GROUP_MSA_EXT_7,
463     S390_FEAT_GROUP_MSA_EXT_8,
464     S390_FEAT_CMM_NT,
465     S390_FEAT_HPMA2,
466     S390_FEAT_SIE_KSS,
467 };
468 
469 /* Default features (in order of release)
470  * Automatically includes corresponding base features.
471  * Default features are all features this version of QEMU supports for this
472  * hardware model. Default feature sets can grow with new QEMU releases.
473  */
474 #define default_GEN7_GA1 EmptyFeat
475 #define default_GEN7_GA2 EmptyFeat
476 #define default_GEN7_GA3 EmptyFeat
477 #define default_GEN8_GA1 EmptyFeat
478 #define default_GEN8_GA2 EmptyFeat
479 #define default_GEN8_GA3 EmptyFeat
480 #define default_GEN8_GA4 EmptyFeat
481 #define default_GEN8_GA5 EmptyFeat
482 
483 static uint16_t default_GEN9_GA1[] = {
484     S390_FEAT_STORE_HYPERVISOR_INFO,
485     S390_FEAT_GROUP_MSA_EXT_1,
486     S390_FEAT_CMM,
487 };
488 
489 #define default_GEN9_GA2 EmptyFeat
490 #define default_GEN9_GA3 EmptyFeat
491 
492 static uint16_t default_GEN10_GA1[] = {
493     S390_FEAT_EDAT,
494     S390_FEAT_GROUP_MSA_EXT_2,
495 };
496 
497 #define default_GEN10_GA2 EmptyFeat
498 #define default_GEN10_GA3 EmptyFeat
499 
500 static uint16_t default_GEN11_GA1[] = {
501     S390_FEAT_GROUP_MSA_EXT_3,
502     S390_FEAT_IPTE_RANGE,
503     S390_FEAT_ACCESS_EXCEPTION_FS_INDICATION,
504     S390_FEAT_GROUP_MSA_EXT_4,
505 };
506 
507 #define default_GEN11_GA2 EmptyFeat
508 
509 static uint16_t default_GEN12_GA1[] = {
510     S390_FEAT_CONSTRAINT_TRANSACTIONAL_EXE,
511     S390_FEAT_TRANSACTIONAL_EXE,
512     S390_FEAT_RUNTIME_INSTRUMENTATION,
513     S390_FEAT_ZPCI,
514     S390_FEAT_ADAPTER_EVENT_NOTIFICATION,
515     S390_FEAT_EDAT_2,
516     S390_FEAT_ESOP,
517     S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2,
518 };
519 
520 #define default_GEN12_GA2 EmptyFeat
521 
522 static uint16_t default_GEN13_GA1[] = {
523     S390_FEAT_GROUP_MSA_EXT_5,
524     S390_FEAT_VECTOR,
525 };
526 
527 #define default_GEN13_GA2 EmptyFeat
528 
529 static uint16_t default_GEN14_GA1[] = {
530     S390_FEAT_ADAPTER_INT_SUPPRESSION,
531     S390_FEAT_INSTRUCTION_EXEC_PROT,
532     S390_FEAT_GUARDED_STORAGE,
533     S390_FEAT_VECTOR_PACKED_DECIMAL,
534     S390_FEAT_VECTOR_ENH,
535     S390_FEAT_GROUP_MSA_EXT_6,
536     S390_FEAT_GROUP_MSA_EXT_7,
537     S390_FEAT_GROUP_MSA_EXT_8,
538     S390_FEAT_SIE_KSS,
539 };
540 
541 /****** END FEATURE DEFS ******/
542 
543 #define _YEARS  "2016"
544 #define _NAME_H "TARGET_S390X_GEN_FEATURES_H"
545 
546 #define CPU_FEAT_INITIALIZER(_name)                    \
547     {                                                  \
548         .name = "S390_FEAT_LIST_" #_name,              \
549         .base_bits =                                   \
550             { .data = base_##_name,                    \
551               .len = ARRAY_SIZE(base_##_name) },       \
552         .default_bits =                                \
553             { .data = default_##_name,                 \
554               .len = ARRAY_SIZE(default_##_name) },    \
555         .full_bits =                                   \
556             { .data = full_##_name,                    \
557               .len = ARRAY_SIZE(full_##_name) },       \
558     }
559 
560 typedef struct BitSpec {
561     uint16_t *data;
562     uint32_t len;
563 } BitSpec;
564 
565 typedef struct {
566     const char *name;
567     BitSpec base_bits;
568     BitSpec default_bits;
569     BitSpec full_bits;
570 } CpuFeatDefSpec;
571 
572 static uint16_t EmptyFeat[] = {};
573 
574 /*******************************
575  * processor GA series
576  *******************************/
577 static CpuFeatDefSpec CpuFeatDef[] = {
578     CPU_FEAT_INITIALIZER(GEN7_GA1),
579     CPU_FEAT_INITIALIZER(GEN7_GA2),
580     CPU_FEAT_INITIALIZER(GEN7_GA3),
581     CPU_FEAT_INITIALIZER(GEN8_GA1),
582     CPU_FEAT_INITIALIZER(GEN8_GA2),
583     CPU_FEAT_INITIALIZER(GEN8_GA3),
584     CPU_FEAT_INITIALIZER(GEN8_GA4),
585     CPU_FEAT_INITIALIZER(GEN8_GA5),
586     CPU_FEAT_INITIALIZER(GEN9_GA1),
587     CPU_FEAT_INITIALIZER(GEN9_GA2),
588     CPU_FEAT_INITIALIZER(GEN9_GA3),
589     CPU_FEAT_INITIALIZER(GEN10_GA1),
590     CPU_FEAT_INITIALIZER(GEN10_GA2),
591     CPU_FEAT_INITIALIZER(GEN10_GA3),
592     CPU_FEAT_INITIALIZER(GEN11_GA1),
593     CPU_FEAT_INITIALIZER(GEN11_GA2),
594     CPU_FEAT_INITIALIZER(GEN12_GA1),
595     CPU_FEAT_INITIALIZER(GEN12_GA2),
596     CPU_FEAT_INITIALIZER(GEN13_GA1),
597     CPU_FEAT_INITIALIZER(GEN13_GA2),
598     CPU_FEAT_INITIALIZER(GEN14_GA1),
599 };
600 
601 #define FEAT_GROUP_INITIALIZER(_name)                  \
602     {                                                  \
603         .name = "S390_FEAT_GROUP_LIST_" #_name,        \
604         .bits =                                        \
605             { .data = group_##_name,                   \
606               .len = ARRAY_SIZE(group_##_name) },      \
607     }
608 
609 typedef struct {
610     const char *name;
611     BitSpec bits;
612 } FeatGroupDefSpec;
613 
614 /*******************************
615  * feature groups
616  *******************************/
617 static FeatGroupDefSpec FeatGroupDef[] = {
618     FEAT_GROUP_INITIALIZER(PLO),
619     FEAT_GROUP_INITIALIZER(TOD_CLOCK_STEERING),
620     FEAT_GROUP_INITIALIZER(GEN13_PTFF),
621     FEAT_GROUP_INITIALIZER(MSA),
622     FEAT_GROUP_INITIALIZER(MSA_EXT_1),
623     FEAT_GROUP_INITIALIZER(MSA_EXT_2),
624     FEAT_GROUP_INITIALIZER(MSA_EXT_3),
625     FEAT_GROUP_INITIALIZER(MSA_EXT_4),
626     FEAT_GROUP_INITIALIZER(MSA_EXT_5),
627     FEAT_GROUP_INITIALIZER(MSA_EXT_6),
628     FEAT_GROUP_INITIALIZER(MSA_EXT_7),
629     FEAT_GROUP_INITIALIZER(MSA_EXT_8),
630 };
631 
632 static void set_bits(uint64_t list[], BitSpec bits)
633 {
634     uint32_t i;
635 
636     for (i = 0; i < bits.len; i++) {
637         list[bits.data[i] / 64] |= 1ULL << (bits.data[i] % 64);
638     }
639 }
640 
641 static void print_feature_defs(void)
642 {
643     uint64_t base_feat[S390_FEAT_MAX / 64 + 1] = {};
644     uint64_t default_feat[S390_FEAT_MAX / 64 + 1] = {};
645     uint64_t full_feat[S390_FEAT_MAX / 64 + 1] = {};
646     int i, j;
647 
648     printf("\n/* CPU model feature list data */\n");
649 
650     for (i = 0; i < ARRAY_SIZE(CpuFeatDef); i++) {
651         set_bits(base_feat, CpuFeatDef[i].base_bits);
652         /* add the base to the default features */
653         set_bits(default_feat, CpuFeatDef[i].base_bits);
654         set_bits(default_feat, CpuFeatDef[i].default_bits);
655         /* add the base to the full features */
656         set_bits(full_feat, CpuFeatDef[i].base_bits);
657         set_bits(full_feat, CpuFeatDef[i].full_bits);
658 
659         printf("#define %s_BASE\t", CpuFeatDef[i].name);
660         for (j = 0; j < ARRAY_SIZE(base_feat); j++) {
661             printf("0x%016"PRIx64"ULL", base_feat[j]);
662             if (j < ARRAY_SIZE(base_feat) - 1) {
663                 printf(",");
664             } else {
665                 printf("\n");
666             }
667         }
668         printf("#define %s_DEFAULT\t", CpuFeatDef[i].name);
669         for (j = 0; j < ARRAY_SIZE(default_feat); j++) {
670             printf("0x%016"PRIx64"ULL", default_feat[j]);
671             if (j < ARRAY_SIZE(default_feat) - 1) {
672                 printf(",");
673             } else {
674                 printf("\n");
675             }
676         }
677         printf("#define %s_FULL\t\t", CpuFeatDef[i].name);
678         for (j = 0; j < ARRAY_SIZE(full_feat); j++) {
679             printf("0x%016"PRIx64"ULL", full_feat[j]);
680             if (j < ARRAY_SIZE(full_feat) - 1) {
681                 printf(",");
682             } else {
683                 printf("\n");
684             }
685         }
686     }
687 }
688 
689 static void print_feature_group_defs(void)
690 {
691     int i, j;
692 
693     printf("\n/* CPU feature group list data */\n");
694 
695     for (i = 0; i < ARRAY_SIZE(FeatGroupDef); i++) {
696         uint64_t feat[S390_FEAT_MAX / 64 + 1] = {};
697 
698         set_bits(feat, FeatGroupDef[i].bits);
699         printf("#define %s\t", FeatGroupDef[i].name);
700         for (j = 0; j < ARRAY_SIZE(feat); j++) {
701             printf("0x%016"PRIx64"ULL", feat[j]);
702             if (j < ARRAY_SIZE(feat) - 1) {
703                 printf(",");
704             } else {
705                 printf("\n");
706             }
707         }
708     }
709 }
710 
711 int main(int argc, char *argv[])
712 {
713     printf("/*\n"
714            " * AUTOMATICALLY GENERATED, DO NOT MODIFY HERE, EDIT\n"
715            " * SOURCE FILE \"%s\" INSTEAD.\n"
716            " *\n"
717            " * Copyright %s IBM Corp.\n"
718            " *\n"
719            " * This work is licensed under the terms of the GNU GPL, "
720            "version 2 or (at\n * your option) any later version. See "
721            "the COPYING file in the top-level\n * directory.\n"
722            " */\n\n"
723            "#ifndef %s\n#define %s\n", __FILE__, _YEARS, _NAME_H, _NAME_H);
724     print_feature_defs();
725     print_feature_group_defs();
726     printf("\n#endif\n");
727     return 0;
728 }
729