// 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 */3118, /* long displacement facility */3221, /* extended-immediate facility */3325, /* store clock fast */3427, /* mvcos */3532, /* compare and swap and store */3633, /* compare and swap and store 2 */3734, /* general instructions extension */3835, /* execute extensions */39#ifdef CONFIG_HAVE_MARCH_Z196_FEATURES4045, /* fast-BCR, etc. */41#endif42#ifdef CONFIG_HAVE_MARCH_ZEC12_FEATURES4349, /* misc-instruction-extensions */4452, /* interlocked facility 2 */45#endif46#ifdef CONFIG_HAVE_MARCH_Z13_FEATURES4753, /* load-and-zero-rightmost-byte, etc. */48129, /* vector */49#endif50#ifdef CONFIG_HAVE_MARCH_Z14_FEATURES5158, /* miscellaneous-instruction-extension 2 */52#endif53#ifdef CONFIG_HAVE_MARCH_Z15_FEATURES5461, /* miscellaneous-instruction-extension 3 */55#endif56#ifdef CONFIG_HAVE_MARCH_Z17_FEATURES5784, /* miscellaneous-instruction-extension 4 */58#endif59-1 /* END */60}61},62{63/*64* FACILITIES_KVM contains the list of facilities that are part65* of the default facility mask and list that are passed to the66* initial CPU model. If no CPU model is used, this, together67* with the non-hypervisor managed bits, is the maximum list of68* guest facilities supported by KVM.69*/70.name = "FACILITIES_KVM",71.bits = (int[]){720, /* N3 instructions */731, /* z/Arch mode installed */742, /* z/Arch mode active */753, /* DAT-enhancement */764, /* idte segment table */775, /* idte region table */786, /* ASN-and-LX reuse */797, /* stfle */808, /* enhanced-DAT 1 */819, /* sense-running-status */8210, /* conditional sske */8313, /* ipte-range */8414, /* nonquiescing key-setting */8573, /* transactional execution */8675, /* access-exception-fetch/store indication */8776, /* msa extension 3 */8877, /* msa extension 4 */8978, /* enhanced-DAT 2 */90130, /* instruction-execution-protection */91131, /* enhanced-SOP 2 and side-effect */92139, /* multiple epoch facility */93146, /* msa extension 8 */94150, /* enhanced sort */95151, /* deflate conversion */96155, /* msa extension 9 */97-1 /* END */98}99},100{101/*102* FACILITIES_KVM_CPUMODEL contains the list of facilities103* that can be enabled by CPU model code if the host supports104* it. These facilities are not passed to the guest without105* CPU model support.106*/107108.name = "FACILITIES_KVM_CPUMODEL",109.bits = (int[]){11012, /* AP Query Configuration Information */11115, /* AP Facilities Test */112156, /* etoken facility */113165, /* nnpa facility */114170, /* ineffective-nonconstrained-transaction facility */115193, /* bear enhancement facility */116194, /* rdp enhancement facility */117196, /* processor activity instrumentation facility */118197, /* processor activity instrumentation extension 1 */119201, /* concurrent-functions facility */120-1 /* END */121}122},123};124125static void print_facility_list(struct facility_def *def)126{127unsigned int high, bit, dword, i;128unsigned long long *array;129130array = calloc(1, 8);131if (!array)132exit(EXIT_FAILURE);133high = 0;134for (i = 0; def->bits[i] != -1; i++) {135bit = 63 - (def->bits[i] & 63);136dword = def->bits[i] / 64;137if (dword > high) {138array = realloc(array, (dword + 1) * 8);139if (!array)140exit(EXIT_FAILURE);141memset(array + high + 1, 0, (dword - high) * 8);142high = dword;143}144array[dword] |= 1ULL << bit;145}146printf("#define %s ", def->name);147for (i = 0; i <= high; i++)148printf("_AC(0x%016llx,UL)%c", array[i], i < high ? ',' : '\n');149free(array);150}151152static void print_facility_lists(void)153{154unsigned int i;155156for (i = 0; i < sizeof(facility_defs) / sizeof(facility_defs[0]); i++)157print_facility_list(&facility_defs[i]);158}159160int main(int argc, char **argv)161{162printf("#ifndef __ASM_S390_FACILITY_DEFS__\n");163printf("#define __ASM_S390_FACILITY_DEFS__\n");164printf("/*\n");165printf(" * DO NOT MODIFY.\n");166printf(" *\n");167printf(" * This file was generated by %s\n", __FILE__);168printf(" */\n\n");169printf("#include <linux/const.h>\n\n");170print_facility_lists();171printf("\n#endif\n");172return 0;173}174175176