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