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();
158 if (feat
== S390_FEAT_MSA_EXT_3
) {
165 return test_bit(feat
, cpu
->model
->features
);
168 uint8_t s390_get_gen_for_cpu_type(uint16_t type
)
172 for (i
= 0; i
< ARRAY_SIZE(s390_cpu_defs
); i
++) {
173 if (s390_cpu_defs
[i
].type
== type
) {
174 return s390_cpu_defs
[i
].gen
;
180 const S390CPUDef
*s390_find_cpu_def(uint16_t type
, uint8_t gen
, uint8_t ec_ga
,
181 S390FeatBitmap features
)
183 const S390CPUDef
*last_compatible
= NULL
;
190 gen
= s390_get_gen_for_cpu_type(type
);
193 for (i
= 0; i
< ARRAY_SIZE(s390_cpu_defs
); i
++) {
194 const S390CPUDef
*def
= &s390_cpu_defs
[i
];
195 S390FeatBitmap missing
;
197 /* don't even try newer generations if we know the generation */
199 if (def
->gen
> gen
) {
201 } else if (def
->gen
== gen
&& ec_ga
&& def
->ec_ga
> ec_ga
) {
207 /* see if the model satisfies the minimum features */
208 bitmap_andnot(missing
, def
->base_feat
, features
, S390_FEAT_MAX
);
209 if (!bitmap_empty(missing
, S390_FEAT_MAX
)) {
214 /* stop the search if we found the exact model */
215 if (def
->type
== type
&& def
->ec_ga
== ec_ga
) {
218 last_compatible
= def
;
220 return last_compatible
;
223 struct S390PrintCpuListInfo
{
225 fprintf_function print
;
228 static void print_cpu_model_list(ObjectClass
*klass
, void *opaque
)
230 struct S390PrintCpuListInfo
*info
= opaque
;
231 S390CPUClass
*scc
= S390_CPU_CLASS(klass
);
232 char *name
= g_strdup(object_class_get_name(klass
));
233 const char *details
= "";
235 if (scc
->is_static
) {
236 details
= "(static, migration-safe)";
237 } else if (scc
->is_migration_safe
) {
238 details
= "(migration-safe)";
241 /* strip off the -s390-cpu */
242 g_strrstr(name
, "-" TYPE_S390_CPU
)[0] = 0;
243 (*info
->print
)(info
->f
, "s390 %-15s %-35s %s\n", name
, scc
->desc
,
248 void s390_cpu_list(FILE *f
, fprintf_function print
)
250 struct S390PrintCpuListInfo info
= {
257 object_class_foreach(print_cpu_model_list
, TYPE_S390_CPU
, false, &info
);
259 (*print
)(f
, "\nRecognized feature flags:\n");
260 for (feat
= 0; feat
< S390_FEAT_MAX
; feat
++) {
261 const S390FeatDef
*def
= s390_feat_def(feat
);
263 (*print
)(f
, "%-20s %-50s\n", def
->name
, def
->desc
);
266 (*print
)(f
, "\nRecognized feature groups:\n");
267 for (group
= 0; group
< S390_FEAT_GROUP_MAX
; group
++) {
268 const S390FeatGroupDef
*def
= s390_feat_group_def(group
);
270 (*print
)(f
, "%-20s %-50s\n", def
->name
, def
->desc
);
274 #ifndef CONFIG_USER_ONLY
275 static void create_cpu_model_list(ObjectClass
*klass
, void *opaque
)
277 CpuDefinitionInfoList
**cpu_list
= opaque
;
278 CpuDefinitionInfoList
*entry
;
279 CpuDefinitionInfo
*info
;
280 char *name
= g_strdup(object_class_get_name(klass
));
281 S390CPUClass
*scc
= S390_CPU_CLASS(klass
);
283 /* strip off the -s390-cpu */
284 g_strrstr(name
, "-" TYPE_S390_CPU
)[0] = 0;
285 info
= g_malloc0(sizeof(*info
));
287 info
->has_migration_safe
= true;
288 info
->migration_safe
= scc
->is_migration_safe
;
289 info
->q_static
= scc
->is_static
;
292 entry
= g_malloc0(sizeof(*entry
));
294 entry
->next
= *cpu_list
;
298 CpuDefinitionInfoList
*arch_query_cpu_definitions(Error
**errp
)
300 CpuDefinitionInfoList
*list
= NULL
;
302 object_class_foreach(create_cpu_model_list
, TYPE_S390_CPU
, false, &list
);
308 static void check_consistency(const S390CPUModel
*model
)
310 static int dep
[][2] = {
311 { S390_FEAT_IPTE_RANGE
, S390_FEAT_DAT_ENH
},
312 { S390_FEAT_IDTE_SEGMENT
, S390_FEAT_DAT_ENH
},
313 { S390_FEAT_IDTE_REGION
, S390_FEAT_DAT_ENH
},
314 { S390_FEAT_IDTE_REGION
, S390_FEAT_IDTE_SEGMENT
},
315 { S390_FEAT_LOCAL_TLB_CLEARING
, S390_FEAT_DAT_ENH
},
316 { S390_FEAT_LONG_DISPLACEMENT_FAST
, S390_FEAT_LONG_DISPLACEMENT
},
317 { S390_FEAT_DFP_FAST
, S390_FEAT_DFP
},
318 { S390_FEAT_TRANSACTIONAL_EXE
, S390_FEAT_STFLE_49
},
319 { S390_FEAT_EDAT_2
, S390_FEAT_EDAT
},
320 { S390_FEAT_MSA_EXT_5
, S390_FEAT_KIMD_SHA_512
},
321 { S390_FEAT_MSA_EXT_5
, S390_FEAT_KLMD_SHA_512
},
322 { S390_FEAT_MSA_EXT_4
, S390_FEAT_MSA_EXT_3
},
323 { S390_FEAT_SIE_CMMA
, S390_FEAT_CMM
},
324 { S390_FEAT_SIE_CMMA
, S390_FEAT_SIE_GSLS
},
325 { S390_FEAT_SIE_PFMFI
, S390_FEAT_EDAT
},
329 for (i
= 0; i
< ARRAY_SIZE(dep
); i
++) {
330 if (test_bit(dep
[i
][0], model
->features
) &&
331 !test_bit(dep
[i
][1], model
->features
)) {
332 error_report("Warning: \'%s\' requires \'%s\'.",
333 s390_feat_def(dep
[i
][0])->name
,
334 s390_feat_def(dep
[i
][1])->name
);
339 static void error_prepend_missing_feat(const char *name
, void *opaque
)
341 error_prepend((Error
**) opaque
, "%s ", name
);
344 static void check_compatibility(const S390CPUModel
*max_model
,
345 const S390CPUModel
*model
, Error
**errp
)
347 S390FeatBitmap missing
;
349 if (model
->def
->gen
> max_model
->def
->gen
) {
350 error_setg(errp
, "Selected CPU generation is too new. Maximum "
351 "supported model in the configuration: \'%s\'",
352 max_model
->def
->name
);
354 } else if (model
->def
->gen
== max_model
->def
->gen
&&
355 model
->def
->ec_ga
> max_model
->def
->ec_ga
) {
356 error_setg(errp
, "Selected CPU GA level is too new. Maximum "
357 "supported model in the configuration: \'%s\'",
358 max_model
->def
->name
);
362 /* detect the missing features to properly report them */
363 bitmap_andnot(missing
, model
->features
, max_model
->features
, S390_FEAT_MAX
);
364 if (bitmap_empty(missing
, S390_FEAT_MAX
)) {
368 error_setg(errp
, " ");
369 s390_feat_bitmap_to_ascii(missing
, errp
, error_prepend_missing_feat
);
370 error_prepend(errp
, "Some features requested in the CPU model are not "
371 "available in the configuration: ");
374 static S390CPUModel
*get_max_cpu_model(Error
**errp
)
376 #ifndef CONFIG_USER_ONLY
377 static S390CPUModel max_model
;
385 kvm_s390_get_host_cpu_model(&max_model
, errp
);
387 /* TCG enulates a z900 */
388 max_model
.def
= &s390_cpu_defs
[0];
389 bitmap_copy(max_model
.features
, max_model
.def
->default_feat
,
400 static inline void apply_cpu_model(const S390CPUModel
*model
, Error
**errp
)
402 #ifndef CONFIG_USER_ONLY
403 static S390CPUModel applied_model
;
407 * We have the same model for all VCPUs. KVM can only be configured before
408 * any VCPUs are defined in KVM.
411 if (model
&& memcmp(&applied_model
, model
, sizeof(S390CPUModel
))) {
412 error_setg(errp
, "Mixed CPU models are not supported on s390x.");
418 kvm_s390_apply_cpu_model(model
, errp
);
420 /* FIXME TCG - use data for stdip/stfl */
426 applied_model
= *model
;
432 void s390_realize_cpu_model(CPUState
*cs
, Error
**errp
)
434 S390CPUClass
*xcc
= S390_CPU_GET_CLASS(cs
);
435 S390CPU
*cpu
= S390_CPU(cs
);
436 const S390CPUModel
*max_model
;
438 if (xcc
->kvm_required
&& !kvm_enabled()) {
439 error_setg(errp
, "CPU definition requires KVM");
444 /* no host model support -> perform compatibility stuff */
445 apply_cpu_model(NULL
, errp
);
449 max_model
= get_max_cpu_model(errp
);
451 error_prepend(errp
, "CPU models are not available: ");
455 /* copy over properties that can vary */
456 cpu
->model
->lowest_ibc
= max_model
->lowest_ibc
;
457 cpu
->model
->cpu_id
= max_model
->cpu_id
;
458 cpu
->model
->cpu_ver
= max_model
->cpu_ver
;
460 check_consistency(cpu
->model
);
461 check_compatibility(max_model
, cpu
->model
, errp
);
466 apply_cpu_model(cpu
->model
, errp
);
469 static void get_feature(Object
*obj
, Visitor
*v
, const char *name
,
470 void *opaque
, Error
**errp
)
472 S390Feat feat
= (S390Feat
) opaque
;
473 S390CPU
*cpu
= S390_CPU(obj
);
477 error_setg(errp
, "Details about the host CPU model are not available, "
478 "features cannot be queried.");
482 value
= test_bit(feat
, cpu
->model
->features
);
483 visit_type_bool(v
, name
, &value
, errp
);
486 static void set_feature(Object
*obj
, Visitor
*v
, const char *name
,
487 void *opaque
, Error
**errp
)
489 S390Feat feat
= (S390Feat
) opaque
;
490 DeviceState
*dev
= DEVICE(obj
);
491 S390CPU
*cpu
= S390_CPU(obj
);
495 error_setg(errp
, "Attempt to set property '%s' on '%s' after "
496 "it was realized", name
, object_get_typename(obj
));
498 } else if (!cpu
->model
) {
499 error_setg(errp
, "Details about the host CPU model are not available, "
500 "features cannot be changed.");
504 visit_type_bool(v
, name
, &value
, errp
);
509 if (!test_bit(feat
, cpu
->model
->def
->full_feat
)) {
510 error_setg(errp
, "Feature '%s' is not available for CPU model '%s',"
511 " it was introduced with later models.",
512 name
, cpu
->model
->def
->name
);
515 set_bit(feat
, cpu
->model
->features
);
517 clear_bit(feat
, cpu
->model
->features
);
521 static void get_feature_group(Object
*obj
, Visitor
*v
, const char *name
,
522 void *opaque
, Error
**errp
)
524 S390FeatGroup group
= (S390FeatGroup
) opaque
;
525 const S390FeatGroupDef
*def
= s390_feat_group_def(group
);
526 S390CPU
*cpu
= S390_CPU(obj
);
531 error_setg(errp
, "Details about the host CPU model are not available, "
532 "features cannot be queried.");
536 /* a group is enabled if all features are enabled */
537 bitmap_and(tmp
, cpu
->model
->features
, def
->feat
, S390_FEAT_MAX
);
538 value
= bitmap_equal(tmp
, def
->feat
, S390_FEAT_MAX
);
539 visit_type_bool(v
, name
, &value
, errp
);
542 static void set_feature_group(Object
*obj
, Visitor
*v
, const char *name
,
543 void *opaque
, Error
**errp
)
545 S390FeatGroup group
= (S390FeatGroup
) opaque
;
546 const S390FeatGroupDef
*def
= s390_feat_group_def(group
);
547 DeviceState
*dev
= DEVICE(obj
);
548 S390CPU
*cpu
= S390_CPU(obj
);
552 error_setg(errp
, "Attempt to set property '%s' on '%s' after "
553 "it was realized", name
, object_get_typename(obj
));
555 } else if (!cpu
->model
) {
556 error_setg(errp
, "Details about the host CPU model are not available, "
557 "features cannot be changed.");
561 visit_type_bool(v
, name
, &value
, errp
);
566 /* groups are added in one shot, so an intersect is sufficient */
567 if (!bitmap_intersects(def
->feat
, cpu
->model
->def
->full_feat
,
569 error_setg(errp
, "Group '%s' is not available for CPU model '%s',"
570 " it was introduced with later models.",
571 name
, cpu
->model
->def
->name
);
574 bitmap_or(cpu
->model
->features
, cpu
->model
->features
, def
->feat
,
577 bitmap_andnot(cpu
->model
->features
, cpu
->model
->features
, def
->feat
,
582 void s390_cpu_model_register_props(Object
*obj
)
587 for (feat
= 0; feat
< S390_FEAT_MAX
; feat
++) {
588 const S390FeatDef
*def
= s390_feat_def(feat
);
589 object_property_add(obj
, def
->name
, "bool", get_feature
,
590 set_feature
, NULL
, (void *) feat
, NULL
);
591 object_property_set_description(obj
, def
->name
, def
->desc
, NULL
);
593 for (group
= 0; group
< S390_FEAT_GROUP_MAX
; group
++) {
594 const S390FeatGroupDef
*def
= s390_feat_group_def(group
);
595 object_property_add(obj
, def
->name
, "bool", get_feature_group
,
596 set_feature_group
, NULL
, (void *) group
, NULL
);
597 object_property_set_description(obj
, def
->name
, def
->desc
, NULL
);
601 static void s390_cpu_model_initfn(Object
*obj
)
603 S390CPU
*cpu
= S390_CPU(obj
);
604 S390CPUClass
*xcc
= S390_CPU_GET_CLASS(cpu
);
606 cpu
->model
= g_malloc0(sizeof(*cpu
->model
));
607 /* copy the model, so we can modify it */
608 cpu
->model
->def
= xcc
->cpu_def
;
609 if (xcc
->is_static
) {
610 /* base model - features will never change */
611 bitmap_copy(cpu
->model
->features
, cpu
->model
->def
->base_feat
,
614 /* latest model - features can change */
615 bitmap_copy(cpu
->model
->features
,
616 cpu
->model
->def
->default_feat
, S390_FEAT_MAX
);
621 static void s390_host_cpu_model_initfn(Object
*obj
)
623 S390CPU
*cpu
= S390_CPU(obj
);
626 if (!kvm_enabled() || !kvm_s390_cpu_models_supported()) {
630 cpu
->model
= g_malloc0(sizeof(*cpu
->model
));
631 kvm_s390_get_host_cpu_model(cpu
->model
, &err
);
633 error_report_err(err
);
635 /* fallback to unsupported cpu models */
641 static void s390_qemu_cpu_model_initfn(Object
*obj
)
643 S390CPU
*cpu
= S390_CPU(obj
);
645 cpu
->model
= g_malloc0(sizeof(*cpu
->model
));
646 /* TCG emulates a z900 */
647 cpu
->model
->def
= &s390_cpu_defs
[0];
648 bitmap_copy(cpu
->model
->features
, cpu
->model
->def
->default_feat
,
652 static void s390_cpu_model_finalize(Object
*obj
)
654 S390CPU
*cpu
= S390_CPU(obj
);
660 static bool get_is_migration_safe(Object
*obj
, Error
**errp
)
662 return S390_CPU_GET_CLASS(obj
)->is_migration_safe
;
665 static bool get_is_static(Object
*obj
, Error
**errp
)
667 return S390_CPU_GET_CLASS(obj
)->is_static
;
670 static char *get_description(Object
*obj
, Error
**errp
)
672 return g_strdup(S390_CPU_GET_CLASS(obj
)->desc
);
675 void s390_cpu_model_class_register_props(ObjectClass
*oc
)
677 object_class_property_add_bool(oc
, "migration-safe", get_is_migration_safe
,
679 object_class_property_add_bool(oc
, "static", get_is_static
,
681 object_class_property_add_str(oc
, "description", get_description
, NULL
,
686 static void s390_host_cpu_model_class_init(ObjectClass
*oc
, void *data
)
688 S390CPUClass
*xcc
= S390_CPU_CLASS(oc
);
690 xcc
->kvm_required
= true;
691 xcc
->desc
= "KVM only: All recognized features";
695 static void s390_base_cpu_model_class_init(ObjectClass
*oc
, void *data
)
697 S390CPUClass
*xcc
= S390_CPU_CLASS(oc
);
699 /* all base models are migration safe */
700 xcc
->cpu_def
= (const S390CPUDef
*) data
;
701 xcc
->is_migration_safe
= true;
702 xcc
->is_static
= true;
703 xcc
->desc
= xcc
->cpu_def
->desc
;
706 static void s390_cpu_model_class_init(ObjectClass
*oc
, void *data
)
708 S390CPUClass
*xcc
= S390_CPU_CLASS(oc
);
710 /* model that can change between QEMU versions */
711 xcc
->cpu_def
= (const S390CPUDef
*) data
;
712 xcc
->is_migration_safe
= true;
713 xcc
->desc
= xcc
->cpu_def
->desc
;
716 static void s390_qemu_cpu_model_class_init(ObjectClass
*oc
, void *data
)
718 S390CPUClass
*xcc
= S390_CPU_CLASS(oc
);
720 xcc
->is_migration_safe
= true;
721 xcc
->desc
= g_strdup_printf("QEMU Virtual CPU version %s",
725 #define S390_CPU_TYPE_SUFFIX "-" TYPE_S390_CPU
726 #define S390_CPU_TYPE_NAME(name) (name S390_CPU_TYPE_SUFFIX)
728 /* Generate type name for a cpu model. Caller has to free the string. */
729 static char *s390_cpu_type_name(const char *model_name
)
731 return g_strdup_printf(S390_CPU_TYPE_NAME("%s"), model_name
);
734 /* Generate type name for a base cpu model. Caller has to free the string. */
735 static char *s390_base_cpu_type_name(const char *model_name
)
737 return g_strdup_printf(S390_CPU_TYPE_NAME("%s-base"), model_name
);
740 ObjectClass
*s390_cpu_class_by_name(const char *name
)
742 char *typename
= s390_cpu_type_name(name
);
745 oc
= object_class_by_name(typename
);
750 static const TypeInfo qemu_s390_cpu_type_info
= {
751 .name
= S390_CPU_TYPE_NAME("qemu"),
752 .parent
= TYPE_S390_CPU
,
753 .instance_init
= s390_qemu_cpu_model_initfn
,
754 .instance_finalize
= s390_cpu_model_finalize
,
755 .class_init
= s390_qemu_cpu_model_class_init
,
759 static const TypeInfo host_s390_cpu_type_info
= {
760 .name
= S390_CPU_TYPE_NAME("host"),
761 .parent
= TYPE_S390_CPU
,
762 .instance_init
= s390_host_cpu_model_initfn
,
763 .instance_finalize
= s390_cpu_model_finalize
,
764 .class_init
= s390_host_cpu_model_class_init
,
768 static void register_types(void)
772 /* init all bitmaps from gnerated data initially */
773 for (i
= 0; i
< ARRAY_SIZE(s390_cpu_defs
); i
++) {
774 s390_init_feat_bitmap(s390_cpu_defs
[i
].base_init
,
775 s390_cpu_defs
[i
].base_feat
);
776 s390_init_feat_bitmap(s390_cpu_defs
[i
].default_init
,
777 s390_cpu_defs
[i
].default_feat
);
778 s390_init_feat_bitmap(s390_cpu_defs
[i
].full_init
,
779 s390_cpu_defs
[i
].full_feat
);
782 for (i
= 0; i
< ARRAY_SIZE(s390_cpu_defs
); i
++) {
783 char *base_name
= s390_base_cpu_type_name(s390_cpu_defs
[i
].name
);
786 .parent
= TYPE_S390_CPU
,
787 .instance_init
= s390_cpu_model_initfn
,
788 .instance_finalize
= s390_cpu_model_finalize
,
789 .class_init
= s390_base_cpu_model_class_init
,
790 .class_data
= (void *) &s390_cpu_defs
[i
],
792 char *name
= s390_cpu_type_name(s390_cpu_defs
[i
].name
);
795 .parent
= TYPE_S390_CPU
,
796 .instance_init
= s390_cpu_model_initfn
,
797 .instance_finalize
= s390_cpu_model_finalize
,
798 .class_init
= s390_cpu_model_class_init
,
799 .class_data
= (void *) &s390_cpu_defs
[i
],
802 type_register_static(&ti_base
);
803 type_register_static(&ti
);
808 type_register_static(&qemu_s390_cpu_type_info
);
810 type_register_static(&host_s390_cpu_type_info
);
814 type_init(register_types
)