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