developer | 86ada3c | 2020-07-03 09:19:06 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020, MediaTek Inc. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch_helpers.h> |
| 8 | #include <mt_timer.h> |
| 9 | #include <platform_def.h> |
| 10 | |
| 11 | |
| 12 | uint64_t normal_time_base; |
| 13 | uint64_t atf_time_base; |
| 14 | |
| 15 | void sched_clock_init(uint64_t normal_base, uint64_t atf_base) |
| 16 | { |
| 17 | normal_time_base += normal_base; |
| 18 | atf_time_base = atf_base; |
| 19 | } |
| 20 | |
| 21 | uint64_t sched_clock(void) |
| 22 | { |
| 23 | uint64_t cval; |
| 24 | uint64_t rel_base; |
| 25 | |
| 26 | rel_base = read_cntpct_el0() - atf_time_base; |
| 27 | cval = ((rel_base * 1000U) / SYS_COUNTER_FREQ_IN_MHZ) |
| 28 | - normal_time_base; |
| 29 | return cval; |
| 30 | } |