.. | .. |
---|
1 | 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ |
---|
2 | 2 | /* |
---|
3 | 3 | * |
---|
4 | | - * (C) COPYRIGHT 2014, 2018-2021 ARM Limited. All rights reserved. |
---|
| 4 | + * (C) COPYRIGHT 2014, 2018-2021, 2023 ARM Limited. All rights reserved. |
---|
5 | 5 | * |
---|
6 | 6 | * This program is free software and is provided to you under the terms of the |
---|
7 | 7 | * GNU General Public License version 2 as published by the Free Software |
---|
.. | .. |
---|
21 | 21 | |
---|
22 | 22 | #ifndef _KBASE_BACKEND_TIME_H_ |
---|
23 | 23 | #define _KBASE_BACKEND_TIME_H_ |
---|
| 24 | + |
---|
| 25 | +#if MALI_USE_CSF |
---|
| 26 | +/** |
---|
| 27 | + * struct kbase_backend_time - System timestamp attributes. |
---|
| 28 | + * |
---|
| 29 | + * @multiplier: Numerator of the converter's fraction. |
---|
| 30 | + * @divisor: Denominator of the converter's fraction. |
---|
| 31 | + * @offset: Converter's offset term. |
---|
| 32 | + * |
---|
| 33 | + * According to Generic timer spec, system timer: |
---|
| 34 | + * - Increments at a fixed frequency |
---|
| 35 | + * - Starts operating from zero |
---|
| 36 | + * |
---|
| 37 | + * Hence CPU time is a linear function of System Time. |
---|
| 38 | + * |
---|
| 39 | + * CPU_ts = alpha * SYS_ts + beta |
---|
| 40 | + * |
---|
| 41 | + * Where |
---|
| 42 | + * - alpha = 10^9/SYS_ts_freq |
---|
| 43 | + * - beta is calculated by two timer samples taken at the same time: |
---|
| 44 | + * beta = CPU_ts_s - SYS_ts_s * alpha |
---|
| 45 | + * |
---|
| 46 | + * Since alpha is a rational number, we minimizing possible |
---|
| 47 | + * rounding error by simplifying the ratio. Thus alpha is stored |
---|
| 48 | + * as a simple `multiplier / divisor` ratio. |
---|
| 49 | + * |
---|
| 50 | + */ |
---|
| 51 | +struct kbase_backend_time { |
---|
| 52 | + u64 multiplier; |
---|
| 53 | + u64 divisor; |
---|
| 54 | + s64 offset; |
---|
| 55 | +}; |
---|
| 56 | + |
---|
| 57 | +/** |
---|
| 58 | + * kbase_backend_time_convert_gpu_to_cpu() - Convert GPU timestamp to CPU timestamp. |
---|
| 59 | + * |
---|
| 60 | + * @kbdev: Kbase device pointer |
---|
| 61 | + * @gpu_ts: System timestamp value to converter. |
---|
| 62 | + * |
---|
| 63 | + * Return: The CPU timestamp. |
---|
| 64 | + */ |
---|
| 65 | +u64 __maybe_unused kbase_backend_time_convert_gpu_to_cpu(struct kbase_device *kbdev, u64 gpu_ts); |
---|
| 66 | +#endif |
---|
24 | 67 | |
---|
25 | 68 | /** |
---|
26 | 69 | * kbase_backend_get_gpu_time() - Get current GPU time |
---|
.. | .. |
---|
46 | 89 | u64 *cycle_counter, |
---|
47 | 90 | u64 *system_time, |
---|
48 | 91 | struct timespec64 *ts); |
---|
| 92 | +/** |
---|
| 93 | + * kbase_get_timeout_ms - Choose a timeout value to get a timeout scaled |
---|
| 94 | + * GPU frequency, using a choice from |
---|
| 95 | + * kbase_timeout_selector. |
---|
| 96 | + * |
---|
| 97 | + * @kbdev: KBase device pointer. |
---|
| 98 | + * @selector: Value from kbase_scaled_timeout_selector enum. |
---|
| 99 | + * |
---|
| 100 | + * Return: Timeout in milliseconds, as an unsigned integer. |
---|
| 101 | + */ |
---|
| 102 | +unsigned int kbase_get_timeout_ms(struct kbase_device *kbdev, |
---|
| 103 | + enum kbase_timeout_selector selector); |
---|
| 104 | + |
---|
| 105 | +/** |
---|
| 106 | + * kbase_backend_get_cycle_cnt - Reads the GPU cycle counter |
---|
| 107 | + * |
---|
| 108 | + * @kbdev: Instance of a GPU platform device that implements a CSF interface. |
---|
| 109 | + * |
---|
| 110 | + * Return: Snapshot of the GPU cycle count register. |
---|
| 111 | + */ |
---|
| 112 | +u64 kbase_backend_get_cycle_cnt(struct kbase_device *kbdev); |
---|
| 113 | + |
---|
| 114 | +/** |
---|
| 115 | + * kbase_backend_time_init() - Initialize system timestamp converter. |
---|
| 116 | + * |
---|
| 117 | + * @kbdev: Kbase device pointer |
---|
| 118 | + * |
---|
| 119 | + * This function should only be called after GPU is powered-up and |
---|
| 120 | + * L2 cached power-up has been initiated. |
---|
| 121 | + * |
---|
| 122 | + * Return: Zero on success, error code otherwise. |
---|
| 123 | + */ |
---|
| 124 | +int kbase_backend_time_init(struct kbase_device *kbdev); |
---|
49 | 125 | |
---|
50 | 126 | #endif /* _KBASE_BACKEND_TIME_H_ */ |
---|