blob: 9d06ea9c47ae29435eaea9ef21b890b7421c4693 [file] [log] [blame]
J-Alves7ec9d6e2023-02-28 16:39:56 +00001/*
2 * Copyright 2023 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#pragma once
10
11#include <stdint.h>
12
13#include "hf/addr.h"
14#include "hf/memiter.h"
15#include "hf/string.h"
16
17#include "vmapi/hf/ffa.h"
18
19#define MANIFEST_INVALID_ADDRESS UINT64_MAX
20#define MANIFEST_INVALID_ID UINT32_MAX
21
22#define SP_RTX_BUF_NAME_SIZE 10
23
24/** FF-A manifest memory and device regions attributes. */
25#define MANIFEST_REGION_ATTR_READ (UINT32_C(1) << 0)
26#define MANIFEST_REGION_ATTR_WRITE (UINT32_C(1) << 1)
27#define MANIFEST_REGION_ATTR_EXEC (UINT32_C(1) << 2)
28#define MANIFEST_REGION_ATTR_SECURITY (UINT32_C(1) << 3)
29
Olivier Deprez058ddee2024-08-27 09:22:11 +020030#define MANIFEST_REGION_ALL_ATTR_MASK \
31 (MANIFEST_REGION_ATTR_READ | MANIFEST_REGION_ATTR_WRITE | \
32 MANIFEST_REGION_ATTR_EXEC | MANIFEST_REGION_ATTR_SECURITY)
J-Alves7ec9d6e2023-02-28 16:39:56 +000033
34#define MANIFEST_POWER_MANAGEMENT_CPU_OFF_SUPPORTED (UINT32_C(1) << 0)
J-Alves7ec9d6e2023-02-28 16:39:56 +000035#define MANIFEST_POWER_MANAGEMENT_NONE_MASK (UINT32_C(0))
Madhukar Pappireddy958c8412024-11-25 09:54:17 -060036#define MANIFEST_POWER_MANAGEMENT_ALL_MASK \
37 MANIFEST_POWER_MANAGEMENT_CPU_OFF_SUPPORTED
J-Alves7ec9d6e2023-02-28 16:39:56 +000038
39/* Highest possible value for the boot-order field. */
40#define DEFAULT_BOOT_ORDER 0xFFFF
41#define DEFAULT_BOOT_GP_REGISTER UINT32_C(-1)
42
43enum run_time_el {
44 EL1 = 0,
45 S_EL0,
46 S_EL1,
47 SUPERVISOR_MODE,
48 SECURE_USER_MODE,
Daniel Boulby874d5432023-04-27 12:40:24 +010049 SECURE_SUPERVISOR_MODE,
50 EL0
J-Alves7ec9d6e2023-02-28 16:39:56 +000051};
52
53enum execution_state { AARCH64 = 0, AARCH32 };
54
55enum xlat_granule { PAGE_4KB = 0, PAGE_16KB, PAGE_64KB };
56
Madhukar Pappireddyc35573d2025-03-17 18:00:32 -050057/**
58 * Refer section 7.3 of the FF-A v1.3 ALP2 specification.
59 */
60enum abort_action {
61 /** Keep vCPU in STOPPED state. */
62 ACTION_STOP = 0,
63
64 /** Transition vCPU to NULL state. */
65 ACTION_DESTROY = 1,
66
67 /** Transition vCPU to STARTING state. */
68 ACTION_RESTART = 2,
69
70 /** SPMC aborts itself and informs SPMD. */
71 ACTION_PROPAGATE = 3,
72
73 /**
74 * SPMC takes implementation defined action if not specified explicitly.
75 */
76 ACTION_IMP_DEF,
77
78 /** No other actions supported. */
79};
80
J-Alvesbb2703a2025-02-10 12:11:56 +000081struct sri_interrupts_policy {
82 /**
83 * When the partition is in waiting state at the moment one
84 * of its interrupts fires, the SPMC will trigger an SRI
85 * to the scheduler to explicitly provide CPU cycles, such that
86 * the interrupt can be handled.
87 */
88 bool intr_while_waiting : 1;
89
90 /**
91 * If the SP is trying to go into a waiting state and it has
92 * pending interrupts, leave interrupts pended and trigger
93 * SRI to the scheduler of the system to explicitly provide
94 * CPU cycles at a later instance, such that the interrupt
95 * can be handled.
96 */
97 bool intr_pending_entry_wait : 1;
98
99 uint8_t mbz : 6;
100};
101
J-Alves7ec9d6e2023-02-28 16:39:56 +0000102/**
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -0500103 * Properties of the DMA capable device upstream of an SMMU as specified in the
104 * memory region description of the partition manifest.
105 */
106struct dma_device_properties {
107 /** SMMU ID - optional */
108 uint32_t smmu_id;
109 /** IMPDEF id tracking DMA peripheral device - optional */
110 uint8_t dma_device_id;
111 /** Count of Stream IDs assigned to device - optional */
112 uint8_t stream_count;
113 /** List of Stream IDs assigned to device - optional */
114 uint32_t stream_ids[PARTITION_MAX_STREAMS_PER_DEVICE];
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -0500115};
116
117/**
118 * Partition Memory region as described in FFA v1.2 spec, Table 5.2 along with
119 * an implementation defined struct to track the properties of a DMA capable
120 * device that has access to this memory region.
J-Alves7ec9d6e2023-02-28 16:39:56 +0000121 */
122struct memory_region {
Karl Meakinfb761eb2024-11-20 15:59:56 +0000123 struct string description;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000124 /**
125 * Specify PA, VA for S-EL0 partitions or IPA
126 * for S-EL1 partitions - optional.
127 */
128 uintptr_t base_address;
Karl Meakin6291eb22024-11-18 12:43:47 +0000129 /** True if `load-address-relative-offset` was specified. */
130 bool is_relative;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000131 /** Page count - mandatory */
132 uint32_t page_count;
133 /** Memory attributes - mandatory */
134 uint32_t attributes;
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -0500135 /** DMA device properties - optional */
136 struct dma_device_properties dma_prop;
Madhukar Pappireddy9c764b32024-06-20 14:36:55 -0500137 /** Instruction and data access permissions for DMA device - optional */
138 uint32_t dma_access_permissions;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000139};
140
Daniel Boulby18485942024-10-14 16:23:03 +0100141/**
142 * Interrupts attibutes encoding in the manifest:
143 * Field Bit(s)
144 * ---------------------------
145 * Priority 7:0
146 * Security_State 8
147 * Config(Edge/Level) 9
148 * Type(SPI/PPI/SGI) 11:10
149 * Reserved 31:12
150 */
151#define INT_INFO_ATTR_PRIORITY_SHIFT 0
152#define INT_INFO_ATTR_SEC_STATE_SHIFT 8
153#define INT_INFO_ATTR_CONFIG_SHIFT 9
154#define INT_INFO_ATTR_TYPE_SHIFT 10
155
J-Alves7ec9d6e2023-02-28 16:39:56 +0000156struct interrupt_info {
157 uint32_t id;
158 uint32_t attributes;
159 bool mpidr_valid;
160 uint64_t mpidr;
161};
162
163/**
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -0500164 * Partition Device region as described in FFA v1.2 spec, Table 5.3 along with
165 * few implementation defined fields.
J-Alves7ec9d6e2023-02-28 16:39:56 +0000166 */
167struct device_region {
168 /** Device base PA - mandatory */
169 uintptr_t base_address;
170 /** Page count - mandatory */
171 uint32_t page_count;
172 /** Memory attributes - mandatory */
173 uint32_t attributes;
174 /** List of physical interrupt ID's and their attributes - optional */
175 struct interrupt_info interrupts[PARTITION_MAX_INTERRUPTS_PER_DEVICE];
176 /** Count of physical interrupts - optional */
177 uint8_t interrupt_count;
Madhukar Pappireddy9c764b32024-06-20 14:36:55 -0500178 /** DMA device properties - optional */
179 struct dma_device_properties dma_prop;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000180 /** Exclusive access to an endpoint - optional */
181 bool exclusive_access;
182 /** Name of Device region - optional */
183 struct string name;
184};
185
186/**
187 * RX/TX buffer, reference to memory-region entries that describe RX/TX
188 * buffers in partition manifest.
189 */
190struct rx_tx {
191 bool available;
192 uint32_t rx_phandle;
193 uint32_t tx_phandle;
194 struct memory_region *rx_buffer;
195 struct memory_region *tx_buffer;
196};
197
Karl Meakin18694022024-08-02 13:59:25 +0100198struct vm_availability_messages {
199 bool vm_created : 1;
200 bool vm_destroyed : 1;
201 uint32_t mbz : 30;
202};
203
204static_assert(sizeof(struct vm_availability_messages) == sizeof(uint32_t),
205 "vm_availability_messages must have same size as uint32_t");
206
J-Alves7ec9d6e2023-02-28 16:39:56 +0000207/**
208 * Partition manifest as described in FF-A v1.0 spec section 3.1
209 */
210struct ffa_partition_manifest {
211 /** FF-A expected version - mandatory */
Karl Meakin0e617d92024-04-05 12:55:22 +0100212 enum ffa_version ffa_version;
Kathleen Capella422b10b2023-06-30 18:28:27 -0400213 /** UUID - at least one UUID mandatory */
214 uint16_t uuid_count;
215 struct ffa_uuid uuids[PARTITION_MAX_UUIDS];
J-Alves7ec9d6e2023-02-28 16:39:56 +0000216 /** Partition id - optional */
J-Alves19e20cf2023-08-02 12:48:55 +0100217 ffa_id_t id;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000218 /** Aux ids for mem transactions - optional */
J-Alves19e20cf2023-08-02 12:48:55 +0100219 ffa_id_t aux_id;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000220
221 /* NOTE: optional name field maps to VM debug_name field */
222
223 /** mandatory */
224 ffa_vcpu_count_t execution_ctx_count;
225 /** EL1 or secure EL1, secure EL0 - mandatory */
226 enum run_time_el run_time_el;
227 /** AArch32 / AArch64 - mandatory */
228 enum execution_state execution_state;
229 /** optional */
230 uintpaddr_t load_addr;
231 /** optional */
232 size_t ep_offset;
233 /** 4/16/64KB - optional */
234 enum xlat_granule xlat_granule;
235 /** Register id from w0/x0-w3/x3 - optional. */
236 uint32_t gp_register_num;
237 /**
238 * Flags the presence of the optional IMPDEF node to define Partition's
239 * Boot Info.
240 */
241 bool boot_info;
242 /** optional */
243 uint16_t boot_order;
244
245 /** Optional RX/TX buffers */
246 struct rx_tx rxtx;
247
248 /** mandatory - direct/indirect msg or both */
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400249 uint16_t messaging_method;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000250 /** mandatory - action in response to non secure interrupt */
251 uint8_t ns_interrupts_action;
252 /** optional - managed exit signaled through vIRQ */
253 bool me_signal_virq;
254 /** optional - receipt of notifications. */
255 bool notification_support;
J-Alvesbb2703a2025-02-10 12:11:56 +0000256
257 /** optional - request the scheduler cycles to handle interrupts. */
258 struct sri_interrupts_policy sri_policy;
259
J-Alves7ec9d6e2023-02-28 16:39:56 +0000260 /**
Karl Meakin18694022024-08-02 13:59:25 +0100261 * optional - VM availability messages bitfield.
262 */
263 struct vm_availability_messages vm_availability_messages;
264
265 /**
J-Alves7ec9d6e2023-02-28 16:39:56 +0000266 * optional - power management messages bitfield.
267 *
268 * See [1] power-management-messages manifest field.
269 *
270 * The Hafnium supported combinations for a MP SP are:
271 * Bit 0 - relay PSCI cpu off message to the SP.
272 * Bit 3 - relay PSCI cpu on to the SP.
273 *
274 * [1]
275 * https://trustedfirmware-a.readthedocs.io/en/latest/components/ffa-manifest-binding.html#partition-properties
276 */
277 uint32_t power_management;
278 /** optional */
279 bool has_primary_scheduler;
280 /** optional - tuples SEPID/SMMUID/streamId */
281 uint32_t stream_ep_ids[1];
282
283 /** Memory regions */
284 uint16_t mem_region_count;
285 struct memory_region mem_regions[PARTITION_MAX_MEMORY_REGIONS];
286 /** Device regions */
287 uint16_t dev_region_count;
288 struct device_region dev_regions[PARTITION_MAX_DEVICE_REGIONS];
Madhukar Pappireddye032af52023-10-11 14:52:58 -0500289 /** DMA device count. */
290 uint8_t dma_device_count;
291
J-Alves7ec9d6e2023-02-28 16:39:56 +0000292 /** optional - action in response to Other-Secure interrupt */
293 uint8_t other_s_interrupts_action;
Madhukar Pappireddyc35573d2025-03-17 18:00:32 -0500294
295 /** optional - SP lifecycle supported. */
296 bool lifecycle_support;
297
298 /** optional - Action in response to FFA_ABORT if SP lifecycle
299 * supported.
300 */
301 uint8_t abort_action;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000302};