Madhukar Pappireddy | e9c1812 | 2024-09-10 16:28:48 -0500 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2024, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include "cactus_message_loop.h" |
| 8 | #include "cactus_test_cmds.h" |
| 9 | #include "debug.h" |
| 10 | |
| 11 | uint32_t ms_to_ticks(uint64_t ms) |
| 12 | { |
| 13 | return ms * read_cntfrq_el0() / 1000; |
| 14 | } |
| 15 | |
| 16 | CACTUS_CMD_HANDLER(set_virtual_timer, CACTUS_SET_ARCH_TIMER_CMD) |
| 17 | { |
| 18 | uint64_t deadline_ms = cactus_get_timer_deadline(*args); |
| 19 | uint64_t wait_time = cactus_get_timer_wait_time(*args); |
| 20 | uint32_t ticks = ms_to_ticks(deadline_ms); |
| 21 | |
| 22 | write_cntp_ctl_el0(0); |
| 23 | write_cntp_tval_el0(ticks); |
| 24 | write_cntp_ctl_el0(1); |
| 25 | |
| 26 | if (wait_time != 0U) { |
| 27 | waitms(wait_time); |
| 28 | } |
| 29 | |
| 30 | return cactus_response(ffa_dir_msg_dest(*args), |
| 31 | ffa_dir_msg_source(*args), |
| 32 | CACTUS_SUCCESS); |
| 33 | } |