J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 1 | /* |
| 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 Deprez | 058ddee | 2024-08-27 09:22:11 +0200 | [diff] [blame] | 30 | #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-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 33 | |
| 34 | #define MANIFEST_POWER_MANAGEMENT_CPU_OFF_SUPPORTED (UINT32_C(1) << 0) |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 35 | #define MANIFEST_POWER_MANAGEMENT_NONE_MASK (UINT32_C(0)) |
Madhukar Pappireddy | 958c841 | 2024-11-25 09:54:17 -0600 | [diff] [blame] | 36 | #define MANIFEST_POWER_MANAGEMENT_ALL_MASK \ |
| 37 | MANIFEST_POWER_MANAGEMENT_CPU_OFF_SUPPORTED |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 38 | |
| 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 | |
| 43 | enum run_time_el { |
| 44 | EL1 = 0, |
| 45 | S_EL0, |
| 46 | S_EL1, |
| 47 | SUPERVISOR_MODE, |
| 48 | SECURE_USER_MODE, |
Daniel Boulby | 874d543 | 2023-04-27 12:40:24 +0100 | [diff] [blame] | 49 | SECURE_SUPERVISOR_MODE, |
| 50 | EL0 |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | enum execution_state { AARCH64 = 0, AARCH32 }; |
| 54 | |
| 55 | enum xlat_granule { PAGE_4KB = 0, PAGE_16KB, PAGE_64KB }; |
| 56 | |
J-Alves | bb2703a | 2025-02-10 12:11:56 +0000 | [diff] [blame] | 57 | struct 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-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 78 | /** |
Madhukar Pappireddy | 3c2b791 | 2023-10-11 14:47:27 -0500 | [diff] [blame] | 79 | * Properties of the DMA capable device upstream of an SMMU as specified in the |
| 80 | * memory region description of the partition manifest. |
| 81 | */ |
| 82 | struct 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 Pappireddy | 3c2b791 | 2023-10-11 14:47:27 -0500 | [diff] [blame] | 91 | }; |
| 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-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 97 | */ |
| 98 | struct memory_region { |
Karl Meakin | fb761eb | 2024-11-20 15:59:56 +0000 | [diff] [blame] | 99 | struct string description; |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 100 | /** |
| 101 | * Specify PA, VA for S-EL0 partitions or IPA |
| 102 | * for S-EL1 partitions - optional. |
| 103 | */ |
| 104 | uintptr_t base_address; |
Karl Meakin | 6291eb2 | 2024-11-18 12:43:47 +0000 | [diff] [blame] | 105 | /** True if `load-address-relative-offset` was specified. */ |
| 106 | bool is_relative; |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 107 | /** Page count - mandatory */ |
| 108 | uint32_t page_count; |
| 109 | /** Memory attributes - mandatory */ |
| 110 | uint32_t attributes; |
Madhukar Pappireddy | 3c2b791 | 2023-10-11 14:47:27 -0500 | [diff] [blame] | 111 | /** DMA device properties - optional */ |
| 112 | struct dma_device_properties dma_prop; |
Madhukar Pappireddy | 9c764b3 | 2024-06-20 14:36:55 -0500 | [diff] [blame] | 113 | /** Instruction and data access permissions for DMA device - optional */ |
| 114 | uint32_t dma_access_permissions; |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
Daniel Boulby | 1848594 | 2024-10-14 16:23:03 +0100 | [diff] [blame] | 117 | /** |
| 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-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 132 | struct interrupt_info { |
| 133 | uint32_t id; |
| 134 | uint32_t attributes; |
| 135 | bool mpidr_valid; |
| 136 | uint64_t mpidr; |
| 137 | }; |
| 138 | |
| 139 | /** |
Madhukar Pappireddy | 3c2b791 | 2023-10-11 14:47:27 -0500 | [diff] [blame] | 140 | * Partition Device region as described in FFA v1.2 spec, Table 5.3 along with |
| 141 | * few implementation defined fields. |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 142 | */ |
| 143 | struct 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 Pappireddy | 9c764b3 | 2024-06-20 14:36:55 -0500 | [diff] [blame] | 154 | /** DMA device properties - optional */ |
| 155 | struct dma_device_properties dma_prop; |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 156 | /** 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 | */ |
| 166 | struct 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 Meakin | 1869402 | 2024-08-02 13:59:25 +0100 | [diff] [blame] | 174 | struct vm_availability_messages { |
| 175 | bool vm_created : 1; |
| 176 | bool vm_destroyed : 1; |
| 177 | uint32_t mbz : 30; |
| 178 | }; |
| 179 | |
| 180 | static_assert(sizeof(struct vm_availability_messages) == sizeof(uint32_t), |
| 181 | "vm_availability_messages must have same size as uint32_t"); |
| 182 | |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 183 | /** |
| 184 | * Partition manifest as described in FF-A v1.0 spec section 3.1 |
| 185 | */ |
| 186 | struct ffa_partition_manifest { |
| 187 | /** FF-A expected version - mandatory */ |
Karl Meakin | 0e617d9 | 2024-04-05 12:55:22 +0100 | [diff] [blame] | 188 | enum ffa_version ffa_version; |
Kathleen Capella | 422b10b | 2023-06-30 18:28:27 -0400 | [diff] [blame] | 189 | /** UUID - at least one UUID mandatory */ |
| 190 | uint16_t uuid_count; |
| 191 | struct ffa_uuid uuids[PARTITION_MAX_UUIDS]; |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 192 | /** Partition id - optional */ |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 193 | ffa_id_t id; |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 194 | /** Aux ids for mem transactions - optional */ |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 195 | ffa_id_t aux_id; |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 196 | |
| 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 Capella | f71dee4 | 2023-08-08 16:24:14 -0400 | [diff] [blame] | 225 | uint16_t messaging_method; |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 226 | /** 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-Alves | bb2703a | 2025-02-10 12:11:56 +0000 | [diff] [blame] | 232 | |
| 233 | /** optional - request the scheduler cycles to handle interrupts. */ |
| 234 | struct sri_interrupts_policy sri_policy; |
| 235 | |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 236 | /** |
Karl Meakin | 1869402 | 2024-08-02 13:59:25 +0100 | [diff] [blame] | 237 | * optional - VM availability messages bitfield. |
| 238 | */ |
| 239 | struct vm_availability_messages vm_availability_messages; |
| 240 | |
| 241 | /** |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 242 | * 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 Pappireddy | e032af5 | 2023-10-11 14:52:58 -0500 | [diff] [blame] | 265 | /** DMA device count. */ |
| 266 | uint8_t dma_device_count; |
| 267 | |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 268 | /** optional - action in response to Other-Secure interrupt */ |
| 269 | uint8_t other_s_interrupts_action; |
| 270 | }; |