blob: 586d4005bafbadf53c86136edc97541a6b750a52 [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
Shruti Gupta369955a2023-04-19 18:05:56 +010021static fpu_reg_state_t fpu_temp_rl;
nabkah01002e5692022-10-10 12:36:46 +010022/*
AlexeiFedorov2f30f102023-03-13 19:37:46 +000023 * This function reads sleep time in ms from shared buffer and spins PE
24 * in a loop for that time period.
nabkah01002e5692022-10-10 12:36:46 +010025 */
26static void realm_sleep_cmd(void)
27{
Shruti Gupta550e3e82023-08-16 13:20:11 +010028 uint64_t sleep = realm_shared_data_get_my_host_val(HOST_SLEEP_INDEX);
nabkah01002e5692022-10-10 12:36:46 +010029
AlexeiFedorov2f30f102023-03-13 19:37:46 +000030 realm_printf("Realm: going to sleep for %llums\n", sleep);
nabkah01002e5692022-10-10 12:36:46 +010031 waitms(sleep);
32}
33
34/*
35 * This function requests RSI/ABI version from RMM.
36 */
37static void realm_get_rsi_version(void)
38{
39 u_register_t version;
40
41 version = rsi_get_version();
42 if (version == (u_register_t)SMC_UNKNOWN) {
AlexeiFedorov2f30f102023-03-13 19:37:46 +000043 realm_printf("SMC_RSI_ABI_VERSION failed (%ld)", (long)version);
nabkah01002e5692022-10-10 12:36:46 +010044 return;
45 }
46
AlexeiFedorov2f30f102023-03-13 19:37:46 +000047 realm_printf("RSI ABI version %u.%u (expected: %u.%u)",
nabkah01002e5692022-10-10 12:36:46 +010048 RSI_ABI_VERSION_GET_MAJOR(version),
49 RSI_ABI_VERSION_GET_MINOR(version),
50 RSI_ABI_VERSION_GET_MAJOR(RSI_ABI_VERSION),
51 RSI_ABI_VERSION_GET_MINOR(RSI_ABI_VERSION));
52}
53
54/*
55 * This is the entry function for Realm payload, it first requests the shared buffer
56 * IPA address from Host using HOST_CALL/RSI, it reads the command to be executed,
57 * performs the request, and returns to Host with the execution state SUCCESS/FAILED
58 *
59 * Host in NS world requests Realm to execute certain operations using command
60 * depending on the test case the Host wants to perform.
61 */
62void realm_payload_main(void)
63{
nabkah01002e5692022-10-10 12:36:46 +010064 bool test_succeed = false;
65
66 realm_set_shared_structure((host_shared_data_t *)rsi_get_ns_buffer());
Shruti Gupta550e3e82023-08-16 13:20:11 +010067 if (realm_get_my_shared_structure() != NULL) {
68 uint8_t cmd = realm_shared_data_get_my_realm_cmd();
AlexeiFedorov2f30f102023-03-13 19:37:46 +000069
nabkah01002e5692022-10-10 12:36:46 +010070 switch (cmd) {
71 case REALM_SLEEP_CMD:
72 realm_sleep_cmd();
73 test_succeed = true;
74 break;
Shruti Gupta9d0cfe82023-04-17 10:57:26 +010075 case REALM_PAUTH_SET_CMD:
76 test_succeed = test_realm_pauth_set_cmd();
77 break;
78 case REALM_PAUTH_CHECK_CMD:
79 test_succeed = test_realm_pauth_check_cmd();
80 break;
81 case REALM_PAUTH_FAULT:
82 test_succeed = test_realm_pauth_fault();
83 break;
nabkah01002e5692022-10-10 12:36:46 +010084 case REALM_GET_RSI_VERSION:
85 realm_get_rsi_version();
86 test_succeed = true;
87 break;
AlexeiFedorov2f30f102023-03-13 19:37:46 +000088 case REALM_PMU_CYCLE:
89 test_succeed = test_pmuv3_cycle_works_realm();
90 break;
91 case REALM_PMU_EVENT:
92 test_succeed = test_pmuv3_event_works_realm();
93 break;
94 case REALM_PMU_PRESERVE:
95 test_succeed = test_pmuv3_rmm_preserves();
96 break;
97 case REALM_PMU_INTERRUPT:
98 test_succeed = test_pmuv3_overflow_interrupt();
99 break;
Shruti Gupta369955a2023-04-19 18:05:56 +0100100 case REALM_REQ_FPU_FILL_CMD:
101 fpu_state_fill_regs_and_template(&fpu_temp_rl);
102 test_succeed = true;
103 break;
104 case REALM_REQ_FPU_CMP_CMD:
105 test_succeed = fpu_state_compare_template(&fpu_temp_rl);
Arunachalam Ganapathy9af432e2023-06-02 17:18:23 +0100106 break;
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +0100107 case REALM_SVE_RDVL:
108 test_succeed = test_realm_sve_rdvl();
109 break;
110 case REALM_SVE_ID_REGISTERS:
111 test_succeed = test_realm_sve_read_id_registers();
112 break;
113 case REALM_SVE_PROBE_VL:
114 test_succeed = test_realm_sve_probe_vl();
Shruti Gupta369955a2023-04-19 18:05:56 +0100115 break;
Arunachalam Ganapathyc1136a82023-04-12 15:24:44 +0100116 case REALM_SVE_OPS:
117 test_succeed = test_realm_sve_ops();
118 break;
Arunachalam Ganapathy5270d012023-04-19 14:53:42 +0100119 case REALM_SVE_FILL_REGS:
120 test_succeed = test_realm_sve_fill_regs();
121 break;
nabkah01002e5692022-10-10 12:36:46 +0100122 default:
AlexeiFedorov2f30f102023-03-13 19:37:46 +0000123 realm_printf("%s() invalid cmd %u\n", __func__, cmd);
nabkah01002e5692022-10-10 12:36:46 +0100124 break;
125 }
126 }
127
128 if (test_succeed) {
129 rsi_exit_to_host(HOST_CALL_EXIT_SUCCESS_CMD);
130 } else {
131 rsi_exit_to_host(HOST_CALL_EXIT_FAILED_CMD);
132 }
133}