blob: a9c78d335409d56862fcb1db3fced693de1a5c45 [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"
Karl Meakin18694022024-08-02 13:59:25 +010015#include "hf/static_assert.h"
J-Alves7ec9d6e2023-02-28 16:39:56 +000016#include "hf/string.h"
17
18#include "vmapi/hf/ffa.h"
19
20#define MANIFEST_INVALID_ADDRESS UINT64_MAX
21#define MANIFEST_INVALID_ID UINT32_MAX
22
23#define SP_RTX_BUF_NAME_SIZE 10
24
25/** FF-A manifest memory and device regions attributes. */
26#define MANIFEST_REGION_ATTR_READ (UINT32_C(1) << 0)
27#define MANIFEST_REGION_ATTR_WRITE (UINT32_C(1) << 1)
28#define MANIFEST_REGION_ATTR_EXEC (UINT32_C(1) << 2)
29#define MANIFEST_REGION_ATTR_SECURITY (UINT32_C(1) << 3)
30
Olivier Deprez058ddee2024-08-27 09:22:11 +020031#define MANIFEST_REGION_ALL_ATTR_MASK \
32 (MANIFEST_REGION_ATTR_READ | MANIFEST_REGION_ATTR_WRITE | \
33 MANIFEST_REGION_ATTR_EXEC | MANIFEST_REGION_ATTR_SECURITY)
J-Alves7ec9d6e2023-02-28 16:39:56 +000034
35#define MANIFEST_POWER_MANAGEMENT_CPU_OFF_SUPPORTED (UINT32_C(1) << 0)
J-Alves7ec9d6e2023-02-28 16:39:56 +000036#define MANIFEST_POWER_MANAGEMENT_NONE_MASK (UINT32_C(0))
Madhukar Pappireddy958c8412024-11-25 09:54:17 -060037#define MANIFEST_POWER_MANAGEMENT_ALL_MASK \
38 MANIFEST_POWER_MANAGEMENT_CPU_OFF_SUPPORTED
J-Alves7ec9d6e2023-02-28 16:39:56 +000039
40/* Highest possible value for the boot-order field. */
41#define DEFAULT_BOOT_ORDER 0xFFFF
42#define DEFAULT_BOOT_GP_REGISTER UINT32_C(-1)
43
44enum run_time_el {
45 EL1 = 0,
46 S_EL0,
47 S_EL1,
48 SUPERVISOR_MODE,
49 SECURE_USER_MODE,
Daniel Boulby874d5432023-04-27 12:40:24 +010050 SECURE_SUPERVISOR_MODE,
51 EL0
J-Alves7ec9d6e2023-02-28 16:39:56 +000052};
53
54enum execution_state { AARCH64 = 0, AARCH32 };
55
56enum xlat_granule { PAGE_4KB = 0, PAGE_16KB, PAGE_64KB };
57
J-Alvesbb2703a2025-02-10 12:11:56 +000058struct sri_interrupts_policy {
59 /**
60 * When the partition is in waiting state at the moment one
61 * of its interrupts fires, the SPMC will trigger an SRI
62 * to the scheduler to explicitly provide CPU cycles, such that
63 * the interrupt can be handled.
64 */
65 bool intr_while_waiting : 1;
66
67 /**
68 * If the SP is trying to go into a waiting state and it has
69 * pending interrupts, leave interrupts pended and trigger
70 * SRI to the scheduler of the system to explicitly provide
71 * CPU cycles at a later instance, such that the interrupt
72 * can be handled.
73 */
74 bool intr_pending_entry_wait : 1;
75
76 uint8_t mbz : 6;
77};
78
J-Alves7ec9d6e2023-02-28 16:39:56 +000079/**
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -050080 * Properties of the DMA capable device upstream of an SMMU as specified in the
81 * memory region description of the partition manifest.
82 */
83struct dma_device_properties {
84 /** SMMU ID - optional */
85 uint32_t smmu_id;
86 /** IMPDEF id tracking DMA peripheral device - optional */
87 uint8_t dma_device_id;
88 /** Count of Stream IDs assigned to device - optional */
89 uint8_t stream_count;
90 /** List of Stream IDs assigned to device - optional */
91 uint32_t stream_ids[PARTITION_MAX_STREAMS_PER_DEVICE];
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -050092};
93
94/**
95 * Partition Memory region as described in FFA v1.2 spec, Table 5.2 along with
96 * an implementation defined struct to track the properties of a DMA capable
97 * device that has access to this memory region.
J-Alves7ec9d6e2023-02-28 16:39:56 +000098 */
99struct memory_region {
Karl Meakinfb761eb2024-11-20 15:59:56 +0000100 struct string description;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000101 /**
102 * Specify PA, VA for S-EL0 partitions or IPA
103 * for S-EL1 partitions - optional.
104 */
105 uintptr_t base_address;
Karl Meakin6291eb22024-11-18 12:43:47 +0000106 /** True if `load-address-relative-offset` was specified. */
107 bool is_relative;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000108 /** Page count - mandatory */
109 uint32_t page_count;
110 /** Memory attributes - mandatory */
111 uint32_t attributes;
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -0500112 /** DMA device properties - optional */
113 struct dma_device_properties dma_prop;
Madhukar Pappireddy9c764b32024-06-20 14:36:55 -0500114 /** Instruction and data access permissions for DMA device - optional */
115 uint32_t dma_access_permissions;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000116};
117
Daniel Boulby18485942024-10-14 16:23:03 +0100118/**
119 * Interrupts attibutes encoding in the manifest:
120 * Field Bit(s)
121 * ---------------------------
122 * Priority 7:0
123 * Security_State 8
124 * Config(Edge/Level) 9
125 * Type(SPI/PPI/SGI) 11:10
126 * Reserved 31:12
127 */
128#define INT_INFO_ATTR_PRIORITY_SHIFT 0
129#define INT_INFO_ATTR_SEC_STATE_SHIFT 8
130#define INT_INFO_ATTR_CONFIG_SHIFT 9
131#define INT_INFO_ATTR_TYPE_SHIFT 10
132
J-Alves7ec9d6e2023-02-28 16:39:56 +0000133struct interrupt_info {
134 uint32_t id;
135 uint32_t attributes;
136 bool mpidr_valid;
137 uint64_t mpidr;
138};
139
140/**
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -0500141 * Partition Device region as described in FFA v1.2 spec, Table 5.3 along with
142 * few implementation defined fields.
J-Alves7ec9d6e2023-02-28 16:39:56 +0000143 */
144struct device_region {
145 /** Device base PA - mandatory */
146 uintptr_t base_address;
147 /** Page count - mandatory */
148 uint32_t page_count;
149 /** Memory attributes - mandatory */
150 uint32_t attributes;
151 /** List of physical interrupt ID's and their attributes - optional */
152 struct interrupt_info interrupts[PARTITION_MAX_INTERRUPTS_PER_DEVICE];
153 /** Count of physical interrupts - optional */
154 uint8_t interrupt_count;
Madhukar Pappireddy9c764b32024-06-20 14:36:55 -0500155 /** DMA device properties - optional */
156 struct dma_device_properties dma_prop;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000157 /** Exclusive access to an endpoint - optional */
158 bool exclusive_access;
159 /** Name of Device region - optional */
160 struct string name;
161};
162
163/**
164 * RX/TX buffer, reference to memory-region entries that describe RX/TX
165 * buffers in partition manifest.
166 */
167struct rx_tx {
168 bool available;
169 uint32_t rx_phandle;
170 uint32_t tx_phandle;
171 struct memory_region *rx_buffer;
172 struct memory_region *tx_buffer;
173};
174
Karl Meakin18694022024-08-02 13:59:25 +0100175struct vm_availability_messages {
176 bool vm_created : 1;
177 bool vm_destroyed : 1;
178 uint32_t mbz : 30;
179};
180
181static_assert(sizeof(struct vm_availability_messages) == sizeof(uint32_t),
182 "vm_availability_messages must have same size as uint32_t");
183
J-Alves7ec9d6e2023-02-28 16:39:56 +0000184/**
185 * Partition manifest as described in FF-A v1.0 spec section 3.1
186 */
187struct ffa_partition_manifest {
188 /** FF-A expected version - mandatory */
Karl Meakin0e617d92024-04-05 12:55:22 +0100189 enum ffa_version ffa_version;
Kathleen Capella422b10b2023-06-30 18:28:27 -0400190 /** UUID - at least one UUID mandatory */
191 uint16_t uuid_count;
192 struct ffa_uuid uuids[PARTITION_MAX_UUIDS];
J-Alves7ec9d6e2023-02-28 16:39:56 +0000193 /** Partition id - optional */
J-Alves19e20cf2023-08-02 12:48:55 +0100194 ffa_id_t id;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000195 /** Aux ids for mem transactions - optional */
J-Alves19e20cf2023-08-02 12:48:55 +0100196 ffa_id_t aux_id;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000197
198 /* NOTE: optional name field maps to VM debug_name field */
199
200 /** mandatory */
201 ffa_vcpu_count_t execution_ctx_count;
202 /** EL1 or secure EL1, secure EL0 - mandatory */
203 enum run_time_el run_time_el;
204 /** AArch32 / AArch64 - mandatory */
205 enum execution_state execution_state;
206 /** optional */
207 uintpaddr_t load_addr;
208 /** optional */
209 size_t ep_offset;
210 /** 4/16/64KB - optional */
211 enum xlat_granule xlat_granule;
212 /** Register id from w0/x0-w3/x3 - optional. */
213 uint32_t gp_register_num;
214 /**
215 * Flags the presence of the optional IMPDEF node to define Partition's
216 * Boot Info.
217 */
218 bool boot_info;
219 /** optional */
220 uint16_t boot_order;
221
222 /** Optional RX/TX buffers */
223 struct rx_tx rxtx;
224
225 /** mandatory - direct/indirect msg or both */
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400226 uint16_t messaging_method;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000227 /** mandatory - action in response to non secure interrupt */
228 uint8_t ns_interrupts_action;
229 /** optional - managed exit signaled through vIRQ */
230 bool me_signal_virq;
231 /** optional - receipt of notifications. */
232 bool notification_support;
J-Alvesbb2703a2025-02-10 12:11:56 +0000233
234 /** optional - request the scheduler cycles to handle interrupts. */
235 struct sri_interrupts_policy sri_policy;
236
J-Alves7ec9d6e2023-02-28 16:39:56 +0000237 /**
Karl Meakin18694022024-08-02 13:59:25 +0100238 * optional - VM availability messages bitfield.
239 */
240 struct vm_availability_messages vm_availability_messages;
241
242 /**
J-Alves7ec9d6e2023-02-28 16:39:56 +0000243 * optional - power management messages bitfield.
244 *
245 * See [1] power-management-messages manifest field.
246 *
247 * The Hafnium supported combinations for a MP SP are:
248 * Bit 0 - relay PSCI cpu off message to the SP.
249 * Bit 3 - relay PSCI cpu on to the SP.
250 *
251 * [1]
252 * https://trustedfirmware-a.readthedocs.io/en/latest/components/ffa-manifest-binding.html#partition-properties
253 */
254 uint32_t power_management;
255 /** optional */
256 bool has_primary_scheduler;
257 /** optional - tuples SEPID/SMMUID/streamId */
258 uint32_t stream_ep_ids[1];
259
260 /** Memory regions */
261 uint16_t mem_region_count;
262 struct memory_region mem_regions[PARTITION_MAX_MEMORY_REGIONS];
263 /** Device regions */
264 uint16_t dev_region_count;
265 struct device_region dev_regions[PARTITION_MAX_DEVICE_REGIONS];
Madhukar Pappireddye032af52023-10-11 14:52:58 -0500266 /** DMA device count. */
267 uint8_t dma_device_count;
268
J-Alves7ec9d6e2023-02-28 16:39:56 +0000269 /** optional - action in response to Other-Secure interrupt */
270 uint8_t other_s_interrupts_action;
271};