3 * (C) COPYRIGHT 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.
20 #include <linux/ioport.h>
21 #include <mali_kbase.h>
22 #include <mali_kbase_defs.h>
23 #include <mali_kbase_config.h>
25 #include <linux/ump-common.h>
26 #endif /* CONFIG_UMP */
27 #include <platform/rk/mali_kbase_platform.h>
28 #include <platform/rk/mali_kbase_dvfs.h>
29 #include <linux/pm_runtime.h>
30 #include <linux/suspend.h>
32 int get_cpu_clock_speed(u32 *cpu_clock);
34 #define HZ_IN_MHZ (1000000)
35 #ifdef CONFIG_MALI_MIDGARD_RT_PM
36 #define RUNTIME_PM_DELAY_TIME 100
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.
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
49 #define KBASE_VE_UMP_DEVICE UMP_DEVICE_Z_SHIFT
50 #endif /* CONFIG_UMP */
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 */
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 */
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)
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
82 static kbase_io_resources io_resources = {
88 .end = 0xFC010000 + (4096 * 5) - 1}
91 int get_cpu_clock_speed(u32 *cpu_clock)
96 cpu_clk = clk_get(NULL, "armclk");
99 freq = clk_get_rate(cpu_clk);
100 *cpu_clock = (freq / HZ_IN_MHZ);
105 static int mali_pm_notifier(struct notifier_block *nb,unsigned long event,void* cmd)
109 case PM_SUSPEND_PREPARE:
110 #ifdef CONFIG_MALI_MIDGARD_DVFS
111 //if (kbase_platform_dvfs_enable(false, MALI_DVFS_BL_CONFIG_FREQ)!= MALI_TRUE)
112 if (kbase_platform_dvfs_enable(false, p_mali_dvfs_infotbl[0].clock)!= MALI_TRUE)
116 case PM_POST_SUSPEND:
117 #ifdef CONFIG_MALI_MIDGARD_DVFS
118 //if (kbase_platform_dvfs_enable(true, MALI_DVFS_START_FREQ)!= MALI_TRUE)
119 if (kbase_platform_dvfs_enable(true, p_mali_dvfs_infotbl[0].clock)!= MALI_TRUE)
130 rk3288 hardware specific initialization
132 mali_bool kbase_platform_rk_init(kbase_device *kbdev)
134 if(MALI_ERROR_NONE == kbase_platform_init(kbdev))
136 if (register_pm_notifier(&mali_pm_nb)) {
145 rk3288 hardware specific termination
147 void kbase_platform_rk_term(kbase_device *kbdev)
149 unregister_pm_notifier(&mali_pm_nb);
150 #ifdef CONFIG_MALI_MIDGARD_DEBUG_SYS
151 kbase_platform_remove_sysfs_file(kbdev->dev);
152 #endif /* CONFIG_MALI_MIDGARD_DEBUG_SYS */
153 kbase_platform_term(kbdev);
156 kbase_platform_funcs_conf platform_funcs = {
157 .platform_init_func = &kbase_platform_rk_init,
158 .platform_term_func = &kbase_platform_rk_term,
161 #ifdef CONFIG_MALI_MIDGARD_RT_PM
162 static int pm_callback_power_on(kbase_device *kbdev)
166 struct device *dev = kbdev->dev;
167 struct rk_context *platform;
169 platform = (struct rk_context *)kbdev->platform_context;
171 if (pm_runtime_status_suspended(dev))
176 if(dev->power.disable_depth > 0) {
177 if(platform->cmu_pmu_status == 0)
178 kbase_platform_cmu_pmu_control(kbdev, 1);
181 result = pm_runtime_resume(dev);
183 if (result < 0 && result == -EAGAIN)
184 kbase_platform_cmu_pmu_control(kbdev, 1);
186 printk(KERN_ERR "pm_runtime_get_sync failed (%d)\n", result);
191 static void pm_callback_power_off(kbase_device *kbdev)
193 struct device *dev = kbdev->dev;
194 pm_schedule_suspend(dev, RUNTIME_PM_DELAY_TIME);
197 mali_error kbase_device_runtime_init(struct kbase_device *kbdev)
199 pm_suspend_ignore_children(kbdev->dev, true);
200 pm_runtime_enable(kbdev->dev);
201 #ifdef CONFIG_MALI_MIDGARD_DEBUG_SYS
202 if (kbase_platform_create_sysfs_file(kbdev->dev))
203 return MALI_ERROR_FUNCTION_FAILED;
204 #endif /* CONFIG_MALI_MIDGARD_DEBUG_SYS */
205 return MALI_ERROR_NONE;
208 void kbase_device_runtime_disable(struct kbase_device *kbdev)
210 pm_runtime_disable(kbdev->dev);
213 static int pm_callback_runtime_on(kbase_device *kbdev)
215 #ifdef CONFIG_MALI_MIDGARD_DVFS
216 struct rk_context *platform = (struct rk_context *)kbdev->platform_context;
218 kbase_platform_clock_on(kbdev);
219 #ifdef CONFIG_MALI_MIDGARD_DVFS
220 if (platform->dvfs_enabled) {
221 //if (kbase_platform_dvfs_enable(true, MALI_DVFS_START_FREQ)!= MALI_TRUE)
222 if (kbase_platform_dvfs_enable(true, p_mali_dvfs_infotbl[MALI_DVFS_STEP-1].clock)!= MALI_TRUE)
225 if (kbase_platform_dvfs_enable(false, MALI_DVFS_CURRENT_FREQ)!= MALI_TRUE)
232 static void pm_callback_runtime_off(kbase_device *kbdev)
234 kbase_platform_clock_off(kbdev);
235 #ifdef CONFIG_MALI_MIDGARD_DVFS
236 if (kbase_platform_dvfs_enable(false, MALI_DVFS_CURRENT_FREQ)!= MALI_TRUE)
237 printk("[err] disabling dvfs is faled\n");
241 static kbase_pm_callback_conf pm_callbacks = {
242 .power_on_callback = pm_callback_power_on,
243 .power_off_callback = pm_callback_power_off,
244 #ifdef CONFIG_PM_RUNTIME
245 .power_runtime_init_callback = kbase_device_runtime_init,
246 .power_runtime_term_callback = kbase_device_runtime_disable,
247 .power_runtime_on_callback = pm_callback_runtime_on,
248 .power_runtime_off_callback = pm_callback_runtime_off,
250 #else /* CONFIG_PM_RUNTIME */
251 .power_runtime_init_callback = NULL,
252 .power_runtime_term_callback = NULL,
253 .power_runtime_on_callback = NULL,
254 .power_runtime_off_callback = NULL,
256 #endif /* CONFIG_PM_RUNTIME */
261 /* Please keep table config_attributes in sync with config_attributes_hw_issue_8408 */
262 static kbase_attribute config_attributes[] = {
265 KBASE_CONFIG_ATTR_MEMORY_PER_PROCESS_LIMIT,
266 KBASE_VE_MEMORY_PER_PROCESS_LIMIT},
270 KBASE_CONFIG_ATTR_UMP_DEVICE,
271 KBASE_VE_UMP_DEVICE},
272 #endif /* CONFIG_UMP */
273 #ifdef CONFIG_MALI_MIDGARD_RT_PM
275 KBASE_CONFIG_ATTR_POWER_MANAGEMENT_CALLBACKS,
276 (uintptr_t)&pm_callbacks},
280 KBASE_CONFIG_ATTR_MEMORY_OS_SHARED_MAX,
281 KBASE_VE_MEMORY_OS_SHARED_MAX},
285 KBASE_CONFIG_ATTR_MEMORY_OS_SHARED_PERF_GPU,
286 KBASE_VE_MEMORY_OS_SHARED_PERF_GPU},
289 KBASE_CONFIG_ATTR_PLATFORM_FUNCS,
290 (uintptr_t) &platform_funcs},
293 KBASE_CONFIG_ATTR_GPU_FREQ_KHZ_MAX,
294 KBASE_VE_GPU_FREQ_KHZ_MAX},
297 KBASE_CONFIG_ATTR_GPU_FREQ_KHZ_MIN,
298 KBASE_VE_GPU_FREQ_KHZ_MIN},
300 #ifdef CONFIG_MALI_DEBUG
301 /* Use more aggressive scheduling timeouts in debug builds for testing purposes */
303 KBASE_CONFIG_ATTR_JS_SCHEDULING_TICK_NS,
304 KBASE_VE_JS_SCHEDULING_TICK_NS_DEBUG},
307 KBASE_CONFIG_ATTR_JS_SOFT_STOP_TICKS,
308 KBASE_VE_JS_SOFT_STOP_TICKS_DEBUG},
311 KBASE_CONFIG_ATTR_JS_HARD_STOP_TICKS_SS,
312 KBASE_VE_JS_HARD_STOP_TICKS_SS_DEBUG},
315 KBASE_CONFIG_ATTR_JS_HARD_STOP_TICKS_NSS,
316 KBASE_VE_JS_HARD_STOP_TICKS_NSS_DEBUG},
319 KBASE_CONFIG_ATTR_JS_RESET_TICKS_SS,
320 KBASE_VE_JS_RESET_TICKS_SS_DEBUG},
323 KBASE_CONFIG_ATTR_JS_RESET_TICKS_NSS,
324 KBASE_VE_JS_RESET_TICKS_NSS_DEBUG},
325 #else /* CONFIG_MALI_DEBUG */
326 /* In release builds same as the defaults but scaled for 5MHz FPGA */
329 KBASE_CONFIG_ATTR_JS_SCHEDULING_TICK_NS,
330 KBASE_VE_JS_SCHEDULING_TICK_NS},
334 KBASE_CONFIG_ATTR_JS_SOFT_STOP_TICKS,
335 KBASE_VE_JS_SOFT_STOP_TICKS},
339 KBASE_CONFIG_ATTR_JS_HARD_STOP_TICKS_SS,
340 KBASE_VE_JS_HARD_STOP_TICKS_SS},
344 KBASE_CONFIG_ATTR_JS_HARD_STOP_TICKS_NSS,
345 KBASE_VE_JS_HARD_STOP_TICKS_NSS},
349 KBASE_CONFIG_ATTR_JS_RESET_TICKS_SS,
350 KBASE_VE_JS_RESET_TICKS_SS},
354 KBASE_CONFIG_ATTR_JS_RESET_TICKS_NSS,
355 KBASE_VE_JS_RESET_TICKS_NSS},
357 #endif /* CONFIG_MALI_DEBUG */
360 KBASE_CONFIG_ATTR_JS_RESET_TIMEOUT_MS,
361 KBASE_VE_JS_RESET_TIMEOUT_MS},
365 KBASE_CONFIG_ATTR_JS_CTX_TIMESLICE_NS,
366 KBASE_VE_JS_CTX_TIMESLICE_NS},
370 KBASE_CONFIG_ATTR_CPU_SPEED_FUNC,
371 KBASE_VE_CPU_SPEED_FUNC},
375 KBASE_CONFIG_ATTR_SECURE_BUT_LOSS_OF_PERFORMANCE,
376 KBASE_VE_SECURE_BUT_LOSS_OF_PERFORMANCE},
380 KBASE_CONFIG_ATTR_GPU_IRQ_THROTTLE_TIME_US,
384 KBASE_CONFIG_ATTR_END,
388 static kbase_platform_config rk_platform_config = {
389 .attributes = config_attributes,
391 .io_resources = &io_resources
395 kbase_platform_config *kbase_get_platform_config(void)
397 return &rk_platform_config;
400 int kbase_platform_early_init(void)
402 /* Nothing needed at this stage */