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