blob: 8254a70f3bb5f52ca89ef4653b7dd5989ab33e2a [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
58/**
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -050059 * Properties of the DMA capable device upstream of an SMMU as specified in the
60 * memory region description of the partition manifest.
61 */
62struct dma_device_properties {
63 /** SMMU ID - optional */
64 uint32_t smmu_id;
65 /** IMPDEF id tracking DMA peripheral device - optional */
66 uint8_t dma_device_id;
67 /** Count of Stream IDs assigned to device - optional */
68 uint8_t stream_count;
69 /** List of Stream IDs assigned to device - optional */
70 uint32_t stream_ids[PARTITION_MAX_STREAMS_PER_DEVICE];
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -050071};
72
73/**
74 * Partition Memory region as described in FFA v1.2 spec, Table 5.2 along with
75 * an implementation defined struct to track the properties of a DMA capable
76 * device that has access to this memory region.
J-Alves7ec9d6e2023-02-28 16:39:56 +000077 */
78struct memory_region {
Karl Meakinfb761eb2024-11-20 15:59:56 +000079 struct string description;
J-Alves7ec9d6e2023-02-28 16:39:56 +000080 /**
81 * Specify PA, VA for S-EL0 partitions or IPA
82 * for S-EL1 partitions - optional.
83 */
84 uintptr_t base_address;
Karl Meakin6291eb22024-11-18 12:43:47 +000085 /** True if `load-address-relative-offset` was specified. */
86 bool is_relative;
J-Alves7ec9d6e2023-02-28 16:39:56 +000087 /** Page count - mandatory */
88 uint32_t page_count;
89 /** Memory attributes - mandatory */
90 uint32_t attributes;
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -050091 /** DMA device properties - optional */
92 struct dma_device_properties dma_prop;
Madhukar Pappireddy9c764b32024-06-20 14:36:55 -050093 /** Instruction and data access permissions for DMA device - optional */
94 uint32_t dma_access_permissions;
J-Alves7ec9d6e2023-02-28 16:39:56 +000095};
96
Daniel Boulby18485942024-10-14 16:23:03 +010097/**
98 * Interrupts attibutes encoding in the manifest:
99 * Field Bit(s)
100 * ---------------------------
101 * Priority 7:0
102 * Security_State 8
103 * Config(Edge/Level) 9
104 * Type(SPI/PPI/SGI) 11:10
105 * Reserved 31:12
106 */
107#define INT_INFO_ATTR_PRIORITY_SHIFT 0
108#define INT_INFO_ATTR_SEC_STATE_SHIFT 8
109#define INT_INFO_ATTR_CONFIG_SHIFT 9
110#define INT_INFO_ATTR_TYPE_SHIFT 10
111
J-Alves7ec9d6e2023-02-28 16:39:56 +0000112struct interrupt_info {
113 uint32_t id;
114 uint32_t attributes;
115 bool mpidr_valid;
116 uint64_t mpidr;
117};
118
119/**
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -0500120 * Partition Device region as described in FFA v1.2 spec, Table 5.3 along with
121 * few implementation defined fields.
J-Alves7ec9d6e2023-02-28 16:39:56 +0000122 */
123struct device_region {
124 /** Device base PA - mandatory */
125 uintptr_t base_address;
126 /** Page count - mandatory */
127 uint32_t page_count;
128 /** Memory attributes - mandatory */
129 uint32_t attributes;
130 /** List of physical interrupt ID's and their attributes - optional */
131 struct interrupt_info interrupts[PARTITION_MAX_INTERRUPTS_PER_DEVICE];
132 /** Count of physical interrupts - optional */
133 uint8_t interrupt_count;
Madhukar Pappireddy9c764b32024-06-20 14:36:55 -0500134 /** DMA device properties - optional */
135 struct dma_device_properties dma_prop;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000136 /** Exclusive access to an endpoint - optional */
137 bool exclusive_access;
138 /** Name of Device region - optional */
139 struct string name;
140};
141
142/**
143 * RX/TX buffer, reference to memory-region entries that describe RX/TX
144 * buffers in partition manifest.
145 */
146struct rx_tx {
147 bool available;
148 uint32_t rx_phandle;
149 uint32_t tx_phandle;
150 struct memory_region *rx_buffer;
151 struct memory_region *tx_buffer;
152};
153
Karl Meakin18694022024-08-02 13:59:25 +0100154struct vm_availability_messages {
155 bool vm_created : 1;
156 bool vm_destroyed : 1;
157 uint32_t mbz : 30;
158};
159
160static_assert(sizeof(struct vm_availability_messages) == sizeof(uint32_t),
161 "vm_availability_messages must have same size as uint32_t");
162
J-Alves7ec9d6e2023-02-28 16:39:56 +0000163/**
164 * Partition manifest as described in FF-A v1.0 spec section 3.1
165 */
166struct ffa_partition_manifest {
167 /** FF-A expected version - mandatory */
Karl Meakin0e617d92024-04-05 12:55:22 +0100168 enum ffa_version ffa_version;
Kathleen Capella422b10b2023-06-30 18:28:27 -0400169 /** UUID - at least one UUID mandatory */
170 uint16_t uuid_count;
171 struct ffa_uuid uuids[PARTITION_MAX_UUIDS];
J-Alves7ec9d6e2023-02-28 16:39:56 +0000172 /** Partition id - optional */
J-Alves19e20cf2023-08-02 12:48:55 +0100173 ffa_id_t id;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000174 /** Aux ids for mem transactions - optional */
J-Alves19e20cf2023-08-02 12:48:55 +0100175 ffa_id_t aux_id;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000176
177 /* NOTE: optional name field maps to VM debug_name field */
178
179 /** mandatory */
180 ffa_vcpu_count_t execution_ctx_count;
181 /** EL1 or secure EL1, secure EL0 - mandatory */
182 enum run_time_el run_time_el;
183 /** AArch32 / AArch64 - mandatory */
184 enum execution_state execution_state;
185 /** optional */
186 uintpaddr_t load_addr;
187 /** optional */
188 size_t ep_offset;
189 /** 4/16/64KB - optional */
190 enum xlat_granule xlat_granule;
191 /** Register id from w0/x0-w3/x3 - optional. */
192 uint32_t gp_register_num;
193 /**
194 * Flags the presence of the optional IMPDEF node to define Partition's
195 * Boot Info.
196 */
197 bool boot_info;
198 /** optional */
199 uint16_t boot_order;
200
201 /** Optional RX/TX buffers */
202 struct rx_tx rxtx;
203
204 /** mandatory - direct/indirect msg or both */
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400205 uint16_t messaging_method;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000206 /** mandatory - action in response to non secure interrupt */
207 uint8_t ns_interrupts_action;
208 /** optional - managed exit signaled through vIRQ */
209 bool me_signal_virq;
210 /** optional - receipt of notifications. */
211 bool notification_support;
212 /**
Karl Meakin18694022024-08-02 13:59:25 +0100213 * optional - VM availability messages bitfield.
214 */
215 struct vm_availability_messages vm_availability_messages;
216
217 /**
J-Alves7ec9d6e2023-02-28 16:39:56 +0000218 * optional - power management messages bitfield.
219 *
220 * See [1] power-management-messages manifest field.
221 *
222 * The Hafnium supported combinations for a MP SP are:
223 * Bit 0 - relay PSCI cpu off message to the SP.
224 * Bit 3 - relay PSCI cpu on to the SP.
225 *
226 * [1]
227 * https://trustedfirmware-a.readthedocs.io/en/latest/components/ffa-manifest-binding.html#partition-properties
228 */
229 uint32_t power_management;
230 /** optional */
231 bool has_primary_scheduler;
232 /** optional - tuples SEPID/SMMUID/streamId */
233 uint32_t stream_ep_ids[1];
234
235 /** Memory regions */
236 uint16_t mem_region_count;
237 struct memory_region mem_regions[PARTITION_MAX_MEMORY_REGIONS];
238 /** Device regions */
239 uint16_t dev_region_count;
240 struct device_region dev_regions[PARTITION_MAX_DEVICE_REGIONS];
Madhukar Pappireddye032af52023-10-11 14:52:58 -0500241 /** DMA device count. */
242 uint8_t dma_device_count;
243
J-Alves7ec9d6e2023-02-28 16:39:56 +0000244 /** optional - action in response to Other-Secure interrupt */
245 uint8_t other_s_interrupts_action;
246};