Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Heiko Carstens | c30f682 | 2015-02-02 07:08:44 +0100 | [diff] [blame] | 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 | * |
Christian Borntraeger | a3da7b4 | 2018-03-08 16:08:49 +0000 | [diff] [blame] | 7 | * Copyright IBM Corp. 2015, 2018 |
Heiko Carstens | c30f682 | 2015-02-02 07:08:44 +0100 | [diff] [blame] | 8 | * |
| 9 | */ |
| 10 | |
Heiko Carstens | c30f682 | 2015-02-02 07:08:44 +0100 | [diff] [blame] | 11 | #include <strings.h> |
| 12 | #include <string.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <stdio.h> |
Masahiro Yamada | d1f7e8f | 2016-11-06 12:45:28 +0900 | [diff] [blame] | 15 | |
| 16 | struct facility_def { |
| 17 | char *name; |
| 18 | int *bits; |
| 19 | }; |
| 20 | |
| 21 | static struct facility_def facility_defs[] = { |
| 22 | { |
| 23 | /* |
| 24 | * FACILITIES_ALS contains the list of facilities that are |
| 25 | * required to run a kernel that is compiled e.g. with |
| 26 | * -march=<machine>. |
| 27 | */ |
| 28 | .name = "FACILITIES_ALS", |
| 29 | .bits = (int[]){ |
| 30 | #ifdef CONFIG_HAVE_MARCH_Z900_FEATURES |
| 31 | 0, /* N3 instructions */ |
| 32 | 1, /* z/Arch mode installed */ |
| 33 | #endif |
| 34 | #ifdef CONFIG_HAVE_MARCH_Z990_FEATURES |
| 35 | 18, /* long displacement facility */ |
| 36 | #endif |
| 37 | #ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES |
Masahiro Yamada | d1f7e8f | 2016-11-06 12:45:28 +0900 | [diff] [blame] | 38 | 21, /* extended-immediate facility */ |
| 39 | 25, /* store clock fast */ |
| 40 | #endif |
| 41 | #ifdef CONFIG_HAVE_MARCH_Z10_FEATURES |
| 42 | 27, /* mvcos */ |
| 43 | 32, /* compare and swap and store */ |
| 44 | 33, /* compare and swap and store 2 */ |
Heiko Carstens | ba79441 | 2017-08-18 09:02:01 +0200 | [diff] [blame] | 45 | 34, /* general instructions extension */ |
Masahiro Yamada | d1f7e8f | 2016-11-06 12:45:28 +0900 | [diff] [blame] | 46 | 35, /* execute extensions */ |
| 47 | #endif |
| 48 | #ifdef CONFIG_HAVE_MARCH_Z196_FEATURES |
| 49 | 45, /* fast-BCR, etc. */ |
| 50 | #endif |
| 51 | #ifdef CONFIG_HAVE_MARCH_ZEC12_FEATURES |
| 52 | 49, /* misc-instruction-extensions */ |
| 53 | 52, /* interlocked facility 2 */ |
| 54 | #endif |
| 55 | #ifdef CONFIG_HAVE_MARCH_Z13_FEATURES |
| 56 | 53, /* load-and-zero-rightmost-byte, etc. */ |
| 57 | #endif |
Martin Schwidefsky | 6997c32 | 2017-04-12 14:17:25 +0200 | [diff] [blame] | 58 | #ifdef CONFIG_HAVE_MARCH_Z14_FEATURES |
| 59 | 58, /* miscellaneous-instruction-extension 2 */ |
| 60 | #endif |
Martin Schwidefsky | a0e2251 | 2019-02-06 08:22:11 +0100 | [diff] [blame] | 61 | #ifdef CONFIG_HAVE_MARCH_Z15_FEATURES |
| 62 | 61, /* miscellaneous-instruction-extension 3 */ |
| 63 | #endif |
Masahiro Yamada | d1f7e8f | 2016-11-06 12:45:28 +0900 | [diff] [blame] | 64 | -1 /* END */ |
| 65 | } |
| 66 | }, |
| 67 | { |
Christian Borntraeger | c3b9e3e | 2018-02-09 16:26:29 +0000 | [diff] [blame] | 68 | /* |
| 69 | * FACILITIES_KVM contains the list of facilities that are part |
| 70 | * of the default facility mask and list that are passed to the |
| 71 | * initial CPU model. If no CPU model is used, this, together |
| 72 | * with the non-hypervisor managed bits, is the maximum list of |
| 73 | * guest facilities supported by KVM. |
| 74 | */ |
Masahiro Yamada | d1f7e8f | 2016-11-06 12:45:28 +0900 | [diff] [blame] | 75 | .name = "FACILITIES_KVM", |
| 76 | .bits = (int[]){ |
| 77 | 0, /* N3 instructions */ |
| 78 | 1, /* z/Arch mode installed */ |
| 79 | 2, /* z/Arch mode active */ |
| 80 | 3, /* DAT-enhancement */ |
| 81 | 4, /* idte segment table */ |
| 82 | 5, /* idte region table */ |
| 83 | 6, /* ASN-and-LX reuse */ |
| 84 | 7, /* stfle */ |
| 85 | 8, /* enhanced-DAT 1 */ |
| 86 | 9, /* sense-running-status */ |
| 87 | 10, /* conditional sske */ |
| 88 | 13, /* ipte-range */ |
| 89 | 14, /* nonquiescing key-setting */ |
| 90 | 73, /* transactional execution */ |
| 91 | 75, /* access-exception-fetch/store indication */ |
| 92 | 76, /* msa extension 3 */ |
| 93 | 77, /* msa extension 4 */ |
| 94 | 78, /* enhanced-DAT 2 */ |
Janosch Frank | cd1836f | 2016-08-04 09:57:36 +0200 | [diff] [blame] | 95 | 130, /* instruction-execution-protection */ |
Christian Borntraeger | a679c54 | 2016-12-15 15:58:14 +0100 | [diff] [blame] | 96 | 131, /* enhanced-SOP 2 and side-effect */ |
Collin L. Walling | 8fa1696 | 2016-07-26 15:29:44 -0400 | [diff] [blame] | 97 | 139, /* multiple epoch facility */ |
Jason J. Herne | e000b8e | 2017-03-20 09:57:42 -0400 | [diff] [blame] | 98 | 146, /* msa extension 8 */ |
Christian Borntraeger | 173aec2 | 2018-12-28 10:59:06 +0100 | [diff] [blame] | 99 | 150, /* enhanced sort */ |
Christian Borntraeger | 4f45b90 | 2018-12-28 10:46:04 +0100 | [diff] [blame] | 100 | 151, /* deflate conversion */ |
Christian Borntraeger | 13209ad | 2018-12-28 09:33:35 +0100 | [diff] [blame] | 101 | 155, /* msa extension 9 */ |
Masahiro Yamada | d1f7e8f | 2016-11-06 12:45:28 +0900 | [diff] [blame] | 102 | -1 /* END */ |
| 103 | } |
| 104 | }, |
Christian Borntraeger | c3b9e3e | 2018-02-09 16:26:29 +0000 | [diff] [blame] | 105 | { |
| 106 | /* |
| 107 | * FACILITIES_KVM_CPUMODEL contains the list of facilities |
| 108 | * that can be enabled by CPU model code if the host supports |
| 109 | * it. These facilities are not passed to the guest without |
| 110 | * CPU model support. |
| 111 | */ |
| 112 | |
| 113 | .name = "FACILITIES_KVM_CPUMODEL", |
| 114 | .bits = (int[]){ |
Tony Krowiak | 112c24d | 2018-09-25 19:16:40 -0400 | [diff] [blame] | 115 | 12, /* AP Query Configuration Information */ |
| 116 | 15, /* AP Facilities Test */ |
Christian Borntraeger | a3da7b4 | 2018-03-08 16:08:49 +0000 | [diff] [blame] | 117 | 156, /* etoken facility */ |
Christian Borntraeger | a3efa84 | 2021-03-09 16:24:19 +0100 | [diff] [blame] | 118 | 165, /* nnpa facility */ |
| 119 | 193, /* bear enhancement facility */ |
| 120 | 194, /* rdp enhancement facility */ |
| 121 | 196, /* processor activity instrumentation facility */ |
Christian Borntraeger | c3b9e3e | 2018-02-09 16:26:29 +0000 | [diff] [blame] | 122 | -1 /* END */ |
| 123 | } |
| 124 | }, |
Masahiro Yamada | d1f7e8f | 2016-11-06 12:45:28 +0900 | [diff] [blame] | 125 | }; |
Heiko Carstens | c30f682 | 2015-02-02 07:08:44 +0100 | [diff] [blame] | 126 | |
| 127 | static void print_facility_list(struct facility_def *def) |
| 128 | { |
| 129 | unsigned int high, bit, dword, i; |
| 130 | unsigned long long *array; |
| 131 | |
| 132 | array = calloc(1, 8); |
| 133 | if (!array) |
| 134 | exit(EXIT_FAILURE); |
| 135 | high = 0; |
| 136 | for (i = 0; def->bits[i] != -1; i++) { |
| 137 | bit = 63 - (def->bits[i] & 63); |
| 138 | dword = def->bits[i] / 64; |
| 139 | if (dword > high) { |
| 140 | array = realloc(array, (dword + 1) * 8); |
| 141 | if (!array) |
| 142 | exit(EXIT_FAILURE); |
| 143 | memset(array + high + 1, 0, (dword - high) * 8); |
| 144 | high = dword; |
| 145 | } |
| 146 | array[dword] |= 1ULL << bit; |
| 147 | } |
| 148 | printf("#define %s ", def->name); |
| 149 | for (i = 0; i <= high; i++) |
| 150 | printf("_AC(0x%016llx,UL)%c", array[i], i < high ? ',' : '\n'); |
Heiko Carstens | c30f682 | 2015-02-02 07:08:44 +0100 | [diff] [blame] | 151 | free(array); |
| 152 | } |
| 153 | |
| 154 | static void print_facility_lists(void) |
| 155 | { |
| 156 | unsigned int i; |
| 157 | |
| 158 | for (i = 0; i < sizeof(facility_defs) / sizeof(facility_defs[0]); i++) |
| 159 | print_facility_list(&facility_defs[i]); |
| 160 | } |
| 161 | |
| 162 | int main(int argc, char **argv) |
| 163 | { |
Hendrik Brueckner | 7fbf831 | 2018-01-11 12:13:18 +0100 | [diff] [blame] | 164 | printf("#ifndef __ASM_S390_FACILITY_DEFS__\n"); |
| 165 | printf("#define __ASM_S390_FACILITY_DEFS__\n"); |
Heiko Carstens | c30f682 | 2015-02-02 07:08:44 +0100 | [diff] [blame] | 166 | printf("/*\n"); |
| 167 | printf(" * DO NOT MODIFY.\n"); |
| 168 | printf(" *\n"); |
| 169 | printf(" * This file was generated by %s\n", __FILE__); |
| 170 | printf(" */\n\n"); |
| 171 | printf("#include <linux/const.h>\n\n"); |
| 172 | print_facility_lists(); |
| 173 | printf("\n#endif\n"); |
| 174 | return 0; |
| 175 | } |