blob: 5005d8c78729b3c52e702875bc355ddb1b56bbf7 [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)
36#define MANIFEST_POWER_MANAGEMENT_CPU_ON_SUPPORTED (UINT32_C(1) << 3)
37#define MANIFEST_POWER_MANAGEMENT_NONE_MASK (UINT32_C(0))
38#define MANIFEST_POWER_MANAGEMENT_ALL_MASK \
39 (MANIFEST_POWER_MANAGEMENT_CPU_OFF_SUPPORTED | \
40 MANIFEST_POWER_MANAGEMENT_CPU_ON_SUPPORTED)
41
42/* Highest possible value for the boot-order field. */
43#define DEFAULT_BOOT_ORDER 0xFFFF
44#define DEFAULT_BOOT_GP_REGISTER UINT32_C(-1)
45
46enum run_time_el {
47 EL1 = 0,
48 S_EL0,
49 S_EL1,
50 SUPERVISOR_MODE,
51 SECURE_USER_MODE,
Daniel Boulby874d5432023-04-27 12:40:24 +010052 SECURE_SUPERVISOR_MODE,
53 EL0
J-Alves7ec9d6e2023-02-28 16:39:56 +000054};
55
56enum execution_state { AARCH64 = 0, AARCH32 };
57
58enum xlat_granule { PAGE_4KB = 0, PAGE_16KB, PAGE_64KB };
59
60/**
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -050061 * Properties of the DMA capable device upstream of an SMMU as specified in the
62 * memory region description of the partition manifest.
63 */
64struct dma_device_properties {
65 /** SMMU ID - optional */
66 uint32_t smmu_id;
67 /** IMPDEF id tracking DMA peripheral device - optional */
68 uint8_t dma_device_id;
69 /** Count of Stream IDs assigned to device - optional */
70 uint8_t stream_count;
71 /** List of Stream IDs assigned to device - optional */
72 uint32_t stream_ids[PARTITION_MAX_STREAMS_PER_DEVICE];
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -050073};
74
75/**
76 * Partition Memory region as described in FFA v1.2 spec, Table 5.2 along with
77 * an implementation defined struct to track the properties of a DMA capable
78 * device that has access to this memory region.
J-Alves7ec9d6e2023-02-28 16:39:56 +000079 */
80struct memory_region {
81 struct string name;
82 /**
83 * Specify PA, VA for S-EL0 partitions or IPA
84 * for S-EL1 partitions - optional.
85 */
86 uintptr_t base_address;
Karl Meakin6291eb22024-11-18 12:43:47 +000087 /** True if `load-address-relative-offset` was specified. */
88 bool is_relative;
J-Alves7ec9d6e2023-02-28 16:39:56 +000089 /** Page count - mandatory */
90 uint32_t page_count;
91 /** Memory attributes - mandatory */
92 uint32_t attributes;
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -050093 /** DMA device properties - optional */
94 struct dma_device_properties dma_prop;
Madhukar Pappireddy9c764b32024-06-20 14:36:55 -050095 /** Instruction and data access permissions for DMA device - optional */
96 uint32_t dma_access_permissions;
J-Alves7ec9d6e2023-02-28 16:39:56 +000097};
98
Daniel Boulby18485942024-10-14 16:23:03 +010099/**
100 * Interrupts attibutes encoding in the manifest:
101 * Field Bit(s)
102 * ---------------------------
103 * Priority 7:0
104 * Security_State 8
105 * Config(Edge/Level) 9
106 * Type(SPI/PPI/SGI) 11:10
107 * Reserved 31:12
108 */
109#define INT_INFO_ATTR_PRIORITY_SHIFT 0
110#define INT_INFO_ATTR_SEC_STATE_SHIFT 8
111#define INT_INFO_ATTR_CONFIG_SHIFT 9
112#define INT_INFO_ATTR_TYPE_SHIFT 10
113
J-Alves7ec9d6e2023-02-28 16:39:56 +0000114struct interrupt_info {
115 uint32_t id;
116 uint32_t attributes;
117 bool mpidr_valid;
118 uint64_t mpidr;
119};
120
121/**
Madhukar Pappireddy3c2b7912023-10-11 14:47:27 -0500122 * Partition Device region as described in FFA v1.2 spec, Table 5.3 along with
123 * few implementation defined fields.
J-Alves7ec9d6e2023-02-28 16:39:56 +0000124 */
125struct device_region {
126 /** Device base PA - mandatory */
127 uintptr_t base_address;
128 /** Page count - mandatory */
129 uint32_t page_count;
130 /** Memory attributes - mandatory */
131 uint32_t attributes;
132 /** List of physical interrupt ID's and their attributes - optional */
133 struct interrupt_info interrupts[PARTITION_MAX_INTERRUPTS_PER_DEVICE];
134 /** Count of physical interrupts - optional */
135 uint8_t interrupt_count;
Madhukar Pappireddy9c764b32024-06-20 14:36:55 -0500136 /** DMA device properties - optional */
137 struct dma_device_properties dma_prop;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000138 /** Exclusive access to an endpoint - optional */
139 bool exclusive_access;
140 /** Name of Device region - optional */
141 struct string name;
142};
143
144/**
145 * RX/TX buffer, reference to memory-region entries that describe RX/TX
146 * buffers in partition manifest.
147 */
148struct rx_tx {
149 bool available;
150 uint32_t rx_phandle;
151 uint32_t tx_phandle;
152 struct memory_region *rx_buffer;
153 struct memory_region *tx_buffer;
154};
155
Karl Meakin18694022024-08-02 13:59:25 +0100156struct vm_availability_messages {
157 bool vm_created : 1;
158 bool vm_destroyed : 1;
159 uint32_t mbz : 30;
160};
161
162static_assert(sizeof(struct vm_availability_messages) == sizeof(uint32_t),
163 "vm_availability_messages must have same size as uint32_t");
164
J-Alves7ec9d6e2023-02-28 16:39:56 +0000165/**
166 * Partition manifest as described in FF-A v1.0 spec section 3.1
167 */
168struct ffa_partition_manifest {
169 /** FF-A expected version - mandatory */
Karl Meakin0e617d92024-04-05 12:55:22 +0100170 enum ffa_version ffa_version;
Kathleen Capella422b10b2023-06-30 18:28:27 -0400171 /** UUID - at least one UUID mandatory */
172 uint16_t uuid_count;
173 struct ffa_uuid uuids[PARTITION_MAX_UUIDS];
J-Alves7ec9d6e2023-02-28 16:39:56 +0000174 /** Partition id - optional */
J-Alves19e20cf2023-08-02 12:48:55 +0100175 ffa_id_t id;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000176 /** Aux ids for mem transactions - optional */
J-Alves19e20cf2023-08-02 12:48:55 +0100177 ffa_id_t aux_id;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000178
179 /* NOTE: optional name field maps to VM debug_name field */
180
181 /** mandatory */
182 ffa_vcpu_count_t execution_ctx_count;
183 /** EL1 or secure EL1, secure EL0 - mandatory */
184 enum run_time_el run_time_el;
185 /** AArch32 / AArch64 - mandatory */
186 enum execution_state execution_state;
187 /** optional */
188 uintpaddr_t load_addr;
189 /** optional */
190 size_t ep_offset;
191 /** 4/16/64KB - optional */
192 enum xlat_granule xlat_granule;
193 /** Register id from w0/x0-w3/x3 - optional. */
194 uint32_t gp_register_num;
195 /**
196 * Flags the presence of the optional IMPDEF node to define Partition's
197 * Boot Info.
198 */
199 bool boot_info;
200 /** optional */
201 uint16_t boot_order;
202
203 /** Optional RX/TX buffers */
204 struct rx_tx rxtx;
205
206 /** mandatory - direct/indirect msg or both */
Kathleen Capellaf71dee42023-08-08 16:24:14 -0400207 uint16_t messaging_method;
J-Alves7ec9d6e2023-02-28 16:39:56 +0000208 /** mandatory - action in response to non secure interrupt */
209 uint8_t ns_interrupts_action;
210 /** optional - managed exit signaled through vIRQ */
211 bool me_signal_virq;
212 /** optional - receipt of notifications. */
213 bool notification_support;
214 /**
Karl Meakin18694022024-08-02 13:59:25 +0100215 * optional - VM availability messages bitfield.
216 */
217 struct vm_availability_messages vm_availability_messages;
218
219 /**
J-Alves7ec9d6e2023-02-28 16:39:56 +0000220 * optional - power management messages bitfield.
221 *
222 * See [1] power-management-messages manifest field.
223 *
224 * The Hafnium supported combinations for a MP SP are:
225 * Bit 0 - relay PSCI cpu off message to the SP.
226 * Bit 3 - relay PSCI cpu on to the SP.
227 *
228 * [1]
229 * https://trustedfirmware-a.readthedocs.io/en/latest/components/ffa-manifest-binding.html#partition-properties
230 */
231 uint32_t power_management;
232 /** optional */
233 bool has_primary_scheduler;
234 /** optional - tuples SEPID/SMMUID/streamId */
235 uint32_t stream_ep_ids[1];
236
237 /** Memory regions */
238 uint16_t mem_region_count;
239 struct memory_region mem_regions[PARTITION_MAX_MEMORY_REGIONS];
240 /** Device regions */
241 uint16_t dev_region_count;
242 struct device_region dev_regions[PARTITION_MAX_DEVICE_REGIONS];
Madhukar Pappireddye032af52023-10-11 14:52:58 -0500243 /** DMA device count. */
244 uint8_t dma_device_count;
245
J-Alves7ec9d6e2023-02-28 16:39:56 +0000246 /** optional - action in response to Other-Secure interrupt */
247 uint8_t other_s_interrupts_action;
248};