2 * CPU features/facilities for s390x
4 * Copyright IBM Corp. 2016, 2018
5 * Copyright Red Hat, Inc. 2019
7 * Author(s): David Hildenbrand <david@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or (at
10 * your option) any later version. See the COPYING file in the top-level
14 #include "qemu/osdep.h"
15 #include "qemu/module.h"
16 #include "cpu_features.h"
17 #ifndef CONFIG_USER_ONLY
18 #include "target/s390x/kvm/pv.h"
21 #define DEF_FEAT(_FEAT, _NAME, _TYPE, _BIT, _DESC) \
22 [S390_FEAT_##_FEAT] = { \
24 .type = S390_FEAT_TYPE_##_TYPE, \
28 static const S390FeatDef s390_features
[S390_FEAT_MAX
] = {
29 #include "cpu_features_def.h.inc"
33 const S390FeatDef
*s390_feat_def(S390Feat feat
)
35 return &s390_features
[feat
];
38 S390Feat
s390_feat_by_type_and_bit(S390FeatType type
, int bit
)
42 for (feat
= 0; feat
< ARRAY_SIZE(s390_features
); feat
++) {
43 if (s390_features
[feat
].type
== type
&&
44 s390_features
[feat
].bit
== bit
) {
51 void s390_init_feat_bitmap(const S390FeatInit init
, S390FeatBitmap bitmap
)
55 for (i
= 0; i
< (S390_FEAT_MAX
/ 64 + 1); i
++) {
57 for (j
= 0; j
< 64; j
++) {
58 if (init
[i
] & 1ULL << j
) {
59 set_bit(i
* 64 + j
, bitmap
);
66 void s390_fill_feat_block(const S390FeatBitmap features
, S390FeatType type
,
73 case S390_FEAT_TYPE_STFL
:
74 if (test_bit(S390_FEAT_ZARCH
, features
)) {
75 /* Features that are always active */
76 set_be_bit(2, data
); /* z/Architecture */
77 set_be_bit(138, data
); /* Configuration-z-architectural-mode */
80 case S390_FEAT_TYPE_PTFF
:
81 case S390_FEAT_TYPE_KMAC
:
82 case S390_FEAT_TYPE_KMC
:
83 case S390_FEAT_TYPE_KM
:
84 case S390_FEAT_TYPE_KIMD
:
85 case S390_FEAT_TYPE_KLMD
:
86 case S390_FEAT_TYPE_PCKMO
:
87 case S390_FEAT_TYPE_KMCTR
:
88 case S390_FEAT_TYPE_KMF
:
89 case S390_FEAT_TYPE_KMO
:
90 case S390_FEAT_TYPE_PCC
:
91 case S390_FEAT_TYPE_PPNO
:
92 case S390_FEAT_TYPE_KMA
:
93 case S390_FEAT_TYPE_KDSA
:
94 case S390_FEAT_TYPE_SORTL
:
95 case S390_FEAT_TYPE_DFLTCC
:
96 set_be_bit(0, data
); /* query is always available */
102 feat
= find_first_bit(features
, S390_FEAT_MAX
);
103 while (feat
< S390_FEAT_MAX
) {
104 if (s390_features
[feat
].type
== type
) {
105 bit_nr
= s390_features
[feat
].bit
;
106 /* big endian on uint8_t array */
107 set_be_bit(bit_nr
, data
);
109 feat
= find_next_bit(features
, S390_FEAT_MAX
, feat
+ 1);
112 #ifndef CONFIG_USER_ONLY
118 * Some facilities are not available for CPUs in protected mode:
119 * - All SIE facilities because SIE is not available
122 * As VMs can move in and out of protected mode the CPU model
123 * doesn't protect us from that problem because it is only
124 * validated at the start of the VM.
127 case S390_FEAT_TYPE_SCLP_CPU
:
128 clear_be_bit(s390_feat_def(S390_FEAT_SIE_F2
)->bit
, data
);
129 clear_be_bit(s390_feat_def(S390_FEAT_SIE_SKEY
)->bit
, data
);
130 clear_be_bit(s390_feat_def(S390_FEAT_SIE_GPERE
)->bit
, data
);
131 clear_be_bit(s390_feat_def(S390_FEAT_SIE_SIIF
)->bit
, data
);
132 clear_be_bit(s390_feat_def(S390_FEAT_SIE_SIGPIF
)->bit
, data
);
133 clear_be_bit(s390_feat_def(S390_FEAT_SIE_IB
)->bit
, data
);
134 clear_be_bit(s390_feat_def(S390_FEAT_SIE_CEI
)->bit
, data
);
136 case S390_FEAT_TYPE_SCLP_CONF_CHAR
:
137 clear_be_bit(s390_feat_def(S390_FEAT_SIE_GSLS
)->bit
, data
);
138 clear_be_bit(s390_feat_def(S390_FEAT_HPMA2
)->bit
, data
);
139 clear_be_bit(s390_feat_def(S390_FEAT_SIE_KSS
)->bit
, data
);
141 case S390_FEAT_TYPE_SCLP_CONF_CHAR_EXT
:
142 clear_be_bit(s390_feat_def(S390_FEAT_SIE_64BSCAO
)->bit
, data
);
143 clear_be_bit(s390_feat_def(S390_FEAT_SIE_CMMA
)->bit
, data
);
144 clear_be_bit(s390_feat_def(S390_FEAT_SIE_PFMFI
)->bit
, data
);
145 clear_be_bit(s390_feat_def(S390_FEAT_SIE_IBS
)->bit
, data
);
147 case S390_FEAT_TYPE_SCLP_FAC134
:
148 clear_be_bit(s390_feat_def(S390_FEAT_DIAG_318
)->bit
, data
);
156 void s390_add_from_feat_block(S390FeatBitmap features
, S390FeatType type
,
162 case S390_FEAT_TYPE_STFL
:
165 case S390_FEAT_TYPE_PLO
:
166 case S390_FEAT_TYPE_SORTL
:
167 case S390_FEAT_TYPE_DFLTCC
:
171 /* all cpu subfunctions have 128 bit */
175 le_bit
= find_first_bit((unsigned long *) data
, nr_bits
);
176 while (le_bit
< nr_bits
) {
177 /* convert the bit number to a big endian bit nr */
178 S390Feat feat
= s390_feat_by_type_and_bit(type
, BE_BIT_NR(le_bit
));
179 /* ignore unknown bits */
180 if (feat
< S390_FEAT_MAX
) {
181 set_bit(feat
, features
);
183 le_bit
= find_next_bit((unsigned long *) data
, nr_bits
, le_bit
+ 1);
187 void s390_feat_bitmap_to_ascii(const S390FeatBitmap features
, void *opaque
,
188 void (*fn
)(const char *name
, void *opaque
))
190 S390FeatBitmap bitmap
, tmp
;
194 bitmap_copy(bitmap
, features
, S390_FEAT_MAX
);
196 /* process whole groups first */
197 for (group
= 0; group
< S390_FEAT_GROUP_MAX
; group
++) {
198 const S390FeatGroupDef
*def
= s390_feat_group_def(group
);
200 bitmap_and(tmp
, bitmap
, def
->feat
, S390_FEAT_MAX
);
201 if (bitmap_equal(tmp
, def
->feat
, S390_FEAT_MAX
)) {
202 bitmap_andnot(bitmap
, bitmap
, def
->feat
, S390_FEAT_MAX
);
203 fn(def
->name
, opaque
);
207 /* report leftovers as separate features */
208 feat
= find_first_bit(bitmap
, S390_FEAT_MAX
);
209 while (feat
< S390_FEAT_MAX
) {
210 fn(s390_feat_def(feat
)->name
, opaque
);
211 feat
= find_next_bit(bitmap
, S390_FEAT_MAX
, feat
+ 1);
215 #define FEAT_GROUP_INIT(_name, _group, _desc) \
219 .init = { S390_FEAT_GROUP_LIST_ ## _group }, \
222 /* indexed by feature group number for easy lookup */
223 static S390FeatGroupDef s390_feature_groups
[] = {
224 FEAT_GROUP_INIT("plo", PLO
, "Perform-locked-operation facility"),
225 FEAT_GROUP_INIT("tods", TOD_CLOCK_STEERING
, "Tod-clock-steering facility"),
226 FEAT_GROUP_INIT("gen13ptff", GEN13_PTFF
, "PTFF enhancements introduced with z13"),
227 FEAT_GROUP_INIT("msa", MSA
, "Message-security-assist facility"),
228 FEAT_GROUP_INIT("msa1", MSA_EXT_1
, "Message-security-assist-extension 1 facility"),
229 FEAT_GROUP_INIT("msa2", MSA_EXT_2
, "Message-security-assist-extension 2 facility"),
230 FEAT_GROUP_INIT("msa3", MSA_EXT_3
, "Message-security-assist-extension 3 facility"),
231 FEAT_GROUP_INIT("msa4", MSA_EXT_4
, "Message-security-assist-extension 4 facility"),
232 FEAT_GROUP_INIT("msa5", MSA_EXT_5
, "Message-security-assist-extension 5 facility"),
233 FEAT_GROUP_INIT("msa6", MSA_EXT_6
, "Message-security-assist-extension 6 facility"),
234 FEAT_GROUP_INIT("msa7", MSA_EXT_7
, "Message-security-assist-extension 7 facility"),
235 FEAT_GROUP_INIT("msa8", MSA_EXT_8
, "Message-security-assist-extension 8 facility"),
236 FEAT_GROUP_INIT("msa9", MSA_EXT_9
, "Message-security-assist-extension 9 facility"),
237 FEAT_GROUP_INIT("msa9_pckmo", MSA_EXT_9_PCKMO
, "Message-security-assist-extension 9 PCKMO subfunctions"),
238 FEAT_GROUP_INIT("mepochptff", MULTIPLE_EPOCH_PTFF
, "PTFF enhancements introduced with Multiple-epoch facility"),
239 FEAT_GROUP_INIT("esort", ENH_SORT
, "Enhanced-sort facility"),
240 FEAT_GROUP_INIT("deflate", DEFLATE_CONVERSION
, "Deflate-conversion facility"),
243 const S390FeatGroupDef
*s390_feat_group_def(S390FeatGroup group
)
245 return &s390_feature_groups
[group
];
248 static void init_groups(void)
252 /* init all bitmaps from generated data initially */
253 for (i
= 0; i
< ARRAY_SIZE(s390_feature_groups
); i
++) {
254 s390_init_feat_bitmap(s390_feature_groups
[i
].init
,
255 s390_feature_groups
[i
].feat
);
259 type_init(init_groups
)