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
13 #include "qemu/osdep.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"
23 #define CPUDEF_INIT(_type, _gen, _ec_ga, _mha_pow, _hmfai, _name, _desc) \
29 .mha_pow = _mha_pow, \
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)
82 cpu
= S390_CPU(qemu_get_cpu(0));
85 if (!cpu
|| !cpu
->model
) {
88 return cpu
->model
->def
->hmfai
;
91 uint8_t s390_get_mha_pow(void)
96 cpu
= S390_CPU(qemu_get_cpu(0));
99 if (!cpu
|| !cpu
->model
) {
102 return cpu
->model
->def
->mha_pow
;
105 uint32_t s390_get_ibc_val(void)
107 uint16_t unblocked_ibc
, lowest_ibc
;
111 cpu
= S390_CPU(qemu_get_cpu(0));
114 if (!cpu
|| !cpu
->model
) {
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
) {
123 return ((uint32_t) lowest_ibc
<< 16) | unblocked_ibc
;
126 void s390_get_feat_block(S390FeatType type
, uint8_t *data
)
131 cpu
= S390_CPU(qemu_get_cpu(0));
134 if (!cpu
|| !cpu
->model
) {
137 s390_fill_feat_block(cpu
->model
->features
, type
, data
);
140 bool s390_has_feat(S390Feat feat
)
145 cpu
= S390_CPU(qemu_get_cpu(0));
148 if (!cpu
|| !cpu
->model
) {
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();
162 return test_bit(feat
, cpu
->model
->features
);
165 uint8_t s390_get_gen_for_cpu_type(uint16_t type
)
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
;
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
;
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 */
196 if (def
->gen
> gen
) {
198 } else if (def
->gen
== gen
&& ec_ga
&& def
->ec_ga
> ec_ga
) {
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
)) {
211 /* stop the search if we found the exact model */
212 if (def
->type
== type
&& def
->ec_ga
== ec_ga
) {
215 last_compatible
= def
;
217 return last_compatible
;
220 struct S390PrintCpuListInfo
{
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
,
245 void s390_cpu_list(FILE *f
, fprintf_function print
)
247 struct S390PrintCpuListInfo info
= {
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
));
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
));
291 entry
->next
= *cpu_list
;
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
);
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
},
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
);
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
);
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
)) {
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
;
382 kvm_s390_get_host_cpu_model(&max_model
, errp
);
384 /* TCG enulates a z900 */
385 max_model
.def
= &s390_cpu_defs
[0];
386 bitmap_copy(max_model
.features
, max_model
.def
->default_feat
,
397 static inline void apply_cpu_model(const S390CPUModel
*model
, Error
**errp
)
399 #ifndef CONFIG_USER_ONLY
400 static S390CPUModel applied_model
;
404 * We have the same model for all VCPUs. KVM can only be configured before
405 * any VCPUs are defined in KVM.
408 if (model
&& memcmp(&applied_model
, model
, sizeof(S390CPUModel
))) {
409 error_setg(errp
, "Mixed CPU models are not supported on s390x.");
415 kvm_s390_apply_cpu_model(model
, errp
);
417 /* FIXME TCG - use data for stdip/stfl */
423 applied_model
= *model
;
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");
441 /* no host model support -> perform compatibility stuff */
442 apply_cpu_model(NULL
, errp
);
446 max_model
= get_max_cpu_model(errp
);
448 error_prepend(errp
, "CPU models are not available: ");
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
);
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
);
474 error_setg(errp
, "Details about the host CPU model are not available, "
475 "features cannot be queried.");
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
);
492 error_setg(errp
, "Attempt to set property '%s' on '%s' after "
493 "it was realized", name
, object_get_typename(obj
));
495 } else if (!cpu
->model
) {
496 error_setg(errp
, "Details about the host CPU model are not available, "
497 "features cannot be changed.");
501 visit_type_bool(v
, name
, &value
, errp
);
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
);
512 set_bit(feat
, cpu
->model
->features
);
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
);
528 error_setg(errp
, "Details about the host CPU model are not available, "
529 "features cannot be queried.");
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
);
549 error_setg(errp
, "Attempt to set property '%s' on '%s' after "
550 "it was realized", name
, object_get_typename(obj
));
552 } else if (!cpu
->model
) {
553 error_setg(errp
, "Details about the host CPU model are not available, "
554 "features cannot be changed.");
558 visit_type_bool(v
, name
, &value
, errp
);
563 /* groups are added in one shot, so an intersect is sufficient */
564 if (!bitmap_intersects(def
->feat
, cpu
->model
->def
->full_feat
,
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
);
571 bitmap_or(cpu
->model
->features
, cpu
->model
->features
, def
->feat
,
574 bitmap_andnot(cpu
->model
->features
, cpu
->model
->features
, def
->feat
,
579 void s390_cpu_model_register_props(Object
*obj
)
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
,
611 /* latest model - features can change */
612 bitmap_copy(cpu
->model
->features
,
613 cpu
->model
->def
->default_feat
, S390_FEAT_MAX
);
618 static void s390_host_cpu_model_initfn(Object
*obj
)
620 S390CPU
*cpu
= S390_CPU(obj
);
623 if (!kvm_enabled() || !kvm_s390_cpu_models_supported()) {
627 cpu
->model
= g_malloc0(sizeof(*cpu
->model
));
628 kvm_s390_get_host_cpu_model(cpu
->model
, &err
);
630 error_report_err(err
);
632 /* fallback to unsupported cpu models */
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
,
649 static void s390_cpu_model_finalize(Object
*obj
)
651 S390CPU
*cpu
= S390_CPU(obj
);
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
,
676 object_class_property_add_bool(oc
, "static", get_is_static
,
678 object_class_property_add_str(oc
, "description", get_description
, NULL
,
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";
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",
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
);
742 oc
= object_class_by_name(typename
);
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
,
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
,
765 static void register_types(void)
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
);
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
);
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
);
805 type_register_static(&qemu_s390_cpu_type_info
);
807 type_register_static(&host_s390_cpu_type_info
);
811 type_init(register_types
)