3 * (C) COPYRIGHT 2011-2015 ARM Limited. All rights reserved.
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
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.
21 * Base kernel instrumentation APIs.
24 #include <mali_kbase.h>
25 #include <mali_midg_regmap.h>
27 void kbase_instr_hwcnt_suspend(struct kbase_device *kbdev)
29 struct kbase_context *kctx;
31 KBASE_DEBUG_ASSERT(kbdev);
32 KBASE_DEBUG_ASSERT(!kbdev->hwcnt.suspended_kctx);
34 kctx = kbdev->hwcnt.kctx;
35 kbdev->hwcnt.suspended_kctx = kctx;
37 /* Relevant state was saved into hwcnt.suspended_state when enabling the
41 KBASE_DEBUG_ASSERT(kctx->jctx.sched_info.ctx.flags &
42 KBASE_CTX_FLAG_PRIVILEGED);
43 kbase_instr_hwcnt_disable(kctx);
47 void kbase_instr_hwcnt_resume(struct kbase_device *kbdev)
49 struct kbase_context *kctx;
51 KBASE_DEBUG_ASSERT(kbdev);
53 kctx = kbdev->hwcnt.suspended_kctx;
54 kbdev->hwcnt.suspended_kctx = NULL;
59 err = kbase_instr_hwcnt_enable_internal(kbdev, kctx,
60 &kbdev->hwcnt.suspended_state);
61 WARN(err, "Failed to restore instrumented hardware counters on resume\n");
65 int kbase_instr_hwcnt_enable(struct kbase_context *kctx,
66 struct kbase_uk_hwcnt_setup *setup)
68 struct kbase_device *kbdev;
73 /* Mark the context as active so the GPU is kept turned on */
74 /* A suspend won't happen here, because we're in a syscall from a
75 * userspace thread. */
76 kbase_pm_context_active(kbdev);
78 /* Schedule the context in */
79 kbasep_js_schedule_privileged_ctx(kbdev, kctx);
80 err = kbase_instr_hwcnt_enable_internal(kbdev, kctx, setup);
82 /* Release the context. This had its own Power Manager Active
84 kbasep_js_release_privileged_ctx(kbdev, kctx);
86 /* Also release our Power Manager Active reference */
87 kbase_pm_context_idle(kbdev);
92 KBASE_EXPORT_SYMBOL(kbase_instr_hwcnt_enable);
94 int kbase_instr_hwcnt_disable(struct kbase_context *kctx)
97 struct kbase_device *kbdev = kctx->kbdev;
99 err = kbase_instr_hwcnt_disable_internal(kctx);
103 /* Release the context. This had its own Power Manager Active reference
105 kbasep_js_release_privileged_ctx(kbdev, kctx);
107 /* Also release our Power Manager Active reference */
108 kbase_pm_context_idle(kbdev);
110 dev_dbg(kbdev->dev, "HW counters dumping disabled for context %p",
115 KBASE_EXPORT_SYMBOL(kbase_instr_hwcnt_disable);
117 int kbase_instr_hwcnt_dump(struct kbase_context *kctx)
121 err = kbase_instr_hwcnt_request_dump(kctx);
125 err = kbase_instr_hwcnt_wait_for_dump(kctx);
128 KBASE_EXPORT_SYMBOL(kbase_instr_hwcnt_dump);