// SPDX-License-Identifier: GPL-2.01/*2* Simple program to generate defines out of facility lists that use the bit3* numbering scheme from the Princples of Operations: most significant bit4* has bit number 0.5*6* Copyright IBM Corp. 2015, 20187*8*/910#include <strings.h>11#include <string.h>12#include <stdlib.h>13#include <stdio.h>1415struct facility_def {16char *name;17int *bits;18};1920static struct facility_def facility_defs[] = {21{22/*23* FACILITIES_ALS contains the list of facilities that are24* required to run a kernel that is compiled e.g. with25* -march=<machine>.26*/27.name = "FACILITIES_ALS",28.bits = (int[]){290, /* N3 instructions */301, /* z/Arch mode installed */313, /* dat-enhancement 1 */3218, /* long displacement facility */3321, /* extended-immediate facility */3425, /* store clock fast */3527, /* mvcos */3632, /* compare and swap and store */3733, /* compare and swap and store 2 */3834, /* general instructions extension */3935, /* execute extensions */40#ifdef CONFIG_HAVE_MARCH_Z196_FEATURES4145, /* fast-BCR, etc. */42#endif43#ifdef CONFIG_HAVE_MARCH_ZEC12_FEATURES4449, /* misc-instruction-extensions */4552, /* interlocked facility 2 */46#endif47#ifdef CONFIG_HAVE_MARCH_Z13_FEATURES4853, /* load-and-zero-rightmost-byte, etc. */49129, /* vector */50#endif51#ifdef CONFIG_HAVE_MARCH_Z14_FEATURES5258, /* miscellaneous-instruction-extension 2 */53#endif54#ifdef CONFIG_HAVE_MARCH_Z15_FEATURES5561, /* miscellaneous-instruction-extension 3 */56#endif57#ifdef CONFIG_HAVE_MARCH_Z17_FEATURES5884, /* miscellaneous-instruction-extension 4 */59#endif60-1 /* END */61}62},63{64/*65* FACILITIES_KVM contains the list of facilities that are part66* of the default facility mask and list that are passed to the67* initial CPU model. If no CPU model is used, this, together68* with the non-hypervisor managed bits, is the maximum list of69* guest facilities supported by KVM.70*/71.name = "FACILITIES_KVM",72.bits = (int[]){730, /* N3 instructions */741, /* z/Arch mode installed */752, /* z/Arch mode active */763, /* DAT-enhancement */774, /* idte segment table */785, /* idte region table */796, /* ASN-and-LX reuse */807, /* stfle */818, /* enhanced-DAT 1 */829, /* sense-running-status */8310, /* conditional sske */8413, /* ipte-range */8514, /* nonquiescing key-setting */8673, /* transactional execution */8775, /* access-exception-fetch/store indication */8876, /* msa extension 3 */8977, /* msa extension 4 */9078, /* enhanced-DAT 2 */91130, /* instruction-execution-protection */92131, /* enhanced-SOP 2 and side-effect */93139, /* multiple epoch facility */94146, /* msa extension 8 */95150, /* enhanced sort */96151, /* deflate conversion */97155, /* msa extension 9 */98-1 /* END */99}100},101{102/*103* FACILITIES_KVM_CPUMODEL contains the list of facilities104* that can be enabled by CPU model code if the host supports105* it. These facilities are not passed to the guest without106* CPU model support.107*/108109.name = "FACILITIES_KVM_CPUMODEL",110.bits = (int[]){11112, /* AP Query Configuration Information */11215, /* AP Facilities Test */113156, /* etoken facility */114165, /* nnpa facility */115170, /* ineffective-nonconstrained-transaction facility */116193, /* bear enhancement facility */117194, /* rdp enhancement facility */118196, /* processor activity instrumentation facility */119197, /* processor activity instrumentation extension 1 */120201, /* concurrent-functions facility */121-1 /* END */122}123},124};125126static void print_facility_list(struct facility_def *def)127{128unsigned int high, bit, dword, i;129unsigned long long *array;130131array = calloc(1, 8);132if (!array)133exit(EXIT_FAILURE);134high = 0;135for (i = 0; def->bits[i] != -1; i++) {136bit = 63 - (def->bits[i] & 63);137dword = def->bits[i] / 64;138if (dword > high) {139array = realloc(array, (dword + 1) * 8);140if (!array)141exit(EXIT_FAILURE);142memset(array + high + 1, 0, (dword - high) * 8);143high = dword;144}145array[dword] |= 1ULL << bit;146}147printf("#define %s ", def->name);148for (i = 0; i <= high; i++)149printf("_AC(0x%016llx,UL)%c", array[i], i < high ? ',' : '\n');150free(array);151}152153static void print_facility_lists(void)154{155unsigned int i;156157for (i = 0; i < sizeof(facility_defs) / sizeof(facility_defs[0]); i++)158print_facility_list(&facility_defs[i]);159}160161int main(int argc, char **argv)162{163printf("#ifndef __ASM_S390_FACILITY_DEFS__\n");164printf("#define __ASM_S390_FACILITY_DEFS__\n");165printf("/*\n");166printf(" * DO NOT MODIFY.\n");167printf(" *\n");168printf(" * This file was generated by %s\n", __FILE__);169printf(" */\n\n");170printf("#include <linux/const.h>\n\n");171print_facility_lists();172printf("\n#endif\n");173return 0;174}175176177