From 6f4572bd7857122e65bd6d9bce9e39fc572d7c56 Mon Sep 17 00:00:00 2001 From: Yann Gautier Date: Thu, 14 Feb 2019 11:14:18 +0100 Subject: [PATCH] Introduce timeout_init_us/timeout_elapsed() delay tracking with CNTPCT. timeout_init_us(some_timeout_us); returns a reference to detect timeout for the provided microsecond delay value from current time. timeout_elapsed(reference) return true/false whether the reference timeout is elapsed. This change is inspired by the OP-TEE OS timeout resources [1]. [1] https://github.com/OP-TEE/optee_os/blob/3.4.0/core/arch/arm/include/kernel/delay.h#L45 Change-Id: Id81ff48aa49693f555dc621064878417101d5587 Signed-off-by: Yann Gautier Signed-off-by: Etienne Carriere --- plat/st/common/include/stm32mp_common.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plat/st/common/include/stm32mp_common.h b/plat/st/common/include/stm32mp_common.h index 269d8acb..5f54b103 100644 --- a/plat/st/common/include/stm32mp_common.h +++ b/plat/st/common/include/stm32mp_common.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2018-2019, STMicroelectronics - All Rights Reserved + * Copyright (c) 2018-2019, Linaro Limited * * SPDX-License-Identifier: BSD-3-Clause */ @@ -9,6 +10,8 @@ #include +#include + /* Functions to save and get boot context address given by ROM code */ void stm32mp_save_boot_ctx_address(uintptr_t address); uintptr_t stm32mp_get_boot_ctx_address(void); @@ -42,4 +45,19 @@ unsigned long stm32mp_clk_get_rate(unsigned long id); /* Initialise the IO layer and register platform IO devices */ void stm32mp_io_setup(void); +static inline uint64_t arm_cnt_us2cnt(uint32_t us) +{ + return ((uint64_t)us * (uint64_t)read_cntfrq()) / 1000000ULL; +} + +static inline uint64_t timeout_init_us(uint32_t us) +{ + return read_cntpct_el0() + arm_cnt_us2cnt(us); +} + +static inline bool timeout_elapsed(uint64_t expire) +{ + return read_cntpct_el0() > expire; +} + #endif /* STM32MP_COMMON_H */ -- 2.30.2