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" 1978241744SMichael Mueller 2078241744SMichael Mueller /* CPU features are announced via different ways */ 2178241744SMichael Mueller typedef enum { 2278241744SMichael Mueller S390_FEAT_TYPE_STFL, 2378241744SMichael Mueller S390_FEAT_TYPE_SCLP_CONF_CHAR, 2478241744SMichael Mueller S390_FEAT_TYPE_SCLP_CONF_CHAR_EXT, 2578241744SMichael Mueller S390_FEAT_TYPE_SCLP_CPU, 2678241744SMichael Mueller S390_FEAT_TYPE_MISC, 2778241744SMichael Mueller S390_FEAT_TYPE_PLO, 2878241744SMichael Mueller S390_FEAT_TYPE_PTFF, 2978241744SMichael Mueller S390_FEAT_TYPE_KMAC, 3078241744SMichael Mueller S390_FEAT_TYPE_KMC, 3178241744SMichael Mueller S390_FEAT_TYPE_KM, 3278241744SMichael Mueller S390_FEAT_TYPE_KIMD, 3378241744SMichael Mueller S390_FEAT_TYPE_KLMD, 3478241744SMichael Mueller S390_FEAT_TYPE_PCKMO, 3578241744SMichael Mueller S390_FEAT_TYPE_KMCTR, 3678241744SMichael Mueller S390_FEAT_TYPE_KMF, 3778241744SMichael Mueller S390_FEAT_TYPE_KMO, 3878241744SMichael Mueller S390_FEAT_TYPE_PCC, 3978241744SMichael Mueller S390_FEAT_TYPE_PPNO, 406da5c593SJason J. Herne S390_FEAT_TYPE_KMA, 4178241744SMichael Mueller } S390FeatType; 4278241744SMichael Mueller 4378241744SMichael Mueller /* Definition of a CPU feature */ 4478241744SMichael Mueller typedef struct { 4578241744SMichael Mueller const char *name; /* name exposed to the user */ 4678241744SMichael Mueller const char *desc; /* description exposed to the user */ 4778241744SMichael Mueller S390FeatType type; /* feature type (way of indication)*/ 4878241744SMichael Mueller int bit; /* bit within the feature type area (fixed) */ 4978241744SMichael Mueller } S390FeatDef; 5078241744SMichael Mueller 5178241744SMichael Mueller /* use ordinary bitmap operations to work with features */ 5278241744SMichael Mueller typedef unsigned long S390FeatBitmap[BITS_TO_LONGS(S390_FEAT_MAX)]; 5378241744SMichael Mueller 5478241744SMichael Mueller /* 64bit based bitmap used to init S390FeatBitmap from generated data */ 5578241744SMichael Mueller typedef uint64_t S390FeatInit[S390_FEAT_MAX / 64 + 1]; 5678241744SMichael Mueller 5778241744SMichael Mueller const S390FeatDef *s390_feat_def(S390Feat feat); 5878241744SMichael Mueller S390Feat s390_feat_by_type_and_bit(S390FeatType type, int bit); 5978241744SMichael Mueller void s390_init_feat_bitmap(const S390FeatInit init, S390FeatBitmap bitmap); 6078241744SMichael Mueller void s390_fill_feat_block(const S390FeatBitmap features, S390FeatType type, 6178241744SMichael Mueller uint8_t *data); 6278241744SMichael Mueller void s390_add_from_feat_block(S390FeatBitmap features, S390FeatType type, 6378241744SMichael Mueller uint8_t *data); 6478241744SMichael Mueller void s390_feat_bitmap_to_ascii(const S390FeatBitmap features, void *opaque, 6578241744SMichael Mueller void (*fn)(const char *name, void *opaque)); 6678241744SMichael Mueller 678b3d6cb1SDavid Hildenbrand /* static groups that will never change */ 688b3d6cb1SDavid Hildenbrand typedef enum { 698b3d6cb1SDavid Hildenbrand S390_FEAT_GROUP_PLO, 708b3d6cb1SDavid Hildenbrand S390_FEAT_GROUP_TOD_CLOCK_STEERING, 718b3d6cb1SDavid Hildenbrand S390_FEAT_GROUP_GEN13_PTFF_ENH, 728b3d6cb1SDavid Hildenbrand S390_FEAT_GROUP_MSA, 738b3d6cb1SDavid Hildenbrand S390_FEAT_GROUP_MSA_EXT_1, 748b3d6cb1SDavid Hildenbrand S390_FEAT_GROUP_MSA_EXT_2, 758b3d6cb1SDavid Hildenbrand S390_FEAT_GROUP_MSA_EXT_3, 768b3d6cb1SDavid Hildenbrand S390_FEAT_GROUP_MSA_EXT_4, 778b3d6cb1SDavid Hildenbrand S390_FEAT_GROUP_MSA_EXT_5, 786da5c593SJason J. Herne S390_FEAT_GROUP_MSA_EXT_6, 796da5c593SJason J. Herne S390_FEAT_GROUP_MSA_EXT_7, 806da5c593SJason J. Herne S390_FEAT_GROUP_MSA_EXT_8, 818b3d6cb1SDavid Hildenbrand S390_FEAT_GROUP_MAX, 828b3d6cb1SDavid Hildenbrand } S390FeatGroup; 838b3d6cb1SDavid Hildenbrand 848b3d6cb1SDavid Hildenbrand /* Definition of a CPU feature group */ 858b3d6cb1SDavid Hildenbrand typedef struct { 868b3d6cb1SDavid Hildenbrand const char *name; /* name exposed to the user */ 878b3d6cb1SDavid Hildenbrand const char *desc; /* description exposed to the user */ 888b3d6cb1SDavid Hildenbrand S390FeatBitmap feat; /* features contained in the group */ 898b3d6cb1SDavid Hildenbrand S390FeatInit init; /* used to init feat from generated data */ 908b3d6cb1SDavid Hildenbrand } S390FeatGroupDef; 918b3d6cb1SDavid Hildenbrand 928b3d6cb1SDavid Hildenbrand const S390FeatGroupDef *s390_feat_group_def(S390FeatGroup group); 938b3d6cb1SDavid Hildenbrand 9478241744SMichael Mueller #define BE_BIT_NR(BIT) (BIT ^ (BITS_PER_LONG - 1)) 9578241744SMichael Mueller 96*3d1cfc3cSDavid Hildenbrand static inline void set_be_bit(unsigned int bit_nr, uint8_t *array) 97*3d1cfc3cSDavid Hildenbrand { 98*3d1cfc3cSDavid Hildenbrand array[bit_nr / 8] |= 0x80 >> (bit_nr % 8); 99*3d1cfc3cSDavid Hildenbrand } 100*3d1cfc3cSDavid Hildenbrand static inline bool test_be_bit(unsigned int bit_nr, const uint8_t *array) 101*3d1cfc3cSDavid Hildenbrand { 102*3d1cfc3cSDavid Hildenbrand return array[bit_nr / 8] & (0x80 >> (bit_nr % 8)); 103*3d1cfc3cSDavid Hildenbrand } 10478241744SMichael Mueller #endif /* TARGET_S390X_CPU_FEATURES_H */ 105