facility.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright IBM Corp. 1999, 2009
  3. *
  4. * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
  5. */
  6. #ifndef __ASM_FACILITY_H
  7. #define __ASM_FACILITY_H
  8. #include <generated/facilities.h>
  9. #ifndef __ASSEMBLY__
  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. /**
  51. * stfle - Store facility list extended
  52. * @stfle_fac_list: array where facility list can be stored
  53. * @size: size of passed in array in double words
  54. */
  55. static inline void stfle(u64 *stfle_fac_list, int size)
  56. {
  57. unsigned long nr;
  58. preempt_disable();
  59. asm volatile(
  60. " stfl 0(0)\n"
  61. : "=m" (S390_lowcore.stfl_fac_list));
  62. nr = 4; /* bytes stored by stfl */
  63. memcpy(stfle_fac_list, &S390_lowcore.stfl_fac_list, 4);
  64. if (S390_lowcore.stfl_fac_list & 0x01000000) {
  65. /* More facility bits available with stfle */
  66. register unsigned long reg0 asm("0") = size - 1;
  67. asm volatile(".insn s,0xb2b00000,0(%1)" /* stfle */
  68. : "+d" (reg0)
  69. : "a" (stfle_fac_list)
  70. : "memory", "cc");
  71. nr = (reg0 + 1) * 8; /* # bytes stored by stfle */
  72. }
  73. memset((char *) stfle_fac_list + nr, 0, size * 8 - nr);
  74. preempt_enable();
  75. }
  76. #endif /* __ASSEMBLY__ */
  77. #endif /* __ASM_FACILITY_H */