blob: 6271da6e3effd614cae08082a78d300c0d12229c [file] [log] [blame]
David Brazdil7a462ec2019-08-15 12:27:47 +01001/*
2 * Copyright 2019 The Hafnium Authors.
3 *
Andrew Walbrane959ec12020-06-17 15:01:09 +01004 * Use of this source code is governed by a BSD-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/BSD-3-Clause.
David Brazdil7a462ec2019-08-15 12:27:47 +01007 */
8
David Brazdil52256ff2019-08-23 15:15:15 +01009#include <array>
10#include <cstdio>
Andrew Scullae9962e2019-10-03 16:51:16 +010011#include <span>
David Brazdil52256ff2019-08-23 15:15:15 +010012#include <sstream>
13
David Brazdil7a462ec2019-08-15 12:27:47 +010014#include <gmock/gmock.h>
15
16extern "C" {
J-Alves2f86c1e2022-02-23 18:44:19 +000017#include "hf/arch/std.h"
18
David Brazdil7a462ec2019-08-15 12:27:47 +010019#include "hf/manifest.h"
J-Alves2f86c1e2022-02-23 18:44:19 +000020#include "hf/sp_pkg.h"
David Brazdil7a462ec2019-08-15 12:27:47 +010021}
22
23namespace
24{
Andrew Scullae9962e2019-10-03 16:51:16 +010025using ::testing::ElementsAre;
David Brazdil7a462ec2019-08-15 12:27:47 +010026using ::testing::Eq;
Andrew Scullae9962e2019-10-03 16:51:16 +010027using ::testing::IsEmpty;
David Brazdil7a462ec2019-08-15 12:27:47 +010028using ::testing::NotNull;
29
Daniel Boulby801f8ef2022-06-27 14:21:01 +010030using struct_manifest = struct manifest;
31
32constexpr size_t TEST_HEAP_SIZE = PAGE_SIZE * 32;
33
David Brazdil52256ff2019-08-23 15:15:15 +010034template <typename T>
David Brazdil0dbb41f2019-09-09 18:03:35 +010035void exec(const char *program, const char *args[], const T &stdin,
David Brazdil52256ff2019-08-23 15:15:15 +010036 std::vector<char> *stdout)
37{
38 /* Create two pipes, one for stdin and one for stdout. */
39 int pipes[2][2];
40 pipe(pipes[0]);
41 pipe(pipes[1]);
David Brazdil7a462ec2019-08-15 12:27:47 +010042
David Brazdil52256ff2019-08-23 15:15:15 +010043 /* Assign FDs for reading/writing by the parent/child. */
44 int parent_read_fd = pipes[1][0]; /* stdout pipe, read FD */
45 int parent_write_fd = pipes[0][1]; /* stdin pipe, write FD */
46 int child_read_fd = pipes[0][0]; /* stdin pipe, read FD */
47 int child_write_fd = pipes[1][1]; /* stdout pipe, write FD */
David Brazdil7a462ec2019-08-15 12:27:47 +010048
David Brazdil52256ff2019-08-23 15:15:15 +010049 if (fork()) {
50 /* Parent process. */
51 std::array<char, 128> buf;
52 ssize_t res;
53
54 /* Close child FDs which won't be used. */
55 close(child_read_fd);
56 close(child_write_fd);
57
58 /* Write to stdin. */
59 for (size_t count = 0; count < stdin.size();) {
60 res = write(parent_write_fd, stdin.data() + count,
61 stdin.size() - count);
62 if (res < 0) {
63 std::cerr << "IO error" << std::endl;
64 exit(1);
65 }
66 count += res;
67 }
68 close(parent_write_fd);
69
70 /* Read from stdout. */
71 while (true) {
72 res = read(parent_read_fd, buf.data(), buf.size());
73 if (res == 0) {
74 /* EOF */
75 break;
76 } else if (res < 0) {
77 std::cerr << "IO error" << std::endl;
78 exit(1);
79 }
80 stdout->insert(stdout->end(), buf.begin(),
81 buf.begin() + res);
82 }
83 close(parent_read_fd);
84 } else {
85 /* Child process. */
86
87 /* Redirect stdin/stdout to read/write FDs. */
88 dup2(child_read_fd, STDIN_FILENO);
89 dup2(child_write_fd, STDOUT_FILENO);
90
91 /* Close all FDs which are now unused. */
92 close(child_read_fd);
93 close(child_write_fd);
94 close(parent_read_fd);
95 close(parent_write_fd);
96
97 /* Execute the given program. */
David Brazdil0dbb41f2019-09-09 18:03:35 +010098 execv(program, const_cast<char *const *>(args));
David Brazdil52256ff2019-08-23 15:15:15 +010099 }
100}
101
102/**
103 * Class for programatically building a Device Tree.
104 *
105 * Usage:
106 * std::vector<char> dtb = ManifestDtBuilder()
107 * .Command1()
108 * .Command2()
109 * ...
110 * .CommandN()
111 * .Build();
112 */
113class ManifestDtBuilder
114{
115 public:
116 ManifestDtBuilder()
117 {
118 dts_ << "/dts-v1/;" << std::endl;
119 dts_ << std::endl;
120
121 /* Start root node. */
122 StartChild("/");
123 }
124
Andrew Scullae9962e2019-10-03 16:51:16 +0100125 std::vector<char> Build(bool dump = false)
David Brazdil52256ff2019-08-23 15:15:15 +0100126 {
David Brazdil0dbb41f2019-09-09 18:03:35 +0100127 const char *program = "./build/image/dtc.py";
128 const char *dtc_args[] = {program, "compile", NULL};
David Brazdil52256ff2019-08-23 15:15:15 +0100129 std::vector<char> dtc_stdout;
130
131 /* Finish root node. */
132 EndChild();
133
Andrew Scullae9962e2019-10-03 16:51:16 +0100134 if (dump) {
135 Dump();
136 }
137
David Brazdil0dbb41f2019-09-09 18:03:35 +0100138 exec(program, dtc_args, dts_.str(), &dtc_stdout);
David Brazdil52256ff2019-08-23 15:15:15 +0100139 return dtc_stdout;
140 }
141
Andrew Scullae9962e2019-10-03 16:51:16 +0100142 void Dump()
143 {
144 std::cerr << dts_.str() << std::endl;
145 }
146
David Brazdil52256ff2019-08-23 15:15:15 +0100147 ManifestDtBuilder &StartChild(const std::string_view &name)
148 {
149 dts_ << name << " {" << std::endl;
150 return *this;
151 }
152
153 ManifestDtBuilder &EndChild()
154 {
155 dts_ << "};" << std::endl;
156 return *this;
157 }
158
David Brazdil74e9c3b2019-08-28 11:09:08 +0100159 ManifestDtBuilder &Compatible(const std::vector<std::string_view>
160 &value = {"hafnium,hafnium"})
161 {
162 return StringListProperty("compatible", value);
163 }
164
David Brazdil52256ff2019-08-23 15:15:15 +0100165 ManifestDtBuilder &DebugName(const std::string_view &value)
166 {
167 return StringProperty("debug_name", value);
168 }
169
Manish Pandey6542f5c2020-04-27 14:37:46 +0100170 ManifestDtBuilder &Description(const std::string_view &value)
171 {
172 return StringProperty("description", value);
173 }
174
David Brazdil52256ff2019-08-23 15:15:15 +0100175 ManifestDtBuilder &KernelFilename(const std::string_view &value)
176 {
177 return StringProperty("kernel_filename", value);
178 }
179
David Brazdile6f83222019-09-23 14:47:37 +0100180 ManifestDtBuilder &RamdiskFilename(const std::string_view &value)
181 {
182 return StringProperty("ramdisk_filename", value);
183 }
184
David Brazdil080ee312020-02-25 15:30:30 -0800185 ManifestDtBuilder &BootAddress(uint64_t value)
186 {
187 return Integer64Property("boot_address", value);
188 }
189
Andrew Scullae9962e2019-10-03 16:51:16 +0100190 ManifestDtBuilder &VcpuCount(uint32_t value)
David Brazdil52256ff2019-08-23 15:15:15 +0100191 {
192 return IntegerProperty("vcpu_count", value);
193 }
194
Andrew Scullae9962e2019-10-03 16:51:16 +0100195 ManifestDtBuilder &MemSize(uint32_t value)
David Brazdil52256ff2019-08-23 15:15:15 +0100196 {
197 return IntegerProperty("mem_size", value);
198 }
199
Andrew Scullae9962e2019-10-03 16:51:16 +0100200 ManifestDtBuilder &SmcWhitelist(const std::vector<uint32_t> &value)
201 {
202 return IntegerListProperty("smc_whitelist", value);
203 }
204
205 ManifestDtBuilder &SmcWhitelistPermissive()
206 {
207 return BooleanProperty("smc_whitelist_permissive");
208 }
209
Olivier Deprez62d99e32020-01-09 15:58:07 +0100210 ManifestDtBuilder &LoadAddress(uint64_t value)
211 {
212 return Integer64Property("load_address", value);
213 }
214
215 ManifestDtBuilder &FfaPartition()
216 {
217 return BooleanProperty("is_ffa_partition");
218 }
219
Andrew Scullae9962e2019-10-03 16:51:16 +0100220 ManifestDtBuilder &Property(const std::string_view &name,
221 const std::string_view &value)
222 {
223 dts_ << name << " = " << value << ";" << std::endl;
224 return *this;
225 }
226
Manish Pandeyfa1f2912020-05-05 12:57:01 +0100227 ManifestDtBuilder &Label(const std::string_view &name)
228 {
229 dts_ << name << ": ";
230 return *this;
231 }
232
Manish Pandeycb8fbb22020-08-18 00:04:43 +0100233 ManifestDtBuilder &FfaValidManifest()
234 {
235 Compatible({"arm,ffa-manifest-1.0"});
236 Property("ffa-version", "<0x10000>");
237 Property("uuid",
238 "<0xb4b5671e 0x4a904fe1 0xb81ffb13 0xdae1dacb>");
239 Property("execution-ctx-count", "<1>");
240 Property("exception-level", "<2>");
241 Property("execution-state", "<0>");
J-Alves2f86c1e2022-02-23 18:44:19 +0000242 Property("entrypoint-offset", "<0x00002000>");
Manish Pandeycb8fbb22020-08-18 00:04:43 +0100243 Property("xlat-granule", "<0>");
J-Alvesb37fd082020-10-22 12:29:21 +0100244 Property("boot-order", "<0>");
Maksims Svecovsb596eab2021-04-27 00:52:27 +0100245 Property("messaging-method", "<4>");
Madhukar Pappireddy84154052022-06-21 18:30:25 -0500246 Property("ns-interrupts-action", "<1>");
Manish Pandeycb8fbb22020-08-18 00:04:43 +0100247 return *this;
248 }
249
David Brazdil52256ff2019-08-23 15:15:15 +0100250 private:
251 ManifestDtBuilder &StringProperty(const std::string_view &name,
252 const std::string_view &value)
253 {
254 dts_ << name << " = \"" << value << "\";" << std::endl;
255 return *this;
256 }
257
David Brazdil74e9c3b2019-08-28 11:09:08 +0100258 ManifestDtBuilder &StringListProperty(
259 const std::string_view &name,
260 const std::vector<std::string_view> &value)
261 {
262 bool is_first = true;
263
264 dts_ << name << " = ";
265 for (const std::string_view &entry : value) {
266 if (is_first) {
267 is_first = false;
268 } else {
269 dts_ << ", ";
270 }
271 dts_ << "\"" << entry << "\"";
272 }
273 dts_ << ";" << std::endl;
274 return *this;
275 }
276
David Brazdil52256ff2019-08-23 15:15:15 +0100277 ManifestDtBuilder &IntegerProperty(const std::string_view &name,
Andrew Scullae9962e2019-10-03 16:51:16 +0100278 uint32_t value)
David Brazdil52256ff2019-08-23 15:15:15 +0100279 {
280 dts_ << name << " = <" << value << ">;" << std::endl;
281 return *this;
282 }
283
David Brazdil080ee312020-02-25 15:30:30 -0800284 ManifestDtBuilder &Integer64Property(const std::string_view &name,
285 uint64_t value)
286 {
287 uint32_t high = value >> 32;
288 uint32_t low = (uint32_t)value;
289 dts_ << name << " = <" << high << " " << low << ">;"
290 << std::endl;
291 return *this;
292 }
293
Andrew Scullae9962e2019-10-03 16:51:16 +0100294 ManifestDtBuilder &IntegerListProperty(
295 const std::string_view &name,
296 const std::vector<uint32_t> &value)
297 {
298 dts_ << name << " = < ";
299 for (const uint32_t entry : value) {
300 dts_ << entry << " ";
301 }
302 dts_ << ">;" << std::endl;
303 return *this;
304 }
305
306 ManifestDtBuilder &BooleanProperty(const std::string_view &name)
307 {
Andrew Scull5dc089e2019-11-04 13:21:03 +0000308 dts_ << name << ";" << std::endl;
309 return *this;
Andrew Scullae9962e2019-10-03 16:51:16 +0100310 }
311
David Brazdil52256ff2019-08-23 15:15:15 +0100312 std::stringstream dts_;
313};
314
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100315class manifest : public ::testing::Test
David Brazdil0dbb41f2019-09-09 18:03:35 +0100316{
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100317 void SetUp() override
318 {
319 test_heap = std::make_unique<uint8_t[]>(TEST_HEAP_SIZE);
320 mpool_init(&ppool, MM_PPOOL_ENTRY_SIZE);
321 mpool_add_chunk(&ppool, test_heap.get(), TEST_HEAP_SIZE);
322 }
323
Olivier Deprez93644652022-09-09 11:01:12 +0200324 void TearDown() override
325 {
326 manifest_dealloc();
327 }
328
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100329 std::unique_ptr<uint8_t[]> test_heap;
330
331 protected:
Olivier Deprez62d99e32020-01-09 15:58:07 +0100332 struct mpool ppool;
David Brazdil0dbb41f2019-09-09 18:03:35 +0100333
Olivier Deprez93644652022-09-09 11:01:12 +0200334 void manifest_dealloc(void)
335 {
336 manifest_deinit(&ppool);
337 }
338
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100339 public:
340 /**
341 * Class for programatically building a Partition package.
342 */
343 class Partition_package
344 {
345 public:
346 __attribute__((aligned(PAGE_SIZE))) struct sp_pkg_header spkg;
347 __attribute__((
348 aligned(PAGE_SIZE))) char manifest_dtb[PAGE_SIZE] = {};
349 __attribute__((aligned(PAGE_SIZE))) char img[PAGE_SIZE] = {};
David Brazdil0dbb41f2019-09-09 18:03:35 +0100350
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100351 Partition_package(const std::vector<char> &vec)
352 {
353 // Initialise header field
354 spkg.magic = SP_PKG_HEADER_MAGIC;
355 spkg.version = SP_PKG_HEADER_VERSION_2;
356 spkg.pm_offset = PAGE_SIZE;
357 spkg.pm_size = vec.size();
358 spkg.img_offset = 2 * PAGE_SIZE;
359 spkg.img_size = ARRAY_SIZE(img);
360
361 // Copy dtb into package
362 std::copy(vec.begin(), vec.end(), manifest_dtb);
363 }
364 };
365
366 enum manifest_return_code manifest_from_vec(
Olivier Deprez93644652022-09-09 11:01:12 +0200367 struct_manifest **m, const std::vector<char> &vec)
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100368 {
369 struct memiter it;
370 struct mm_stage1_locked mm_stage1_locked;
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100371
372 memiter_init(&it, vec.data(), vec.size());
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100373
Olivier Deprez93644652022-09-09 11:01:12 +0200374 return manifest_init(mm_stage1_locked, m, &it, &ppool);
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100375 }
376
377 enum manifest_return_code ffa_manifest_from_vec(
Olivier Deprez93644652022-09-09 11:01:12 +0200378 struct_manifest **m, const std::vector<char> &vec)
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100379 {
380 struct memiter it;
381 struct mm_stage1_locked mm_stage1_locked;
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100382 Partition_package spkg(vec);
383
384 /* clang-format off */
385 std::vector<char> core_dtb = ManifestDtBuilder()
386 .StartChild("hypervisor")
387 .Compatible()
388 .StartChild("vm1")
389 .DebugName("primary_vm")
390 .FfaPartition()
391 .LoadAddress((uint64_t)&spkg)
392 .EndChild()
393 .EndChild()
394 .Build();
395 /* clang-format on */
396 memiter_init(&it, core_dtb.data(), core_dtb.size());
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100397
Olivier Deprez93644652022-09-09 11:01:12 +0200398 return manifest_init(mm_stage1_locked, m, &it, &ppool);
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100399 }
400};
401
402TEST_F(manifest, no_hypervisor_node)
David Brazdil7a462ec2019-08-15 12:27:47 +0100403{
Olivier Deprez93644652022-09-09 11:01:12 +0200404 struct_manifest *m;
David Brazdil52256ff2019-08-23 15:15:15 +0100405 std::vector<char> dtb = ManifestDtBuilder().Build();
David Brazdil7a462ec2019-08-15 12:27:47 +0100406
David Brazdila2358d42020-01-27 18:51:38 +0000407 ASSERT_EQ(manifest_from_vec(&m, dtb),
David Brazdil7a462ec2019-08-15 12:27:47 +0100408 MANIFEST_ERROR_NO_HYPERVISOR_FDT_NODE);
409}
410
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100411TEST_F(manifest, no_compatible_property)
David Brazdil7a462ec2019-08-15 12:27:47 +0100412{
Olivier Deprez93644652022-09-09 11:01:12 +0200413 struct_manifest *m;
David Brazdil7a462ec2019-08-15 12:27:47 +0100414
David Brazdil52256ff2019-08-23 15:15:15 +0100415 /* clang-format off */
416 std::vector<char> dtb = ManifestDtBuilder()
417 .StartChild("hypervisor")
418 .EndChild()
419 .Build();
420 /* clang-format on */
421
David Brazdilf4925382020-03-25 13:33:51 +0000422 ASSERT_EQ(manifest_from_vec(&m, dtb), MANIFEST_ERROR_NOT_COMPATIBLE);
David Brazdil7a462ec2019-08-15 12:27:47 +0100423}
424
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100425TEST_F(manifest, not_compatible)
David Brazdil7a462ec2019-08-15 12:27:47 +0100426{
Olivier Deprez93644652022-09-09 11:01:12 +0200427 struct_manifest *m;
David Brazdil7a462ec2019-08-15 12:27:47 +0100428
David Brazdil52256ff2019-08-23 15:15:15 +0100429 /* clang-format off */
430 std::vector<char> dtb = ManifestDtBuilder()
431 .StartChild("hypervisor")
David Brazdil74e9c3b2019-08-28 11:09:08 +0100432 .Compatible({ "foo,bar" })
433 .EndChild()
434 .Build();
435 /* clang-format on */
436
David Brazdila2358d42020-01-27 18:51:38 +0000437 ASSERT_EQ(manifest_from_vec(&m, dtb), MANIFEST_ERROR_NOT_COMPATIBLE);
David Brazdil74e9c3b2019-08-28 11:09:08 +0100438}
439
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100440TEST_F(manifest, compatible_one_of_many)
David Brazdil74e9c3b2019-08-28 11:09:08 +0100441{
Olivier Deprez93644652022-09-09 11:01:12 +0200442 struct_manifest *m;
David Brazdil74e9c3b2019-08-28 11:09:08 +0100443
444 /* clang-format off */
445 std::vector<char> dtb = ManifestDtBuilder()
446 .StartChild("hypervisor")
447 .Compatible({ "foo,bar", "hafnium,hafnium" })
448 .StartChild("vm1")
449 .DebugName("primary")
450 .EndChild()
451 .EndChild()
452 .Build();
453 /* clang-format on */
454
David Brazdila2358d42020-01-27 18:51:38 +0000455 ASSERT_EQ(manifest_from_vec(&m, dtb), MANIFEST_SUCCESS);
David Brazdil74e9c3b2019-08-28 11:09:08 +0100456}
457
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100458TEST_F(manifest, no_vm_nodes)
David Brazdil74e9c3b2019-08-28 11:09:08 +0100459{
Olivier Deprez93644652022-09-09 11:01:12 +0200460 struct_manifest *m;
David Brazdil74e9c3b2019-08-28 11:09:08 +0100461
462 /* clang-format off */
463 std::vector<char> dtb = ManifestDtBuilder()
464 .StartChild("hypervisor")
465 .Compatible()
466 .EndChild()
467 .Build();
468 /* clang-format on */
469
David Brazdila2358d42020-01-27 18:51:38 +0000470 ASSERT_EQ(manifest_from_vec(&m, dtb), MANIFEST_ERROR_NO_PRIMARY_VM);
David Brazdil0dbb41f2019-09-09 18:03:35 +0100471}
472
473static std::vector<char> gen_long_string_dtb(bool valid)
474{
475 const char last_valid[] = "1234567890123456789012345678901";
476 const char first_invalid[] = "12345678901234567890123456789012";
David Brazdil136f2942019-09-23 14:11:03 +0100477 static_assert(sizeof(last_valid) == STRING_MAX_SIZE);
478 static_assert(sizeof(first_invalid) == STRING_MAX_SIZE + 1);
David Brazdil0dbb41f2019-09-09 18:03:35 +0100479
480 /* clang-format off */
481 return ManifestDtBuilder()
482 .StartChild("hypervisor")
483 .Compatible()
484 .StartChild("vm1")
485 .DebugName(valid ? last_valid : first_invalid)
486 .EndChild()
487 .EndChild()
488 .Build();
489 /* clang-format on */
490}
491
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100492TEST_F(manifest, long_string)
David Brazdil0dbb41f2019-09-09 18:03:35 +0100493{
Olivier Deprez93644652022-09-09 11:01:12 +0200494 struct_manifest *m;
David Brazdil0dbb41f2019-09-09 18:03:35 +0100495 std::vector<char> dtb_last_valid = gen_long_string_dtb(true);
496 std::vector<char> dtb_first_invalid = gen_long_string_dtb(false);
497
David Brazdila2358d42020-01-27 18:51:38 +0000498 ASSERT_EQ(manifest_from_vec(&m, dtb_last_valid), MANIFEST_SUCCESS);
Olivier Deprez93644652022-09-09 11:01:12 +0200499 manifest_dealloc();
500
David Brazdila2358d42020-01-27 18:51:38 +0000501 ASSERT_EQ(manifest_from_vec(&m, dtb_first_invalid),
502 MANIFEST_ERROR_STRING_TOO_LONG);
David Brazdil74e9c3b2019-08-28 11:09:08 +0100503}
504
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100505TEST_F(manifest, reserved_vm_id)
David Brazdil74e9c3b2019-08-28 11:09:08 +0100506{
Olivier Deprez93644652022-09-09 11:01:12 +0200507 struct_manifest *m;
David Brazdil74e9c3b2019-08-28 11:09:08 +0100508
509 /* clang-format off */
510 std::vector<char> dtb = ManifestDtBuilder()
511 .StartChild("hypervisor")
512 .Compatible()
David Brazdil52256ff2019-08-23 15:15:15 +0100513 .StartChild("vm1")
514 .DebugName("primary_vm")
515 .EndChild()
516 .StartChild("vm0")
517 .DebugName("reserved_vm")
518 .VcpuCount(1)
519 .MemSize(0x1000)
520 .KernelFilename("kernel")
521 .EndChild()
522 .EndChild()
523 .Build();
524 /* clang-format on */
525
David Brazdila2358d42020-01-27 18:51:38 +0000526 ASSERT_EQ(manifest_from_vec(&m, dtb), MANIFEST_ERROR_RESERVED_VM_ID);
David Brazdil7a462ec2019-08-15 12:27:47 +0100527}
528
Andrew Scullae9962e2019-10-03 16:51:16 +0100529static std::vector<char> gen_vcpu_count_limit_dtb(uint32_t vcpu_count)
David Brazdil52256ff2019-08-23 15:15:15 +0100530{
531 /* clang-format off */
532 return ManifestDtBuilder()
533 .StartChild("hypervisor")
David Brazdil74e9c3b2019-08-28 11:09:08 +0100534 .Compatible()
David Brazdil52256ff2019-08-23 15:15:15 +0100535 .StartChild("vm1")
536 .DebugName("primary_vm")
537 .EndChild()
538 .StartChild("vm2")
539 .DebugName("secondary_vm")
540 .VcpuCount(vcpu_count)
541 .MemSize(0x1000)
542 .KernelFilename("kernel")
543 .EndChild()
544 .EndChild()
545 .Build();
546 /* clang-format on */
547}
David Brazdil7a462ec2019-08-15 12:27:47 +0100548
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100549TEST_F(manifest, vcpu_count_limit)
David Brazdil7a462ec2019-08-15 12:27:47 +0100550{
Olivier Deprez93644652022-09-09 11:01:12 +0200551 struct_manifest *m;
David Brazdil52256ff2019-08-23 15:15:15 +0100552 std::vector<char> dtb_last_valid = gen_vcpu_count_limit_dtb(UINT16_MAX);
553 std::vector<char> dtb_first_invalid =
554 gen_vcpu_count_limit_dtb(UINT16_MAX + 1);
David Brazdil7a462ec2019-08-15 12:27:47 +0100555
David Brazdila2358d42020-01-27 18:51:38 +0000556 ASSERT_EQ(manifest_from_vec(&m, dtb_last_valid), MANIFEST_SUCCESS);
Olivier Deprez93644652022-09-09 11:01:12 +0200557 ASSERT_EQ(m->vm_count, 2);
558 ASSERT_EQ(m->vm[1].secondary.vcpu_count, UINT16_MAX);
559 manifest_dealloc();
David Brazdil7a462ec2019-08-15 12:27:47 +0100560
David Brazdila2358d42020-01-27 18:51:38 +0000561 ASSERT_EQ(manifest_from_vec(&m, dtb_first_invalid),
David Brazdil0dbb41f2019-09-09 18:03:35 +0100562 MANIFEST_ERROR_INTEGER_OVERFLOW);
David Brazdil7a462ec2019-08-15 12:27:47 +0100563}
564
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100565TEST_F(manifest, no_ramdisk_primary)
David Brazdile6f83222019-09-23 14:47:37 +0100566{
Olivier Deprez93644652022-09-09 11:01:12 +0200567 struct_manifest *m;
David Brazdile6f83222019-09-23 14:47:37 +0100568
569 /* clang-format off */
570 std::vector<char> dtb = ManifestDtBuilder()
571 .StartChild("hypervisor")
572 .Compatible()
573 .StartChild("vm1")
574 .DebugName("primary_vm")
575 .EndChild()
576 .EndChild()
577 .Build();
578 /* clang-format on */
579
David Brazdila2358d42020-01-27 18:51:38 +0000580 ASSERT_EQ(manifest_from_vec(&m, dtb), MANIFEST_SUCCESS);
Olivier Deprez93644652022-09-09 11:01:12 +0200581 ASSERT_EQ(m->vm_count, 1);
582 ASSERT_STREQ(string_data(&m->vm[0].debug_name), "primary_vm");
583 ASSERT_STREQ(string_data(&m->vm[0].primary.ramdisk_filename), "");
David Brazdile6f83222019-09-23 14:47:37 +0100584}
585
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100586TEST_F(manifest, no_boot_address_primary)
David Brazdil080ee312020-02-25 15:30:30 -0800587{
Olivier Deprez93644652022-09-09 11:01:12 +0200588 struct_manifest *m;
David Brazdil080ee312020-02-25 15:30:30 -0800589
590 /* clang-format off */
591 std::vector<char> dtb = ManifestDtBuilder()
592 .StartChild("hypervisor")
593 .Compatible()
594 .StartChild("vm1")
595 .DebugName("primary_vm")
596 .EndChild()
597 .EndChild()
598 .Build();
599 /* clang-format on */
600
601 ASSERT_EQ(manifest_from_vec(&m, dtb), MANIFEST_SUCCESS);
Olivier Deprez93644652022-09-09 11:01:12 +0200602 ASSERT_EQ(m->vm_count, 1);
603 ASSERT_STREQ(string_data(&m->vm[0].debug_name), "primary_vm");
604 ASSERT_EQ(m->vm[0].primary.boot_address, MANIFEST_INVALID_ADDRESS);
David Brazdil080ee312020-02-25 15:30:30 -0800605}
606
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100607TEST_F(manifest, boot_address_primary)
David Brazdil080ee312020-02-25 15:30:30 -0800608{
Olivier Deprez93644652022-09-09 11:01:12 +0200609 struct_manifest *m;
David Brazdil080ee312020-02-25 15:30:30 -0800610 const uint64_t addr = UINT64_C(0x12345678ABCDEFEF);
611
612 /* clang-format off */
613 std::vector<char> dtb = ManifestDtBuilder()
614 .StartChild("hypervisor")
615 .Compatible()
616 .StartChild("vm1")
617 .DebugName("primary_vm")
618 .BootAddress(addr)
619 .EndChild()
620 .EndChild()
621 .Build();
622 /* clang-format on */
623
624 ASSERT_EQ(manifest_from_vec(&m, dtb), MANIFEST_SUCCESS);
Olivier Deprez93644652022-09-09 11:01:12 +0200625 ASSERT_EQ(m->vm_count, 1);
626 ASSERT_STREQ(string_data(&m->vm[0].debug_name), "primary_vm");
627 ASSERT_EQ(m->vm[0].primary.boot_address, addr);
David Brazdil080ee312020-02-25 15:30:30 -0800628}
629
Andrew Scullb2c3a242019-11-04 13:52:36 +0000630static std::vector<char> gen_malformed_boolean_dtb(
631 const std::string_view &value)
Andrew Scullae9962e2019-10-03 16:51:16 +0100632{
Andrew Scullae9962e2019-10-03 16:51:16 +0100633 /* clang-format off */
Andrew Scullb2c3a242019-11-04 13:52:36 +0000634 return ManifestDtBuilder()
Andrew Scullae9962e2019-10-03 16:51:16 +0100635 .StartChild("hypervisor")
636 .Compatible()
637 .StartChild("vm1")
638 .DebugName("primary_vm")
Andrew Scullb2c3a242019-11-04 13:52:36 +0000639 .Property("smc_whitelist_permissive", value)
Andrew Scull5dc089e2019-11-04 13:21:03 +0000640 .EndChild()
Andrew Scullae9962e2019-10-03 16:51:16 +0100641 .EndChild()
642 .Build();
643 /* clang-format on */
Andrew Scullb2c3a242019-11-04 13:52:36 +0000644}
Andrew Scullae9962e2019-10-03 16:51:16 +0100645
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100646TEST_F(manifest, malformed_booleans)
Andrew Scullb2c3a242019-11-04 13:52:36 +0000647{
Olivier Deprez93644652022-09-09 11:01:12 +0200648 struct_manifest *m;
Andrew Scullae9962e2019-10-03 16:51:16 +0100649
Andrew Scullb2c3a242019-11-04 13:52:36 +0000650 std::vector<char> dtb_false = gen_malformed_boolean_dtb("\"false\"");
651 std::vector<char> dtb_true = gen_malformed_boolean_dtb("\"true\"");
652 std::vector<char> dtb_0 = gen_malformed_boolean_dtb("\"<0>\"");
653 std::vector<char> dtb_1 = gen_malformed_boolean_dtb("\"<1>\"");
Andrew Scullae9962e2019-10-03 16:51:16 +0100654
David Brazdila2358d42020-01-27 18:51:38 +0000655 ASSERT_EQ(manifest_from_vec(&m, dtb_false),
Andrew Scullb2c3a242019-11-04 13:52:36 +0000656 MANIFEST_ERROR_MALFORMED_BOOLEAN);
Olivier Deprez93644652022-09-09 11:01:12 +0200657 manifest_dealloc();
658
David Brazdila2358d42020-01-27 18:51:38 +0000659 ASSERT_EQ(manifest_from_vec(&m, dtb_true),
Andrew Scullb2c3a242019-11-04 13:52:36 +0000660 MANIFEST_ERROR_MALFORMED_BOOLEAN);
Olivier Deprez93644652022-09-09 11:01:12 +0200661 manifest_dealloc();
662
David Brazdila2358d42020-01-27 18:51:38 +0000663 ASSERT_EQ(manifest_from_vec(&m, dtb_0),
Andrew Scullb2c3a242019-11-04 13:52:36 +0000664 MANIFEST_ERROR_MALFORMED_BOOLEAN);
Olivier Deprez93644652022-09-09 11:01:12 +0200665 manifest_dealloc();
666
David Brazdila2358d42020-01-27 18:51:38 +0000667 ASSERT_EQ(manifest_from_vec(&m, dtb_1),
Andrew Scullb2c3a242019-11-04 13:52:36 +0000668 MANIFEST_ERROR_MALFORMED_BOOLEAN);
Andrew Scullae9962e2019-10-03 16:51:16 +0100669}
670
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100671TEST_F(manifest, valid)
David Brazdil7a462ec2019-08-15 12:27:47 +0100672{
Olivier Deprez93644652022-09-09 11:01:12 +0200673 struct_manifest *m;
David Brazdil7a462ec2019-08-15 12:27:47 +0100674 struct manifest_vm *vm;
David Brazdil7a462ec2019-08-15 12:27:47 +0100675
David Brazdil52256ff2019-08-23 15:15:15 +0100676 /* clang-format off */
677 std::vector<char> dtb = ManifestDtBuilder()
678 .StartChild("hypervisor")
David Brazdil74e9c3b2019-08-28 11:09:08 +0100679 .Compatible()
David Brazdil52256ff2019-08-23 15:15:15 +0100680 .StartChild("vm1")
681 .DebugName("primary_vm")
Andrew Scull72b43c02019-09-18 13:53:45 +0100682 .KernelFilename("primary_kernel")
David Brazdile6f83222019-09-23 14:47:37 +0100683 .RamdiskFilename("primary_ramdisk")
Andrew Scullae9962e2019-10-03 16:51:16 +0100684 .SmcWhitelist({0x32000000, 0x33001111})
David Brazdil52256ff2019-08-23 15:15:15 +0100685 .EndChild()
686 .StartChild("vm3")
687 .DebugName("second_secondary_vm")
688 .VcpuCount(43)
689 .MemSize(0x12345)
Andrew Scull72b43c02019-09-18 13:53:45 +0100690 .KernelFilename("second_secondary_kernel")
David Brazdil52256ff2019-08-23 15:15:15 +0100691 .EndChild()
692 .StartChild("vm2")
693 .DebugName("first_secondary_vm")
694 .VcpuCount(42)
695 .MemSize(12345)
Andrew Scullae9962e2019-10-03 16:51:16 +0100696 .SmcWhitelist({0x04000000, 0x30002222, 0x31445566})
697 .SmcWhitelistPermissive()
David Brazdil52256ff2019-08-23 15:15:15 +0100698 .EndChild()
699 .EndChild()
700 .Build();
701 /* clang-format on */
702
David Brazdila2358d42020-01-27 18:51:38 +0000703 ASSERT_EQ(manifest_from_vec(&m, dtb), MANIFEST_SUCCESS);
Olivier Deprez93644652022-09-09 11:01:12 +0200704 ASSERT_EQ(m->vm_count, 3);
David Brazdil7a462ec2019-08-15 12:27:47 +0100705
Olivier Deprez93644652022-09-09 11:01:12 +0200706 vm = &m->vm[0];
David Brazdil136f2942019-09-23 14:11:03 +0100707 ASSERT_STREQ(string_data(&vm->debug_name), "primary_vm");
708 ASSERT_STREQ(string_data(&vm->kernel_filename), "primary_kernel");
David Brazdile6f83222019-09-23 14:47:37 +0100709 ASSERT_STREQ(string_data(&vm->primary.ramdisk_filename),
710 "primary_ramdisk");
Andrew Scullae9962e2019-10-03 16:51:16 +0100711 ASSERT_THAT(
712 std::span(vm->smc_whitelist.smcs, vm->smc_whitelist.smc_count),
713 ElementsAre(0x32000000, 0x33001111));
714 ASSERT_FALSE(vm->smc_whitelist.permissive);
David Brazdil7a462ec2019-08-15 12:27:47 +0100715
Olivier Deprez93644652022-09-09 11:01:12 +0200716 vm = &m->vm[1];
David Brazdil136f2942019-09-23 14:11:03 +0100717 ASSERT_STREQ(string_data(&vm->debug_name), "first_secondary_vm");
718 ASSERT_STREQ(string_data(&vm->kernel_filename), "");
David Brazdil7a462ec2019-08-15 12:27:47 +0100719 ASSERT_EQ(vm->secondary.vcpu_count, 42);
720 ASSERT_EQ(vm->secondary.mem_size, 12345);
Andrew Scullae9962e2019-10-03 16:51:16 +0100721 ASSERT_THAT(
722 std::span(vm->smc_whitelist.smcs, vm->smc_whitelist.smc_count),
723 ElementsAre(0x04000000, 0x30002222, 0x31445566));
724 ASSERT_TRUE(vm->smc_whitelist.permissive);
David Brazdil7a462ec2019-08-15 12:27:47 +0100725
Olivier Deprez93644652022-09-09 11:01:12 +0200726 vm = &m->vm[2];
David Brazdil136f2942019-09-23 14:11:03 +0100727 ASSERT_STREQ(string_data(&vm->debug_name), "second_secondary_vm");
728 ASSERT_STREQ(string_data(&vm->kernel_filename),
729 "second_secondary_kernel");
David Brazdil7a462ec2019-08-15 12:27:47 +0100730 ASSERT_EQ(vm->secondary.vcpu_count, 43);
731 ASSERT_EQ(vm->secondary.mem_size, 0x12345);
Andrew Scullae9962e2019-10-03 16:51:16 +0100732 ASSERT_THAT(
733 std::span(vm->smc_whitelist.smcs, vm->smc_whitelist.smc_count),
734 IsEmpty());
735 ASSERT_FALSE(vm->smc_whitelist.permissive);
David Brazdil7a462ec2019-08-15 12:27:47 +0100736}
737
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100738TEST_F(manifest, ffa_not_compatible)
Olivier Deprez62d99e32020-01-09 15:58:07 +0100739{
Olivier Deprez93644652022-09-09 11:01:12 +0200740 struct_manifest *m;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100741
742 /* clang-format off */
743 std::vector<char> dtb = ManifestDtBuilder()
744 .Compatible({ "arm,ffa-manifest-2.0" })
745 .Property("ffa-version", "<0x10000>")
746 .Property("uuid", "<0xb4b5671e 0x4a904fe1 0xb81ffb13 0xdae1dacb>")
747 .Property("execution-ctx-count", "<1>")
748 .Property("exception-level", "<2>")
749 .Property("execution-state", "<0>")
J-Alves2f86c1e2022-02-23 18:44:19 +0000750 .Property("entrypoint-offset", "<0x00002000>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100751 .Property("xlat-granule", "<0>")
752 .Property("messaging-method", "<1>")
Madhukar Pappireddy84154052022-06-21 18:30:25 -0500753 .Property("ns-interrupts-action", "<1>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100754 .Build();
755 /* clang-format on */
756
757 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
758 MANIFEST_ERROR_NOT_COMPATIBLE);
759}
760
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100761TEST_F(manifest, ffa_missing_property)
Olivier Deprez62d99e32020-01-09 15:58:07 +0100762{
Olivier Deprez93644652022-09-09 11:01:12 +0200763 struct_manifest *m;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100764
765 /* clang-format off */
766 std::vector<char> dtb = ManifestDtBuilder()
767 .Compatible({ "arm,ffa-manifest-1.0" })
768 .Property("ffa-version", "<0x10000>")
769 .Build();
770 /* clang-format on */
771
772 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
773 MANIFEST_ERROR_PROPERTY_NOT_FOUND);
774}
775
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100776TEST_F(manifest, ffa_validate_sanity_check)
Olivier Deprez62d99e32020-01-09 15:58:07 +0100777{
J-Alvesb37fd082020-10-22 12:29:21 +0100778 /*
779 * TODO: write test excluding all optional fields of the manifest, in
780 * accordance with specification.
781 */
Olivier Deprez93644652022-09-09 11:01:12 +0200782 struct_manifest *m;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100783
784 /* Incompatible version */
785 /* clang-format off */
786 std::vector<char> dtb = ManifestDtBuilder()
787 .Compatible({ "arm,ffa-manifest-1.0" })
788 .Property("ffa-version", "<0xa1>")
789 .Property("uuid", "<0xb4b5671e 0x4a904fe1 0xb81ffb13 0xdae1dacb>")
790 .Property("execution-ctx-count", "<1>")
791 .Property("exception-level", "<2>")
792 .Property("execution-state", "<0>")
J-Alves2f86c1e2022-02-23 18:44:19 +0000793 .Property("entrypoint-offset", "<0x00002000>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100794 .Property("xlat-granule", "<0>")
J-Alvesb37fd082020-10-22 12:29:21 +0100795 .Property("boot-order", "<0>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100796 .Property("messaging-method", "<1>")
Madhukar Pappireddy84154052022-06-21 18:30:25 -0500797 .Property("ns-interrupts-action", "<1>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100798 .Build();
799 /* clang-format on */
800 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
801 MANIFEST_ERROR_NOT_COMPATIBLE);
Olivier Deprez93644652022-09-09 11:01:12 +0200802 manifest_dealloc();
Olivier Deprez62d99e32020-01-09 15:58:07 +0100803
804 /* Incompatible translation granule */
805 /* clang-format off */
806 dtb = ManifestDtBuilder()
807 .Compatible({ "arm,ffa-manifest-1.0" })
808 .Property("ffa-version", "<0x10000>")
809 .Property("uuid", "<0xb4b5671e 0x4a904fe1 0xb81ffb13 0xdae1dacb>")
810 .Property("execution-ctx-count", "<1>")
811 .Property("exception-level", "<2>")
812 .Property("execution-state", "<0>")
J-Alves2f86c1e2022-02-23 18:44:19 +0000813 .Property("entrypoint-offset", "<0x00002000>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100814 .Property("xlat-granule", "<3>")
J-Alvesb37fd082020-10-22 12:29:21 +0100815 .Property("boot-order", "<0>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100816 .Property("messaging-method", "<1>")
Madhukar Pappireddy84154052022-06-21 18:30:25 -0500817 .Property("ns-interrupts-action", "<1>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100818 .Build();
819 /* clang-format on */
820 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
821 MANIFEST_ERROR_NOT_COMPATIBLE);
Olivier Deprez93644652022-09-09 11:01:12 +0200822 manifest_dealloc();
Olivier Deprez62d99e32020-01-09 15:58:07 +0100823
824 /* Incompatible exeption level */
825 /* clang-format off */
826 dtb = ManifestDtBuilder()
827 .Compatible({ "arm,ffa-manifest-1.0" })
828 .Property("ffa-version", "<0x10000>")
829 .Property("uuid", "<0xb4b5671e 0x4a904fe1 0xb81ffb13 0xdae1dacb>")
830 .Property("execution-ctx-count", "<1>")
831 .Property("exception-level", "<6>")
832 .Property("execution-state", "<0>")
J-Alves2f86c1e2022-02-23 18:44:19 +0000833 .Property("entrypoint-offset", "<0x00002000>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100834 .Property("xlat-granule", "<0>")
J-Alvesb37fd082020-10-22 12:29:21 +0100835 .Property("boot-order", "<0>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100836 .Property("messaging-method", "<1>")
Madhukar Pappireddy84154052022-06-21 18:30:25 -0500837 .Property("ns-interrupts-action", "<0>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100838 .Build();
839 /* clang-format on */
840 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
841 MANIFEST_ERROR_NOT_COMPATIBLE);
Olivier Deprez93644652022-09-09 11:01:12 +0200842 manifest_dealloc();
Olivier Deprez62d99e32020-01-09 15:58:07 +0100843
844 /* Incompatible execution state */
845 /* clang-format off */
846 dtb = ManifestDtBuilder()
847 .Compatible({ "arm,ffa-manifest-1.0" })
848 .Property("ffa-version", "<0x10000>")
849 .Property("uuid", "<0xb4b5671e 0x4a904fe1 0xb81ffb13 0xdae1dacb>")
850 .Property("execution-ctx-count", "<1>")
851 .Property("exception-level", "<2>")
852 .Property("execution-state", "<2>")
J-Alves2f86c1e2022-02-23 18:44:19 +0000853 .Property("entrypoint-offset", "<0x00002000>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100854 .Property("xlat-granule", "<0>")
J-Alvesb37fd082020-10-22 12:29:21 +0100855 .Property("boot-order", "<0>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100856 .Property("messaging-method", "<1>")
Madhukar Pappireddy84154052022-06-21 18:30:25 -0500857 .Property("ns-interrupts-action", "<0>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100858 .Build();
859 /* clang-format on */
860 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
861 MANIFEST_ERROR_NOT_COMPATIBLE);
Olivier Deprez93644652022-09-09 11:01:12 +0200862 manifest_dealloc();
Olivier Deprez62d99e32020-01-09 15:58:07 +0100863
864 /* Incompatible messaging method */
865 /* clang-format off */
866 dtb = ManifestDtBuilder()
867 .Compatible({ "arm,ffa-manifest-1.0" })
868 .Property("ffa-version", "<0x10000>")
869 .Property("uuid", "<0xb4b5671e 0x4a904fe1 0xb81ffb13 0xdae1dacb>")
870 .Property("execution-ctx-count", "<1>")
871 .Property("exception-level", "<2>")
872 .Property("execution-state", "<0>")
J-Alves2f86c1e2022-02-23 18:44:19 +0000873 .Property("entrypoint-offset", "<0x00002000>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100874 .Property("xlat-granule", "<0>")
J-Alvesb37fd082020-10-22 12:29:21 +0100875 .Property("boot-order", "<0>")
Maksims Svecovsb596eab2021-04-27 00:52:27 +0100876 .Property("messaging-method", "<16>")
Madhukar Pappireddy84154052022-06-21 18:30:25 -0500877 .Property("ns-interrupts-action", "<0>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100878 .Build();
879 /* clang-format on */
880 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
881 MANIFEST_ERROR_NOT_COMPATIBLE);
Madhukar Pappireddy5c04a382022-12-28 11:29:26 -0600882
883 /*
884 * No need to invoke manifest_dealloac() since manifest TearDown calls
885 * it when the test ends.
886 */
887}
888
889TEST_F(manifest, ffa_validate_interrupt_actions)
890{
891 struct_manifest *m;
Madhukar Pappireddy84154052022-06-21 18:30:25 -0500892
893 /* Incompatible NS interrupt action */
894 /* clang-format off */
Madhukar Pappireddy5c04a382022-12-28 11:29:26 -0600895 std::vector<char> dtb = ManifestDtBuilder()
Madhukar Pappireddy84154052022-06-21 18:30:25 -0500896 .Compatible({ "arm,ffa-manifest-1.0" })
897 .Property("ffa-version", "<0x10000>")
898 .Property("uuid", "<0xb4b5671e 0x4a904fe1 0xb81ffb13 0xdae1dacb>")
899 .Property("execution-ctx-count", "<1>")
900 .Property("exception-level", "<2>")
901 .Property("execution-state", "<0>")
902 .Property("entrypoint-offset", "<0x00002000>")
903 .Property("xlat-granule", "<0>")
904 .Property("boot-order", "<0>")
905 .Property("messaging-method", "<1>")
906 .Property("ns-interrupts-action", "<4>")
907 .Build();
908 /* clang-format on */
Madhukar Pappireddy5c04a382022-12-28 11:29:26 -0600909 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
910 MANIFEST_ERROR_ILLEGAL_NS_INT_ACTION);
Olivier Deprez62d99e32020-01-09 15:58:07 +0100911}
912
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100913TEST_F(manifest, ffa_validate_rxtx_info)
Manish Pandeyfa1f2912020-05-05 12:57:01 +0100914{
Olivier Deprez93644652022-09-09 11:01:12 +0200915 struct_manifest *m;
Manish Pandeyfa1f2912020-05-05 12:57:01 +0100916
917 /* Not Compatible */
918 /* clang-format off */
919 std::vector<char> dtb = ManifestDtBuilder()
920 .FfaValidManifest()
921 .StartChild("rx_tx-info")
922 .Compatible({ "foo,bar" })
923 .EndChild()
924 .Build();
925 /* clang-format on */
926 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
927 MANIFEST_ERROR_NOT_COMPATIBLE);
Olivier Deprez93644652022-09-09 11:01:12 +0200928 manifest_dealloc();
Manish Pandeyfa1f2912020-05-05 12:57:01 +0100929
930 /* Missing Properties */
931 /* clang-format off */
932 dtb = ManifestDtBuilder()
933 .FfaValidManifest()
934 .StartChild("rx_tx-info")
935 .Compatible({ "arm,ffa-manifest-rx_tx-buffer" })
936 .EndChild()
937 .Build();
938 /* clang-format on */
939 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
940 MANIFEST_ERROR_PROPERTY_NOT_FOUND);
941}
942
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100943TEST_F(manifest, ffa_validate_mem_regions)
Manish Pandey6542f5c2020-04-27 14:37:46 +0100944{
Olivier Deprez93644652022-09-09 11:01:12 +0200945 struct_manifest *m;
Manish Pandey6542f5c2020-04-27 14:37:46 +0100946
947 /* Not Compatible */
948 /* clang-format off */
949 std::vector<char> dtb = ManifestDtBuilder()
950 .FfaValidManifest()
951 .StartChild("memory-regions")
952 .Compatible({ "foo,bar" })
953 .EndChild()
954 .Build();
955 /* clang-format on */
956 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
957 MANIFEST_ERROR_NOT_COMPATIBLE);
Olivier Deprez93644652022-09-09 11:01:12 +0200958 manifest_dealloc();
Manish Pandey6542f5c2020-04-27 14:37:46 +0100959
960 /* Memory regions unavailable */
961 /* clang-format off */
962 dtb = ManifestDtBuilder()
963 .FfaValidManifest()
964 .StartChild("memory-regions")
965 .Compatible({ "arm,ffa-manifest-memory-regions" })
966 .EndChild()
967 .Build();
968 /* clang-format on */
969 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
970 MANIFEST_ERROR_MEMORY_REGION_NODE_EMPTY);
Olivier Deprez93644652022-09-09 11:01:12 +0200971 manifest_dealloc();
Manish Pandey6542f5c2020-04-27 14:37:46 +0100972
973 /* Missing Properties */
974 /* clang-format off */
975 dtb = ManifestDtBuilder()
976 .FfaValidManifest()
977 .StartChild("memory-regions")
978 .Compatible({ "arm,ffa-manifest-memory-regions" })
979 .StartChild("test-memory")
980 .Description("test-memory")
981 .EndChild()
982 .EndChild()
983 .Build();
984 /* clang-format on */
985 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
986 MANIFEST_ERROR_PROPERTY_NOT_FOUND);
Olivier Deprez93644652022-09-09 11:01:12 +0200987 manifest_dealloc();
Manish Pandeyf06c9072020-09-29 15:41:58 +0100988
Daniel Boulby9279b552022-06-28 17:04:01 +0100989 /* Overlapping memory regions */
990 /* clang-format off */
991 dtb = ManifestDtBuilder()
992 .FfaValidManifest()
993 .StartChild("memory-regions")
994 .Compatible({ "arm,ffa-manifest-memory-regions" })
995 .Label("rx")
996 .StartChild("rx")
997 .Description("rx-buffer")
998 .Property("base-address", "<0x7300000>")
999 .Property("pages-count", "<1>")
1000 .Property("attributes", "<1>")
1001 .EndChild()
1002 .Label("tx")
1003 .StartChild("tx")
1004 .Description("tx-buffer")
1005 .Property("base-address", "<0x7300000>")
1006 .Property("pages-count", "<2>")
1007 .Property("attributes", "<3>")
1008 .EndChild()
1009 .EndChild()
1010 .Build();
1011 /* clang-format on */
1012 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1013 MANIFEST_ERROR_MEM_REGION_OVERLAP);
Olivier Deprez93644652022-09-09 11:01:12 +02001014 manifest_dealloc();
Daniel Boulby9279b552022-06-28 17:04:01 +01001015
1016 /* clang-format off */
1017 dtb = ManifestDtBuilder()
1018 .FfaValidManifest()
1019 .StartChild("memory-regions")
1020 .Compatible({ "arm,ffa-manifest-memory-regions" })
1021 .Label("rx")
1022 .StartChild("rx")
1023 .Description("rx-buffer")
1024 .Property("base-address", "<0x7300000>")
1025 .Property("pages-count", "<2>")
1026 .Property("attributes", "<1>")
1027 .EndChild()
1028 .Label("tx")
1029 .StartChild("tx")
1030 .Description("tx-buffer")
1031 .Property("base-address", "<0x7301000>")
1032 .Property("pages-count", "<2>")
1033 .Property("attributes", "<3>")
1034 .EndChild()
1035 .EndChild()
1036 .Build();
1037 /* clang-format on */
1038 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1039 MANIFEST_ERROR_MEM_REGION_OVERLAP);
Olivier Deprez93644652022-09-09 11:01:12 +02001040 manifest_dealloc();
Daniel Boulby9279b552022-06-28 17:04:01 +01001041
1042 /* clang-format off */
1043 dtb = ManifestDtBuilder()
1044 .FfaValidManifest()
1045 .StartChild("memory-regions")
1046 .Compatible({ "arm,ffa-manifest-memory-regions" })
1047 .Label("rx")
1048 .StartChild("rx")
1049 .Description("rx-buffer")
1050 .Property("base-address", "<0x7300000>")
1051 .Property("pages-count", "<2>")
1052 .Property("attributes", "<1>")
1053 .EndChild()
1054 .Label("tx")
1055 .StartChild("tx")
1056 .Description("tx-buffer")
1057 .Property("base-address", "<0x7301FFF>")
1058 .Property("pages-count", "<2>")
1059 .Property("attributes", "<3>")
1060 .EndChild()
1061 .EndChild()
1062 .Build();
1063 /* clang-format on */
1064 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1065 MANIFEST_ERROR_MEM_REGION_OVERLAP);
Olivier Deprez93644652022-09-09 11:01:12 +02001066 manifest_dealloc();
Daniel Boulby9279b552022-06-28 17:04:01 +01001067
Manish Pandeyf06c9072020-09-29 15:41:58 +01001068 /* Different RXTX buffer sizes */
1069 /* clang-format off */
1070 dtb = ManifestDtBuilder()
1071 .FfaValidManifest()
1072 .StartChild("memory-regions")
1073 .Compatible({ "arm,ffa-manifest-memory-regions" })
1074 .Label("rx")
1075 .StartChild("rx")
1076 .Description("rx-buffer")
1077 .Property("base-address", "<0x7300000>")
1078 .Property("pages-count", "<1>")
1079 .Property("attributes", "<1>")
1080 .EndChild()
1081 .Label("tx")
1082 .StartChild("tx")
1083 .Description("tx-buffer")
1084 .Property("base-address", "<0x7310000>")
1085 .Property("pages-count", "<2>")
1086 .Property("attributes", "<3>")
1087 .EndChild()
1088 .EndChild()
1089 .StartChild("rx_tx-info")
1090 .Compatible({ "arm,ffa-manifest-rx_tx-buffer" })
1091 .Property("rx-buffer", "<&rx>")
1092 .Property("tx-buffer", "<&tx>")
1093 .EndChild()
1094 .Build();
1095 /* clang-format on */
1096 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1097 MANIFEST_ERROR_RXTX_SIZE_MISMATCH);
Manish Pandey6542f5c2020-04-27 14:37:46 +01001098}
1099
Daniel Boulby801f8ef2022-06-27 14:21:01 +01001100TEST_F(manifest, ffa_validate_dev_regions)
Manish Pandeye68e7932020-04-23 15:29:28 +01001101{
Olivier Deprez93644652022-09-09 11:01:12 +02001102 struct_manifest *m;
Manish Pandeye68e7932020-04-23 15:29:28 +01001103
1104 /* Not Compatible */
1105 /* clang-format off */
1106 std::vector<char> dtb = ManifestDtBuilder()
1107 .FfaValidManifest()
1108 .StartChild("device-regions")
1109 .Compatible({ "foo,bar" })
1110 .EndChild()
1111 .Build();
1112 /* clang-format on */
1113 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1114 MANIFEST_ERROR_NOT_COMPATIBLE);
Olivier Deprez93644652022-09-09 11:01:12 +02001115 manifest_dealloc();
Manish Pandeye68e7932020-04-23 15:29:28 +01001116
1117 /* Memory regions unavailable */
1118 /* clang-format off */
1119 dtb = ManifestDtBuilder()
1120 .FfaValidManifest()
1121 .StartChild("device-regions")
1122 .Compatible({ "arm,ffa-manifest-device-regions" })
1123 .EndChild()
1124 .Build();
1125 /* clang-format on */
1126 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1127 MANIFEST_ERROR_DEVICE_REGION_NODE_EMPTY);
Olivier Deprez93644652022-09-09 11:01:12 +02001128 manifest_dealloc();
Manish Pandeye68e7932020-04-23 15:29:28 +01001129
1130 /* Missing Properties */
1131 /* clang-format off */
1132 dtb = ManifestDtBuilder()
1133 .FfaValidManifest()
1134 .StartChild("device-regions")
1135 .Compatible({ "arm,ffa-manifest-device-regions" })
1136 .StartChild("test-device")
1137 .Description("test-device")
1138 .EndChild()
1139 .EndChild()
1140 .Build();
1141 /* clang-format on */
1142 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1143 MANIFEST_ERROR_PROPERTY_NOT_FOUND);
Olivier Deprez93644652022-09-09 11:01:12 +02001144 manifest_dealloc();
Manish Pandeye68e7932020-04-23 15:29:28 +01001145
1146 /* Malformed interrupt list pair */
1147 /* clang-format off */
1148 dtb = ManifestDtBuilder()
1149 .FfaValidManifest()
1150 .StartChild("device-regions")
1151 .Compatible({ "arm,ffa-manifest-device-regions" })
1152 .StartChild("test-device")
1153 .Description("test-device")
1154 .Property("base-address", "<0x7200000>")
1155 .Property("pages-count", "<16>")
1156 .Property("attributes", "<3>")
1157 .Property("smmu-id", "<1>")
1158 .Property("stream-ids", "<0 1>")
1159 .Property("interrupts", "<2 3>, <4>")
1160 .EndChild()
1161 .EndChild()
1162 .Build();
1163 /* clang-format on */
1164 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1165 MANIFEST_ERROR_MALFORMED_INTEGER_LIST);
Olivier Deprez93644652022-09-09 11:01:12 +02001166 manifest_dealloc();
Daniel Boulby667334f2022-06-27 15:23:21 +01001167
1168 /* Non-unique interrupt IDs */
1169 /* clang-format off */
1170 dtb = ManifestDtBuilder()
1171 .FfaValidManifest()
1172 .StartChild("device-regions")
1173 .Compatible({ "arm,ffa-manifest-device-regions" })
1174 .StartChild("test-device-0")
1175 .Description("test-device-0")
1176 .Property("base-address", "<0x7200000>")
1177 .Property("pages-count", "<16>")
1178 .Property("attributes", "<3>")
1179 .Property("interrupts", "<2 3>")
1180 .EndChild()
1181 .StartChild("test-device-1")
1182 .Description("test-device-1")
1183 .Property("base-address", "<0x8200000>")
1184 .Property("pages-count", "<16>")
1185 .Property("attributes", "<3>")
1186 .Property("interrupts", "<1 3>, <2 5> ")
1187 .EndChild()
1188 .EndChild()
1189 .Build();
1190 /* clang-format on */
1191 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1192 MANIFEST_ERROR_INTERRUPT_ID_REPEATED);
1193 /* Check valid interrupts were still mapped */
Olivier Deprez93644652022-09-09 11:01:12 +02001194 ASSERT_EQ(m->vm[0].partition.dev_regions[0].interrupts[0].id, 2);
1195 ASSERT_EQ(m->vm[0].partition.dev_regions[0].interrupts[0].attributes,
1196 3);
1197 ASSERT_EQ(m->vm[0].partition.dev_regions[1].interrupts[0].id, 1);
1198 ASSERT_EQ(m->vm[0].partition.dev_regions[1].interrupts[0].attributes,
1199 3);
Manish Pandeye68e7932020-04-23 15:29:28 +01001200}
Daniel Boulby801f8ef2022-06-27 14:21:01 +01001201
1202TEST_F(manifest, ffa_invalid_memory_region_attributes)
Raghu Krishnamurthy384693c2021-10-11 13:56:24 -07001203{
Olivier Deprez93644652022-09-09 11:01:12 +02001204 struct_manifest *m;
Raghu Krishnamurthy384693c2021-10-11 13:56:24 -07001205
1206 /* clang-format off */
1207 std::vector<char> dtb = ManifestDtBuilder()
1208 .FfaValidManifest()
1209 .StartChild("rx_tx-info")
1210 .Compatible({ "arm,ffa-manifest-rx_tx-buffer" })
1211 .Property("rx-buffer", "<&rx>")
1212 .Property("tx-buffer", "<&tx>")
1213 .EndChild()
1214 .StartChild("memory-regions")
1215 .Compatible({ "arm,ffa-manifest-memory-regions" })
1216 .StartChild("test-memory")
1217 .Description("test-memory")
1218 .Property("base-address", "<0x7100000>")
1219 .Property("pages-count", "<4>")
1220 .Property("attributes", "<7>")
1221 .EndChild()
1222 .Label("rx")
1223 .StartChild("rx")
1224 .Description("rx-buffer")
1225 .Property("base-address", "<0x7300000>")
1226 .Property("pages-count", "<1>")
1227 .Property("attributes", "<1>")
1228 .EndChild()
1229 .Label("tx")
1230 .StartChild("tx")
1231 .Description("tx-buffer")
1232 .Property("base-address", "<0x7310000>")
1233 .Property("pages-count", "<1>")
1234 .Property("attributes", "<3>")
1235 .EndChild()
1236 .EndChild()
1237 .Build();
1238 /* clang-format on */
1239
1240 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1241 MANIFEST_ERROR_INVALID_MEM_PERM);
1242}
1243
Daniel Boulby801f8ef2022-06-27 14:21:01 +01001244TEST_F(manifest, ffa_invalid_device_region_attributes)
Raghu Krishnamurthy384693c2021-10-11 13:56:24 -07001245{
Olivier Deprez93644652022-09-09 11:01:12 +02001246 struct_manifest *m;
Raghu Krishnamurthy384693c2021-10-11 13:56:24 -07001247
1248 /* clang-format off */
1249 std::vector<char> dtb = ManifestDtBuilder()
1250 .FfaValidManifest()
1251 .StartChild("rx_tx-info")
1252 .Compatible({ "arm,ffa-manifest-rx_tx-buffer" })
1253 .Property("rx-buffer", "<&rx>")
1254 .Property("tx-buffer", "<&tx>")
1255 .EndChild()
1256 .StartChild("memory-regions")
1257 .Compatible({ "arm,ffa-manifest-memory-regions" })
1258 .StartChild("test-memory")
1259 .Description("test-memory")
1260 .Property("base-address", "<0x7100000>")
1261 .Property("pages-count", "<4>")
1262 .Property("attributes", "<3>")
1263 .EndChild()
1264 .Label("rx")
1265 .StartChild("rx")
1266 .Description("rx-buffer")
1267 .Property("base-address", "<0x7300000>")
1268 .Property("pages-count", "<1>")
1269 .Property("attributes", "<1>")
1270 .EndChild()
1271 .Label("tx")
1272 .StartChild("tx")
1273 .Description("tx-buffer")
1274 .Property("base-address", "<0x7310000>")
1275 .Property("pages-count", "<1>")
1276 .Property("attributes", "<3>")
1277 .EndChild()
1278 .EndChild()
1279 .StartChild("device-regions")
1280 .Compatible({ "arm,ffa-manifest-device-regions" })
1281 .StartChild("test-device")
1282 .Description("test-device")
1283 .Property("base-address", "<0x7200000>")
1284 .Property("pages-count", "<16>")
1285 .Property("attributes", "<5>")
1286 .Property("smmu-id", "<1>")
1287 .Property("stream-ids", "<0 1>")
1288 .Property("interrupts", "<2 3>, <4 5>")
1289 .EndChild()
1290 .EndChild()
1291 .Build();
1292 /* clang-format on */
1293
1294 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1295 MANIFEST_ERROR_INVALID_MEM_PERM);
1296}
Manish Pandeye68e7932020-04-23 15:29:28 +01001297
Daniel Boulby801f8ef2022-06-27 14:21:01 +01001298TEST_F(manifest, ffa_valid)
Olivier Deprez62d99e32020-01-09 15:58:07 +01001299{
Olivier Deprez93644652022-09-09 11:01:12 +02001300 struct manifest_vm *vm;
1301 struct_manifest *m;
Olivier Deprez62d99e32020-01-09 15:58:07 +01001302
1303 /* clang-format off */
1304 std::vector<char> dtb = ManifestDtBuilder()
Manish Pandeycb8fbb22020-08-18 00:04:43 +01001305 .FfaValidManifest()
Manish Pandeyfa1f2912020-05-05 12:57:01 +01001306 .StartChild("rx_tx-info")
1307 .Compatible({ "arm,ffa-manifest-rx_tx-buffer" })
1308 .Property("rx-buffer", "<&rx>")
1309 .Property("tx-buffer", "<&tx>")
1310 .EndChild()
Manish Pandey6542f5c2020-04-27 14:37:46 +01001311 .StartChild("memory-regions")
1312 .Compatible({ "arm,ffa-manifest-memory-regions" })
1313 .StartChild("test-memory")
1314 .Description("test-memory")
1315 .Property("base-address", "<0x7100000>")
1316 .Property("pages-count", "<4>")
Raghu Krishnamurthy384693c2021-10-11 13:56:24 -07001317 .Property("attributes", "<3>")
Manish Pandey6542f5c2020-04-27 14:37:46 +01001318 .EndChild()
Olivier Deprez035fa152022-03-14 11:19:10 +01001319 .StartChild("test-memory-ns")
1320 .Description("test-memory")
1321 .Property("base-address", "<0x7200000>")
1322 .Property("pages-count", "<1>")
1323 .Property("attributes", "<0xb>")
1324 .EndChild()
Manish Pandeyfa1f2912020-05-05 12:57:01 +01001325 .Label("rx")
1326 .StartChild("rx")
1327 .Description("rx-buffer")
1328 .Property("base-address", "<0x7300000>")
1329 .Property("pages-count", "<1>")
1330 .Property("attributes", "<1>")
1331 .EndChild()
1332 .Label("tx")
1333 .StartChild("tx")
1334 .Description("tx-buffer")
Daniel Boulby9279b552022-06-28 17:04:01 +01001335 .Property("base-address", "<0x7301000>")
Manish Pandeyfa1f2912020-05-05 12:57:01 +01001336 .Property("pages-count", "<1>")
1337 .Property("attributes", "<3>")
1338 .EndChild()
Manish Pandey6542f5c2020-04-27 14:37:46 +01001339 .EndChild()
Manish Pandeye68e7932020-04-23 15:29:28 +01001340 .StartChild("device-regions")
1341 .Compatible({ "arm,ffa-manifest-device-regions" })
1342 .StartChild("test-device")
1343 .Description("test-device")
Olivier Deprez035fa152022-03-14 11:19:10 +01001344 .Property("base-address", "<0x7400000>")
Manish Pandeye68e7932020-04-23 15:29:28 +01001345 .Property("pages-count", "<16>")
1346 .Property("attributes", "<3>")
1347 .Property("smmu-id", "<1>")
1348 .Property("stream-ids", "<0 1>")
1349 .Property("interrupts", "<2 3>, <4 5>")
1350 .EndChild()
Olivier Deprez035fa152022-03-14 11:19:10 +01001351 .StartChild("test-device-ns")
1352 .Description("test-device")
1353 .Property("base-address", "<0x7500000>")
1354 .Property("pages-count", "<1>")
1355 .Property("attributes", "<0x9>")
1356 .EndChild()
Manish Pandeye68e7932020-04-23 15:29:28 +01001357 .EndChild()
Olivier Deprez62d99e32020-01-09 15:58:07 +01001358 .Build();
1359 /* clang-format on */
1360
1361 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb), MANIFEST_SUCCESS);
1362
Olivier Deprez93644652022-09-09 11:01:12 +02001363 vm = &m->vm[0];
1364 ASSERT_EQ(vm->partition.ffa_version, 0x10000);
Olivier Deprez62d99e32020-01-09 15:58:07 +01001365 ASSERT_THAT(
Olivier Deprez93644652022-09-09 11:01:12 +02001366 std::span(vm->partition.uuid.uuid, 4),
Olivier Deprez62d99e32020-01-09 15:58:07 +01001367 ElementsAre(0xb4b5671e, 0x4a904fe1, 0xb81ffb13, 0xdae1dacb));
Olivier Deprez93644652022-09-09 11:01:12 +02001368 ASSERT_EQ(vm->partition.execution_ctx_count, 1);
1369 ASSERT_EQ(vm->partition.run_time_el, S_EL1);
1370 ASSERT_EQ(vm->partition.execution_state, AARCH64);
1371 ASSERT_EQ(vm->partition.ep_offset, 0x00002000);
1372 ASSERT_EQ(vm->partition.xlat_granule, PAGE_4KB);
1373 ASSERT_EQ(vm->partition.boot_order, 0);
1374 ASSERT_EQ(vm->partition.messaging_method, FFA_PARTITION_INDIRECT_MSG);
1375 ASSERT_EQ(vm->partition.ns_interrupts_action, NS_ACTION_ME);
1376 ASSERT_EQ(vm->partition.mem_regions[0].base_address, 0x7100000);
1377 ASSERT_EQ(vm->partition.mem_regions[0].page_count, 4);
1378 ASSERT_EQ(vm->partition.mem_regions[0].attributes, 3);
1379 ASSERT_EQ(vm->partition.mem_regions[1].attributes, (8 | 3));
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -07001380
Olivier Deprez93644652022-09-09 11:01:12 +02001381 ASSERT_EQ(vm->partition.rxtx.available, true);
1382 ASSERT_EQ(vm->partition.rxtx.rx_buffer->base_address, 0x7300000);
1383 ASSERT_EQ(vm->partition.rxtx.rx_buffer->page_count, 1);
1384 ASSERT_EQ(vm->partition.rxtx.rx_buffer->attributes, 1);
1385 ASSERT_EQ(vm->partition.rxtx.tx_buffer->base_address, 0x7301000);
1386 ASSERT_EQ(vm->partition.rxtx.tx_buffer->page_count, 1);
1387 ASSERT_EQ(vm->partition.rxtx.tx_buffer->attributes, 3);
1388
1389 ASSERT_EQ(vm->partition.dev_regions[0].base_address, 0x7400000);
1390 ASSERT_EQ(vm->partition.dev_regions[0].page_count, 16);
1391 ASSERT_EQ(vm->partition.dev_regions[0].attributes, 3);
1392 ASSERT_EQ(vm->partition.dev_regions[0].smmu_id, 1);
1393 ASSERT_EQ(vm->partition.dev_regions[0].stream_ids[0], 0);
1394 ASSERT_EQ(vm->partition.dev_regions[0].stream_ids[1], 1);
1395 ASSERT_EQ(vm->partition.dev_regions[0].interrupts[0].id, 2);
1396 ASSERT_EQ(vm->partition.dev_regions[0].interrupts[0].attributes, 3);
1397 ASSERT_EQ(vm->partition.dev_regions[0].interrupts[1].id, 4);
1398 ASSERT_EQ(vm->partition.dev_regions[0].interrupts[1].attributes, 5);
1399 ASSERT_EQ(vm->partition.dev_regions[1].attributes, (8 | 1));
Olivier Deprez62d99e32020-01-09 15:58:07 +01001400}
1401
Raghu Krishnamurthy98da1ca2022-10-04 08:59:01 -07001402TEST_F(manifest, ffa_valid_interrupt_target_manifest)
1403{
1404 struct manifest_vm *vm;
1405 struct_manifest *m;
1406
1407 /* clang-format off */
1408 std::vector<char> dtb = ManifestDtBuilder()
1409 .FfaValidManifest()
1410 .StartChild("device-regions")
1411 .Compatible({ "arm,ffa-manifest-device-regions" })
1412 .StartChild("test-device")
1413 .Description("test-device")
1414 .Property("base-address", "<0x7400000>")
1415 .Property("pages-count", "<16>")
1416 .Property("attributes", "<3>")
1417 .Property("smmu-id", "<1>")
1418 .Property("stream-ids", "<0 1>")
1419 .Property("interrupts", "<2 3>, <4 5>")
1420 .Property("interrupts-target", "<2 0x1234 0x5678>, <4 0x12345678 0x87654321>")
1421 .EndChild()
1422 .EndChild()
1423 .Build();
1424 /* clang-format on */
1425
1426 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb), MANIFEST_SUCCESS);
1427
1428 vm = &m->vm[0];
1429
1430 ASSERT_EQ(vm->partition.dev_regions[0].base_address, 0x7400000);
1431 ASSERT_EQ(vm->partition.dev_regions[0].page_count, 16);
1432 ASSERT_EQ(vm->partition.dev_regions[0].attributes, 3);
1433 ASSERT_EQ(vm->partition.dev_regions[0].smmu_id, 1);
1434 ASSERT_EQ(vm->partition.dev_regions[0].stream_ids[0], 0);
1435 ASSERT_EQ(vm->partition.dev_regions[0].stream_ids[1], 1);
1436 ASSERT_EQ(vm->partition.dev_regions[0].interrupts[0].id, 2);
1437 ASSERT_EQ(vm->partition.dev_regions[0].interrupts[0].attributes, 3);
1438 ASSERT_EQ(vm->partition.dev_regions[0].interrupts[0].mpidr_valid, true);
1439 ASSERT_EQ(vm->partition.dev_regions[0].interrupts[0].mpidr,
1440 0x123400005678);
1441 ASSERT_EQ(vm->partition.dev_regions[0].interrupts[1].id, 4);
1442 ASSERT_EQ(vm->partition.dev_regions[0].interrupts[1].attributes, 5);
1443 ASSERT_EQ(vm->partition.dev_regions[0].interrupts[1].mpidr_valid, true);
1444 ASSERT_EQ(vm->partition.dev_regions[0].interrupts[1].mpidr,
1445 0x1234567887654321);
1446}
1447
1448TEST_F(manifest, ffa_invalid_interrupt_target_manifest)
1449{
1450 struct_manifest *m;
1451
1452 /* clang-format off */
1453 std::vector<char> dtb = ManifestDtBuilder()
1454 .FfaValidManifest()
1455 .StartChild("device-regions")
1456 .Compatible({ "arm,ffa-manifest-device-regions" })
1457 .StartChild("test-device")
1458 .Description("test-device")
1459 .Property("base-address", "<0x7400000>")
1460 .Property("pages-count", "<16>")
1461 .Property("attributes", "<3>")
1462 .Property("smmu-id", "<1>")
1463 .Property("stream-ids", "<0 1>")
1464 .Property("interrupts", "<2 3>, <4 5>")
1465 .Property("interrupts-target", "<20 0x1234 0x5678>")
1466 .EndChild()
1467 .EndChild()
1468 .Build();
1469 /* clang-format on */
1470
1471 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1472 MANIFEST_ERROR_INTERRUPT_ID_NOT_IN_LIST);
1473}
1474
David Brazdil7a462ec2019-08-15 12:27:47 +01001475} /* namespace */