1 /* 2 * Simple program to generate defines out of facility lists that use the bit 3 * numbering scheme from the Princples of Operations: most significant bit 4 * has bit number 0. 5 * 6 * Copyright IBM Corp. 2015 7 * 8 */ 9 10 #include <strings.h> 11 #include <string.h> 12 #include <stdlib.h> 13 #include <stdio.h> 14 15 struct facility_def { 16 char *name; 17 int *bits; 18 }; 19 20 static struct facility_def facility_defs[] = { 21 { 22 /* 23 * FACILITIES_ALS contains the list of facilities that are 24 * required to run a kernel that is compiled e.g. with 25 * -march=<machine>. 26 */ 27 .name = "FACILITIES_ALS", 28 .bits = (int[]){ 29 #ifdef CONFIG_HAVE_MARCH_Z900_FEATURES 30 0, /* N3 instructions */ 31 1, /* z/Arch mode installed */ 32 #endif 33 #ifdef CONFIG_HAVE_MARCH_Z990_FEATURES 34 18, /* long displacement facility */ 35 #endif 36 #ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES 37 21, /* extended-immediate facility */ 38 25, /* store clock fast */ 39 #endif 40 #ifdef CONFIG_HAVE_MARCH_Z10_FEATURES 41 27, /* mvcos */ 42 32, /* compare and swap and store */ 43 33, /* compare and swap and store 2 */ 44 34, /* general extension facility */ 45 35, /* execute extensions */ 46 #endif 47 #ifdef CONFIG_HAVE_MARCH_Z196_FEATURES 48 45, /* fast-BCR, etc. */ 49 #endif 50 #ifdef CONFIG_HAVE_MARCH_ZEC12_FEATURES 51 49, /* misc-instruction-extensions */ 52 52, /* interlocked facility 2 */ 53 #endif 54 #ifdef CONFIG_HAVE_MARCH_Z13_FEATURES 55 53, /* load-and-zero-rightmost-byte, etc. */ 56 #endif 57 -1 /* END */ 58 } 59 }, 60 { 61 .name = "FACILITIES_KVM", 62 .bits = (int[]){ 63 0, /* N3 instructions */ 64 1, /* z/Arch mode installed */ 65 2, /* z/Arch mode active */ 66 3, /* DAT-enhancement */ 67 4, /* idte segment table */ 68 5, /* idte region table */ 69 6, /* ASN-and-LX reuse */ 70 7, /* stfle */ 71 8, /* enhanced-DAT 1 */ 72 9, /* sense-running-status */ 73 10, /* conditional sske */ 74 13, /* ipte-range */ 75 14, /* nonquiescing key-setting */ 76 73, /* transactional execution */ 77 75, /* access-exception-fetch/store indication */ 78 76, /* msa extension 3 */ 79 77, /* msa extension 4 */ 80 78, /* enhanced-DAT 2 */ 81 130, /* instruction-execution-protection */ 82 131, /* enhanced-SOP 2 and side-effect */ 83 146, /* msa extension 8 */ 84 -1 /* END */ 85 } 86 }, 87 }; 88 89 static void print_facility_list(struct facility_def *def) 90 { 91 unsigned int high, bit, dword, i; 92 unsigned long long *array; 93 94 array = calloc(1, 8); 95 if (!array) 96 exit(EXIT_FAILURE); 97 high = 0; 98 for (i = 0; def->bits[i] != -1; i++) { 99 bit = 63 - (def->bits[i] & 63); 100 dword = def->bits[i] / 64; 101 if (dword > high) { 102 array = realloc(array, (dword + 1) * 8); 103 if (!array) 104 exit(EXIT_FAILURE); 105 memset(array + high + 1, 0, (dword - high) * 8); 106 high = dword; 107 } 108 array[dword] |= 1ULL << bit; 109 } 110 printf("#define %s ", def->name); 111 for (i = 0; i <= high; i++) 112 printf("_AC(0x%016llx,UL)%c", array[i], i < high ? ',' : '\n'); 113 free(array); 114 } 115 116 static void print_facility_lists(void) 117 { 118 unsigned int i; 119 120 for (i = 0; i < sizeof(facility_defs) / sizeof(facility_defs[0]); i++) 121 print_facility_list(&facility_defs[i]); 122 } 123 124 int main(int argc, char **argv) 125 { 126 printf("#ifndef __ASM_S390_FACILITIES__\n"); 127 printf("#define __ASM_S390_FACILITIES__\n"); 128 printf("/*\n"); 129 printf(" * DO NOT MODIFY.\n"); 130 printf(" *\n"); 131 printf(" * This file was generated by %s\n", __FILE__); 132 printf(" */\n\n"); 133 printf("#include <linux/const.h>\n\n"); 134 print_facility_lists(); 135 printf("\n#endif\n"); 136 return 0; 137 } 138