mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-05-03 01:06:13 +00:00
Merge "refactor(delay-timer): add timer callback functions" into integration
This commit is contained in:
commit
d7adbb5258
4 changed files with 55 additions and 25 deletions
|
@ -900,6 +900,9 @@ subsections:
|
||||||
- title: Console
|
- title: Console
|
||||||
scope: console
|
scope: console
|
||||||
|
|
||||||
|
- title: Delay Timer
|
||||||
|
scope: delay-timer
|
||||||
|
|
||||||
- title: Generic Clock
|
- title: Generic Clock
|
||||||
scope: clk
|
scope: clk
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
|
* Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -80,3 +80,25 @@ void timer_init(const timer_ops_t *ops_ptr)
|
||||||
|
|
||||||
timer_ops = ops_ptr;
|
timer_ops = ops_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***********************************************************
|
||||||
|
* Initialize the timer in us
|
||||||
|
***********************************************************/
|
||||||
|
uint64_t timeout_init_us(uint32_t usec)
|
||||||
|
{
|
||||||
|
assert(timer_ops != NULL);
|
||||||
|
assert(timer_ops->timeout_init_us != NULL);
|
||||||
|
|
||||||
|
return timer_ops->timeout_init_us(usec);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************************************
|
||||||
|
* check the given timeout elapsed or not.
|
||||||
|
***********************************************************/
|
||||||
|
bool timeout_elapsed(uint64_t cnt)
|
||||||
|
{
|
||||||
|
assert(timer_ops != NULL);
|
||||||
|
assert(timer_ops->timeout_elapsed != NULL);
|
||||||
|
|
||||||
|
return timer_ops->timeout_elapsed(cnt);
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved.
|
* Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved.
|
||||||
* Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
|
* Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
@ -18,7 +18,26 @@
|
||||||
|
|
||||||
static timer_ops_t ops;
|
static timer_ops_t ops;
|
||||||
|
|
||||||
static uint32_t get_timer_value(void)
|
static uint64_t timeout_cnt_us2cnt(uint32_t us)
|
||||||
|
{
|
||||||
|
return ((uint64_t)us * (uint64_t)read_cntfrq_el0()) / 1000000ULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint64_t generic_delay_timeout_init_us(uint32_t us)
|
||||||
|
{
|
||||||
|
uint64_t cnt = timeout_cnt_us2cnt(us);
|
||||||
|
|
||||||
|
cnt += read_cntpct_el0();
|
||||||
|
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool generic_delay_timeout_elapsed(uint64_t expire_cnt)
|
||||||
|
{
|
||||||
|
return read_cntpct_el0() > expire_cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t generic_delay_get_timer_value(void)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Generic delay timer implementation expects the timer to be a down
|
* Generic delay timer implementation expects the timer to be a down
|
||||||
|
@ -31,9 +50,11 @@ static uint32_t get_timer_value(void)
|
||||||
|
|
||||||
void generic_delay_timer_init_args(uint32_t mult, uint32_t div)
|
void generic_delay_timer_init_args(uint32_t mult, uint32_t div)
|
||||||
{
|
{
|
||||||
ops.get_timer_value = get_timer_value;
|
ops.get_timer_value = generic_delay_get_timer_value;
|
||||||
ops.clk_mult = mult;
|
ops.clk_mult = mult;
|
||||||
ops.clk_div = div;
|
ops.clk_div = div;
|
||||||
|
ops.timeout_init_us = generic_delay_timeout_init_us;
|
||||||
|
ops.timeout_elapsed = generic_delay_timeout_elapsed;
|
||||||
|
|
||||||
timer_init(&ops);
|
timer_init(&ops);
|
||||||
|
|
||||||
|
@ -59,4 +80,3 @@ void generic_delay_timer_init(void)
|
||||||
|
|
||||||
generic_delay_timer_init_args(mult, div);
|
generic_delay_timer_init_args(mult, div);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
|
* Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
|
||||||
* Copyright (c) 2019, Linaro Limited
|
* Copyright (c) 2019, Linaro Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
@ -25,27 +25,12 @@ typedef struct timer_ops {
|
||||||
uint32_t (*get_timer_value)(void);
|
uint32_t (*get_timer_value)(void);
|
||||||
uint32_t clk_mult;
|
uint32_t clk_mult;
|
||||||
uint32_t clk_div;
|
uint32_t clk_div;
|
||||||
|
uint64_t (*timeout_init_us)(uint32_t usec);
|
||||||
|
bool (*timeout_elapsed)(uint64_t cnt);
|
||||||
} timer_ops_t;
|
} timer_ops_t;
|
||||||
|
|
||||||
static inline uint64_t timeout_cnt_us2cnt(uint32_t us)
|
uint64_t timeout_init_us(uint32_t usec);
|
||||||
{
|
bool timeout_elapsed(uint64_t cnt);
|
||||||
return ((uint64_t)us * (uint64_t)read_cntfrq_el0()) / 1000000ULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint64_t timeout_init_us(uint32_t us)
|
|
||||||
{
|
|
||||||
uint64_t cnt = timeout_cnt_us2cnt(us);
|
|
||||||
|
|
||||||
cnt += read_cntpct_el0();
|
|
||||||
|
|
||||||
return cnt;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool timeout_elapsed(uint64_t expire_cnt)
|
|
||||||
{
|
|
||||||
return read_cntpct_el0() > expire_cnt;
|
|
||||||
}
|
|
||||||
|
|
||||||
void mdelay(uint32_t msec);
|
void mdelay(uint32_t msec);
|
||||||
void udelay(uint32_t usec);
|
void udelay(uint32_t usec);
|
||||||
void timer_init(const timer_ops_t *ops_ptr);
|
void timer_init(const timer_ops_t *ops_ptr);
|
||||||
|
|
Loading…
Add table
Reference in a new issue