facility.h 1.7 KB

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