blob: b13e0a19ab22361f8d23b036096556be6eb94f5b [file] [log] [blame]
nabkah01002e5692022-10-10 12:36:46 +01001/*
AlexeiFedorov2f30f102023-03-13 19:37:46 +00002 * Copyright (c) 2022-2023, Arm Limited. All rights reserved.
nabkah01002e5692022-10-10 12:36:46 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include <stdio.h>
9
10#include <debug.h>
Shruti Gupta369955a2023-04-19 18:05:56 +010011#include <fpu.h>
nabkah01002e5692022-10-10 12:36:46 +010012#include <host_realm_helper.h>
13#include <host_shared_data.h>
14#include "realm_def.h"
15#include <realm_rsi.h>
AlexeiFedorov2f30f102023-03-13 19:37:46 +000016#include <realm_tests.h>
nabkah01002e5692022-10-10 12:36:46 +010017#include <tftf_lib.h>
18
Shruti Gupta369955a2023-04-19 18:05:56 +010019static fpu_reg_state_t fpu_temp_rl;
nabkah01002e5692022-10-10 12:36:46 +010020/*
AlexeiFedorov2f30f102023-03-13 19:37:46 +000021 * This function reads sleep time in ms from shared buffer and spins PE
22 * in a loop for that time period.
nabkah01002e5692022-10-10 12:36:46 +010023 */
24static void realm_sleep_cmd(void)
25{
26 uint64_t sleep = realm_shared_data_get_host_val(HOST_SLEEP_INDEX);
27
AlexeiFedorov2f30f102023-03-13 19:37:46 +000028 realm_printf("Realm: going to sleep for %llums\n", sleep);
nabkah01002e5692022-10-10 12:36:46 +010029 waitms(sleep);
30}
31
32/*
33 * This function requests RSI/ABI version from RMM.
34 */
35static void realm_get_rsi_version(void)
36{
37 u_register_t version;
38
39 version = rsi_get_version();
40 if (version == (u_register_t)SMC_UNKNOWN) {
AlexeiFedorov2f30f102023-03-13 19:37:46 +000041 realm_printf("SMC_RSI_ABI_VERSION failed (%ld)", (long)version);
nabkah01002e5692022-10-10 12:36:46 +010042 return;
43 }
44
AlexeiFedorov2f30f102023-03-13 19:37:46 +000045 realm_printf("RSI ABI version %u.%u (expected: %u.%u)",
nabkah01002e5692022-10-10 12:36:46 +010046 RSI_ABI_VERSION_GET_MAJOR(version),
47 RSI_ABI_VERSION_GET_MINOR(version),
48 RSI_ABI_VERSION_GET_MAJOR(RSI_ABI_VERSION),
49 RSI_ABI_VERSION_GET_MINOR(RSI_ABI_VERSION));
50}
51
52/*
53 * This is the entry function for Realm payload, it first requests the shared buffer
54 * IPA address from Host using HOST_CALL/RSI, it reads the command to be executed,
55 * performs the request, and returns to Host with the execution state SUCCESS/FAILED
56 *
57 * Host in NS world requests Realm to execute certain operations using command
58 * depending on the test case the Host wants to perform.
59 */
60void realm_payload_main(void)
61{
nabkah01002e5692022-10-10 12:36:46 +010062 bool test_succeed = false;
63
64 realm_set_shared_structure((host_shared_data_t *)rsi_get_ns_buffer());
AlexeiFedorov2f30f102023-03-13 19:37:46 +000065
nabkah01002e5692022-10-10 12:36:46 +010066 if (realm_get_shared_structure() != NULL) {
AlexeiFedorov2f30f102023-03-13 19:37:46 +000067 uint8_t cmd = realm_shared_data_get_realm_cmd();
68
nabkah01002e5692022-10-10 12:36:46 +010069 switch (cmd) {
70 case REALM_SLEEP_CMD:
71 realm_sleep_cmd();
72 test_succeed = true;
73 break;
74 case REALM_GET_RSI_VERSION:
75 realm_get_rsi_version();
76 test_succeed = true;
77 break;
AlexeiFedorov2f30f102023-03-13 19:37:46 +000078 case REALM_PMU_CYCLE:
79 test_succeed = test_pmuv3_cycle_works_realm();
80 break;
81 case REALM_PMU_EVENT:
82 test_succeed = test_pmuv3_event_works_realm();
83 break;
84 case REALM_PMU_PRESERVE:
85 test_succeed = test_pmuv3_rmm_preserves();
86 break;
87 case REALM_PMU_INTERRUPT:
88 test_succeed = test_pmuv3_overflow_interrupt();
89 break;
Shruti Gupta369955a2023-04-19 18:05:56 +010090 case REALM_REQ_FPU_FILL_CMD:
91 fpu_state_fill_regs_and_template(&fpu_temp_rl);
92 test_succeed = true;
93 break;
94 case REALM_REQ_FPU_CMP_CMD:
95 test_succeed = fpu_state_compare_template(&fpu_temp_rl);
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +010096 case REALM_SVE_RDVL:
97 test_succeed = test_realm_sve_rdvl();
98 break;
99 case REALM_SVE_ID_REGISTERS:
100 test_succeed = test_realm_sve_read_id_registers();
101 break;
102 case REALM_SVE_PROBE_VL:
103 test_succeed = test_realm_sve_probe_vl();
Shruti Gupta369955a2023-04-19 18:05:56 +0100104 break;
Arunachalam Ganapathyc1136a82023-04-12 15:24:44 +0100105 case REALM_SVE_OPS:
106 test_succeed = test_realm_sve_ops();
107 break;
nabkah01002e5692022-10-10 12:36:46 +0100108 default:
AlexeiFedorov2f30f102023-03-13 19:37:46 +0000109 realm_printf("%s() invalid cmd %u\n", __func__, cmd);
nabkah01002e5692022-10-10 12:36:46 +0100110 break;
111 }
112 }
113
114 if (test_succeed) {
115 rsi_exit_to_host(HOST_CALL_EXIT_SUCCESS_CMD);
116 } else {
117 rsi_exit_to_host(HOST_CALL_EXIT_FAILED_CMD);
118 }
119}