facility.h 1.9 KB

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