1
0

facility.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #ifndef SELFTEST_KVM_FACILITY_H
  11. #define SELFTEST_KVM_FACILITY_H
  12. #include <linux/bitops.h>
  13. /* alt_stfle_fac_list[16] + stfle_fac_list[16] */
  14. #define NB_STFL_DOUBLEWORDS 32
  15. extern uint64_t stfl_doublewords[NB_STFL_DOUBLEWORDS];
  16. extern bool stfle_flag;
  17. static inline bool test_bit_inv(unsigned long nr, const unsigned long *ptr)
  18. {
  19. return test_bit(nr ^ (BITS_PER_LONG - 1), ptr);
  20. }
  21. static inline void stfle(uint64_t *fac, unsigned int nb_doublewords)
  22. {
  23. register unsigned long r0 asm("0") = nb_doublewords - 1;
  24. asm volatile(" .insn s,0xb2b00000,0(%1)\n"
  25. : "+d" (r0)
  26. : "a" (fac)
  27. : "memory", "cc");
  28. }
  29. static inline void setup_facilities(void)
  30. {
  31. stfle(stfl_doublewords, NB_STFL_DOUBLEWORDS);
  32. stfle_flag = true;
  33. }
  34. static inline bool test_facility(int nr)
  35. {
  36. if (!stfle_flag)
  37. setup_facilities();
  38. return test_bit_inv(nr, stfl_doublewords);
  39. }
  40. #endif