1 /* 2 * CPU models for s390x 3 * 4 * Copyright 2016 IBM Corp. 5 * 6 * Author(s): David Hildenbrand <dahi@linux.vnet.ibm.com> 7 * 8 * This work is licensed under the terms of the GNU GPL, version 2 or (at 9 * your option) any later version. See the COPYING file in the top-level 10 * directory. 11 */ 12 13 #include "qemu/osdep.h" 14 #include "cpu.h" 15 #include "internal.h" 16 #include "gen-features.h" 17 #include "qapi/error.h" 18 #include "qapi/visitor.h" 19 #include "qemu/error-report.h" 20 #include "qapi/qmp/qerror.h" 21 #include "qapi/qobject-input-visitor.h" 22 #include "qapi/qmp/qbool.h" 23 #ifndef CONFIG_USER_ONLY 24 #include "sysemu/arch_init.h" 25 #endif 26 27 #define CPUDEF_INIT(_type, _gen, _ec_ga, _mha_pow, _hmfai, _name, _desc) \ 28 { \ 29 .name = _name, \ 30 .type = _type, \ 31 .gen = _gen, \ 32 .ec_ga = _ec_ga, \ 33 .mha_pow = _mha_pow, \ 34 .hmfai = _hmfai, \ 35 .desc = _desc, \ 36 .base_init = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _BASE }, \ 37 .default_init = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _DEFAULT }, \ 38 .full_init = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _FULL }, \ 39 } 40 41 /* 42 * CPU definiton list in order of release. For now, base features of a 43 * following release are always a subset of base features of the previous 44 * release. Same is correct for the other feature sets. 45 * A BC release always follows the corresponding EC release. 46 */ 47 static S390CPUDef s390_cpu_defs[] = { 48 CPUDEF_INIT(0x2064, 7, 1, 38, 0x00000000U, "z900", "IBM zSeries 900 GA1"), 49 CPUDEF_INIT(0x2064, 7, 2, 38, 0x00000000U, "z900.2", "IBM zSeries 900 GA2"), 50 CPUDEF_INIT(0x2064, 7, 3, 38, 0x00000000U, "z900.3", "IBM zSeries 900 GA3"), 51 CPUDEF_INIT(0x2066, 7, 3, 38, 0x00000000U, "z800", "IBM zSeries 800 GA1"), 52 CPUDEF_INIT(0x2084, 8, 1, 38, 0x00000000U, "z990", "IBM zSeries 990 GA1"), 53 CPUDEF_INIT(0x2084, 8, 2, 38, 0x00000000U, "z990.2", "IBM zSeries 990 GA2"), 54 CPUDEF_INIT(0x2084, 8, 3, 38, 0x00000000U, "z990.3", "IBM zSeries 990 GA3"), 55 CPUDEF_INIT(0x2086, 8, 3, 38, 0x00000000U, "z890", "IBM zSeries 880 GA1"), 56 CPUDEF_INIT(0x2084, 8, 4, 38, 0x00000000U, "z990.4", "IBM zSeries 990 GA4"), 57 CPUDEF_INIT(0x2086, 8, 4, 38, 0x00000000U, "z890.2", "IBM zSeries 880 GA2"), 58 CPUDEF_INIT(0x2084, 8, 5, 38, 0x00000000U, "z990.5", "IBM zSeries 990 GA5"), 59 CPUDEF_INIT(0x2086, 8, 5, 38, 0x00000000U, "z890.3", "IBM zSeries 880 GA3"), 60 CPUDEF_INIT(0x2094, 9, 1, 40, 0x00000000U, "z9EC", "IBM System z9 EC GA1"), 61 CPUDEF_INIT(0x2094, 9, 2, 40, 0x00000000U, "z9EC.2", "IBM System z9 EC GA2"), 62 CPUDEF_INIT(0x2096, 9, 2, 40, 0x00000000U, "z9BC", "IBM System z9 BC GA1"), 63 CPUDEF_INIT(0x2094, 9, 3, 40, 0x00000000U, "z9EC.3", "IBM System z9 EC GA3"), 64 CPUDEF_INIT(0x2096, 9, 3, 40, 0x00000000U, "z9BC.2", "IBM System z9 BC GA2"), 65 CPUDEF_INIT(0x2097, 10, 1, 43, 0x00000000U, "z10EC", "IBM System z10 EC GA1"), 66 CPUDEF_INIT(0x2097, 10, 2, 43, 0x00000000U, "z10EC.2", "IBM System z10 EC GA2"), 67 CPUDEF_INIT(0x2098, 10, 2, 43, 0x00000000U, "z10BC", "IBM System z10 BC GA1"), 68 CPUDEF_INIT(0x2097, 10, 3, 43, 0x00000000U, "z10EC.3", "IBM System z10 EC GA3"), 69 CPUDEF_INIT(0x2098, 10, 3, 43, 0x00000000U, "z10BC.2", "IBM System z10 BC GA2"), 70 CPUDEF_INIT(0x2817, 11, 1, 44, 0x08000000U, "z196", "IBM zEnterprise 196 GA1"), 71 CPUDEF_INIT(0x2817, 11, 2, 44, 0x08000000U, "z196.2", "IBM zEnterprise 196 GA2"), 72 CPUDEF_INIT(0x2818, 11, 2, 44, 0x08000000U, "z114", "IBM zEnterprise 114 GA1"), 73 CPUDEF_INIT(0x2827, 12, 1, 44, 0x08000000U, "zEC12", "IBM zEnterprise EC12 GA1"), 74 CPUDEF_INIT(0x2827, 12, 2, 44, 0x08000000U, "zEC12.2", "IBM zEnterprise EC12 GA2"), 75 CPUDEF_INIT(0x2828, 12, 2, 44, 0x08000000U, "zBC12", "IBM zEnterprise BC12 GA1"), 76 CPUDEF_INIT(0x2964, 13, 1, 47, 0x08000000U, "z13", "IBM z13 GA1"), 77 CPUDEF_INIT(0x2964, 13, 2, 47, 0x08000000U, "z13.2", "IBM z13 GA2"), 78 CPUDEF_INIT(0x2965, 13, 2, 47, 0x08000000U, "z13s", "IBM z13s GA1"), 79 CPUDEF_INIT(0x3906, 14, 1, 47, 0x08000000U, "z14", "IBM z14 GA1"), 80 }; 81 82 /* features part of a base model but not relevant for finding a base model */ 83 S390FeatBitmap ignored_base_feat; 84 85 void s390_cpudef_featoff(uint8_t gen, uint8_t ec_ga, S390Feat feat) 86 { 87 const S390CPUDef *def; 88 89 def = s390_find_cpu_def(0, gen, ec_ga, NULL); 90 clear_bit(feat, (unsigned long *)&def->default_feat); 91 } 92 93 void s390_cpudef_featoff_greater(uint8_t gen, uint8_t ec_ga, S390Feat feat) 94 { 95 int i; 96 97 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) { 98 const S390CPUDef *def = &s390_cpu_defs[i]; 99 100 if (def->gen < gen) { 101 continue; 102 } 103 if (def->gen == gen && def->ec_ga < ec_ga) { 104 continue; 105 } 106 107 clear_bit(feat, (unsigned long *)&def->default_feat); 108 } 109 } 110 111 uint32_t s390_get_hmfai(void) 112 { 113 static S390CPU *cpu; 114 115 if (!cpu) { 116 cpu = S390_CPU(qemu_get_cpu(0)); 117 } 118 119 if (!cpu || !cpu->model) { 120 return 0; 121 } 122 return cpu->model->def->hmfai; 123 } 124 125 uint8_t s390_get_mha_pow(void) 126 { 127 static S390CPU *cpu; 128 129 if (!cpu) { 130 cpu = S390_CPU(qemu_get_cpu(0)); 131 } 132 133 if (!cpu || !cpu->model) { 134 return 0; 135 } 136 return cpu->model->def->mha_pow; 137 } 138 139 uint32_t s390_get_ibc_val(void) 140 { 141 uint16_t unblocked_ibc, lowest_ibc; 142 static S390CPU *cpu; 143 144 if (!cpu) { 145 cpu = S390_CPU(qemu_get_cpu(0)); 146 } 147 148 if (!cpu || !cpu->model) { 149 return 0; 150 } 151 unblocked_ibc = s390_ibc_from_cpu_model(cpu->model); 152 lowest_ibc = cpu->model->lowest_ibc; 153 /* the lowest_ibc always has to be <= unblocked_ibc */ 154 if (!lowest_ibc || lowest_ibc > unblocked_ibc) { 155 return 0; 156 } 157 return ((uint32_t) lowest_ibc << 16) | unblocked_ibc; 158 } 159 160 void s390_get_feat_block(S390FeatType type, uint8_t *data) 161 { 162 static S390CPU *cpu; 163 164 if (!cpu) { 165 cpu = S390_CPU(qemu_get_cpu(0)); 166 } 167 168 if (!cpu || !cpu->model) { 169 return; 170 } 171 s390_fill_feat_block(cpu->model->features, type, data); 172 } 173 174 bool s390_has_feat(S390Feat feat) 175 { 176 static S390CPU *cpu; 177 178 if (!cpu) { 179 cpu = S390_CPU(qemu_get_cpu(0)); 180 } 181 182 if (!cpu || !cpu->model) { 183 #ifdef CONFIG_KVM 184 if (kvm_enabled()) { 185 if (feat == S390_FEAT_VECTOR) { 186 return kvm_check_extension(kvm_state, 187 KVM_CAP_S390_VECTOR_REGISTERS); 188 } 189 if (feat == S390_FEAT_RUNTIME_INSTRUMENTATION) { 190 return kvm_s390_get_ri(); 191 } 192 if (feat == S390_FEAT_MSA_EXT_3) { 193 return true; 194 } 195 } 196 #endif 197 return 0; 198 } 199 return test_bit(feat, cpu->model->features); 200 } 201 202 uint8_t s390_get_gen_for_cpu_type(uint16_t type) 203 { 204 int i; 205 206 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) { 207 if (s390_cpu_defs[i].type == type) { 208 return s390_cpu_defs[i].gen; 209 } 210 } 211 return 0; 212 } 213 214 const S390CPUDef *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga, 215 S390FeatBitmap features) 216 { 217 const S390CPUDef *last_compatible = NULL; 218 const S390CPUDef *matching_cpu_type = NULL; 219 int i; 220 221 if (!gen) { 222 ec_ga = 0; 223 } 224 if (!gen && type) { 225 gen = s390_get_gen_for_cpu_type(type); 226 } 227 228 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) { 229 const S390CPUDef *def = &s390_cpu_defs[i]; 230 S390FeatBitmap missing; 231 232 /* don't even try newer generations if we know the generation */ 233 if (gen) { 234 if (def->gen > gen) { 235 break; 236 } else if (def->gen == gen && ec_ga && def->ec_ga > ec_ga) { 237 break; 238 } 239 } 240 241 if (features) { 242 /* see if the model satisfies the minimum features */ 243 bitmap_andnot(missing, def->base_feat, features, S390_FEAT_MAX); 244 /* 245 * Ignore certain features that are in the base model, but not 246 * relevant for the search (esp. MSA subfunctions). 247 */ 248 bitmap_andnot(missing, missing, ignored_base_feat, S390_FEAT_MAX); 249 if (!bitmap_empty(missing, S390_FEAT_MAX)) { 250 break; 251 } 252 } 253 254 /* stop the search if we found the exact model */ 255 if (def->type == type && def->ec_ga == ec_ga) { 256 return def; 257 } 258 /* remember if we've at least seen one with the same cpu type */ 259 if (def->type == type) { 260 matching_cpu_type = def; 261 } 262 last_compatible = def; 263 } 264 /* prefer the model with the same cpu type, esp. don't take the BC for EC */ 265 if (matching_cpu_type) { 266 return matching_cpu_type; 267 } 268 return last_compatible; 269 } 270 271 struct S390PrintCpuListInfo { 272 FILE *f; 273 fprintf_function print; 274 }; 275 276 static void print_cpu_model_list(ObjectClass *klass, void *opaque) 277 { 278 struct S390PrintCpuListInfo *info = opaque; 279 S390CPUClass *scc = S390_CPU_CLASS(klass); 280 char *name = g_strdup(object_class_get_name(klass)); 281 const char *details = ""; 282 283 if (scc->is_static) { 284 details = "(static, migration-safe)"; 285 } else if (scc->is_migration_safe) { 286 details = "(migration-safe)"; 287 } 288 289 /* strip off the -s390-cpu */ 290 g_strrstr(name, "-" TYPE_S390_CPU)[0] = 0; 291 (*info->print)(info->f, "s390 %-15s %-35s %s\n", name, scc->desc, 292 details); 293 g_free(name); 294 } 295 296 void s390_cpu_list(FILE *f, fprintf_function print) 297 { 298 struct S390PrintCpuListInfo info = { 299 .f = f, 300 .print = print, 301 }; 302 S390FeatGroup group; 303 S390Feat feat; 304 305 object_class_foreach(print_cpu_model_list, TYPE_S390_CPU, false, &info); 306 307 (*print)(f, "\nRecognized feature flags:\n"); 308 for (feat = 0; feat < S390_FEAT_MAX; feat++) { 309 const S390FeatDef *def = s390_feat_def(feat); 310 311 (*print)(f, "%-20s %-50s\n", def->name, def->desc); 312 } 313 314 (*print)(f, "\nRecognized feature groups:\n"); 315 for (group = 0; group < S390_FEAT_GROUP_MAX; group++) { 316 const S390FeatGroupDef *def = s390_feat_group_def(group); 317 318 (*print)(f, "%-20s %-50s\n", def->name, def->desc); 319 } 320 } 321 322 static S390CPUModel *get_max_cpu_model(Error **errp); 323 324 #ifndef CONFIG_USER_ONLY 325 static void list_add_feat(const char *name, void *opaque); 326 327 static void check_unavailable_features(const S390CPUModel *max_model, 328 const S390CPUModel *model, 329 strList **unavailable) 330 { 331 S390FeatBitmap missing; 332 333 /* check general model compatibility */ 334 if (max_model->def->gen < model->def->gen || 335 (max_model->def->gen == model->def->gen && 336 max_model->def->ec_ga < model->def->ec_ga)) { 337 list_add_feat("type", unavailable); 338 } 339 340 /* detect missing features if any to properly report them */ 341 bitmap_andnot(missing, model->features, max_model->features, 342 S390_FEAT_MAX); 343 if (!bitmap_empty(missing, S390_FEAT_MAX)) { 344 s390_feat_bitmap_to_ascii(missing, unavailable, list_add_feat); 345 } 346 } 347 348 struct CpuDefinitionInfoListData { 349 CpuDefinitionInfoList *list; 350 S390CPUModel *model; 351 }; 352 353 static void create_cpu_model_list(ObjectClass *klass, void *opaque) 354 { 355 struct CpuDefinitionInfoListData *cpu_list_data = opaque; 356 CpuDefinitionInfoList **cpu_list = &cpu_list_data->list; 357 CpuDefinitionInfoList *entry; 358 CpuDefinitionInfo *info; 359 char *name = g_strdup(object_class_get_name(klass)); 360 S390CPUClass *scc = S390_CPU_CLASS(klass); 361 362 /* strip off the -s390-cpu */ 363 g_strrstr(name, "-" TYPE_S390_CPU)[0] = 0; 364 info = g_malloc0(sizeof(*info)); 365 info->name = name; 366 info->has_migration_safe = true; 367 info->migration_safe = scc->is_migration_safe; 368 info->q_static = scc->is_static; 369 info->q_typename = g_strdup(object_class_get_name(klass)); 370 /* check for unavailable features */ 371 if (cpu_list_data->model) { 372 Object *obj; 373 S390CPU *sc; 374 obj = object_new(object_class_get_name(klass)); 375 sc = S390_CPU(obj); 376 if (sc->model) { 377 info->has_unavailable_features = true; 378 check_unavailable_features(cpu_list_data->model, sc->model, 379 &info->unavailable_features); 380 } 381 object_unref(obj); 382 } 383 384 entry = g_malloc0(sizeof(*entry)); 385 entry->value = info; 386 entry->next = *cpu_list; 387 *cpu_list = entry; 388 } 389 390 CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) 391 { 392 struct CpuDefinitionInfoListData list_data = { 393 .list = NULL, 394 }; 395 396 list_data.model = get_max_cpu_model(errp); 397 if (*errp) { 398 error_free(*errp); 399 *errp = NULL; 400 } 401 402 object_class_foreach(create_cpu_model_list, TYPE_S390_CPU, false, 403 &list_data); 404 405 return list_data.list; 406 } 407 408 static void cpu_model_from_info(S390CPUModel *model, const CpuModelInfo *info, 409 Error **errp) 410 { 411 const QDict *qdict = NULL; 412 const QDictEntry *e; 413 Visitor *visitor; 414 ObjectClass *oc; 415 S390CPU *cpu; 416 Object *obj; 417 418 if (info->props) { 419 qdict = qobject_to_qdict(info->props); 420 if (!qdict) { 421 error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict"); 422 return; 423 } 424 } 425 426 oc = cpu_class_by_name(TYPE_S390_CPU, info->name); 427 if (!oc) { 428 error_setg(errp, "The CPU definition \'%s\' is unknown.", info->name); 429 return; 430 } 431 if (S390_CPU_CLASS(oc)->kvm_required && !kvm_enabled()) { 432 error_setg(errp, "The CPU definition '%s' requires KVM", info->name); 433 return; 434 } 435 obj = object_new(object_class_get_name(oc)); 436 cpu = S390_CPU(obj); 437 438 if (!cpu->model) { 439 error_setg(errp, "Details about the host CPU model are not available, " 440 "it cannot be used."); 441 object_unref(obj); 442 return; 443 } 444 445 if (qdict) { 446 visitor = qobject_input_visitor_new(info->props); 447 visit_start_struct(visitor, NULL, NULL, 0, errp); 448 if (*errp) { 449 object_unref(obj); 450 return; 451 } 452 for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) { 453 object_property_set(obj, visitor, e->key, errp); 454 if (*errp) { 455 break; 456 } 457 } 458 if (!*errp) { 459 visit_check_struct(visitor, errp); 460 } 461 visit_end_struct(visitor, NULL); 462 visit_free(visitor); 463 if (*errp) { 464 object_unref(obj); 465 return; 466 } 467 } 468 469 /* copy the model and throw the cpu away */ 470 memcpy(model, cpu->model, sizeof(*model)); 471 object_unref(obj); 472 } 473 474 static void qdict_add_disabled_feat(const char *name, void *opaque) 475 { 476 qdict_put_bool(opaque, name, false); 477 } 478 479 static void qdict_add_enabled_feat(const char *name, void *opaque) 480 { 481 qdict_put_bool(opaque, name, true); 482 } 483 484 /* convert S390CPUDef into a static CpuModelInfo */ 485 static void cpu_info_from_model(CpuModelInfo *info, const S390CPUModel *model, 486 bool delta_changes) 487 { 488 QDict *qdict = qdict_new(); 489 S390FeatBitmap bitmap; 490 491 /* always fallback to the static base model */ 492 info->name = g_strdup_printf("%s-base", model->def->name); 493 494 if (delta_changes) { 495 /* features deleted from the base feature set */ 496 bitmap_andnot(bitmap, model->def->base_feat, model->features, 497 S390_FEAT_MAX); 498 if (!bitmap_empty(bitmap, S390_FEAT_MAX)) { 499 s390_feat_bitmap_to_ascii(bitmap, qdict, qdict_add_disabled_feat); 500 } 501 502 /* features added to the base feature set */ 503 bitmap_andnot(bitmap, model->features, model->def->base_feat, 504 S390_FEAT_MAX); 505 if (!bitmap_empty(bitmap, S390_FEAT_MAX)) { 506 s390_feat_bitmap_to_ascii(bitmap, qdict, qdict_add_enabled_feat); 507 } 508 } else { 509 /* expand all features */ 510 s390_feat_bitmap_to_ascii(model->features, qdict, 511 qdict_add_enabled_feat); 512 bitmap_complement(bitmap, model->features, S390_FEAT_MAX); 513 s390_feat_bitmap_to_ascii(bitmap, qdict, qdict_add_disabled_feat); 514 } 515 516 if (!qdict_size(qdict)) { 517 QDECREF(qdict); 518 } else { 519 info->props = QOBJECT(qdict); 520 info->has_props = true; 521 } 522 } 523 524 CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type, 525 CpuModelInfo *model, 526 Error **errp) 527 { 528 CpuModelExpansionInfo *expansion_info = NULL; 529 S390CPUModel s390_model; 530 bool delta_changes = false; 531 532 /* convert it to our internal representation */ 533 cpu_model_from_info(&s390_model, model, errp); 534 if (*errp) { 535 return NULL; 536 } 537 538 if (type == CPU_MODEL_EXPANSION_TYPE_STATIC) { 539 delta_changes = true; 540 } else if (type != CPU_MODEL_EXPANSION_TYPE_FULL) { 541 error_setg(errp, "The requested expansion type is not supported."); 542 return NULL; 543 } 544 545 /* convert it back to a static representation */ 546 expansion_info = g_malloc0(sizeof(*expansion_info)); 547 expansion_info->model = g_malloc0(sizeof(*expansion_info->model)); 548 cpu_info_from_model(expansion_info->model, &s390_model, delta_changes); 549 return expansion_info; 550 } 551 552 static void list_add_feat(const char *name, void *opaque) 553 { 554 strList **last = (strList **) opaque; 555 strList *entry; 556 557 entry = g_malloc0(sizeof(*entry)); 558 entry->value = g_strdup(name); 559 entry->next = *last; 560 *last = entry; 561 } 562 563 CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *infoa, 564 CpuModelInfo *infob, 565 Error **errp) 566 { 567 CpuModelCompareResult feat_result, gen_result; 568 CpuModelCompareInfo *compare_info; 569 S390FeatBitmap missing, added; 570 S390CPUModel modela, modelb; 571 572 /* convert both models to our internal representation */ 573 cpu_model_from_info(&modela, infoa, errp); 574 if (*errp) { 575 return NULL; 576 } 577 cpu_model_from_info(&modelb, infob, errp); 578 if (*errp) { 579 return NULL; 580 } 581 compare_info = g_malloc0(sizeof(*compare_info)); 582 583 /* check the cpu generation and ga level */ 584 if (modela.def->gen == modelb.def->gen) { 585 if (modela.def->ec_ga == modelb.def->ec_ga) { 586 /* ec and corresponding bc are identical */ 587 gen_result = CPU_MODEL_COMPARE_RESULT_IDENTICAL; 588 } else if (modela.def->ec_ga < modelb.def->ec_ga) { 589 gen_result = CPU_MODEL_COMPARE_RESULT_SUBSET; 590 } else { 591 gen_result = CPU_MODEL_COMPARE_RESULT_SUPERSET; 592 } 593 } else if (modela.def->gen < modelb.def->gen) { 594 gen_result = CPU_MODEL_COMPARE_RESULT_SUBSET; 595 } else { 596 gen_result = CPU_MODEL_COMPARE_RESULT_SUPERSET; 597 } 598 if (gen_result != CPU_MODEL_COMPARE_RESULT_IDENTICAL) { 599 /* both models cannot be made identical */ 600 list_add_feat("type", &compare_info->responsible_properties); 601 } 602 603 /* check the feature set */ 604 if (bitmap_equal(modela.features, modelb.features, S390_FEAT_MAX)) { 605 feat_result = CPU_MODEL_COMPARE_RESULT_IDENTICAL; 606 } else { 607 bitmap_andnot(missing, modela.features, modelb.features, S390_FEAT_MAX); 608 s390_feat_bitmap_to_ascii(missing, 609 &compare_info->responsible_properties, 610 list_add_feat); 611 bitmap_andnot(added, modelb.features, modela.features, S390_FEAT_MAX); 612 s390_feat_bitmap_to_ascii(added, &compare_info->responsible_properties, 613 list_add_feat); 614 if (bitmap_empty(missing, S390_FEAT_MAX)) { 615 feat_result = CPU_MODEL_COMPARE_RESULT_SUBSET; 616 } else if (bitmap_empty(added, S390_FEAT_MAX)) { 617 feat_result = CPU_MODEL_COMPARE_RESULT_SUPERSET; 618 } else { 619 feat_result = CPU_MODEL_COMPARE_RESULT_INCOMPATIBLE; 620 } 621 } 622 623 /* combine the results */ 624 if (gen_result == feat_result) { 625 compare_info->result = gen_result; 626 } else if (feat_result == CPU_MODEL_COMPARE_RESULT_IDENTICAL) { 627 compare_info->result = gen_result; 628 } else if (gen_result == CPU_MODEL_COMPARE_RESULT_IDENTICAL) { 629 compare_info->result = feat_result; 630 } else { 631 compare_info->result = CPU_MODEL_COMPARE_RESULT_INCOMPATIBLE; 632 } 633 return compare_info; 634 } 635 636 CpuModelBaselineInfo *arch_query_cpu_model_baseline(CpuModelInfo *infoa, 637 CpuModelInfo *infob, 638 Error **errp) 639 { 640 CpuModelBaselineInfo *baseline_info; 641 S390CPUModel modela, modelb, model; 642 uint16_t cpu_type; 643 uint8_t max_gen_ga; 644 uint8_t max_gen; 645 646 /* convert both models to our internal representation */ 647 cpu_model_from_info(&modela, infoa, errp); 648 if (*errp) { 649 return NULL; 650 } 651 652 cpu_model_from_info(&modelb, infob, errp); 653 if (*errp) { 654 return NULL; 655 } 656 657 /* features both models support */ 658 bitmap_and(model.features, modela.features, modelb.features, S390_FEAT_MAX); 659 660 /* detect the maximum model not regarding features */ 661 if (modela.def->gen == modelb.def->gen) { 662 if (modela.def->type == modelb.def->type) { 663 cpu_type = modela.def->type; 664 } else { 665 cpu_type = 0; 666 } 667 max_gen = modela.def->gen; 668 max_gen_ga = MIN(modela.def->ec_ga, modelb.def->ec_ga); 669 } else if (modela.def->gen > modelb.def->gen) { 670 cpu_type = modelb.def->type; 671 max_gen = modelb.def->gen; 672 max_gen_ga = modelb.def->ec_ga; 673 } else { 674 cpu_type = modela.def->type; 675 max_gen = modela.def->gen; 676 max_gen_ga = modela.def->ec_ga; 677 } 678 679 model.def = s390_find_cpu_def(cpu_type, max_gen, max_gen_ga, 680 model.features); 681 /* strip off features not part of the max model */ 682 bitmap_and(model.features, model.features, model.def->full_feat, 683 S390_FEAT_MAX); 684 685 baseline_info = g_malloc0(sizeof(*baseline_info)); 686 baseline_info->model = g_malloc0(sizeof(*baseline_info->model)); 687 cpu_info_from_model(baseline_info->model, &model, true); 688 return baseline_info; 689 } 690 #endif 691 692 static void check_consistency(const S390CPUModel *model) 693 { 694 static int dep[][2] = { 695 { S390_FEAT_IPTE_RANGE, S390_FEAT_DAT_ENH }, 696 { S390_FEAT_IDTE_SEGMENT, S390_FEAT_DAT_ENH }, 697 { S390_FEAT_IDTE_REGION, S390_FEAT_DAT_ENH }, 698 { S390_FEAT_IDTE_REGION, S390_FEAT_IDTE_SEGMENT }, 699 { S390_FEAT_LOCAL_TLB_CLEARING, S390_FEAT_DAT_ENH}, 700 { S390_FEAT_LONG_DISPLACEMENT_FAST, S390_FEAT_LONG_DISPLACEMENT }, 701 { S390_FEAT_DFP_FAST, S390_FEAT_DFP }, 702 { S390_FEAT_TRANSACTIONAL_EXE, S390_FEAT_STFLE_49 }, 703 { S390_FEAT_EDAT_2, S390_FEAT_EDAT}, 704 { S390_FEAT_MSA_EXT_5, S390_FEAT_KIMD_SHA_512 }, 705 { S390_FEAT_MSA_EXT_5, S390_FEAT_KLMD_SHA_512 }, 706 { S390_FEAT_MSA_EXT_4, S390_FEAT_MSA_EXT_3 }, 707 { S390_FEAT_SIE_CMMA, S390_FEAT_CMM }, 708 { S390_FEAT_SIE_CMMA, S390_FEAT_SIE_GSLS }, 709 { S390_FEAT_SIE_PFMFI, S390_FEAT_EDAT }, 710 { S390_FEAT_MSA_EXT_8, S390_FEAT_MSA_EXT_3 }, 711 { S390_FEAT_MULTIPLE_EPOCH, S390_FEAT_TOD_CLOCK_STEERING }, 712 { S390_FEAT_VECTOR_PACKED_DECIMAL, S390_FEAT_VECTOR }, 713 { S390_FEAT_VECTOR_ENH, S390_FEAT_VECTOR }, 714 { S390_FEAT_INSTRUCTION_EXEC_PROT, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2 }, 715 { S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2, S390_FEAT_ESOP }, 716 { S390_FEAT_CMM_NT, S390_FEAT_CMM }, 717 { S390_FEAT_GUARDED_STORAGE, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2 }, 718 { S390_FEAT_MULTIPLE_EPOCH, S390_FEAT_STORE_CLOCK_FAST }, 719 { S390_FEAT_MULTIPLE_EPOCH, S390_FEAT_TOD_CLOCK_STEERING }, 720 { S390_FEAT_SEMAPHORE_ASSIST, S390_FEAT_STFLE_49 }, 721 { S390_FEAT_KIMD_SHA3_224, S390_FEAT_MSA }, 722 { S390_FEAT_KIMD_SHA3_256, S390_FEAT_MSA }, 723 { S390_FEAT_KIMD_SHA3_384, S390_FEAT_MSA }, 724 { S390_FEAT_KIMD_SHA3_512, S390_FEAT_MSA }, 725 { S390_FEAT_KIMD_SHAKE_128, S390_FEAT_MSA }, 726 { S390_FEAT_KIMD_SHAKE_256, S390_FEAT_MSA }, 727 { S390_FEAT_KLMD_SHA3_224, S390_FEAT_MSA }, 728 { S390_FEAT_KLMD_SHA3_256, S390_FEAT_MSA }, 729 { S390_FEAT_KLMD_SHA3_384, S390_FEAT_MSA }, 730 { S390_FEAT_KLMD_SHA3_512, S390_FEAT_MSA }, 731 { S390_FEAT_KLMD_SHAKE_128, S390_FEAT_MSA }, 732 { S390_FEAT_KLMD_SHAKE_256, S390_FEAT_MSA }, 733 { S390_FEAT_PRNO_TRNG_QRTCR, S390_FEAT_MSA_EXT_5 }, 734 { S390_FEAT_PRNO_TRNG, S390_FEAT_MSA_EXT_5 }, 735 { S390_FEAT_SIE_KSS, S390_FEAT_SIE_F2 }, 736 }; 737 int i; 738 739 for (i = 0; i < ARRAY_SIZE(dep); i++) { 740 if (test_bit(dep[i][0], model->features) && 741 !test_bit(dep[i][1], model->features)) { 742 warn_report("\'%s\' requires \'%s\'.", 743 s390_feat_def(dep[i][0])->name, 744 s390_feat_def(dep[i][1])->name); 745 } 746 } 747 } 748 749 static void error_prepend_missing_feat(const char *name, void *opaque) 750 { 751 error_prepend((Error **) opaque, "%s ", name); 752 } 753 754 static void check_compatibility(const S390CPUModel *max_model, 755 const S390CPUModel *model, Error **errp) 756 { 757 S390FeatBitmap missing; 758 759 if (model->def->gen > max_model->def->gen) { 760 error_setg(errp, "Selected CPU generation is too new. Maximum " 761 "supported model in the configuration: \'%s\'", 762 max_model->def->name); 763 return; 764 } else if (model->def->gen == max_model->def->gen && 765 model->def->ec_ga > max_model->def->ec_ga) { 766 error_setg(errp, "Selected CPU GA level is too new. Maximum " 767 "supported model in the configuration: \'%s\'", 768 max_model->def->name); 769 return; 770 } 771 772 /* detect the missing features to properly report them */ 773 bitmap_andnot(missing, model->features, max_model->features, S390_FEAT_MAX); 774 if (bitmap_empty(missing, S390_FEAT_MAX)) { 775 return; 776 } 777 778 error_setg(errp, " "); 779 s390_feat_bitmap_to_ascii(missing, errp, error_prepend_missing_feat); 780 error_prepend(errp, "Some features requested in the CPU model are not " 781 "available in the configuration: "); 782 } 783 784 /** 785 * The base TCG CPU model "qemu" is based on the z900. However, we already 786 * can also emulate some additional features of later CPU generations, so 787 * we add these additional feature bits here. 788 */ 789 static void add_qemu_cpu_model_features(S390FeatBitmap fbm) 790 { 791 static const int feats[] = { 792 S390_FEAT_DAT_ENH, 793 S390_FEAT_IDTE_SEGMENT, 794 S390_FEAT_STFLE, 795 S390_FEAT_EXTENDED_IMMEDIATE, 796 S390_FEAT_EXTENDED_TRANSLATION_2, 797 S390_FEAT_EXTENDED_TRANSLATION_3, 798 S390_FEAT_LONG_DISPLACEMENT, 799 S390_FEAT_LONG_DISPLACEMENT_FAST, 800 S390_FEAT_ETF2_ENH, 801 S390_FEAT_STORE_CLOCK_FAST, 802 S390_FEAT_MOVE_WITH_OPTIONAL_SPEC, 803 S390_FEAT_ETF3_ENH, 804 S390_FEAT_COMPARE_AND_SWAP_AND_STORE, 805 S390_FEAT_COMPARE_AND_SWAP_AND_STORE_2, 806 S390_FEAT_GENERAL_INSTRUCTIONS_EXT, 807 S390_FEAT_EXECUTE_EXT, 808 S390_FEAT_FLOATING_POINT_SUPPPORT_ENH, 809 S390_FEAT_STFLE_45, 810 S390_FEAT_STFLE_49, 811 S390_FEAT_LOCAL_TLB_CLEARING, 812 S390_FEAT_STFLE_53, 813 }; 814 int i; 815 816 for (i = 0; i < ARRAY_SIZE(feats); i++) { 817 set_bit(feats[i], fbm); 818 } 819 } 820 821 static S390CPUModel *get_max_cpu_model(Error **errp) 822 { 823 static S390CPUModel max_model; 824 static bool cached; 825 826 if (cached) { 827 return &max_model; 828 } 829 830 if (kvm_enabled()) { 831 kvm_s390_get_host_cpu_model(&max_model, errp); 832 } else { 833 /* TCG emulates a z900 (with some optional additional features) */ 834 max_model.def = &s390_cpu_defs[0]; 835 bitmap_copy(max_model.features, max_model.def->default_feat, 836 S390_FEAT_MAX); 837 add_qemu_cpu_model_features(max_model.features); 838 } 839 if (!*errp) { 840 cached = true; 841 return &max_model; 842 } 843 return NULL; 844 } 845 846 static inline void apply_cpu_model(const S390CPUModel *model, Error **errp) 847 { 848 #ifndef CONFIG_USER_ONLY 849 static S390CPUModel applied_model; 850 static bool applied; 851 852 /* 853 * We have the same model for all VCPUs. KVM can only be configured before 854 * any VCPUs are defined in KVM. 855 */ 856 if (applied) { 857 if (model && memcmp(&applied_model, model, sizeof(S390CPUModel))) { 858 error_setg(errp, "Mixed CPU models are not supported on s390x."); 859 } 860 return; 861 } 862 863 if (kvm_enabled()) { 864 kvm_s390_apply_cpu_model(model, errp); 865 } 866 867 if (!*errp) { 868 applied = true; 869 if (model) { 870 applied_model = *model; 871 } 872 } 873 #endif 874 } 875 876 void s390_realize_cpu_model(CPUState *cs, Error **errp) 877 { 878 S390CPUClass *xcc = S390_CPU_GET_CLASS(cs); 879 S390CPU *cpu = S390_CPU(cs); 880 const S390CPUModel *max_model; 881 882 if (xcc->kvm_required && !kvm_enabled()) { 883 error_setg(errp, "CPU definition requires KVM"); 884 return; 885 } 886 887 if (!cpu->model) { 888 /* no host model support -> perform compatibility stuff */ 889 apply_cpu_model(NULL, errp); 890 return; 891 } 892 893 max_model = get_max_cpu_model(errp); 894 if (*errp) { 895 error_prepend(errp, "CPU models are not available: "); 896 return; 897 } 898 899 /* copy over properties that can vary */ 900 cpu->model->lowest_ibc = max_model->lowest_ibc; 901 cpu->model->cpu_id = max_model->cpu_id; 902 cpu->model->cpu_id_format = max_model->cpu_id_format; 903 cpu->model->cpu_ver = max_model->cpu_ver; 904 905 check_consistency(cpu->model); 906 check_compatibility(max_model, cpu->model, errp); 907 if (*errp) { 908 return; 909 } 910 911 apply_cpu_model(cpu->model, errp); 912 913 cpu->env.cpuid = s390_cpuid_from_cpu_model(cpu->model); 914 if (tcg_enabled()) { 915 /* basic mode, write the cpu address into the first 4 bit of the ID */ 916 cpu->env.cpuid = deposit64(cpu->env.cpuid, 54, 4, cpu->env.cpu_num); 917 } 918 } 919 920 static void get_feature(Object *obj, Visitor *v, const char *name, 921 void *opaque, Error **errp) 922 { 923 S390Feat feat = (S390Feat) opaque; 924 S390CPU *cpu = S390_CPU(obj); 925 bool value; 926 927 if (!cpu->model) { 928 error_setg(errp, "Details about the host CPU model are not available, " 929 "features cannot be queried."); 930 return; 931 } 932 933 value = test_bit(feat, cpu->model->features); 934 visit_type_bool(v, name, &value, errp); 935 } 936 937 static void set_feature(Object *obj, Visitor *v, const char *name, 938 void *opaque, Error **errp) 939 { 940 S390Feat feat = (S390Feat) opaque; 941 DeviceState *dev = DEVICE(obj); 942 S390CPU *cpu = S390_CPU(obj); 943 bool value; 944 945 if (dev->realized) { 946 error_setg(errp, "Attempt to set property '%s' on '%s' after " 947 "it was realized", name, object_get_typename(obj)); 948 return; 949 } else if (!cpu->model) { 950 error_setg(errp, "Details about the host CPU model are not available, " 951 "features cannot be changed."); 952 return; 953 } 954 955 visit_type_bool(v, name, &value, errp); 956 if (*errp) { 957 return; 958 } 959 if (value) { 960 if (!test_bit(feat, cpu->model->def->full_feat)) { 961 error_setg(errp, "Feature '%s' is not available for CPU model '%s'," 962 " it was introduced with later models.", 963 name, cpu->model->def->name); 964 return; 965 } 966 set_bit(feat, cpu->model->features); 967 } else { 968 clear_bit(feat, cpu->model->features); 969 } 970 } 971 972 static void get_feature_group(Object *obj, Visitor *v, const char *name, 973 void *opaque, Error **errp) 974 { 975 S390FeatGroup group = (S390FeatGroup) opaque; 976 const S390FeatGroupDef *def = s390_feat_group_def(group); 977 S390CPU *cpu = S390_CPU(obj); 978 S390FeatBitmap tmp; 979 bool value; 980 981 if (!cpu->model) { 982 error_setg(errp, "Details about the host CPU model are not available, " 983 "features cannot be queried."); 984 return; 985 } 986 987 /* a group is enabled if all features are enabled */ 988 bitmap_and(tmp, cpu->model->features, def->feat, S390_FEAT_MAX); 989 value = bitmap_equal(tmp, def->feat, S390_FEAT_MAX); 990 visit_type_bool(v, name, &value, errp); 991 } 992 993 static void set_feature_group(Object *obj, Visitor *v, const char *name, 994 void *opaque, Error **errp) 995 { 996 S390FeatGroup group = (S390FeatGroup) opaque; 997 const S390FeatGroupDef *def = s390_feat_group_def(group); 998 DeviceState *dev = DEVICE(obj); 999 S390CPU *cpu = S390_CPU(obj); 1000 bool value; 1001 1002 if (dev->realized) { 1003 error_setg(errp, "Attempt to set property '%s' on '%s' after " 1004 "it was realized", name, object_get_typename(obj)); 1005 return; 1006 } else if (!cpu->model) { 1007 error_setg(errp, "Details about the host CPU model are not available, " 1008 "features cannot be changed."); 1009 return; 1010 } 1011 1012 visit_type_bool(v, name, &value, errp); 1013 if (*errp) { 1014 return; 1015 } 1016 if (value) { 1017 /* groups are added in one shot, so an intersect is sufficient */ 1018 if (!bitmap_intersects(def->feat, cpu->model->def->full_feat, 1019 S390_FEAT_MAX)) { 1020 error_setg(errp, "Group '%s' is not available for CPU model '%s'," 1021 " it was introduced with later models.", 1022 name, cpu->model->def->name); 1023 return; 1024 } 1025 bitmap_or(cpu->model->features, cpu->model->features, def->feat, 1026 S390_FEAT_MAX); 1027 } else { 1028 bitmap_andnot(cpu->model->features, cpu->model->features, def->feat, 1029 S390_FEAT_MAX); 1030 } 1031 } 1032 1033 void s390_cpu_model_register_props(Object *obj) 1034 { 1035 S390FeatGroup group; 1036 S390Feat feat; 1037 1038 for (feat = 0; feat < S390_FEAT_MAX; feat++) { 1039 const S390FeatDef *def = s390_feat_def(feat); 1040 object_property_add(obj, def->name, "bool", get_feature, 1041 set_feature, NULL, (void *) feat, NULL); 1042 object_property_set_description(obj, def->name, def->desc , NULL); 1043 } 1044 for (group = 0; group < S390_FEAT_GROUP_MAX; group++) { 1045 const S390FeatGroupDef *def = s390_feat_group_def(group); 1046 object_property_add(obj, def->name, "bool", get_feature_group, 1047 set_feature_group, NULL, (void *) group, NULL); 1048 object_property_set_description(obj, def->name, def->desc , NULL); 1049 } 1050 } 1051 1052 static void s390_cpu_model_initfn(Object *obj) 1053 { 1054 S390CPU *cpu = S390_CPU(obj); 1055 S390CPUClass *xcc = S390_CPU_GET_CLASS(cpu); 1056 1057 cpu->model = g_malloc0(sizeof(*cpu->model)); 1058 /* copy the model, so we can modify it */ 1059 cpu->model->def = xcc->cpu_def; 1060 if (xcc->is_static) { 1061 /* base model - features will never change */ 1062 bitmap_copy(cpu->model->features, cpu->model->def->base_feat, 1063 S390_FEAT_MAX); 1064 } else { 1065 /* latest model - features can change */ 1066 bitmap_copy(cpu->model->features, 1067 cpu->model->def->default_feat, S390_FEAT_MAX); 1068 } 1069 } 1070 1071 #ifdef CONFIG_KVM 1072 static void s390_host_cpu_model_initfn(Object *obj) 1073 { 1074 S390CPU *cpu = S390_CPU(obj); 1075 Error *err = NULL; 1076 1077 if (!kvm_enabled() || !kvm_s390_cpu_models_supported()) { 1078 return; 1079 } 1080 1081 cpu->model = g_malloc0(sizeof(*cpu->model)); 1082 kvm_s390_get_host_cpu_model(cpu->model, &err); 1083 if (err) { 1084 error_report_err(err); 1085 g_free(cpu->model); 1086 /* fallback to unsupported cpu models */ 1087 cpu->model = NULL; 1088 } 1089 } 1090 #endif 1091 1092 static void s390_qemu_cpu_model_initfn(Object *obj) 1093 { 1094 static S390CPUDef s390_qemu_cpu_defs; 1095 S390CPU *cpu = S390_CPU(obj); 1096 1097 cpu->model = g_malloc0(sizeof(*cpu->model)); 1098 /* TCG emulates a z900 (with some optional additional features) */ 1099 memcpy(&s390_qemu_cpu_defs, &s390_cpu_defs[0], sizeof(s390_qemu_cpu_defs)); 1100 add_qemu_cpu_model_features(s390_qemu_cpu_defs.full_feat); 1101 cpu->model->def = &s390_qemu_cpu_defs; 1102 bitmap_copy(cpu->model->features, cpu->model->def->default_feat, 1103 S390_FEAT_MAX); 1104 } 1105 1106 static void s390_cpu_model_finalize(Object *obj) 1107 { 1108 S390CPU *cpu = S390_CPU(obj); 1109 1110 g_free(cpu->model); 1111 cpu->model = NULL; 1112 } 1113 1114 static bool get_is_migration_safe(Object *obj, Error **errp) 1115 { 1116 return S390_CPU_GET_CLASS(obj)->is_migration_safe; 1117 } 1118 1119 static bool get_is_static(Object *obj, Error **errp) 1120 { 1121 return S390_CPU_GET_CLASS(obj)->is_static; 1122 } 1123 1124 static char *get_description(Object *obj, Error **errp) 1125 { 1126 return g_strdup(S390_CPU_GET_CLASS(obj)->desc); 1127 } 1128 1129 void s390_cpu_model_class_register_props(ObjectClass *oc) 1130 { 1131 object_class_property_add_bool(oc, "migration-safe", get_is_migration_safe, 1132 NULL, NULL); 1133 object_class_property_add_bool(oc, "static", get_is_static, 1134 NULL, NULL); 1135 object_class_property_add_str(oc, "description", get_description, NULL, 1136 NULL); 1137 } 1138 1139 #ifdef CONFIG_KVM 1140 static void s390_host_cpu_model_class_init(ObjectClass *oc, void *data) 1141 { 1142 S390CPUClass *xcc = S390_CPU_CLASS(oc); 1143 1144 xcc->kvm_required = true; 1145 xcc->desc = "KVM only: All recognized features"; 1146 } 1147 #endif 1148 1149 static void s390_base_cpu_model_class_init(ObjectClass *oc, void *data) 1150 { 1151 S390CPUClass *xcc = S390_CPU_CLASS(oc); 1152 1153 /* all base models are migration safe */ 1154 xcc->cpu_def = (const S390CPUDef *) data; 1155 xcc->is_migration_safe = true; 1156 xcc->is_static = true; 1157 xcc->desc = xcc->cpu_def->desc; 1158 } 1159 1160 static void s390_cpu_model_class_init(ObjectClass *oc, void *data) 1161 { 1162 S390CPUClass *xcc = S390_CPU_CLASS(oc); 1163 1164 /* model that can change between QEMU versions */ 1165 xcc->cpu_def = (const S390CPUDef *) data; 1166 xcc->is_migration_safe = true; 1167 xcc->desc = xcc->cpu_def->desc; 1168 } 1169 1170 static void s390_qemu_cpu_model_class_init(ObjectClass *oc, void *data) 1171 { 1172 S390CPUClass *xcc = S390_CPU_CLASS(oc); 1173 1174 xcc->is_migration_safe = true; 1175 xcc->desc = g_strdup_printf("QEMU Virtual CPU version %s", 1176 qemu_hw_version()); 1177 } 1178 1179 #define S390_CPU_TYPE_SUFFIX "-" TYPE_S390_CPU 1180 #define S390_CPU_TYPE_NAME(name) (name S390_CPU_TYPE_SUFFIX) 1181 1182 /* Generate type name for a cpu model. Caller has to free the string. */ 1183 static char *s390_cpu_type_name(const char *model_name) 1184 { 1185 return g_strdup_printf(S390_CPU_TYPE_NAME("%s"), model_name); 1186 } 1187 1188 /* Generate type name for a base cpu model. Caller has to free the string. */ 1189 static char *s390_base_cpu_type_name(const char *model_name) 1190 { 1191 return g_strdup_printf(S390_CPU_TYPE_NAME("%s-base"), model_name); 1192 } 1193 1194 ObjectClass *s390_cpu_class_by_name(const char *name) 1195 { 1196 char *typename = s390_cpu_type_name(name); 1197 ObjectClass *oc; 1198 1199 oc = object_class_by_name(typename); 1200 g_free(typename); 1201 return oc; 1202 } 1203 1204 const char *s390_default_cpu_model_name(void) 1205 { 1206 if (kvm_enabled()) { 1207 return "host"; 1208 } 1209 return "qemu"; 1210 } 1211 1212 static const TypeInfo qemu_s390_cpu_type_info = { 1213 .name = S390_CPU_TYPE_NAME("qemu"), 1214 .parent = TYPE_S390_CPU, 1215 .instance_init = s390_qemu_cpu_model_initfn, 1216 .instance_finalize = s390_cpu_model_finalize, 1217 .class_init = s390_qemu_cpu_model_class_init, 1218 }; 1219 1220 #ifdef CONFIG_KVM 1221 static const TypeInfo host_s390_cpu_type_info = { 1222 .name = S390_CPU_TYPE_NAME("host"), 1223 .parent = TYPE_S390_CPU, 1224 .instance_init = s390_host_cpu_model_initfn, 1225 .instance_finalize = s390_cpu_model_finalize, 1226 .class_init = s390_host_cpu_model_class_init, 1227 }; 1228 #endif 1229 1230 static void init_ignored_base_feat(void) 1231 { 1232 static const int feats[] = { 1233 /* MSA subfunctions that could not be available on certain machines */ 1234 S390_FEAT_KMAC_DEA, 1235 S390_FEAT_KMAC_TDEA_128, 1236 S390_FEAT_KMAC_TDEA_192, 1237 S390_FEAT_KMC_DEA, 1238 S390_FEAT_KMC_TDEA_128, 1239 S390_FEAT_KMC_TDEA_192, 1240 S390_FEAT_KM_DEA, 1241 S390_FEAT_KM_TDEA_128, 1242 S390_FEAT_KM_TDEA_192, 1243 S390_FEAT_KIMD_SHA_1, 1244 S390_FEAT_KLMD_SHA_1, 1245 }; 1246 int i; 1247 1248 for (i = 0; i < ARRAY_SIZE(feats); i++) { 1249 set_bit(feats[i], ignored_base_feat); 1250 } 1251 } 1252 1253 static void register_types(void) 1254 { 1255 int i; 1256 1257 init_ignored_base_feat(); 1258 1259 /* init all bitmaps from gnerated data initially */ 1260 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) { 1261 s390_init_feat_bitmap(s390_cpu_defs[i].base_init, 1262 s390_cpu_defs[i].base_feat); 1263 s390_init_feat_bitmap(s390_cpu_defs[i].default_init, 1264 s390_cpu_defs[i].default_feat); 1265 s390_init_feat_bitmap(s390_cpu_defs[i].full_init, 1266 s390_cpu_defs[i].full_feat); 1267 } 1268 1269 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) { 1270 char *base_name = s390_base_cpu_type_name(s390_cpu_defs[i].name); 1271 TypeInfo ti_base = { 1272 .name = base_name, 1273 .parent = TYPE_S390_CPU, 1274 .instance_init = s390_cpu_model_initfn, 1275 .instance_finalize = s390_cpu_model_finalize, 1276 .class_init = s390_base_cpu_model_class_init, 1277 .class_data = (void *) &s390_cpu_defs[i], 1278 }; 1279 char *name = s390_cpu_type_name(s390_cpu_defs[i].name); 1280 TypeInfo ti = { 1281 .name = name, 1282 .parent = TYPE_S390_CPU, 1283 .instance_init = s390_cpu_model_initfn, 1284 .instance_finalize = s390_cpu_model_finalize, 1285 .class_init = s390_cpu_model_class_init, 1286 .class_data = (void *) &s390_cpu_defs[i], 1287 }; 1288 1289 type_register_static(&ti_base); 1290 type_register_static(&ti); 1291 g_free(base_name); 1292 g_free(name); 1293 } 1294 1295 type_register_static(&qemu_s390_cpu_type_info); 1296 #ifdef CONFIG_KVM 1297 type_register_static(&host_s390_cpu_type_info); 1298 #endif 1299 } 1300 1301 type_init(register_types) 1302