gen_facilities.c 4.2 KB

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