s390x/kvm: implement CPU model support
[qemu.git] / target-s390x / cpu_models.c
blob5b9f35ee8757c67ac343b96c194926e7370bcf35
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 "gen-features.h"
16 #include "qapi/error.h"
17 #include "qapi/visitor.h"
18 #include "qemu/error-report.h"
19 #ifndef CONFIG_USER_ONLY
20 #include "sysemu/arch_init.h"
21 #endif
23 #define CPUDEF_INIT(_type, _gen, _ec_ga, _mha_pow, _hmfai, _name, _desc) \
24 { \
25 .name = _name, \
26 .type = _type, \
27 .gen = _gen, \
28 .ec_ga = _ec_ga, \
29 .mha_pow = _mha_pow, \
30 .hmfai = _hmfai, \
31 .desc = _desc, \
32 .base_init = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _BASE }, \
33 .default_init = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _DEFAULT }, \
34 .full_init = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _FULL }, \
38 * CPU definiton list in order of release. For now, base features of a
39 * following release are always a subset of base features of the previous
40 * release. Same is correct for the other feature sets.
41 * A BC release always follows the corresponding EC release.
43 static S390CPUDef s390_cpu_defs[] = {
44 CPUDEF_INIT(0x2064, 7, 1, 38, 0x00000000U, "z900", "IBM zSeries 900 GA1"),
45 CPUDEF_INIT(0x2064, 7, 2, 38, 0x00000000U, "z900.2", "IBM zSeries 900 GA2"),
46 CPUDEF_INIT(0x2064, 7, 3, 38, 0x00000000U, "z900.3", "IBM zSeries 900 GA3"),
47 CPUDEF_INIT(0x2066, 7, 3, 38, 0x00000000U, "z800", "IBM zSeries 800 GA1"),
48 CPUDEF_INIT(0x2084, 8, 1, 38, 0x00000000U, "z990", "IBM zSeries 990 GA1"),
49 CPUDEF_INIT(0x2084, 8, 2, 38, 0x00000000U, "z990.2", "IBM zSeries 990 GA2"),
50 CPUDEF_INIT(0x2084, 8, 3, 38, 0x00000000U, "z990.3", "IBM zSeries 990 GA3"),
51 CPUDEF_INIT(0x2086, 8, 3, 38, 0x00000000U, "z890", "IBM zSeries 880 GA1"),
52 CPUDEF_INIT(0x2084, 8, 4, 38, 0x00000000U, "z990.4", "IBM zSeries 990 GA4"),
53 CPUDEF_INIT(0x2086, 8, 4, 38, 0x00000000U, "z890.2", "IBM zSeries 880 GA2"),
54 CPUDEF_INIT(0x2084, 8, 5, 38, 0x00000000U, "z990.5", "IBM zSeries 990 GA5"),
55 CPUDEF_INIT(0x2086, 8, 5, 38, 0x00000000U, "z890.3", "IBM zSeries 880 GA3"),
56 CPUDEF_INIT(0x2094, 9, 1, 40, 0x00000000U, "z9EC", "IBM System z9 EC GA1"),
57 CPUDEF_INIT(0x2094, 9, 2, 40, 0x00000000U, "z9EC.2", "IBM System z9 EC GA2"),
58 CPUDEF_INIT(0x2096, 9, 2, 40, 0x00000000U, "z9BC", "IBM System z9 BC GA1"),
59 CPUDEF_INIT(0x2094, 9, 3, 40, 0x00000000U, "z9EC.3", "IBM System z9 EC GA3"),
60 CPUDEF_INIT(0x2096, 9, 3, 40, 0x00000000U, "z9BC.2", "IBM System z9 BC GA2"),
61 CPUDEF_INIT(0x2097, 10, 1, 43, 0x00000000U, "z10EC", "IBM System z10 EC GA1"),
62 CPUDEF_INIT(0x2097, 10, 2, 43, 0x00000000U, "z10EC.2", "IBM System z10 EC GA2"),
63 CPUDEF_INIT(0x2098, 10, 2, 43, 0x00000000U, "z10BC", "IBM System z10 BC GA1"),
64 CPUDEF_INIT(0x2097, 10, 3, 43, 0x00000000U, "z10EC.3", "IBM System z10 EC GA3"),
65 CPUDEF_INIT(0x2098, 10, 3, 43, 0x00000000U, "z10BC.2", "IBM System z10 BC GA2"),
66 CPUDEF_INIT(0x2817, 11, 1, 44, 0x08000000U, "z196", "IBM zEnterprise 196 GA1"),
67 CPUDEF_INIT(0x2817, 11, 2, 44, 0x08000000U, "z196.2", "IBM zEnterprise 196 GA2"),
68 CPUDEF_INIT(0x2818, 11, 2, 44, 0x08000000U, "z114", "IBM zEnterprise 114 GA1"),
69 CPUDEF_INIT(0x2827, 12, 1, 44, 0x08000000U, "zEC12", "IBM zEnterprise EC12 GA1"),
70 CPUDEF_INIT(0x2827, 12, 2, 44, 0x08000000U, "zEC12.2", "IBM zEnterprise EC12 GA2"),
71 CPUDEF_INIT(0x2828, 12, 2, 44, 0x08000000U, "zBC12", "IBM zEnterprise BC12 GA1"),
72 CPUDEF_INIT(0x2964, 13, 1, 47, 0x08000000U, "z13", "IBM z13 GA1"),
73 CPUDEF_INIT(0x2964, 13, 2, 47, 0x08000000U, "z13.2", "IBM z13 GA2"),
74 CPUDEF_INIT(0x2965, 13, 2, 47, 0x08000000U, "z13s", "IBM z13s GA1"),
77 uint32_t s390_get_hmfai(void)
79 static S390CPU *cpu;
81 if (!cpu) {
82 cpu = S390_CPU(qemu_get_cpu(0));
85 if (!cpu || !cpu->model) {
86 return 0;
88 return cpu->model->def->hmfai;
91 uint8_t s390_get_mha_pow(void)
93 static S390CPU *cpu;
95 if (!cpu) {
96 cpu = S390_CPU(qemu_get_cpu(0));
99 if (!cpu || !cpu->model) {
100 return 0;
102 return cpu->model->def->mha_pow;
105 uint32_t s390_get_ibc_val(void)
107 uint16_t unblocked_ibc, lowest_ibc;
108 static S390CPU *cpu;
110 if (!cpu) {
111 cpu = S390_CPU(qemu_get_cpu(0));
114 if (!cpu || !cpu->model) {
115 return 0;
117 unblocked_ibc = s390_ibc_from_cpu_model(cpu->model);
118 lowest_ibc = cpu->model->lowest_ibc;
119 /* the lowest_ibc always has to be <= unblocked_ibc */
120 if (!lowest_ibc || lowest_ibc > unblocked_ibc) {
121 return 0;
123 return ((uint32_t) lowest_ibc << 16) | unblocked_ibc;
126 void s390_get_feat_block(S390FeatType type, uint8_t *data)
128 static S390CPU *cpu;
130 if (!cpu) {
131 cpu = S390_CPU(qemu_get_cpu(0));
134 if (!cpu || !cpu->model) {
135 return;
137 s390_fill_feat_block(cpu->model->features, type, data);
140 bool s390_has_feat(S390Feat feat)
142 static S390CPU *cpu;
144 if (!cpu) {
145 cpu = S390_CPU(qemu_get_cpu(0));
148 if (!cpu || !cpu->model) {
149 #ifdef CONFIG_KVM
150 if (kvm_enabled()) {
151 if (feat == S390_FEAT_VECTOR) {
152 return kvm_check_extension(kvm_state,
153 KVM_CAP_S390_VECTOR_REGISTERS);
155 if (feat == S390_FEAT_RUNTIME_INSTRUMENTATION) {
156 return kvm_s390_get_ri();
159 #endif
160 return 0;
162 return test_bit(feat, cpu->model->features);
165 uint8_t s390_get_gen_for_cpu_type(uint16_t type)
167 int i;
169 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
170 if (s390_cpu_defs[i].type == type) {
171 return s390_cpu_defs[i].gen;
174 return 0;
177 const S390CPUDef *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga,
178 S390FeatBitmap features)
180 const S390CPUDef *last_compatible = NULL;
181 int i;
183 if (!gen) {
184 ec_ga = 0;
186 if (!gen && type) {
187 gen = s390_get_gen_for_cpu_type(type);
190 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
191 const S390CPUDef *def = &s390_cpu_defs[i];
192 S390FeatBitmap missing;
194 /* don't even try newer generations if we know the generation */
195 if (gen) {
196 if (def->gen > gen) {
197 break;
198 } else if (def->gen == gen && ec_ga && def->ec_ga > ec_ga) {
199 break;
203 if (features) {
204 /* see if the model satisfies the minimum features */
205 bitmap_andnot(missing, def->base_feat, features, S390_FEAT_MAX);
206 if (!bitmap_empty(missing, S390_FEAT_MAX)) {
207 break;
211 /* stop the search if we found the exact model */
212 if (def->type == type && def->ec_ga == ec_ga) {
213 return def;
215 last_compatible = def;
217 return last_compatible;
220 struct S390PrintCpuListInfo {
221 FILE *f;
222 fprintf_function print;
225 static void print_cpu_model_list(ObjectClass *klass, void *opaque)
227 struct S390PrintCpuListInfo *info = opaque;
228 S390CPUClass *scc = S390_CPU_CLASS(klass);
229 char *name = g_strdup(object_class_get_name(klass));
230 const char *details = "";
232 if (scc->is_static) {
233 details = "(static, migration-safe)";
234 } else if (scc->is_migration_safe) {
235 details = "(migration-safe)";
238 /* strip off the -s390-cpu */
239 g_strrstr(name, "-" TYPE_S390_CPU)[0] = 0;
240 (*info->print)(info->f, "s390 %-15s %-35s %s\n", name, scc->desc,
241 details);
242 g_free(name);
245 void s390_cpu_list(FILE *f, fprintf_function print)
247 struct S390PrintCpuListInfo info = {
248 .f = f,
249 .print = print,
251 S390FeatGroup group;
252 S390Feat feat;
254 object_class_foreach(print_cpu_model_list, TYPE_S390_CPU, false, &info);
256 (*print)(f, "\nRecognized feature flags:\n");
257 for (feat = 0; feat < S390_FEAT_MAX; feat++) {
258 const S390FeatDef *def = s390_feat_def(feat);
260 (*print)(f, "%-20s %-50s\n", def->name, def->desc);
263 (*print)(f, "\nRecognized feature groups:\n");
264 for (group = 0; group < S390_FEAT_GROUP_MAX; group++) {
265 const S390FeatGroupDef *def = s390_feat_group_def(group);
267 (*print)(f, "%-20s %-50s\n", def->name, def->desc);
271 #ifndef CONFIG_USER_ONLY
272 static void create_cpu_model_list(ObjectClass *klass, void *opaque)
274 CpuDefinitionInfoList **cpu_list = opaque;
275 CpuDefinitionInfoList *entry;
276 CpuDefinitionInfo *info;
277 char *name = g_strdup(object_class_get_name(klass));
278 S390CPUClass *scc = S390_CPU_CLASS(klass);
280 /* strip off the -s390-cpu */
281 g_strrstr(name, "-" TYPE_S390_CPU)[0] = 0;
282 info = g_malloc0(sizeof(*info));
283 info->name = name;
284 info->has_migration_safe = true;
285 info->migration_safe = scc->is_migration_safe;
286 info->q_static = scc->is_static;
289 entry = g_malloc0(sizeof(*entry));
290 entry->value = info;
291 entry->next = *cpu_list;
292 *cpu_list = entry;
295 CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
297 CpuDefinitionInfoList *list = NULL;
299 object_class_foreach(create_cpu_model_list, TYPE_S390_CPU, false, &list);
301 return list;
303 #endif
305 static void check_consistency(const S390CPUModel *model)
307 static int dep[][2] = {
308 { S390_FEAT_IPTE_RANGE, S390_FEAT_DAT_ENH },
309 { S390_FEAT_IDTE_SEGMENT, S390_FEAT_DAT_ENH },
310 { S390_FEAT_IDTE_REGION, S390_FEAT_DAT_ENH },
311 { S390_FEAT_IDTE_REGION, S390_FEAT_IDTE_SEGMENT },
312 { S390_FEAT_LOCAL_TLB_CLEARING, S390_FEAT_DAT_ENH},
313 { S390_FEAT_LONG_DISPLACEMENT_FAST, S390_FEAT_LONG_DISPLACEMENT },
314 { S390_FEAT_DFP_FAST, S390_FEAT_DFP },
315 { S390_FEAT_TRANSACTIONAL_EXE, S390_FEAT_STFLE_49 },
316 { S390_FEAT_EDAT_2, S390_FEAT_EDAT},
317 { S390_FEAT_MSA_EXT_5, S390_FEAT_KIMD_SHA_512 },
318 { S390_FEAT_MSA_EXT_5, S390_FEAT_KLMD_SHA_512 },
319 { S390_FEAT_MSA_EXT_4, S390_FEAT_MSA_EXT_3 },
320 { S390_FEAT_SIE_CMMA, S390_FEAT_CMM },
321 { S390_FEAT_SIE_CMMA, S390_FEAT_SIE_GSLS },
322 { S390_FEAT_SIE_PFMFI, S390_FEAT_EDAT },
324 int i;
326 for (i = 0; i < ARRAY_SIZE(dep); i++) {
327 if (test_bit(dep[i][0], model->features) &&
328 !test_bit(dep[i][1], model->features)) {
329 error_report("Warning: \'%s\' requires \'%s\'.",
330 s390_feat_def(dep[i][0])->name,
331 s390_feat_def(dep[i][1])->name);
336 static void error_prepend_missing_feat(const char *name, void *opaque)
338 error_prepend((Error **) opaque, "%s ", name);
341 static void check_compatibility(const S390CPUModel *max_model,
342 const S390CPUModel *model, Error **errp)
344 S390FeatBitmap missing;
346 if (model->def->gen > max_model->def->gen) {
347 error_setg(errp, "Selected CPU generation is too new. Maximum "
348 "supported model in the configuration: \'%s\'",
349 max_model->def->name);
350 return;
351 } else if (model->def->gen == max_model->def->gen &&
352 model->def->ec_ga > max_model->def->ec_ga) {
353 error_setg(errp, "Selected CPU GA level is too new. Maximum "
354 "supported model in the configuration: \'%s\'",
355 max_model->def->name);
356 return;
359 /* detect the missing features to properly report them */
360 bitmap_andnot(missing, model->features, max_model->features, S390_FEAT_MAX);
361 if (bitmap_empty(missing, S390_FEAT_MAX)) {
362 return;
365 error_setg(errp, " ");
366 s390_feat_bitmap_to_ascii(missing, errp, error_prepend_missing_feat);
367 error_prepend(errp, "Some features requested in the CPU model are not "
368 "available in the configuration: ");
371 static S390CPUModel *get_max_cpu_model(Error **errp)
373 #ifndef CONFIG_USER_ONLY
374 static S390CPUModel max_model;
375 static bool cached;
377 if (cached) {
378 return &max_model;
381 if (kvm_enabled()) {
382 kvm_s390_get_host_cpu_model(&max_model, errp);
383 } else {
384 /* TCG enulates a z900 */
385 max_model.def = &s390_cpu_defs[0];
386 bitmap_copy(max_model.features, max_model.def->default_feat,
387 S390_FEAT_MAX);
389 if (!*errp) {
390 cached = true;
391 return &max_model;
393 #endif
394 return NULL;
397 static inline void apply_cpu_model(const S390CPUModel *model, Error **errp)
399 #ifndef CONFIG_USER_ONLY
400 static S390CPUModel applied_model;
401 static bool applied;
404 * We have the same model for all VCPUs. KVM can only be configured before
405 * any VCPUs are defined in KVM.
407 if (applied) {
408 if (model && memcmp(&applied_model, model, sizeof(S390CPUModel))) {
409 error_setg(errp, "Mixed CPU models are not supported on s390x.");
411 return;
414 if (kvm_enabled()) {
415 kvm_s390_apply_cpu_model(model, errp);
416 } else if (model) {
417 /* FIXME TCG - use data for stdip/stfl */
420 if (!*errp) {
421 applied = true;
422 if (model) {
423 applied_model = *model;
426 #endif
429 void s390_realize_cpu_model(CPUState *cs, Error **errp)
431 S390CPUClass *xcc = S390_CPU_GET_CLASS(cs);
432 S390CPU *cpu = S390_CPU(cs);
433 const S390CPUModel *max_model;
435 if (xcc->kvm_required && !kvm_enabled()) {
436 error_setg(errp, "CPU definition requires KVM");
437 return;
440 if (!cpu->model) {
441 /* no host model support -> perform compatibility stuff */
442 apply_cpu_model(NULL, errp);
443 return;
446 max_model = get_max_cpu_model(errp);
447 if (*errp) {
448 error_prepend(errp, "CPU models are not available: ");
449 return;
452 /* copy over properties that can vary */
453 cpu->model->lowest_ibc = max_model->lowest_ibc;
454 cpu->model->cpu_id = max_model->cpu_id;
455 cpu->model->cpu_ver = max_model->cpu_ver;
457 check_consistency(cpu->model);
458 check_compatibility(max_model, cpu->model, errp);
459 if (*errp) {
460 return;
463 apply_cpu_model(cpu->model, errp);
466 static void get_feature(Object *obj, Visitor *v, const char *name,
467 void *opaque, Error **errp)
469 S390Feat feat = (S390Feat) opaque;
470 S390CPU *cpu = S390_CPU(obj);
471 bool value;
473 if (!cpu->model) {
474 error_setg(errp, "Details about the host CPU model are not available, "
475 "features cannot be queried.");
476 return;
479 value = test_bit(feat, cpu->model->features);
480 visit_type_bool(v, name, &value, errp);
483 static void set_feature(Object *obj, Visitor *v, const char *name,
484 void *opaque, Error **errp)
486 S390Feat feat = (S390Feat) opaque;
487 DeviceState *dev = DEVICE(obj);
488 S390CPU *cpu = S390_CPU(obj);
489 bool value;
491 if (dev->realized) {
492 error_setg(errp, "Attempt to set property '%s' on '%s' after "
493 "it was realized", name, object_get_typename(obj));
494 return;
495 } else if (!cpu->model) {
496 error_setg(errp, "Details about the host CPU model are not available, "
497 "features cannot be changed.");
498 return;
501 visit_type_bool(v, name, &value, errp);
502 if (*errp) {
503 return;
505 if (value) {
506 if (!test_bit(feat, cpu->model->def->full_feat)) {
507 error_setg(errp, "Feature '%s' is not available for CPU model '%s',"
508 " it was introduced with later models.",
509 name, cpu->model->def->name);
510 return;
512 set_bit(feat, cpu->model->features);
513 } else {
514 clear_bit(feat, cpu->model->features);
518 static void get_feature_group(Object *obj, Visitor *v, const char *name,
519 void *opaque, Error **errp)
521 S390FeatGroup group = (S390FeatGroup) opaque;
522 const S390FeatGroupDef *def = s390_feat_group_def(group);
523 S390CPU *cpu = S390_CPU(obj);
524 S390FeatBitmap tmp;
525 bool value;
527 if (!cpu->model) {
528 error_setg(errp, "Details about the host CPU model are not available, "
529 "features cannot be queried.");
530 return;
533 /* a group is enabled if all features are enabled */
534 bitmap_and(tmp, cpu->model->features, def->feat, S390_FEAT_MAX);
535 value = bitmap_equal(tmp, def->feat, S390_FEAT_MAX);
536 visit_type_bool(v, name, &value, errp);
539 static void set_feature_group(Object *obj, Visitor *v, const char *name,
540 void *opaque, Error **errp)
542 S390FeatGroup group = (S390FeatGroup) opaque;
543 const S390FeatGroupDef *def = s390_feat_group_def(group);
544 DeviceState *dev = DEVICE(obj);
545 S390CPU *cpu = S390_CPU(obj);
546 bool value;
548 if (dev->realized) {
549 error_setg(errp, "Attempt to set property '%s' on '%s' after "
550 "it was realized", name, object_get_typename(obj));
551 return;
552 } else if (!cpu->model) {
553 error_setg(errp, "Details about the host CPU model are not available, "
554 "features cannot be changed.");
555 return;
558 visit_type_bool(v, name, &value, errp);
559 if (*errp) {
560 return;
562 if (value) {
563 /* groups are added in one shot, so an intersect is sufficient */
564 if (!bitmap_intersects(def->feat, cpu->model->def->full_feat,
565 S390_FEAT_MAX)) {
566 error_setg(errp, "Group '%s' is not available for CPU model '%s',"
567 " it was introduced with later models.",
568 name, cpu->model->def->name);
569 return;
571 bitmap_or(cpu->model->features, cpu->model->features, def->feat,
572 S390_FEAT_MAX);
573 } else {
574 bitmap_andnot(cpu->model->features, cpu->model->features, def->feat,
575 S390_FEAT_MAX);
579 void s390_cpu_model_register_props(Object *obj)
581 S390FeatGroup group;
582 S390Feat feat;
584 for (feat = 0; feat < S390_FEAT_MAX; feat++) {
585 const S390FeatDef *def = s390_feat_def(feat);
586 object_property_add(obj, def->name, "bool", get_feature,
587 set_feature, NULL, (void *) feat, NULL);
588 object_property_set_description(obj, def->name, def->desc , NULL);
590 for (group = 0; group < S390_FEAT_GROUP_MAX; group++) {
591 const S390FeatGroupDef *def = s390_feat_group_def(group);
592 object_property_add(obj, def->name, "bool", get_feature_group,
593 set_feature_group, NULL, (void *) group, NULL);
594 object_property_set_description(obj, def->name, def->desc , NULL);
598 static void s390_cpu_model_initfn(Object *obj)
600 S390CPU *cpu = S390_CPU(obj);
601 S390CPUClass *xcc = S390_CPU_GET_CLASS(cpu);
603 cpu->model = g_malloc0(sizeof(*cpu->model));
604 /* copy the model, so we can modify it */
605 cpu->model->def = xcc->cpu_def;
606 if (xcc->is_static) {
607 /* base model - features will never change */
608 bitmap_copy(cpu->model->features, cpu->model->def->base_feat,
609 S390_FEAT_MAX);
610 } else {
611 /* latest model - features can change */
612 bitmap_copy(cpu->model->features,
613 cpu->model->def->default_feat, S390_FEAT_MAX);
617 #ifdef CONFIG_KVM
618 static void s390_host_cpu_model_initfn(Object *obj)
620 S390CPU *cpu = S390_CPU(obj);
621 Error *err = NULL;
623 if (!kvm_enabled() || !kvm_s390_cpu_models_supported()) {
624 return;
627 cpu->model = g_malloc0(sizeof(*cpu->model));
628 kvm_s390_get_host_cpu_model(cpu->model, &err);
629 if (err) {
630 error_report_err(err);
631 g_free(cpu->model);
632 /* fallback to unsupported cpu models */
633 cpu->model = NULL;
636 #endif
638 static void s390_qemu_cpu_model_initfn(Object *obj)
640 S390CPU *cpu = S390_CPU(obj);
642 cpu->model = g_malloc0(sizeof(*cpu->model));
643 /* TCG emulates a z900 */
644 cpu->model->def = &s390_cpu_defs[0];
645 bitmap_copy(cpu->model->features, cpu->model->def->default_feat,
646 S390_FEAT_MAX);
649 static void s390_cpu_model_finalize(Object *obj)
651 S390CPU *cpu = S390_CPU(obj);
653 g_free(cpu->model);
654 cpu->model = NULL;
657 static bool get_is_migration_safe(Object *obj, Error **errp)
659 return S390_CPU_GET_CLASS(obj)->is_migration_safe;
662 static bool get_is_static(Object *obj, Error **errp)
664 return S390_CPU_GET_CLASS(obj)->is_static;
667 static char *get_description(Object *obj, Error **errp)
669 return g_strdup(S390_CPU_GET_CLASS(obj)->desc);
672 void s390_cpu_model_class_register_props(ObjectClass *oc)
674 object_class_property_add_bool(oc, "migration-safe", get_is_migration_safe,
675 NULL, NULL);
676 object_class_property_add_bool(oc, "static", get_is_static,
677 NULL, NULL);
678 object_class_property_add_str(oc, "description", get_description, NULL,
679 NULL);
682 #ifdef CONFIG_KVM
683 static void s390_host_cpu_model_class_init(ObjectClass *oc, void *data)
685 S390CPUClass *xcc = S390_CPU_CLASS(oc);
687 xcc->kvm_required = true;
688 xcc->desc = "KVM only: All recognized features";
690 #endif
692 static void s390_base_cpu_model_class_init(ObjectClass *oc, void *data)
694 S390CPUClass *xcc = S390_CPU_CLASS(oc);
696 /* all base models are migration safe */
697 xcc->cpu_def = (const S390CPUDef *) data;
698 xcc->is_migration_safe = true;
699 xcc->is_static = true;
700 xcc->desc = xcc->cpu_def->desc;
703 static void s390_cpu_model_class_init(ObjectClass *oc, void *data)
705 S390CPUClass *xcc = S390_CPU_CLASS(oc);
707 /* model that can change between QEMU versions */
708 xcc->cpu_def = (const S390CPUDef *) data;
709 xcc->is_migration_safe = true;
710 xcc->desc = xcc->cpu_def->desc;
713 static void s390_qemu_cpu_model_class_init(ObjectClass *oc, void *data)
715 S390CPUClass *xcc = S390_CPU_CLASS(oc);
717 xcc->is_migration_safe = true;
718 xcc->desc = g_strdup_printf("QEMU Virtual CPU version %s",
719 qemu_hw_version());
722 #define S390_CPU_TYPE_SUFFIX "-" TYPE_S390_CPU
723 #define S390_CPU_TYPE_NAME(name) (name S390_CPU_TYPE_SUFFIX)
725 /* Generate type name for a cpu model. Caller has to free the string. */
726 static char *s390_cpu_type_name(const char *model_name)
728 return g_strdup_printf(S390_CPU_TYPE_NAME("%s"), model_name);
731 /* Generate type name for a base cpu model. Caller has to free the string. */
732 static char *s390_base_cpu_type_name(const char *model_name)
734 return g_strdup_printf(S390_CPU_TYPE_NAME("%s-base"), model_name);
737 ObjectClass *s390_cpu_class_by_name(const char *name)
739 char *typename = s390_cpu_type_name(name);
740 ObjectClass *oc;
742 oc = object_class_by_name(typename);
743 g_free(typename);
744 return oc;
747 static const TypeInfo qemu_s390_cpu_type_info = {
748 .name = S390_CPU_TYPE_NAME("qemu"),
749 .parent = TYPE_S390_CPU,
750 .instance_init = s390_qemu_cpu_model_initfn,
751 .instance_finalize = s390_cpu_model_finalize,
752 .class_init = s390_qemu_cpu_model_class_init,
755 #ifdef CONFIG_KVM
756 static const TypeInfo host_s390_cpu_type_info = {
757 .name = S390_CPU_TYPE_NAME("host"),
758 .parent = TYPE_S390_CPU,
759 .instance_init = s390_host_cpu_model_initfn,
760 .instance_finalize = s390_cpu_model_finalize,
761 .class_init = s390_host_cpu_model_class_init,
763 #endif
765 static void register_types(void)
767 int i;
769 /* init all bitmaps from gnerated data initially */
770 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
771 s390_init_feat_bitmap(s390_cpu_defs[i].base_init,
772 s390_cpu_defs[i].base_feat);
773 s390_init_feat_bitmap(s390_cpu_defs[i].default_init,
774 s390_cpu_defs[i].default_feat);
775 s390_init_feat_bitmap(s390_cpu_defs[i].full_init,
776 s390_cpu_defs[i].full_feat);
779 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
780 char *base_name = s390_base_cpu_type_name(s390_cpu_defs[i].name);
781 TypeInfo ti_base = {
782 .name = base_name,
783 .parent = TYPE_S390_CPU,
784 .instance_init = s390_cpu_model_initfn,
785 .instance_finalize = s390_cpu_model_finalize,
786 .class_init = s390_base_cpu_model_class_init,
787 .class_data = (void *) &s390_cpu_defs[i],
789 char *name = s390_cpu_type_name(s390_cpu_defs[i].name);
790 TypeInfo ti = {
791 .name = name,
792 .parent = TYPE_S390_CPU,
793 .instance_init = s390_cpu_model_initfn,
794 .instance_finalize = s390_cpu_model_finalize,
795 .class_init = s390_cpu_model_class_init,
796 .class_data = (void *) &s390_cpu_defs[i],
799 type_register_static(&ti_base);
800 type_register_static(&ti);
801 g_free(base_name);
802 g_free(name);
805 type_register_static(&qemu_s390_cpu_type_info);
806 #ifdef CONFIG_KVM
807 type_register_static(&host_s390_cpu_type_info);
808 #endif
811 type_init(register_types)