blob: 7b23c9e3b18d38f6509af067b6a001f7dffd8d45 [file] [log] [blame]
Marc Bonnici8e1a7552021-12-01 17:57:04 +00001/*
2 * Copyright (c) 2022, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
8#include <string.h>
9
10#include <arch.h>
11#include <arch_helpers.h>
12#include <common/debug.h>
13#include <context.h>
14#include <lib/el3_runtime/context_mgmt.h>
15#include <lib/utils.h>
16#include <lib/xlat_tables/xlat_tables_v2.h>
17#include <plat/common/common_def.h>
18#include <plat/common/platform.h>
19#include <services/ffa_svc.h>
20#include "spm_common.h"
21#include "spmc.h"
22
23#include <platform_def.h>
24
25/*
26 * We are assuming that the index of the execution
27 * context used is the linear index of the current physical cpu.
28 */
29unsigned int get_ec_index(struct secure_partition_desc *sp)
30{
31 return plat_my_core_pos();
32}
33
34/* S-EL1 partition specific initialisation. */
35void spmc_el1_sp_setup(struct secure_partition_desc *sp,
36 entry_point_info_t *ep_info)
37{
38 /* Sanity check input arguments. */
39 assert(sp != NULL);
40 assert(ep_info != NULL);
41
42 /* Initialise the SPSR for S-EL1 SPs. */
43 ep_info->spsr = SPSR_64(MODE_EL1, MODE_SP_ELX,
44 DISABLE_ALL_EXCEPTIONS);
45
46 /*
47 * Check whether setup is being performed for the primary or a secondary
48 * execution context. In the latter case, indicate to the SP that this
49 * is a warm boot.
50 * TODO: This check would need to be reworked if the same entry point is
51 * used for both primary and secondary initialisation.
52 */
53 if (sp->secondary_ep != 0U) {
54 /*
55 * Sanity check that the secondary entry point is still what was
56 * originally set.
57 */
58 assert(sp->secondary_ep == ep_info->pc);
59 ep_info->args.arg0 = FFA_WB_TYPE_S2RAM;
60 }
61}
62
63/* Common initialisation for all SPs. */
64void spmc_sp_common_setup(struct secure_partition_desc *sp,
65 entry_point_info_t *ep_info)
66{
67 uint16_t sp_id;
68
69 /* Assign FF-A Partition ID if not already assigned. */
70 if (sp->sp_id == INV_SP_ID) {
71 sp_id = FFA_SP_ID_BASE + ACTIVE_SP_DESC_INDEX;
72 /*
73 * Ensure we don't clash with previously assigned partition
74 * IDs.
75 */
76 while (!is_ffa_secure_id_valid(sp_id)) {
77 sp_id++;
78
79 if (sp_id == FFA_SWD_ID_LIMIT) {
80 ERROR("Unable to determine valid SP ID.\n");
81 panic();
82 }
83 }
84 sp->sp_id = sp_id;
85 }
86
87 /*
88 * We currently only support S-EL1 partitions so ensure this is the
89 * case.
90 */
91 assert(sp->runtime_el == S_EL1);
92
93 /*
94 * Clear the general purpose registers. These should be populated as
95 * required.
96 */
97 zeromem(&ep_info->args, sizeof(ep_info->args));
98}
99
100/*
101 * Initialise the SP context now we have populated the common and EL specific
102 * entrypoint information.
103 */
104void spmc_sp_common_ep_commit(struct secure_partition_desc *sp,
105 entry_point_info_t *ep_info)
106{
107 cpu_context_t *cpu_ctx;
108
109 cpu_ctx = &(spmc_get_sp_ec(sp)->cpu_ctx);
110 print_entry_point_info(ep_info);
111 cm_setup_context(cpu_ctx, ep_info);
112}