gen_facilities.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Simple program to generate defines out of facility lists that use the bit
  4. * numbering scheme from the Princples of Operations: most significant bit
  5. * has bit number 0.
  6. *
  7. * Copyright IBM Corp. 2015, 2018
  8. *
  9. */
  10. #include <strings.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <stdio.h>
  14. struct facility_def {
  15. char *name;
  16. int *bits;
  17. };
  18. static struct facility_def facility_defs[] = {
  19. {
  20. /*
  21. * FACILITIES_ALS contains the list of facilities that are
  22. * required to run a kernel that is compiled e.g. with
  23. * -march=<machine>.
  24. */
  25. .name = "FACILITIES_ALS",
  26. .bits = (int[]){
  27. 0, /* N3 instructions */
  28. 1, /* z/Arch mode installed */
  29. 18, /* long displacement facility */
  30. 21, /* extended-immediate facility */
  31. 25, /* store clock fast */
  32. 27, /* mvcos */
  33. 32, /* compare and swap and store */
  34. 33, /* compare and swap and store 2 */
  35. 34, /* general instructions extension */
  36. 35, /* execute extensions */
  37. #ifdef CONFIG_HAVE_MARCH_Z196_FEATURES
  38. 45, /* fast-BCR, etc. */
  39. #endif
  40. #ifdef CONFIG_HAVE_MARCH_ZEC12_FEATURES
  41. 49, /* misc-instruction-extensions */
  42. 52, /* interlocked facility 2 */
  43. #endif
  44. #ifdef CONFIG_HAVE_MARCH_Z13_FEATURES
  45. 53, /* load-and-zero-rightmost-byte, etc. */
  46. #endif
  47. #ifdef CONFIG_HAVE_MARCH_Z14_FEATURES
  48. 58, /* miscellaneous-instruction-extension 2 */
  49. #endif
  50. #ifdef CONFIG_HAVE_MARCH_Z15_FEATURES
  51. 61, /* miscellaneous-instruction-extension 3 */
  52. #endif
  53. -1 /* END */
  54. }
  55. },
  56. {
  57. /*
  58. * FACILITIES_KVM contains the list of facilities that are part
  59. * of the default facility mask and list that are passed to the
  60. * initial CPU model. If no CPU model is used, this, together
  61. * with the non-hypervisor managed bits, is the maximum list of
  62. * guest facilities supported by KVM.
  63. */
  64. .name = "FACILITIES_KVM",
  65. .bits = (int[]){
  66. 0, /* N3 instructions */
  67. 1, /* z/Arch mode installed */
  68. 2, /* z/Arch mode active */
  69. 3, /* DAT-enhancement */
  70. 4, /* idte segment table */
  71. 5, /* idte region table */
  72. 6, /* ASN-and-LX reuse */
  73. 7, /* stfle */
  74. 8, /* enhanced-DAT 1 */
  75. 9, /* sense-running-status */
  76. 10, /* conditional sske */
  77. 13, /* ipte-range */
  78. 14, /* nonquiescing key-setting */
  79. 73, /* transactional execution */
  80. 75, /* access-exception-fetch/store indication */
  81. 76, /* msa extension 3 */
  82. 77, /* msa extension 4 */
  83. 78, /* enhanced-DAT 2 */
  84. 130, /* instruction-execution-protection */
  85. 131, /* enhanced-SOP 2 and side-effect */
  86. 139, /* multiple epoch facility */
  87. 146, /* msa extension 8 */
  88. 150, /* enhanced sort */
  89. 151, /* deflate conversion */
  90. 155, /* msa extension 9 */
  91. -1 /* END */
  92. }
  93. },
  94. {
  95. /*
  96. * FACILITIES_KVM_CPUMODEL contains the list of facilities
  97. * that can be enabled by CPU model code if the host supports
  98. * it. These facilities are not passed to the guest without
  99. * CPU model support.
  100. */
  101. .name = "FACILITIES_KVM_CPUMODEL",
  102. .bits = (int[]){
  103. 12, /* AP Query Configuration Information */
  104. 15, /* AP Facilities Test */
  105. 156, /* etoken facility */
  106. 165, /* nnpa facility */
  107. 193, /* bear enhancement facility */
  108. 194, /* rdp enhancement facility */
  109. 196, /* processor activity instrumentation facility */
  110. 197, /* processor activity instrumentation extension 1 */
  111. -1 /* END */
  112. }
  113. },
  114. };
  115. static void print_facility_list(struct facility_def *def)
  116. {
  117. unsigned int high, bit, dword, i;
  118. unsigned long long *array;
  119. array = calloc(1, 8);
  120. if (!array)
  121. exit(EXIT_FAILURE);
  122. high = 0;
  123. for (i = 0; def->bits[i] != -1; i++) {
  124. bit = 63 - (def->bits[i] & 63);
  125. dword = def->bits[i] / 64;
  126. if (dword > high) {
  127. array = realloc(array, (dword + 1) * 8);
  128. if (!array)
  129. exit(EXIT_FAILURE);
  130. memset(array + high + 1, 0, (dword - high) * 8);
  131. high = dword;
  132. }
  133. array[dword] |= 1ULL << bit;
  134. }
  135. printf("#define %s ", def->name);
  136. for (i = 0; i <= high; i++)
  137. printf("_AC(0x%016llx,UL)%c", array[i], i < high ? ',' : '\n');
  138. free(array);
  139. }
  140. static void print_facility_lists(void)
  141. {
  142. unsigned int i;
  143. for (i = 0; i < sizeof(facility_defs) / sizeof(facility_defs[0]); i++)
  144. print_facility_list(&facility_defs[i]);
  145. }
  146. int main(int argc, char **argv)
  147. {
  148. printf("#ifndef __ASM_S390_FACILITY_DEFS__\n");
  149. printf("#define __ASM_S390_FACILITY_DEFS__\n");
  150. printf("/*\n");
  151. printf(" * DO NOT MODIFY.\n");
  152. printf(" *\n");
  153. printf(" * This file was generated by %s\n", __FILE__);
  154. printf(" */\n\n");
  155. printf("#include <linux/const.h>\n\n");
  156. print_facility_lists();
  157. printf("\n#endif\n");
  158. return 0;
  159. }