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