3 * (C) COPYRIGHT 2014-2015 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.
23 #include <mali_kbase.h>
24 #include <mali_kbase_hwaccess_time.h>
25 #include <backend/gpu/mali_kbase_device_internal.h>
26 #include <backend/gpu/mali_kbase_pm_internal.h>
28 void kbase_backend_get_gpu_time(struct kbase_device *kbdev, u64 *cycle_counter,
29 u64 *system_time, struct timespec *ts)
33 kbase_pm_request_gpu_cycle_counter(kbdev);
35 /* Read hi, lo, hi to ensure that overflow from lo to hi is handled
38 hi1 = kbase_reg_read(kbdev, GPU_CONTROL_REG(CYCLE_COUNT_HI),
40 *cycle_counter = kbase_reg_read(kbdev,
41 GPU_CONTROL_REG(CYCLE_COUNT_LO), NULL);
42 hi2 = kbase_reg_read(kbdev, GPU_CONTROL_REG(CYCLE_COUNT_HI),
44 *cycle_counter |= (((u64) hi1) << 32);
47 /* Read hi, lo, hi to ensure that overflow from lo to hi is handled
50 hi1 = kbase_reg_read(kbdev, GPU_CONTROL_REG(TIMESTAMP_HI),
52 *system_time = kbase_reg_read(kbdev,
53 GPU_CONTROL_REG(TIMESTAMP_LO), NULL);
54 hi2 = kbase_reg_read(kbdev, GPU_CONTROL_REG(TIMESTAMP_HI),
56 *system_time |= (((u64) hi1) << 32);
59 /* Record the CPU's idea of current time */
62 kbase_pm_release_gpu_cycle_counter(kbdev);
66 * kbase_wait_write_flush - Wait for GPU write flush
67 * @kctx: Context pointer
69 * Wait 1000 GPU clock cycles. This delay is known to give the GPU time to flush
72 * Only in use for BASE_HW_ISSUE_6367
74 * Note : If GPU resets occur then the counters are reset to zero, the delay may
77 #ifndef CONFIG_MALI_NO_MALI
78 void kbase_wait_write_flush(struct kbase_context *kctx)
82 /* A suspend won't happen here, because we're in a syscall from a
85 kbase_pm_context_active(kctx->kbdev);
86 kbase_pm_request_gpu_cycle_counter(kctx->kbdev);
91 new_count = kbase_reg_read(kctx->kbdev,
92 GPU_CONTROL_REG(CYCLE_COUNT_LO), NULL);
93 /* First time around, just store the count. */
94 if (base_count == 0) {
95 base_count = new_count;
99 /* No need to handle wrapping, unsigned maths works for this. */
100 if ((new_count - base_count) > 1000)
104 kbase_pm_release_gpu_cycle_counter(kctx->kbdev);
105 kbase_pm_context_idle(kctx->kbdev);
107 #endif /* CONFIG_MALI_NO_MALI */