Merge branch 'work.ipc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[sfrench/cifs-2.6.git] / arch / s390 / tools / gen_facilities.c
1 /*
2  * Simple program to generate defines out of facility lists that use the bit
3  * numbering scheme from the Princples of Operations: most significant bit
4  * has bit number 0.
5  *
6  *    Copyright IBM Corp. 2015
7  *
8  */
9
10 #include <strings.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include <stdio.h>
14
15 struct facility_def {
16         char *name;
17         int *bits;
18 };
19
20 static struct facility_def facility_defs[] = {
21         {
22                 /*
23                  * FACILITIES_ALS contains the list of facilities that are
24                  * required to run a kernel that is compiled e.g. with
25                  * -march=<machine>.
26                  */
27                 .name = "FACILITIES_ALS",
28                 .bits = (int[]){
29 #ifdef CONFIG_HAVE_MARCH_Z900_FEATURES
30                         0,  /* N3 instructions */
31                         1,  /* z/Arch mode installed */
32 #endif
33 #ifdef CONFIG_HAVE_MARCH_Z990_FEATURES
34                         18, /* long displacement facility */
35 #endif
36 #ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
37                         21, /* extended-immediate facility */
38                         25, /* store clock fast */
39 #endif
40 #ifdef CONFIG_HAVE_MARCH_Z10_FEATURES
41                         27, /* mvcos */
42                         32, /* compare and swap and store */
43                         33, /* compare and swap and store 2 */
44                         34, /* general instructions extension */
45                         35, /* execute extensions */
46 #endif
47 #ifdef CONFIG_HAVE_MARCH_Z196_FEATURES
48                         45, /* fast-BCR, etc. */
49 #endif
50 #ifdef CONFIG_HAVE_MARCH_ZEC12_FEATURES
51                         49, /* misc-instruction-extensions */
52                         52, /* interlocked facility 2 */
53 #endif
54 #ifdef CONFIG_HAVE_MARCH_Z13_FEATURES
55                         53, /* load-and-zero-rightmost-byte, etc. */
56 #endif
57 #ifdef CONFIG_HAVE_MARCH_Z14_FEATURES
58                         58, /* miscellaneous-instruction-extension 2 */
59 #endif
60                         -1 /* END */
61                 }
62         },
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                         -1  /* END */
89                 }
90         },
91 };
92
93 static void print_facility_list(struct facility_def *def)
94 {
95         unsigned int high, bit, dword, i;
96         unsigned long long *array;
97
98         array = calloc(1, 8);
99         if (!array)
100                 exit(EXIT_FAILURE);
101         high = 0;
102         for (i = 0; def->bits[i] != -1; i++) {
103                 bit = 63 - (def->bits[i] & 63);
104                 dword = def->bits[i] / 64;
105                 if (dword > high) {
106                         array = realloc(array, (dword + 1) * 8);
107                         if (!array)
108                                 exit(EXIT_FAILURE);
109                         memset(array + high + 1, 0, (dword - high) * 8);
110                         high = dword;
111                 }
112                 array[dword] |= 1ULL << bit;
113         }
114         printf("#define %s ", def->name);
115         for (i = 0; i <= high; i++)
116                 printf("_AC(0x%016llx,UL)%c", array[i], i < high ? ',' : '\n');
117         free(array);
118 }
119
120 static void print_facility_lists(void)
121 {
122         unsigned int i;
123
124         for (i = 0; i < sizeof(facility_defs) / sizeof(facility_defs[0]); i++)
125                 print_facility_list(&facility_defs[i]);
126 }
127
128 int main(int argc, char **argv)
129 {
130         printf("#ifndef __ASM_S390_FACILITIES__\n");
131         printf("#define __ASM_S390_FACILITIES__\n");
132         printf("/*\n");
133         printf(" * DO NOT MODIFY.\n");
134         printf(" *\n");
135         printf(" * This file was generated by %s\n", __FILE__);
136         printf(" */\n\n");
137         printf("#include <linux/const.h>\n\n");
138         print_facility_lists();
139         printf("\n#endif\n");
140         return 0;
141 }