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 <kbase/src/common/mali_kbase.h>
22 #include <kbase/src/common/mali_kbase_defs.h>
23 #include <kbase/mali_kbase_config.h>
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>
32 int get_cpu_clock_speed(u32 *cpu_clock);
34 #define HZ_IN_MHZ (1000000)
35 #ifdef CONFIG_MALI_T6XX_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_T6XX_DVFS
111 if (kbase_platform_dvfs_enable(false, MALI_DVFS_BL_CONFIG_FREQ)!= MALI_TRUE)
115 case PM_POST_SUSPEND:
116 #ifdef CONFIG_MALI_T6XX_DVFS
117 if (kbase_platform_dvfs_enable(true, MALI_DVFS_START_FREQ)!= MALI_TRUE)
128 rk3288 hardware specific initialization
130 mali_bool kbase_platform_rk_init(kbase_device *kbdev)
132 if(MALI_ERROR_NONE == kbase_platform_init(kbdev))
134 if (register_pm_notifier(&mali_pm_nb)) {
143 rk3288 hardware specific termination
145 void kbase_platform_rk_term(kbase_device *kbdev)
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);
154 kbase_platform_funcs_conf platform_funcs = {
155 .platform_init_func = &kbase_platform_rk_init,
156 .platform_term_func = &kbase_platform_rk_term,
159 #ifdef CONFIG_MALI_T6XX_RT_PM
160 static int pm_callback_power_on(kbase_device *kbdev)
164 struct kbase_os_device *osdev = &kbdev->osdev;
165 struct rk_context *platform;
167 platform = (struct rk_context *)kbdev->platform_context;
169 if (pm_runtime_status_suspended(osdev->dev))
174 if(osdev->dev->power.disable_depth > 0) {
175 if(platform->cmu_pmu_status == 0)
176 kbase_platform_cmu_pmu_control(kbdev, 1);
179 result = pm_runtime_resume(osdev->dev);
181 if (result < 0 && result == -EAGAIN)
182 kbase_platform_cmu_pmu_control(kbdev, 1);
184 printk(KERN_ERR "pm_runtime_get_sync failed (%d)\n", result);
189 static void pm_callback_power_off(kbase_device *kbdev)
191 struct kbase_os_device *osdev = &kbdev->osdev;
192 pm_schedule_suspend(osdev->dev, RUNTIME_PM_DELAY_TIME);
195 mali_error kbase_device_runtime_init(struct kbase_device *kbdev)
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;
206 void kbase_device_runtime_disable(struct kbase_device *kbdev)
208 pm_runtime_disable(kbdev->osdev.dev);
211 static int pm_callback_runtime_on(kbase_device *kbdev)
213 #ifdef CONFIG_MALI_T6XX_DVFS
214 struct rk_context *platform = (struct rk_context *)kbdev->platform_context;
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)
222 if (kbase_platform_dvfs_enable(false, MALI_DVFS_CURRENT_FREQ)!= MALI_TRUE)
229 static void pm_callback_runtime_off(kbase_device *kbdev)
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");
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,
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,
253 #endif /* CONFIG_PM_RUNTIME */
258 /* Please keep table config_attributes in sync with config_attributes_hw_issue_8408 */
259 static kbase_attribute config_attributes[] = {
262 KBASE_CONFIG_ATTR_MEMORY_PER_PROCESS_LIMIT,
263 KBASE_VE_MEMORY_PER_PROCESS_LIMIT},
267 KBASE_CONFIG_ATTR_UMP_DEVICE,
268 KBASE_VE_UMP_DEVICE},
269 #endif /* CONFIG_UMP */
270 #ifdef CONFIG_MALI_T6XX_RT_PM
272 KBASE_CONFIG_ATTR_POWER_MANAGEMENT_CALLBACKS,
273 (uintptr_t)&pm_callbacks},
277 KBASE_CONFIG_ATTR_MEMORY_OS_SHARED_MAX,
278 KBASE_VE_MEMORY_OS_SHARED_MAX},
282 KBASE_CONFIG_ATTR_MEMORY_OS_SHARED_PERF_GPU,
283 KBASE_VE_MEMORY_OS_SHARED_PERF_GPU},
286 KBASE_CONFIG_ATTR_PLATFORM_FUNCS,
287 (uintptr_t) &platform_funcs},
290 KBASE_CONFIG_ATTR_GPU_FREQ_KHZ_MAX,
291 KBASE_VE_GPU_FREQ_KHZ_MAX},
294 KBASE_CONFIG_ATTR_GPU_FREQ_KHZ_MIN,
295 KBASE_VE_GPU_FREQ_KHZ_MIN},
297 #ifdef CONFIG_MALI_DEBUG
298 /* Use more aggressive scheduling timeouts in debug builds for testing purposes */
300 KBASE_CONFIG_ATTR_JS_SCHEDULING_TICK_NS,
301 KBASE_VE_JS_SCHEDULING_TICK_NS_DEBUG},
304 KBASE_CONFIG_ATTR_JS_SOFT_STOP_TICKS,
305 KBASE_VE_JS_SOFT_STOP_TICKS_DEBUG},
308 KBASE_CONFIG_ATTR_JS_HARD_STOP_TICKS_SS,
309 KBASE_VE_JS_HARD_STOP_TICKS_SS_DEBUG},
312 KBASE_CONFIG_ATTR_JS_HARD_STOP_TICKS_NSS,
313 KBASE_VE_JS_HARD_STOP_TICKS_NSS_DEBUG},
316 KBASE_CONFIG_ATTR_JS_RESET_TICKS_SS,
317 KBASE_VE_JS_RESET_TICKS_SS_DEBUG},
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 */
326 KBASE_CONFIG_ATTR_JS_SCHEDULING_TICK_NS,
327 KBASE_VE_JS_SCHEDULING_TICK_NS},
331 KBASE_CONFIG_ATTR_JS_SOFT_STOP_TICKS,
332 KBASE_VE_JS_SOFT_STOP_TICKS},
336 KBASE_CONFIG_ATTR_JS_HARD_STOP_TICKS_SS,
337 KBASE_VE_JS_HARD_STOP_TICKS_SS},
341 KBASE_CONFIG_ATTR_JS_HARD_STOP_TICKS_NSS,
342 KBASE_VE_JS_HARD_STOP_TICKS_NSS},
346 KBASE_CONFIG_ATTR_JS_RESET_TICKS_SS,
347 KBASE_VE_JS_RESET_TICKS_SS},
351 KBASE_CONFIG_ATTR_JS_RESET_TICKS_NSS,
352 KBASE_VE_JS_RESET_TICKS_NSS},
354 #endif /* CONFIG_MALI_DEBUG */
357 KBASE_CONFIG_ATTR_JS_RESET_TIMEOUT_MS,
358 KBASE_VE_JS_RESET_TIMEOUT_MS},
362 KBASE_CONFIG_ATTR_JS_CTX_TIMESLICE_NS,
363 KBASE_VE_JS_CTX_TIMESLICE_NS},
367 KBASE_CONFIG_ATTR_CPU_SPEED_FUNC,
368 KBASE_VE_CPU_SPEED_FUNC},
372 KBASE_CONFIG_ATTR_SECURE_BUT_LOSS_OF_PERFORMANCE,
373 KBASE_VE_SECURE_BUT_LOSS_OF_PERFORMANCE},
377 KBASE_CONFIG_ATTR_GPU_IRQ_THROTTLE_TIME_US,
381 KBASE_CONFIG_ATTR_END,
385 static kbase_platform_config rk_platform_config = {
386 .attributes = config_attributes,
388 .io_resources = &io_resources
392 kbase_platform_config *kbase_get_platform_config(void)
394 return &rk_platform_config;
397 int kbase_platform_early_init(void)
399 /* Nothing needed at this stage */