1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright IBM Corp. 2024 4 * 5 * Authors: 6 * Hariharan Mari <hari55@linux.ibm.com> 7 * 8 * Get the facility bits with the STFLE instruction 9 */ 10 11 #ifndef SELFTEST_KVM_FACILITY_H 12 #define SELFTEST_KVM_FACILITY_H 13 14 #include <linux/bitops.h> 15 16 /* alt_stfle_fac_list[16] + stfle_fac_list[16] */ 17 #define NB_STFL_DOUBLEWORDS 32 18 19 extern uint64_t stfl_doublewords[NB_STFL_DOUBLEWORDS]; 20 extern bool stfle_flag; 21 22 static inline bool test_bit_inv(unsigned long nr, const unsigned long *ptr) 23 { 24 return test_bit(nr ^ (BITS_PER_LONG - 1), ptr); 25 } 26 27 static inline void stfle(uint64_t *fac, unsigned int nb_doublewords) 28 { 29 register unsigned long r0 asm("0") = nb_doublewords - 1; 30 31 asm volatile(" .insn s,0xb2b00000,0(%1)\n" 32 : "+d" (r0) 33 : "a" (fac) 34 : "memory", "cc"); 35 } 36 37 static inline void setup_facilities(void) 38 { 39 stfle(stfl_doublewords, NB_STFL_DOUBLEWORDS); 40 stfle_flag = true; 41 } 42 43 static inline bool test_facility(int nr) 44 { 45 if (!stfle_flag) 46 setup_facilities(); 47 return test_bit_inv(nr, stfl_doublewords); 48 } 49 50 #endif 51