141868f84SDavid Hildenbrand /* 241868f84SDavid Hildenbrand * CPU models for s390x 341868f84SDavid Hildenbrand * 441868f84SDavid Hildenbrand * Copyright 2016 IBM Corp. 541868f84SDavid Hildenbrand * 641868f84SDavid Hildenbrand * Author(s): David Hildenbrand <dahi@linux.vnet.ibm.com> 741868f84SDavid Hildenbrand * 841868f84SDavid Hildenbrand * This work is licensed under the terms of the GNU GPL, version 2 or (at 941868f84SDavid Hildenbrand * your option) any later version. See the COPYING file in the top-level 1041868f84SDavid Hildenbrand * directory. 1141868f84SDavid Hildenbrand */ 1241868f84SDavid Hildenbrand 1341868f84SDavid Hildenbrand #include "qemu/osdep.h" 1441868f84SDavid Hildenbrand #include "cpu.h" 15b6b47223SCho, Yu-Chen #include "s390x-internal.h" 1667043607SCho, Yu-Chen #include "kvm/kvm_s390x.h" 17f16bbb9bSDavid Hildenbrand #include "sysemu/kvm.h" 1814a48c1dSMarkus Armbruster #include "sysemu/tcg.h" 1941868f84SDavid Hildenbrand #include "qapi/error.h" 20cc37d98bSRichard Henderson #include "qemu/error-report.h" 210754f604SDavid Hildenbrand #include "qapi/visitor.h" 220b8fa32fSMarkus Armbruster #include "qemu/module.h" 2315e09912SPeter Maydell #include "qemu/hw-version.h" 240442428aSMarkus Armbruster #include "qemu/qemu-print.h" 2541868f84SDavid Hildenbrand #ifndef CONFIG_USER_ONLY 260110253eSChristian Borntraeger #include "sysemu/sysemu.h" 27f5f9c6eaSPhilippe Mathieu-Daudé #include "target/s390x/kvm/pv.h" 28d6a7c3f4SThomas Huth #include CONFIG_DEVICES 293ea7e312SPhilippe Mathieu-Daudé #endif 3041868f84SDavid Hildenbrand 316c064de1SDavid Hildenbrand #define CPUDEF_INIT(_type, _gen, _ec_ga, _mha_pow, _hmfai, _name, _desc) \ 326c064de1SDavid Hildenbrand { \ 336c064de1SDavid Hildenbrand .name = _name, \ 346c064de1SDavid Hildenbrand .type = _type, \ 356c064de1SDavid Hildenbrand .gen = _gen, \ 366c064de1SDavid Hildenbrand .ec_ga = _ec_ga, \ 376c064de1SDavid Hildenbrand .mha_pow = _mha_pow, \ 386c064de1SDavid Hildenbrand .hmfai = _hmfai, \ 396c064de1SDavid Hildenbrand .desc = _desc, \ 406c064de1SDavid Hildenbrand .base_init = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _BASE }, \ 416c064de1SDavid Hildenbrand .default_init = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _DEFAULT }, \ 426c064de1SDavid Hildenbrand .full_init = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _FULL }, \ 436c064de1SDavid Hildenbrand } 446c064de1SDavid Hildenbrand 456c064de1SDavid Hildenbrand /* 46c657e84fSChristian Borntraeger * CPU definition list in order of release. Up to generation 14 base features 47c657e84fSChristian Borntraeger * of a following release have been a superset of the previous release. With 48c657e84fSChristian Borntraeger * generation 15 one base feature and one optional feature have been deprecated. 496c064de1SDavid Hildenbrand */ 506c064de1SDavid Hildenbrand static S390CPUDef s390_cpu_defs[] = { 51d6a7c3f4SThomas Huth /* 52d6a7c3f4SThomas Huth * Linux requires at least z10 nowadays, and IBM only supports recent CPUs 53d6a7c3f4SThomas Huth * (see https://www.ibm.com/support/pages/ibm-mainframe-life-cycle-history), 54d6a7c3f4SThomas Huth * so we consider older CPUs as legacy that can optionally be disabled via 55d6a7c3f4SThomas Huth * the CONFIG_S390X_LEGACY_CPUS config switch. 56d6a7c3f4SThomas Huth */ 57d6a7c3f4SThomas Huth #if defined(CONFIG_S390X_LEGACY_CPUS) || defined(CONFIG_USER_ONLY) 586c064de1SDavid Hildenbrand CPUDEF_INIT(0x2064, 7, 1, 38, 0x00000000U, "z900", "IBM zSeries 900 GA1"), 596c064de1SDavid Hildenbrand CPUDEF_INIT(0x2064, 7, 2, 38, 0x00000000U, "z900.2", "IBM zSeries 900 GA2"), 606c064de1SDavid Hildenbrand CPUDEF_INIT(0x2064, 7, 3, 38, 0x00000000U, "z900.3", "IBM zSeries 900 GA3"), 616c064de1SDavid Hildenbrand CPUDEF_INIT(0x2066, 7, 3, 38, 0x00000000U, "z800", "IBM zSeries 800 GA1"), 626c064de1SDavid Hildenbrand CPUDEF_INIT(0x2084, 8, 1, 38, 0x00000000U, "z990", "IBM zSeries 990 GA1"), 636c064de1SDavid Hildenbrand CPUDEF_INIT(0x2084, 8, 2, 38, 0x00000000U, "z990.2", "IBM zSeries 990 GA2"), 646c064de1SDavid Hildenbrand CPUDEF_INIT(0x2084, 8, 3, 38, 0x00000000U, "z990.3", "IBM zSeries 990 GA3"), 656c064de1SDavid Hildenbrand CPUDEF_INIT(0x2086, 8, 3, 38, 0x00000000U, "z890", "IBM zSeries 880 GA1"), 666c064de1SDavid Hildenbrand CPUDEF_INIT(0x2084, 8, 4, 38, 0x00000000U, "z990.4", "IBM zSeries 990 GA4"), 676c064de1SDavid Hildenbrand CPUDEF_INIT(0x2086, 8, 4, 38, 0x00000000U, "z890.2", "IBM zSeries 880 GA2"), 686c064de1SDavid Hildenbrand CPUDEF_INIT(0x2084, 8, 5, 38, 0x00000000U, "z990.5", "IBM zSeries 990 GA5"), 696c064de1SDavid Hildenbrand CPUDEF_INIT(0x2086, 8, 5, 38, 0x00000000U, "z890.3", "IBM zSeries 880 GA3"), 706c064de1SDavid Hildenbrand CPUDEF_INIT(0x2094, 9, 1, 40, 0x00000000U, "z9EC", "IBM System z9 EC GA1"), 716c064de1SDavid Hildenbrand CPUDEF_INIT(0x2094, 9, 2, 40, 0x00000000U, "z9EC.2", "IBM System z9 EC GA2"), 726c064de1SDavid Hildenbrand CPUDEF_INIT(0x2096, 9, 2, 40, 0x00000000U, "z9BC", "IBM System z9 BC GA1"), 736c064de1SDavid Hildenbrand CPUDEF_INIT(0x2094, 9, 3, 40, 0x00000000U, "z9EC.3", "IBM System z9 EC GA3"), 746c064de1SDavid Hildenbrand CPUDEF_INIT(0x2096, 9, 3, 40, 0x00000000U, "z9BC.2", "IBM System z9 BC GA2"), 75d6a7c3f4SThomas Huth #endif 766c064de1SDavid Hildenbrand CPUDEF_INIT(0x2097, 10, 1, 43, 0x00000000U, "z10EC", "IBM System z10 EC GA1"), 776c064de1SDavid Hildenbrand CPUDEF_INIT(0x2097, 10, 2, 43, 0x00000000U, "z10EC.2", "IBM System z10 EC GA2"), 786c064de1SDavid Hildenbrand CPUDEF_INIT(0x2098, 10, 2, 43, 0x00000000U, "z10BC", "IBM System z10 BC GA1"), 796c064de1SDavid Hildenbrand CPUDEF_INIT(0x2097, 10, 3, 43, 0x00000000U, "z10EC.3", "IBM System z10 EC GA3"), 806c064de1SDavid Hildenbrand CPUDEF_INIT(0x2098, 10, 3, 43, 0x00000000U, "z10BC.2", "IBM System z10 BC GA2"), 816c064de1SDavid Hildenbrand CPUDEF_INIT(0x2817, 11, 1, 44, 0x08000000U, "z196", "IBM zEnterprise 196 GA1"), 826c064de1SDavid Hildenbrand CPUDEF_INIT(0x2817, 11, 2, 44, 0x08000000U, "z196.2", "IBM zEnterprise 196 GA2"), 836c064de1SDavid Hildenbrand CPUDEF_INIT(0x2818, 11, 2, 44, 0x08000000U, "z114", "IBM zEnterprise 114 GA1"), 846c064de1SDavid Hildenbrand CPUDEF_INIT(0x2827, 12, 1, 44, 0x08000000U, "zEC12", "IBM zEnterprise EC12 GA1"), 856c064de1SDavid Hildenbrand CPUDEF_INIT(0x2827, 12, 2, 44, 0x08000000U, "zEC12.2", "IBM zEnterprise EC12 GA2"), 866c064de1SDavid Hildenbrand CPUDEF_INIT(0x2828, 12, 2, 44, 0x08000000U, "zBC12", "IBM zEnterprise BC12 GA1"), 876c064de1SDavid Hildenbrand CPUDEF_INIT(0x2964, 13, 1, 47, 0x08000000U, "z13", "IBM z13 GA1"), 886c064de1SDavid Hildenbrand CPUDEF_INIT(0x2964, 13, 2, 47, 0x08000000U, "z13.2", "IBM z13 GA2"), 896c064de1SDavid Hildenbrand CPUDEF_INIT(0x2965, 13, 2, 47, 0x08000000U, "z13s", "IBM z13s GA1"), 90cc28a594SJason J. Herne CPUDEF_INIT(0x3906, 14, 1, 47, 0x08000000U, "z14", "IBM z14 GA1"), 91f2a7d157SCollin Walling CPUDEF_INIT(0x3906, 14, 2, 47, 0x08000000U, "z14.2", "IBM z14 GA2"), 9223ad956bSChristian Borntraeger CPUDEF_INIT(0x3907, 14, 1, 47, 0x08000000U, "z14ZR1", "IBM z14 Model ZR1 GA1"), 93d66a52b5SCornelia Huck CPUDEF_INIT(0x8561, 15, 1, 47, 0x08000000U, "gen15a", "IBM z15 T01 GA1"), 94d66a52b5SCornelia Huck CPUDEF_INIT(0x8562, 15, 1, 47, 0x08000000U, "gen15b", "IBM z15 T02 GA1"), 95fb4a0812SChristian Borntraeger CPUDEF_INIT(0x3931, 16, 1, 47, 0x08000000U, "gen16a", "IBM 3931 GA1"), 96fb4a0812SChristian Borntraeger CPUDEF_INIT(0x3932, 16, 1, 47, 0x08000000U, "gen16b", "IBM 3932 GA1"), 976c064de1SDavid Hildenbrand }; 986c064de1SDavid Hildenbrand 998a4eafb6SDavid Miller #define QEMU_MAX_CPU_TYPE 0x8561 1008a4eafb6SDavid Miller #define QEMU_MAX_CPU_GEN 15 1018a4eafb6SDavid Miller #define QEMU_MAX_CPU_EC_GA 1 10235b4df64SDavid Hildenbrand static S390FeatBitmap qemu_max_cpu_feat; 10335b4df64SDavid Hildenbrand 10430e82de7SDavid Hildenbrand /* features part of a base model but not relevant for finding a base model */ 10530e82de7SDavid Hildenbrand S390FeatBitmap ignored_base_feat; 10630e82de7SDavid Hildenbrand 107c9ad8a7aSJason J. Herne void s390_cpudef_featoff(uint8_t gen, uint8_t ec_ga, S390Feat feat) 108c9ad8a7aSJason J. Herne { 109c9ad8a7aSJason J. Herne const S390CPUDef *def; 110c9ad8a7aSJason J. Herne 111c9ad8a7aSJason J. Herne def = s390_find_cpu_def(0, gen, ec_ga, NULL); 112c9ad8a7aSJason J. Herne clear_bit(feat, (unsigned long *)&def->default_feat); 113c9ad8a7aSJason J. Herne } 114c9ad8a7aSJason J. Herne 115c9ad8a7aSJason J. Herne void s390_cpudef_featoff_greater(uint8_t gen, uint8_t ec_ga, S390Feat feat) 116c9ad8a7aSJason J. Herne { 117c9ad8a7aSJason J. Herne int i; 118c9ad8a7aSJason J. Herne 119c9ad8a7aSJason J. Herne for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) { 120c9ad8a7aSJason J. Herne const S390CPUDef *def = &s390_cpu_defs[i]; 121c9ad8a7aSJason J. Herne 122c9ad8a7aSJason J. Herne if (def->gen < gen) { 123c9ad8a7aSJason J. Herne continue; 124c9ad8a7aSJason J. Herne } 125c9ad8a7aSJason J. Herne if (def->gen == gen && def->ec_ga < ec_ga) { 126c9ad8a7aSJason J. Herne continue; 127c9ad8a7aSJason J. Herne } 128c9ad8a7aSJason J. Herne 129c9ad8a7aSJason J. Herne clear_bit(feat, (unsigned long *)&def->default_feat); 130c9ad8a7aSJason J. Herne } 131c9ad8a7aSJason J. Herne } 132c9ad8a7aSJason J. Herne 13384176c79SCollin Walling void s390_cpudef_group_featoff_greater(uint8_t gen, uint8_t ec_ga, 13484176c79SCollin Walling S390FeatGroup group) 13584176c79SCollin Walling { 13684176c79SCollin Walling const S390FeatGroupDef *group_def = s390_feat_group_def(group); 13784176c79SCollin Walling S390FeatBitmap group_def_off; 13884176c79SCollin Walling int i; 13984176c79SCollin Walling 14084176c79SCollin Walling bitmap_complement(group_def_off, group_def->feat, S390_FEAT_MAX); 14184176c79SCollin Walling 14284176c79SCollin Walling for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) { 14384176c79SCollin Walling const S390CPUDef *cpu_def = &s390_cpu_defs[i]; 14484176c79SCollin Walling 14584176c79SCollin Walling if (cpu_def->gen < gen) { 14684176c79SCollin Walling continue; 14784176c79SCollin Walling } 14884176c79SCollin Walling if (cpu_def->gen == gen && cpu_def->ec_ga < ec_ga) { 14984176c79SCollin Walling continue; 15084176c79SCollin Walling } 15184176c79SCollin Walling 15284176c79SCollin Walling bitmap_and((unsigned long *)&cpu_def->default_feat, 15384176c79SCollin Walling cpu_def->default_feat, group_def_off, S390_FEAT_MAX); 15484176c79SCollin Walling } 15584176c79SCollin Walling } 15684176c79SCollin Walling 157a3669307SDavid Hildenbrand uint32_t s390_get_hmfai(void) 158a3669307SDavid Hildenbrand { 159a3669307SDavid Hildenbrand static S390CPU *cpu; 160a3669307SDavid Hildenbrand 161a3669307SDavid Hildenbrand if (!cpu) { 162a3669307SDavid Hildenbrand cpu = S390_CPU(qemu_get_cpu(0)); 163a3669307SDavid Hildenbrand } 164a3669307SDavid Hildenbrand 165a3669307SDavid Hildenbrand if (!cpu || !cpu->model) { 166a3669307SDavid Hildenbrand return 0; 167a3669307SDavid Hildenbrand } 168a3669307SDavid Hildenbrand return cpu->model->def->hmfai; 169a3669307SDavid Hildenbrand } 170a3669307SDavid Hildenbrand 1713fad3252SDavid Hildenbrand uint8_t s390_get_mha_pow(void) 1723fad3252SDavid Hildenbrand { 1733fad3252SDavid Hildenbrand static S390CPU *cpu; 1743fad3252SDavid Hildenbrand 1753fad3252SDavid Hildenbrand if (!cpu) { 1763fad3252SDavid Hildenbrand cpu = S390_CPU(qemu_get_cpu(0)); 1773fad3252SDavid Hildenbrand } 1783fad3252SDavid Hildenbrand 1793fad3252SDavid Hildenbrand if (!cpu || !cpu->model) { 1803fad3252SDavid Hildenbrand return 0; 1813fad3252SDavid Hildenbrand } 1823fad3252SDavid Hildenbrand return cpu->model->def->mha_pow; 1833fad3252SDavid Hildenbrand } 1843fad3252SDavid Hildenbrand 185059be520SDavid Hildenbrand uint32_t s390_get_ibc_val(void) 186059be520SDavid Hildenbrand { 187059be520SDavid Hildenbrand uint16_t unblocked_ibc, lowest_ibc; 188059be520SDavid Hildenbrand static S390CPU *cpu; 189059be520SDavid Hildenbrand 190059be520SDavid Hildenbrand if (!cpu) { 191059be520SDavid Hildenbrand cpu = S390_CPU(qemu_get_cpu(0)); 192059be520SDavid Hildenbrand } 193059be520SDavid Hildenbrand 194059be520SDavid Hildenbrand if (!cpu || !cpu->model) { 195059be520SDavid Hildenbrand return 0; 196059be520SDavid Hildenbrand } 197059be520SDavid Hildenbrand unblocked_ibc = s390_ibc_from_cpu_model(cpu->model); 198059be520SDavid Hildenbrand lowest_ibc = cpu->model->lowest_ibc; 199059be520SDavid Hildenbrand /* the lowest_ibc always has to be <= unblocked_ibc */ 200059be520SDavid Hildenbrand if (!lowest_ibc || lowest_ibc > unblocked_ibc) { 201059be520SDavid Hildenbrand return 0; 202059be520SDavid Hildenbrand } 203059be520SDavid Hildenbrand return ((uint32_t) lowest_ibc << 16) | unblocked_ibc; 204059be520SDavid Hildenbrand } 205059be520SDavid Hildenbrand 2064dd4200eSDavid Hildenbrand void s390_get_feat_block(S390FeatType type, uint8_t *data) 2074dd4200eSDavid Hildenbrand { 208ad63e6d6SPhilippe Mathieu-Daudé S390CPU *cpu = S390_CPU(first_cpu); 2094dd4200eSDavid Hildenbrand 2104dd4200eSDavid Hildenbrand if (!cpu || !cpu->model) { 2114dd4200eSDavid Hildenbrand return; 2124dd4200eSDavid Hildenbrand } 2134dd4200eSDavid Hildenbrand s390_fill_feat_block(cpu->model->features, type, data); 2144dd4200eSDavid Hildenbrand } 2154dd4200eSDavid Hildenbrand 2167c72ac49SDavid Hildenbrand bool s390_has_feat(S390Feat feat) 2177c72ac49SDavid Hildenbrand { 2187c72ac49SDavid Hildenbrand static S390CPU *cpu; 2197c72ac49SDavid Hildenbrand 2207c72ac49SDavid Hildenbrand if (!cpu) { 2217c72ac49SDavid Hildenbrand cpu = S390_CPU(qemu_get_cpu(0)); 2227c72ac49SDavid Hildenbrand } 2237c72ac49SDavid Hildenbrand 2247c72ac49SDavid Hildenbrand if (!cpu || !cpu->model) { 2257c72ac49SDavid Hildenbrand #ifdef CONFIG_KVM 2267c72ac49SDavid Hildenbrand if (kvm_enabled()) { 2277c72ac49SDavid Hildenbrand if (feat == S390_FEAT_VECTOR) { 2287c72ac49SDavid Hildenbrand return kvm_check_extension(kvm_state, 2297c72ac49SDavid Hildenbrand KVM_CAP_S390_VECTOR_REGISTERS); 2307c72ac49SDavid Hildenbrand } 2317c72ac49SDavid Hildenbrand if (feat == S390_FEAT_RUNTIME_INSTRUMENTATION) { 2327c72ac49SDavid Hildenbrand return kvm_s390_get_ri(); 2337c72ac49SDavid Hildenbrand } 234c85d21c7SDavid Hildenbrand if (feat == S390_FEAT_MSA_EXT_3) { 235c85d21c7SDavid Hildenbrand return true; 236c85d21c7SDavid Hildenbrand } 2377c72ac49SDavid Hildenbrand } 2387c72ac49SDavid Hildenbrand #endif 2398ad9087cSCornelia Huck if (feat == S390_FEAT_ZPCI) { 2408ad9087cSCornelia Huck return true; 2418ad9087cSCornelia Huck } 2427c72ac49SDavid Hildenbrand return 0; 2437c72ac49SDavid Hildenbrand } 24410248418SJanosch Frank 2453ea7e312SPhilippe Mathieu-Daudé #ifndef CONFIG_USER_ONLY 24610248418SJanosch Frank if (s390_is_pv()) { 24710248418SJanosch Frank switch (feat) { 24810248418SJanosch Frank case S390_FEAT_DIAG_318: 24910248418SJanosch Frank case S390_FEAT_HPMA2: 25010248418SJanosch Frank case S390_FEAT_SIE_F2: 25110248418SJanosch Frank case S390_FEAT_SIE_SKEY: 25210248418SJanosch Frank case S390_FEAT_SIE_GPERE: 25310248418SJanosch Frank case S390_FEAT_SIE_SIIF: 25410248418SJanosch Frank case S390_FEAT_SIE_SIGPIF: 25510248418SJanosch Frank case S390_FEAT_SIE_IB: 25610248418SJanosch Frank case S390_FEAT_SIE_CEI: 25710248418SJanosch Frank case S390_FEAT_SIE_KSS: 25810248418SJanosch Frank case S390_FEAT_SIE_GSLS: 25910248418SJanosch Frank case S390_FEAT_SIE_64BSCAO: 26010248418SJanosch Frank case S390_FEAT_SIE_CMMA: 26110248418SJanosch Frank case S390_FEAT_SIE_PFMFI: 26210248418SJanosch Frank case S390_FEAT_SIE_IBS: 263f530b9e7SPierre Morel case S390_FEAT_CONFIGURATION_TOPOLOGY: 2643ded270aSJanosch Frank return false; 26510248418SJanosch Frank break; 26610248418SJanosch Frank default: 26710248418SJanosch Frank break; 26810248418SJanosch Frank } 2693ded270aSJanosch Frank } 2703ea7e312SPhilippe Mathieu-Daudé #endif 2717c72ac49SDavid Hildenbrand return test_bit(feat, cpu->model->features); 2727c72ac49SDavid Hildenbrand } 2737c72ac49SDavid Hildenbrand 2743b84c25cSDavid Hildenbrand uint8_t s390_get_gen_for_cpu_type(uint16_t type) 2753b84c25cSDavid Hildenbrand { 2763b84c25cSDavid Hildenbrand int i; 2773b84c25cSDavid Hildenbrand 2783b84c25cSDavid Hildenbrand for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) { 2793b84c25cSDavid Hildenbrand if (s390_cpu_defs[i].type == type) { 2803b84c25cSDavid Hildenbrand return s390_cpu_defs[i].gen; 2813b84c25cSDavid Hildenbrand } 2823b84c25cSDavid Hildenbrand } 2833b84c25cSDavid Hildenbrand return 0; 2843b84c25cSDavid Hildenbrand } 2853b84c25cSDavid Hildenbrand 2863b84c25cSDavid Hildenbrand const S390CPUDef *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga, 2873b84c25cSDavid Hildenbrand S390FeatBitmap features) 2883b84c25cSDavid Hildenbrand { 2893b84c25cSDavid Hildenbrand const S390CPUDef *last_compatible = NULL; 290fbe8202eSDavid Hildenbrand const S390CPUDef *matching_cpu_type = NULL; 2913b84c25cSDavid Hildenbrand int i; 2923b84c25cSDavid Hildenbrand 2933b84c25cSDavid Hildenbrand if (!gen) { 2943b84c25cSDavid Hildenbrand ec_ga = 0; 2953b84c25cSDavid Hildenbrand } 2963b84c25cSDavid Hildenbrand if (!gen && type) { 2973b84c25cSDavid Hildenbrand gen = s390_get_gen_for_cpu_type(type); 2983b84c25cSDavid Hildenbrand } 2993b84c25cSDavid Hildenbrand 3003b84c25cSDavid Hildenbrand for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) { 3013b84c25cSDavid Hildenbrand const S390CPUDef *def = &s390_cpu_defs[i]; 3023b84c25cSDavid Hildenbrand S390FeatBitmap missing; 3033b84c25cSDavid Hildenbrand 3043b84c25cSDavid Hildenbrand /* don't even try newer generations if we know the generation */ 3053b84c25cSDavid Hildenbrand if (gen) { 3063b84c25cSDavid Hildenbrand if (def->gen > gen) { 3073b84c25cSDavid Hildenbrand break; 3083b84c25cSDavid Hildenbrand } else if (def->gen == gen && ec_ga && def->ec_ga > ec_ga) { 3093b84c25cSDavid Hildenbrand break; 3103b84c25cSDavid Hildenbrand } 3113b84c25cSDavid Hildenbrand } 3123b84c25cSDavid Hildenbrand 3133b84c25cSDavid Hildenbrand if (features) { 3143b84c25cSDavid Hildenbrand /* see if the model satisfies the minimum features */ 3153b84c25cSDavid Hildenbrand bitmap_andnot(missing, def->base_feat, features, S390_FEAT_MAX); 31630e82de7SDavid Hildenbrand /* 31730e82de7SDavid Hildenbrand * Ignore certain features that are in the base model, but not 31830e82de7SDavid Hildenbrand * relevant for the search (esp. MSA subfunctions). 31930e82de7SDavid Hildenbrand */ 32030e82de7SDavid Hildenbrand bitmap_andnot(missing, missing, ignored_base_feat, S390_FEAT_MAX); 3213b84c25cSDavid Hildenbrand if (!bitmap_empty(missing, S390_FEAT_MAX)) { 3223b84c25cSDavid Hildenbrand break; 3233b84c25cSDavid Hildenbrand } 3243b84c25cSDavid Hildenbrand } 3253b84c25cSDavid Hildenbrand 3263b84c25cSDavid Hildenbrand /* stop the search if we found the exact model */ 3273b84c25cSDavid Hildenbrand if (def->type == type && def->ec_ga == ec_ga) { 3283b84c25cSDavid Hildenbrand return def; 3293b84c25cSDavid Hildenbrand } 330fbe8202eSDavid Hildenbrand /* remember if we've at least seen one with the same cpu type */ 331fbe8202eSDavid Hildenbrand if (def->type == type) { 332fbe8202eSDavid Hildenbrand matching_cpu_type = def; 333fbe8202eSDavid Hildenbrand } 3343b84c25cSDavid Hildenbrand last_compatible = def; 3353b84c25cSDavid Hildenbrand } 336fbe8202eSDavid Hildenbrand /* prefer the model with the same cpu type, esp. don't take the BC for EC */ 337fbe8202eSDavid Hildenbrand if (matching_cpu_type) { 338fbe8202eSDavid Hildenbrand return matching_cpu_type; 339fbe8202eSDavid Hildenbrand } 3403b84c25cSDavid Hildenbrand return last_compatible; 3413b84c25cSDavid Hildenbrand } 3423b84c25cSDavid Hildenbrand 34399aa6bf2SDavid Hildenbrand static void s390_print_cpu_model_list_entry(gpointer data, gpointer user_data) 34441868f84SDavid Hildenbrand { 34599aa6bf2SDavid Hildenbrand const S390CPUClass *scc = S390_CPU_CLASS((ObjectClass *)data); 346738cdc2fSDaniel P. Berrangé CPUClass *cc = CPU_CLASS(scc); 34799aa6bf2SDavid Hildenbrand char *name = g_strdup(object_class_get_name((ObjectClass *)data)); 348738cdc2fSDaniel P. Berrangé g_autoptr(GString) details = g_string_new(""); 34941868f84SDavid Hildenbrand 35041868f84SDavid Hildenbrand if (scc->is_static) { 351738cdc2fSDaniel P. Berrangé g_string_append(details, "static, "); 352738cdc2fSDaniel P. Berrangé } 353738cdc2fSDaniel P. Berrangé if (scc->is_migration_safe) { 354738cdc2fSDaniel P. Berrangé g_string_append(details, "migration-safe, "); 355738cdc2fSDaniel P. Berrangé } 356738cdc2fSDaniel P. Berrangé if (cc->deprecation_note) { 357738cdc2fSDaniel P. Berrangé g_string_append(details, "deprecated, "); 358738cdc2fSDaniel P. Berrangé } 359738cdc2fSDaniel P. Berrangé if (details->len) { 360738cdc2fSDaniel P. Berrangé /* cull trailing ', ' */ 361738cdc2fSDaniel P. Berrangé g_string_truncate(details, details->len - 2); 36241868f84SDavid Hildenbrand } 36341868f84SDavid Hildenbrand 364e555cbe7SDavid Hildenbrand /* strip off the -s390x-cpu */ 36541868f84SDavid Hildenbrand g_strrstr(name, "-" TYPE_S390_CPU)[0] = 0; 366738cdc2fSDaniel P. Berrangé if (details->len) { 3677febce36SThomas Huth qemu_printf(" %-15s %-35s (%s)\n", name, scc->desc, details->str); 368738cdc2fSDaniel P. Berrangé } else { 3697febce36SThomas Huth qemu_printf(" %-15s %-35s\n", name, scc->desc); 370738cdc2fSDaniel P. Berrangé } 37141868f84SDavid Hildenbrand g_free(name); 37241868f84SDavid Hildenbrand } 37341868f84SDavid Hildenbrand 37499aa6bf2SDavid Hildenbrand static gint s390_cpu_list_compare(gconstpointer a, gconstpointer b) 37599aa6bf2SDavid Hildenbrand { 37699aa6bf2SDavid Hildenbrand const S390CPUClass *cc_a = S390_CPU_CLASS((ObjectClass *)a); 37799aa6bf2SDavid Hildenbrand const S390CPUClass *cc_b = S390_CPU_CLASS((ObjectClass *)b); 37899aa6bf2SDavid Hildenbrand const char *name_a = object_class_get_name((ObjectClass *)a); 37999aa6bf2SDavid Hildenbrand const char *name_b = object_class_get_name((ObjectClass *)b); 38099aa6bf2SDavid Hildenbrand 381c6117788SDavid Hildenbrand /* 382c6117788SDavid Hildenbrand * Move qemu, host and max to the top of the list, qemu first, host second, 383c6117788SDavid Hildenbrand * max third. 384c6117788SDavid Hildenbrand */ 38599aa6bf2SDavid Hildenbrand if (name_a[0] == 'q') { 38699aa6bf2SDavid Hildenbrand return -1; 38799aa6bf2SDavid Hildenbrand } else if (name_b[0] == 'q') { 38899aa6bf2SDavid Hildenbrand return 1; 38999aa6bf2SDavid Hildenbrand } else if (name_a[0] == 'h') { 39099aa6bf2SDavid Hildenbrand return -1; 39199aa6bf2SDavid Hildenbrand } else if (name_b[0] == 'h') { 39299aa6bf2SDavid Hildenbrand return 1; 393c6117788SDavid Hildenbrand } else if (name_a[0] == 'm') { 394c6117788SDavid Hildenbrand return -1; 395c6117788SDavid Hildenbrand } else if (name_b[0] == 'm') { 396c6117788SDavid Hildenbrand return 1; 39799aa6bf2SDavid Hildenbrand } 39899aa6bf2SDavid Hildenbrand 39999aa6bf2SDavid Hildenbrand /* keep the same order we have in our table (sorted by release date) */ 40099aa6bf2SDavid Hildenbrand if (cc_a->cpu_def != cc_b->cpu_def) { 40199aa6bf2SDavid Hildenbrand return cc_a->cpu_def - cc_b->cpu_def; 40299aa6bf2SDavid Hildenbrand } 40399aa6bf2SDavid Hildenbrand 40499aa6bf2SDavid Hildenbrand /* exact same definition - list base model first */ 40599aa6bf2SDavid Hildenbrand return cc_a->is_static ? -1 : 1; 40699aa6bf2SDavid Hildenbrand } 40799aa6bf2SDavid Hildenbrand 4080442428aSMarkus Armbruster void s390_cpu_list(void) 40941868f84SDavid Hildenbrand { 4100754f604SDavid Hildenbrand S390FeatGroup group; 4110754f604SDavid Hildenbrand S390Feat feat; 41299aa6bf2SDavid Hildenbrand GSList *list; 41341868f84SDavid Hildenbrand 4147febce36SThomas Huth qemu_printf("Available CPUs:\n"); 41599aa6bf2SDavid Hildenbrand list = object_class_get_list(TYPE_S390_CPU, false); 41699aa6bf2SDavid Hildenbrand list = g_slist_sort(list, s390_cpu_list_compare); 4170442428aSMarkus Armbruster g_slist_foreach(list, s390_print_cpu_model_list_entry, NULL); 41899aa6bf2SDavid Hildenbrand g_slist_free(list); 4190754f604SDavid Hildenbrand 4200442428aSMarkus Armbruster qemu_printf("\nRecognized feature flags:\n"); 4210754f604SDavid Hildenbrand for (feat = 0; feat < S390_FEAT_MAX; feat++) { 4220754f604SDavid Hildenbrand const S390FeatDef *def = s390_feat_def(feat); 4230754f604SDavid Hildenbrand 42461848717SMarkus Armbruster qemu_printf(" %-20s %s\n", def->name, def->desc); 4250754f604SDavid Hildenbrand } 4260754f604SDavid Hildenbrand 4270442428aSMarkus Armbruster qemu_printf("\nRecognized feature groups:\n"); 4280754f604SDavid Hildenbrand for (group = 0; group < S390_FEAT_GROUP_MAX; group++) { 4290754f604SDavid Hildenbrand const S390FeatGroupDef *def = s390_feat_group_def(group); 4300754f604SDavid Hildenbrand 43161848717SMarkus Armbruster qemu_printf(" %-20s %s\n", def->name, def->desc); 4320754f604SDavid Hildenbrand } 43341868f84SDavid Hildenbrand } 43441868f84SDavid Hildenbrand 43580560137SDavid Hildenbrand static void check_consistency(const S390CPUModel *model) 43680560137SDavid Hildenbrand { 43780560137SDavid Hildenbrand static int dep[][2] = { 43880560137SDavid Hildenbrand { S390_FEAT_IPTE_RANGE, S390_FEAT_DAT_ENH }, 43980560137SDavid Hildenbrand { S390_FEAT_IDTE_SEGMENT, S390_FEAT_DAT_ENH }, 44080560137SDavid Hildenbrand { S390_FEAT_IDTE_REGION, S390_FEAT_DAT_ENH }, 44180560137SDavid Hildenbrand { S390_FEAT_IDTE_REGION, S390_FEAT_IDTE_SEGMENT }, 44280560137SDavid Hildenbrand { S390_FEAT_LOCAL_TLB_CLEARING, S390_FEAT_DAT_ENH}, 44380560137SDavid Hildenbrand { S390_FEAT_LONG_DISPLACEMENT_FAST, S390_FEAT_LONG_DISPLACEMENT }, 44480560137SDavid Hildenbrand { S390_FEAT_DFP_FAST, S390_FEAT_DFP }, 44580560137SDavid Hildenbrand { S390_FEAT_TRANSACTIONAL_EXE, S390_FEAT_STFLE_49 }, 44680560137SDavid Hildenbrand { S390_FEAT_EDAT_2, S390_FEAT_EDAT}, 44780560137SDavid Hildenbrand { S390_FEAT_MSA_EXT_5, S390_FEAT_KIMD_SHA_512 }, 44880560137SDavid Hildenbrand { S390_FEAT_MSA_EXT_5, S390_FEAT_KLMD_SHA_512 }, 44980560137SDavid Hildenbrand { S390_FEAT_MSA_EXT_4, S390_FEAT_MSA_EXT_3 }, 45080560137SDavid Hildenbrand { S390_FEAT_SIE_CMMA, S390_FEAT_CMM }, 45180560137SDavid Hildenbrand { S390_FEAT_SIE_CMMA, S390_FEAT_SIE_GSLS }, 45280560137SDavid Hildenbrand { S390_FEAT_SIE_PFMFI, S390_FEAT_EDAT }, 4536da5c593SJason J. Herne { S390_FEAT_MSA_EXT_8, S390_FEAT_MSA_EXT_3 }, 4545dacbe23SChristian Borntraeger { S390_FEAT_MSA_EXT_9, S390_FEAT_MSA_EXT_3 }, 4555dacbe23SChristian Borntraeger { S390_FEAT_MSA_EXT_9, S390_FEAT_MSA_EXT_4 }, 4566da5c593SJason J. Herne { S390_FEAT_MULTIPLE_EPOCH, S390_FEAT_TOD_CLOCK_STEERING }, 4576da5c593SJason J. Herne { S390_FEAT_VECTOR_PACKED_DECIMAL, S390_FEAT_VECTOR }, 458fb4a0812SChristian Borntraeger { S390_FEAT_VECTOR_PACKED_DECIMAL_ENH, S390_FEAT_VECTOR_PACKED_DECIMAL }, 459fb4a0812SChristian Borntraeger { S390_FEAT_VECTOR_PACKED_DECIMAL_ENH2, S390_FEAT_VECTOR_PACKED_DECIMAL_ENH }, 460db4c208aSHendrik Brueckner { S390_FEAT_VECTOR_PACKED_DECIMAL_ENH3, S390_FEAT_VECTOR_PACKED_DECIMAL_ENH2 }, 4616da5c593SJason J. Herne { S390_FEAT_VECTOR_ENH, S390_FEAT_VECTOR }, 4620b2c66a3SHendrik Brueckner { S390_FEAT_VECTOR_ENH2, S390_FEAT_VECTOR_ENH }, 4630b2c66a3SHendrik Brueckner { S390_FEAT_VECTOR_ENH3, S390_FEAT_VECTOR_ENH2 }, 4646da5c593SJason J. Herne { S390_FEAT_INSTRUCTION_EXEC_PROT, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2 }, 4656da5c593SJason J. Herne { S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2, S390_FEAT_ESOP }, 4666da5c593SJason J. Herne { S390_FEAT_CMM_NT, S390_FEAT_CMM }, 4676da5c593SJason J. Herne { S390_FEAT_GUARDED_STORAGE, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2 }, 4686da5c593SJason J. Herne { S390_FEAT_MULTIPLE_EPOCH, S390_FEAT_STORE_CLOCK_FAST }, 4696da5c593SJason J. Herne { S390_FEAT_MULTIPLE_EPOCH, S390_FEAT_TOD_CLOCK_STEERING }, 4706da5c593SJason J. Herne { S390_FEAT_SEMAPHORE_ASSIST, S390_FEAT_STFLE_49 }, 4716da5c593SJason J. Herne { S390_FEAT_KIMD_SHA3_224, S390_FEAT_MSA }, 4726da5c593SJason J. Herne { S390_FEAT_KIMD_SHA3_256, S390_FEAT_MSA }, 4736da5c593SJason J. Herne { S390_FEAT_KIMD_SHA3_384, S390_FEAT_MSA }, 4746da5c593SJason J. Herne { S390_FEAT_KIMD_SHA3_512, S390_FEAT_MSA }, 4756da5c593SJason J. Herne { S390_FEAT_KIMD_SHAKE_128, S390_FEAT_MSA }, 4766da5c593SJason J. Herne { S390_FEAT_KIMD_SHAKE_256, S390_FEAT_MSA }, 4776da5c593SJason J. Herne { S390_FEAT_KLMD_SHA3_224, S390_FEAT_MSA }, 4786da5c593SJason J. Herne { S390_FEAT_KLMD_SHA3_256, S390_FEAT_MSA }, 4796da5c593SJason J. Herne { S390_FEAT_KLMD_SHA3_384, S390_FEAT_MSA }, 4806da5c593SJason J. Herne { S390_FEAT_KLMD_SHA3_512, S390_FEAT_MSA }, 4816da5c593SJason J. Herne { S390_FEAT_KLMD_SHAKE_128, S390_FEAT_MSA }, 4826da5c593SJason J. Herne { S390_FEAT_KLMD_SHAKE_256, S390_FEAT_MSA }, 48311dc9020SHendrik Brueckner { S390_FEAT_KMAC_HMAC_SHA_224, S390_FEAT_MSA_EXT_3 }, 48411dc9020SHendrik Brueckner { S390_FEAT_KMAC_HMAC_SHA_256, S390_FEAT_MSA_EXT_3 }, 48511dc9020SHendrik Brueckner { S390_FEAT_KMAC_HMAC_SHA_384, S390_FEAT_MSA_EXT_3 }, 48611dc9020SHendrik Brueckner { S390_FEAT_KMAC_HMAC_SHA_512, S390_FEAT_MSA_EXT_3 }, 48711dc9020SHendrik Brueckner { S390_FEAT_KMAC_HMAC_ESHA_224, S390_FEAT_MSA_EXT_3 }, 48811dc9020SHendrik Brueckner { S390_FEAT_KMAC_HMAC_ESHA_256, S390_FEAT_MSA_EXT_3 }, 48911dc9020SHendrik Brueckner { S390_FEAT_KMAC_HMAC_ESHA_384, S390_FEAT_MSA_EXT_3 }, 49011dc9020SHendrik Brueckner { S390_FEAT_KMAC_HMAC_ESHA_512, S390_FEAT_MSA_EXT_3 }, 4911029cd5bSHendrik Brueckner { S390_FEAT_KM_FULL_XTS_AES_128, S390_FEAT_MSA_EXT_4 }, 4921029cd5bSHendrik Brueckner { S390_FEAT_KM_FULL_XTS_AES_256, S390_FEAT_MSA_EXT_4 }, 4931029cd5bSHendrik Brueckner { S390_FEAT_KM_FULL_XTS_EAES_128, S390_FEAT_MSA_EXT_4 }, 4941029cd5bSHendrik Brueckner { S390_FEAT_KM_FULL_XTS_EAES_256, S390_FEAT_MSA_EXT_4 }, 4956da5c593SJason J. Herne { S390_FEAT_PRNO_TRNG_QRTCR, S390_FEAT_MSA_EXT_5 }, 4966da5c593SJason J. Herne { S390_FEAT_PRNO_TRNG, S390_FEAT_MSA_EXT_5 }, 497c1b364ffSChristian Borntraeger { S390_FEAT_SIE_KSS, S390_FEAT_SIE_F2 }, 498c5cd17afSTony Krowiak { S390_FEAT_AP_QUERY_CONFIG_INFO, S390_FEAT_AP }, 499c5cd17afSTony Krowiak { S390_FEAT_AP_FACILITIES_TEST, S390_FEAT_AP }, 500ddf5d18aSCollin Walling { S390_FEAT_PTFF_QSIE, S390_FEAT_MULTIPLE_EPOCH }, 501ddf5d18aSCollin Walling { S390_FEAT_PTFF_QTOUE, S390_FEAT_MULTIPLE_EPOCH }, 502ddf5d18aSCollin Walling { S390_FEAT_PTFF_STOE, S390_FEAT_MULTIPLE_EPOCH }, 503ddf5d18aSCollin Walling { S390_FEAT_PTFF_STOUE, S390_FEAT_MULTIPLE_EPOCH }, 5049ef2d19eSPierre Morel { S390_FEAT_AP_QUEUE_INTERRUPT_CONTROL, S390_FEAT_AP }, 505fabdada9SCollin Walling { S390_FEAT_DIAG_318, S390_FEAT_EXTENDED_LENGTH_SCCB }, 506fb4a0812SChristian Borntraeger { S390_FEAT_NNPA, S390_FEAT_VECTOR }, 507fb4a0812SChristian Borntraeger { S390_FEAT_RDP, S390_FEAT_LOCAL_TLB_CLEARING }, 5085ac95151SSteffen Eiden { S390_FEAT_UV_FEAT_AP, S390_FEAT_AP }, 5095ac95151SSteffen Eiden { S390_FEAT_UV_FEAT_AP_INTR, S390_FEAT_UV_FEAT_AP }, 510c9ea365dSHendrik Brueckner { S390_FEAT_PFCR_QAF, S390_FEAT_CCF_BASE }, 511c9ea365dSHendrik Brueckner { S390_FEAT_PFCR_CSDST, S390_FEAT_CCF_BASE }, 512c9ea365dSHendrik Brueckner { S390_FEAT_PFCR_CSDSTG, S390_FEAT_CCF_BASE }, 513c9ea365dSHendrik Brueckner { S390_FEAT_PFCR_CSTST, S390_FEAT_CCF_BASE }, 514c9ea365dSHendrik Brueckner { S390_FEAT_PFCR_CSTSTG, S390_FEAT_CCF_BASE }, 51512417b71SHendrik Brueckner { S390_FEAT_INEFF_NC_TX, S390_FEAT_TRANSACTIONAL_EXE }, 516*393c835eSHendrik Brueckner { S390_FEAT_PLO_CLO, S390_FEAT_PLO_EXT }, 517*393c835eSHendrik Brueckner { S390_FEAT_PLO_CSO, S390_FEAT_PLO_EXT }, 518*393c835eSHendrik Brueckner { S390_FEAT_PLO_DCSO, S390_FEAT_PLO_EXT }, 519*393c835eSHendrik Brueckner { S390_FEAT_PLO_CSSTO, S390_FEAT_PLO_EXT }, 520*393c835eSHendrik Brueckner { S390_FEAT_PLO_CSDSTO, S390_FEAT_PLO_EXT }, 521*393c835eSHendrik Brueckner { S390_FEAT_PLO_CSTSTO, S390_FEAT_PLO_EXT }, 522*393c835eSHendrik Brueckner { S390_FEAT_PLO_TCS, S390_FEAT_PLO_EXT }, 523*393c835eSHendrik Brueckner { S390_FEAT_PLO_TCSG, S390_FEAT_PLO_EXT }, 524*393c835eSHendrik Brueckner { S390_FEAT_PLO_TCSX, S390_FEAT_PLO_EXT }, 525*393c835eSHendrik Brueckner { S390_FEAT_PLO_TCSO, S390_FEAT_PLO_EXT }, 526*393c835eSHendrik Brueckner { S390_FEAT_PLO_QCS, S390_FEAT_PLO_EXT }, 527*393c835eSHendrik Brueckner { S390_FEAT_PLO_QCSG, S390_FEAT_PLO_EXT }, 528*393c835eSHendrik Brueckner { S390_FEAT_PLO_QCSX, S390_FEAT_PLO_EXT }, 529*393c835eSHendrik Brueckner { S390_FEAT_PLO_QCSO, S390_FEAT_PLO_EXT }, 530*393c835eSHendrik Brueckner { S390_FEAT_PLO_LO, S390_FEAT_PLO_EXT }, 531*393c835eSHendrik Brueckner { S390_FEAT_PLO_DLX, S390_FEAT_PLO_EXT }, 532*393c835eSHendrik Brueckner { S390_FEAT_PLO_DLO, S390_FEAT_PLO_EXT }, 533*393c835eSHendrik Brueckner { S390_FEAT_PLO_TL, S390_FEAT_PLO_EXT }, 534*393c835eSHendrik Brueckner { S390_FEAT_PLO_TLG, S390_FEAT_PLO_EXT }, 535*393c835eSHendrik Brueckner { S390_FEAT_PLO_TLX, S390_FEAT_PLO_EXT }, 536*393c835eSHendrik Brueckner { S390_FEAT_PLO_TLO, S390_FEAT_PLO_EXT }, 537*393c835eSHendrik Brueckner { S390_FEAT_PLO_QL, S390_FEAT_PLO_EXT }, 538*393c835eSHendrik Brueckner { S390_FEAT_PLO_QLG, S390_FEAT_PLO_EXT }, 539*393c835eSHendrik Brueckner { S390_FEAT_PLO_QLX, S390_FEAT_PLO_EXT }, 540*393c835eSHendrik Brueckner { S390_FEAT_PLO_QLO, S390_FEAT_PLO_EXT }, 541*393c835eSHendrik Brueckner { S390_FEAT_PLO_STO, S390_FEAT_PLO_EXT }, 542*393c835eSHendrik Brueckner { S390_FEAT_PLO_DST, S390_FEAT_PLO_EXT }, 543*393c835eSHendrik Brueckner { S390_FEAT_PLO_DSTG, S390_FEAT_PLO_EXT }, 544*393c835eSHendrik Brueckner { S390_FEAT_PLO_DSTX, S390_FEAT_PLO_EXT }, 545*393c835eSHendrik Brueckner { S390_FEAT_PLO_DSTO, S390_FEAT_PLO_EXT }, 546*393c835eSHendrik Brueckner { S390_FEAT_PLO_TST, S390_FEAT_PLO_EXT }, 547*393c835eSHendrik Brueckner { S390_FEAT_PLO_TSTG, S390_FEAT_PLO_EXT }, 548*393c835eSHendrik Brueckner { S390_FEAT_PLO_TSTX, S390_FEAT_PLO_EXT }, 549*393c835eSHendrik Brueckner { S390_FEAT_PLO_TSTO, S390_FEAT_PLO_EXT }, 550*393c835eSHendrik Brueckner { S390_FEAT_PLO_QST, S390_FEAT_PLO_EXT }, 551*393c835eSHendrik Brueckner { S390_FEAT_PLO_QSTG, S390_FEAT_PLO_EXT }, 552*393c835eSHendrik Brueckner { S390_FEAT_PLO_QSTX, S390_FEAT_PLO_EXT }, 553*393c835eSHendrik Brueckner { S390_FEAT_PLO_QSTO, S390_FEAT_PLO_EXT }, 55480560137SDavid Hildenbrand }; 55580560137SDavid Hildenbrand int i; 55680560137SDavid Hildenbrand 55780560137SDavid Hildenbrand for (i = 0; i < ARRAY_SIZE(dep); i++) { 55880560137SDavid Hildenbrand if (test_bit(dep[i][0], model->features) && 55980560137SDavid Hildenbrand !test_bit(dep[i][1], model->features)) { 5603dc6f869SAlistair Francis warn_report("\'%s\' requires \'%s\'.", 56180560137SDavid Hildenbrand s390_feat_def(dep[i][0])->name, 56280560137SDavid Hildenbrand s390_feat_def(dep[i][1])->name); 56380560137SDavid Hildenbrand } 56480560137SDavid Hildenbrand } 56580560137SDavid Hildenbrand } 56680560137SDavid Hildenbrand 56780560137SDavid Hildenbrand static void error_prepend_missing_feat(const char *name, void *opaque) 56880560137SDavid Hildenbrand { 56980560137SDavid Hildenbrand error_prepend((Error **) opaque, "%s ", name); 57080560137SDavid Hildenbrand } 57180560137SDavid Hildenbrand 572ff7c98a9SClaudio Fontana static void check_compat_model_failed(Error **errp, 573ff7c98a9SClaudio Fontana const S390CPUModel *max_model, 574ff7c98a9SClaudio Fontana const char *msg) 575ff7c98a9SClaudio Fontana { 576ff7c98a9SClaudio Fontana error_setg(errp, "%s. Maximum supported model in the current configuration: \'%s\'", 577ff7c98a9SClaudio Fontana msg, max_model->def->name); 578ff7c98a9SClaudio Fontana error_append_hint(errp, "Consider a different accelerator, try \"-accel help\"\n"); 579ff7c98a9SClaudio Fontana return; 580ff7c98a9SClaudio Fontana } 581ff7c98a9SClaudio Fontana 5827c0c099aSZhao Liu static bool check_compatibility(const S390CPUModel *max_model, 58380560137SDavid Hildenbrand const S390CPUModel *model, Error **errp) 58480560137SDavid Hildenbrand { 58595e9053aSZhao Liu ERRP_GUARD(); 58680560137SDavid Hildenbrand S390FeatBitmap missing; 58780560137SDavid Hildenbrand 58880560137SDavid Hildenbrand if (model->def->gen > max_model->def->gen) { 589ff7c98a9SClaudio Fontana check_compat_model_failed(errp, max_model, "Selected CPU generation is too new"); 5907c0c099aSZhao Liu return false; 59180560137SDavid Hildenbrand } else if (model->def->gen == max_model->def->gen && 59280560137SDavid Hildenbrand model->def->ec_ga > max_model->def->ec_ga) { 593ff7c98a9SClaudio Fontana check_compat_model_failed(errp, max_model, "Selected CPU GA level is too new"); 5947c0c099aSZhao Liu return false; 59580560137SDavid Hildenbrand } 59680560137SDavid Hildenbrand 5970110253eSChristian Borntraeger #ifndef CONFIG_USER_ONLY 5980110253eSChristian Borntraeger if (only_migratable && test_bit(S390_FEAT_UNPACK, model->features)) { 5990110253eSChristian Borntraeger error_setg(errp, "The unpack facility is not compatible with " 6000110253eSChristian Borntraeger "the --only-migratable option. You must remove either " 6010110253eSChristian Borntraeger "the 'unpack' facility or the --only-migratable option"); 6027c0c099aSZhao Liu return false; 6030110253eSChristian Borntraeger } 6040110253eSChristian Borntraeger #endif 6050110253eSChristian Borntraeger 60680560137SDavid Hildenbrand /* detect the missing features to properly report them */ 60780560137SDavid Hildenbrand bitmap_andnot(missing, model->features, max_model->features, S390_FEAT_MAX); 60880560137SDavid Hildenbrand if (bitmap_empty(missing, S390_FEAT_MAX)) { 6097c0c099aSZhao Liu return true; 61080560137SDavid Hildenbrand } 61180560137SDavid Hildenbrand 61280560137SDavid Hildenbrand error_setg(errp, " "); 61380560137SDavid Hildenbrand s390_feat_bitmap_to_ascii(missing, errp, error_prepend_missing_feat); 61480560137SDavid Hildenbrand error_prepend(errp, "Some features requested in the CPU model are not " 615ff7c98a9SClaudio Fontana "available in the current configuration: "); 616ff7c98a9SClaudio Fontana error_append_hint(errp, 617ff7c98a9SClaudio Fontana "Consider a different accelerator, QEMU, or kernel version\n"); 6187c0c099aSZhao Liu return false; 61980560137SDavid Hildenbrand } 62080560137SDavid Hildenbrand 6217ab3eb42SCho, Yu-Chen S390CPUModel *get_max_cpu_model(Error **errp) 62280560137SDavid Hildenbrand { 62380560137SDavid Hildenbrand static S390CPUModel max_model; 62480560137SDavid Hildenbrand static bool cached; 62580560137SDavid Hildenbrand 62680560137SDavid Hildenbrand if (cached) { 62780560137SDavid Hildenbrand return &max_model; 62880560137SDavid Hildenbrand } 62980560137SDavid Hildenbrand 63080560137SDavid Hildenbrand if (kvm_enabled()) { 631c6f1baf2SZhao Liu if (!kvm_s390_get_host_cpu_model(&max_model, errp)) { 63247ab3b21SZhao Liu return NULL; 63347ab3b21SZhao Liu } 63480560137SDavid Hildenbrand } else { 63535b4df64SDavid Hildenbrand max_model.def = s390_find_cpu_def(QEMU_MAX_CPU_TYPE, QEMU_MAX_CPU_GEN, 63635b4df64SDavid Hildenbrand QEMU_MAX_CPU_EC_GA, NULL); 63735b4df64SDavid Hildenbrand bitmap_copy(max_model.features, qemu_max_cpu_feat, S390_FEAT_MAX); 63880560137SDavid Hildenbrand } 63980560137SDavid Hildenbrand cached = true; 64080560137SDavid Hildenbrand return &max_model; 64180560137SDavid Hildenbrand } 64280560137SDavid Hildenbrand 64341868f84SDavid Hildenbrand void s390_realize_cpu_model(CPUState *cs, Error **errp) 64441868f84SDavid Hildenbrand { 64595e9053aSZhao Liu ERRP_GUARD(); 64641868f84SDavid Hildenbrand S390CPUClass *xcc = S390_CPU_GET_CLASS(cs); 64780560137SDavid Hildenbrand S390CPU *cpu = S390_CPU(cs); 64880560137SDavid Hildenbrand const S390CPUModel *max_model; 64941868f84SDavid Hildenbrand 65041868f84SDavid Hildenbrand if (xcc->kvm_required && !kvm_enabled()) { 65141868f84SDavid Hildenbrand error_setg(errp, "CPU definition requires KVM"); 65241868f84SDavid Hildenbrand return; 65341868f84SDavid Hildenbrand } 65480560137SDavid Hildenbrand 65580560137SDavid Hildenbrand if (!cpu->model) { 65680560137SDavid Hildenbrand /* no host model support -> perform compatibility stuff */ 65780560137SDavid Hildenbrand apply_cpu_model(NULL, errp); 65880560137SDavid Hildenbrand return; 65980560137SDavid Hildenbrand } 66080560137SDavid Hildenbrand 66180560137SDavid Hildenbrand max_model = get_max_cpu_model(errp); 662d687ae1aSMarkus Armbruster if (!max_model) { 66380560137SDavid Hildenbrand error_prepend(errp, "CPU models are not available: "); 66480560137SDavid Hildenbrand return; 66580560137SDavid Hildenbrand } 66680560137SDavid Hildenbrand 66780560137SDavid Hildenbrand /* copy over properties that can vary */ 66880560137SDavid Hildenbrand cpu->model->lowest_ibc = max_model->lowest_ibc; 66980560137SDavid Hildenbrand cpu->model->cpu_id = max_model->cpu_id; 67064bc98f4SDavid Hildenbrand cpu->model->cpu_id_format = max_model->cpu_id_format; 67180560137SDavid Hildenbrand cpu->model->cpu_ver = max_model->cpu_ver; 67280560137SDavid Hildenbrand 67380560137SDavid Hildenbrand check_consistency(cpu->model); 6749c2df9c5SZhao Liu if (!check_compatibility(max_model, cpu->model, errp)) { 67580560137SDavid Hildenbrand return; 67680560137SDavid Hildenbrand } 67780560137SDavid Hildenbrand 67880560137SDavid Hildenbrand apply_cpu_model(cpu->model, errp); 679076d4d39SDavid Hildenbrand 6801e70ba24SDavid Hildenbrand #if !defined(CONFIG_USER_ONLY) 681076d4d39SDavid Hildenbrand cpu->env.cpuid = s390_cpuid_from_cpu_model(cpu->model); 682076d4d39SDavid Hildenbrand if (tcg_enabled()) { 68371b11cbeSIlya Leoshkevich cpu->env.cpuid = deposit64(cpu->env.cpuid, CPU_PHYS_ADDR_SHIFT, 68471b11cbeSIlya Leoshkevich CPU_PHYS_ADDR_BITS, cpu->env.core_id); 685076d4d39SDavid Hildenbrand } 6861e70ba24SDavid Hildenbrand #endif 68741868f84SDavid Hildenbrand } 68841868f84SDavid Hildenbrand 6890754f604SDavid Hildenbrand static void get_feature(Object *obj, Visitor *v, const char *name, 6900754f604SDavid Hildenbrand void *opaque, Error **errp) 6910754f604SDavid Hildenbrand { 692074df27fSDaniele Buono S390Feat feat = (S390Feat) (uintptr_t) opaque; 6930754f604SDavid Hildenbrand S390CPU *cpu = S390_CPU(obj); 6940754f604SDavid Hildenbrand bool value; 6950754f604SDavid Hildenbrand 6960754f604SDavid Hildenbrand if (!cpu->model) { 6970754f604SDavid Hildenbrand error_setg(errp, "Details about the host CPU model are not available, " 6980754f604SDavid Hildenbrand "features cannot be queried."); 6990754f604SDavid Hildenbrand return; 7000754f604SDavid Hildenbrand } 7010754f604SDavid Hildenbrand 7020754f604SDavid Hildenbrand value = test_bit(feat, cpu->model->features); 7030754f604SDavid Hildenbrand visit_type_bool(v, name, &value, errp); 7040754f604SDavid Hildenbrand } 7050754f604SDavid Hildenbrand 7060754f604SDavid Hildenbrand static void set_feature(Object *obj, Visitor *v, const char *name, 7070754f604SDavid Hildenbrand void *opaque, Error **errp) 7080754f604SDavid Hildenbrand { 709074df27fSDaniele Buono S390Feat feat = (S390Feat) (uintptr_t) opaque; 7100754f604SDavid Hildenbrand DeviceState *dev = DEVICE(obj); 7110754f604SDavid Hildenbrand S390CPU *cpu = S390_CPU(obj); 7120754f604SDavid Hildenbrand bool value; 7130754f604SDavid Hildenbrand 7140754f604SDavid Hildenbrand if (dev->realized) { 7150754f604SDavid Hildenbrand error_setg(errp, "Attempt to set property '%s' on '%s' after " 7160754f604SDavid Hildenbrand "it was realized", name, object_get_typename(obj)); 7170754f604SDavid Hildenbrand return; 7180754f604SDavid Hildenbrand } else if (!cpu->model) { 7190754f604SDavid Hildenbrand error_setg(errp, "Details about the host CPU model are not available, " 7200754f604SDavid Hildenbrand "features cannot be changed."); 7210754f604SDavid Hildenbrand return; 7220754f604SDavid Hildenbrand } 7230754f604SDavid Hildenbrand 724668f62ecSMarkus Armbruster if (!visit_type_bool(v, name, &value, errp)) { 7250754f604SDavid Hildenbrand return; 7260754f604SDavid Hildenbrand } 7270754f604SDavid Hildenbrand if (value) { 7280754f604SDavid Hildenbrand if (!test_bit(feat, cpu->model->def->full_feat)) { 7290754f604SDavid Hildenbrand error_setg(errp, "Feature '%s' is not available for CPU model '%s'," 7300754f604SDavid Hildenbrand " it was introduced with later models.", 7310754f604SDavid Hildenbrand name, cpu->model->def->name); 7320754f604SDavid Hildenbrand return; 7330754f604SDavid Hildenbrand } 7340754f604SDavid Hildenbrand set_bit(feat, cpu->model->features); 7350754f604SDavid Hildenbrand } else { 7360754f604SDavid Hildenbrand clear_bit(feat, cpu->model->features); 7370754f604SDavid Hildenbrand } 7380754f604SDavid Hildenbrand } 7390754f604SDavid Hildenbrand 7400754f604SDavid Hildenbrand static void get_feature_group(Object *obj, Visitor *v, const char *name, 7410754f604SDavid Hildenbrand void *opaque, Error **errp) 7420754f604SDavid Hildenbrand { 743074df27fSDaniele Buono S390FeatGroup group = (S390FeatGroup) (uintptr_t) opaque; 7440754f604SDavid Hildenbrand const S390FeatGroupDef *def = s390_feat_group_def(group); 7450754f604SDavid Hildenbrand S390CPU *cpu = S390_CPU(obj); 7460754f604SDavid Hildenbrand S390FeatBitmap tmp; 7470754f604SDavid Hildenbrand bool value; 7480754f604SDavid Hildenbrand 7490754f604SDavid Hildenbrand if (!cpu->model) { 7500754f604SDavid Hildenbrand error_setg(errp, "Details about the host CPU model are not available, " 7510754f604SDavid Hildenbrand "features cannot be queried."); 7520754f604SDavid Hildenbrand return; 7530754f604SDavid Hildenbrand } 7540754f604SDavid Hildenbrand 7550754f604SDavid Hildenbrand /* a group is enabled if all features are enabled */ 7560754f604SDavid Hildenbrand bitmap_and(tmp, cpu->model->features, def->feat, S390_FEAT_MAX); 7570754f604SDavid Hildenbrand value = bitmap_equal(tmp, def->feat, S390_FEAT_MAX); 7580754f604SDavid Hildenbrand visit_type_bool(v, name, &value, errp); 7590754f604SDavid Hildenbrand } 7600754f604SDavid Hildenbrand 7610754f604SDavid Hildenbrand static void set_feature_group(Object *obj, Visitor *v, const char *name, 7620754f604SDavid Hildenbrand void *opaque, Error **errp) 7630754f604SDavid Hildenbrand { 764074df27fSDaniele Buono S390FeatGroup group = (S390FeatGroup) (uintptr_t) opaque; 7650754f604SDavid Hildenbrand const S390FeatGroupDef *def = s390_feat_group_def(group); 7660754f604SDavid Hildenbrand DeviceState *dev = DEVICE(obj); 7670754f604SDavid Hildenbrand S390CPU *cpu = S390_CPU(obj); 7680754f604SDavid Hildenbrand bool value; 7690754f604SDavid Hildenbrand 7700754f604SDavid Hildenbrand if (dev->realized) { 7710754f604SDavid Hildenbrand error_setg(errp, "Attempt to set property '%s' on '%s' after " 7720754f604SDavid Hildenbrand "it was realized", name, object_get_typename(obj)); 7730754f604SDavid Hildenbrand return; 7740754f604SDavid Hildenbrand } else if (!cpu->model) { 7750754f604SDavid Hildenbrand error_setg(errp, "Details about the host CPU model are not available, " 7760754f604SDavid Hildenbrand "features cannot be changed."); 7770754f604SDavid Hildenbrand return; 7780754f604SDavid Hildenbrand } 7790754f604SDavid Hildenbrand 780668f62ecSMarkus Armbruster if (!visit_type_bool(v, name, &value, errp)) { 7810754f604SDavid Hildenbrand return; 7820754f604SDavid Hildenbrand } 7830754f604SDavid Hildenbrand if (value) { 7840754f604SDavid Hildenbrand /* groups are added in one shot, so an intersect is sufficient */ 7850754f604SDavid Hildenbrand if (!bitmap_intersects(def->feat, cpu->model->def->full_feat, 7860754f604SDavid Hildenbrand S390_FEAT_MAX)) { 7870754f604SDavid Hildenbrand error_setg(errp, "Group '%s' is not available for CPU model '%s'," 7880754f604SDavid Hildenbrand " it was introduced with later models.", 7890754f604SDavid Hildenbrand name, cpu->model->def->name); 7900754f604SDavid Hildenbrand return; 7910754f604SDavid Hildenbrand } 7920754f604SDavid Hildenbrand bitmap_or(cpu->model->features, cpu->model->features, def->feat, 7930754f604SDavid Hildenbrand S390_FEAT_MAX); 7940754f604SDavid Hildenbrand } else { 7950754f604SDavid Hildenbrand bitmap_andnot(cpu->model->features, cpu->model->features, def->feat, 7960754f604SDavid Hildenbrand S390_FEAT_MAX); 7970754f604SDavid Hildenbrand } 7980754f604SDavid Hildenbrand } 7990754f604SDavid Hildenbrand 8006c064de1SDavid Hildenbrand static void s390_cpu_model_initfn(Object *obj) 8016c064de1SDavid Hildenbrand { 802ad5afd07SDavid Hildenbrand S390CPU *cpu = S390_CPU(obj); 803ad5afd07SDavid Hildenbrand S390CPUClass *xcc = S390_CPU_GET_CLASS(cpu); 804ad5afd07SDavid Hildenbrand 805ad5afd07SDavid Hildenbrand cpu->model = g_malloc0(sizeof(*cpu->model)); 806ad5afd07SDavid Hildenbrand /* copy the model, so we can modify it */ 807ad5afd07SDavid Hildenbrand cpu->model->def = xcc->cpu_def; 808ad5afd07SDavid Hildenbrand if (xcc->is_static) { 809ad5afd07SDavid Hildenbrand /* base model - features will never change */ 810ad5afd07SDavid Hildenbrand bitmap_copy(cpu->model->features, cpu->model->def->base_feat, 811ad5afd07SDavid Hildenbrand S390_FEAT_MAX); 812ad5afd07SDavid Hildenbrand } else { 813ad5afd07SDavid Hildenbrand /* latest model - features can change */ 814ad5afd07SDavid Hildenbrand bitmap_copy(cpu->model->features, 815ad5afd07SDavid Hildenbrand cpu->model->def->default_feat, S390_FEAT_MAX); 816ad5afd07SDavid Hildenbrand } 8176c064de1SDavid Hildenbrand } 8186c064de1SDavid Hildenbrand 81935b4df64SDavid Hildenbrand static S390CPUModel s390_qemu_cpu_model; 82035b4df64SDavid Hildenbrand 82135b4df64SDavid Hildenbrand /* Set the qemu CPU model (on machine initialization). Must not be called 82235b4df64SDavid Hildenbrand * once CPUs have been created. 82335b4df64SDavid Hildenbrand */ 82435b4df64SDavid Hildenbrand void s390_set_qemu_cpu_model(uint16_t type, uint8_t gen, uint8_t ec_ga, 82535b4df64SDavid Hildenbrand const S390FeatInit feat_init) 82635b4df64SDavid Hildenbrand { 82735b4df64SDavid Hildenbrand const S390CPUDef *def = s390_find_cpu_def(type, gen, ec_ga, NULL); 82835b4df64SDavid Hildenbrand 82935b4df64SDavid Hildenbrand g_assert(def); 8303c55dd58SPhilippe Mathieu-Daudé g_assert(QTAILQ_EMPTY_RCU(&cpus_queue)); 83135b4df64SDavid Hildenbrand 83235b4df64SDavid Hildenbrand /* build the CPU model */ 833d98ed7d9SDavid Hildenbrand s390_qemu_cpu_model.def = def; 83435b4df64SDavid Hildenbrand bitmap_zero(s390_qemu_cpu_model.features, S390_FEAT_MAX); 83535b4df64SDavid Hildenbrand s390_init_feat_bitmap(feat_init, s390_qemu_cpu_model.features); 83635b4df64SDavid Hildenbrand } 83735b4df64SDavid Hildenbrand 83841868f84SDavid Hildenbrand static void s390_qemu_cpu_model_initfn(Object *obj) 83941868f84SDavid Hildenbrand { 840ad5afd07SDavid Hildenbrand S390CPU *cpu = S390_CPU(obj); 841ad5afd07SDavid Hildenbrand 842ad5afd07SDavid Hildenbrand cpu->model = g_malloc0(sizeof(*cpu->model)); 84335b4df64SDavid Hildenbrand /* copy the CPU model so we can modify it */ 84435b4df64SDavid Hildenbrand memcpy(cpu->model, &s390_qemu_cpu_model, sizeof(*cpu->model)); 84541868f84SDavid Hildenbrand } 84641868f84SDavid Hildenbrand 847c6117788SDavid Hildenbrand static void s390_max_cpu_model_initfn(Object *obj) 848c6117788SDavid Hildenbrand { 849c6117788SDavid Hildenbrand const S390CPUModel *max_model; 850c6117788SDavid Hildenbrand S390CPU *cpu = S390_CPU(obj); 851c6117788SDavid Hildenbrand Error *local_err = NULL; 852c6117788SDavid Hildenbrand 853c6117788SDavid Hildenbrand if (kvm_enabled() && !kvm_s390_cpu_models_supported()) { 854c6117788SDavid Hildenbrand /* "max" and "host" always work, even without CPU model support */ 855c6117788SDavid Hildenbrand return; 856c6117788SDavid Hildenbrand } 857c6117788SDavid Hildenbrand 858c6117788SDavid Hildenbrand max_model = get_max_cpu_model(&local_err); 859c6117788SDavid Hildenbrand if (local_err) { 860c6117788SDavid Hildenbrand /* we expect errors only under KVM, when actually querying the kernel */ 861c6117788SDavid Hildenbrand g_assert(kvm_enabled()); 862c6117788SDavid Hildenbrand error_report_err(local_err); 863c6117788SDavid Hildenbrand /* fallback to unsupported CPU models */ 864c6117788SDavid Hildenbrand return; 865c6117788SDavid Hildenbrand } 866c6117788SDavid Hildenbrand 867c6117788SDavid Hildenbrand cpu->model = g_new(S390CPUModel, 1); 868c6117788SDavid Hildenbrand /* copy the CPU model so we can modify it */ 869c6117788SDavid Hildenbrand memcpy(cpu->model, max_model, sizeof(*cpu->model)); 870c6117788SDavid Hildenbrand } 871c6117788SDavid Hildenbrand 87241868f84SDavid Hildenbrand static void s390_cpu_model_finalize(Object *obj) 87341868f84SDavid Hildenbrand { 874ad5afd07SDavid Hildenbrand S390CPU *cpu = S390_CPU(obj); 875ad5afd07SDavid Hildenbrand 876ad5afd07SDavid Hildenbrand g_free(cpu->model); 877ad5afd07SDavid Hildenbrand cpu->model = NULL; 87841868f84SDavid Hildenbrand } 87941868f84SDavid Hildenbrand 8806efadc90SDavid Hildenbrand static bool get_is_migration_safe(Object *obj, Error **errp) 8816efadc90SDavid Hildenbrand { 8826efadc90SDavid Hildenbrand return S390_CPU_GET_CLASS(obj)->is_migration_safe; 8836efadc90SDavid Hildenbrand } 8846efadc90SDavid Hildenbrand 8856efadc90SDavid Hildenbrand static bool get_is_static(Object *obj, Error **errp) 8866efadc90SDavid Hildenbrand { 8876efadc90SDavid Hildenbrand return S390_CPU_GET_CLASS(obj)->is_static; 8886efadc90SDavid Hildenbrand } 8896efadc90SDavid Hildenbrand 8906efadc90SDavid Hildenbrand static char *get_description(Object *obj, Error **errp) 8916efadc90SDavid Hildenbrand { 8926efadc90SDavid Hildenbrand return g_strdup(S390_CPU_GET_CLASS(obj)->desc); 8936efadc90SDavid Hildenbrand } 8946efadc90SDavid Hildenbrand 8956efadc90SDavid Hildenbrand void s390_cpu_model_class_register_props(ObjectClass *oc) 8966efadc90SDavid Hildenbrand { 897ab76d63aSEduardo Habkost S390FeatGroup group; 898ab76d63aSEduardo Habkost S390Feat feat; 899ab76d63aSEduardo Habkost 9006efadc90SDavid Hildenbrand object_class_property_add_bool(oc, "migration-safe", get_is_migration_safe, 9016efadc90SDavid Hildenbrand NULL); 902d2623129SMarkus Armbruster object_class_property_add_bool(oc, "static", get_is_static, 903d2623129SMarkus Armbruster NULL); 904d2623129SMarkus Armbruster object_class_property_add_str(oc, "description", get_description, NULL); 905ab76d63aSEduardo Habkost 906ab76d63aSEduardo Habkost for (feat = 0; feat < S390_FEAT_MAX; feat++) { 907ab76d63aSEduardo Habkost const S390FeatDef *def = s390_feat_def(feat); 908ab76d63aSEduardo Habkost object_class_property_add(oc, def->name, "bool", get_feature, 909ab76d63aSEduardo Habkost set_feature, NULL, (void *) feat); 910ab76d63aSEduardo Habkost object_class_property_set_description(oc, def->name, def->desc); 911ab76d63aSEduardo Habkost } 912ab76d63aSEduardo Habkost for (group = 0; group < S390_FEAT_GROUP_MAX; group++) { 913ab76d63aSEduardo Habkost const S390FeatGroupDef *def = s390_feat_group_def(group); 914ab76d63aSEduardo Habkost object_class_property_add(oc, def->name, "bool", get_feature_group, 915ab76d63aSEduardo Habkost set_feature_group, NULL, (void *) group); 916ab76d63aSEduardo Habkost object_class_property_set_description(oc, def->name, def->desc); 917ab76d63aSEduardo Habkost } 9186efadc90SDavid Hildenbrand } 9196efadc90SDavid Hildenbrand 92041868f84SDavid Hildenbrand #ifdef CONFIG_KVM 92141868f84SDavid Hildenbrand static void s390_host_cpu_model_class_init(ObjectClass *oc, void *data) 92241868f84SDavid Hildenbrand { 92341868f84SDavid Hildenbrand S390CPUClass *xcc = S390_CPU_CLASS(oc); 92441868f84SDavid Hildenbrand 92541868f84SDavid Hildenbrand xcc->kvm_required = true; 92641868f84SDavid Hildenbrand xcc->desc = "KVM only: All recognized features"; 92741868f84SDavid Hildenbrand } 92841868f84SDavid Hildenbrand #endif 92941868f84SDavid Hildenbrand 9306c064de1SDavid Hildenbrand static void s390_base_cpu_model_class_init(ObjectClass *oc, void *data) 9316c064de1SDavid Hildenbrand { 9326c064de1SDavid Hildenbrand S390CPUClass *xcc = S390_CPU_CLASS(oc); 9336c064de1SDavid Hildenbrand 9346c064de1SDavid Hildenbrand /* all base models are migration safe */ 9356c064de1SDavid Hildenbrand xcc->cpu_def = (const S390CPUDef *) data; 9366c064de1SDavid Hildenbrand xcc->is_migration_safe = true; 9376c064de1SDavid Hildenbrand xcc->is_static = true; 9386c064de1SDavid Hildenbrand xcc->desc = xcc->cpu_def->desc; 9396c064de1SDavid Hildenbrand } 9406c064de1SDavid Hildenbrand 9416c064de1SDavid Hildenbrand static void s390_cpu_model_class_init(ObjectClass *oc, void *data) 9426c064de1SDavid Hildenbrand { 9436c064de1SDavid Hildenbrand S390CPUClass *xcc = S390_CPU_CLASS(oc); 9446c064de1SDavid Hildenbrand 9456c064de1SDavid Hildenbrand /* model that can change between QEMU versions */ 9466c064de1SDavid Hildenbrand xcc->cpu_def = (const S390CPUDef *) data; 9476c064de1SDavid Hildenbrand xcc->is_migration_safe = true; 9486c064de1SDavid Hildenbrand xcc->desc = xcc->cpu_def->desc; 9496c064de1SDavid Hildenbrand } 9506c064de1SDavid Hildenbrand 95141868f84SDavid Hildenbrand static void s390_qemu_cpu_model_class_init(ObjectClass *oc, void *data) 95241868f84SDavid Hildenbrand { 95341868f84SDavid Hildenbrand S390CPUClass *xcc = S390_CPU_CLASS(oc); 95441868f84SDavid Hildenbrand 95541868f84SDavid Hildenbrand xcc->is_migration_safe = true; 95641868f84SDavid Hildenbrand xcc->desc = g_strdup_printf("QEMU Virtual CPU version %s", 95741868f84SDavid Hildenbrand qemu_hw_version()); 95841868f84SDavid Hildenbrand } 95941868f84SDavid Hildenbrand 960c6117788SDavid Hildenbrand static void s390_max_cpu_model_class_init(ObjectClass *oc, void *data) 961c6117788SDavid Hildenbrand { 962c6117788SDavid Hildenbrand S390CPUClass *xcc = S390_CPU_CLASS(oc); 963c6117788SDavid Hildenbrand 964c6117788SDavid Hildenbrand /* 965c6117788SDavid Hildenbrand * The "max" model is neither static nor migration safe. Under KVM 966d98ed7d9SDavid Hildenbrand * it represents the "host" model. Under TCG it represents the "qemu" CPU 967d98ed7d9SDavid Hildenbrand * model of the latest QEMU machine. 968c6117788SDavid Hildenbrand */ 969c6117788SDavid Hildenbrand xcc->desc = 970c6117788SDavid Hildenbrand "Enables all features supported by the accelerator in the current host"; 971c6117788SDavid Hildenbrand } 972c6117788SDavid Hildenbrand 97341868f84SDavid Hildenbrand /* Generate type name for a cpu model. Caller has to free the string. */ 97441868f84SDavid Hildenbrand static char *s390_cpu_type_name(const char *model_name) 97541868f84SDavid Hildenbrand { 97641868f84SDavid Hildenbrand return g_strdup_printf(S390_CPU_TYPE_NAME("%s"), model_name); 97741868f84SDavid Hildenbrand } 97841868f84SDavid Hildenbrand 9796c064de1SDavid Hildenbrand /* Generate type name for a base cpu model. Caller has to free the string. */ 9806c064de1SDavid Hildenbrand static char *s390_base_cpu_type_name(const char *model_name) 9816c064de1SDavid Hildenbrand { 9826c064de1SDavid Hildenbrand return g_strdup_printf(S390_CPU_TYPE_NAME("%s-base"), model_name); 9836c064de1SDavid Hildenbrand } 9846c064de1SDavid Hildenbrand 98541868f84SDavid Hildenbrand ObjectClass *s390_cpu_class_by_name(const char *name) 98641868f84SDavid Hildenbrand { 98741868f84SDavid Hildenbrand char *typename = s390_cpu_type_name(name); 98841868f84SDavid Hildenbrand ObjectClass *oc; 98941868f84SDavid Hildenbrand 99041868f84SDavid Hildenbrand oc = object_class_by_name(typename); 99141868f84SDavid Hildenbrand g_free(typename); 99241868f84SDavid Hildenbrand return oc; 99341868f84SDavid Hildenbrand } 99441868f84SDavid Hildenbrand 99541868f84SDavid Hildenbrand static const TypeInfo qemu_s390_cpu_type_info = { 99641868f84SDavid Hildenbrand .name = S390_CPU_TYPE_NAME("qemu"), 99741868f84SDavid Hildenbrand .parent = TYPE_S390_CPU, 99841868f84SDavid Hildenbrand .instance_init = s390_qemu_cpu_model_initfn, 99941868f84SDavid Hildenbrand .instance_finalize = s390_cpu_model_finalize, 100041868f84SDavid Hildenbrand .class_init = s390_qemu_cpu_model_class_init, 100141868f84SDavid Hildenbrand }; 100241868f84SDavid Hildenbrand 1003c6117788SDavid Hildenbrand static const TypeInfo max_s390_cpu_type_info = { 1004c6117788SDavid Hildenbrand .name = S390_CPU_TYPE_NAME("max"), 1005c6117788SDavid Hildenbrand .parent = TYPE_S390_CPU, 1006c6117788SDavid Hildenbrand .instance_init = s390_max_cpu_model_initfn, 1007c6117788SDavid Hildenbrand .instance_finalize = s390_cpu_model_finalize, 1008c6117788SDavid Hildenbrand .class_init = s390_max_cpu_model_class_init, 1009c6117788SDavid Hildenbrand }; 1010c6117788SDavid Hildenbrand 101141868f84SDavid Hildenbrand #ifdef CONFIG_KVM 101241868f84SDavid Hildenbrand static const TypeInfo host_s390_cpu_type_info = { 101341868f84SDavid Hildenbrand .name = S390_CPU_TYPE_NAME("host"), 1014c6117788SDavid Hildenbrand .parent = S390_CPU_TYPE_NAME("max"), 101541868f84SDavid Hildenbrand .class_init = s390_host_cpu_model_class_init, 101641868f84SDavid Hildenbrand }; 101741868f84SDavid Hildenbrand #endif 101841868f84SDavid Hildenbrand 101930e82de7SDavid Hildenbrand static void init_ignored_base_feat(void) 102030e82de7SDavid Hildenbrand { 102130e82de7SDavid Hildenbrand static const int feats[] = { 102230e82de7SDavid Hildenbrand /* MSA subfunctions that could not be available on certain machines */ 102330e82de7SDavid Hildenbrand S390_FEAT_KMAC_DEA, 102430e82de7SDavid Hildenbrand S390_FEAT_KMAC_TDEA_128, 102530e82de7SDavid Hildenbrand S390_FEAT_KMAC_TDEA_192, 102630e82de7SDavid Hildenbrand S390_FEAT_KMC_DEA, 102730e82de7SDavid Hildenbrand S390_FEAT_KMC_TDEA_128, 102830e82de7SDavid Hildenbrand S390_FEAT_KMC_TDEA_192, 102930e82de7SDavid Hildenbrand S390_FEAT_KM_DEA, 103030e82de7SDavid Hildenbrand S390_FEAT_KM_TDEA_128, 103130e82de7SDavid Hildenbrand S390_FEAT_KM_TDEA_192, 103230e82de7SDavid Hildenbrand S390_FEAT_KIMD_SHA_1, 103330e82de7SDavid Hildenbrand S390_FEAT_KLMD_SHA_1, 1034eaf6f642SChristian Borntraeger /* CSSKE is deprecated on newer generations */ 1035eaf6f642SChristian Borntraeger S390_FEAT_CONDITIONAL_SSKE, 103630e82de7SDavid Hildenbrand }; 103730e82de7SDavid Hildenbrand int i; 103830e82de7SDavid Hildenbrand 103930e82de7SDavid Hildenbrand for (i = 0; i < ARRAY_SIZE(feats); i++) { 104030e82de7SDavid Hildenbrand set_bit(feats[i], ignored_base_feat); 104130e82de7SDavid Hildenbrand } 104230e82de7SDavid Hildenbrand } 104330e82de7SDavid Hildenbrand 104441868f84SDavid Hildenbrand static void register_types(void) 104541868f84SDavid Hildenbrand { 1046d98ed7d9SDavid Hildenbrand static const S390FeatInit qemu_max_init = { S390_FEAT_LIST_QEMU_MAX }; 10476c064de1SDavid Hildenbrand int i; 10486c064de1SDavid Hildenbrand 104930e82de7SDavid Hildenbrand init_ignored_base_feat(); 105030e82de7SDavid Hildenbrand 1051cced0d65SMichael Tokarev /* init all bitmaps from generated data initially */ 1052d98ed7d9SDavid Hildenbrand s390_init_feat_bitmap(qemu_max_init, qemu_max_cpu_feat); 10536c064de1SDavid Hildenbrand for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) { 10546c064de1SDavid Hildenbrand s390_init_feat_bitmap(s390_cpu_defs[i].base_init, 10556c064de1SDavid Hildenbrand s390_cpu_defs[i].base_feat); 10566c064de1SDavid Hildenbrand s390_init_feat_bitmap(s390_cpu_defs[i].default_init, 10576c064de1SDavid Hildenbrand s390_cpu_defs[i].default_feat); 10586c064de1SDavid Hildenbrand s390_init_feat_bitmap(s390_cpu_defs[i].full_init, 10596c064de1SDavid Hildenbrand s390_cpu_defs[i].full_feat); 10606c064de1SDavid Hildenbrand } 10616c064de1SDavid Hildenbrand 1062d98ed7d9SDavid Hildenbrand /* initialize the qemu model with the maximum definition ("max" model) */ 106335b4df64SDavid Hildenbrand s390_set_qemu_cpu_model(QEMU_MAX_CPU_TYPE, QEMU_MAX_CPU_GEN, 1064d98ed7d9SDavid Hildenbrand QEMU_MAX_CPU_EC_GA, qemu_max_init); 106535b4df64SDavid Hildenbrand 10666c064de1SDavid Hildenbrand for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) { 10676c064de1SDavid Hildenbrand char *base_name = s390_base_cpu_type_name(s390_cpu_defs[i].name); 10686c064de1SDavid Hildenbrand TypeInfo ti_base = { 10696c064de1SDavid Hildenbrand .name = base_name, 10706c064de1SDavid Hildenbrand .parent = TYPE_S390_CPU, 10716c064de1SDavid Hildenbrand .instance_init = s390_cpu_model_initfn, 10726c064de1SDavid Hildenbrand .instance_finalize = s390_cpu_model_finalize, 10736c064de1SDavid Hildenbrand .class_init = s390_base_cpu_model_class_init, 10746c064de1SDavid Hildenbrand .class_data = (void *) &s390_cpu_defs[i], 10756c064de1SDavid Hildenbrand }; 10766c064de1SDavid Hildenbrand char *name = s390_cpu_type_name(s390_cpu_defs[i].name); 10776c064de1SDavid Hildenbrand TypeInfo ti = { 10786c064de1SDavid Hildenbrand .name = name, 10796c064de1SDavid Hildenbrand .parent = TYPE_S390_CPU, 10806c064de1SDavid Hildenbrand .instance_init = s390_cpu_model_initfn, 10816c064de1SDavid Hildenbrand .instance_finalize = s390_cpu_model_finalize, 10826c064de1SDavid Hildenbrand .class_init = s390_cpu_model_class_init, 10836c064de1SDavid Hildenbrand .class_data = (void *) &s390_cpu_defs[i], 10846c064de1SDavid Hildenbrand }; 10856c064de1SDavid Hildenbrand 10866c064de1SDavid Hildenbrand type_register_static(&ti_base); 10876c064de1SDavid Hildenbrand type_register_static(&ti); 10886c064de1SDavid Hildenbrand g_free(base_name); 10896c064de1SDavid Hildenbrand g_free(name); 10906c064de1SDavid Hildenbrand } 10916c064de1SDavid Hildenbrand 109241868f84SDavid Hildenbrand type_register_static(&qemu_s390_cpu_type_info); 1093c6117788SDavid Hildenbrand type_register_static(&max_s390_cpu_type_info); 109441868f84SDavid Hildenbrand #ifdef CONFIG_KVM 109541868f84SDavid Hildenbrand type_register_static(&host_s390_cpu_type_info); 109641868f84SDavid Hildenbrand #endif 109741868f84SDavid Hildenbrand } 109841868f84SDavid Hildenbrand 109941868f84SDavid Hildenbrand type_init(register_types) 1100