MALI: rockchip: upgrade DDK to r8p0-02rel0.
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / mali_kbase_instr.c
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
17
18
19
20 /*
21  * Base kernel instrumentation APIs.
22  */
23
24 #include <mali_kbase.h>
25 #include <mali_midg_regmap.h>
26
27 void kbase_instr_hwcnt_suspend(struct kbase_device *kbdev)
28 {
29         struct kbase_context *kctx;
30
31         KBASE_DEBUG_ASSERT(kbdev);
32         KBASE_DEBUG_ASSERT(!kbdev->hwcnt.suspended_kctx);
33
34         kctx = kbdev->hwcnt.kctx;
35         kbdev->hwcnt.suspended_kctx = kctx;
36
37         /* Relevant state was saved into hwcnt.suspended_state when enabling the
38          * counters */
39
40         if (kctx) {
41                 KBASE_DEBUG_ASSERT(kctx->jctx.sched_info.ctx.flags &
42                                                 KBASE_CTX_FLAG_PRIVILEGED);
43                 kbase_instr_hwcnt_disable(kctx);
44         }
45 }
46
47 void kbase_instr_hwcnt_resume(struct kbase_device *kbdev)
48 {
49         struct kbase_context *kctx;
50
51         KBASE_DEBUG_ASSERT(kbdev);
52
53         kctx = kbdev->hwcnt.suspended_kctx;
54         kbdev->hwcnt.suspended_kctx = NULL;
55
56         if (kctx) {
57                 int err;
58
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");
62         }
63 }
64
65 int kbase_instr_hwcnt_enable(struct kbase_context *kctx,
66                 struct kbase_uk_hwcnt_setup *setup)
67 {
68         struct kbase_device *kbdev;
69         int err;
70
71         kbdev = kctx->kbdev;
72
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);
77
78         /* Schedule the context in */
79         kbasep_js_schedule_privileged_ctx(kbdev, kctx);
80         err = kbase_instr_hwcnt_enable_internal(kbdev, kctx, setup);
81         if (err) {
82                 /* Release the context. This had its own Power Manager Active
83                  * reference */
84                 kbasep_js_release_privileged_ctx(kbdev, kctx);
85
86                 /* Also release our Power Manager Active reference */
87                 kbase_pm_context_idle(kbdev);
88         }
89
90         return err;
91 }
92 KBASE_EXPORT_SYMBOL(kbase_instr_hwcnt_enable);
93
94 int kbase_instr_hwcnt_disable(struct kbase_context *kctx)
95 {
96         int err = -EINVAL;
97         struct kbase_device *kbdev = kctx->kbdev;
98
99         err = kbase_instr_hwcnt_disable_internal(kctx);
100         if (err)
101                 goto out;
102
103         /* Release the context. This had its own Power Manager Active reference
104          */
105         kbasep_js_release_privileged_ctx(kbdev, kctx);
106
107         /* Also release our Power Manager Active reference */
108         kbase_pm_context_idle(kbdev);
109
110         dev_dbg(kbdev->dev, "HW counters dumping disabled for context %p",
111                                                                         kctx);
112 out:
113         return err;
114 }
115 KBASE_EXPORT_SYMBOL(kbase_instr_hwcnt_disable);
116
117 int kbase_instr_hwcnt_dump(struct kbase_context *kctx)
118 {
119         int err;
120
121         err = kbase_instr_hwcnt_request_dump(kctx);
122         if (err)
123                 return err;
124
125         err = kbase_instr_hwcnt_wait_for_dump(kctx);
126         return err;
127 }
128 KBASE_EXPORT_SYMBOL(kbase_instr_hwcnt_dump);
129