]>
Commit | Line | Data |
---|---|---|
6c064de1 DH |
1 | /* |
2 | * CPU models for s390x | |
3 | * | |
4 | * Copyright 2016 IBM Corp. | |
5 | * | |
6 | * Author(s): David Hildenbrand <[email protected]> | |
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 | #ifndef TARGET_S390X_CPU_MODELS_H | |
14 | #define TARGET_S390X_CPU_MODELS_H | |
15 | ||
16 | #include "cpu_features.h" | |
35b4df64 | 17 | #include "gen-features.h" |
6c064de1 DH |
18 | #include "qom/cpu.h" |
19 | ||
20 | /* static CPU definition */ | |
ef2974cc | 21 | struct S390CPUDef { |
6c064de1 DH |
22 | const char *name; /* name exposed to the user */ |
23 | const char *desc; /* description exposed to the user */ | |
24 | uint8_t gen; /* hw generation identification */ | |
25 | uint16_t type; /* cpu type identification */ | |
26 | uint8_t ec_ga; /* EC GA version (on which also the BC is based) */ | |
27 | uint8_t mha_pow; /* Maximum Host Adress Power, mha = 2^pow-1 */ | |
28 | uint32_t hmfai; /* hypervisor-managed facilities */ | |
29 | /* base/min features, must never be changed between QEMU versions */ | |
30 | S390FeatBitmap base_feat; | |
31 | /* used to init base_feat from generated data */ | |
32 | S390FeatInit base_init; | |
33 | /* deafault features, QEMU version specific */ | |
34 | S390FeatBitmap default_feat; | |
35 | /* used to init default_feat from generated data */ | |
36 | S390FeatInit default_init; | |
37 | /* max allowed features, QEMU version specific */ | |
38 | S390FeatBitmap full_feat; | |
39 | /* used to init full_feat from generated data */ | |
40 | S390FeatInit full_init; | |
ef2974cc | 41 | }; |
6c064de1 | 42 | |
ad5afd07 | 43 | /* CPU model based on a CPU definition */ |
ef2974cc | 44 | struct S390CPUModel { |
ad5afd07 DH |
45 | const S390CPUDef *def; |
46 | S390FeatBitmap features; | |
47 | /* values copied from the "host" model, can change during migration */ | |
48 | uint16_t lowest_ibc; /* lowest IBC that the hardware supports */ | |
49 | uint32_t cpu_id; /* CPU id */ | |
64bc98f4 | 50 | uint8_t cpu_id_format; /* CPU id format bit */ |
ad5afd07 | 51 | uint8_t cpu_ver; /* CPU version, usually "ff" for kvm */ |
ef2974cc | 52 | }; |
ad5afd07 | 53 | |
3b84c25c DH |
54 | /* |
55 | * CPU ID | |
56 | * | |
57 | * bits 0-7: Zeroes (ff for kvm) | |
58 | * bits 8-31: CPU ID (serial number) | |
64bc98f4 DH |
59 | * bits 32-47: Machine type |
60 | * bit 48: CPU ID format | |
61 | * bits 49-63: Zeroes | |
3b84c25c DH |
62 | */ |
63 | #define cpuid_type(x) (((x) >> 16) & 0xffff) | |
64 | #define cpuid_id(x) (((x) >> 32) & 0xffffff) | |
65 | #define cpuid_ver(x) (((x) >> 56) & 0xff) | |
64bc98f4 | 66 | #define cpuid_format(x) (((x) >> 15) & 0x1) |
3b84c25c DH |
67 | |
68 | #define lowest_ibc(x) (((uint32_t)(x) >> 16) & 0xfff) | |
69 | #define unblocked_ibc(x) ((uint32_t)(x) & 0xfff) | |
70 | #define has_ibc(x) (lowest_ibc(x) != 0) | |
71 | ||
059be520 | 72 | #define S390_GEN_Z10 0xa |
3b84c25c DH |
73 | #define ibc_gen(x) (x == 0 ? 0 : ((x >> 4) + S390_GEN_Z10)) |
74 | #define ibc_ec_ga(x) (x & 0xf) | |
059be520 | 75 | |
c9ad8a7a JH |
76 | void s390_cpudef_featoff(uint8_t gen, uint8_t ec_ga, S390Feat feat); |
77 | void s390_cpudef_featoff_greater(uint8_t gen, uint8_t ec_ga, S390Feat feat); | |
a3669307 | 78 | uint32_t s390_get_hmfai(void); |
3fad3252 | 79 | uint8_t s390_get_mha_pow(void); |
059be520 DH |
80 | uint32_t s390_get_ibc_val(void); |
81 | static inline uint16_t s390_ibc_from_cpu_model(const S390CPUModel *model) | |
82 | { | |
83 | uint16_t ibc = 0; | |
84 | ||
85 | if (model->def->gen >= S390_GEN_Z10) { | |
86 | ibc = ((model->def->gen - S390_GEN_Z10) << 4) + model->def->ec_ga; | |
87 | } | |
88 | return ibc; | |
89 | } | |
4dd4200e | 90 | void s390_get_feat_block(S390FeatType type, uint8_t *data); |
7c72ac49 | 91 | bool s390_has_feat(S390Feat feat); |
3b84c25c DH |
92 | uint8_t s390_get_gen_for_cpu_type(uint16_t type); |
93 | static inline bool s390_known_cpu_type(uint16_t type) | |
94 | { | |
95 | return s390_get_gen_for_cpu_type(type) != 0; | |
96 | } | |
97 | static inline uint64_t s390_cpuid_from_cpu_model(const S390CPUModel *model) | |
98 | { | |
99 | return ((uint64_t)model->cpu_ver << 56) | | |
100 | ((uint64_t)model->cpu_id << 32) | | |
64bc98f4 DH |
101 | ((uint64_t)model->def->type << 16) | |
102 | (model->def->gen == 7 ? 0 : (uint64_t)model->cpu_id_format << 15); | |
3b84c25c DH |
103 | } |
104 | S390CPUDef const *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga, | |
105 | S390FeatBitmap features); | |
106 | ||
107 | #ifdef CONFIG_KVM | |
108 | bool kvm_s390_cpu_models_supported(void); | |
109 | void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp); | |
110 | void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp); | |
111 | #else | |
112 | static inline void kvm_s390_get_host_cpu_model(S390CPUModel *model, | |
113 | Error **errp) | |
114 | { | |
115 | } | |
116 | static inline void kvm_s390_apply_cpu_model(const S390CPUModel *model, | |
117 | Error **errp) | |
118 | { | |
119 | } | |
120 | static inline bool kvm_s390_cpu_models_supported(void) | |
121 | { | |
122 | return false; | |
123 | } | |
124 | #endif | |
7c72ac49 | 125 | |
6c064de1 | 126 | #endif /* TARGET_S390X_CPU_MODELS_H */ |