xref: /linux/arch/s390/tools/gen_facilities.c (revision a679c547d19ded9b7d1a88e17cf5e5b69ac619b6)
1c30f6828SHeiko Carstens /*
2c30f6828SHeiko Carstens  * Simple program to generate defines out of facility lists that use the bit
3c30f6828SHeiko Carstens  * numbering scheme from the Princples of Operations: most significant bit
4c30f6828SHeiko Carstens  * has bit number 0.
5c30f6828SHeiko Carstens  *
6c30f6828SHeiko Carstens  *    Copyright IBM Corp. 2015
7c30f6828SHeiko Carstens  *
8c30f6828SHeiko Carstens  */
9c30f6828SHeiko Carstens 
10c30f6828SHeiko Carstens #include <strings.h>
11c30f6828SHeiko Carstens #include <string.h>
12c30f6828SHeiko Carstens #include <stdlib.h>
13c30f6828SHeiko Carstens #include <stdio.h>
14d1f7e8f8SMasahiro Yamada 
15d1f7e8f8SMasahiro Yamada struct facility_def {
16d1f7e8f8SMasahiro Yamada 	char *name;
17d1f7e8f8SMasahiro Yamada 	int *bits;
18d1f7e8f8SMasahiro Yamada };
19d1f7e8f8SMasahiro Yamada 
20d1f7e8f8SMasahiro Yamada static struct facility_def facility_defs[] = {
21d1f7e8f8SMasahiro Yamada 	{
22d1f7e8f8SMasahiro Yamada 		/*
23d1f7e8f8SMasahiro Yamada 		 * FACILITIES_ALS contains the list of facilities that are
24d1f7e8f8SMasahiro Yamada 		 * required to run a kernel that is compiled e.g. with
25d1f7e8f8SMasahiro Yamada 		 * -march=<machine>.
26d1f7e8f8SMasahiro Yamada 		 */
27d1f7e8f8SMasahiro Yamada 		.name = "FACILITIES_ALS",
28d1f7e8f8SMasahiro Yamada 		.bits = (int[]){
29d1f7e8f8SMasahiro Yamada #ifdef CONFIG_HAVE_MARCH_Z900_FEATURES
30d1f7e8f8SMasahiro Yamada 			0,  /* N3 instructions */
31d1f7e8f8SMasahiro Yamada 			1,  /* z/Arch mode installed */
32d1f7e8f8SMasahiro Yamada #endif
33d1f7e8f8SMasahiro Yamada #ifdef CONFIG_HAVE_MARCH_Z990_FEATURES
34d1f7e8f8SMasahiro Yamada 			18, /* long displacement facility */
35d1f7e8f8SMasahiro Yamada #endif
36d1f7e8f8SMasahiro Yamada #ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
37d1f7e8f8SMasahiro Yamada 			7,  /* stfle */
38d1f7e8f8SMasahiro Yamada 			17, /* message security assist */
39d1f7e8f8SMasahiro Yamada 			21, /* extended-immediate facility */
40d1f7e8f8SMasahiro Yamada 			25, /* store clock fast */
41d1f7e8f8SMasahiro Yamada #endif
42d1f7e8f8SMasahiro Yamada #ifdef CONFIG_HAVE_MARCH_Z10_FEATURES
43d1f7e8f8SMasahiro Yamada 			27, /* mvcos */
44d1f7e8f8SMasahiro Yamada 			32, /* compare and swap and store */
45d1f7e8f8SMasahiro Yamada 			33, /* compare and swap and store 2 */
46d1f7e8f8SMasahiro Yamada 			34, /* general extension facility */
47d1f7e8f8SMasahiro Yamada 			35, /* execute extensions */
48d1f7e8f8SMasahiro Yamada #endif
49d1f7e8f8SMasahiro Yamada #ifdef CONFIG_HAVE_MARCH_Z196_FEATURES
50d1f7e8f8SMasahiro Yamada 			45, /* fast-BCR, etc. */
51d1f7e8f8SMasahiro Yamada #endif
52d1f7e8f8SMasahiro Yamada #ifdef CONFIG_HAVE_MARCH_ZEC12_FEATURES
53d1f7e8f8SMasahiro Yamada 			49, /* misc-instruction-extensions */
54d1f7e8f8SMasahiro Yamada 			52, /* interlocked facility 2 */
55d1f7e8f8SMasahiro Yamada #endif
56d1f7e8f8SMasahiro Yamada #ifdef CONFIG_HAVE_MARCH_Z13_FEATURES
57d1f7e8f8SMasahiro Yamada 			53, /* load-and-zero-rightmost-byte, etc. */
58d1f7e8f8SMasahiro Yamada #endif
59d1f7e8f8SMasahiro Yamada 			-1 /* END */
60d1f7e8f8SMasahiro Yamada 		}
61d1f7e8f8SMasahiro Yamada 	},
62d1f7e8f8SMasahiro Yamada 	{
63d1f7e8f8SMasahiro Yamada 		.name = "FACILITIES_KVM",
64d1f7e8f8SMasahiro Yamada 		.bits = (int[]){
65d1f7e8f8SMasahiro Yamada 			0,  /* N3 instructions */
66d1f7e8f8SMasahiro Yamada 			1,  /* z/Arch mode installed */
67d1f7e8f8SMasahiro Yamada 			2,  /* z/Arch mode active */
68d1f7e8f8SMasahiro Yamada 			3,  /* DAT-enhancement */
69d1f7e8f8SMasahiro Yamada 			4,  /* idte segment table */
70d1f7e8f8SMasahiro Yamada 			5,  /* idte region table */
71d1f7e8f8SMasahiro Yamada 			6,  /* ASN-and-LX reuse */
72d1f7e8f8SMasahiro Yamada 			7,  /* stfle */
73d1f7e8f8SMasahiro Yamada 			8,  /* enhanced-DAT 1 */
74d1f7e8f8SMasahiro Yamada 			9,  /* sense-running-status */
75d1f7e8f8SMasahiro Yamada 			10, /* conditional sske */
76d1f7e8f8SMasahiro Yamada 			13, /* ipte-range */
77d1f7e8f8SMasahiro Yamada 			14, /* nonquiescing key-setting */
78d1f7e8f8SMasahiro Yamada 			73, /* transactional execution */
79d1f7e8f8SMasahiro Yamada 			75, /* access-exception-fetch/store indication */
80d1f7e8f8SMasahiro Yamada 			76, /* msa extension 3 */
81d1f7e8f8SMasahiro Yamada 			77, /* msa extension 4 */
82d1f7e8f8SMasahiro Yamada 			78, /* enhanced-DAT 2 */
83*a679c547SChristian Borntraeger 			131, /* enhanced-SOP 2 and side-effect */
84d1f7e8f8SMasahiro Yamada 			-1  /* END */
85d1f7e8f8SMasahiro Yamada 		}
86d1f7e8f8SMasahiro Yamada 	},
87d1f7e8f8SMasahiro Yamada };
88c30f6828SHeiko Carstens 
89c30f6828SHeiko Carstens static void print_facility_list(struct facility_def *def)
90c30f6828SHeiko Carstens {
91c30f6828SHeiko Carstens 	unsigned int high, bit, dword, i;
92c30f6828SHeiko Carstens 	unsigned long long *array;
93c30f6828SHeiko Carstens 
94c30f6828SHeiko Carstens 	array = calloc(1, 8);
95c30f6828SHeiko Carstens 	if (!array)
96c30f6828SHeiko Carstens 		exit(EXIT_FAILURE);
97c30f6828SHeiko Carstens 	high = 0;
98c30f6828SHeiko Carstens 	for (i = 0; def->bits[i] != -1; i++) {
99c30f6828SHeiko Carstens 		bit = 63 - (def->bits[i] & 63);
100c30f6828SHeiko Carstens 		dword = def->bits[i] / 64;
101c30f6828SHeiko Carstens 		if (dword > high) {
102c30f6828SHeiko Carstens 			array = realloc(array, (dword + 1) * 8);
103c30f6828SHeiko Carstens 			if (!array)
104c30f6828SHeiko Carstens 				exit(EXIT_FAILURE);
105c30f6828SHeiko Carstens 			memset(array + high + 1, 0, (dword - high) * 8);
106c30f6828SHeiko Carstens 			high = dword;
107c30f6828SHeiko Carstens 		}
108c30f6828SHeiko Carstens 		array[dword] |= 1ULL << bit;
109c30f6828SHeiko Carstens 	}
110c30f6828SHeiko Carstens 	printf("#define %s ", def->name);
111c30f6828SHeiko Carstens 	for (i = 0; i <= high; i++)
112c30f6828SHeiko Carstens 		printf("_AC(0x%016llx,UL)%c", array[i], i < high ? ',' : '\n');
113c30f6828SHeiko Carstens 	free(array);
114c30f6828SHeiko Carstens }
115c30f6828SHeiko Carstens 
116c30f6828SHeiko Carstens static void print_facility_lists(void)
117c30f6828SHeiko Carstens {
118c30f6828SHeiko Carstens 	unsigned int i;
119c30f6828SHeiko Carstens 
120c30f6828SHeiko Carstens 	for (i = 0; i < sizeof(facility_defs) / sizeof(facility_defs[0]); i++)
121c30f6828SHeiko Carstens 		print_facility_list(&facility_defs[i]);
122c30f6828SHeiko Carstens }
123c30f6828SHeiko Carstens 
124c30f6828SHeiko Carstens int main(int argc, char **argv)
125c30f6828SHeiko Carstens {
126c30f6828SHeiko Carstens 	printf("#ifndef __ASM_S390_FACILITIES__\n");
127c30f6828SHeiko Carstens 	printf("#define __ASM_S390_FACILITIES__\n");
128c30f6828SHeiko Carstens 	printf("/*\n");
129c30f6828SHeiko Carstens 	printf(" * DO NOT MODIFY.\n");
130c30f6828SHeiko Carstens 	printf(" *\n");
131c30f6828SHeiko Carstens 	printf(" * This file was generated by %s\n", __FILE__);
132c30f6828SHeiko Carstens 	printf(" */\n\n");
133c30f6828SHeiko Carstens 	printf("#include <linux/const.h>\n\n");
134c30f6828SHeiko Carstens 	print_facility_lists();
135c30f6828SHeiko Carstens 	printf("\n#endif\n");
136c30f6828SHeiko Carstens 	return 0;
137c30f6828SHeiko Carstens }
138