blob: db29727ea17c8b55e7ce3d1f64387c5d85c2c446 [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#ifndef SPMC_H
8#define SPMC_H
9
10#include <stdint.h>
11
12#include <lib/psci/psci.h>
13#include <lib/spinlock.h>
Marc Bonnici9a297042022-02-14 17:06:09 +000014#include <services/el3_spmc_logical_sp.h>
Marc Bonnici8e1a7552021-12-01 17:57:04 +000015#include "spm_common.h"
16
17/*
18 * Ranges of FF-A IDs for Normal world and Secure world components. The
19 * convention matches that used by other SPMCs i.e. Hafnium and OP-TEE.
20 */
21#define FFA_NWD_ID_BASE 0x0
22#define FFA_NWD_ID_LIMIT 0x7FFF
23#define FFA_SWD_ID_BASE 0x8000
24#define FFA_SWD_ID_LIMIT SPMD_DIRECT_MSG_ENDPOINT_ID - 1
25#define FFA_SWD_ID_MASK 0x8000
26
Marc Bonnici8eb15202021-11-29 17:05:33 +000027/* ID 0 is reserved for the normal world entity, (Hypervisor or OS Kernel). */
28#define FFA_NWD_ID U(0)
Marc Bonnici8e1a7552021-12-01 17:57:04 +000029/* First ID is reserved for the SPMC */
30#define FFA_SPMC_ID U(FFA_SWD_ID_BASE)
31/* SP IDs are allocated after the SPMC ID */
32#define FFA_SP_ID_BASE (FFA_SPMC_ID + 1)
33/* Align with Hafnium implementation */
34#define INV_SP_ID 0x7FFF
35
36/* FF-A warm boot types. */
37#define FFA_WB_TYPE_S2RAM 0
38#define FFA_WB_TYPE_NOTS2RAM 1
39
40/*
41 * Runtime states of an execution context as per the FF-A v1.1 specification.
42 */
43enum sp_runtime_states {
44 RT_STATE_WAITING,
45 RT_STATE_RUNNING,
46 RT_STATE_PREEMPTED,
47 RT_STATE_BLOCKED
48};
49
50/*
51 * Runtime model of an execution context as per the FF-A v1.1 specification. Its
52 * value is valid only if the execution context is not in the waiting state.
53 */
54enum sp_runtime_model {
55 RT_MODEL_DIR_REQ,
56 RT_MODEL_RUN,
57 RT_MODEL_INIT,
58 RT_MODEL_INTR
59};
60
61enum sp_runtime_el {
62 EL1 = 0,
63 S_EL0,
64 S_EL1
65};
66
67enum sp_execution_state {
68 SP_STATE_AARCH64 = 0,
69 SP_STATE_AARCH32
70};
71
72/*
73 * Execution context members for an SP. This is a bit like struct
74 * vcpu in a hypervisor.
75 */
76struct sp_exec_ctx {
77 /*
78 * Store the stack address to restore C runtime context from after
79 * returning from a synchronous entry into the SP.
80 */
81 uint64_t c_rt_ctx;
82
83 /* Space to maintain the architectural state of an SP. */
84 cpu_context_t cpu_ctx;
85
86 /* Track the current runtime state of the SP. */
87 enum sp_runtime_states rt_state;
88
89 /* Track the current runtime model of the SP. */
90 enum sp_runtime_model rt_model;
91};
92
93/*
94 * Structure to describe the cumulative properties of an SP.
95 */
96struct secure_partition_desc {
97 /*
98 * Execution contexts allocated to this endpoint. Ideally,
99 * we need as many contexts as there are physical cpus only
100 * for a S-EL1 SP which is MP-pinned.
101 */
102 struct sp_exec_ctx ec[PLATFORM_CORE_COUNT];
103
104 /* ID of the Secure Partition. */
105 uint16_t sp_id;
106
107 /* Runtime EL. */
108 enum sp_runtime_el runtime_el;
109
110 /* Partition UUID. */
111 uint32_t uuid[4];
112
113 /* Partition Properties. */
114 uint32_t properties;
115
116 /* Supported FF-A Version. */
117 uint32_t ffa_version;
118
119 /* Execution State. */
120 enum sp_execution_state execution_state;
121
122 /* Secondary entrypoint. Only valid for a S-EL1 SP. */
123 uintptr_t secondary_ep;
124};
125
126/*
127 * This define identifies the only SP that will be initialised and participate
128 * in FF-A communication. The implementation leaves the door open for more SPs
129 * to be managed in future but for now it is reasonable to assume that either a
130 * single S-EL0 or a single S-EL1 SP will be supported. This define will be used
131 * to identify which SP descriptor to initialise and manage during SP runtime.
132 */
133#define ACTIVE_SP_DESC_INDEX 0
134
135/*
136 * Structure to describe the cumulative properties of the Hypervisor and
137 * NS-Endpoints.
138 */
139struct ns_endpoint_desc {
140 /*
141 * ID of the NS-Endpoint or Hypervisor.
142 */
143 uint16_t ns_ep_id;
144
145 /*
146 * Supported FF-A Version.
147 */
148 uint32_t ffa_version;
149};
150
151/* Setup Function for different SP types. */
152void spmc_sp_common_setup(struct secure_partition_desc *sp,
153 entry_point_info_t *ep_info);
154void spmc_el1_sp_setup(struct secure_partition_desc *sp,
155 entry_point_info_t *ep_info);
156void spmc_sp_common_ep_commit(struct secure_partition_desc *sp,
157 entry_point_info_t *ep_info);
158
159/*
160 * Helper function to perform a synchronous entry into a SP.
161 */
162uint64_t spmc_sp_synchronous_entry(struct sp_exec_ctx *ec);
163
164/*
165 * Helper function to obtain the descriptor of the current SP on a physical cpu.
166 */
167struct secure_partition_desc *spmc_get_current_sp_ctx(void);
168
169/*
170 * Helper function to obtain the execution context of an SP on a
171 * physical cpu.
172 */
173struct sp_exec_ctx *spmc_get_sp_ec(struct secure_partition_desc *sp);
174
175/*
176 * Helper function to obtain the index of the execution context of an SP on a
177 * physical cpu.
178 */
179unsigned int get_ec_index(struct secure_partition_desc *sp);
180
181uint64_t spmc_ffa_error_return(void *handle, int error_code);
182
183/*
184 * Ensure a partition ID does not clash and follows the secure world convention.
185 */
186bool is_ffa_secure_id_valid(uint16_t partition_id);
187
Marc Bonnici9a297042022-02-14 17:06:09 +0000188/*
189 * Helper function to obtain the array storing the EL3
190 * Logical Partition descriptors.
191 */
192struct el3_lp_desc *get_el3_lp_array(void);
193
Marc Bonnici8e1a7552021-12-01 17:57:04 +0000194#endif /* SPMC_H */