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