xref: /openbmc/qemu/target/s390x/gen-features.c (revision 55bbc861)
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_INSTRUCTION_EXEC_PROT,
531     S390_FEAT_GUARDED_STORAGE,
532     S390_FEAT_VECTOR_PACKED_DECIMAL,
533     S390_FEAT_VECTOR_ENH,
534     S390_FEAT_GROUP_MSA_EXT_6,
535     S390_FEAT_GROUP_MSA_EXT_7,
536     S390_FEAT_GROUP_MSA_EXT_8,
537 };
538 
539 /* QEMU (CPU model) features */
540 
541 static uint16_t qemu_V2_11[] = {
542     S390_FEAT_GROUP_PLO,
543     S390_FEAT_ESAN3,
544     S390_FEAT_ZARCH,
545 };
546 
547 static uint16_t qemu_LATEST[] = {
548     S390_FEAT_DAT_ENH,
549     S390_FEAT_IDTE_SEGMENT,
550     S390_FEAT_STFLE,
551     S390_FEAT_SENSE_RUNNING_STATUS,
552     S390_FEAT_EXTENDED_TRANSLATION_2,
553     S390_FEAT_MSA,
554     S390_FEAT_LONG_DISPLACEMENT,
555     S390_FEAT_LONG_DISPLACEMENT_FAST,
556     S390_FEAT_EXTENDED_IMMEDIATE,
557     S390_FEAT_EXTENDED_TRANSLATION_3,
558     S390_FEAT_ETF2_ENH,
559     S390_FEAT_STORE_CLOCK_FAST,
560     S390_FEAT_MOVE_WITH_OPTIONAL_SPEC,
561     S390_FEAT_ETF3_ENH,
562     S390_FEAT_EXTRACT_CPU_TIME,
563     S390_FEAT_COMPARE_AND_SWAP_AND_STORE,
564     S390_FEAT_COMPARE_AND_SWAP_AND_STORE_2,
565     S390_FEAT_GENERAL_INSTRUCTIONS_EXT,
566     S390_FEAT_EXECUTE_EXT,
567     S390_FEAT_SET_PROGRAM_PARAMETERS,
568     S390_FEAT_FLOATING_POINT_SUPPPORT_ENH,
569     S390_FEAT_STFLE_45,
570     S390_FEAT_STFLE_49,
571     S390_FEAT_LOCAL_TLB_CLEARING,
572     S390_FEAT_INTERLOCKED_ACCESS_2,
573     S390_FEAT_MSA_EXT_4,
574     S390_FEAT_MSA_EXT_3,
575 };
576 
577 /* add all new definitions before this point */
578 static uint16_t qemu_MAX[] = {
579     /* z13+ features */
580     S390_FEAT_STFLE_53,
581     /* generates a dependency warning, leave it out for now */
582     S390_FEAT_MSA_EXT_5,
583 };
584 
585 /****** END FEATURE DEFS ******/
586 
587 #define _YEARS  "2016"
588 #define _NAME_H "TARGET_S390X_GEN_FEATURES_H"
589 
590 #define CPU_FEAT_INITIALIZER(_name)                    \
591     {                                                  \
592         .name = "S390_FEAT_LIST_" #_name,              \
593         .base_bits =                                   \
594             { .data = base_##_name,                    \
595               .len = ARRAY_SIZE(base_##_name) },       \
596         .default_bits =                                \
597             { .data = default_##_name,                 \
598               .len = ARRAY_SIZE(default_##_name) },    \
599         .full_bits =                                   \
600             { .data = full_##_name,                    \
601               .len = ARRAY_SIZE(full_##_name) },       \
602     }
603 
604 typedef struct BitSpec {
605     uint16_t *data;
606     uint32_t len;
607 } BitSpec;
608 
609 typedef struct {
610     const char *name;
611     BitSpec base_bits;
612     BitSpec default_bits;
613     BitSpec full_bits;
614 } CpuFeatDefSpec;
615 
616 static uint16_t EmptyFeat[] = {};
617 
618 /*******************************
619  * processor GA series
620  *******************************/
621 static CpuFeatDefSpec CpuFeatDef[] = {
622     CPU_FEAT_INITIALIZER(GEN7_GA1),
623     CPU_FEAT_INITIALIZER(GEN7_GA2),
624     CPU_FEAT_INITIALIZER(GEN7_GA3),
625     CPU_FEAT_INITIALIZER(GEN8_GA1),
626     CPU_FEAT_INITIALIZER(GEN8_GA2),
627     CPU_FEAT_INITIALIZER(GEN8_GA3),
628     CPU_FEAT_INITIALIZER(GEN8_GA4),
629     CPU_FEAT_INITIALIZER(GEN8_GA5),
630     CPU_FEAT_INITIALIZER(GEN9_GA1),
631     CPU_FEAT_INITIALIZER(GEN9_GA2),
632     CPU_FEAT_INITIALIZER(GEN9_GA3),
633     CPU_FEAT_INITIALIZER(GEN10_GA1),
634     CPU_FEAT_INITIALIZER(GEN10_GA2),
635     CPU_FEAT_INITIALIZER(GEN10_GA3),
636     CPU_FEAT_INITIALIZER(GEN11_GA1),
637     CPU_FEAT_INITIALIZER(GEN11_GA2),
638     CPU_FEAT_INITIALIZER(GEN12_GA1),
639     CPU_FEAT_INITIALIZER(GEN12_GA2),
640     CPU_FEAT_INITIALIZER(GEN13_GA1),
641     CPU_FEAT_INITIALIZER(GEN13_GA2),
642     CPU_FEAT_INITIALIZER(GEN14_GA1),
643 };
644 
645 #define FEAT_GROUP_INITIALIZER(_name)                  \
646     {                                                  \
647         .name = "S390_FEAT_GROUP_LIST_" #_name,        \
648         .bits =                                        \
649             { .data = group_##_name,                   \
650               .len = ARRAY_SIZE(group_##_name) },      \
651     }
652 
653 typedef struct {
654     const char *name;
655     BitSpec bits;
656 } FeatGroupDefSpec;
657 
658 /*******************************
659  * feature groups
660  *******************************/
661 static FeatGroupDefSpec FeatGroupDef[] = {
662     FEAT_GROUP_INITIALIZER(PLO),
663     FEAT_GROUP_INITIALIZER(TOD_CLOCK_STEERING),
664     FEAT_GROUP_INITIALIZER(GEN13_PTFF),
665     FEAT_GROUP_INITIALIZER(MSA),
666     FEAT_GROUP_INITIALIZER(MSA_EXT_1),
667     FEAT_GROUP_INITIALIZER(MSA_EXT_2),
668     FEAT_GROUP_INITIALIZER(MSA_EXT_3),
669     FEAT_GROUP_INITIALIZER(MSA_EXT_4),
670     FEAT_GROUP_INITIALIZER(MSA_EXT_5),
671     FEAT_GROUP_INITIALIZER(MSA_EXT_6),
672     FEAT_GROUP_INITIALIZER(MSA_EXT_7),
673     FEAT_GROUP_INITIALIZER(MSA_EXT_8),
674 };
675 
676 #define QEMU_FEAT_INITIALIZER(_name)                   \
677     {                                                  \
678         .name = "S390_FEAT_LIST_QEMU_" #_name,         \
679         .bits =                                        \
680             { .data = qemu_##_name,                    \
681               .len = ARRAY_SIZE(qemu_##_name) },       \
682     }
683 
684 /*******************************
685  * QEMU (CPU model) features
686  *******************************/
687 static FeatGroupDefSpec QemuFeatDef[] = {
688     QEMU_FEAT_INITIALIZER(V2_11),
689     QEMU_FEAT_INITIALIZER(LATEST),
690     QEMU_FEAT_INITIALIZER(MAX),
691 };
692 
693 
694 static void set_bits(uint64_t list[], BitSpec bits)
695 {
696     uint32_t i;
697 
698     for (i = 0; i < bits.len; i++) {
699         list[bits.data[i] / 64] |= 1ULL << (bits.data[i] % 64);
700     }
701 }
702 
703 static void print_feature_defs(void)
704 {
705     uint64_t base_feat[S390_FEAT_MAX / 64 + 1] = {};
706     uint64_t default_feat[S390_FEAT_MAX / 64 + 1] = {};
707     uint64_t full_feat[S390_FEAT_MAX / 64 + 1] = {};
708     int i, j;
709 
710     printf("\n/* CPU model feature list data */\n");
711 
712     for (i = 0; i < ARRAY_SIZE(CpuFeatDef); i++) {
713         set_bits(base_feat, CpuFeatDef[i].base_bits);
714         /* add the base to the default features */
715         set_bits(default_feat, CpuFeatDef[i].base_bits);
716         set_bits(default_feat, CpuFeatDef[i].default_bits);
717         /* add the base to the full features */
718         set_bits(full_feat, CpuFeatDef[i].base_bits);
719         set_bits(full_feat, CpuFeatDef[i].full_bits);
720 
721         printf("#define %s_BASE\t", CpuFeatDef[i].name);
722         for (j = 0; j < ARRAY_SIZE(base_feat); j++) {
723             printf("0x%016"PRIx64"ULL", base_feat[j]);
724             if (j < ARRAY_SIZE(base_feat) - 1) {
725                 printf(",");
726             } else {
727                 printf("\n");
728             }
729         }
730         printf("#define %s_DEFAULT\t", CpuFeatDef[i].name);
731         for (j = 0; j < ARRAY_SIZE(default_feat); j++) {
732             printf("0x%016"PRIx64"ULL", default_feat[j]);
733             if (j < ARRAY_SIZE(default_feat) - 1) {
734                 printf(",");
735             } else {
736                 printf("\n");
737             }
738         }
739         printf("#define %s_FULL\t\t", CpuFeatDef[i].name);
740         for (j = 0; j < ARRAY_SIZE(full_feat); j++) {
741             printf("0x%016"PRIx64"ULL", full_feat[j]);
742             if (j < ARRAY_SIZE(full_feat) - 1) {
743                 printf(",");
744             } else {
745                 printf("\n");
746             }
747         }
748     }
749 }
750 
751 static void print_qemu_feature_defs(void)
752 {
753     uint64_t feat[S390_FEAT_MAX / 64 + 1] = {};
754     int i, j;
755 
756     printf("\n/* QEMU (CPU model) feature list data */\n");
757 
758     /* for now we assume that we only add new features */
759     for (i = 0; i < ARRAY_SIZE(QemuFeatDef); i++) {
760         set_bits(feat, QemuFeatDef[i].bits);
761 
762         printf("#define %s\t", QemuFeatDef[i].name);
763         for (j = 0; j < ARRAY_SIZE(feat); j++) {
764             printf("0x%016"PRIx64"ULL", feat[j]);
765             if (j < ARRAY_SIZE(feat) - 1) {
766                 printf(",");
767             } else {
768                 printf("\n");
769             }
770         }
771     }
772 }
773 
774 static void print_feature_group_defs(void)
775 {
776     int i, j;
777 
778     printf("\n/* CPU feature group list data */\n");
779 
780     for (i = 0; i < ARRAY_SIZE(FeatGroupDef); i++) {
781         uint64_t feat[S390_FEAT_MAX / 64 + 1] = {};
782 
783         set_bits(feat, FeatGroupDef[i].bits);
784         printf("#define %s\t", FeatGroupDef[i].name);
785         for (j = 0; j < ARRAY_SIZE(feat); j++) {
786             printf("0x%016"PRIx64"ULL", feat[j]);
787             if (j < ARRAY_SIZE(feat) - 1) {
788                 printf(",");
789             } else {
790                 printf("\n");
791             }
792         }
793     }
794 }
795 
796 int main(int argc, char *argv[])
797 {
798     printf("/*\n"
799            " * AUTOMATICALLY GENERATED, DO NOT MODIFY HERE, EDIT\n"
800            " * SOURCE FILE \"%s\" INSTEAD.\n"
801            " *\n"
802            " * Copyright %s IBM Corp.\n"
803            " *\n"
804            " * This work is licensed under the terms of the GNU GPL, "
805            "version 2 or (at\n * your option) any later version. See "
806            "the COPYING file in the top-level\n * directory.\n"
807            " */\n\n"
808            "#ifndef %s\n#define %s\n", __FILE__, _YEARS, _NAME_H, _NAME_H);
809     print_feature_defs();
810     print_feature_group_defs();
811     print_qemu_feature_defs();
812     printf("\n#endif\n");
813     return 0;
814 }
815