J-Alves | 0e1e7ca | 2021-01-25 14:11:06 +0000 | [diff] [blame] | 1 | /* |
Shruti Gupta | 38133fa | 2023-04-19 17:00:38 +0100 | [diff] [blame] | 2 | * Copyright (c) 2023, Arm Limited. All rights reserved. |
J-Alves | 0e1e7ca | 2021-01-25 14:11:06 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
J-Alves | eeb2547 | 2021-03-11 09:54:21 +0000 | [diff] [blame] | 7 | #include "cactus_message_loop.h" |
J-Alves | 0e1e7ca | 2021-01-25 14:11:06 +0000 | [diff] [blame] | 8 | #include "cactus_test_cmds.h" |
Shruti Gupta | 38133fa | 2023-04-19 17:00:38 +0100 | [diff] [blame] | 9 | #include <fpu.h> |
Olivier Deprez | 19626b4 | 2023-12-21 18:29:05 +0100 | [diff] [blame] | 10 | #include <spm_helpers.h> |
J-Alves | 0e1e7ca | 2021-01-25 14:11:06 +0000 | [diff] [blame] | 11 | #include "spm_common.h" |
| 12 | |
| 13 | /* |
Shruti Gupta | 38133fa | 2023-04-19 17:00:38 +0100 | [diff] [blame] | 14 | * Note Test must exercise FILL and COMPARE command in |
| 15 | * sequence and on same CPU. |
| 16 | */ |
Arunachalam Ganapathy | 7e514f6 | 2023-08-30 13:27:36 +0100 | [diff] [blame] | 17 | static fpu_state_t sp_fpu_state_write; |
| 18 | static fpu_state_t sp_fpu_state_read; |
Shruti Gupta | 38133fa | 2023-04-19 17:00:38 +0100 | [diff] [blame] | 19 | static unsigned int core_pos; |
| 20 | /* |
J-Alves | 0e1e7ca | 2021-01-25 14:11:06 +0000 | [diff] [blame] | 21 | * Fill SIMD vectors from secure world side with a unique value. |
J-Alves | 0e1e7ca | 2021-01-25 14:11:06 +0000 | [diff] [blame] | 22 | */ |
| 23 | CACTUS_CMD_HANDLER(req_simd_fill, CACTUS_REQ_SIMD_FILL_CMD) |
| 24 | { |
Olivier Deprez | 19626b4 | 2023-12-21 18:29:05 +0100 | [diff] [blame] | 25 | /* Get vCPU index for currently running vCPU. */ |
| 26 | core_pos = spm_get_my_core_pos(); |
Arunachalam Ganapathy | 7e514f6 | 2023-08-30 13:27:36 +0100 | [diff] [blame] | 27 | fpu_state_write_rand(&sp_fpu_state_write); |
J-Alves | 0e1e7ca | 2021-01-25 14:11:06 +0000 | [diff] [blame] | 28 | return cactus_response(ffa_dir_msg_dest(*args), |
| 29 | ffa_dir_msg_source(*args), |
| 30 | CACTUS_SUCCESS); |
| 31 | } |
Shruti Gupta | 38133fa | 2023-04-19 17:00:38 +0100 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * compare FPU state(SIMD vectors, FPCR, FPSR) from secure world side with the previous |
| 35 | * SIMD_SECURE_VALUE unique value. |
| 36 | */ |
| 37 | CACTUS_CMD_HANDLER(req_simd_compare, CACTUS_CMP_SIMD_VALUE_CMD) |
| 38 | { |
| 39 | bool test_succeed = false; |
| 40 | |
Olivier Deprez | 19626b4 | 2023-12-21 18:29:05 +0100 | [diff] [blame] | 41 | /* Get vCPU index for currently running vCPU. */ |
| 42 | unsigned int core_pos1 = spm_get_my_core_pos(); |
Shruti Gupta | 38133fa | 2023-04-19 17:00:38 +0100 | [diff] [blame] | 43 | if (core_pos1 == core_pos) { |
Arunachalam Ganapathy | 7e514f6 | 2023-08-30 13:27:36 +0100 | [diff] [blame] | 44 | fpu_state_read(&sp_fpu_state_read); |
| 45 | if (fpu_state_compare(&sp_fpu_state_write, |
| 46 | &sp_fpu_state_read) == 0) { |
| 47 | test_succeed = true; |
| 48 | } |
Shruti Gupta | 38133fa | 2023-04-19 17:00:38 +0100 | [diff] [blame] | 49 | } |
| 50 | return cactus_response(ffa_dir_msg_dest(*args), |
| 51 | ffa_dir_msg_source(*args), |
| 52 | test_succeed ? CACTUS_SUCCESS : CACTUS_ERROR); |
| 53 | } |