| 1 | /* |
| 2 | * CPU features/facilities helper structs and utility functions for s390 |
| 3 | * |
| 4 | * Copyright 2016 IBM Corp. |
| 5 | * |
| 6 | * Author(s): Michael Mueller <mimu@linux.vnet.ibm.com> |
| 7 | * David Hildenbrand <dahi@linux.vnet.ibm.com> |
| 8 | * |
| 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 |
| 11 | * directory. |
| 12 | */ |
| 13 | |
| 14 | #ifndef TARGET_S390X_CPU_FEATURES_H |
| 15 | #define TARGET_S390X_CPU_FEATURES_H |
| 16 | |
| 17 | #include "qemu/bitmap.h" |
| 18 | #include "cpu_features_def.h" |
| 19 | #include "target/s390x/gen-features.h" |
| 20 | |
| 21 | /* CPU features are announced via different ways */ |
| 22 | typedef enum { |
| 23 | S390_FEAT_TYPE_STFL, |
| 24 | S390_FEAT_TYPE_SCLP_CONF_CHAR, |
| 25 | S390_FEAT_TYPE_SCLP_CONF_CHAR_EXT, |
| 26 | S390_FEAT_TYPE_SCLP_FAC134, |
| 27 | S390_FEAT_TYPE_SCLP_FAC_IPL, |
| 28 | S390_FEAT_TYPE_SCLP_FAC139, |
| 29 | S390_FEAT_TYPE_SCLP_CPU, |
| 30 | S390_FEAT_TYPE_MISC, |
| 31 | S390_FEAT_TYPE_PLO, |
| 32 | S390_FEAT_TYPE_PTFF, |
| 33 | S390_FEAT_TYPE_KMAC, |
| 34 | S390_FEAT_TYPE_KMC, |
| 35 | S390_FEAT_TYPE_KM, |
| 36 | S390_FEAT_TYPE_KIMD, |
| 37 | S390_FEAT_TYPE_KLMD, |
| 38 | S390_FEAT_TYPE_PCKMO, |
| 39 | S390_FEAT_TYPE_KMCTR, |
| 40 | S390_FEAT_TYPE_KMF, |
| 41 | S390_FEAT_TYPE_KMO, |
| 42 | S390_FEAT_TYPE_PCC, |
| 43 | S390_FEAT_TYPE_PPNO, |
| 44 | S390_FEAT_TYPE_KMA, |
| 45 | S390_FEAT_TYPE_KDSA, |
| 46 | S390_FEAT_TYPE_SORTL, |
| 47 | S390_FEAT_TYPE_DFLTCC, |
| 48 | S390_FEAT_TYPE_UV_FEAT_GUEST, |
| 49 | S390_FEAT_TYPE_PFCR, |
| 50 | } S390FeatType; |
| 51 | |
| 52 | /* Definition of a CPU feature */ |
| 53 | typedef struct { |
| 54 | const char *name; /* name exposed to the user */ |
| 55 | const char *desc; /* description exposed to the user */ |
| 56 | S390FeatType type; /* feature type (way of indication)*/ |
| 57 | int bit; /* bit within the feature type area (fixed) */ |
| 58 | } S390FeatDef; |
| 59 | |
| 60 | /* use ordinary bitmap operations to work with features */ |
| 61 | typedef unsigned long S390FeatBitmap[BITS_TO_LONGS(S390_FEAT_MAX)]; |
| 62 | |
| 63 | /* 64bit based bitmap used to init S390FeatBitmap from generated data */ |
| 64 | typedef uint64_t S390FeatInit[S390_FEAT_MAX / 64 + 1]; |
| 65 | |
| 66 | const S390FeatDef *s390_feat_def(S390Feat feat); |
| 67 | S390Feat s390_feat_by_type_and_bit(S390FeatType type, int bit); |
| 68 | void s390_init_feat_bitmap(const S390FeatInit init, S390FeatBitmap bitmap); |
| 69 | void s390_fill_feat_block(const S390FeatBitmap features, S390FeatType type, |
| 70 | uint8_t *data); |
| 71 | void s390_add_from_feat_block(S390FeatBitmap features, S390FeatType type, |
| 72 | uint8_t *data); |
| 73 | void s390_feat_bitmap_to_ascii(const S390FeatBitmap features, void *opaque, |
| 74 | void (*fn)(const char *name, void *opaque)); |
| 75 | void s390_get_deprecated_features(S390FeatBitmap features); |
| 76 | |
| 77 | /* Definition of a CPU feature group */ |
| 78 | typedef struct { |
| 79 | const char *name; /* name exposed to the user */ |
| 80 | const char *desc; /* description exposed to the user */ |
| 81 | S390FeatBitmap feat; /* features contained in the group */ |
| 82 | S390FeatInit init; /* used to init feat from generated data */ |
| 83 | } S390FeatGroupDef; |
| 84 | |
| 85 | const S390FeatGroupDef *s390_feat_group_def(S390FeatGroup group); |
| 86 | |
| 87 | #define BE_BIT_NR(BIT) (BIT ^ (BITS_PER_LONG - 1)) |
| 88 | |
| 89 | static inline void clear_be_bit(unsigned int bit_nr, uint8_t *array) |
| 90 | { |
| 91 | array[bit_nr / 8] &= ~(0x80 >> (bit_nr % 8)); |
| 92 | } |
| 93 | static inline void set_be_bit(unsigned int bit_nr, uint8_t *array) |
| 94 | { |
| 95 | array[bit_nr / 8] |= 0x80 >> (bit_nr % 8); |
| 96 | } |
| 97 | static inline bool test_be_bit(unsigned int bit_nr, const uint8_t *array) |
| 98 | { |
| 99 | return array[bit_nr / 8] & (0x80 >> (bit_nr % 8)); |
| 100 | } |
| 101 | #endif /* TARGET_S390X_CPU_FEATURES_H */ |