bd7a913ebc1017270d0f66254578d0d9846c1a73
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / t6xx / kbase / src / platform / rk / mali_kbase_config_rk.c
1 /*
2  *
3  * (C) COPYRIGHT 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 #include <linux/ioport.h>
21 #include <kbase/src/common/mali_kbase.h>
22 #include <kbase/src/common/mali_kbase_defs.h>
23 #include <kbase/mali_kbase_config.h>
24 #ifdef CONFIG_UMP
25 #include <linux/ump-common.h>
26 #endif                          /* CONFIG_UMP */
27 #include <kbase/src/platform/rk/mali_kbase_platform.h>
28 #include <kbase/src/platform/rk/mali_kbase_dvfs.h>
29 #include <linux/pm_runtime.h>
30 #include <linux/suspend.h>
31
32 int get_cpu_clock_speed(u32 *cpu_clock);
33
34 #define HZ_IN_MHZ                           (1000000)
35 #ifdef CONFIG_MALI_T6XX_RT_PM
36 #define RUNTIME_PM_DELAY_TIME 100
37 #endif
38
39 /* Versatile Express (VE) configuration defaults shared between config_attributes[]
40  * and config_attributes_hw_issue_8408[]. Settings are not shared for
41  * JS_HARD_STOP_TICKS_SS and JS_RESET_TICKS_SS.
42  */
43 #define KBASE_VE_MEMORY_PER_PROCESS_LIMIT       (512 * 1024 * 1024UL)   /* 512MB */
44 #define KBASE_VE_MEMORY_OS_SHARED_MAX           (2048 * 1024 * 1024UL)  /* 768MB */
45 #define KBASE_VE_MEMORY_OS_SHARED_PERF_GPU      KBASE_MEM_PERF_FAST/*KBASE_MEM_PERF_SLOW*/
46 #define KBASE_VE_GPU_FREQ_KHZ_MAX               500000
47 #define KBASE_VE_GPU_FREQ_KHZ_MIN               100000
48 #ifdef CONFIG_UMP
49 #define KBASE_VE_UMP_DEVICE                     UMP_DEVICE_Z_SHIFT
50 #endif                          /* CONFIG_UMP */
51
52 #define KBASE_VE_JS_SCHEDULING_TICK_NS_DEBUG    15000000u      /* 15ms, an agressive tick for testing purposes. This will reduce performance significantly */
53 #define KBASE_VE_JS_SOFT_STOP_TICKS_DEBUG       1       /* between 15ms and 30ms before soft-stop a job */
54 #define KBASE_VE_JS_HARD_STOP_TICKS_SS_DEBUG    333     /* 5s before hard-stop */
55 #define KBASE_VE_JS_HARD_STOP_TICKS_SS_8401_DEBUG 2000  /* 30s before hard-stop, for a certain GLES2 test at 128x128 (bound by combined vertex+tiler job) - for issue 8401 */
56 #define KBASE_VE_JS_HARD_STOP_TICKS_NSS_DEBUG   100000  /* 1500s (25mins) before NSS hard-stop */
57 #define KBASE_VE_JS_RESET_TICKS_SS_DEBUG        500     /* 45s before resetting GPU, for a certain GLES2 test at 128x128 (bound by combined vertex+tiler job) */
58 #define KBASE_VE_JS_RESET_TICKS_SS_8401_DEBUG   3000    /* 7.5s before resetting GPU - for issue 8401 */
59 #define KBASE_VE_JS_RESET_TICKS_NSS_DEBUG       100166  /* 1502s before resetting GPU */
60
61 #define KBASE_VE_JS_SCHEDULING_TICK_NS          2500000000u     /* 2.5s */
62 #define KBASE_VE_JS_SOFT_STOP_TICKS             1       /* 2.5s before soft-stop a job */
63 #define KBASE_VE_JS_HARD_STOP_TICKS_SS          2       /* 5s before hard-stop */
64 #define KBASE_VE_JS_HARD_STOP_TICKS_SS_8401     12      /* 30s before hard-stop, for a certain GLES2 test at 128x128 (bound by combined vertex+tiler job) - for issue 8401 */
65 #define KBASE_VE_JS_HARD_STOP_TICKS_NSS         600     /* 1500s before NSS hard-stop */
66 #define KBASE_VE_JS_RESET_TICKS_SS              3       /* 7.5s before resetting GPU */
67 #define KBASE_VE_JS_RESET_TICKS_SS_8401         18      /* 45s before resetting GPU, for a certain GLES2 test at 128x128 (bound by combined vertex+tiler job) - for issue 8401 */
68 #define KBASE_VE_JS_RESET_TICKS_NSS             601     /* 1502s before resetting GPU */
69
70 #define KBASE_VE_JS_RESET_TIMEOUT_MS            500     /* 3s before cancelling stuck jobs */
71 #define KBASE_VE_JS_CTX_TIMESLICE_NS            1000000 /* 1ms - an agressive timeslice for testing purposes (causes lots of scheduling out for >4 ctxs) */
72 #define KBASE_VE_SECURE_BUT_LOSS_OF_PERFORMANCE ((uintptr_t)MALI_FALSE) /* By default we prefer performance over security on r0p0-15dev0 and KBASE_CONFIG_ATTR_ earlier */
73 //#define KBASE_VE_POWER_MANAGEMENT_CALLBACKS     ((uintptr_t)&pm_callbacks)
74 #define KBASE_VE_CPU_SPEED_FUNC                 ((uintptr_t)&get_cpu_clock_speed)
75
76 static int mali_pm_notifier(struct notifier_block *nb,unsigned long event,void* cmd);
77 static struct notifier_block mali_pm_nb = {
78         .notifier_call = mali_pm_notifier
79 };
80
81 #ifndef CONFIG_OF
82 static kbase_io_resources io_resources = {
83         .job_irq_number = 68,
84         .mmu_irq_number = 69,
85         .gpu_irq_number = 70,
86         .io_memory_region = {
87                              .start = 0xFC010000,
88                              .end = 0xFC010000 + (4096 * 5) - 1}
89 };
90 #endif
91 int get_cpu_clock_speed(u32 *cpu_clock)
92 {
93 #if 0
94         struct clk *cpu_clk;
95         u32 freq = 0;
96         cpu_clk = clk_get(NULL, "armclk");
97         if (IS_ERR(cpu_clk))
98                 return 1;
99         freq = clk_get_rate(cpu_clk);
100         *cpu_clock = (freq / HZ_IN_MHZ);
101 #endif
102         return 0;
103 }
104
105 static int mali_pm_notifier(struct notifier_block *nb,unsigned long event,void* cmd)
106 {
107         int err = NOTIFY_OK;
108         switch (event) {
109                 case PM_SUSPEND_PREPARE:
110 #ifdef CONFIG_MALI_T6XX_DVFS
111                         if (kbase_platform_dvfs_enable(false, MALI_DVFS_BL_CONFIG_FREQ)!= MALI_TRUE)
112                                 err = NOTIFY_BAD;
113 #endif
114                         break;
115                 case PM_POST_SUSPEND:
116 #ifdef CONFIG_MALI_T6XX_DVFS
117                         if (kbase_platform_dvfs_enable(true, MALI_DVFS_START_FREQ)!= MALI_TRUE)
118                                 err = NOTIFY_BAD;
119 #endif
120                         break;
121                 default:
122                         break;
123         }
124         return err;
125 }
126
127 /*
128   rk3288 hardware specific initialization
129  */
130 mali_bool kbase_platform_rk_init(kbase_device *kbdev)
131 {
132         if(MALI_ERROR_NONE == kbase_platform_init(kbdev))
133         {
134                 if (register_pm_notifier(&mali_pm_nb)) {
135                         return MALI_FALSE;
136                 }
137                 return MALI_TRUE;
138         }
139         return MALI_FALSE;
140 }
141
142 /*
143  rk3288  hardware specific termination
144 */
145 void kbase_platform_rk_term(kbase_device *kbdev)
146 {
147         unregister_pm_notifier(&mali_pm_nb);
148 #ifdef CONFIG_MALI_T6XX_DEBUG_SYS
149         kbase_platform_remove_sysfs_file(kbdev->osdev.dev);
150 #endif                          /* CONFIG_MALI_T6XX_DEBUG_SYS */
151         kbase_platform_term(kbdev);
152 }
153
154 kbase_platform_funcs_conf platform_funcs = {
155         .platform_init_func = &kbase_platform_rk_init,
156         .platform_term_func = &kbase_platform_rk_term,
157 };
158
159 #ifdef CONFIG_MALI_T6XX_RT_PM
160 static int pm_callback_power_on(kbase_device *kbdev)
161 {
162         int result;
163         int ret_val;
164         struct kbase_os_device *osdev = &kbdev->osdev;
165         struct rk_context *platform;
166
167         platform = (struct rk_context *)kbdev->platform_context;
168
169         if (pm_runtime_status_suspended(osdev->dev))
170                 ret_val = 1;
171         else
172                 ret_val = 0;
173
174         if(osdev->dev->power.disable_depth > 0) {
175                 if(platform->cmu_pmu_status == 0)
176                         kbase_platform_cmu_pmu_control(kbdev, 1);
177                 return ret_val;
178         }
179         result = pm_runtime_resume(osdev->dev);
180
181         if (result < 0 && result == -EAGAIN)
182                 kbase_platform_cmu_pmu_control(kbdev, 1);
183         else if (result < 0)
184                 printk(KERN_ERR "pm_runtime_get_sync failed (%d)\n", result);
185
186         return ret_val;
187 }
188
189 static void pm_callback_power_off(kbase_device *kbdev)
190 {
191         struct kbase_os_device *osdev = &kbdev->osdev;
192         pm_schedule_suspend(osdev->dev, RUNTIME_PM_DELAY_TIME);
193 }
194
195 mali_error kbase_device_runtime_init(struct kbase_device *kbdev)
196 {
197         pm_suspend_ignore_children(kbdev->osdev.dev, true);
198         pm_runtime_enable(kbdev->osdev.dev);
199 #ifdef CONFIG_MALI_T6XX_DEBUG_SYS
200         if (kbase_platform_create_sysfs_file(kbdev->osdev.dev))
201                 return MALI_ERROR_FUNCTION_FAILED;
202 #endif                          /* CONFIG_MALI_T6XX_DEBUG_SYS */
203         return MALI_ERROR_NONE;
204 }
205
206 void kbase_device_runtime_disable(struct kbase_device *kbdev)
207 {
208         pm_runtime_disable(kbdev->osdev.dev);
209 }
210
211 static int pm_callback_runtime_on(kbase_device *kbdev)
212 {
213 #ifdef CONFIG_MALI_T6XX_DVFS    
214         struct rk_context *platform = (struct rk_context *)kbdev->platform_context;
215 #endif
216         kbase_platform_clock_on(kbdev);
217 #ifdef CONFIG_MALI_T6XX_DVFS
218         if (platform->dvfs_enabled) {
219                 if (kbase_platform_dvfs_enable(true, MALI_DVFS_START_FREQ)!= MALI_TRUE)
220                         return -EPERM;
221         } else {
222                 if (kbase_platform_dvfs_enable(false, MALI_DVFS_CURRENT_FREQ)!= MALI_TRUE)
223                         return -EPERM;
224         }
225 #endif  
226         return 0;
227 }
228
229 static void pm_callback_runtime_off(kbase_device *kbdev)
230 {
231         kbase_platform_clock_off(kbdev);
232 #ifdef CONFIG_MALI_T6XX_DVFS
233         if (kbase_platform_dvfs_enable(false, MALI_DVFS_CURRENT_FREQ)!= MALI_TRUE)
234                 printk("[err] disabling dvfs is faled\n");
235 #endif
236 }
237
238 static kbase_pm_callback_conf pm_callbacks = {
239         .power_on_callback = pm_callback_power_on,
240         .power_off_callback = pm_callback_power_off,
241 #ifdef CONFIG_PM_RUNTIME
242         .power_runtime_init_callback = kbase_device_runtime_init,
243         .power_runtime_term_callback = kbase_device_runtime_disable,
244         .power_runtime_on_callback = pm_callback_runtime_on,
245         .power_runtime_off_callback = pm_callback_runtime_off,
246
247 #else                           /* CONFIG_PM_RUNTIME */
248         .power_runtime_init_callback = NULL,
249         .power_runtime_term_callback = NULL,
250         .power_runtime_on_callback = NULL,
251         .power_runtime_off_callback = NULL,
252
253 #endif                          /* CONFIG_PM_RUNTIME */
254 };
255 #endif
256
257
258 /* Please keep table config_attributes in sync with config_attributes_hw_issue_8408 */
259 static kbase_attribute config_attributes[] = {
260 #if 0
261         {
262          KBASE_CONFIG_ATTR_MEMORY_PER_PROCESS_LIMIT,
263          KBASE_VE_MEMORY_PER_PROCESS_LIMIT},
264 #endif
265 #ifdef CONFIG_UMP
266         {
267          KBASE_CONFIG_ATTR_UMP_DEVICE,
268          KBASE_VE_UMP_DEVICE},
269 #endif                          /* CONFIG_UMP */
270 #ifdef CONFIG_MALI_T6XX_RT_PM
271         {
272          KBASE_CONFIG_ATTR_POWER_MANAGEMENT_CALLBACKS,
273          (uintptr_t)&pm_callbacks},
274 #endif
275 #if 0
276         {
277          KBASE_CONFIG_ATTR_MEMORY_OS_SHARED_MAX,
278          KBASE_VE_MEMORY_OS_SHARED_MAX},
279 #endif
280 #if 1
281         {
282          KBASE_CONFIG_ATTR_MEMORY_OS_SHARED_PERF_GPU,
283          KBASE_VE_MEMORY_OS_SHARED_PERF_GPU},
284 #endif
285         {
286          KBASE_CONFIG_ATTR_PLATFORM_FUNCS,
287          (uintptr_t) &platform_funcs},
288         
289         {
290          KBASE_CONFIG_ATTR_GPU_FREQ_KHZ_MAX,
291          KBASE_VE_GPU_FREQ_KHZ_MAX},
292
293         {
294          KBASE_CONFIG_ATTR_GPU_FREQ_KHZ_MIN,
295          KBASE_VE_GPU_FREQ_KHZ_MIN},
296
297 #ifdef CONFIG_MALI_DEBUG
298 /* Use more aggressive scheduling timeouts in debug builds for testing purposes */
299         {
300          KBASE_CONFIG_ATTR_JS_SCHEDULING_TICK_NS,
301          KBASE_VE_JS_SCHEDULING_TICK_NS_DEBUG},
302
303         {
304          KBASE_CONFIG_ATTR_JS_SOFT_STOP_TICKS,
305          KBASE_VE_JS_SOFT_STOP_TICKS_DEBUG},
306
307         {
308          KBASE_CONFIG_ATTR_JS_HARD_STOP_TICKS_SS,
309          KBASE_VE_JS_HARD_STOP_TICKS_SS_DEBUG},
310
311         {
312          KBASE_CONFIG_ATTR_JS_HARD_STOP_TICKS_NSS,
313          KBASE_VE_JS_HARD_STOP_TICKS_NSS_DEBUG},
314
315         {
316          KBASE_CONFIG_ATTR_JS_RESET_TICKS_SS,
317          KBASE_VE_JS_RESET_TICKS_SS_DEBUG},
318
319         {
320          KBASE_CONFIG_ATTR_JS_RESET_TICKS_NSS,
321          KBASE_VE_JS_RESET_TICKS_NSS_DEBUG},
322 #else                           /* CONFIG_MALI_DEBUG */
323 /* In release builds same as the defaults but scaled for 5MHz FPGA */
324 #if 0
325         {
326          KBASE_CONFIG_ATTR_JS_SCHEDULING_TICK_NS,
327          KBASE_VE_JS_SCHEDULING_TICK_NS},
328 #endif
329 #if 0
330         {
331          KBASE_CONFIG_ATTR_JS_SOFT_STOP_TICKS,
332          KBASE_VE_JS_SOFT_STOP_TICKS},
333 #endif
334 #if 0
335         {
336          KBASE_CONFIG_ATTR_JS_HARD_STOP_TICKS_SS,
337          KBASE_VE_JS_HARD_STOP_TICKS_SS},
338 #endif
339 #if 0
340         {
341          KBASE_CONFIG_ATTR_JS_HARD_STOP_TICKS_NSS,
342          KBASE_VE_JS_HARD_STOP_TICKS_NSS},
343 #endif
344 #if 0
345         {
346          KBASE_CONFIG_ATTR_JS_RESET_TICKS_SS,
347          KBASE_VE_JS_RESET_TICKS_SS},
348 #endif
349 #if 0 
350         {
351          KBASE_CONFIG_ATTR_JS_RESET_TICKS_NSS,
352          KBASE_VE_JS_RESET_TICKS_NSS},
353 #endif
354 #endif                          /* CONFIG_MALI_DEBUG */
355 #if 1
356         {
357          KBASE_CONFIG_ATTR_JS_RESET_TIMEOUT_MS,
358          KBASE_VE_JS_RESET_TIMEOUT_MS},
359 #endif
360 #if 0
361         {
362          KBASE_CONFIG_ATTR_JS_CTX_TIMESLICE_NS,
363          KBASE_VE_JS_CTX_TIMESLICE_NS},
364 #endif
365 #if 0
366         {
367          KBASE_CONFIG_ATTR_CPU_SPEED_FUNC,
368          KBASE_VE_CPU_SPEED_FUNC},
369 #endif
370 #if 0
371         {
372          KBASE_CONFIG_ATTR_SECURE_BUT_LOSS_OF_PERFORMANCE,
373          KBASE_VE_SECURE_BUT_LOSS_OF_PERFORMANCE},
374 #endif
375 #if 0
376         {
377          KBASE_CONFIG_ATTR_GPU_IRQ_THROTTLE_TIME_US,
378          20},
379 #endif
380         {
381          KBASE_CONFIG_ATTR_END,
382          0}
383 };
384
385 static kbase_platform_config rk_platform_config = {
386         .attributes = config_attributes,
387 #ifndef CONFIG_OF
388         .io_resources = &io_resources
389 #endif
390 };
391 #if 1
392 kbase_platform_config *kbase_get_platform_config(void)
393 {
394         return &rk_platform_config;
395 }
396 #endif
397 int kbase_platform_early_init(void)
398 {
399         /* Nothing needed at this stage */
400         return 0;
401 }