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