aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHeiko Carstens <heiko.carstens@de.ibm.com>2015-02-02 01:08:44 -0500
committerMartin Schwidefsky <schwidefsky@de.ibm.com>2015-12-18 08:59:20 -0500
commitc30f6828fed9d33c2d54dfaf3621717c56f9c779 (patch)
tree70ceed0eaf29d2410f8ac06c999a53d62368a44b
parent76cdd44c2e56ffabc297494c090c6babc8985998 (diff)
s390/facilities: add helper tool to generate facility lists
Modifying the architecture level set facility lists was always very error prone. Given the numbering of the facility bits within the Principles of Operation, where the most significant bit number is 0, it happened a lot of times that wrong bits were set or cleared. Therefore this patch adds a tool "gen_facilities" which generates include/generated/facilites.h. The definition of the bits to be set is contained within arch/s390/include/asm/facilities_src.h and can be easily extended to e.g. also generate such lists for the KVM module. The generated file looks like this: #define FACILITIES_ALS _AC(0xc1006450f0040000,UL) #define FACILITIES_ALS_DWORDS 1 The facility bits defined in this patch match 1:1 to the current masks that can be found in head.S. That is if the tool gets executed with -march=z990 then the generated masks will equal the masks in head.S for CONFIG_MARCH_Z990. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
-rw-r--r--arch/s390/Makefile5
-rw-r--r--arch/s390/include/asm/facilities_src.h67
-rw-r--r--arch/s390/include/asm/facility.h5
-rw-r--r--arch/s390/tools/.gitignore1
-rw-r--r--arch/s390/tools/Makefile15
-rw-r--r--arch/s390/tools/gen_facilities.c67
6 files changed, 160 insertions, 0 deletions
diff --git a/arch/s390/Makefile b/arch/s390/Makefile
index 647bd14b223e..224b42734f0d 100644
--- a/arch/s390/Makefile
+++ b/arch/s390/Makefile
@@ -106,6 +106,7 @@ drivers-y += drivers/s390/
106drivers-$(CONFIG_OPROFILE) += arch/s390/oprofile/ 106drivers-$(CONFIG_OPROFILE) += arch/s390/oprofile/
107 107
108boot := arch/s390/boot 108boot := arch/s390/boot
109tools := arch/s390/tools
109 110
110all: image bzImage 111all: image bzImage
111 112
@@ -124,6 +125,10 @@ vdso_install:
124 125
125archclean: 126archclean:
126 $(Q)$(MAKE) $(clean)=$(boot) 127 $(Q)$(MAKE) $(clean)=$(boot)
128 $(Q)$(MAKE) $(clean)=$(tools)
129
130archprepare:
131 $(Q)$(MAKE) $(build)=$(tools) include/generated/facilities.h
127 132
128# Don't use tabs in echo arguments 133# Don't use tabs in echo arguments
129define archhelp 134define archhelp
diff --git a/arch/s390/include/asm/facilities_src.h b/arch/s390/include/asm/facilities_src.h
new file mode 100644
index 000000000000..4555fa69a29e
--- /dev/null
+++ b/arch/s390/include/asm/facilities_src.h
@@ -0,0 +1,67 @@
1/*
2 * Copyright IBM Corp. 2015
3 */
4
5#ifndef S390_GEN_FACILITIES_C
6#error "This file can only be included by gen_facilities.c"
7#endif
8
9#include <linux/kconfig.h>
10
11struct facility_def {
12 char *name;
13 int *bits;
14};
15
16static struct facility_def facility_defs[] = {
17 {
18 /*
19 * FACILITIES_ALS contains the list of facilities that are
20 * required to run a kernel that is compiled e.g. with
21 * -march=<machine>.
22 */
23 .name = "FACILITIES_ALS",
24 .bits = (int[]){
25#ifdef CONFIG_HAVE_MARCH_Z900_FEATURES
26 0, /* N3 instructions */
27 1, /* z/Arch mode installed */
28#endif
29#ifdef CONFIG_HAVE_MARCH_Z990_FEATURES
30 18, /* long displacement facility */
31#endif
32#ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
33 7, /* stfle */
34 16, /* extended translation facility 2 */
35 17, /* message security assist */
36 20, /* HFP-multiply-and-add */
37 21, /* extended-immediate facility */
38 22, /* extended-translation facility 3 */
39 23, /* HFP-unnormalized-extension */
40 24, /* ETF2-enhancement */
41 25, /* store clock fast */
42 30, /* ETF3-enhancement */
43#endif
44#ifdef CONFIG_HAVE_MARCH_Z10_FEATURES
45 26, /* parsing enhancement facility */
46 27, /* mvcos */
47 32, /* compare and swap and store */
48 33, /* compare and swap and store 2 */
49 34, /* general extension facility */
50 35, /* execute extensions */
51 41, /* floating point support enhancement */
52 42, /* DFP facility */
53 44, /* PFPO */
54#endif
55#ifdef CONFIG_HAVE_MARCH_Z196_FEATURES
56 37, /* floating point extension */
57 45, /* fast-BCR, etc. */
58#endif
59#ifdef CONFIG_HAVE_MARCH_ZEC12_FEATURES
60 48, /* decimal floating point zoned */
61 49, /* misc-instruction-extensions */
62 52, /* interlocked facility 2 */
63#endif
64 -1 /* END */
65 }
66 },
67};
diff --git a/arch/s390/include/asm/facility.h b/arch/s390/include/asm/facility.h
index b4f99d22ba04..007163f91856 100644
--- a/arch/s390/include/asm/facility.h
+++ b/arch/s390/include/asm/facility.h
@@ -7,6 +7,10 @@
7#ifndef __ASM_FACILITY_H 7#ifndef __ASM_FACILITY_H
8#define __ASM_FACILITY_H 8#define __ASM_FACILITY_H
9 9
10#include <generated/facilities.h>
11
12#ifndef __ASSEMBLY__
13
10#include <linux/string.h> 14#include <linux/string.h>
11#include <linux/preempt.h> 15#include <linux/preempt.h>
12#include <asm/lowcore.h> 16#include <asm/lowcore.h>
@@ -62,4 +66,5 @@ static inline void stfle(u64 *stfle_fac_list, int size)
62 preempt_enable(); 66 preempt_enable();
63} 67}
64 68
69#endif /* __ASSEMBLY__ */
65#endif /* __ASM_FACILITY_H */ 70#endif /* __ASM_FACILITY_H */
diff --git a/arch/s390/tools/.gitignore b/arch/s390/tools/.gitignore
new file mode 100644
index 000000000000..72a4b2cf1365
--- /dev/null
+++ b/arch/s390/tools/.gitignore
@@ -0,0 +1 @@
gen_facilities
diff --git a/arch/s390/tools/Makefile b/arch/s390/tools/Makefile
new file mode 100644
index 000000000000..6d9814c9df2b
--- /dev/null
+++ b/arch/s390/tools/Makefile
@@ -0,0 +1,15 @@
1#
2# Makefile for s390 specific build tools
3#
4
5hostprogs-y += gen_facilities
6HOSTCFLAGS_gen_facilities.o += -Wall $(LINUXINCLUDE)
7
8define filechk_facilities.h
9 $(obj)/gen_facilities
10endef
11
12$(obj)/gen_facilities.o: $(srctree)/arch/s390/tools/gen_facilities.c
13
14include/generated/facilities.h: $(obj)/gen_facilities FORCE
15 $(call filechk,facilities.h)
diff --git a/arch/s390/tools/gen_facilities.c b/arch/s390/tools/gen_facilities.c
new file mode 100644
index 000000000000..e2660d27889b
--- /dev/null
+++ b/arch/s390/tools/gen_facilities.c
@@ -0,0 +1,67 @@
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#define S390_GEN_FACILITIES_C
11
12#include <strings.h>
13#include <string.h>
14#include <stdlib.h>
15#include <stdio.h>
16#include <asm/facilities_src.h>
17
18static void print_facility_list(struct facility_def *def)
19{
20 unsigned int high, bit, dword, i;
21 unsigned long long *array;
22
23 array = calloc(1, 8);
24 if (!array)
25 exit(EXIT_FAILURE);
26 high = 0;
27 for (i = 0; def->bits[i] != -1; i++) {
28 bit = 63 - (def->bits[i] & 63);
29 dword = def->bits[i] / 64;
30 if (dword > high) {
31 array = realloc(array, (dword + 1) * 8);
32 if (!array)
33 exit(EXIT_FAILURE);
34 memset(array + high + 1, 0, (dword - high) * 8);
35 high = dword;
36 }
37 array[dword] |= 1ULL << bit;
38 }
39 printf("#define %s ", def->name);
40 for (i = 0; i <= high; i++)
41 printf("_AC(0x%016llx,UL)%c", array[i], i < high ? ',' : '\n');
42 printf("#define %s_DWORDS %d\n", def->name, high + 1);
43 free(array);
44}
45
46static void print_facility_lists(void)
47{
48 unsigned int i;
49
50 for (i = 0; i < sizeof(facility_defs) / sizeof(facility_defs[0]); i++)
51 print_facility_list(&facility_defs[i]);
52}
53
54int main(int argc, char **argv)
55{
56 printf("#ifndef __ASM_S390_FACILITIES__\n");
57 printf("#define __ASM_S390_FACILITIES__\n");
58 printf("/*\n");
59 printf(" * DO NOT MODIFY.\n");
60 printf(" *\n");
61 printf(" * This file was generated by %s\n", __FILE__);
62 printf(" */\n\n");
63 printf("#include <linux/const.h>\n\n");
64 print_facility_lists();
65 printf("\n#endif\n");
66 return 0;
67}