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" 19a5f9ecc4SMichael Mueller #include "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, 2678241744SMichael Mueller S390_FEAT_TYPE_SCLP_CPU, 2778241744SMichael Mueller S390_FEAT_TYPE_MISC, 2878241744SMichael Mueller S390_FEAT_TYPE_PLO, 2978241744SMichael Mueller S390_FEAT_TYPE_PTFF, 3078241744SMichael Mueller S390_FEAT_TYPE_KMAC, 3178241744SMichael Mueller S390_FEAT_TYPE_KMC, 3278241744SMichael Mueller S390_FEAT_TYPE_KM, 3378241744SMichael Mueller S390_FEAT_TYPE_KIMD, 3478241744SMichael Mueller S390_FEAT_TYPE_KLMD, 3578241744SMichael Mueller S390_FEAT_TYPE_PCKMO, 3678241744SMichael Mueller S390_FEAT_TYPE_KMCTR, 3778241744SMichael Mueller S390_FEAT_TYPE_KMF, 3878241744SMichael Mueller S390_FEAT_TYPE_KMO, 3978241744SMichael Mueller S390_FEAT_TYPE_PCC, 4078241744SMichael Mueller S390_FEAT_TYPE_PPNO, 416da5c593SJason J. Herne S390_FEAT_TYPE_KMA, 425dacbe23SChristian Borntraeger S390_FEAT_TYPE_KDSA, 43d220fabfSChristian Borntraeger S390_FEAT_TYPE_SORTL, 44*afc7b866SChristian Borntraeger S390_FEAT_TYPE_DFLTCC, 4578241744SMichael Mueller } S390FeatType; 4678241744SMichael Mueller 4778241744SMichael Mueller /* Definition of a CPU feature */ 4878241744SMichael Mueller typedef struct { 4978241744SMichael Mueller const char *name; /* name exposed to the user */ 5078241744SMichael Mueller const char *desc; /* description exposed to the user */ 5178241744SMichael Mueller S390FeatType type; /* feature type (way of indication)*/ 5278241744SMichael Mueller int bit; /* bit within the feature type area (fixed) */ 5378241744SMichael Mueller } S390FeatDef; 5478241744SMichael Mueller 5578241744SMichael Mueller /* use ordinary bitmap operations to work with features */ 5678241744SMichael Mueller typedef unsigned long S390FeatBitmap[BITS_TO_LONGS(S390_FEAT_MAX)]; 5778241744SMichael Mueller 5878241744SMichael Mueller /* 64bit based bitmap used to init S390FeatBitmap from generated data */ 5978241744SMichael Mueller typedef uint64_t S390FeatInit[S390_FEAT_MAX / 64 + 1]; 6078241744SMichael Mueller 6178241744SMichael Mueller const S390FeatDef *s390_feat_def(S390Feat feat); 6278241744SMichael Mueller S390Feat s390_feat_by_type_and_bit(S390FeatType type, int bit); 6378241744SMichael Mueller void s390_init_feat_bitmap(const S390FeatInit init, S390FeatBitmap bitmap); 6478241744SMichael Mueller void s390_fill_feat_block(const S390FeatBitmap features, S390FeatType type, 6578241744SMichael Mueller uint8_t *data); 6678241744SMichael Mueller void s390_add_from_feat_block(S390FeatBitmap features, S390FeatType type, 6778241744SMichael Mueller uint8_t *data); 6878241744SMichael Mueller void s390_feat_bitmap_to_ascii(const S390FeatBitmap features, void *opaque, 6978241744SMichael Mueller void (*fn)(const char *name, void *opaque)); 7078241744SMichael Mueller 718b3d6cb1SDavid Hildenbrand /* Definition of a CPU feature group */ 728b3d6cb1SDavid Hildenbrand typedef struct { 738b3d6cb1SDavid Hildenbrand const char *name; /* name exposed to the user */ 748b3d6cb1SDavid Hildenbrand const char *desc; /* description exposed to the user */ 758b3d6cb1SDavid Hildenbrand S390FeatBitmap feat; /* features contained in the group */ 768b3d6cb1SDavid Hildenbrand S390FeatInit init; /* used to init feat from generated data */ 778b3d6cb1SDavid Hildenbrand } S390FeatGroupDef; 788b3d6cb1SDavid Hildenbrand 798b3d6cb1SDavid Hildenbrand const S390FeatGroupDef *s390_feat_group_def(S390FeatGroup group); 808b3d6cb1SDavid Hildenbrand 8178241744SMichael Mueller #define BE_BIT_NR(BIT) (BIT ^ (BITS_PER_LONG - 1)) 8278241744SMichael Mueller 833d1cfc3cSDavid Hildenbrand static inline void set_be_bit(unsigned int bit_nr, uint8_t *array) 843d1cfc3cSDavid Hildenbrand { 853d1cfc3cSDavid Hildenbrand array[bit_nr / 8] |= 0x80 >> (bit_nr % 8); 863d1cfc3cSDavid Hildenbrand } 873d1cfc3cSDavid Hildenbrand static inline bool test_be_bit(unsigned int bit_nr, const uint8_t *array) 883d1cfc3cSDavid Hildenbrand { 893d1cfc3cSDavid Hildenbrand return array[bit_nr / 8] & (0x80 >> (bit_nr % 8)); 903d1cfc3cSDavid Hildenbrand } 9178241744SMichael Mueller #endif /* TARGET_S390X_CPU_FEATURES_H */ 92