]> git.karo-electronics.de Git - linux-beck.git/commitdiff
s390/facilities: add helper tool to generate facility lists
authorHeiko Carstens <heiko.carstens@de.ibm.com>
Mon, 2 Feb 2015 06:08:44 +0000 (07:08 +0100)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Fri, 18 Dec 2015 13:59:20 +0000 (14:59 +0100)
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>
arch/s390/Makefile
arch/s390/include/asm/facilities_src.h [new file with mode: 0644]
arch/s390/include/asm/facility.h
arch/s390/tools/.gitignore [new file with mode: 0644]
arch/s390/tools/Makefile [new file with mode: 0644]
arch/s390/tools/gen_facilities.c [new file with mode: 0644]

index 647bd14b223e0e45ab91628273a2324009b03f3e..224b42734f0d93d29da6c018f3872288983e2006 100644 (file)
@@ -106,6 +106,7 @@ drivers-y   += drivers/s390/
 drivers-$(CONFIG_OPROFILE)     += arch/s390/oprofile/
 
 boot           := arch/s390/boot
+tools          := arch/s390/tools
 
 all: image bzImage
 
@@ -124,6 +125,10 @@ vdso_install:
 
 archclean:
        $(Q)$(MAKE) $(clean)=$(boot)
+       $(Q)$(MAKE) $(clean)=$(tools)
+
+archprepare:
+       $(Q)$(MAKE) $(build)=$(tools) include/generated/facilities.h
 
 # Don't use tabs in echo arguments
 define archhelp
diff --git a/arch/s390/include/asm/facilities_src.h b/arch/s390/include/asm/facilities_src.h
new file mode 100644 (file)
index 0000000..4555fa6
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ *    Copyright IBM Corp. 2015
+ */
+
+#ifndef S390_GEN_FACILITIES_C
+#error "This file can only be included by gen_facilities.c"
+#endif
+
+#include <linux/kconfig.h>
+
+struct facility_def {
+       char *name;
+       int *bits;
+};
+
+static struct facility_def facility_defs[] = {
+       {
+               /*
+                * FACILITIES_ALS contains the list of facilities that are
+                * required to run a kernel that is compiled e.g. with
+                * -march=<machine>.
+                */
+               .name = "FACILITIES_ALS",
+               .bits = (int[]){
+#ifdef CONFIG_HAVE_MARCH_Z900_FEATURES
+                       0,  /* N3 instructions */
+                       1,  /* z/Arch mode installed */
+#endif
+#ifdef CONFIG_HAVE_MARCH_Z990_FEATURES
+                       18, /* long displacement facility */
+#endif
+#ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
+                       7,  /* stfle */
+                       16, /* extended translation facility 2 */
+                       17, /* message security assist */
+                       20, /* HFP-multiply-and-add */
+                       21, /* extended-immediate facility */
+                       22, /* extended-translation facility 3 */
+                       23, /* HFP-unnormalized-extension */
+                       24, /* ETF2-enhancement */
+                       25, /* store clock fast */
+                       30, /* ETF3-enhancement */
+#endif
+#ifdef CONFIG_HAVE_MARCH_Z10_FEATURES
+                       26, /* parsing enhancement facility */
+                       27, /* mvcos */
+                       32, /* compare and swap and store */
+                       33, /* compare and swap and store 2 */
+                       34, /* general extension facility */
+                       35, /* execute extensions */
+                       41, /* floating point support enhancement */
+                       42, /* DFP facility */
+                       44, /* PFPO */
+#endif
+#ifdef CONFIG_HAVE_MARCH_Z196_FEATURES
+                       37, /* floating point extension */
+                       45, /* fast-BCR, etc. */
+#endif
+#ifdef CONFIG_HAVE_MARCH_ZEC12_FEATURES
+                       48, /* decimal floating point zoned */
+                       49, /* misc-instruction-extensions */
+                       52, /* interlocked facility 2 */
+#endif
+                       -1 /* END */
+               }
+       },
+};
index b4f99d22ba047f3b50484969e257cf4367a33c2c..007163f91856d79849004423ec3efac348733b76 100644 (file)
@@ -7,6 +7,10 @@
 #ifndef __ASM_FACILITY_H
 #define __ASM_FACILITY_H
 
