1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef TARGET_S390X_CPU_MODELS_H
14#define TARGET_S390X_CPU_MODELS_H
15
16#include "cpu_features.h"
17#include "target/s390x/gen-features.h"
18#include "hw/core/cpu.h"
19
20
21struct S390CPUDef {
22 const char *name;
23 const char *desc;
24 uint8_t gen;
25 uint16_t type;
26 uint8_t ec_ga;
27 uint8_t mha_pow;
28 uint32_t hmfai;
29
30 S390FeatBitmap base_feat;
31
32 S390FeatInit base_init;
33
34 S390FeatBitmap default_feat;
35
36 S390FeatInit default_init;
37
38 S390FeatBitmap full_feat;
39
40 S390FeatInit full_init;
41};
42
43
44struct S390CPUModel {
45 const S390CPUDef *def;
46 S390FeatBitmap features;
47
48 uint16_t lowest_ibc;
49 uint32_t cpu_id;
50 uint8_t cpu_id_format;
51 uint8_t cpu_ver;
52};
53
54
55
56
57
58
59
60
61
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)
66#define cpuid_format(x) (((x) >> 15) & 0x1)
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
72#define S390_GEN_Z10 0xa
73#define ibc_gen(x) (x == 0 ? 0 : ((x >> 4) + S390_GEN_Z10))
74#define ibc_ec_ga(x) (x & 0xf)
75
76void s390_cpudef_featoff(uint8_t gen, uint8_t ec_ga, S390Feat feat);
77void s390_cpudef_featoff_greater(uint8_t gen, uint8_t ec_ga, S390Feat feat);
78void s390_cpudef_group_featoff_greater(uint8_t gen, uint8_t ec_ga,
79 S390FeatGroup group);
80uint32_t s390_get_hmfai(void);
81uint8_t s390_get_mha_pow(void);
82uint32_t s390_get_ibc_val(void);
83static inline uint16_t s390_ibc_from_cpu_model(const S390CPUModel *model)
84{
85 uint16_t ibc = 0;
86
87 if (model->def->gen >= S390_GEN_Z10) {
88 ibc = ((model->def->gen - S390_GEN_Z10) << 4) + model->def->ec_ga;
89 }
90 return ibc;
91}
92void s390_get_feat_block(S390FeatType type, uint8_t *data);
93bool s390_has_feat(S390Feat feat);
94uint8_t s390_get_gen_for_cpu_type(uint16_t type);
95static inline bool s390_known_cpu_type(uint16_t type)
96{
97 return s390_get_gen_for_cpu_type(type) != 0;
98}
99#define CPU_ID_SHIFT 32
100#define CPU_ID_BITS 24
101
102
103
104
105#define CPU_PHYS_ADDR_BITS 4
106#define CPU_PHYS_ADDR_SHIFT (CPU_ID_SHIFT + CPU_ID_BITS - CPU_PHYS_ADDR_BITS)
107static inline uint64_t s390_cpuid_from_cpu_model(const S390CPUModel *model)
108{
109 return ((uint64_t)model->cpu_ver << 56) |
110 ((uint64_t)model->cpu_id << CPU_ID_SHIFT) |
111 ((uint64_t)model->def->type << 16) |
112 (model->def->gen == 7 ? 0 : (uint64_t)model->cpu_id_format << 15);
113}
114S390CPUDef const *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga,
115 S390FeatBitmap features);
116
117#ifdef CONFIG_KVM
118bool kvm_s390_cpu_models_supported(void);
119void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp);
120void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp);
121#else
122static inline void kvm_s390_get_host_cpu_model(S390CPUModel *model,
123 Error **errp)
124{
125}
126static inline void kvm_s390_apply_cpu_model(const S390CPUModel *model,
127 Error **errp)
128{
129}
130static inline bool kvm_s390_cpu_models_supported(void)
131{
132 return false;
133}
134#endif
135
136#endif
137