blob: d32168b20216e092ed14abbb116bc8e8037fedfb [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
J-Alvesbb2703a2025-02-10 12:11:56 +000057struct sri_interrupts_policy {
58 /**
59 * When the partition is in waiting state at the moment one
60 * of its interrupts fires, the SPMC will trigger an SRI
61 * to the scheduler to explicitly provide CPU cycles, such that
62 * the interrupt can be handled.
63 */
64 bool intr_while_waiting : 1;
65
66 /**
67 * If the SP is trying to go into a waiting state and it has
68 * pending interrupts, leave interrupts pended and trigger
69 * SRI to the scheduler of the system to explicitly provide
70 * CPU cycles at a later instance, such that the interrupt
71 * can be handled.
72 */
73 bool intr_pending_entry_wait : 1;
74
75 uint8_t mbz : 6;
76};
77
J-Alves7ec9d6e2023-02-28 16:39:56 +000078/**
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -050079 * Properties of the DMA capable device upstream of an SMMU as specified in the
80 * memory region description of the partition manifest.
81 */
82struct dma_device_properties {
83 /** SMMU ID - optional */
84 uint32_t smmu_id;
85 /** IMPDEF id tracking DMA peripheral device - optional */
86 uint8_t dma_device_id;
87 /** Count of Stream IDs assigned to device - optional */
88 uint8_t stream_count;
89 /** List of Stream IDs assigned to device - optional */
90 uint32_t stream_ids[PARTITION_MAX_STREAMS_PER_DEVICE];
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -050091};
92
93/**
94 * Partition Memory region as described in FFA v1.2 spec, Table 5.2 along with
95 * an implementation defined struct to track the properties of a DMA capable
96 * device that has access to this memory region.
J-Alves7ec9d6e2023-02-28 16:39:56 +000097 */
98struct memory_region {
Karl Meakinfb761eb2024-11-20 15:59:56 +000099 struct string description;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000100 /**
101 * Specify PA, VA for S-EL0 partitions or IPA
102 * for S-EL1 partitions - optional.
103 */
104 uintptr_t base_address;
Karl Meakin6291eb22024-11-18 12:43:47 +0000105 /** True if `load-address-relative-offset` was specified. */
106 bool is_relative;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000107 /** Page count - mandatory */
108 uint32_t page_count;
109 /** Memory attributes - mandatory */
110 uint32_t attributes;
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -0500111 /** DMA device properties - optional */
112 struct dma_device_properties dma_prop;
Madhukar Pappireddy9c764b32024-06-20 14:36:55 -0500113 /** Instruction and data access permissions for DMA device - optional */
114 uint32_t dma_access_permissions;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000115};
116
Daniel Boulby18485942024-10-14 16:23:03 +0100117/**
118 * Interrupts attibutes encoding in the manifest:
119 * Field Bit(s)
120 * ---------------------------
121 * Priority 7:0
122 * Security_State 8
123 * Config(Edge/Level) 9
124 * Type(SPI/PPI/SGI) 11:10
125 * Reserved 31:12
126 */
127#define INT_INFO_ATTR_PRIORITY_SHIFT 0
128#define INT_INFO_ATTR_SEC_STATE_SHIFT 8
129#define INT_INFO_ATTR_CONFIG_SHIFT 9
130#define INT_INFO_ATTR_TYPE_SHIFT 10
131
J-Alves7ec9d6e2023-02-28 16:39:56 +0000132struct interrupt_info {
133 uint32_t id;
134 uint32_t attributes;
135 bool mpidr_valid;
136 uint64_t mpidr;
137};
138
139/**
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -0500140 * Partition Device region as described in FFA v1.2 spec, Table 5.3 along with
141 * few implementation defined fields.
J-Alves7ec9d6e2023-02-28 16:39:56 +0000142 */
143struct device_region {
144 /** Device base PA - mandatory */
145 uintptr_t base_address;
146 /** Page count - mandatory */
147 uint32_t page_count;
148 /** Memory attributes - mandatory */
149 uint32_t attributes;
150 /** List of physical interrupt ID's and their attributes - optional */
151 struct interrupt_info interrupts[PARTITION_MAX_INTERRUPTS_PER_DEVICE];
152 /** Count of physical interrupts - optional */
153 uint8_t interrupt_count;
Madhukar Pappireddy9c764b32024-06-20 14:36:55 -0500154 /** DMA device properties - optional */
155 struct dma_device_properties dma_prop;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000156 /** Exclusive access to an endpoint - optional */
157 bool exclusive_access;
158 /** Name of Device region - optional */
159 struct string name;
160};
161
162/**
163 * RX/TX buffer, reference to memory-region entries that describe RX/TX
164 * buffers in partition manifest.
165 */
166struct rx_tx {
167 bool available;
168 uint32_t rx_phandle;
169 uint32_t tx_phandle;
170 struct memory_region *rx_buffer;
171 struct memory_region *tx_buffer;
172};
173
Karl Meakin18694022024-08-02 13:59:25 +0100174struct vm_availability_messages {
175 bool vm_created : 1;
176 bool vm_destroyed : 1;
177 uint32_t mbz : 30;
178};
179
180static_assert(sizeof(struct vm_availability_messages) == sizeof(uint32_t),
181 "vm_availability_messages must have same size as uint32_t");
182
J-Alves7ec9d6e2023-02-28 16:39:56 +0000183/**
184 * Partition manifest as described in FF-A v1.0 spec section 3.1
185 */
186struct ffa_partition_manifest {
187 /** FF-A expected version - mandatory */
Karl Meakin0e617d92024-04-05 12:55:22 +0100188 enum ffa_version ffa_version;
Kathleen Capella422b10b2023-06-30 18:28:27 -0400189 /** UUID - at least one UUID mandatory */
190 uint16_t uuid_count;
191 struct ffa_uuid uuids[PARTITION_MAX_UUIDS];
J-Alves7ec9d6e2023-02-28 16:39:56 +0000192 /** Partition id - optional */
J-Alves19e20cf2023-08-02 12:48:55 +0100193 ffa_id_t id;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000194 /** Aux ids for mem transactions - optional */
J-Alves19e20cf2023-08-02 12:48:55 +0100195 ffa_id_t aux_id;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000196
197 /* NOTE: optional name field maps to VM debug_name field */
198
199 /** mandatory */
200 ffa_vcpu_count_t execution_ctx_count;
201 /** EL1 or secure EL1, secure EL0 - mandatory */
202 enum run_time_el run_time_el;
203 /** AArch32 / AArch64 - mandatory */
204 enum execution_state execution_state;
205 /** optional */
206 uintpaddr_t load_addr;
207 /** optional */
208 size_t ep_offset;
209 /** 4/16/64KB - optional */
210 enum xlat_granule xlat_granule;
211 /** Register id from w0/x0-w3/x3 - optional. */
212 uint32_t gp_register_num;
213 /**
214 * Flags the presence of the optional IMPDEF node to define Partition's
215 * Boot Info.
216 */
217 bool boot_info;
218 /** optional */
219 uint16_t boot_order;
220
221 /** Optional RX/TX buffers */
222 struct rx_tx rxtx;
223
224 /** mandatory - direct/indirect msg or both */
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400225 uint16_t messaging_method;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000226 /** mandatory - action in response to non secure interrupt */
227 uint8_t ns_interrupts_action;
228 /** optional - managed exit signaled through vIRQ */
229 bool me_signal_virq;
230 /** optional - receipt of notifications. */
231 bool notification_support;
J-Alvesbb2703a2025-02-10 12:11:56 +0000232
233 /** optional - request the scheduler cycles to handle interrupts. */
234 struct sri_interrupts_policy sri_policy;
235
J-Alves7ec9d6e2023-02-28 16:39:56 +0000236 /**
Karl Meakin18694022024-08-02 13:59:25 +0100237 * optional - VM availability messages bitfield.
238 */
239 struct vm_availability_messages vm_availability_messages;
240
241 /**
J-Alves7ec9d6e2023-02-28 16:39:56 +0000242 * optional - power management messages bitfield.
243 *
244 * See [1] power-management-messages manifest field.
245 *
246 * The Hafnium supported combinations for a MP SP are:
247 * Bit 0 - relay PSCI cpu off message to the SP.
248 * Bit 3 - relay PSCI cpu on to the SP.
249 *
250 * [1]
251 * https://trustedfirmware-a.readthedocs.io/en/latest/components/ffa-manifest-binding.html#partition-properties
252 */
253 uint32_t power_management;
254 /** optional */
255 bool has_primary_scheduler;
256 /** optional - tuples SEPID/SMMUID/streamId */
257 uint32_t stream_ep_ids[1];
258
259 /** Memory regions */
260 uint16_t mem_region_count;
261 struct memory_region mem_regions[PARTITION_MAX_MEMORY_REGIONS];
262 /** Device regions */
263 uint16_t dev_region_count;
264 struct device_region dev_regions[PARTITION_MAX_DEVICE_REGIONS];
Madhukar Pappireddye032af52023-10-11 14:52:58 -0500265 /** DMA device count. */
266 uint8_t dma_device_count;
267
J-Alves7ec9d6e2023-02-28 16:39:56 +0000268 /** optional - action in response to Other-Secure interrupt */
269 uint8_t other_s_interrupts_action;
270};