+#include <generated/facilities.h>
+
+#ifndef __ASSEMBLY__
+
 #include <linux/string.h>
 #include <linux/preempt.h>
 #include <asm/lowcore.h>
@@ -62,4 +66,5 @@ static inline void stfle(u64 *stfle_fac_list, int size)
        preempt_enable();
 }
 
+#endif /* __ASSEMBLY__ */
 #endif /* __ASM_FACILITY_H */
diff --git a/arch/s390/tools/.gitignore b/arch/s390/tools/.gitignore
new file mode 100644 (file)
index 0000000..72a4b2c
--- /dev/null
@@ -0,0 +1 @@
+gen_facilities
diff --git a/arch/s390/tools/Makefile b/arch/s390/tools/Makefile
new file mode 100644 (file)
index 0000000..6d9814c
--- /dev/null
@@ -0,0 +1,15 @@
+#
+# Makefile for s390 specific build tools
+#
+
+hostprogs-y                += gen_facilities
+HOSTCFLAGS_gen_facilities.o += -Wall $(LINUXINCLUDE)
+
+define filechk_facilities.h
+       $(obj)/gen_facilities
+endef
+
+$(obj)/gen_facilities.o: $(srctree)/arch/s390/tools/gen_facilities.c
+
+include/generated/facilities.h: $(obj)/gen_facilities FORCE
+       $(call filechk,facilities.h)
diff --git a/arch/s390/tools/gen_facilities.c b/arch/s390/tools/gen_facilities.c
new file mode 100644 (file)
index 0000000..e2660d2
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Simple program to generate defines out of facility lists that use the bit
+ * numbering scheme from the Princples of Operations: most significant bit
+ * has bit number 0.
+ *
+ *    Copyright IBM Corp. 2015
+ *
+ */
+
+#define S390_GEN_FACILITIES_C
+
+#include <strings.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <asm/facilities_src.h>
+
+static void print_facility_list(struct facility_def *def)
+{
+       unsigned int high, bit, dword, i;
+       unsigned long long *array;
+
+       array = calloc(1, 8);
+       if (!array)
+               exit(EXIT_FAILURE);
+       high = 0;
+       for (i = 0; def->bits[i] != -1; i++) {
+               bit = 63 - (def->bits[i] & 63);
+               dword = def->bits[i] / 64;
+               if (dword > high) {
+                       array = realloc(array, (dword + 1) * 8);
+                       if (!array)
+                               exit(EXIT_FAILURE);
+                       memset(array + high + 1, 0, (dword - high) * 8);
+                       high = dword;
+               }
+               array[dword] |= 1ULL << bit;
+       }
+       printf("#define %s ", def->name);
+       for (i = 0; i <= high; i++)
+               printf("_AC(0x%016llx,UL)%c", array[i], i < high ? ',' : '\n');
+       printf("#define %s_DWORDS %d\n", def->name, high + 1);
+       free(array);
+}
+
+static void print_facility_lists(void)
+{
+       unsigned int i;
+
+       for (i = 0; i < sizeof(facility_defs) / sizeof(facility_defs[0]); i++)
+               print_facility_list(&facility_defs[i]);
+}
+
+int main(int argc, char **argv)
+{
+       printf("#ifndef __ASM_S390_FACILITIES__\n");
+       printf("#define __ASM_S390_FACILITIES__\n");
+       printf("/*\n");
+       printf(" * DO NOT MODIFY.\n");
+       printf(" *\n");
+       printf(" * This file was generated by %s\n", __FILE__);
+       printf(" */\n\n");
+       printf("#include <linux/const.h>\n\n");
+       print_facility_lists();
+       printf("\n#endif\n");
+       return 0;
+}