cpu_mf.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_RI_HALTED (1 << 5) /* run-time instr. halted */
  23. #define CPU_MF_INT_RI_BUF_FULL (1 << 4) /* run-time instr. program
  24. buffer full */
  25. #define CPU_MF_INT_CF_MASK (CPU_MF_INT_CF_CACA|CPU_MF_INT_CF_LCDA)
  26. #define CPU_MF_INT_SF_MASK (CPU_MF_INT_SF_IAE|CPU_MF_INT_SF_ISE| \
  27. CPU_MF_INT_SF_PRA|CPU_MF_INT_SF_SACA| \
  28. CPU_MF_INT_SF_LSDA)
  29. #define CPU_MF_INT_RI_MASK (CPU_MF_INT_RI_HALTED|CPU_MF_INT_RI_BUF_FULL)
  30. /* CPU measurement facility support */
  31. static inline int cpum_cf_avail(void)
  32. {
  33. return MACHINE_HAS_LPP && test_facility(67);
  34. }
  35. static inline int cpum_sf_avail(void)
  36. {
  37. return MACHINE_HAS_LPP && test_facility(68);
  38. }
  39. struct cpumf_ctr_info {
  40. u16 cfvn;
  41. u16 auth_ctl;
  42. u16 enable_ctl;
  43. u16 act_ctl;
  44. u16 max_cpu;
  45. u16 csvn;
  46. u16 max_cg;
  47. u16 reserved1;
  48. u32 reserved2[12];
  49. } __packed;
  50. /* Query counter information */
  51. static inline int qctri(struct cpumf_ctr_info *info)
  52. {
  53. int rc = -EINVAL;
  54. asm volatile (
  55. "0: .insn s,0xb28e0000,%1\n"
  56. "1: lhi %0,0\n"
  57. "2:\n"
  58. EX_TABLE(1b, 2b)
  59. : "+d" (rc), "=Q" (*info));
  60. return rc;
  61. }
  62. /* Load CPU-counter-set controls */
  63. static inline int lcctl(u64 ctl)
  64. {
  65. int cc;
  66. asm volatile (
  67. " .insn s,0xb2840000,%1\n"
  68. " ipm %0\n"
  69. " srl %0,28\n"
  70. : "=d" (cc) : "m" (ctl) : "cc");
  71. return cc;
  72. }
  73. /* Extract CPU counter */
  74. static inline int ecctr(u64 ctr, u64 *val)
  75. {
  76. register u64 content asm("4") = 0;
  77. int cc;
  78. asm volatile (
  79. " .insn rre,0xb2e40000,%0,%2\n"
  80. " ipm %1\n"
  81. " srl %1,28\n"
  82. : "=d" (content), "=d" (cc) : "d" (ctr) : "cc");
  83. if (!cc)
  84. *val = content;
  85. return cc;
  86. }
  87. #endif /* _ASM_S390_CPU_MF_H */