facility.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright IBM Corp. 1999, 2009
  4. *
  5. * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
  6. */
  7. #ifndef __ASM_FACILITY_H
  8. #define __ASM_FACILITY_H
  9. #include <asm/facility-defs.h>
  10. #include <linux/string.h>
  11. #include <linux/preempt.h>
  12. #include <asm/lowcore.h>
  13. #define MAX_FACILITY_BIT (sizeof(((struct lowcore *)0)->stfle_fac_list) * 8)
  14. static inline void __set_facility(unsigned long nr, void *facilities)
  15. {
  16. unsigned char *ptr = (unsigned char *) facilities;
  17. if (nr >= MAX_FACILITY_BIT)
  18. return;
  19. ptr[nr >> 3] |= 0x80 >> (nr & 7);
  20. }
  21. static inline void __clear_facility(unsigned long nr, void *facilities)
  22. {
  23. unsigned char *ptr = (unsigned char *) facilities;
  24. if (nr >= MAX_FACILITY_BIT)
  25. return;
  26. ptr[nr >> 3] &= ~(0x80 >> (nr & 7));
  27. }
  28. static inline int __test_facility(unsigned long nr, void *facilities)
  29. {
  30. unsigned char *ptr;
  31. if (nr >= MAX_FACILITY_BIT)
  32. return 0;
  33. ptr = (unsigned char *) facilities + (nr >> 3);
  34. return (*ptr & (0x80 >> (nr & 7))) != 0;
  35. }
  36. /*
  37. * The test_facility function uses the bit odering where the MSB is bit 0.
  38. * That makes it easier to query facility bits with the bit number as
  39. * documented in the Principles of Operation.
  40. */
  41. static inline int test_facility(unsigned long nr)
  42. {
  43. unsigned long facilities_als[] = { FACILITIES_ALS };
  44. if (__builtin_constant_p(nr) && nr < sizeof(facilities_als) * 8) {
  45. if (__test_facility(nr, &facilities_als))
  46. return 1;
  47. }
  48. return __test_facility(nr, &S390_lowcore.stfle_fac_list);
  49. }
  50. static inline unsigned long __stfle_asm(u64 *stfle_fac_list, int size)
  51. {
  52. register unsigned long reg0 asm("0") = size - 1;
  53. asm volatile(
  54. ".insn s,0xb2b00000,0(%1)" /* stfle */
  55. : "+d" (reg0)
  56. : "a" (stfle_fac_list)
  57. : "memory", "cc");
  58. return reg0;
  59. }
  60. /**
  61. * stfle - Store facility list extended
  62. * @stfle_fac_list: array where facility list can be stored
  63. * @size: size of passed in array in double words
  64. */
  65. static inline void stfle(u64 *stfle_fac_list, int size)
  66. {
  67. unsigned long nr;
  68. preempt_disable();
  69. asm volatile(
  70. " stfl 0(0)\n"
  71. : "=m" (S390_lowcore.stfl_fac_list));
  72. nr = 4; /* bytes stored by stfl */
  73. memcpy(stfle_fac_list, &S390_lowcore.stfl_fac_list, 4);
  74. if (S390_lowcore.stfl_fac_list & 0x01000000) {
  75. /* More facility bits available with stfle */
  76. nr = __stfle_asm(stfle_fac_list, size);
  77. nr = min_t(unsigned long, (nr + 1) * 8, size * 8);
  78. }
  79. memset((char *) stfle_fac_list + nr, 0, size * 8 - nr);
  80. preempt_enable();
  81. }
  82. #endif /* __ASM_FACILITY_H */