Include qapi/qmp/qbool.h exactly where needed
[qemu/ar7.git] / target / s390x / cpu_models.c
blob584c409a1902a6515460a27067b00e1489f02251
1 /*
2 * CPU models for s390x
4 * Copyright 2016 IBM Corp.
6 * Author(s): David Hildenbrand <dahi@linux.vnet.ibm.com>
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.
13 #include "qemu/osdep.h"
14 #include "cpu.h"
15 #include "internal.h"
16 #include "kvm_s390x.h"
17 #include "sysemu/kvm.h"
18 #include "qapi/error.h"
19 #include "qapi/visitor.h"
20 #include "qemu/error-report.h"
21 #include "qapi/qmp/qerror.h"
22 #include "qapi/qobject-input-visitor.h"
23 #include "qapi/qmp/qdict.h"
24 #ifndef CONFIG_USER_ONLY
25 #include "sysemu/arch_init.h"
26 #endif
28 #define CPUDEF_INIT(_type, _gen, _ec_ga, _mha_pow, _hmfai, _name, _desc) \
29 { \
30 .name = _name, \
31 .type = _type, \
32 .gen = _gen, \
33 .ec_ga = _ec_ga, \
34 .mha_pow = _mha_pow, \
35 .hmfai = _hmfai, \
36 .desc = _desc, \
37 .base_init = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _BASE }, \
38 .default_init = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _DEFAULT }, \
39 .full_init = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _FULL }, \
43 * CPU definiton list in order of release. For now, base features of a
44 * following release are always a subset of base features of the previous
45 * release. Same is correct for the other feature sets.
46 * A BC release always follows the corresponding EC release.
48 static S390CPUDef s390_cpu_defs[] = {
49 CPUDEF_INIT(0x2064, 7, 1, 38, 0x00000000U, "z900", "IBM zSeries 900 GA1"),
50 CPUDEF_INIT(0x2064, 7, 2, 38, 0x00000000U, "z900.2", "IBM zSeries 900 GA2"),
51 CPUDEF_INIT(0x2064, 7, 3, 38, 0x00000000U, "z900.3", "IBM zSeries 900 GA3"),
52 CPUDEF_INIT(0x2066, 7, 3, 38, 0x00000000U, "z800", "IBM zSeries 800 GA1"),
53 CPUDEF_INIT(0x2084, 8, 1, 38, 0x00000000U, "z990", "IBM zSeries 990 GA1"),
54 CPUDEF_INIT(0x2084, 8, 2, 38, 0x00000000U, "z990.2", "IBM zSeries 990 GA2"),
55 CPUDEF_INIT(0x2084, 8, 3, 38, 0x00000000U, "z990.3", "IBM zSeries 990 GA3"),
56 CPUDEF_INIT(0x2086, 8, 3, 38, 0x00000000U, "z890", "IBM zSeries 880 GA1"),
57 CPUDEF_INIT(0x2084, 8, 4, 38, 0x00000000U, "z990.4", "IBM zSeries 990 GA4"),
58 CPUDEF_INIT(0x2086, 8, 4, 38, 0x00000000U, "z890.2", "IBM zSeries 880 GA2"),
59 CPUDEF_INIT(0x2084, 8, 5, 38, 0x00000000U, "z990.5", "IBM zSeries 990 GA5"),
60 CPUDEF_INIT(0x2086, 8, 5, 38, 0x00000000U, "z890.3", "IBM zSeries 880 GA3"),
61 CPUDEF_INIT(0x2094, 9, 1, 40, 0x00000000U, "z9EC", "IBM System z9 EC GA1"),
62 CPUDEF_INIT(0x2094, 9, 2, 40, 0x00000000U, "z9EC.2", "IBM System z9 EC GA2"),
63 CPUDEF_INIT(0x2096, 9, 2, 40, 0x00000000U, "z9BC", "IBM System z9 BC GA1"),
64 CPUDEF_INIT(0x2094, 9, 3, 40, 0x00000000U, "z9EC.3", "IBM System z9 EC GA3"),
65 CPUDEF_INIT(0x2096, 9, 3, 40, 0x00000000U, "z9BC.2", "IBM System z9 BC GA2"),
66 CPUDEF_INIT(0x2097, 10, 1, 43, 0x00000000U, "z10EC", "IBM System z10 EC GA1"),
67 CPUDEF_INIT(0x2097, 10, 2, 43, 0x00000000U, "z10EC.2", "IBM System z10 EC GA2"),
68 CPUDEF_INIT(0x2098, 10, 2, 43, 0x00000000U, "z10BC", "IBM System z10 BC GA1"),
69 CPUDEF_INIT(0x2097, 10, 3, 43, 0x00000000U, "z10EC.3", "IBM System z10 EC GA3"),
70 CPUDEF_INIT(0x2098, 10, 3, 43, 0x00000000U, "z10BC.2", "IBM System z10 BC GA2"),
71 CPUDEF_INIT(0x2817, 11, 1, 44, 0x08000000U, "z196", "IBM zEnterprise 196 GA1"),
72 CPUDEF_INIT(0x2817, 11, 2, 44, 0x08000000U, "z196.2", "IBM zEnterprise 196 GA2"),
73 CPUDEF_INIT(0x2818, 11, 2, 44, 0x08000000U, "z114", "IBM zEnterprise 114 GA1"),
74 CPUDEF_INIT(0x2827, 12, 1, 44, 0x08000000U, "zEC12", "IBM zEnterprise EC12 GA1"),
75 CPUDEF_INIT(0x2827, 12, 2, 44, 0x08000000U, "zEC12.2", "IBM zEnterprise EC12 GA2"),
76 CPUDEF_INIT(0x2828, 12, 2, 44, 0x08000000U, "zBC12", "IBM zEnterprise BC12 GA1"),
77 CPUDEF_INIT(0x2964, 13, 1, 47, 0x08000000U, "z13", "IBM z13 GA1"),
78 CPUDEF_INIT(0x2964, 13, 2, 47, 0x08000000U, "z13.2", "IBM z13 GA2"),
79 CPUDEF_INIT(0x2965, 13, 2, 47, 0x08000000U, "z13s", "IBM z13s GA1"),
80 CPUDEF_INIT(0x3906, 14, 1, 47, 0x08000000U, "z14", "IBM z14 GA1"),
83 #define QEMU_MAX_CPU_TYPE 0x2827
84 #define QEMU_MAX_CPU_GEN 12
85 #define QEMU_MAX_CPU_EC_GA 2
86 static const S390FeatInit qemu_max_cpu_feat_init = { S390_FEAT_LIST_QEMU_MAX };
87 static S390FeatBitmap qemu_max_cpu_feat;
89 /* features part of a base model but not relevant for finding a base model */
90 S390FeatBitmap ignored_base_feat;
92 void s390_cpudef_featoff(uint8_t gen, uint8_t ec_ga, S390Feat feat)
94 const S390CPUDef *def;
96 def = s390_find_cpu_def(0, gen, ec_ga, NULL);
97 clear_bit(feat, (unsigned long *)&def->default_feat);
100 void s390_cpudef_featoff_greater(uint8_t gen, uint8_t ec_ga, S390Feat feat)
102 int i;
104 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
105 const S390CPUDef *def = &s390_cpu_defs[i];
107 if (def->gen < gen) {
108 continue;
110 if (def->gen == gen && def->ec_ga < ec_ga) {
111 continue;
114 clear_bit(feat, (unsigned long *)&def->default_feat);
118 uint32_t s390_get_hmfai(void)
120 static S390CPU *cpu;
122 if (!cpu) {
123 cpu = S390_CPU(qemu_get_cpu(0));
126 if (!cpu || !cpu->model) {
127 return 0;
129 return cpu->model->def->hmfai;
132 uint8_t s390_get_mha_pow(void)
134 static S390CPU *cpu;
136 if (!cpu) {
137 cpu = S390_CPU(qemu_get_cpu(0));
140 if (!cpu || !cpu->model) {
141 return 0;
143 return cpu->model->def->mha_pow;
146 uint32_t s390_get_ibc_val(void)
148 uint16_t unblocked_ibc, lowest_ibc;
149 static S390CPU *cpu;
151 if (!cpu) {
152 cpu = S390_CPU(qemu_get_cpu(0));
155 if (!cpu || !cpu->model) {
156 return 0;
158 unblocked_ibc = s390_ibc_from_cpu_model(cpu->model);
159 lowest_ibc = cpu->model->lowest_ibc;
160 /* the lowest_ibc always has to be <= unblocked_ibc */
161 if (!lowest_ibc || lowest_ibc > unblocked_ibc) {
162 return 0;
164 return ((uint32_t) lowest_ibc << 16) | unblocked_ibc;
167 void s390_get_feat_block(S390FeatType type, uint8_t *data)
169 static S390CPU *cpu;
171 if (!cpu) {
172 cpu = S390_CPU(qemu_get_cpu(0));
175 if (!cpu || !cpu->model) {
176 return;
178 s390_fill_feat_block(cpu->model->features, type, data);
181 bool s390_has_feat(S390Feat feat)
183 static S390CPU *cpu;
185 if (!cpu) {
186 cpu = S390_CPU(qemu_get_cpu(0));
189 if (!cpu || !cpu->model) {
190 #ifdef CONFIG_KVM
191 if (kvm_enabled()) {
192 if (feat == S390_FEAT_VECTOR) {
193 return kvm_check_extension(kvm_state,
194 KVM_CAP_S390_VECTOR_REGISTERS);
196 if (feat == S390_FEAT_RUNTIME_INSTRUMENTATION) {
197 return kvm_s390_get_ri();
199 if (feat == S390_FEAT_MSA_EXT_3) {
200 return true;
203 #endif
204 if (feat == S390_FEAT_ZPCI) {
205 return true;
207 return 0;
209 return test_bit(feat, cpu->model->features);
212 uint8_t s390_get_gen_for_cpu_type(uint16_t type)
214 int i;
216 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
217 if (s390_cpu_defs[i].type == type) {
218 return s390_cpu_defs[i].gen;
221 return 0;
224 const S390CPUDef *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga,
225 S390FeatBitmap features)
227 const S390CPUDef *last_compatible = NULL;
228 const S390CPUDef *matching_cpu_type = NULL;
229 int i;
231 if (!gen) {
232 ec_ga = 0;
234 if (!gen && type) {
235 gen = s390_get_gen_for_cpu_type(type);
238 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
239 const S390CPUDef *def = &s390_cpu_defs[i];
240 S390FeatBitmap missing;
242 /* don't even try newer generations if we know the generation */
243 if (gen) {
244 if (def->gen > gen) {
245 break;
246 } else if (def->gen == gen && ec_ga && def->ec_ga > ec_ga) {
247 break;
251 if (features) {
252 /* see if the model satisfies the minimum features */
253 bitmap_andnot(missing, def->base_feat, features, S390_FEAT_MAX);
255 * Ignore certain features that are in the base model, but not
256 * relevant for the search (esp. MSA subfunctions).
258 bitmap_andnot(missing, missing, ignored_base_feat, S390_FEAT_MAX);
259 if (!bitmap_empty(missing, S390_FEAT_MAX)) {
260 break;
264 /* stop the search if we found the exact model */
265 if (def->type == type && def->ec_ga == ec_ga) {
266 return def;
268 /* remember if we've at least seen one with the same cpu type */
269 if (def->type == type) {
270 matching_cpu_type = def;
272 last_compatible = def;
274 /* prefer the model with the same cpu type, esp. don't take the BC for EC */
275 if (matching_cpu_type) {
276 return matching_cpu_type;
278 return last_compatible;
281 static void s390_print_cpu_model_list_entry(gpointer data, gpointer user_data)
283 CPUListState *s = user_data;
284 const S390CPUClass *scc = S390_CPU_CLASS((ObjectClass *)data);
285 char *name = g_strdup(object_class_get_name((ObjectClass *)data));
286 const char *details = "";
288 if (scc->is_static) {
289 details = "(static, migration-safe)";
290 } else if (scc->is_migration_safe) {
291 details = "(migration-safe)";
294 /* strip off the -s390x-cpu */
295 g_strrstr(name, "-" TYPE_S390_CPU)[0] = 0;
296 (*s->cpu_fprintf)(s->file, "s390 %-15s %-35s %s\n", name, scc->desc,
297 details);
298 g_free(name);
301 static gint s390_cpu_list_compare(gconstpointer a, gconstpointer b)
303 const S390CPUClass *cc_a = S390_CPU_CLASS((ObjectClass *)a);
304 const S390CPUClass *cc_b = S390_CPU_CLASS((ObjectClass *)b);
305 const char *name_a = object_class_get_name((ObjectClass *)a);
306 const char *name_b = object_class_get_name((ObjectClass *)b);
308 /* move qemu and host to the top of the list, qemu first, host second */
309 if (name_a[0] == 'q') {
310 return -1;
311 } else if (name_b[0] == 'q') {
312 return 1;
313 } else if (name_a[0] == 'h') {
314 return -1;
315 } else if (name_b[0] == 'h') {
316 return 1;
319 /* keep the same order we have in our table (sorted by release date) */
320 if (cc_a->cpu_def != cc_b->cpu_def) {
321 return cc_a->cpu_def - cc_b->cpu_def;
324 /* exact same definition - list base model first */
325 return cc_a->is_static ? -1 : 1;
328 void s390_cpu_list(FILE *f, fprintf_function print)
330 CPUListState s = {
331 .file = f,
332 .cpu_fprintf = print,
334 S390FeatGroup group;
335 S390Feat feat;
336 GSList *list;
338 list = object_class_get_list(TYPE_S390_CPU, false);
339 list = g_slist_sort(list, s390_cpu_list_compare);
340 g_slist_foreach(list, s390_print_cpu_model_list_entry, &s);
341 g_slist_free(list);
343 (*print)(f, "\nRecognized feature flags:\n");
344 for (feat = 0; feat < S390_FEAT_MAX; feat++) {
345 const S390FeatDef *def = s390_feat_def(feat);
347 (*print)(f, "%-20s %-50s\n", def->name, def->desc);
350 (*print)(f, "\nRecognized feature groups:\n");
351 for (group = 0; group < S390_FEAT_GROUP_MAX; group++) {
352 const S390FeatGroupDef *def = s390_feat_group_def(group);
354 (*print)(f, "%-20s %-50s\n", def->name, def->desc);
358 static S390CPUModel *get_max_cpu_model(Error **errp);
360 #ifndef CONFIG_USER_ONLY
361 static void list_add_feat(const char *name, void *opaque);
363 static void check_unavailable_features(const S390CPUModel *max_model,
364 const S390CPUModel *model,
365 strList **unavailable)
367 S390FeatBitmap missing;
369 /* check general model compatibility */
370 if (max_model->def->gen < model->def->gen ||
371 (max_model->def->gen == model->def->gen &&
372 max_model->def->ec_ga < model->def->ec_ga)) {
373 list_add_feat("type", unavailable);
376 /* detect missing features if any to properly report them */
377 bitmap_andnot(missing, model->features, max_model->features,
378 S390_FEAT_MAX);
379 if (!bitmap_empty(missing, S390_FEAT_MAX)) {
380 s390_feat_bitmap_to_ascii(missing, unavailable, list_add_feat);
384 struct CpuDefinitionInfoListData {
385 CpuDefinitionInfoList *list;
386 S390CPUModel *model;
389 static void create_cpu_model_list(ObjectClass *klass, void *opaque)
391 struct CpuDefinitionInfoListData *cpu_list_data = opaque;
392 CpuDefinitionInfoList **cpu_list = &cpu_list_data->list;
393 CpuDefinitionInfoList *entry;
394 CpuDefinitionInfo *info;
395 char *name = g_strdup(object_class_get_name(klass));
396 S390CPUClass *scc = S390_CPU_CLASS(klass);
398 /* strip off the -s390x-cpu */
399 g_strrstr(name, "-" TYPE_S390_CPU)[0] = 0;
400 info = g_new0(CpuDefinitionInfo, 1);
401 info->name = name;
402 info->has_migration_safe = true;
403 info->migration_safe = scc->is_migration_safe;
404 info->q_static = scc->is_static;
405 info->q_typename = g_strdup(object_class_get_name(klass));
406 /* check for unavailable features */
407 if (cpu_list_data->model) {
408 Object *obj;
409 S390CPU *sc;
410 obj = object_new(object_class_get_name(klass));
411 sc = S390_CPU(obj);
412 if (sc->model) {
413 info->has_unavailable_features = true;
414 check_unavailable_features(cpu_list_data->model, sc->model,
415 &info->unavailable_features);
417 object_unref(obj);
420 entry = g_new0(CpuDefinitionInfoList, 1);
421 entry->value = info;
422 entry->next = *cpu_list;
423 *cpu_list = entry;
426 CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
428 struct CpuDefinitionInfoListData list_data = {
429 .list = NULL,
432 list_data.model = get_max_cpu_model(errp);
433 if (*errp) {
434 error_free(*errp);
435 *errp = NULL;
438 object_class_foreach(create_cpu_model_list, TYPE_S390_CPU, false,
439 &list_data);
441 return list_data.list;
444 static void cpu_model_from_info(S390CPUModel *model, const CpuModelInfo *info,
445 Error **errp)
447 const QDict *qdict = NULL;
448 const QDictEntry *e;
449 Visitor *visitor;
450 ObjectClass *oc;
451 S390CPU *cpu;
452 Object *obj;
454 if (info->props) {
455 qdict = qobject_to_qdict(info->props);
456 if (!qdict) {
457 error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
458 return;
462 oc = cpu_class_by_name(TYPE_S390_CPU, info->name);
463 if (!oc) {
464 error_setg(errp, "The CPU definition \'%s\' is unknown.", info->name);
465 return;
467 if (S390_CPU_CLASS(oc)->kvm_required && !kvm_enabled()) {
468 error_setg(errp, "The CPU definition '%s' requires KVM", info->name);
469 return;
471 obj = object_new(object_class_get_name(oc));
472 cpu = S390_CPU(obj);
474 if (!cpu->model) {
475 error_setg(errp, "Details about the host CPU model are not available, "
476 "it cannot be used.");
477 object_unref(obj);
478 return;
481 if (qdict) {
482 visitor = qobject_input_visitor_new(info->props);
483 visit_start_struct(visitor, NULL, NULL, 0, errp);
484 if (*errp) {
485 object_unref(obj);
486 return;
488 for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
489 object_property_set(obj, visitor, e->key, errp);
490 if (*errp) {
491 break;
494 if (!*errp) {
495 visit_check_struct(visitor, errp);
497 visit_end_struct(visitor, NULL);
498 visit_free(visitor);
499 if (*errp) {
500 object_unref(obj);
501 return;
505 /* copy the model and throw the cpu away */
506 memcpy(model, cpu->model, sizeof(*model));
507 object_unref(obj);
510 static void qdict_add_disabled_feat(const char *name, void *opaque)
512 qdict_put_bool(opaque, name, false);
515 static void qdict_add_enabled_feat(const char *name, void *opaque)
517 qdict_put_bool(opaque, name, true);
520 /* convert S390CPUDef into a static CpuModelInfo */
521 static void cpu_info_from_model(CpuModelInfo *info, const S390CPUModel *model,
522 bool delta_changes)
524 QDict *qdict = qdict_new();
525 S390FeatBitmap bitmap;
527 /* always fallback to the static base model */
528 info->name = g_strdup_printf("%s-base", model->def->name);
530 if (delta_changes) {
531 /* features deleted from the base feature set */
532 bitmap_andnot(bitmap, model->def->base_feat, model->features,
533 S390_FEAT_MAX);
534 if (!bitmap_empty(bitmap, S390_FEAT_MAX)) {
535 s390_feat_bitmap_to_ascii(bitmap, qdict, qdict_add_disabled_feat);
538 /* features added to the base feature set */
539 bitmap_andnot(bitmap, model->features, model->def->base_feat,
540 S390_FEAT_MAX);
541 if (!bitmap_empty(bitmap, S390_FEAT_MAX)) {
542 s390_feat_bitmap_to_ascii(bitmap, qdict, qdict_add_enabled_feat);
544 } else {
545 /* expand all features */
546 s390_feat_bitmap_to_ascii(model->features, qdict,
547 qdict_add_enabled_feat);
548 bitmap_complement(bitmap, model->features, S390_FEAT_MAX);
549 s390_feat_bitmap_to_ascii(bitmap, qdict, qdict_add_disabled_feat);
552 if (!qdict_size(qdict)) {
553 QDECREF(qdict);
554 } else {
555 info->props = QOBJECT(qdict);
556 info->has_props = true;
560 CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type,
561 CpuModelInfo *model,
562 Error **errp)
564 CpuModelExpansionInfo *expansion_info = NULL;
565 S390CPUModel s390_model;
566 bool delta_changes = false;
568 /* convert it to our internal representation */
569 cpu_model_from_info(&s390_model, model, errp);
570 if (*errp) {
571 return NULL;
574 if (type == CPU_MODEL_EXPANSION_TYPE_STATIC) {
575 delta_changes = true;
576 } else if (type != CPU_MODEL_EXPANSION_TYPE_FULL) {
577 error_setg(errp, "The requested expansion type is not supported.");
578 return NULL;
581 /* convert it back to a static representation */
582 expansion_info = g_new0(CpuModelExpansionInfo, 1);
583 expansion_info->model = g_malloc0(sizeof(*expansion_info->model));
584 cpu_info_from_model(expansion_info->model, &s390_model, delta_changes);
585 return expansion_info;
588 static void list_add_feat(const char *name, void *opaque)
590 strList **last = (strList **) opaque;
591 strList *entry;
593 entry = g_new0(strList, 1);
594 entry->value = g_strdup(name);
595 entry->next = *last;
596 *last = entry;
599 CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *infoa,
600 CpuModelInfo *infob,
601 Error **errp)
603 CpuModelCompareResult feat_result, gen_result;
604 CpuModelCompareInfo *compare_info;
605 S390FeatBitmap missing, added;
606 S390CPUModel modela, modelb;
608 /* convert both models to our internal representation */
609 cpu_model_from_info(&modela, infoa, errp);
610 if (*errp) {
611 return NULL;
613 cpu_model_from_info(&modelb, infob, errp);
614 if (*errp) {
615 return NULL;
617 compare_info = g_new0(CpuModelCompareInfo, 1);
619 /* check the cpu generation and ga level */
620 if (modela.def->gen == modelb.def->gen) {
621 if (modela.def->ec_ga == modelb.def->ec_ga) {
622 /* ec and corresponding bc are identical */
623 gen_result = CPU_MODEL_COMPARE_RESULT_IDENTICAL;
624 } else if (modela.def->ec_ga < modelb.def->ec_ga) {
625 gen_result = CPU_MODEL_COMPARE_RESULT_SUBSET;
626 } else {
627 gen_result = CPU_MODEL_COMPARE_RESULT_SUPERSET;
629 } else if (modela.def->gen < modelb.def->gen) {
630 gen_result = CPU_MODEL_COMPARE_RESULT_SUBSET;
631 } else {
632 gen_result = CPU_MODEL_COMPARE_RESULT_SUPERSET;
634 if (gen_result != CPU_MODEL_COMPARE_RESULT_IDENTICAL) {
635 /* both models cannot be made identical */
636 list_add_feat("type", &compare_info->responsible_properties);
639 /* check the feature set */
640 if (bitmap_equal(modela.features, modelb.features, S390_FEAT_MAX)) {
641 feat_result = CPU_MODEL_COMPARE_RESULT_IDENTICAL;
642 } else {
643 bitmap_andnot(missing, modela.features, modelb.features, S390_FEAT_MAX);
644 s390_feat_bitmap_to_ascii(missing,
645 &compare_info->responsible_properties,
646 list_add_feat);
647 bitmap_andnot(added, modelb.features, modela.features, S390_FEAT_MAX);
648 s390_feat_bitmap_to_ascii(added, &compare_info->responsible_properties,
649 list_add_feat);
650 if (bitmap_empty(missing, S390_FEAT_MAX)) {
651 feat_result = CPU_MODEL_COMPARE_RESULT_SUBSET;
652 } else if (bitmap_empty(added, S390_FEAT_MAX)) {
653 feat_result = CPU_MODEL_COMPARE_RESULT_SUPERSET;
654 } else {
655 feat_result = CPU_MODEL_COMPARE_RESULT_INCOMPATIBLE;
659 /* combine the results */
660 if (gen_result == feat_result) {
661 compare_info->result = gen_result;
662 } else if (feat_result == CPU_MODEL_COMPARE_RESULT_IDENTICAL) {
663 compare_info->result = gen_result;
664 } else if (gen_result == CPU_MODEL_COMPARE_RESULT_IDENTICAL) {
665 compare_info->result = feat_result;
666 } else {
667 compare_info->result = CPU_MODEL_COMPARE_RESULT_INCOMPATIBLE;
669 return compare_info;
672 CpuModelBaselineInfo *arch_query_cpu_model_baseline(CpuModelInfo *infoa,
673 CpuModelInfo *infob,
674 Error **errp)
676 CpuModelBaselineInfo *baseline_info;
677 S390CPUModel modela, modelb, model;
678 uint16_t cpu_type;
679 uint8_t max_gen_ga;
680 uint8_t max_gen;
682 /* convert both models to our internal representation */
683 cpu_model_from_info(&modela, infoa, errp);
684 if (*errp) {
685 return NULL;
688 cpu_model_from_info(&modelb, infob, errp);
689 if (*errp) {
690 return NULL;
693 /* features both models support */
694 bitmap_and(model.features, modela.features, modelb.features, S390_FEAT_MAX);
696 /* detect the maximum model not regarding features */
697 if (modela.def->gen == modelb.def->gen) {
698 if (modela.def->type == modelb.def->type) {
699 cpu_type = modela.def->type;
700 } else {
701 cpu_type = 0;
703 max_gen = modela.def->gen;
704 max_gen_ga = MIN(modela.def->ec_ga, modelb.def->ec_ga);
705 } else if (modela.def->gen > modelb.def->gen) {
706 cpu_type = modelb.def->type;
707 max_gen = modelb.def->gen;
708 max_gen_ga = modelb.def->ec_ga;
709 } else {
710 cpu_type = modela.def->type;
711 max_gen = modela.def->gen;
712 max_gen_ga = modela.def->ec_ga;
715 model.def = s390_find_cpu_def(cpu_type, max_gen, max_gen_ga,
716 model.features);
717 /* strip off features not part of the max model */
718 bitmap_and(model.features, model.features, model.def->full_feat,
719 S390_FEAT_MAX);
721 baseline_info = g_new0(CpuModelBaselineInfo, 1);
722 baseline_info->model = g_malloc0(sizeof(*baseline_info->model));
723 cpu_info_from_model(baseline_info->model, &model, true);
724 return baseline_info;
726 #endif
728 static void check_consistency(const S390CPUModel *model)
730 static int dep[][2] = {
731 { S390_FEAT_IPTE_RANGE, S390_FEAT_DAT_ENH },
732 { S390_FEAT_IDTE_SEGMENT, S390_FEAT_DAT_ENH },
733 { S390_FEAT_IDTE_REGION, S390_FEAT_DAT_ENH },
734 { S390_FEAT_IDTE_REGION, S390_FEAT_IDTE_SEGMENT },
735 { S390_FEAT_LOCAL_TLB_CLEARING, S390_FEAT_DAT_ENH},
736 { S390_FEAT_LONG_DISPLACEMENT_FAST, S390_FEAT_LONG_DISPLACEMENT },
737 { S390_FEAT_DFP_FAST, S390_FEAT_DFP },
738 { S390_FEAT_TRANSACTIONAL_EXE, S390_FEAT_STFLE_49 },
739 { S390_FEAT_EDAT_2, S390_FEAT_EDAT},
740 { S390_FEAT_MSA_EXT_5, S390_FEAT_KIMD_SHA_512 },
741 { S390_FEAT_MSA_EXT_5, S390_FEAT_KLMD_SHA_512 },
742 { S390_FEAT_MSA_EXT_4, S390_FEAT_MSA_EXT_3 },
743 { S390_FEAT_SIE_CMMA, S390_FEAT_CMM },
744 { S390_FEAT_SIE_CMMA, S390_FEAT_SIE_GSLS },
745 { S390_FEAT_SIE_PFMFI, S390_FEAT_EDAT },
746 { S390_FEAT_MSA_EXT_8, S390_FEAT_MSA_EXT_3 },
747 { S390_FEAT_MULTIPLE_EPOCH, S390_FEAT_TOD_CLOCK_STEERING },
748 { S390_FEAT_VECTOR_PACKED_DECIMAL, S390_FEAT_VECTOR },
749 { S390_FEAT_VECTOR_ENH, S390_FEAT_VECTOR },
750 { S390_FEAT_INSTRUCTION_EXEC_PROT, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2 },
751 { S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2, S390_FEAT_ESOP },
752 { S390_FEAT_CMM_NT, S390_FEAT_CMM },
753 { S390_FEAT_GUARDED_STORAGE, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2 },
754 { S390_FEAT_MULTIPLE_EPOCH, S390_FEAT_STORE_CLOCK_FAST },
755 { S390_FEAT_MULTIPLE_EPOCH, S390_FEAT_TOD_CLOCK_STEERING },
756 { S390_FEAT_SEMAPHORE_ASSIST, S390_FEAT_STFLE_49 },
757 { S390_FEAT_KIMD_SHA3_224, S390_FEAT_MSA },
758 { S390_FEAT_KIMD_SHA3_256, S390_FEAT_MSA },
759 { S390_FEAT_KIMD_SHA3_384, S390_FEAT_MSA },
760 { S390_FEAT_KIMD_SHA3_512, S390_FEAT_MSA },
761 { S390_FEAT_KIMD_SHAKE_128, S390_FEAT_MSA },
762 { S390_FEAT_KIMD_SHAKE_256, S390_FEAT_MSA },
763 { S390_FEAT_KLMD_SHA3_224, S390_FEAT_MSA },
764 { S390_FEAT_KLMD_SHA3_256, S390_FEAT_MSA },
765 { S390_FEAT_KLMD_SHA3_384, S390_FEAT_MSA },
766 { S390_FEAT_KLMD_SHA3_512, S390_FEAT_MSA },
767 { S390_FEAT_KLMD_SHAKE_128, S390_FEAT_MSA },
768 { S390_FEAT_KLMD_SHAKE_256, S390_FEAT_MSA },
769 { S390_FEAT_PRNO_TRNG_QRTCR, S390_FEAT_MSA_EXT_5 },
770 { S390_FEAT_PRNO_TRNG, S390_FEAT_MSA_EXT_5 },
771 { S390_FEAT_SIE_KSS, S390_FEAT_SIE_F2 },
773 int i;
775 for (i = 0; i < ARRAY_SIZE(dep); i++) {
776 if (test_bit(dep[i][0], model->features) &&
777 !test_bit(dep[i][1], model->features)) {
778 warn_report("\'%s\' requires \'%s\'.",
779 s390_feat_def(dep[i][0])->name,
780 s390_feat_def(dep[i][1])->name);
785 static void error_prepend_missing_feat(const char *name, void *opaque)
787 error_prepend((Error **) opaque, "%s ", name);
790 static void check_compatibility(const S390CPUModel *max_model,
791 const S390CPUModel *model, Error **errp)
793 S390FeatBitmap missing;
795 if (model->def->gen > max_model->def->gen) {
796 error_setg(errp, "Selected CPU generation is too new. Maximum "
797 "supported model in the configuration: \'%s\'",
798 max_model->def->name);
799 return;
800 } else if (model->def->gen == max_model->def->gen &&
801 model->def->ec_ga > max_model->def->ec_ga) {
802 error_setg(errp, "Selected CPU GA level is too new. Maximum "
803 "supported model in the configuration: \'%s\'",
804 max_model->def->name);
805 return;
808 /* detect the missing features to properly report them */
809 bitmap_andnot(missing, model->features, max_model->features, S390_FEAT_MAX);
810 if (bitmap_empty(missing, S390_FEAT_MAX)) {
811 return;
814 error_setg(errp, " ");
815 s390_feat_bitmap_to_ascii(missing, errp, error_prepend_missing_feat);
816 error_prepend(errp, "Some features requested in the CPU model are not "
817 "available in the configuration: ");
820 static S390CPUModel *get_max_cpu_model(Error **errp)
822 static S390CPUModel max_model;
823 static bool cached;
825 if (cached) {
826 return &max_model;
829 if (kvm_enabled()) {
830 kvm_s390_get_host_cpu_model(&max_model, errp);
831 } else {
832 max_model.def = s390_find_cpu_def(QEMU_MAX_CPU_TYPE, QEMU_MAX_CPU_GEN,
833 QEMU_MAX_CPU_EC_GA, NULL);
834 bitmap_copy(max_model.features, qemu_max_cpu_feat, S390_FEAT_MAX);
836 if (!*errp) {
837 cached = true;
838 return &max_model;
840 return NULL;
843 static inline void apply_cpu_model(const S390CPUModel *model, Error **errp)
845 #ifndef CONFIG_USER_ONLY
846 static S390CPUModel applied_model;
847 static bool applied;
850 * We have the same model for all VCPUs. KVM can only be configured before
851 * any VCPUs are defined in KVM.
853 if (applied) {
854 if (model && memcmp(&applied_model, model, sizeof(S390CPUModel))) {
855 error_setg(errp, "Mixed CPU models are not supported on s390x.");
857 return;
860 if (kvm_enabled()) {
861 kvm_s390_apply_cpu_model(model, errp);
864 if (!*errp) {
865 applied = true;
866 if (model) {
867 applied_model = *model;
870 #endif
873 void s390_realize_cpu_model(CPUState *cs, Error **errp)
875 S390CPUClass *xcc = S390_CPU_GET_CLASS(cs);
876 S390CPU *cpu = S390_CPU(cs);
877 const S390CPUModel *max_model;
879 if (xcc->kvm_required && !kvm_enabled()) {
880 error_setg(errp, "CPU definition requires KVM");
881 return;
884 if (!cpu->model) {
885 /* no host model support -> perform compatibility stuff */
886 apply_cpu_model(NULL, errp);
887 return;
890 max_model = get_max_cpu_model(errp);
891 if (*errp) {
892 error_prepend(errp, "CPU models are not available: ");
893 return;
896 /* copy over properties that can vary */
897 cpu->model->lowest_ibc = max_model->lowest_ibc;
898 cpu->model->cpu_id = max_model->cpu_id;
899 cpu->model->cpu_id_format = max_model->cpu_id_format;
900 cpu->model->cpu_ver = max_model->cpu_ver;
902 check_consistency(cpu->model);
903 check_compatibility(max_model, cpu->model, errp);
904 if (*errp) {
905 return;
908 apply_cpu_model(cpu->model, errp);
910 #if !defined(CONFIG_USER_ONLY)
911 cpu->env.cpuid = s390_cpuid_from_cpu_model(cpu->model);
912 if (tcg_enabled()) {
913 /* basic mode, write the cpu address into the first 4 bit of the ID */
914 cpu->env.cpuid = deposit64(cpu->env.cpuid, 54, 4, cpu->env.core_id);
916 #endif
919 static void get_feature(Object *obj, Visitor *v, const char *name,
920 void *opaque, Error **errp)
922 S390Feat feat = (S390Feat) opaque;
923 S390CPU *cpu = S390_CPU(obj);
924 bool value;
926 if (!cpu->model) {
927 error_setg(errp, "Details about the host CPU model are not available, "
928 "features cannot be queried.");
929 return;
932 value = test_bit(feat, cpu->model->features);
933 visit_type_bool(v, name, &value, errp);
936 static void set_feature(Object *obj, Visitor *v, const char *name,
937 void *opaque, Error **errp)
939 S390Feat feat = (S390Feat) opaque;
940 DeviceState *dev = DEVICE(obj);
941 S390CPU *cpu = S390_CPU(obj);
942 bool value;
944 if (dev->realized) {
945 error_setg(errp, "Attempt to set property '%s' on '%s' after "
946 "it was realized", name, object_get_typename(obj));
947 return;
948 } else if (!cpu->model) {
949 error_setg(errp, "Details about the host CPU model are not available, "
950 "features cannot be changed.");
951 return;
954 visit_type_bool(v, name, &value, errp);
955 if (*errp) {
956 return;
958 if (value) {
959 if (!test_bit(feat, cpu->model->def->full_feat)) {
960 error_setg(errp, "Feature '%s' is not available for CPU model '%s',"
961 " it was introduced with later models.",
962 name, cpu->model->def->name);
963 return;
965 set_bit(feat, cpu->model->features);
966 } else {
967 clear_bit(feat, cpu->model->features);
971 static void get_feature_group(Object *obj, Visitor *v, const char *name,
972 void *opaque, Error **errp)
974 S390FeatGroup group = (S390FeatGroup) opaque;
975 const S390FeatGroupDef *def = s390_feat_group_def(group);
976 S390CPU *cpu = S390_CPU(obj);
977 S390FeatBitmap tmp;
978 bool value;
980 if (!cpu->model) {
981 error_setg(errp, "Details about the host CPU model are not available, "
982 "features cannot be queried.");
983 return;
986 /* a group is enabled if all features are enabled */
987 bitmap_and(tmp, cpu->model->features, def->feat, S390_FEAT_MAX);
988 value = bitmap_equal(tmp, def->feat, S390_FEAT_MAX);
989 visit_type_bool(v, name, &value, errp);
992 static void set_feature_group(Object *obj, Visitor *v, const char *name,
993 void *opaque, Error **errp)
995 S390FeatGroup group = (S390FeatGroup) opaque;
996 const S390FeatGroupDef *def = s390_feat_group_def(group);
997 DeviceState *dev = DEVICE(obj);
998 S390CPU *cpu = S390_CPU(obj);
999 bool value;
1001 if (dev->realized) {
1002 error_setg(errp, "Attempt to set property '%s' on '%s' after "
1003 "it was realized", name, object_get_typename(obj));
1004 return;
1005 } else if (!cpu->model) {
1006 error_setg(errp, "Details about the host CPU model are not available, "
1007 "features cannot be changed.");
1008 return;
1011 visit_type_bool(v, name, &value, errp);
1012 if (*errp) {
1013 return;
1015 if (value) {
1016 /* groups are added in one shot, so an intersect is sufficient */
1017 if (!bitmap_intersects(def->feat, cpu->model->def->full_feat,
1018 S390_FEAT_MAX)) {
1019 error_setg(errp, "Group '%s' is not available for CPU model '%s',"
1020 " it was introduced with later models.",
1021 name, cpu->model->def->name);
1022 return;
1024 bitmap_or(cpu->model->features, cpu->model->features, def->feat,
1025 S390_FEAT_MAX);
1026 } else {
1027 bitmap_andnot(cpu->model->features, cpu->model->features, def->feat,
1028 S390_FEAT_MAX);
1032 void s390_cpu_model_register_props(Object *obj)
1034 S390FeatGroup group;
1035 S390Feat feat;
1037 for (feat = 0; feat < S390_FEAT_MAX; feat++) {
1038 const S390FeatDef *def = s390_feat_def(feat);
1039 object_property_add(obj, def->name, "bool", get_feature,
1040 set_feature, NULL, (void *) feat, NULL);
1041 object_property_set_description(obj, def->name, def->desc , NULL);
1043 for (group = 0; group < S390_FEAT_GROUP_MAX; group++) {
1044 const S390FeatGroupDef *def = s390_feat_group_def(group);
1045 object_property_add(obj, def->name, "bool", get_feature_group,
1046 set_feature_group, NULL, (void *) group, NULL);
1047 object_property_set_description(obj, def->name, def->desc , NULL);
1051 static void s390_cpu_model_initfn(Object *obj)
1053 S390CPU *cpu = S390_CPU(obj);
1054 S390CPUClass *xcc = S390_CPU_GET_CLASS(cpu);
1056 cpu->model = g_malloc0(sizeof(*cpu->model));
1057 /* copy the model, so we can modify it */
1058 cpu->model->def = xcc->cpu_def;
1059 if (xcc->is_static) {
1060 /* base model - features will never change */
1061 bitmap_copy(cpu->model->features, cpu->model->def->base_feat,
1062 S390_FEAT_MAX);
1063 } else {
1064 /* latest model - features can change */
1065 bitmap_copy(cpu->model->features,
1066 cpu->model->def->default_feat, S390_FEAT_MAX);
1070 #ifdef CONFIG_KVM
1071 static void s390_host_cpu_model_initfn(Object *obj)
1073 S390CPU *cpu = S390_CPU(obj);
1074 Error *err = NULL;
1076 if (!kvm_enabled() || !kvm_s390_cpu_models_supported()) {
1077 return;
1080 cpu->model = g_malloc0(sizeof(*cpu->model));
1081 kvm_s390_get_host_cpu_model(cpu->model, &err);
1082 if (err) {
1083 error_report_err(err);
1084 g_free(cpu->model);
1085 /* fallback to unsupported cpu models */
1086 cpu->model = NULL;
1089 #endif
1091 static S390CPUDef s390_qemu_cpu_def;
1092 static S390CPUModel s390_qemu_cpu_model;
1094 /* Set the qemu CPU model (on machine initialization). Must not be called
1095 * once CPUs have been created.
1097 void s390_set_qemu_cpu_model(uint16_t type, uint8_t gen, uint8_t ec_ga,
1098 const S390FeatInit feat_init)
1100 const S390CPUDef *def = s390_find_cpu_def(type, gen, ec_ga, NULL);
1102 g_assert(def);
1103 g_assert(QTAILQ_EMPTY(&cpus));
1105 /* TCG emulates some features that can usually not be enabled with
1106 * the emulated machine generation. Make sure they can be enabled
1107 * when using the QEMU model by adding them to full_feat. We have
1108 * to copy the definition to do that.
1110 memcpy(&s390_qemu_cpu_def, def, sizeof(s390_qemu_cpu_def));
1111 bitmap_or(s390_qemu_cpu_def.full_feat, s390_qemu_cpu_def.full_feat,
1112 qemu_max_cpu_feat, S390_FEAT_MAX);
1114 /* build the CPU model */
1115 s390_qemu_cpu_model.def = &s390_qemu_cpu_def;
1116 bitmap_zero(s390_qemu_cpu_model.features, S390_FEAT_MAX);
1117 s390_init_feat_bitmap(feat_init, s390_qemu_cpu_model.features);
1120 static void s390_qemu_cpu_model_initfn(Object *obj)
1122 S390CPU *cpu = S390_CPU(obj);
1124 cpu->model = g_malloc0(sizeof(*cpu->model));
1125 /* copy the CPU model so we can modify it */
1126 memcpy(cpu->model, &s390_qemu_cpu_model, sizeof(*cpu->model));
1129 static void s390_cpu_model_finalize(Object *obj)
1131 S390CPU *cpu = S390_CPU(obj);
1133 g_free(cpu->model);
1134 cpu->model = NULL;
1137 static bool get_is_migration_safe(Object *obj, Error **errp)
1139 return S390_CPU_GET_CLASS(obj)->is_migration_safe;
1142 static bool get_is_static(Object *obj, Error **errp)
1144 return S390_CPU_GET_CLASS(obj)->is_static;
1147 static char *get_description(Object *obj, Error **errp)
1149 return g_strdup(S390_CPU_GET_CLASS(obj)->desc);
1152 void s390_cpu_model_class_register_props(ObjectClass *oc)
1154 object_class_property_add_bool(oc, "migration-safe", get_is_migration_safe,
1155 NULL, NULL);
1156 object_class_property_add_bool(oc, "static", get_is_static,
1157 NULL, NULL);
1158 object_class_property_add_str(oc, "description", get_description, NULL,
1159 NULL);
1162 #ifdef CONFIG_KVM
1163 static void s390_host_cpu_model_class_init(ObjectClass *oc, void *data)
1165 S390CPUClass *xcc = S390_CPU_CLASS(oc);
1167 xcc->kvm_required = true;
1168 xcc->desc = "KVM only: All recognized features";
1170 #endif
1172 static void s390_base_cpu_model_class_init(ObjectClass *oc, void *data)
1174 S390CPUClass *xcc = S390_CPU_CLASS(oc);
1176 /* all base models are migration safe */
1177 xcc->cpu_def = (const S390CPUDef *) data;
1178 xcc->is_migration_safe = true;
1179 xcc->is_static = true;
1180 xcc->desc = xcc->cpu_def->desc;
1183 static void s390_cpu_model_class_init(ObjectClass *oc, void *data)
1185 S390CPUClass *xcc = S390_CPU_CLASS(oc);
1187 /* model that can change between QEMU versions */
1188 xcc->cpu_def = (const S390CPUDef *) data;
1189 xcc->is_migration_safe = true;
1190 xcc->desc = xcc->cpu_def->desc;
1193 static void s390_qemu_cpu_model_class_init(ObjectClass *oc, void *data)
1195 S390CPUClass *xcc = S390_CPU_CLASS(oc);
1197 xcc->is_migration_safe = true;
1198 xcc->desc = g_strdup_printf("QEMU Virtual CPU version %s",
1199 qemu_hw_version());
1202 /* Generate type name for a cpu model. Caller has to free the string. */
1203 static char *s390_cpu_type_name(const char *model_name)
1205 return g_strdup_printf(S390_CPU_TYPE_NAME("%s"), model_name);
1208 /* Generate type name for a base cpu model. Caller has to free the string. */
1209 static char *s390_base_cpu_type_name(const char *model_name)
1211 return g_strdup_printf(S390_CPU_TYPE_NAME("%s-base"), model_name);
1214 ObjectClass *s390_cpu_class_by_name(const char *name)
1216 char *typename = s390_cpu_type_name(name);
1217 ObjectClass *oc;
1219 oc = object_class_by_name(typename);
1220 g_free(typename);
1221 return oc;
1224 static const TypeInfo qemu_s390_cpu_type_info = {
1225 .name = S390_CPU_TYPE_NAME("qemu"),
1226 .parent = TYPE_S390_CPU,
1227 .instance_init = s390_qemu_cpu_model_initfn,
1228 .instance_finalize = s390_cpu_model_finalize,
1229 .class_init = s390_qemu_cpu_model_class_init,
1232 #ifdef CONFIG_KVM
1233 static const TypeInfo host_s390_cpu_type_info = {
1234 .name = S390_CPU_TYPE_NAME("host"),
1235 .parent = TYPE_S390_CPU,
1236 .instance_init = s390_host_cpu_model_initfn,
1237 .instance_finalize = s390_cpu_model_finalize,
1238 .class_init = s390_host_cpu_model_class_init,
1240 #endif
1242 static void init_ignored_base_feat(void)
1244 static const int feats[] = {
1245 /* MSA subfunctions that could not be available on certain machines */
1246 S390_FEAT_KMAC_DEA,
1247 S390_FEAT_KMAC_TDEA_128,
1248 S390_FEAT_KMAC_TDEA_192,
1249 S390_FEAT_KMC_DEA,
1250 S390_FEAT_KMC_TDEA_128,
1251 S390_FEAT_KMC_TDEA_192,
1252 S390_FEAT_KM_DEA,
1253 S390_FEAT_KM_TDEA_128,
1254 S390_FEAT_KM_TDEA_192,
1255 S390_FEAT_KIMD_SHA_1,
1256 S390_FEAT_KLMD_SHA_1,
1258 int i;
1260 for (i = 0; i < ARRAY_SIZE(feats); i++) {
1261 set_bit(feats[i], ignored_base_feat);
1265 static void register_types(void)
1267 static const S390FeatInit qemu_latest_init = { S390_FEAT_LIST_QEMU_LATEST };
1268 int i;
1270 init_ignored_base_feat();
1272 /* init all bitmaps from gnerated data initially */
1273 s390_init_feat_bitmap(qemu_max_cpu_feat_init, qemu_max_cpu_feat);
1274 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
1275 s390_init_feat_bitmap(s390_cpu_defs[i].base_init,
1276 s390_cpu_defs[i].base_feat);
1277 s390_init_feat_bitmap(s390_cpu_defs[i].default_init,
1278 s390_cpu_defs[i].default_feat);
1279 s390_init_feat_bitmap(s390_cpu_defs[i].full_init,
1280 s390_cpu_defs[i].full_feat);
1283 /* initialize the qemu model with latest definition */
1284 s390_set_qemu_cpu_model(QEMU_MAX_CPU_TYPE, QEMU_MAX_CPU_GEN,
1285 QEMU_MAX_CPU_EC_GA, qemu_latest_init);
1287 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
1288 char *base_name = s390_base_cpu_type_name(s390_cpu_defs[i].name);
1289 TypeInfo ti_base = {
1290 .name = base_name,
1291 .parent = TYPE_S390_CPU,
1292 .instance_init = s390_cpu_model_initfn,
1293 .instance_finalize = s390_cpu_model_finalize,
1294 .class_init = s390_base_cpu_model_class_init,
1295 .class_data = (void *) &s390_cpu_defs[i],
1297 char *name = s390_cpu_type_name(s390_cpu_defs[i].name);
1298 TypeInfo ti = {
1299 .name = name,
1300 .parent = TYPE_S390_CPU,
1301 .instance_init = s390_cpu_model_initfn,
1302 .instance_finalize = s390_cpu_model_finalize,
1303 .class_init = s390_cpu_model_class_init,
1304 .class_data = (void *) &s390_cpu_defs[i],
1307 type_register_static(&ti_base);
1308 type_register_static(&ti);
1309 g_free(base_name);
1310 g_free(name);
1313 type_register_static(&qemu_s390_cpu_type_info);
1314 #ifdef CONFIG_KVM
1315 type_register_static(&host_s390_cpu_type_info);
1316 #endif
1319 type_init(register_types)