tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / mali / linux / mali_osk_profiling.c
1 /*
2  * Copyright (C) 2011-2012 ARM Limited. All rights reserved.
3  *
4  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
6  *
7  * A copy of the licence is included with the program, and can also be obtained from Free Software
8  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
9  */
10
11 #include <linux/module.h>
12
13 #include "mali_kernel_common.h"
14 #include "mali_osk.h"
15 #include "mali_ukk.h"
16 #include "mali_uk_types.h"
17 #include "mali_osk_profiling.h"
18 #include "mali_linux_trace.h"
19 #include "mali_gp.h"
20 #include "mali_pp.h"
21 #include "mali_l2_cache.h"
22 #include "mali_user_settings_db.h"
23
24 _mali_osk_errcode_t _mali_osk_profiling_init(mali_bool auto_start)
25 {
26         if (MALI_TRUE == auto_start)
27         {
28                 mali_set_user_setting(_MALI_UK_USER_SETTING_SW_EVENTS_ENABLE, MALI_TRUE);
29         }
30
31         return _MALI_OSK_ERR_OK;
32 }
33
34 void _mali_osk_profiling_term(void)
35 {
36         /* Nothing to do */
37 }
38
39 _mali_osk_errcode_t _mali_osk_profiling_start(u32 * limit)
40 {
41         /* Nothing to do */
42         return _MALI_OSK_ERR_OK;
43 }
44
45 _mali_osk_errcode_t _mali_osk_profiling_stop(u32 *count)
46 {
47         /* Nothing to do */
48         return _MALI_OSK_ERR_OK;
49 }
50
51 u32 _mali_osk_profiling_get_count(void)
52 {
53         return 0;
54 }
55
56 _mali_osk_errcode_t _mali_osk_profiling_get_event(u32 index, u64* timestamp, u32* event_id, u32 data[5])
57 {
58         /* Nothing to do */
59         return _MALI_OSK_ERR_OK;
60 }
61
62 _mali_osk_errcode_t _mali_osk_profiling_clear(void)
63 {
64         /* Nothing to do */
65         return _MALI_OSK_ERR_OK;
66 }
67
68 mali_bool _mali_osk_profiling_is_recording(void)
69 {
70         return MALI_FALSE;
71 }
72
73 mali_bool _mali_osk_profiling_have_recording(void)
74 {
75         return MALI_FALSE;
76 }
77
78 void _mali_osk_profiling_report_sw_counters(u32 *counters)
79 {
80         trace_mali_sw_counters(_mali_osk_get_pid(), _mali_osk_get_tid(), NULL, counters);
81 }
82
83
84 _mali_osk_errcode_t _mali_ukk_profiling_start(_mali_uk_profiling_start_s *args)
85 {
86         return _mali_osk_profiling_start(&args->limit);
87 }
88
89 _mali_osk_errcode_t _mali_ukk_profiling_add_event(_mali_uk_profiling_add_event_s *args)
90 {
91         /* Always add process and thread identificator in the first two data elements for events from user space */
92         _mali_osk_profiling_add_event(args->event_id, _mali_osk_get_pid(), _mali_osk_get_tid(), args->data[2], args->data[3], args->data[4]);
93
94         return _MALI_OSK_ERR_OK;
95 }
96
97 _mali_osk_errcode_t _mali_ukk_profiling_stop(_mali_uk_profiling_stop_s *args)
98 {
99         return _mali_osk_profiling_stop(&args->count);
100 }
101
102 _mali_osk_errcode_t _mali_ukk_profiling_get_event(_mali_uk_profiling_get_event_s *args)
103 {
104         return _mali_osk_profiling_get_event(args->index, &args->timestamp, &args->event_id, args->data);
105 }
106
107 _mali_osk_errcode_t _mali_ukk_profiling_clear(_mali_uk_profiling_clear_s *args)
108 {
109         return _mali_osk_profiling_clear();
110 }
111
112 _mali_osk_errcode_t _mali_ukk_sw_counters_report(_mali_uk_sw_counters_report_s *args)
113 {
114         _mali_osk_profiling_report_sw_counters(args->counters);
115         return _MALI_OSK_ERR_OK;
116 }
117
118 /**
119  * Called by gator.ko to set HW counters
120  *
121  * @param counter_id The counter ID.
122  * @param event_id Event ID that the counter should count (HW counter value from TRM).
123  * 
124  * @return 1 on success, 0 on failure.
125  */
126 int _mali_profiling_set_event(u32 counter_id, s32 event_id)
127 {
128         if (COUNTER_VP_C0 == counter_id)
129         {
130                 if (MALI_TRUE == mali_gp_job_set_gp_counter_src0(event_id))
131                 {
132                         return 1;
133                 }
134         }
135         if (COUNTER_VP_C1 == counter_id)
136         {
137                 if (MALI_TRUE == mali_gp_job_set_gp_counter_src1(event_id))
138                 {
139                         return 1;
140                 }
141         }
142         if (COUNTER_FP0_C0 <= counter_id && COUNTER_FP3_C1 >= counter_id)
143         {
144                 u32 core_id = (counter_id - COUNTER_FP0_C0) >> 1;
145                 struct mali_pp_core* pp_core = mali_pp_get_global_pp_core(core_id);
146
147                 if (NULL != pp_core)
148                 {
149                         if ((COUNTER_FP0_C0 == counter_id) || (COUNTER_FP0_C1 == counter_id))
150                         {
151                                 u32 counter_src = (counter_id - COUNTER_FP0_C0) & 1;
152                                 if (0 == counter_src)
153                                 {
154                                         if (MALI_TRUE == mali_pp_job_set_pp_counter_src0(event_id))
155                                         {
156                                                 return 1;
157                                         }
158                                 }
159                                 else
160                                 {
161                                         if (MALI_TRUE == mali_pp_job_set_pp_counter_src1(event_id))
162                                         {
163                                         MALI_DEBUG_PRINT(5, ("MALI PROFILING SET EVENT core 0 counter_id = %d\n",counter_id));
164                                         return 1;
165                                         }
166                                 }
167                         }
168                 }
169         }
170         if (COUNTER_L2_C0 <= counter_id && COUNTER_L2_C1 >= counter_id)
171         {
172                 u32 core_id = (counter_id - COUNTER_L2_C0) >> 1;
173                 struct mali_l2_cache_core* l2_cache_core = mali_l2_cache_core_get_glob_l2_core(core_id);
174
175                 if (NULL != l2_cache_core)
176                 {
177                         u32 counter_src = (counter_id - COUNTER_L2_C0) & 1;
178                         if (0 == counter_src)
179                         {
180                                 MALI_DEBUG_PRINT(5, ("SET EVENT L2 0 COUNTER\n"));
181                                 if (MALI_TRUE == mali_l2_cache_core_set_counter_src0(l2_cache_core, event_id))
182                                 {
183                                         return 1;
184                                 }
185                         }
186                         else
187                         {
188                                 MALI_DEBUG_PRINT(5, ("SET EVENT L2 1 COUNTER\n"));
189                                 if (MALI_TRUE == mali_l2_cache_core_set_counter_src1(l2_cache_core, event_id))
190                                 {
191                                         return 1;
192                                 }
193                         }
194                 }
195         }
196
197         return 0;
198 }
199
200 /**
201  * Called by gator.ko to retrieve the L2 cache counter values for the first L2 cache. 
202  * The L2 cache counters are unique in that they are polled by gator, rather than being
203  * transmitted via the tracepoint mechanism. 
204  *
205  * @param src0 First L2 cache counter ID.
206  * @param val0 First L2 cache counter value.
207  * @param src1 Second L2 cache counter ID.
208  * @param val1 Second L2 cache counter value.
209  */
210 void _mali_profiling_get_counters(u32 *src0, u32 *val0, u32 *src1, u32 *val1)
211 {
212          struct mali_l2_cache_core *l2_cache = mali_l2_cache_core_get_glob_l2_core(0);
213          if (NULL != l2_cache)
214          {
215                 if (MALI_TRUE == mali_l2_cache_lock_power_state(l2_cache))
216                 {
217                         /* It is now safe to access the L2 cache core in order to retrieve the counters */
218                         mali_l2_cache_core_get_counter_values(l2_cache, src0, val0, src1, val1);
219                 }
220                 mali_l2_cache_unlock_power_state(l2_cache);
221          }
222 }
223
224 /*
225  * List of possible actions to be controlled by Streamline.
226  * The following numbers are used by gator to control the frame buffer dumping and s/w counter reporting.
227  * We cannot use the enums in mali_uk_types.h because they are unknown inside gator.
228  */
229 #define FBDUMP_CONTROL_ENABLE (1)
230 #define FBDUMP_CONTROL_RATE (2)
231 #define SW_COUNTER_ENABLE (3)
232 #define FBDUMP_CONTROL_RESIZE_FACTOR (4)
233
234 /**
235  * Called by gator to control the production of profiling information at runtime.
236  */
237 void _mali_profiling_control(u32 action, u32 value)
238 {
239         switch(action)
240         {
241         case FBDUMP_CONTROL_ENABLE:
242                 mali_set_user_setting(_MALI_UK_USER_SETTING_COLORBUFFER_CAPTURE_ENABLED, (value == 0 ? MALI_FALSE : MALI_TRUE));
243                 break;
244         case FBDUMP_CONTROL_RATE:
245                 mali_set_user_setting(_MALI_UK_USER_SETTING_BUFFER_CAPTURE_N_FRAMES, value);
246                 break;
247         case SW_COUNTER_ENABLE:
248                 mali_set_user_setting(_MALI_UK_USER_SETTING_SW_COUNTER_ENABLED, value);
249                 break;
250         case FBDUMP_CONTROL_RESIZE_FACTOR:
251                 mali_set_user_setting(_MALI_UK_USER_SETTING_BUFFER_CAPTURE_RESIZE_FACTOR, value);
252                 break;
253         default:
254                 break;  /* Ignore unimplemented actions */
255         }
256 }
257
258 EXPORT_SYMBOL(_mali_profiling_set_event);
259 EXPORT_SYMBOL(_mali_profiling_get_counters);
260 EXPORT_SYMBOL(_mali_profiling_control);