178241744SMichael Mueller /* 278241744SMichael Mueller * CPU features/facilities helper structs and utility functions for s390 378241744SMichael Mueller * 478241744SMichael Mueller * Copyright 2016 IBM Corp. 578241744SMichael Mueller * 678241744SMichael Mueller * Author(s): Michael Mueller <mimu@linux.vnet.ibm.com> 778241744SMichael Mueller * David Hildenbrand <dahi@linux.vnet.ibm.com> 878241744SMichael Mueller * 978241744SMichael Mueller * This work is licensed under the terms of the GNU GPL, version 2 or (at 1078241744SMichael Mueller * your option) any later version. See the COPYING file in the top-level 1178241744SMichael Mueller * directory. 1278241744SMichael Mueller */ 1378241744SMichael Mueller 1478241744SMichael Mueller #ifndef TARGET_S390X_CPU_FEATURES_H 1578241744SMichael Mueller #define TARGET_S390X_CPU_FEATURES_H 1678241744SMichael Mueller 1778241744SMichael Mueller #include "qemu/bitmap.h" 1878241744SMichael Mueller #include "cpu_features_def.h" 19d3b18480SMarc-André Lureau #include "target/s390x/gen-features.h" 2078241744SMichael Mueller 2178241744SMichael Mueller /* CPU features are announced via different ways */ 2278241744SMichael Mueller typedef enum { 2378241744SMichael Mueller S390_FEAT_TYPE_STFL, 2478241744SMichael Mueller S390_FEAT_TYPE_SCLP_CONF_CHAR, 2578241744SMichael Mueller S390_FEAT_TYPE_SCLP_CONF_CHAR_EXT, 26fabdada9SCollin Walling S390_FEAT_TYPE_SCLP_FAC134, 2778241744SMichael Mueller S390_FEAT_TYPE_SCLP_CPU, 2878241744SMichael Mueller S390_FEAT_TYPE_MISC, 2978241744SMichael Mueller S390_FEAT_TYPE_PLO, 3078241744SMichael Mueller S390_FEAT_TYPE_PTFF, 3178241744SMichael Mueller S390_FEAT_TYPE_KMAC, 3278241744SMichael Mueller S390_FEAT_TYPE_KMC, 3378241744SMichael Mueller S390_FEAT_TYPE_KM, 3478241744SMichael Mueller S390_FEAT_TYPE_KIMD, 3578241744SMichael Mueller S390_FEAT_TYPE_KLMD, 3678241744SMichael Mueller S390_FEAT_TYPE_PCKMO, 3778241744SMichael Mueller S390_FEAT_TYPE_KMCTR, 3878241744SMichael Mueller S390_FEAT_TYPE_KMF, 3978241744SMichael Mueller S390_FEAT_TYPE_KMO, 4078241744SMichael Mueller S390_FEAT_TYPE_PCC, 4178241744SMichael Mueller 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, 4778241744SMichael Mueller } S390FeatType; 4878241744SMichael Mueller 4978241744SMichael Mueller /* Definition of a CPU feature */ 5078241744SMichael Mueller typedef struct { 5178241744SMichael Mueller const char *name; /* name exposed to the user */ 5278241744SMichael Mueller const char *desc; /* description exposed to the user */ 5378241744SMichael Mueller S390FeatType type; /* feature type (way of indication)*/ 5478241744SMichael Mueller int bit; /* bit within the feature type area (fixed) */ 5578241744SMichael Mueller } S390FeatDef; 5678241744SMichael Mueller 5778241744SMichael Mueller /* use ordinary bitmap operations to work with features */ 5878241744SMichael Mueller typedef unsigned long S390FeatBitmap[BITS_TO_LONGS(S390_FEAT_MAX)]; 5978241744SMichael Mueller 6078241744SMichael Mueller /* 64bit based bitmap used to init S390FeatBitmap from generated data */ 6178241744SMichael Mueller typedef uint64_t S390FeatInit[S390_FEAT_MAX / 64 + 1]; 6278241744SMichael Mueller 6378241744SMichael Mueller const S390FeatDef *s390_feat_def(S390Feat feat); 6478241744SMichael Mueller S390Feat s390_feat_by_type_and_bit(S390FeatType type, int bit); 6578241744SMichael Mueller void s390_init_feat_bitmap(const S390FeatInit init, S390FeatBitmap bitmap); 6678241744SMichael Mueller void s390_fill_feat_block(const S390FeatBitmap features, S390FeatType type, 6778241744SMichael Mueller uint8_t *data); 6878241744SMichael Mueller void s390_add_from_feat_block(S390FeatBitmap features, S390FeatType type, 6978241744SMichael Mueller uint8_t *data); 7078241744SMichael Mueller void s390_feat_bitmap_to_ascii(const S390FeatBitmap features, void *opaque, 7178241744SMichael Mueller void (*fn)(const char *name, void *opaque)); 72*8aa2211eSCollin Walling void s390_get_deprecated_features(S390FeatBitmap features); 7378241744SMichael Mueller 748b3d6cb1SDavid Hildenbrand /* Definition of a CPU feature group */ 758b3d6cb1SDavid Hildenbrand typedef struct { 768b3d6cb1SDavid Hildenbrand const char *name; /* name exposed to the user */ 778b3d6cb1SDavid Hildenbrand const char *desc; /* description exposed to the user */ 788b3d6cb1SDavid Hildenbrand S390FeatBitmap feat; /* features contained in the group */ 798b3d6cb1SDavid Hildenbrand S390FeatInit init; /* used to init feat from generated data */ 808b3d6cb1SDavid Hildenbrand } S390FeatGroupDef; 818b3d6cb1SDavid Hildenbrand 828b3d6cb1SDavid Hildenbrand const S390FeatGroupDef *s390_feat_group_def(S390FeatGroup group); 838b3d6cb1SDavid Hildenbrand 8478241744SMichael Mueller #define BE_BIT_NR(BIT) (BIT ^ (BITS_PER_LONG - 1)) 8578241744SMichael Mueller 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 } 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 } 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 } 9878241744SMichael Mueller #endif /* TARGET_S390X_CPU_FEATURES_H */ 99