blob: 43cbf2df0b8ec729d13fb921557b417ccb3d71b3 [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
36/*
37 * This function requests RSI/ABI version from RMM.
38 */
39static void realm_get_rsi_version(void)
40{
41 u_register_t version;
42
43 version = rsi_get_version();
44 if (version == (u_register_t)SMC_UNKNOWN) {
AlexeiFedorov2f30f102023-03-13 19:37:46 +000045 realm_printf("SMC_RSI_ABI_VERSION failed (%ld)", (long)version);
nabkah01002e5692022-10-10 12:36:46 +010046 return;
47 }
48
AlexeiFedorov2f30f102023-03-13 19:37:46 +000049 realm_printf("RSI ABI version %u.%u (expected: %u.%u)",
nabkah01002e5692022-10-10 12:36:46 +010050 RSI_ABI_VERSION_GET_MAJOR(version),
51 RSI_ABI_VERSION_GET_MINOR(version),
52 RSI_ABI_VERSION_GET_MAJOR(RSI_ABI_VERSION),
53 RSI_ABI_VERSION_GET_MINOR(RSI_ABI_VERSION));
54}
55
56/*
57 * This is the entry function for Realm payload, it first requests the shared buffer
58 * IPA address from Host using HOST_CALL/RSI, it reads the command to be executed,
59 * performs the request, and returns to Host with the execution state SUCCESS/FAILED
60 *
61 * Host in NS world requests Realm to execute certain operations using command
62 * depending on the test case the Host wants to perform.
63 */
64void realm_payload_main(void)
65{
nabkah01002e5692022-10-10 12:36:46 +010066 bool test_succeed = false;
67
68 realm_set_shared_structure((host_shared_data_t *)rsi_get_ns_buffer());
Shruti Gupta550e3e82023-08-16 13:20:11 +010069 if (realm_get_my_shared_structure() != NULL) {
70 uint8_t cmd = realm_shared_data_get_my_realm_cmd();
AlexeiFedorov2f30f102023-03-13 19:37:46 +000071
nabkah01002e5692022-10-10 12:36:46 +010072 switch (cmd) {
73 case REALM_SLEEP_CMD:
74 realm_sleep_cmd();
75 test_succeed = true;
76 break;
Shruti Gupta9d0cfe82023-04-17 10:57:26 +010077 case REALM_PAUTH_SET_CMD:
78 test_succeed = test_realm_pauth_set_cmd();
79 break;
80 case REALM_PAUTH_CHECK_CMD:
81 test_succeed = test_realm_pauth_check_cmd();
82 break;
83 case REALM_PAUTH_FAULT:
84 test_succeed = test_realm_pauth_fault();
85 break;
nabkah01002e5692022-10-10 12:36:46 +010086 case REALM_GET_RSI_VERSION:
87 realm_get_rsi_version();
88 test_succeed = true;
89 break;
AlexeiFedorov2f30f102023-03-13 19:37:46 +000090 case REALM_PMU_CYCLE:
91 test_succeed = test_pmuv3_cycle_works_realm();
92 break;
93 case REALM_PMU_EVENT:
94 test_succeed = test_pmuv3_event_works_realm();
95 break;
96 case REALM_PMU_PRESERVE:
97 test_succeed = test_pmuv3_rmm_preserves();
98 break;
99 case REALM_PMU_INTERRUPT:
100 test_succeed = test_pmuv3_overflow_interrupt();
101 break;
Shruti Gupta369955a2023-04-19 18:05:56 +0100102 case REALM_REQ_FPU_FILL_CMD:
Arunachalam Ganapathy7e514f62023-08-30 13:27:36 +0100103 fpu_state_write_rand(&rl_fpu_state_write);
Shruti Gupta369955a2023-04-19 18:05:56 +0100104 test_succeed = true;
105 break;
106 case REALM_REQ_FPU_CMP_CMD:
Arunachalam Ganapathy7e514f62023-08-30 13:27:36 +0100107 fpu_state_read(&rl_fpu_state_read);
108 test_succeed = !fpu_state_compare(&rl_fpu_state_write,
109 &rl_fpu_state_read);
Arunachalam Ganapathy9af432e2023-06-02 17:18:23 +0100110 break;
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +0100111 case REALM_SVE_RDVL:
112 test_succeed = test_realm_sve_rdvl();
113 break;
114 case REALM_SVE_ID_REGISTERS:
115 test_succeed = test_realm_sve_read_id_registers();
116 break;
117 case REALM_SVE_PROBE_VL:
118 test_succeed = test_realm_sve_probe_vl();
Shruti Gupta369955a2023-04-19 18:05:56 +0100119 break;
Arunachalam Ganapathyc1136a82023-04-12 15:24:44 +0100120 case REALM_SVE_OPS:
121 test_succeed = test_realm_sve_ops();
122 break;
Arunachalam Ganapathy5270d012023-04-19 14:53:42 +0100123 case REALM_SVE_FILL_REGS:
124 test_succeed = test_realm_sve_fill_regs();
125 break;
Arunachalam Ganapathyf3697172023-09-04 15:04:46 +0100126 case REALM_SVE_CMP_REGS:
127 test_succeed = test_realm_sve_cmp_regs();
128 break;
Arunachalam Ganapathy73949a22023-06-05 12:01:05 +0100129 case REALM_SVE_UNDEF_ABORT:
130 test_succeed = test_realm_sve_undef_abort();
131 break;
nabkah01002e5692022-10-10 12:36:46 +0100132 default:
AlexeiFedorov2f30f102023-03-13 19:37:46 +0000133 realm_printf("%s() invalid cmd %u\n", __func__, cmd);
nabkah01002e5692022-10-10 12:36:46 +0100134 break;
135 }
136 }
137
138 if (test_succeed) {
139 rsi_exit_to_host(HOST_CALL_EXIT_SUCCESS_CMD);
140 } else {
141 rsi_exit_to_host(HOST_CALL_EXIT_FAILED_CMD);
142 }
143}