1fcf5ef2aSThomas Huth /*
2fcf5ef2aSThomas Huth * CPU features/facilities helper structs and utility functions for s390
3fcf5ef2aSThomas Huth *
4fcf5ef2aSThomas Huth * Copyright 2016 IBM Corp.
5fcf5ef2aSThomas Huth *
6fcf5ef2aSThomas Huth * Author(s): Michael Mueller <mimu@linux.vnet.ibm.com>
7fcf5ef2aSThomas Huth * David Hildenbrand <dahi@linux.vnet.ibm.com>
8fcf5ef2aSThomas Huth *
9fcf5ef2aSThomas Huth * This work is licensed under the terms of the GNU GPL, version 2 or (at
10fcf5ef2aSThomas Huth * your option) any later version. See the COPYING file in the top-level
11fcf5ef2aSThomas Huth * directory.
12fcf5ef2aSThomas Huth */
13fcf5ef2aSThomas Huth
14fcf5ef2aSThomas Huth #ifndef TARGET_S390X_CPU_FEATURES_H
15fcf5ef2aSThomas Huth #define TARGET_S390X_CPU_FEATURES_H
16fcf5ef2aSThomas Huth
17fcf5ef2aSThomas Huth #include "qemu/bitmap.h"
18fcf5ef2aSThomas Huth #include "cpu_features_def.h"
19d3b18480SMarc-André Lureau #include "target/s390x/gen-features.h"
20fcf5ef2aSThomas Huth
21fcf5ef2aSThomas Huth /* CPU features are announced via different ways */
22fcf5ef2aSThomas Huth typedef enum {
23fcf5ef2aSThomas Huth S390_FEAT_TYPE_STFL,
24fcf5ef2aSThomas Huth S390_FEAT_TYPE_SCLP_CONF_CHAR,
25fcf5ef2aSThomas Huth S390_FEAT_TYPE_SCLP_CONF_CHAR_EXT,
26fabdada9SCollin Walling S390_FEAT_TYPE_SCLP_FAC134,
27fcf5ef2aSThomas Huth S390_FEAT_TYPE_SCLP_CPU,
28fcf5ef2aSThomas Huth S390_FEAT_TYPE_MISC,
29fcf5ef2aSThomas Huth S390_FEAT_TYPE_PLO,
30fcf5ef2aSThomas Huth S390_FEAT_TYPE_PTFF,
31fcf5ef2aSThomas Huth S390_FEAT_TYPE_KMAC,
32fcf5ef2aSThomas Huth S390_FEAT_TYPE_KMC,
33fcf5ef2aSThomas Huth S390_FEAT_TYPE_KM,
34fcf5ef2aSThomas Huth S390_FEAT_TYPE_KIMD,
35fcf5ef2aSThomas Huth S390_FEAT_TYPE_KLMD,
36fcf5ef2aSThomas Huth S390_FEAT_TYPE_PCKMO,
37fcf5ef2aSThomas Huth S390_FEAT_TYPE_KMCTR,
38fcf5ef2aSThomas Huth S390_FEAT_TYPE_KMF,
39fcf5ef2aSThomas Huth S390_FEAT_TYPE_KMO,
40fcf5ef2aSThomas Huth S390_FEAT_TYPE_PCC,
41fcf5ef2aSThomas Huth S390_FEAT_TYPE_PPNO,
426da5c593SJason J. Herne S390_FEAT_TYPE_KMA,
435dacbe23SChristian Borntraeger S390_FEAT_TYPE_KDSA,
44d220fabfSChristian Borntraeger S390_FEAT_TYPE_SORTL,
45afc7b866SChristian Borntraeger S390_FEAT_TYPE_DFLTCC,
465ac95151SSteffen Eiden S390_FEAT_TYPE_UV_FEAT_GUEST,
47fcf5ef2aSThomas Huth } S390FeatType;
48fcf5ef2aSThomas Huth
49fcf5ef2aSThomas Huth /* Definition of a CPU feature */
50fcf5ef2aSThomas Huth typedef struct {
51fcf5ef2aSThomas Huth const char *name; /* name exposed to the user */
52fcf5ef2aSThomas Huth const char *desc; /* description exposed to the user */
53fcf5ef2aSThomas Huth S390FeatType type; /* feature type (way of indication)*/
54fcf5ef2aSThomas Huth int bit; /* bit within the feature type area (fixed) */
55fcf5ef2aSThomas Huth } S390FeatDef;
56fcf5ef2aSThomas Huth
57fcf5ef2aSThomas Huth /* use ordinary bitmap operations to work with features */
58fcf5ef2aSThomas Huth typedef unsigned long S390FeatBitmap[BITS_TO_LONGS(S390_FEAT_MAX)];
59fcf5ef2aSThomas Huth
60fcf5ef2aSThomas Huth /* 64bit based bitmap used to init S390FeatBitmap from generated data */
61fcf5ef2aSThomas Huth typedef uint64_t S390FeatInit[S390_FEAT_MAX / 64 + 1];
62fcf5ef2aSThomas Huth
63fcf5ef2aSThomas Huth const S390FeatDef *s390_feat_def(S390Feat feat);
64fcf5ef2aSThomas Huth S390Feat s390_feat_by_type_and_bit(S390FeatType type, int bit);
65fcf5ef2aSThomas Huth void s390_init_feat_bitmap(const S390FeatInit init, S390FeatBitmap bitmap);
66fcf5ef2aSThomas Huth void s390_fill_feat_block(const S390FeatBitmap features, S390FeatType type,
67fcf5ef2aSThomas Huth uint8_t *data);
68fcf5ef2aSThomas Huth void s390_add_from_feat_block(S390FeatBitmap features, S390FeatType type,
69fcf5ef2aSThomas Huth uint8_t *data);
70fcf5ef2aSThomas Huth void s390_feat_bitmap_to_ascii(const S390FeatBitmap features, void *opaque,
71fcf5ef2aSThomas Huth void (*fn)(const char *name, void *opaque));
72*8aa2211eSCollin Walling void s390_get_deprecated_features(S390FeatBitmap features);
73fcf5ef2aSThomas Huth
74fcf5ef2aSThomas Huth /* Definition of a CPU feature group */
75fcf5ef2aSThomas Huth typedef struct {
76fcf5ef2aSThomas Huth const char *name; /* name exposed to the user */
77fcf5ef2aSThomas Huth const char *desc; /* description exposed to the user */
78fcf5ef2aSThomas Huth S390FeatBitmap feat; /* features contained in the group */
79fcf5ef2aSThomas Huth S390FeatInit init; /* used to init feat from generated data */
80fcf5ef2aSThomas Huth } S390FeatGroupDef;
81fcf5ef2aSThomas Huth
82fcf5ef2aSThomas Huth const S390FeatGroupDef *s390_feat_group_def(S390FeatGroup group);
83fcf5ef2aSThomas Huth
84fcf5ef2aSThomas Huth #define BE_BIT_NR(BIT) (BIT ^ (BITS_PER_LONG - 1))
85fcf5ef2aSThomas Huth
clear_be_bit(unsigned int bit_nr,uint8_t * array)863ded270aSJanosch Frank static inline void clear_be_bit(unsigned int bit_nr, uint8_t *array)
873ded270aSJanosch Frank {
883ded270aSJanosch Frank array[bit_nr / 8] &= ~(0x80 >> (bit_nr % 8));
893ded270aSJanosch Frank }
set_be_bit(unsigned int bit_nr,uint8_t * array)903d1cfc3cSDavid Hildenbrand static inline void set_be_bit(unsigned int bit_nr, uint8_t *array)
913d1cfc3cSDavid Hildenbrand {
923d1cfc3cSDavid Hildenbrand array[bit_nr / 8] |= 0x80 >> (bit_nr % 8);
933d1cfc3cSDavid Hildenbrand }
test_be_bit(unsigned int bit_nr,const uint8_t * array)943d1cfc3cSDavid Hildenbrand static inline bool test_be_bit(unsigned int bit_nr, const uint8_t *array)
953d1cfc3cSDavid Hildenbrand {
963d1cfc3cSDavid Hildenbrand return array[bit_nr / 8] & (0x80 >> (bit_nr % 8));
973d1cfc3cSDavid Hildenbrand }
98fcf5ef2aSThomas Huth #endif /* TARGET_S390X_CPU_FEATURES_H */
99