1 /*
2  * Copyright 2021 The Hafnium Authors.
3  *
4  * 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.
7  */
8 
9 #include <stdint.h>
10 
11 #include "hf/ffa.h"
12 #include "hf/mm.h"
13 #include "hf/std.h"
14 
15 #include "vmapi/hf/call.h"
16 
17 #include "test/abort.h"
18 #include "test/hftest.h"
19 #include "test/vmapi/ffa.h"
20 
21 static struct ffa_boot_info_header* boot_info_header;
22 
get_boot_info_header(void)23 struct ffa_boot_info_header* get_boot_info_header(void)
24 {
25 	return boot_info_header;
26 }
27 
28 alignas(4096) uint8_t kstack[MAX_CPUS][4096];
29 
30 void test_main_sp(bool);
31 
sp_register_secondary_ep(struct hftest_context * ctx)32 void sp_register_secondary_ep(struct hftest_context* ctx)
33 {
34 	extern void secondary_ep_entry(void);
35 
36 	if (ctx->partition_manifest.execution_ctx_count > 1) {
37 		struct ffa_value res;
38 		/* Register entry point for secondary vCPUs. */
39 		res = ffa_secondary_ep_register((uintptr_t)secondary_ep_entry);
40 
41 		EXPECT_EQ(res.func, FFA_SUCCESS_32);
42 	}
43 }
44 
run_service_set_up(struct hftest_context * ctx,struct fdt * fdt)45 void run_service_set_up(struct hftest_context* ctx, struct fdt* fdt)
46 {
47 	sp_register_secondary_ep(ctx);
48 	hftest_service_set_up(ctx, fdt);
49 }
50 
kmain(struct ffa_boot_info_header * boot_info_blob)51 [[noreturn]] void kmain(struct ffa_boot_info_header* boot_info_blob)
52 {
53 	/*
54 	 * Initialize the stage-1 MMU and identity-map the entire address space.
55 	 */
56 	if (!hftest_mm_init()) {
57 		HFTEST_LOG_FAILURE();
58 		HFTEST_LOG(HFTEST_LOG_INDENT "Memory initialization failed");
59 		abort();
60 	}
61 
62 	boot_info_header = boot_info_blob;
63 
64 	test_main_sp(true);
65 
66 	/* Do not expect to get to this point, so abort. */
67 	abort();
68 }
69