blob: 2ade7bd98b08ea838a874e06b44a0c30b3fd63f5 [file] [log] [blame]
J-Alves9f6f0142020-06-17 15:37:59 +01001/*
Max Shvetsov103e0562021-02-04 16:58:31 +00002 * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
J-Alves9f6f0142020-06-17 15:37:59 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6#include <assert.h>
J-Alves9f6f0142020-06-17 15:37:59 +01007#include <debug.h>
Max Shvetsov40eb6a22020-06-08 11:15:30 +01008#include <errno.h>
Max Shvetsov103e0562021-02-04 16:58:31 +00009
Max Shvetsovc32f4782020-06-23 09:41:15 +010010#include <cactus_def.h>
Max Shvetsov103e0562021-02-04 16:58:31 +000011#include <cactus_platform_def.h>
J-Alves8f4a56f2020-10-28 10:29:05 +000012#include <ffa_endpoints.h>
J-Alves9f6f0142020-06-17 15:37:59 +010013#include <sp_helpers.h>
Olivier Deprez6967c242021-04-09 09:24:08 +020014#include <spm_helpers.h>
Max Shvetsov103e0562021-02-04 16:58:31 +000015#include <spm_common.h>
J-Alves9f6f0142020-06-17 15:37:59 +010016
J-Alves63cdaa72020-10-08 17:22:45 +010017#include <lib/libc/string.h>
J-Alves63cdaa72020-10-08 17:22:45 +010018
J-Alves9f6f0142020-06-17 15:37:59 +010019/* FFA version test helpers */
20#define FFA_MAJOR 1U
21#define FFA_MINOR 0U
22
Max Shvetsovc32f4782020-06-23 09:41:15 +010023static const uint32_t primary_uuid[4] = PRIMARY_UUID;
24static const uint32_t secondary_uuid[4] = SECONDARY_UUID;
Ruari Phippsd75596a2020-07-17 16:41:34 +010025static const uint32_t tertiary_uuid[4] = TERTIARY_UUID;
Max Shvetsovc32f4782020-06-23 09:41:15 +010026static const uint32_t null_uuid[4] = {0};
27
Max Shvetsov40eb6a22020-06-08 11:15:30 +010028/*
29 * Test FFA_FEATURES interface.
30 */
31static void ffa_features_test(void)
32{
33 const char *test_features = "FFA Features interface";
34 smc_ret_values ffa_ret;
Max Shvetsov103e0562021-02-04 16:58:31 +000035 const struct ffa_features_test *ffa_feature_test_target;
Max Shvetsov40eb6a22020-06-08 11:15:30 +010036 unsigned int i, test_target_size =
Max Shvetsov103e0562021-02-04 16:58:31 +000037 get_ffa_feature_test_target(&ffa_feature_test_target);
38
Max Shvetsov40eb6a22020-06-08 11:15:30 +010039
40 announce_test_section_start(test_features);
41
42 for (i = 0U; i < test_target_size; i++) {
Max Shvetsov103e0562021-02-04 16:58:31 +000043 announce_test_start(ffa_feature_test_target[i].test_name);
Max Shvetsov40eb6a22020-06-08 11:15:30 +010044
Max Shvetsov103e0562021-02-04 16:58:31 +000045 ffa_ret = ffa_features(ffa_feature_test_target[i].feature);
J-Alves6cb21d92021-01-07 15:18:12 +000046 expect(ffa_func_id(ffa_ret), ffa_feature_test_target[i].expected_ret);
Max Shvetsov103e0562021-02-04 16:58:31 +000047 if (ffa_feature_test_target[i].expected_ret == FFA_ERROR) {
J-Alves6cb21d92021-01-07 15:18:12 +000048 expect(ffa_error_code(ffa_ret), FFA_ERROR_NOT_SUPPORTED);
Max Shvetsov40eb6a22020-06-08 11:15:30 +010049 }
50
Max Shvetsov103e0562021-02-04 16:58:31 +000051 announce_test_end(ffa_feature_test_target[i].test_name);
Max Shvetsov40eb6a22020-06-08 11:15:30 +010052 }
53
54 announce_test_section_end(test_features);
55}
56
Max Shvetsovc32f4782020-06-23 09:41:15 +010057static void ffa_partition_info_helper(struct mailbox_buffers *mb, const uint32_t uuid[4],
58 const struct ffa_partition_info *expected,
59 const uint16_t expected_size)
60{
61 smc_ret_values ret = ffa_partition_info_get(uuid);
62 unsigned int i;
J-Alves6cb21d92021-01-07 15:18:12 +000063 expect(ffa_func_id(ret), FFA_SUCCESS_SMC32);
Max Shvetsovc32f4782020-06-23 09:41:15 +010064
65 struct ffa_partition_info *info = (struct ffa_partition_info *)(mb->recv);
66 for (i = 0U; i < expected_size; i++) {
67 expect(info[i].id, expected[i].id);
68 expect(info[i].exec_context, expected[i].exec_context);
69 expect(info[i].properties, expected[i].properties);
70 }
71
72 ret = ffa_rx_release();
J-Alves6cb21d92021-01-07 15:18:12 +000073 expect(ffa_func_id(ret), FFA_SUCCESS_SMC32);
Max Shvetsovc32f4782020-06-23 09:41:15 +010074}
75
76static void ffa_partition_info_wrong_test(void)
77{
78 const char *test_wrong_uuid = "Request wrong UUID";
79 uint32_t uuid[4] = {1};
80
81 announce_test_start(test_wrong_uuid);
82
83 smc_ret_values ret = ffa_partition_info_get(uuid);
J-Alves6cb21d92021-01-07 15:18:12 +000084 expect(ffa_func_id(ret), FFA_ERROR);
85 expect(ffa_error_code(ret), FFA_ERROR_INVALID_PARAMETER);
Max Shvetsovc32f4782020-06-23 09:41:15 +010086
87 announce_test_end(test_wrong_uuid);
88}
89
90static void ffa_partition_info_get_test(struct mailbox_buffers *mb)
91{
92 const char *test_partition_info = "FFA Partition info interface";
93 const char *test_primary = "Get primary partition info";
94 const char *test_secondary = "Get secondary partition info";
Ruari Phippsd75596a2020-07-17 16:41:34 +010095 const char *test_tertiary = "Get tertiary partition info";
Max Shvetsovc32f4782020-06-23 09:41:15 +010096 const char *test_all = "Get all partitions info";
97
98 const struct ffa_partition_info expected_info[] = {
Arunachalam Ganapathy51be1fe2020-09-22 13:25:21 +010099 /* Primary partition info */
100 {
101 .id = SPM_VM_ID_FIRST,
102 .exec_context = CACTUS_PRIMARY_EC_COUNT,
Olivier Deprez6d274a42020-10-23 09:12:27 +0200103 /* Supports receipt of direct message requests. */
104 .properties = 1U
Arunachalam Ganapathy51be1fe2020-09-22 13:25:21 +0100105 },
106 /* Secondary partition info */
107 {
108 .id = SPM_VM_ID_FIRST + 1U,
109 .exec_context = CACTUS_SECONDARY_EC_COUNT,
Olivier Deprez6d274a42020-10-23 09:12:27 +0200110 .properties = 1U
Arunachalam Ganapathy51be1fe2020-09-22 13:25:21 +0100111 },
112 /* Tertiary partition info */
113 {
114 .id = SPM_VM_ID_FIRST + 2U,
115 .exec_context = CACTUS_TERTIARY_EC_COUNT,
Olivier Deprez6d274a42020-10-23 09:12:27 +0200116 .properties = 1U
Arunachalam Ganapathy51be1fe2020-09-22 13:25:21 +0100117 }
Max Shvetsovc32f4782020-06-23 09:41:15 +0100118 };
119
120 announce_test_section_start(test_partition_info);
121
Ruari Phippsd75596a2020-07-17 16:41:34 +0100122 announce_test_start(test_tertiary);
123 ffa_partition_info_helper(mb, tertiary_uuid, &expected_info[2], 1);
124 announce_test_end(test_tertiary);
125
Max Shvetsovc32f4782020-06-23 09:41:15 +0100126 announce_test_start(test_secondary);
127 ffa_partition_info_helper(mb, secondary_uuid, &expected_info[1], 1);
128 announce_test_end(test_secondary);
129
130 announce_test_start(test_primary);
131 ffa_partition_info_helper(mb, primary_uuid, &expected_info[0], 1);
132 announce_test_end(test_primary);
133
134 announce_test_start(test_all);
Ruari Phippsd75596a2020-07-17 16:41:34 +0100135 ffa_partition_info_helper(mb, null_uuid, expected_info, 3);
Max Shvetsovc32f4782020-06-23 09:41:15 +0100136 announce_test_end(test_all);
137
138 ffa_partition_info_wrong_test();
139
140 announce_test_section_end(test_partition_info);
141}
142
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100143void ffa_version_test(void)
J-Alves9f6f0142020-06-17 15:37:59 +0100144{
J-Alves9f6f0142020-06-17 15:37:59 +0100145 const char *test_ffa_version = "FFA Version interface";
146
J-Alves9f6f0142020-06-17 15:37:59 +0100147 announce_test_start(test_ffa_version);
148
149 smc_ret_values ret = ffa_version(MAKE_FFA_VERSION(FFA_MAJOR, FFA_MINOR));
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100150 uint32_t spm_version = (uint32_t)ret.ret0;
J-Alves9f6f0142020-06-17 15:37:59 +0100151
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100152 bool ffa_version_compatible =
153 ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR &&
154 (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR);
J-Alves9f6f0142020-06-17 15:37:59 +0100155
156 NOTICE("FFA_VERSION returned %u.%u; Compatible: %i\n",
157 spm_version >> FFA_VERSION_MAJOR_SHIFT,
158 spm_version & FFA_VERSION_MINOR_MASK,
159 (int)ffa_version_compatible);
160
161 expect((int)ffa_version_compatible, (int)true);
162
163 announce_test_end(test_ffa_version);
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100164}
165
166void ffa_tests(struct mailbox_buffers *mb)
167{
168 const char *test_ffa = "FFA Interfaces";
169
170 announce_test_section_start(test_ffa);
J-Alves9f6f0142020-06-17 15:37:59 +0100171
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100172 ffa_features_test();
Max Shvetsov57c6ddb2020-07-01 14:09:48 +0100173 ffa_version_test();
Max Shvetsovc32f4782020-06-23 09:41:15 +0100174 ffa_partition_info_get_test(mb);
Max Shvetsov40eb6a22020-06-08 11:15:30 +0100175
J-Alves9f6f0142020-06-17 15:37:59 +0100176 announce_test_section_end(test_ffa);
177}