perfmon_montecito.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * This file contains the Montecito PMU register description tables
  4. * and pmc checker used by perfmon.c.
  5. *
  6. * Copyright (c) 2005-2006 Hewlett-Packard Development Company, L.P.
  7. * Contributed by Stephane Eranian <eranian@hpl.hp.com>
  8. */
  9. static int pfm_mont_pmc_check(struct task_struct *task, pfm_context_t *ctx, unsigned int cnum, unsigned long *val, struct pt_regs *regs);
  10. #define RDEP_MONT_ETB (RDEP(38)|RDEP(39)|RDEP(48)|RDEP(49)|RDEP(50)|RDEP(51)|RDEP(52)|RDEP(53)|RDEP(54)|\
  11. RDEP(55)|RDEP(56)|RDEP(57)|RDEP(58)|RDEP(59)|RDEP(60)|RDEP(61)|RDEP(62)|RDEP(63))
  12. #define RDEP_MONT_DEAR (RDEP(32)|RDEP(33)|RDEP(36))
  13. #define RDEP_MONT_IEAR (RDEP(34)|RDEP(35))
  14. static pfm_reg_desc_t pfm_mont_pmc_desc[PMU_MAX_PMCS]={
  15. /* pmc0 */ { PFM_REG_CONTROL , 0, 0x0, -1, NULL, NULL, {0,0, 0, 0}, {0,0, 0, 0}},
  16. /* pmc1 */ { PFM_REG_CONTROL , 0, 0x0, -1, NULL, NULL, {0,0, 0, 0}, {0,0, 0, 0}},
  17. /* pmc2 */ { PFM_REG_CONTROL , 0, 0x0, -1, NULL, NULL, {0,0, 0, 0}, {0,0, 0, 0}},
  18. /* pmc3 */ { PFM_REG_CONTROL , 0, 0x0, -1, NULL, NULL, {0,0, 0, 0}, {0,0, 0, 0}},
  19. /* pmc4 */ { PFM_REG_COUNTING, 6, 0x2000000, 0x7c7fff7f, NULL, pfm_mont_pmc_check, {RDEP(4),0, 0, 0}, {0,0, 0, 0}},
  20. /* pmc5 */ { PFM_REG_COUNTING, 6, 0x2000000, 0x7c7fff7f, NULL, pfm_mont_pmc_check, {RDEP(5),0, 0, 0}, {0,0, 0, 0}},
  21. /* pmc6 */ { PFM_REG_COUNTING, 6, 0x2000000, 0x7c7fff7f, NULL, pfm_mont_pmc_check, {RDEP(6),0, 0, 0}, {0,0, 0, 0}},
  22. /* pmc7 */ { PFM_REG_COUNTING, 6, 0x2000000, 0x7c7fff7f, NULL, pfm_mont_pmc_check, {RDEP(7),0, 0, 0}, {0,0, 0, 0}},
  23. /* pmc8 */ { PFM_REG_COUNTING, 6, 0x2000000, 0x7c7fff7f, NULL, pfm_mont_pmc_check, {RDEP(8),0, 0, 0}, {0,0, 0, 0}},
  24. /* pmc9 */ { PFM_REG_COUNTING, 6, 0x2000000, 0x7c7fff7f, NULL, pfm_mont_pmc_check, {RDEP(9),0, 0, 0}, {0,0, 0, 0}},
  25. /* pmc10 */ { PFM_REG_COUNTING, 6, 0x2000000, 0x7c7fff7f, NULL, pfm_mont_pmc_check, {RDEP(10),0, 0, 0}, {0,0, 0, 0}},
  26. /* pmc11 */ { PFM_REG_COUNTING, 6, 0x2000000, 0x7c7fff7f, NULL, pfm_mont_pmc_check, {RDEP(11),0, 0, 0}, {0,0, 0, 0}},
  27. /* pmc12 */ { PFM_REG_COUNTING, 6, 0x2000000, 0x7c7fff7f, NULL, pfm_mont_pmc_check, {RDEP(12),0, 0, 0}, {0,0, 0, 0}},
  28. /* pmc13 */ { PFM_REG_COUNTING, 6, 0x2000000, 0x7c7fff7f, NULL, pfm_mont_pmc_check, {RDEP(13),0, 0, 0}, {0,0, 0, 0}},
  29. /* pmc14 */ { PFM_REG_COUNTING, 6, 0x2000000, 0x7c7fff7f, NULL, pfm_mont_pmc_check, {RDEP(14),0, 0, 0}, {0,0, 0, 0}},
  30. /* pmc15 */ { PFM_REG_COUNTING, 6, 0x2000000, 0x7c7fff7f, NULL, pfm_mont_pmc_check, {RDEP(15),0, 0, 0}, {0,0, 0, 0}},
  31. /* pmc16 */ { PFM_REG_NOTIMPL, },
  32. /* pmc17 */ { PFM_REG_NOTIMPL, },
  33. /* pmc18 */ { PFM_REG_NOTIMPL, },
  34. /* pmc19 */ { PFM_REG_NOTIMPL, },
  35. /* pmc20 */ { PFM_REG_NOTIMPL, },
  36. /* pmc21 */ { PFM_REG_NOTIMPL, },
  37. /* pmc22 */ { PFM_REG_NOTIMPL, },
  38. /* pmc23 */ { PFM_REG_NOTIMPL, },
  39. /* pmc24 */ { PFM_REG_NOTIMPL, },
  40. /* pmc25 */ { PFM_REG_NOTIMPL, },
  41. /* pmc26 */ { PFM_REG_NOTIMPL, },
  42. /* pmc27 */ { PFM_REG_NOTIMPL, },
  43. /* pmc28 */ { PFM_REG_NOTIMPL, },
  44. /* pmc29 */ { PFM_REG_NOTIMPL, },
  45. /* pmc30 */ { PFM_REG_NOTIMPL, },
  46. /* pmc31 */ { PFM_REG_NOTIMPL, },
  47. /* pmc32 */ { PFM_REG_CONFIG, 0, 0x30f01ffffffffffUL, 0x30f01ffffffffffUL, NULL, pfm_mont_pmc_check, {0,0, 0, 0}, {0,0, 0, 0}},
  48. /* pmc33 */ { PFM_REG_CONFIG, 0, 0x0, 0x1ffffffffffUL, NULL, pfm_mont_pmc_check, {0,0, 0, 0}, {0,0, 0, 0}},
  49. /* pmc34 */ { PFM_REG_CONFIG, 0, 0xf01ffffffffffUL, 0xf01ffffffffffUL, NULL, pfm_mont_pmc_check, {0,0, 0, 0}, {0,0, 0, 0}},
  50. /* pmc35 */ { PFM_REG_CONFIG, 0, 0x0, 0x1ffffffffffUL, NULL, pfm_mont_pmc_check, {0,0, 0, 0}, {0,0, 0, 0}},
  51. /* pmc36 */ { PFM_REG_CONFIG, 0, 0xfffffff0, 0xf, NULL, pfm_mont_pmc_check, {0,0, 0, 0}, {0,0, 0, 0}},
  52. /* pmc37 */ { PFM_REG_MONITOR, 4, 0x0, 0x3fff, NULL, pfm_mont_pmc_check, {RDEP_MONT_IEAR, 0, 0, 0}, {0, 0, 0, 0}},
  53. /* pmc38 */ { PFM_REG_CONFIG, 0, 0xdb6, 0x2492, NULL, pfm_mont_pmc_check, {0,0, 0, 0}, {0,0, 0, 0}},
  54. /* pmc39 */ { PFM_REG_MONITOR, 6, 0x0, 0xffcf, NULL, pfm_mont_pmc_check, {RDEP_MONT_ETB,0, 0, 0}, {0,0, 0, 0}},
  55. /* pmc40 */ { PFM_REG_MONITOR, 6, 0x2000000, 0xf01cf, NULL, pfm_mont_pmc_check, {RDEP_MONT_DEAR,0, 0, 0}, {0,0, 0, 0}},
  56. /* pmc41 */ { PFM_REG_CONFIG, 0, 0x00002078fefefefeUL, 0x1e00018181818UL, NULL, pfm_mont_pmc_check, {0,0, 0, 0}, {0,0, 0, 0}},
  57. /* pmc42 */ { PFM_REG_MONITOR, 6, 0x0, 0x7ff4f, NULL, pfm_mont_pmc_check, {RDEP_MONT_ETB,0, 0, 0}, {0,0, 0, 0}},
  58. { PFM_REG_END , 0, 0x0, -1, NULL, NULL, {0,}, {0,}}, /* end marker */
  59. };
  60. static pfm_reg_desc_t pfm_mont_pmd_desc[PMU_MAX_PMDS]={
  61. /* pmd0 */ { PFM_REG_NOTIMPL, },
  62. /* pmd1 */ { PFM_REG_NOTIMPL, },
  63. /* pmd2 */ { PFM_REG_NOTIMPL, },
  64. /* pmd3 */ { PFM_REG_NOTIMPL, },
  65. /* pmd4 */ { PFM_REG_COUNTING, 0, 0x0, -1, NULL, NULL, {0,0, 0, 0}, {RDEP(4),0, 0, 0}},
  66. /* pmd5 */ { PFM_REG_COUNTING, 0, 0x0, -1, NULL, NULL, {0,0, 0, 0}, {RDEP(5),0, 0, 0}},
  67. /* pmd6 */ { PFM_REG_COUNTING, 0, 0x0, -1, NULL, NULL, {0,0, 0, 0}, {RDEP(6),0, 0, 0}},
  68. /* pmd7 */ { PFM_REG_COUNTING, 0, 0x0, -1, NULL, NULL, {0,0, 0, 0}, {RDEP(7),0, 0, 0}},
  69. /* pmd8 */ { PFM_REG_COUNTING, 0, 0x0, -1, NULL, NULL, {0,0, 0, 0}, {RDEP(8),0, 0, 0}},
  70. /* pmd9 */ { PFM_REG_COUNTING, 0, 0x0, -1, NULL, NULL, {0,0, 0, 0}, {RDEP(9),0, 0, 0}},
  71. /* pmd10 */ { PFM_REG_COUNTING, 0, 0x0, -1, NULL, NULL, {0,0, 0, 0}, {RDEP(10),0, 0, 0}},
  72. /* pmd11 */ { PFM_REG_COUNTING, 0, 0x0, -1, NULL, NULL, {0,0, 0, 0}, {RDEP(11),0, 0, 0}},
  73. /* pmd12 */ { PFM_REG_COUNTING, 0, 0x0, -1, NULL, NULL, {0,0, 0, 0}, {RDEP(12),0, 0, 0}},
  74. /* pmd13 */ { PFM_REG_COUNTING, 0, 0x0, -1, NULL, NULL, {0,0, 0, 0}, {RDEP(13),0, 0, 0}},
  75. /* pmd14 */ { PFM_REG_COUNTING, 0, 0x0, -1, NULL, NULL, {0,0, 0, 0}, {RDEP(14),0, 0, 0}},
  76. /* pmd15 */ { PFM_REG_COUNTING, 0, 0x0, -1, NULL, NULL, {0,0, 0, 0}, {RDEP(15),0, 0, 0}},
  77. /* pmd16 */ { PFM_REG_NOTIMPL, },
  78. /* pmd17 */ { PFM_REG_NOTIMPL, },
  79. /* pmd18 */ { PFM_REG_NOTIMPL, },
  80. /* pmd19 */ { PFM_REG_NOTIMPL, },
  81. /* pmd20 */ { PFM_REG_NOTIMPL, },
  82. /* pmd21 */ { PFM_REG_NOTIMPL, },
  83. /* pmd22 */ { PFM_REG_NOTIMPL, },
  84. /* pmd23 */ { PFM_REG_NOTIMPL, },
  85. /* pmd24 */ { PFM_REG_NOTIMPL, },
  86. /* pmd25 */ { PFM_REG_NOTIMPL, },
  87. /* pmd26 */ { PFM_REG_NOTIMPL, },
  88. /* pmd27 */ { PFM_REG_NOTIMPL, },
  89. /* pmd28 */ { PFM_REG_NOTIMPL, },
  90. /* pmd29 */ { PFM_REG_NOTIMPL, },
  91. /* pmd30 */ { PFM_REG_NOTIMPL, },
  92. /* pmd31 */ { PFM_REG_NOTIMPL, },
  93. /* pmd32 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP(33)|RDEP(36),0, 0, 0}, {RDEP(40),0, 0, 0}},
  94. /* pmd33 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP(32)|RDEP(36),0, 0, 0}, {RDEP(40),0, 0, 0}},
  95. /* pmd34 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP(35),0, 0, 0}, {RDEP(37),0, 0, 0}},
  96. /* pmd35 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP(34),0, 0, 0}, {RDEP(37),0, 0, 0}},
  97. /* pmd36 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP(32)|RDEP(33),0, 0, 0}, {RDEP(40),0, 0, 0}},
  98. /* pmd37 */ { PFM_REG_NOTIMPL, },
  99. /* pmd38 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP_MONT_ETB,0, 0, 0}, {RDEP(39),0, 0, 0}},
  100. /* pmd39 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP_MONT_ETB,0, 0, 0}, {RDEP(39),0, 0, 0}},
  101. /* pmd40 */ { PFM_REG_NOTIMPL, },
  102. /* pmd41 */ { PFM_REG_NOTIMPL, },
  103. /* pmd42 */ { PFM_REG_NOTIMPL, },
  104. /* pmd43 */ { PFM_REG_NOTIMPL, },
  105. /* pmd44 */ { PFM_REG_NOTIMPL, },
  106. /* pmd45 */ { PFM_REG_NOTIMPL, },
  107. /* pmd46 */ { PFM_REG_NOTIMPL, },
  108. /* pmd47 */ { PFM_REG_NOTIMPL, },
  109. /* pmd48 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP_MONT_ETB,0, 0, 0}, {RDEP(39),0, 0, 0}},
  110. /* pmd49 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP_MONT_ETB,0, 0, 0}, {RDEP(39),0, 0, 0}},
  111. /* pmd50 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP_MONT_ETB,0, 0, 0}, {RDEP(39),0, 0, 0}},
  112. /* pmd51 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP_MONT_ETB,0, 0, 0}, {RDEP(39),0, 0, 0}},
  113. /* pmd52 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP_MONT_ETB,0, 0, 0}, {RDEP(39),0, 0, 0}},
  114. /* pmd53 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP_MONT_ETB,0, 0, 0}, {RDEP(39),0, 0, 0}},
  115. /* pmd54 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP_MONT_ETB,0, 0, 0}, {RDEP(39),0, 0, 0}},
  116. /* pmd55 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP_MONT_ETB,0, 0, 0}, {RDEP(39),0, 0, 0}},
  117. /* pmd56 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP_MONT_ETB,0, 0, 0}, {RDEP(39),0, 0, 0}},
  118. /* pmd57 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP_MONT_ETB,0, 0, 0}, {RDEP(39),0, 0, 0}},
  119. /* pmd58 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP_MONT_ETB,0, 0, 0}, {RDEP(39),0, 0, 0}},
  120. /* pmd59 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP_MONT_ETB,0, 0, 0}, {RDEP(39),0, 0, 0}},
  121. /* pmd60 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP_MONT_ETB,0, 0, 0}, {RDEP(39),0, 0, 0}},
  122. /* pmd61 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP_MONT_ETB,0, 0, 0}, {RDEP(39),0, 0, 0}},
  123. /* pmd62 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP_MONT_ETB,0, 0, 0}, {RDEP(39),0, 0, 0}},
  124. /* pmd63 */ { PFM_REG_BUFFER, 0, 0x0, -1, NULL, NULL, {RDEP_MONT_ETB,0, 0, 0}, {RDEP(39),0, 0, 0}},
  125. { PFM_REG_END , 0, 0x0, -1, NULL, NULL, {0,}, {0,}}, /* end marker */
  126. };
  127. /*
  128. * PMC reserved fields must have their power-up values preserved
  129. */
  130. static int
  131. pfm_mont_reserved(unsigned int cnum, unsigned long *val, struct pt_regs *regs)
  132. {
  133. unsigned long tmp1, tmp2, ival = *val;
  134. /* remove reserved areas from user value */
  135. tmp1 = ival & PMC_RSVD_MASK(cnum);
  136. /* get reserved fields values */
  137. tmp2 = PMC_DFL_VAL(cnum) & ~PMC_RSVD_MASK(cnum);
  138. *val = tmp1 | tmp2;
  139. DPRINT(("pmc[%d]=0x%lx, mask=0x%lx, reset=0x%lx, val=0x%lx\n",
  140. cnum, ival, PMC_RSVD_MASK(cnum), PMC_DFL_VAL(cnum), *val));
  141. return 0;
  142. }
  143. /*
  144. * task can be NULL if the context is unloaded
  145. */
  146. static int
  147. pfm_mont_pmc_check(struct task_struct *task, pfm_context_t *ctx, unsigned int cnum, unsigned long *val, struct pt_regs *regs)
  148. {
  149. int ret = 0;
  150. unsigned long val32 = 0, val38 = 0, val41 = 0;
  151. unsigned long tmpval;
  152. int check_case1 = 0;
  153. int is_loaded;
  154. /* first preserve the reserved fields */
  155. pfm_mont_reserved(cnum, val, regs);
  156. tmpval = *val;
  157. /* sanity check */
  158. if (ctx == NULL) return -EINVAL;
  159. is_loaded = ctx->ctx_state == PFM_CTX_LOADED || ctx->ctx_state == PFM_CTX_MASKED;
  160. /*
  161. * we must clear the debug registers if pmc41 has a value which enable
  162. * memory pipeline event constraints. In this case we need to clear the
  163. * the debug registers if they have not yet been accessed. This is required
  164. * to avoid picking stale state.
  165. * PMC41 is "active" if:
  166. * one of the pmc41.cfg_dtagXX field is different from 0x3
  167. * AND
  168. * at the corresponding pmc41.en_dbrpXX is set.
  169. * AND
  170. * ctx_fl_using_dbreg == 0 (i.e., dbr not yet used)
  171. */
  172. DPRINT(("cnum=%u val=0x%lx, using_dbreg=%d loaded=%d\n", cnum, tmpval, ctx->ctx_fl_using_dbreg, is_loaded));
  173. if (cnum == 41 && is_loaded
  174. && (tmpval & 0x1e00000000000UL) && (tmpval & 0x18181818UL) != 0x18181818UL && ctx->ctx_fl_using_dbreg == 0) {
  175. DPRINT(("pmc[%d]=0x%lx has active pmc41 settings, clearing dbr\n", cnum, tmpval));
  176. /* don't mix debug with perfmon */
  177. if (task && (task->thread.flags & IA64_THREAD_DBG_VALID) != 0) return -EINVAL;
  178. /*
  179. * a count of 0 will mark the debug registers if:
  180. * AND
  181. */
  182. ret = pfm_write_ibr_dbr(PFM_DATA_RR, ctx, NULL, 0, regs);
  183. if (ret) return ret;
  184. }
  185. /*
  186. * we must clear the (instruction) debug registers if:
  187. * pmc38.ig_ibrpX is 0 (enabled)
  188. * AND
  189. * ctx_fl_using_dbreg == 0 (i.e., dbr not yet used)
  190. */
  191. if (cnum == 38 && is_loaded && ((tmpval & 0x492UL) != 0x492UL) && ctx->ctx_fl_using_dbreg == 0) {
  192. DPRINT(("pmc38=0x%lx has active pmc38 settings, clearing ibr\n", tmpval));
  193. /* don't mix debug with perfmon */
  194. if (task && (task->thread.flags & IA64_THREAD_DBG_VALID) != 0) return -EINVAL;
  195. /*
  196. * a count of 0 will mark the debug registers as in use and also
  197. * ensure that they are properly cleared.
  198. */
  199. ret = pfm_write_ibr_dbr(PFM_CODE_RR, ctx, NULL, 0, regs);
  200. if (ret) return ret;
  201. }
  202. switch(cnum) {
  203. case 32: val32 = *val;
  204. val38 = ctx->ctx_pmcs[38];
  205. val41 = ctx->ctx_pmcs[41];
  206. check_case1 = 1;
  207. break;
  208. case 38: val38 = *val;
  209. val32 = ctx->ctx_pmcs[32];
  210. val41 = ctx->ctx_pmcs[41];
  211. check_case1 = 1;
  212. break;
  213. case 41: val41 = *val;
  214. val32 = ctx->ctx_pmcs[32];
  215. val38 = ctx->ctx_pmcs[38];
  216. check_case1 = 1;
  217. break;
  218. }
  219. /* check illegal configuration which can produce inconsistencies in tagging
  220. * i-side events in L1D and L2 caches
  221. */
  222. if (check_case1) {
  223. ret = (((val41 >> 45) & 0xf) == 0 && ((val32>>57) & 0x1) == 0)
  224. && ((((val38>>1) & 0x3) == 0x2 || ((val38>>1) & 0x3) == 0)
  225. || (((val38>>4) & 0x3) == 0x2 || ((val38>>4) & 0x3) == 0));
  226. if (ret) {
  227. DPRINT(("invalid config pmc38=0x%lx pmc41=0x%lx pmc32=0x%lx\n", val38, val41, val32));
  228. return -EINVAL;
  229. }
  230. }
  231. *val = tmpval;
  232. return 0;
  233. }
  234. /*
  235. * impl_pmcs, impl_pmds are computed at runtime to minimize errors!
  236. */
  237. static pmu_config_t pmu_conf_mont={
  238. .pmu_name = "Montecito",
  239. .pmu_family = 0x20,
  240. .flags = PFM_PMU_IRQ_RESEND,
  241. .ovfl_val = (1UL << 47) - 1,
  242. .pmd_desc = pfm_mont_pmd_desc,
  243. .pmc_desc = pfm_mont_pmc_desc,
  244. .num_ibrs = 8,
  245. .num_dbrs = 8,
  246. .use_rr_dbregs = 1 /* debug register are use for range retrictions */
  247. };