mali_kbase_instr.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. *
  3. * (C) COPYRIGHT 2011-2015 ARM Limited. All rights reserved.
  4. *
  5. * This program is free software and is provided to you under the terms of the
  6. * GNU General Public License version 2 as published by the Free Software
  7. * Foundation, and any use by you of this program is subject to the terms
  8. * of such GNU licence.
  9. *
  10. * A copy of the licence is included with the program, and can also be obtained
  11. * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  12. * Boston, MA 02110-1301, USA.
  13. *
  14. */
  15. /*
  16. * Base kernel instrumentation APIs.
  17. */
  18. #include <mali_kbase.h>
  19. #include <mali_midg_regmap.h>
  20. void kbase_instr_hwcnt_suspend(struct kbase_device *kbdev)
  21. {
  22. struct kbase_context *kctx;
  23. KBASE_DEBUG_ASSERT(kbdev);
  24. KBASE_DEBUG_ASSERT(!kbdev->hwcnt.suspended_kctx);
  25. kctx = kbdev->hwcnt.kctx;
  26. kbdev->hwcnt.suspended_kctx = kctx;
  27. /* Relevant state was saved into hwcnt.suspended_state when enabling the
  28. * counters */
  29. if (kctx) {
  30. KBASE_DEBUG_ASSERT(kctx->jctx.sched_info.ctx.flags &
  31. KBASE_CTX_FLAG_PRIVILEGED);
  32. kbase_instr_hwcnt_disable(kctx);
  33. }
  34. }
  35. void kbase_instr_hwcnt_resume(struct kbase_device *kbdev)
  36. {
  37. struct kbase_context *kctx;
  38. KBASE_DEBUG_ASSERT(kbdev);
  39. kctx = kbdev->hwcnt.suspended_kctx;
  40. kbdev->hwcnt.suspended_kctx = NULL;
  41. if (kctx) {
  42. int err;
  43. err = kbase_instr_hwcnt_enable_internal(kbdev, kctx,
  44. &kbdev->hwcnt.suspended_state);
  45. WARN(err, "Failed to restore instrumented hardware counters on resume\n");
  46. }
  47. }
  48. int kbase_instr_hwcnt_enable(struct kbase_context *kctx,
  49. struct kbase_uk_hwcnt_setup *setup)
  50. {
  51. struct kbase_device *kbdev;
  52. int err;
  53. kbdev = kctx->kbdev;
  54. /* Mark the context as active so the GPU is kept turned on */
  55. /* A suspend won't happen here, because we're in a syscall from a
  56. * userspace thread. */
  57. kbase_pm_context_active(kbdev);
  58. /* Schedule the context in */
  59. kbasep_js_schedule_privileged_ctx(kbdev, kctx);
  60. err = kbase_instr_hwcnt_enable_internal(kbdev, kctx, setup);
  61. if (err) {
  62. /* Release the context. This had its own Power Manager Active
  63. * reference */
  64. kbasep_js_release_privileged_ctx(kbdev, kctx);
  65. /* Also release our Power Manager Active reference */
  66. kbase_pm_context_idle(kbdev);
  67. }
  68. return err;
  69. }
  70. KBASE_EXPORT_SYMBOL(kbase_instr_hwcnt_enable);
  71. int kbase_instr_hwcnt_disable(struct kbase_context *kctx)
  72. {
  73. int err = -EINVAL;
  74. struct kbase_device *kbdev = kctx->kbdev;
  75. err = kbase_instr_hwcnt_disable_internal(kctx);
  76. if (err)
  77. goto out;
  78. /* Release the context. This had its own Power Manager Active reference
  79. */
  80. kbasep_js_release_privileged_ctx(kbdev, kctx);
  81. /* Also release our Power Manager Active reference */
  82. kbase_pm_context_idle(kbdev);
  83. dev_dbg(kbdev->dev, "HW counters dumping disabled for context %p",
  84. kctx);
  85. out:
  86. return err;
  87. }
  88. KBASE_EXPORT_SYMBOL(kbase_instr_hwcnt_disable);
  89. int kbase_instr_hwcnt_dump(struct kbase_context *kctx)
  90. {
  91. int err;
  92. err = kbase_instr_hwcnt_request_dump(kctx);
  93. if (err)
  94. return err;
  95. err = kbase_instr_hwcnt_wait_for_dump(kctx);
  96. return err;
  97. }
  98. KBASE_EXPORT_SYMBOL(kbase_instr_hwcnt_dump);