1 /*
2 * CPU models for s390x
3 *
4 * Copyright 2016 IBM Corp.
5 *
6 * Author(s): David Hildenbrand <dahi@linux.vnet.ibm.com>
7 *
8 * This work is licensed under the terms of the GNU GPL, version 2 or (at
9 * your option) any later version. See the COPYING file in the top-level
10 * directory.
11 */
12
13 #include "qemu/osdep.h"
14 #include "cpu.h"
15 #include "s390x-internal.h"
16 #include "kvm/kvm_s390x.h"
17 #include "system/kvm.h"
18 #include "system/tcg.h"
19 #include "qapi/error.h"
20 #include "qemu/error-report.h"
21 #include "qapi/visitor.h"
22 #include "qemu/module.h"
23 #include "qemu/hw-version.h"
24 #include "qemu/qemu-print.h"
25 #ifndef CONFIG_USER_ONLY
26 #include "system/system.h"
27 #include "target/s390x/kvm/pv.h"
28 #include CONFIG_DEVICES
29 #endif
30
31 #define CPUDEF_INIT(_type, _gen, _ec_ga, _mha_pow, _hmfai, _name, _desc) \
32 { \
33 .name = _name, \
34 .type = _type, \
35 .gen = _gen, \
36 .ec_ga = _ec_ga, \
37 .mha_pow = _mha_pow, \
38 .hmfai = _hmfai, \
39 .desc = _desc, \
40 .base_init = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _BASE }, \
41 .default_init = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _DEFAULT }, \
42 .full_init = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _FULL }, \
43 }
44
45 /*
46 * CPU definition list in order of release. Up to generation 14 base features
47 * of a following release have been a superset of the previous release. With
48 * generation 15 one base feature and one optional feature have been deprecated.
49 */
50 static S390CPUDef s390_cpu_defs[] = {
51 /*
52 * Linux requires at least z10 nowadays, and IBM only supports recent CPUs
53 * (see https://www.ibm.com/support/pages/ibm-mainframe-life-cycle-history),
54 * so we consider older CPUs as legacy that can optionally be disabled via
55 * the CONFIG_S390X_LEGACY_CPUS config switch.
56 */
57 #if defined(CONFIG_S390X_LEGACY_CPUS) || defined(CONFIG_USER_ONLY)
58 CPUDEF_INIT(0x2064, 7, 1, 38, 0x00000000U, "z900", "IBM zSeries 900 GA1"),
59 CPUDEF_INIT(0x2064, 7, 2, 38, 0x00000000U, "z900.2", "IBM zSeries 900 GA2"),
60 CPUDEF_INIT(0x2064, 7, 3, 38, 0x00000000U, "z900.3", "IBM zSeries 900 GA3"),
61 CPUDEF_INIT(0x2066, 7, 3, 38, 0x00000000U, "z800", "IBM zSeries 800 GA1"),
62 CPUDEF_INIT(0x2084, 8, 1, 38, 0x00000000U, "z990", "IBM zSeries 990 GA1"),
63 CPUDEF_INIT(0x2084, 8, 2, 38, 0x00000000U, "z990.2", "IBM zSeries 990 GA2"),
64 CPUDEF_INIT(0x2084, 8, 3, 38, 0x00000000U, "z990.3", "IBM zSeries 990 GA3"),
65 CPUDEF_INIT(0x2086, 8, 3, 38, 0x00000000U, "z890", "IBM zSeries 880 GA1"),
66 CPUDEF_INIT(0x2084, 8, 4, 38, 0x00000000U, "z990.4", "IBM zSeries 990 GA4"),
67 CPUDEF_INIT(0x2086, 8, 4, 38, 0x00000000U, "z890.2", "IBM zSeries 880 GA2"),
68 CPUDEF_INIT(0x2084, 8, 5, 38, 0x00000000U, "z990.5", "IBM zSeries 990 GA5"),
69 CPUDEF_INIT(0x2086, 8, 5, 38, 0x00000000U, "z890.3", "IBM zSeries 880 GA3"),
70 CPUDEF_INIT(0x2094, 9, 1, 40, 0x00000000U, "z9EC", "IBM System z9 EC GA1"),
71 CPUDEF_INIT(0x2094, 9, 2, 40, 0x00000000U, "z9EC.2", "IBM System z9 EC GA2"),
72 CPUDEF_INIT(0x2096, 9, 2, 40, 0x00000000U, "z9BC", "IBM System z9 BC GA1"),
73 CPUDEF_INIT(0x2094, 9, 3, 40, 0x00000000U, "z9EC.3", "IBM System z9 EC GA3"),
74 CPUDEF_INIT(0x2096, 9, 3, 40, 0x00000000U, "z9BC.2", "IBM System z9 BC GA2"),
75 #endif
76 CPUDEF_INIT(0x2097, 10, 1, 43, 0x00000000U, "z10EC", "IBM System z10 EC GA1"),
77 CPUDEF_INIT(0x2097, 10, 2, 43, 0x00000000U, "z10EC.2", "IBM System z10 EC GA2"),
78 CPUDEF_INIT(0x2098, 10, 2, 43, 0x00000000U, "z10BC", "IBM System z10 BC GA1"),
79 CPUDEF_INIT(0x2097, 10, 3, 43, 0x00000000U, "z10EC.3", "IBM System z10 EC GA3"),
80 CPUDEF_INIT(0x2098, 10, 3, 43, 0x00000000U, "z10BC.2", "IBM System z10 BC GA2"),
81 CPUDEF_INIT(0x2817, 11, 1, 44, 0x08000000U, "z196", "IBM zEnterprise 196 GA1"),
82 CPUDEF_INIT(0x2817, 11, 2, 44, 0x08000000U, "z196.2", "IBM zEnterprise 196 GA2"),
83 CPUDEF_INIT(0x2818, 11, 2, 44, 0x08000000U, "z114", "IBM zEnterprise 114 GA1"),
84 CPUDEF_INIT(0x2827, 12, 1, 44, 0x08000000U, "zEC12", "IBM zEnterprise EC12 GA1"),
85 CPUDEF_INIT(0x2827, 12, 2, 44, 0x08000000U, "zEC12.2", "IBM zEnterprise EC12 GA2"),
86 CPUDEF_INIT(0x2828, 12, 2, 44, 0x08000000U, "zBC12", "IBM zEnterprise BC12 GA1"),
87 CPUDEF_INIT(0x2964, 13, 1, 47, 0x08000000U, "z13", "IBM z13 GA1"),
88 CPUDEF_INIT(0x2964, 13, 2, 47, 0x08000000U, "z13.2", "IBM z13 GA2"),
89 CPUDEF_INIT(0x2965, 13, 2, 47, 0x08000000U, "z13s", "IBM z13s GA1"),
90 CPUDEF_INIT(0x3906, 14, 1, 47, 0x08000000U, "z14", "IBM z14 GA1"),
91 CPUDEF_INIT(0x3906, 14, 2, 47, 0x08000000U, "z14.2", "IBM z14 GA2"),
92 CPUDEF_INIT(0x3907, 14, 1, 47, 0x08000000U, "z14ZR1", "IBM z14 Model ZR1 GA1"),
93 CPUDEF_INIT(0x8561, 15, 1, 47, 0x08000000U, "gen15a", "IBM z15 T01 GA1"),
94 CPUDEF_INIT(0x8562, 15, 1, 47, 0x08000000U, "gen15b", "IBM z15 T02 GA1"),
95 CPUDEF_INIT(0x3931, 16, 1, 47, 0x08000000U, "gen16a", "IBM 3931 GA1"),
96 CPUDEF_INIT(0x3932, 16, 1, 47, 0x08000000U, "gen16b", "IBM 3932 GA1"),
97 CPUDEF_INIT(0x9175, 17, 1, 47, 0x08000000U, "gen17a", "IBM 9175 GA1"),
98 CPUDEF_INIT(0x9176, 17, 1, 47, 0x08000000U, "gen17b", "IBM 9176 GA1"),
99 };
100
101 #define QEMU_MAX_CPU_TYPE 0x8561
102 #define QEMU_MAX_CPU_GEN 15
103 #define QEMU_MAX_CPU_EC_GA 1
104 static S390FeatBitmap qemu_max_cpu_feat;
105
106 /* features part of a base model but not relevant for finding a base model */
107 S390FeatBitmap ignored_base_feat;
108
s390_cpudef_featoff(uint8_t gen,uint8_t ec_ga,S390Feat feat)109 void s390_cpudef_featoff(uint8_t gen, uint8_t ec_ga, S390Feat feat)
110 {
111 const S390CPUDef *def;
112
113 def = s390_find_cpu_def(0, gen, ec_ga, NULL);
114 clear_bit(feat, (unsigned long *)&def->default_feat);
115 }
116
s390_cpudef_featoff_greater(uint8_t gen,uint8_t ec_ga,S390Feat feat)117 void s390_cpudef_featoff_greater(uint8_t gen, uint8_t ec_ga, S390Feat feat)
118 {
119 int i;
120
121 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
122 const S390CPUDef *def = &s390_cpu_defs[i];
123
124 if (def->gen < gen) {
125 continue;
126 }
127 if (def->gen == gen && def->ec_ga < ec_ga) {
128 continue;
129 }
130
131 clear_bit(feat, (unsigned long *)&def->default_feat);
132 }
133 }
134
s390_cpudef_group_featoff_greater(uint8_t gen,uint8_t ec_ga,S390FeatGroup group)135 void s390_cpudef_group_featoff_greater(uint8_t gen, uint8_t ec_ga,
136 S390FeatGroup group)
137 {
138 const S390FeatGroupDef *group_def = s390_feat_group_def(group);
139 S390FeatBitmap group_def_off;
140 int i;
141
142 bitmap_complement(group_def_off, group_def->feat, S390_FEAT_MAX);
143
144 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
145 const S390CPUDef *cpu_def = &s390_cpu_defs[i];
146
147 if (cpu_def->gen < gen) {
148 continue;
149 }
150 if (cpu_def->gen == gen && cpu_def->ec_ga < ec_ga) {
151 continue;
152 }
153
154 bitmap_and((unsigned long *)&cpu_def->default_feat,
155 cpu_def->default_feat, group_def_off, S390_FEAT_MAX);
156 }
157 }
158
s390_get_hmfai(void)159 uint32_t s390_get_hmfai(void)
160 {
161 static S390CPU *cpu;
162
163 if (!cpu) {
164 cpu = S390_CPU(qemu_get_cpu(0));
165 }
166
167 if (!cpu || !cpu->model) {
168 return 0;
169 }
170 return cpu->model->def->hmfai;
171 }
172
s390_get_mha_pow(void)173 uint8_t s390_get_mha_pow(void)
174 {
175 static S390CPU *cpu;
176
177 if (!cpu) {
178 cpu = S390_CPU(qemu_get_cpu(0));
179 }
180
181 if (!cpu || !cpu->model) {
182 return 0;
183 }
184 return cpu->model->def->mha_pow;
185 }
186
s390_get_ibc_val(void)187 uint32_t s390_get_ibc_val(void)
188 {
189 uint16_t unblocked_ibc, lowest_ibc;
190 static S390CPU *cpu;
191
192 if (!cpu) {
193 cpu = S390_CPU(qemu_get_cpu(0));
194 }
195
196 if (!cpu || !cpu->model) {
197 return 0;
198 }
199 unblocked_ibc = s390_ibc_from_cpu_model(cpu->model);
200 lowest_ibc = cpu->model->lowest_ibc;
201 /* the lowest_ibc always has to be <= unblocked_ibc */
202 if (!lowest_ibc || lowest_ibc > unblocked_ibc) {
203 return 0;
204 }
205 return ((uint32_t) lowest_ibc << 16) | unblocked_ibc;
206 }
207
s390_get_feat_block(S390FeatType type,uint8_t * data)208 void s390_get_feat_block(S390FeatType type, uint8_t *data)
209 {
210 S390CPU *cpu = S390_CPU(first_cpu);
211
212 if (!cpu || !cpu->model) {
213 return;
214 }
215 s390_fill_feat_block(cpu->model->features, type, data);
216 }
217
s390_has_feat(S390Feat feat)218 bool s390_has_feat(S390Feat feat)
219 {
220 static S390CPU *cpu;
221
222 if (!cpu) {
223 cpu = S390_CPU(qemu_get_cpu(0));
224 }
225
226 if (!cpu || !cpu->model) {
227 #ifdef CONFIG_KVM
228 if (kvm_enabled()) {
229 if (feat == S390_FEAT_VECTOR) {
230 return kvm_check_extension(kvm_state,
231 KVM_CAP_S390_VECTOR_REGISTERS);
232 }
233 if (feat == S390_FEAT_RUNTIME_INSTRUMENTATION) {
234 return kvm_s390_get_ri();
235 }
236 if (feat == S390_FEAT_MSA_EXT_3) {
237 return true;
238 }
239 }
240 #endif
241 if (feat == S390_FEAT_ZPCI) {
242 return true;
243 }
244 return 0;
245 }
246
247 #ifndef CONFIG_USER_ONLY
248 if (s390_is_pv()) {
249 switch (feat) {
250 case S390_FEAT_DIAG_318:
251 case S390_FEAT_HPMA2:
252 case S390_FEAT_SIE_F2:
253 case S390_FEAT_SIE_SKEY:
254 case S390_FEAT_SIE_GPERE:
255 case S390_FEAT_SIE_SIIF:
256 case S390_FEAT_SIE_SIGPIF:
257 case S390_FEAT_SIE_IB:
258 case S390_FEAT_SIE_CEI:
259 case S390_FEAT_SIE_KSS:
260 case S390_FEAT_SIE_GSLS:
261 case S390_FEAT_SIE_64BSCAO:
262 case S390_FEAT_SIE_CMMA:
263 case S390_FEAT_SIE_PFMFI:
264 case S390_FEAT_SIE_IBS:
265 case S390_FEAT_CONFIGURATION_TOPOLOGY:
266 return false;
267 break;
268 default:
269 break;
270 }
271 }
272 #endif
273 return test_bit(feat, cpu->model->features);
274 }
275
s390_get_gen_for_cpu_type(uint16_t type)276 uint8_t s390_get_gen_for_cpu_type(uint16_t type)
277 {
278 int i;
279
280 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
281 if (s390_cpu_defs[i].type == type) {
282 return s390_cpu_defs[i].gen;
283 }
284 }
285 return 0;
286 }
287
s390_find_cpu_def(uint16_t type,uint8_t gen,uint8_t ec_ga,S390FeatBitmap features)288 const S390CPUDef *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga,
289 S390FeatBitmap features)
290 {
291 const S390CPUDef *last_compatible = NULL;
292 const S390CPUDef *matching_cpu_type = NULL;
293 int i;
294
295 if (!gen) {
296 ec_ga = 0;
297 }
298 if (!gen && type) {
299 gen = s390_get_gen_for_cpu_type(type);
300 }
301
302 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
303 const S390CPUDef *def = &s390_cpu_defs[i];
304 S390FeatBitmap missing;
305
306 /* don't even try newer generations if we know the generation */
307 if (gen) {
308 if (def->gen > gen) {
309 break;
310 } else if (def->gen == gen && ec_ga && def->ec_ga > ec_ga) {
311 break;
312 }
313 }
314
315 if (features) {
316 /* see if the model satisfies the minimum features */
317 bitmap_andnot(missing, def->base_feat, features, S390_FEAT_MAX);
318 /*
319 * Ignore certain features that are in the base model, but not
320 * relevant for the search (esp. MSA subfunctions).
321 */
322 bitmap_andnot(missing, missing, ignored_base_feat, S390_FEAT_MAX);
323 if (!bitmap_empty(missing, S390_FEAT_MAX)) {
324 break;
325 }
326 }
327
328 /* stop the search if we found the exact model */
329 if (def->type == type && def->ec_ga == ec_ga) {
330 return def;
331 }
332 /* remember if we've at least seen one with the same cpu type */
333 if (def->type == type) {
334 matching_cpu_type = def;
335 }
336 last_compatible = def;
337 }
338 /* prefer the model with the same cpu type, esp. don't take the BC for EC */
339 if (matching_cpu_type) {
340 return matching_cpu_type;
341 }
342 return last_compatible;
343 }
344
s390_print_cpu_model_list_entry(gpointer data,gpointer user_data)345 static void s390_print_cpu_model_list_entry(gpointer data, gpointer user_data)
346 {
347 const S390CPUClass *scc = S390_CPU_CLASS((ObjectClass *)data);
348 CPUClass *cc = CPU_CLASS(scc);
349 char *name = g_strdup(object_class_get_name((ObjectClass *)data));
350 g_autoptr(GString) details = g_string_new("");
351
352 if (scc->is_static) {
353 g_string_append(details, "static, ");
354 }
355 if (scc->is_migration_safe) {
356 g_string_append(details, "migration-safe, ");
357 }
358 if (cc->deprecation_note) {
359 g_string_append(details, "deprecated, ");
360 }
361 if (details->len) {
362 /* cull trailing ', ' */
363 g_string_truncate(details, details->len - 2);
364 }
365
366 /* strip off the -s390x-cpu */
367 g_strrstr(name, "-" TYPE_S390_CPU)[0] = 0;
368 if (details->len) {
369 qemu_printf(" %-15s %-35s (%s)\n", name, scc->desc, details->str);
370 } else {
371 qemu_printf(" %-15s %-35s\n", name, scc->desc);
372 }
373 g_free(name);
374 }
375
s390_cpu_list_compare(gconstpointer a,gconstpointer b)376 static gint s390_cpu_list_compare(gconstpointer a, gconstpointer b)
377 {
378 const S390CPUClass *cc_a = S390_CPU_CLASS((ObjectClass *)a);
379 const S390CPUClass *cc_b = S390_CPU_CLASS((ObjectClass *)b);
380 const char *name_a = object_class_get_name((ObjectClass *)a);
381 const char *name_b = object_class_get_name((ObjectClass *)b);
382
383 /*
384 * Move qemu, host and max to the top of the list, qemu first, host second,
385 * max third.
386 */
387 if (name_a[0] == 'q') {
388 return -1;
389 } else if (name_b[0] == 'q') {
390 return 1;
391 } else if (name_a[0] == 'h') {
392 return -1;
393 } else if (name_b[0] == 'h') {
394 return 1;
395 } else if (name_a[0] == 'm') {
396 return -1;
397 } else if (name_b[0] == 'm') {
398 return 1;
399 }
400
401 /* keep the same order we have in our table (sorted by release date) */
402 if (cc_a->cpu_def != cc_b->cpu_def) {
403 return cc_a->cpu_def - cc_b->cpu_def;
404 }
405
406 /* exact same definition - list base model first */
407 return cc_a->is_static ? -1 : 1;
408 }
409
s390_cpu_list(void)410 void s390_cpu_list(void)
411 {
412 S390FeatGroup group;
413 S390Feat feat;
414 GSList *list;
415
416 qemu_printf("Available CPUs:\n");
417 list = object_class_get_list(TYPE_S390_CPU, false);
418 list = g_slist_sort(list, s390_cpu_list_compare);
419 g_slist_foreach(list, s390_print_cpu_model_list_entry, NULL);
420 g_slist_free(list);
421
422 qemu_printf("\nRecognized feature flags:\n");
423 for (feat = 0; feat < S390_FEAT_MAX; feat++) {
424 const S390FeatDef *def = s390_feat_def(feat);
425
426 qemu_printf(" %-20s %s\n", def->name, def->desc);
427 }
428
429 qemu_printf("\nRecognized feature groups:\n");
430 for (group = 0; group < S390_FEAT_GROUP_MAX; group++) {
431 const S390FeatGroupDef *def = s390_feat_group_def(group);
432
433 qemu_printf(" %-20s %s\n", def->name, def->desc);
434 }
435 }
436
check_consistency(const S390CPUModel * model)437 static void check_consistency(const S390CPUModel *model)
438 {
439 static int dep[][2] = {
440 { S390_FEAT_IPTE_RANGE, S390_FEAT_DAT_ENH },
441 { S390_FEAT_IDTE_SEGMENT, S390_FEAT_DAT_ENH },
442 { S390_FEAT_IDTE_REGION, S390_FEAT_DAT_ENH },
443 { S390_FEAT_IDTE_REGION, S390_FEAT_IDTE_SEGMENT },
444 { S390_FEAT_LOCAL_TLB_CLEARING, S390_FEAT_DAT_ENH},
445 { S390_FEAT_LONG_DISPLACEMENT_FAST, S390_FEAT_LONG_DISPLACEMENT },
446 { S390_FEAT_DFP_FAST, S390_FEAT_DFP },
447 { S390_FEAT_TRANSACTIONAL_EXE, S390_FEAT_STFLE_49 },
448 { S390_FEAT_EDAT_2, S390_FEAT_EDAT},
449 { S390_FEAT_MSA_EXT_5, S390_FEAT_KIMD_SHA_512 },
450 { S390_FEAT_MSA_EXT_5, S390_FEAT_KLMD_SHA_512 },
451 { S390_FEAT_MSA_EXT_4, S390_FEAT_MSA_EXT_3 },
452 { S390_FEAT_SIE_CMMA, S390_FEAT_CMM },
453 { S390_FEAT_SIE_CMMA, S390_FEAT_SIE_GSLS },
454 { S390_FEAT_SIE_PFMFI, S390_FEAT_EDAT },
455 { S390_FEAT_MSA_EXT_8, S390_FEAT_MSA_EXT_3 },
456 { S390_FEAT_MSA_EXT_9, S390_FEAT_MSA_EXT_3 },
457 { S390_FEAT_MSA_EXT_9, S390_FEAT_MSA_EXT_4 },
458 { S390_FEAT_MULTIPLE_EPOCH, S390_FEAT_TOD_CLOCK_STEERING },
459 { S390_FEAT_VECTOR_PACKED_DECIMAL, S390_FEAT_VECTOR },
460 { S390_FEAT_VECTOR_PACKED_DECIMAL_ENH, S390_FEAT_VECTOR_PACKED_DECIMAL },
461 { S390_FEAT_VECTOR_PACKED_DECIMAL_ENH2, S390_FEAT_VECTOR_PACKED_DECIMAL_ENH },
462 { S390_FEAT_VECTOR_PACKED_DECIMAL_ENH3, S390_FEAT_VECTOR_PACKED_DECIMAL_ENH2 },
463 { S390_FEAT_VECTOR_ENH, S390_FEAT_VECTOR },
464 { S390_FEAT_VECTOR_ENH2, S390_FEAT_VECTOR_ENH },
465 { S390_FEAT_VECTOR_ENH3, S390_FEAT_VECTOR_ENH2 },
466 { S390_FEAT_INSTRUCTION_EXEC_PROT, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2 },
467 { S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2, S390_FEAT_ESOP },
468 { S390_FEAT_CMM_NT, S390_FEAT_CMM },
469 { S390_FEAT_GUARDED_STORAGE, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2 },
470 { S390_FEAT_MULTIPLE_EPOCH, S390_FEAT_STORE_CLOCK_FAST },
471 { S390_FEAT_MULTIPLE_EPOCH, S390_FEAT_TOD_CLOCK_STEERING },
472 { S390_FEAT_SEMAPHORE_ASSIST, S390_FEAT_STFLE_49 },
473 { S390_FEAT_KIMD_SHA3_224, S390_FEAT_MSA },
474 { S390_FEAT_KIMD_SHA3_256, S390_FEAT_MSA },
475 { S390_FEAT_KIMD_SHA3_384, S390_FEAT_MSA },
476 { S390_FEAT_KIMD_SHA3_512, S390_FEAT_MSA },
477 { S390_FEAT_KIMD_SHAKE_128, S390_FEAT_MSA },
478 { S390_FEAT_KIMD_SHAKE_256, S390_FEAT_MSA },
479 { S390_FEAT_KLMD_SHA3_224, S390_FEAT_MSA },
480 { S390_FEAT_KLMD_SHA3_256, S390_FEAT_MSA },
481 { S390_FEAT_KLMD_SHA3_384, S390_FEAT_MSA },
482 { S390_FEAT_KLMD_SHA3_512, S390_FEAT_MSA },
483 { S390_FEAT_KLMD_SHAKE_128, S390_FEAT_MSA },
484 { S390_FEAT_KLMD_SHAKE_256, S390_FEAT_MSA },
485 { S390_FEAT_KMAC_HMAC_SHA_224, S390_FEAT_MSA_EXT_3 },
486 { S390_FEAT_KMAC_HMAC_SHA_256, S390_FEAT_MSA_EXT_3 },
487 { S390_FEAT_KMAC_HMAC_SHA_384, S390_FEAT_MSA_EXT_3 },
488 { S390_FEAT_KMAC_HMAC_SHA_512, S390_FEAT_MSA_EXT_3 },
489 { S390_FEAT_KMAC_HMAC_ESHA_224, S390_FEAT_MSA_EXT_3 },
490 { S390_FEAT_KMAC_HMAC_ESHA_256, S390_FEAT_MSA_EXT_3 },
491 { S390_FEAT_KMAC_HMAC_ESHA_384, S390_FEAT_MSA_EXT_3 },
492 { S390_FEAT_KMAC_HMAC_ESHA_512, S390_FEAT_MSA_EXT_3 },
493 { S390_FEAT_KM_FULL_XTS_AES_128, S390_FEAT_MSA_EXT_4 },
494 { S390_FEAT_KM_FULL_XTS_AES_256, S390_FEAT_MSA_EXT_4 },
495 { S390_FEAT_KM_FULL_XTS_EAES_128, S390_FEAT_MSA_EXT_4 },
496 { S390_FEAT_KM_FULL_XTS_EAES_256, S390_FEAT_MSA_EXT_4 },
497 { S390_FEAT_PRNO_TRNG_QRTCR, S390_FEAT_MSA_EXT_5 },
498 { S390_FEAT_PRNO_TRNG, S390_FEAT_MSA_EXT_5 },
499 { S390_FEAT_SIE_KSS, S390_FEAT_SIE_F2 },
500 { S390_FEAT_AP_QUERY_CONFIG_INFO, S390_FEAT_AP },
501 { S390_FEAT_AP_FACILITIES_TEST, S390_FEAT_AP },
502 { S390_FEAT_PTFF_QSIE, S390_FEAT_MULTIPLE_EPOCH },
503 { S390_FEAT_PTFF_QTOUE, S390_FEAT_MULTIPLE_EPOCH },
504 { S390_FEAT_PTFF_STOE, S390_FEAT_MULTIPLE_EPOCH },
505 { S390_FEAT_PTFF_STOUE, S390_FEAT_MULTIPLE_EPOCH },
506 { S390_FEAT_AP_QUEUE_INTERRUPT_CONTROL, S390_FEAT_AP },
507 { S390_FEAT_DIAG_318, S390_FEAT_EXTENDED_LENGTH_SCCB },
508 { S390_FEAT_NNPA, S390_FEAT_VECTOR },
509 { S390_FEAT_RDP, S390_FEAT_LOCAL_TLB_CLEARING },
510 { S390_FEAT_UV_FEAT_AP, S390_FEAT_AP },
511 { S390_FEAT_UV_FEAT_AP_INTR, S390_FEAT_UV_FEAT_AP },
512 { S390_FEAT_PFCR_QAF, S390_FEAT_CCF_BASE },
513 { S390_FEAT_PFCR_CSDST, S390_FEAT_CCF_BASE },
514 { S390_FEAT_PFCR_CSDSTG, S390_FEAT_CCF_BASE },
515 { S390_FEAT_PFCR_CSTST, S390_FEAT_CCF_BASE },
516 { S390_FEAT_PFCR_CSTSTG, S390_FEAT_CCF_BASE },
517 { S390_FEAT_INEFF_NC_TX, S390_FEAT_TRANSACTIONAL_EXE },
518 { S390_FEAT_PLO_CLO, S390_FEAT_PLO_EXT },
519 { S390_FEAT_PLO_CSO, S390_FEAT_PLO_EXT },
520 { S390_FEAT_PLO_DCSO, S390_FEAT_PLO_EXT },
521 { S390_FEAT_PLO_CSSTO, S390_FEAT_PLO_EXT },
522 { S390_FEAT_PLO_CSDSTO, S390_FEAT_PLO_EXT },
523 { S390_FEAT_PLO_CSTSTO, S390_FEAT_PLO_EXT },
524 { S390_FEAT_PLO_TCS, S390_FEAT_PLO_EXT },
525 { S390_FEAT_PLO_TCSG, S390_FEAT_PLO_EXT },
526 { S390_FEAT_PLO_TCSX, S390_FEAT_PLO_EXT },
527 { S390_FEAT_PLO_TCSO, S390_FEAT_PLO_EXT },
528 { S390_FEAT_PLO_QCS, S390_FEAT_PLO_EXT },
529 { S390_FEAT_PLO_QCSG, S390_FEAT_PLO_EXT },
530 { S390_FEAT_PLO_QCSX, S390_FEAT_PLO_EXT },
531 { S390_FEAT_PLO_QCSO, S390_FEAT_PLO_EXT },
532 { S390_FEAT_PLO_LO, S390_FEAT_PLO_EXT },
533 { S390_FEAT_PLO_DLX, S390_FEAT_PLO_EXT },
534 { S390_FEAT_PLO_DLO, S390_FEAT_PLO_EXT },
535 { S390_FEAT_PLO_TL, S390_FEAT_PLO_EXT },
536 { S390_FEAT_PLO_TLG, S390_FEAT_PLO_EXT },
537 { S390_FEAT_PLO_TLX, S390_FEAT_PLO_EXT },
538 { S390_FEAT_PLO_TLO, S390_FEAT_PLO_EXT },
539 { S390_FEAT_PLO_QL, S390_FEAT_PLO_EXT },
540 { S390_FEAT_PLO_QLG, S390_FEAT_PLO_EXT },
541 { S390_FEAT_PLO_QLX, S390_FEAT_PLO_EXT },
542 { S390_FEAT_PLO_QLO, S390_FEAT_PLO_EXT },
543 { S390_FEAT_PLO_STO, S390_FEAT_PLO_EXT },
544 { S390_FEAT_PLO_DST, S390_FEAT_PLO_EXT },
545 { S390_FEAT_PLO_DSTG, S390_FEAT_PLO_EXT },
546 { S390_FEAT_PLO_DSTX, S390_FEAT_PLO_EXT },
547 { S390_FEAT_PLO_DSTO, S390_FEAT_PLO_EXT },
548 { S390_FEAT_PLO_TST, S390_FEAT_PLO_EXT },
549 { S390_FEAT_PLO_TSTG, S390_FEAT_PLO_EXT },
550 { S390_FEAT_PLO_TSTX, S390_FEAT_PLO_EXT },
551 { S390_FEAT_PLO_TSTO, S390_FEAT_PLO_EXT },
552 { S390_FEAT_PLO_QST, S390_FEAT_PLO_EXT },
553 { S390_FEAT_PLO_QSTG, S390_FEAT_PLO_EXT },
554 { S390_FEAT_PLO_QSTX, S390_FEAT_PLO_EXT },
555 { S390_FEAT_PLO_QSTO, S390_FEAT_PLO_EXT },
556 };
557 int i;
558
559 for (i = 0; i < ARRAY_SIZE(dep); i++) {
560 if (test_bit(dep[i][0], model->features) &&
561 !test_bit(dep[i][1], model->features)) {
562 warn_report("\'%s\' requires \'%s\'.",
563 s390_feat_def(dep[i][0])->name,
564 s390_feat_def(dep[i][1])->name);
565 }
566 }
567 }
568
error_prepend_missing_feat(const char * name,void * opaque)569 static void error_prepend_missing_feat(const char *name, void *opaque)
570 {
571 error_prepend((Error **) opaque, "%s ", name);
572 }
573
check_compat_model_failed(Error ** errp,const S390CPUModel * max_model,const char * msg)574 static void check_compat_model_failed(Error **errp,
575 const S390CPUModel *max_model,
576 const char *msg)
577 {
578 error_setg(errp, "%s. Maximum supported model in the current configuration: \'%s\'",
579 msg, max_model->def->name);
580 error_append_hint(errp, "Consider a different accelerator, try \"-accel help\"\n");
581 return;
582 }
583
check_compatibility(const S390CPUModel * max_model,const S390CPUModel * model,Error ** errp)584 static bool check_compatibility(const S390CPUModel *max_model,
585 const S390CPUModel *model, Error **errp)
586 {
587 ERRP_GUARD();
588 S390FeatBitmap missing;
589
590 if (model->def->gen > max_model->def->gen) {
591 check_compat_model_failed(errp, max_model, "Selected CPU generation is too new");
592 return false;
593 } else if (model->def->gen == max_model->def->gen &&
594 model->def->ec_ga > max_model->def->ec_ga) {
595 check_compat_model_failed(errp, max_model, "Selected CPU GA level is too new");
596 return false;
597 }
598
599 #ifndef CONFIG_USER_ONLY
600 if (only_migratable && test_bit(S390_FEAT_UNPACK, model->features)) {
601 error_setg(errp, "The unpack facility is not compatible with "
602 "the --only-migratable option. You must remove either "
603 "the 'unpack' facility or the --only-migratable option");
604 return false;
605 }
606 #endif
607
608 /* detect the missing features to properly report them */
609 bitmap_andnot(missing, model->features, max_model->features, S390_FEAT_MAX);
610 if (bitmap_empty(missing, S390_FEAT_MAX)) {
611 return true;
612 }
613
614 error_setg(errp, " ");
615 s390_feat_bitmap_to_ascii(missing, errp, error_prepend_missing_feat);
616 error_prepend(errp, "Some features requested in the CPU model are not "
617 "available in the current configuration: ");
618 error_append_hint(errp,
619 "Consider a different accelerator, QEMU, or kernel version\n");
620 return false;
621 }
622
get_max_cpu_model(Error ** errp)623 S390CPUModel *get_max_cpu_model(Error **errp)
624 {
625 static S390CPUModel max_model;
626 static bool cached;
627
628 if (cached) {
629 return &max_model;
630 }
631
632 if (kvm_enabled()) {
633 if (!kvm_s390_get_host_cpu_model(&max_model, errp)) {
634 return NULL;
635 }
636 } else {
637 max_model.def = s390_find_cpu_def(QEMU_MAX_CPU_TYPE, QEMU_MAX_CPU_GEN,
638 QEMU_MAX_CPU_EC_GA, NULL);
639 bitmap_copy(max_model.features, qemu_max_cpu_feat, S390_FEAT_MAX);
640 }
641 cached = true;
642 return &max_model;
643 }
644
s390_realize_cpu_model(CPUState * cs,Error ** errp)645 void s390_realize_cpu_model(CPUState *cs, Error **errp)
646 {
647 ERRP_GUARD();
648 S390CPUClass *xcc = S390_CPU_GET_CLASS(cs);
649 S390CPU *cpu = S390_CPU(cs);
650 const S390CPUModel *max_model;
651
652 if (xcc->kvm_required && !kvm_enabled()) {
653 error_setg(errp, "CPU definition requires KVM");
654 return;
655 }
656
657 if (!cpu->model) {
658 /* no host model support -> perform compatibility stuff */
659 apply_cpu_model(NULL, errp);
660 return;
661 }
662
663 max_model = get_max_cpu_model(errp);
664 if (!max_model) {
665 error_prepend(errp, "CPU models are not available: ");
666 return;
667 }
668
669 /* copy over properties that can vary */
670 cpu->model->lowest_ibc = max_model->lowest_ibc;
671 cpu->model->cpu_id = max_model->cpu_id;
672 cpu->model->cpu_id_format = max_model->cpu_id_format;
673 cpu->model->cpu_ver = max_model->cpu_ver;
674
675 check_consistency(cpu->model);
676 if (!check_compatibility(max_model, cpu->model, errp)) {
677 return;
678 }
679
680 apply_cpu_model(cpu->model, errp);
681
682 #if !defined(CONFIG_USER_ONLY)
683 cpu->env.cpuid = s390_cpuid_from_cpu_model(cpu->model);
684 if (tcg_enabled()) {
685 cpu->env.cpuid = deposit64(cpu->env.cpuid, CPU_PHYS_ADDR_SHIFT,
686 CPU_PHYS_ADDR_BITS, cpu->env.core_id);
687 }
688 #endif
689 }
690
get_feature(Object * obj,Visitor * v,const char * name,void * opaque,Error ** errp)691 static void get_feature(Object *obj, Visitor *v, const char *name,
692 void *opaque, Error **errp)
693 {
694 S390Feat feat = (S390Feat) (uintptr_t) opaque;
695 S390CPU *cpu = S390_CPU(obj);
696 bool value;
697
698 if (!cpu->model) {
699 error_setg(errp, "Details about the host CPU model are not available, "
700 "features cannot be queried.");
701 return;
702 }
703
704 value = test_bit(feat, cpu->model->features);
705 visit_type_bool(v, name, &value, errp);
706 }
707
set_feature(Object * obj,Visitor * v,const char * name,void * opaque,Error ** errp)708 static void set_feature(Object *obj, Visitor *v, const char *name,
709 void *opaque, Error **errp)
710 {
711 S390Feat feat = (S390Feat) (uintptr_t) opaque;
712 DeviceState *dev = DEVICE(obj);
713 S390CPU *cpu = S390_CPU(obj);
714 bool value;
715
716 if (dev->realized) {
717 error_setg(errp, "Attempt to set property '%s' on '%s' after "
718 "it was realized", name, object_get_typename(obj));
719 return;
720 } else if (!cpu->model) {
721 error_setg(errp, "Details about the host CPU model are not available, "
722 "features cannot be changed.");
723 return;
724 }
725
726 if (!visit_type_bool(v, name, &value, errp)) {
727 return;
728 }
729 if (value) {
730 if (!test_bit(feat, cpu->model->def->full_feat)) {
731 error_setg(errp, "Feature '%s' is not available for CPU model '%s',"
732 " it was introduced with later models.",
733 name, cpu->model->def->name);
734 return;
735 }
736 set_bit(feat, cpu->model->features);
737 } else {
738 clear_bit(feat, cpu->model->features);
739 }
740 }
741
get_feature_group(Object * obj,Visitor * v,const char * name,void * opaque,Error ** errp)742 static void get_feature_group(Object *obj, Visitor *v, const char *name,
743 void *opaque, Error **errp)
744 {
745 S390FeatGroup group = (S390FeatGroup) (uintptr_t) opaque;
746 const S390FeatGroupDef *def = s390_feat_group_def(group);
747 S390CPU *cpu = S390_CPU(obj);
748 S390FeatBitmap tmp;
749 bool value;
750
751 if (!cpu->model) {
752 error_setg(errp, "Details about the host CPU model are not available, "
753 "features cannot be queried.");
754 return;
755 }
756
757 /* a group is enabled if all features are enabled */
758 bitmap_and(tmp, cpu->model->features, def->feat, S390_FEAT_MAX);
759 value = bitmap_equal(tmp, def->feat, S390_FEAT_MAX);
760 visit_type_bool(v, name, &value, errp);
761 }
762
set_feature_group(Object * obj,Visitor * v,const char * name,void * opaque,Error ** errp)763 static void set_feature_group(Object *obj, Visitor *v, const char *name,
764 void *opaque, Error **errp)
765 {
766 S390FeatGroup group = (S390FeatGroup) (uintptr_t) opaque;
767 const S390FeatGroupDef *def = s390_feat_group_def(group);
768 DeviceState *dev = DEVICE(obj);
769 S390CPU *cpu = S390_CPU(obj);
770 bool value;
771
772 if (dev->realized) {
773 error_setg(errp, "Attempt to set property '%s' on '%s' after "
774 "it was realized", name, object_get_typename(obj));
775 return;
776 } else if (!cpu->model) {
777 error_setg(errp, "Details about the host CPU model are not available, "
778 "features cannot be changed.");
779 return;
780 }
781
782 if (!visit_type_bool(v, name, &value, errp)) {
783 return;
784 }
785 if (value) {
786 /* groups are added in one shot, so an intersect is sufficient */
787 if (!bitmap_intersects(def->feat, cpu->model->def->full_feat,
788 S390_FEAT_MAX)) {
789 error_setg(errp, "Group '%s' is not available for CPU model '%s',"
790 " it was introduced with later models.",
791 name, cpu->model->def->name);
792 return;
793 }
794 bitmap_or(cpu->model->features, cpu->model->features, def->feat,
795 S390_FEAT_MAX);
796 } else {
797 bitmap_andnot(cpu->model->features, cpu->model->features, def->feat,
798 S390_FEAT_MAX);
799 }
800 }
801
s390_cpu_model_initfn(Object * obj)802 static void s390_cpu_model_initfn(Object *obj)
803 {
804 S390CPU *cpu = S390_CPU(obj);
805 S390CPUClass *xcc = S390_CPU_GET_CLASS(cpu);
806
807 cpu->model = g_malloc0(sizeof(*cpu->model));
808 /* copy the model, so we can modify it */
809 cpu->model->def = xcc->cpu_def;
810 if (xcc->is_static) {
811 /* base model - features will never change */
812 bitmap_copy(cpu->model->features, cpu->model->def->base_feat,
813 S390_FEAT_MAX);
814 } else {
815 /* latest model - features can change */
816 bitmap_copy(cpu->model->features,
817 cpu->model->def->default_feat, S390_FEAT_MAX);
818 }
819 }
820
821 static S390CPUModel s390_qemu_cpu_model;
822
823 /* Set the qemu CPU model (on machine initialization). Must not be called
824 * once CPUs have been created.
825 */
s390_set_qemu_cpu_model(uint16_t type,uint8_t gen,uint8_t ec_ga,const S390FeatInit feat_init)826 void s390_set_qemu_cpu_model(uint16_t type, uint8_t gen, uint8_t ec_ga,
827 const S390FeatInit feat_init)
828 {
829 const S390CPUDef *def = s390_find_cpu_def(type, gen, ec_ga, NULL);
830
831 g_assert(def);
832 g_assert(QTAILQ_EMPTY_RCU(&cpus_queue));
833
834 /* build the CPU model */
835 s390_qemu_cpu_model.def = def;
836 bitmap_zero(s390_qemu_cpu_model.features, S390_FEAT_MAX);
837 s390_init_feat_bitmap(feat_init, s390_qemu_cpu_model.features);
838 }
839
s390_qemu_cpu_model_initfn(Object * obj)840 static void s390_qemu_cpu_model_initfn(Object *obj)
841 {
842 S390CPU *cpu = S390_CPU(obj);
843
844 cpu->model = g_malloc0(sizeof(*cpu->model));
845 /* copy the CPU model so we can modify it */
846 memcpy(cpu->model, &s390_qemu_cpu_model, sizeof(*cpu->model));
847 }
848
s390_max_cpu_model_initfn(Object * obj)849 static void s390_max_cpu_model_initfn(Object *obj)
850 {
851 const S390CPUModel *max_model;
852 S390CPU *cpu = S390_CPU(obj);
853 Error *local_err = NULL;
854
855 if (kvm_enabled() && !kvm_s390_cpu_models_supported()) {
856 /* "max" and "host" always work, even without CPU model support */
857 return;
858 }
859
860 max_model = get_max_cpu_model(&local_err);
861 if (local_err) {
862 /* we expect errors only under KVM, when actually querying the kernel */
863 g_assert(kvm_enabled());
864 error_report_err(local_err);
865 /* fallback to unsupported CPU models */
866 return;
867 }
868
869 cpu->model = g_new(S390CPUModel, 1);
870 /* copy the CPU model so we can modify it */
871 memcpy(cpu->model, max_model, sizeof(*cpu->model));
872 }
873
s390_cpu_model_finalize(Object * obj)874 static void s390_cpu_model_finalize(Object *obj)
875 {
876 S390CPU *cpu = S390_CPU(obj);
877
878 g_free(cpu->model);
879 cpu->model = NULL;
880 }
881
get_is_migration_safe(Object * obj,Error ** errp)882 static bool get_is_migration_safe(Object *obj, Error **errp)
883 {
884 return S390_CPU_GET_CLASS(obj)->is_migration_safe;
885 }
886
get_is_static(Object * obj,Error ** errp)887 static bool get_is_static(Object *obj, Error **errp)
888 {
889 return S390_CPU_GET_CLASS(obj)->is_static;
890 }
891
get_description(Object * obj,Error ** errp)892 static char *get_description(Object *obj, Error **errp)
893 {
894 return g_strdup(S390_CPU_GET_CLASS(obj)->desc);
895 }
896
s390_cpu_model_class_register_props(ObjectClass * oc)897 void s390_cpu_model_class_register_props(ObjectClass *oc)
898 {
899 S390FeatGroup group;
900 S390Feat feat;
901
902 object_class_property_add_bool(oc, "migration-safe", get_is_migration_safe,
903 NULL);
904 object_class_property_add_bool(oc, "static", get_is_static,
905 NULL);
906 object_class_property_add_str(oc, "description", get_description, NULL);
907
908 for (feat = 0; feat < S390_FEAT_MAX; feat++) {
909 const S390FeatDef *def = s390_feat_def(feat);
910 object_class_property_add(oc, def->name, "bool", get_feature,
911 set_feature, NULL, (void *) feat);
912 object_class_property_set_description(oc, def->name, def->desc);
913 }
914 for (group = 0; group < S390_FEAT_GROUP_MAX; group++) {
915 const S390FeatGroupDef *def = s390_feat_group_def(group);
916 object_class_property_add(oc, def->name, "bool", get_feature_group,
917 set_feature_group, NULL, (void *) group);
918 object_class_property_set_description(oc, def->name, def->desc);
919 }
920 }
921
922 #ifdef CONFIG_KVM
s390_host_cpu_model_class_init(ObjectClass * oc,void * data)923 static void s390_host_cpu_model_class_init(ObjectClass *oc, void *data)
924 {
925 S390CPUClass *xcc = S390_CPU_CLASS(oc);
926
927 xcc->kvm_required = true;
928 xcc->desc = "KVM only: All recognized features";
929 }
930 #endif
931
s390_base_cpu_model_class_init(ObjectClass * oc,void * data)932 static void s390_base_cpu_model_class_init(ObjectClass *oc, void *data)
933 {
934 S390CPUClass *xcc = S390_CPU_CLASS(oc);
935
936 /* all base models are migration safe */
937 xcc->cpu_def = (const S390CPUDef *) data;
938 xcc->is_migration_safe = true;
939 xcc->is_static = true;
940 xcc->desc = xcc->cpu_def->desc;
941 }
942
s390_cpu_model_class_init(ObjectClass * oc,void * data)943 static void s390_cpu_model_class_init(ObjectClass *oc, void *data)
944 {
945 S390CPUClass *xcc = S390_CPU_CLASS(oc);
946
947 /* model that can change between QEMU versions */
948 xcc->cpu_def = (const S390CPUDef *) data;
949 xcc->is_migration_safe = true;
950 xcc->desc = xcc->cpu_def->desc;
951 }
952
s390_qemu_cpu_model_class_init(ObjectClass * oc,void * data)953 static void s390_qemu_cpu_model_class_init(ObjectClass *oc, void *data)
954 {
955 S390CPUClass *xcc = S390_CPU_CLASS(oc);
956
957 xcc->is_migration_safe = true;
958 xcc->desc = g_strdup_printf("QEMU Virtual CPU version %s",
959 qemu_hw_version());
960 }
961
s390_max_cpu_model_class_init(ObjectClass * oc,void * data)962 static void s390_max_cpu_model_class_init(ObjectClass *oc, void *data)
963 {
964 S390CPUClass *xcc = S390_CPU_CLASS(oc);
965
966 /*
967 * The "max" model is neither static nor migration safe. Under KVM
968 * it represents the "host" model. Under TCG it represents the "qemu" CPU
969 * model of the latest QEMU machine.
970 */
971 xcc->desc =
972 "Enables all features supported by the accelerator in the current host";
973 }
974
975 /* Generate type name for a cpu model. Caller has to free the string. */
s390_cpu_type_name(const char * model_name)976 static char *s390_cpu_type_name(const char *model_name)
977 {
978 return g_strdup_printf(S390_CPU_TYPE_NAME("%s"), model_name);
979 }
980
981 /* Generate type name for a base cpu model. Caller has to free the string. */
s390_base_cpu_type_name(const char * model_name)982 static char *s390_base_cpu_type_name(const char *model_name)
983 {
984 return g_strdup_printf(S390_CPU_TYPE_NAME("%s-base"), model_name);
985 }
986
s390_cpu_class_by_name(const char * name)987 ObjectClass *s390_cpu_class_by_name(const char *name)
988 {
989 char *typename = s390_cpu_type_name(name);
990 ObjectClass *oc;
991
992 oc = object_class_by_name(typename);
993 g_free(typename);
994 return oc;
995 }
996
997 static const TypeInfo qemu_s390_cpu_type_info = {
998 .name = S390_CPU_TYPE_NAME("qemu"),
999 .parent = TYPE_S390_CPU,
1000 .instance_init = s390_qemu_cpu_model_initfn,
1001 .instance_finalize = s390_cpu_model_finalize,
1002 .class_init = s390_qemu_cpu_model_class_init,
1003 };
1004
1005 static const TypeInfo max_s390_cpu_type_info = {
1006 .name = S390_CPU_TYPE_NAME("max"),
1007 .parent = TYPE_S390_CPU,
1008 .instance_init = s390_max_cpu_model_initfn,
1009 .instance_finalize = s390_cpu_model_finalize,
1010 .class_init = s390_max_cpu_model_class_init,
1011 };
1012
1013 #ifdef CONFIG_KVM
1014 static const TypeInfo host_s390_cpu_type_info = {
1015 .name = S390_CPU_TYPE_NAME("host"),
1016 .parent = S390_CPU_TYPE_NAME("max"),
1017 .class_init = s390_host_cpu_model_class_init,
1018 };
1019 #endif
1020
init_ignored_base_feat(void)1021 static void init_ignored_base_feat(void)
1022 {
1023 static const int feats[] = {
1024 /* MSA subfunctions that could not be available on certain machines */
1025 S390_FEAT_KMAC_DEA,
1026 S390_FEAT_KMAC_TDEA_128,
1027 S390_FEAT_KMAC_TDEA_192,
1028 S390_FEAT_KMC_DEA,
1029 S390_FEAT_KMC_TDEA_128,
1030 S390_FEAT_KMC_TDEA_192,
1031 S390_FEAT_KM_DEA,
1032 S390_FEAT_KM_TDEA_128,
1033 S390_FEAT_KM_TDEA_192,
1034 S390_FEAT_KIMD_SHA_1,
1035 S390_FEAT_KLMD_SHA_1,
1036 /* CSSKE is deprecated on newer generations */
1037 S390_FEAT_CONDITIONAL_SSKE,
1038 };
1039 int i;
1040
1041 for (i = 0; i < ARRAY_SIZE(feats); i++) {
1042 set_bit(feats[i], ignored_base_feat);
1043 }
1044 }
1045
register_types(void)1046 static void register_types(void)
1047 {
1048 static const S390FeatInit qemu_max_init = { S390_FEAT_LIST_QEMU_MAX };
1049 int i;
1050
1051 init_ignored_base_feat();
1052
1053 /* init all bitmaps from generated data initially */
1054 s390_init_feat_bitmap(qemu_max_init, qemu_max_cpu_feat);
1055 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
1056 s390_init_feat_bitmap(s390_cpu_defs[i].base_init,
1057 s390_cpu_defs[i].base_feat);
1058 s390_init_feat_bitmap(s390_cpu_defs[i].default_init,
1059 s390_cpu_defs[i].default_feat);
1060 s390_init_feat_bitmap(s390_cpu_defs[i].full_init,
1061 s390_cpu_defs[i].full_feat);
1062 }
1063
1064 /* initialize the qemu model with the maximum definition ("max" model) */
1065 s390_set_qemu_cpu_model(QEMU_MAX_CPU_TYPE, QEMU_MAX_CPU_GEN,
1066 QEMU_MAX_CPU_EC_GA, qemu_max_init);
1067
1068 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
1069 char *base_name = s390_base_cpu_type_name(s390_cpu_defs[i].name);
1070 TypeInfo ti_base = {
1071 .name = base_name,
1072 .parent = TYPE_S390_CPU,
1073 .instance_init = s390_cpu_model_initfn,
1074 .instance_finalize = s390_cpu_model_finalize,
1075 .class_init = s390_base_cpu_model_class_init,
1076 .class_data = (void *) &s390_cpu_defs[i],
1077 };
1078 char *name = s390_cpu_type_name(s390_cpu_defs[i].name);
1079 TypeInfo ti = {
1080 .name = name,
1081 .parent = TYPE_S390_CPU,
1082 .instance_init = s390_cpu_model_initfn,
1083 .instance_finalize = s390_cpu_model_finalize,
1084 .class_init = s390_cpu_model_class_init,
1085 .class_data = (void *) &s390_cpu_defs[i],
1086 };
1087
1088 type_register_static(&ti_base);
1089 type_register_static(&ti);
1090 g_free(base_name);
1091 g_free(name);
1092 }
1093
1094 type_register_static(&qemu_s390_cpu_type_info);
1095 type_register_static(&max_s390_cpu_type_info);
1096 #ifdef CONFIG_KVM
1097 type_register_static(&host_s390_cpu_type_info);
1098 #endif
1099 }
1100
1101 type_init(register_types)
1102