Manish Pandey | 9ee6a8d | 2021-03-03 09:53:33 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <common/debug.h> |
| 8 | #include <sp_helpers.h> |
| 9 | #include <spm_helpers.h> |
| 10 | |
| 11 | #include "cactus_message_loop.h" |
| 12 | #include "cactus_test_cmds.h" |
| 13 | |
| 14 | CACTUS_CMD_HANDLER(sleep_cmd, CACTUS_SLEEP_CMD) |
| 15 | { |
| 16 | uint64_t timer_freq = read_cntfrq_el0(); |
| 17 | uint64_t time1, time2, time_lapsed; |
| 18 | uint32_t sleep_time = cactus_get_sleep_time(*args); |
| 19 | |
| 20 | VERBOSE("Request to sleep %x for %ums.\n", ffa_dir_msg_dest(*args), sleep_time); |
| 21 | |
| 22 | time1 = read_cntvct_el0(); |
| 23 | sp_sleep(sleep_time); |
| 24 | time2 = read_cntvct_el0(); |
| 25 | |
| 26 | /* Lapsed time should be at least equal to sleep time */ |
| 27 | time_lapsed = ((time2 - time1) * 1000) / timer_freq; |
| 28 | |
| 29 | return cactus_response(ffa_dir_msg_dest(*args), |
| 30 | ffa_dir_msg_source(*args), |
| 31 | time_lapsed); |
| 32 | } |
| 33 | |
| 34 | CACTUS_CMD_HANDLER(interrupt_cmd, CACTUS_INTERRUPT_CMD) |
| 35 | { |
| 36 | uint32_t int_id = cactus_get_interrupt_id(*args); |
| 37 | bool enable = cactus_get_interrupt_enable(*args); |
| 38 | enum interrupt_pin pin = cactus_get_interrupt_pin(*args); |
| 39 | int64_t ret; |
| 40 | |
| 41 | ret = spm_interrupt_enable(int_id, enable, pin); |
| 42 | if (ret != 0) { |
| 43 | return cactus_error_resp(ffa_dir_msg_dest(*args), |
| 44 | ffa_dir_msg_source(*args), |
| 45 | CACTUS_ERROR_TEST); |
| 46 | } |
| 47 | |
| 48 | return cactus_response(ffa_dir_msg_dest(*args), |
| 49 | ffa_dir_msg_source(*args), |
| 50 | CACTUS_SUCCESS); |
| 51 | } |