Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Simple program to generate defines out of facility lists that use the bit
0004  * numbering scheme from the Princples of Operations: most significant bit
0005  * has bit number 0.
0006  *
0007  *    Copyright IBM Corp. 2015, 2018
0008  *
0009  */
0010 
0011 #include <strings.h>
0012 #include <string.h>
0013 #include <stdlib.h>
0014 #include <stdio.h>
0015 
0016 struct facility_def {
0017     char *name;
0018     int *bits;
0019 };
0020 
0021 static struct facility_def facility_defs[] = {
0022     {
0023         /*
0024          * FACILITIES_ALS contains the list of facilities that are
0025          * required to run a kernel that is compiled e.g. with
0026          * -march=<machine>.
0027          */
0028         .name = "FACILITIES_ALS",
0029         .bits = (int[]){
0030             0,  /* N3 instructions */
0031             1,  /* z/Arch mode installed */
0032             18, /* long displacement facility */
0033             21, /* extended-immediate facility */
0034             25, /* store clock fast */
0035             27, /* mvcos */
0036             32, /* compare and swap and store */
0037             33, /* compare and swap and store 2 */
0038             34, /* general instructions extension */
0039             35, /* execute extensions */
0040 #ifdef CONFIG_HAVE_MARCH_Z196_FEATURES
0041             45, /* fast-BCR, etc. */
0042 #endif
0043 #ifdef CONFIG_HAVE_MARCH_ZEC12_FEATURES
0044             49, /* misc-instruction-extensions */
0045             52, /* interlocked facility 2 */
0046 #endif
0047 #ifdef CONFIG_HAVE_MARCH_Z13_FEATURES
0048             53, /* load-and-zero-rightmost-byte, etc. */
0049 #endif
0050 #ifdef CONFIG_HAVE_MARCH_Z14_FEATURES
0051             58, /* miscellaneous-instruction-extension 2 */
0052 #endif
0053 #ifdef CONFIG_HAVE_MARCH_Z15_FEATURES
0054             61, /* miscellaneous-instruction-extension 3 */
0055 #endif
0056             -1 /* END */
0057         }
0058     },
0059     {
0060         /*
0061          * FACILITIES_KVM contains the list of facilities that are part
0062          * of the default facility mask and list that are passed to the
0063          * initial CPU model. If no CPU model is used, this, together
0064          * with the non-hypervisor managed bits, is the maximum list of
0065          * guest facilities supported by KVM.
0066          */
0067         .name = "FACILITIES_KVM",
0068         .bits = (int[]){
0069             0,  /* N3 instructions */
0070             1,  /* z/Arch mode installed */
0071             2,  /* z/Arch mode active */
0072             3,  /* DAT-enhancement */
0073             4,  /* idte segment table */
0074             5,  /* idte region table */
0075             6,  /* ASN-and-LX reuse */
0076             7,  /* stfle */
0077             8,  /* enhanced-DAT 1 */
0078             9,  /* sense-running-status */
0079             10, /* conditional sske */
0080             13, /* ipte-range */
0081             14, /* nonquiescing key-setting */
0082             73, /* transactional execution */
0083             75, /* access-exception-fetch/store indication */
0084             76, /* msa extension 3 */
0085             77, /* msa extension 4 */
0086             78, /* enhanced-DAT 2 */
0087             130, /* instruction-execution-protection */
0088             131, /* enhanced-SOP 2 and side-effect */
0089             139, /* multiple epoch facility */
0090             146, /* msa extension 8 */
0091             150, /* enhanced sort */
0092             151, /* deflate conversion */
0093             155, /* msa extension 9 */
0094             -1  /* END */
0095         }
0096     },
0097     {
0098         /*
0099          * FACILITIES_KVM_CPUMODEL contains the list of facilities
0100          * that can be enabled by CPU model code if the host supports
0101          * it. These facilities are not passed to the guest without
0102          * CPU model support.
0103          */
0104 
0105         .name = "FACILITIES_KVM_CPUMODEL",
0106         .bits = (int[]){
0107             12, /* AP Query Configuration Information */
0108             15, /* AP Facilities Test */
0109             156, /* etoken facility */
0110             165, /* nnpa facility */
0111             193, /* bear enhancement facility */
0112             194, /* rdp enhancement facility */
0113             196, /* processor activity instrumentation facility */
0114             197, /* processor activity instrumentation extension 1 */
0115             -1  /* END */
0116         }
0117     },
0118 };
0119 
0120 static void print_facility_list(struct facility_def *def)
0121 {
0122     unsigned int high, bit, dword, i;
0123     unsigned long long *array;
0124 
0125     array = calloc(1, 8);
0126     if (!array)
0127         exit(EXIT_FAILURE);
0128     high = 0;
0129     for (i = 0; def->bits[i] != -1; i++) {
0130         bit = 63 - (def->bits[i] & 63);
0131         dword = def->bits[i] / 64;
0132         if (dword > high) {
0133             array = realloc(array, (dword + 1) * 8);
0134             if (!array)
0135                 exit(EXIT_FAILURE);
0136             memset(array + high + 1, 0, (dword - high) * 8);
0137             high = dword;
0138         }
0139         array[dword] |= 1ULL << bit;
0140     }
0141     printf("#define %s ", def->name);
0142     for (i = 0; i <= high; i++)
0143         printf("_AC(0x%016llx,UL)%c", array[i], i < high ? ',' : '\n');
0144     free(array);
0145 }
0146 
0147 static void print_facility_lists(void)
0148 {
0149     unsigned int i;
0150 
0151     for (i = 0; i < sizeof(facility_defs) / sizeof(facility_defs[0]); i++)
0152         print_facility_list(&facility_defs[i]);
0153 }
0154 
0155 int main(int argc, char **argv)
0156 {
0157     printf("#ifndef __ASM_S390_FACILITY_DEFS__\n");
0158     printf("#define __ASM_S390_FACILITY_DEFS__\n");
0159     printf("/*\n");
0160     printf(" * DO NOT MODIFY.\n");
0161     printf(" *\n");
0162     printf(" * This file was generated by %s\n", __FILE__);
0163     printf(" */\n\n");
0164     printf("#include <linux/const.h>\n\n");
0165     print_facility_lists();
0166     printf("\n#endif\n");
0167     return 0;
0168 }