facility.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 (256*8) /* stfle_fac_list has 256 bytes */
  14. static inline int __test_facility(unsigned long nr, void *facilities)
  15. {
  16. unsigned char *ptr;
  17. if (nr >= MAX_FACILITY_BIT)
  18. return 0;
  19. ptr = (unsigned char *) facilities + (nr >> 3);
  20. return (*ptr & (0x80 >> (nr & 7))) != 0;
  21. }
  22. /*
  23. * The test_facility function uses the bit odering where the MSB is bit 0.
  24. * That makes it easier to query facility bits with the bit number as
  25. * documented in the Principles of Operation.
  26. */
  27. static inline int test_facility(unsigned long nr)
  28. {
  29. unsigned long facilities_als[] = { FACILITIES_ALS };
  30. if (__builtin_constant_p(nr) && nr < sizeof(facilities_als) * 8) {
  31. if (__test_facility(nr, &facilities_als))
  32. return 1;
  33. }
  34. return __test_facility(nr, &S390_lowcore.stfle_fac_list);
  35. }
  36. /**
  37. * stfle - Store facility list extended
  38. * @stfle_fac_list: array where facility list can be stored
  39. * @size: size of passed in array in double words
  40. */
  41. static inline void stfle(u64 *stfle_fac_list, int size)
  42. {
  43. unsigned long nr;
  44. preempt_disable();
  45. asm volatile(
  46. " stfl 0(0)\n"
  47. : "=m" (S390_lowcore.stfl_fac_list));
  48. nr = 4; /* bytes stored by stfl */
  49. memcpy(stfle_fac_list, &S390_lowcore.stfl_fac_list, 4);
  50. if (S390_lowcore.stfl_fac_list & 0x01000000) {
  51. /* More facility bits available with stfle */
  52. register unsigned long reg0 asm("0") = size - 1;
  53. asm volatile(".insn s,0xb2b00000,0(%1)" /* stfle */
  54. : "+d" (reg0)
  55. : "a" (stfle_fac_list)
  56. : "memory", "cc");
  57. nr = (reg0 + 1) * 8; /* # bytes stored by stfle */
  58. }
  59. memset((char *) stfle_fac_list + nr, 0, size * 8 - nr);
  60. preempt_enable();
  61. }
  62. #endif /* __ASSEMBLY__ */
  63. #endif /* __ASM_FACILITY_H */