blob: 1440716dcac87e98862c8bf8a07846e5c2c380eb [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
Shruti Gupta9d0cfe82023-04-17 10:57:26 +010010#include <arch_features.h>
nabkah01002e5692022-10-10 12:36:46 +010011#include <debug.h>
Shruti Gupta369955a2023-04-19 18:05:56 +010012#include <fpu.h>
nabkah01002e5692022-10-10 12:36:46 +010013#include <host_realm_helper.h>
14#include <host_shared_data.h>
Shruti Gupta9d0cfe82023-04-17 10:57:26 +010015#include <pauth.h>
nabkah01002e5692022-10-10 12:36:46 +010016#include "realm_def.h"
17#include <realm_rsi.h>
AlexeiFedorov2f30f102023-03-13 19:37:46 +000018#include <realm_tests.h>
nabkah01002e5692022-10-10 12:36:46 +010019#include <tftf_lib.h>
20
Arunachalam Ganapathy7e514f62023-08-30 13:27:36 +010021static fpu_state_t rl_fpu_state_write;
22static fpu_state_t rl_fpu_state_read;
23
nabkah01002e5692022-10-10 12:36:46 +010024/*
AlexeiFedorov2f30f102023-03-13 19:37:46 +000025 * This function reads sleep time in ms from shared buffer and spins PE
26 * in a loop for that time period.
nabkah01002e5692022-10-10 12:36:46 +010027 */
28static void realm_sleep_cmd(void)
29{
Shruti Gupta52b5f022023-10-12 22:02:29 +010030 uint64_t sleep = realm_shared_data_get_my_host_val(HOST_ARG1_INDEX);
nabkah01002e5692022-10-10 12:36:46 +010031
AlexeiFedorov2f30f102023-03-13 19:37:46 +000032 realm_printf("Realm: going to sleep for %llums\n", sleep);
nabkah01002e5692022-10-10 12:36:46 +010033 waitms(sleep);
34}
35
Shruti Gupta6bb95102023-10-02 13:21:37 +010036static void realm_loop_cmd(void)
37{
38 while (true) {
39 waitms(500);
40 }
41}
42
nabkah01002e5692022-10-10 12:36:46 +010043/*
44 * This function requests RSI/ABI version from RMM.
45 */
46static void realm_get_rsi_version(void)
47{
48 u_register_t version;
49
50 version = rsi_get_version();
51 if (version == (u_register_t)SMC_UNKNOWN) {
AlexeiFedorov2f30f102023-03-13 19:37:46 +000052 realm_printf("SMC_RSI_ABI_VERSION failed (%ld)", (long)version);
nabkah01002e5692022-10-10 12:36:46 +010053 return;
54 }
55
AlexeiFedorov2f30f102023-03-13 19:37:46 +000056 realm_printf("RSI ABI version %u.%u (expected: %u.%u)",
nabkah01002e5692022-10-10 12:36:46 +010057 RSI_ABI_VERSION_GET_MAJOR(version),
58 RSI_ABI_VERSION_GET_MINOR(version),
59 RSI_ABI_VERSION_GET_MAJOR(RSI_ABI_VERSION),
60 RSI_ABI_VERSION_GET_MINOR(RSI_ABI_VERSION));
61}
62
63/*
64 * This is the entry function for Realm payload, it first requests the shared buffer
65 * IPA address from Host using HOST_CALL/RSI, it reads the command to be executed,
66 * performs the request, and returns to Host with the execution state SUCCESS/FAILED
67 *
68 * Host in NS world requests Realm to execute certain operations using command
69 * depending on the test case the Host wants to perform.
70 */
71void realm_payload_main(void)
72{
nabkah01002e5692022-10-10 12:36:46 +010073 bool test_succeed = false;
74
75 realm_set_shared_structure((host_shared_data_t *)rsi_get_ns_buffer());
Shruti Gupta550e3e82023-08-16 13:20:11 +010076 if (realm_get_my_shared_structure() != NULL) {
77 uint8_t cmd = realm_shared_data_get_my_realm_cmd();
AlexeiFedorov2f30f102023-03-13 19:37:46 +000078
nabkah01002e5692022-10-10 12:36:46 +010079 switch (cmd) {
80 case REALM_SLEEP_CMD:
81 realm_sleep_cmd();
82 test_succeed = true;
83 break;
Shruti Gupta6bb95102023-10-02 13:21:37 +010084 case REALM_LOOP_CMD:
85 realm_loop_cmd();
86 test_succeed = true;
87 break;
Shruti Gupta24597d12023-10-02 10:40:19 +010088 case REALM_MULTIPLE_REC_PSCI_DENIED_CMD:
89 test_succeed = test_realm_multiple_rec_psci_denied_cmd();
90 break;
Shruti Gupta9d0cfe82023-04-17 10:57:26 +010091 case REALM_PAUTH_SET_CMD:
92 test_succeed = test_realm_pauth_set_cmd();
93 break;
94 case REALM_PAUTH_CHECK_CMD:
95 test_succeed = test_realm_pauth_check_cmd();
96 break;
97 case REALM_PAUTH_FAULT:
98 test_succeed = test_realm_pauth_fault();
99 break;
nabkah01002e5692022-10-10 12:36:46 +0100100 case REALM_GET_RSI_VERSION:
101 realm_get_rsi_version();
102 test_succeed = true;
103 break;
AlexeiFedorov2f30f102023-03-13 19:37:46 +0000104 case REALM_PMU_CYCLE:
105 test_succeed = test_pmuv3_cycle_works_realm();
106 break;
107 case REALM_PMU_EVENT:
108 test_succeed = test_pmuv3_event_works_realm();
109 break;
110 case REALM_PMU_PRESERVE:
111 test_succeed = test_pmuv3_rmm_preserves();
112 break;
113 case REALM_PMU_INTERRUPT:
114 test_succeed = test_pmuv3_overflow_interrupt();
115 break;
Shruti Gupta369955a2023-04-19 18:05:56 +0100116 case REALM_REQ_FPU_FILL_CMD:
Arunachalam Ganapathy7e514f62023-08-30 13:27:36 +0100117 fpu_state_write_rand(&rl_fpu_state_write);
Shruti Gupta369955a2023-04-19 18:05:56 +0100118 test_succeed = true;
119 break;
120 case REALM_REQ_FPU_CMP_CMD:
Arunachalam Ganapathy7e514f62023-08-30 13:27:36 +0100121 fpu_state_read(&rl_fpu_state_read);
122 test_succeed = !fpu_state_compare(&rl_fpu_state_write,
123 &rl_fpu_state_read);
Arunachalam Ganapathy9af432e2023-06-02 17:18:23 +0100124 break;
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +0100125 case REALM_SVE_RDVL:
126 test_succeed = test_realm_sve_rdvl();
127 break;
128 case REALM_SVE_ID_REGISTERS:
129 test_succeed = test_realm_sve_read_id_registers();
130 break;
131 case REALM_SVE_PROBE_VL:
132 test_succeed = test_realm_sve_probe_vl();
Shruti Gupta369955a2023-04-19 18:05:56 +0100133 break;
Arunachalam Ganapathyc1136a82023-04-12 15:24:44 +0100134 case REALM_SVE_OPS:
135 test_succeed = test_realm_sve_ops();
136 break;
Arunachalam Ganapathy5270d012023-04-19 14:53:42 +0100137 case REALM_SVE_FILL_REGS:
138 test_succeed = test_realm_sve_fill_regs();
139 break;
Arunachalam Ganapathyf3697172023-09-04 15:04:46 +0100140 case REALM_SVE_CMP_REGS:
141 test_succeed = test_realm_sve_cmp_regs();
142 break;
Arunachalam Ganapathy73949a22023-06-05 12:01:05 +0100143 case REALM_SVE_UNDEF_ABORT:
144 test_succeed = test_realm_sve_undef_abort();
145 break;
nabkah01002e5692022-10-10 12:36:46 +0100146 default:
AlexeiFedorov2f30f102023-03-13 19:37:46 +0000147 realm_printf("%s() invalid cmd %u\n", __func__, cmd);
nabkah01002e5692022-10-10 12:36:46 +0100148 break;
149 }
150 }
151
152 if (test_succeed) {
153 rsi_exit_to_host(HOST_CALL_EXIT_SUCCESS_CMD);
154 } else {
155 rsi_exit_to_host(HOST_CALL_EXIT_FAILED_CMD);
156 }
157}