cpu_mf.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * CPU-measurement facilities
  3. *
  4. * Copyright IBM Corp. 2012
  5. * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
  6. * Jan Glauber <jang@linux.vnet.ibm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License (version 2 only)
  10. * as published by the Free Software Foundation.
  11. */
  12. #ifndef _ASM_S390_CPU_MF_H
  13. #define _ASM_S390_CPU_MF_H
  14. #include <asm/facility.h>
  15. #define CPU_MF_INT_SF_IAE (1 << 31) /* invalid entry address */
  16. #define CPU_MF_INT_SF_ISE (1 << 30) /* incorrect SDBT entry */
  17. #define CPU_MF_INT_SF_PRA (1 << 29) /* program request alert */
  18. #define CPU_MF_INT_SF_SACA (1 << 23) /* sampler auth. change alert */
  19. #define CPU_MF_INT_SF_LSDA (1 << 22) /* loss of sample data alert */
  20. #define CPU_MF_INT_CF_CACA (1 << 7) /* counter auth. change alert */
  21. #define CPU_MF_INT_CF_LCDA (1 << 6) /* loss of counter data alert */
  22. #define CPU_MF_INT_CF_MASK (CPU_MF_INT_CF_CACA|CPU_MF_INT_CF_LCDA)
  23. #define CPU_MF_INT_SF_MASK (CPU_MF_INT_SF_IAE|CPU_MF_INT_SF_ISE| \
  24. CPU_MF_INT_SF_PRA|CPU_MF_INT_SF_SACA| \
  25. CPU_MF_INT_SF_LSDA)
  26. /* CPU measurement facility support */
  27. static inline int cpum_cf_avail(void)
  28. {
  29. return MACHINE_HAS_SPP && test_facility(67);
  30. }
  31. static inline int cpum_sf_avail(void)
  32. {
  33. return MACHINE_HAS_SPP && test_facility(68);
  34. }
  35. struct cpumf_ctr_info {
  36. u16 cfvn;
  37. u16 auth_ctl;
  38. u16 enable_ctl;
  39. u16 act_ctl;
  40. u16 max_cpu;
  41. u16 csvn;
  42. u16 max_cg;
  43. u16 reserved1;
  44. u32 reserved2[12];
  45. } __packed;
  46. /* Query counter information */
  47. static inline int qctri(struct cpumf_ctr_info *info)
  48. {
  49. int rc = -EINVAL;
  50. asm volatile (
  51. "0: .insn s,0xb28e0000,%1\n"
  52. "1: lhi %0,0\n"
  53. "2:\n"
  54. EX_TABLE(1b, 2b)
  55. : "+d" (rc), "=Q" (*info));
  56. return rc;
  57. }
  58. /* Load CPU-counter-set controls */
  59. static inline int lcctl(u64 ctl)
  60. {
  61. int cc;
  62. asm volatile (
  63. " .insn s,0xb2840000,%1\n"
  64. " ipm %0\n"
  65. " srl %0,28\n"
  66. : "=d" (cc) : "m" (ctl) : "cc");
  67. return cc;
  68. }
  69. /* Extract CPU counter */
  70. static inline int ecctr(u64 ctr, u64 *val)
  71. {
  72. register u64 content asm("4") = 0;
  73. int cc;
  74. asm volatile (
  75. " .insn rre,0xb2e40000,%0,%2\n"
  76. " ipm %1\n"
  77. " srl %1,28\n"
  78. : "=d" (content), "=d" (cc) : "d" (ctr) : "cc");
  79. if (!cc)
  80. *val = content;
  81. return cc;
  82. }
  83. #endif /* _ASM_S390_CPU_MF_H */