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) |
| 35 | #define MANIFEST_POWER_MANAGEMENT_CPU_ON_SUPPORTED (UINT32_C(1) << 3) |
| 36 | #define MANIFEST_POWER_MANAGEMENT_NONE_MASK (UINT32_C(0)) |
| 37 | #define MANIFEST_POWER_MANAGEMENT_ALL_MASK \ |
| 38 | (MANIFEST_POWER_MANAGEMENT_CPU_OFF_SUPPORTED | \ |
| 39 | MANIFEST_POWER_MANAGEMENT_CPU_ON_SUPPORTED) |
| 40 | |
| 41 | /* Highest possible value for the boot-order field. */ |
| 42 | #define DEFAULT_BOOT_ORDER 0xFFFF |
| 43 | #define DEFAULT_BOOT_GP_REGISTER UINT32_C(-1) |
| 44 | |
| 45 | enum run_time_el { |
| 46 | EL1 = 0, |
| 47 | S_EL0, |
| 48 | S_EL1, |
| 49 | SUPERVISOR_MODE, |
| 50 | SECURE_USER_MODE, |
Daniel Boulby | 874d543 | 2023-04-27 12:40:24 +0100 | [diff] [blame] | 51 | SECURE_SUPERVISOR_MODE, |
| 52 | EL0 |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | enum execution_state { AARCH64 = 0, AARCH32 }; |
| 56 | |
| 57 | enum xlat_granule { PAGE_4KB = 0, PAGE_16KB, PAGE_64KB }; |
| 58 | |
| 59 | /** |
Madhukar Pappireddy | 3c2b791 | 2023-10-11 14:47:27 -0500 | [diff] [blame] | 60 | * Properties of the DMA capable device upstream of an SMMU as specified in the |
| 61 | * memory region description of the partition manifest. |
| 62 | */ |
| 63 | struct dma_device_properties { |
| 64 | /** SMMU ID - optional */ |
| 65 | uint32_t smmu_id; |
| 66 | /** IMPDEF id tracking DMA peripheral device - optional */ |
| 67 | uint8_t dma_device_id; |
| 68 | /** Count of Stream IDs assigned to device - optional */ |
| 69 | uint8_t stream_count; |
| 70 | /** List of Stream IDs assigned to device - optional */ |
| 71 | uint32_t stream_ids[PARTITION_MAX_STREAMS_PER_DEVICE]; |
Madhukar Pappireddy | 3c2b791 | 2023-10-11 14:47:27 -0500 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | /** |
| 75 | * Partition Memory region as described in FFA v1.2 spec, Table 5.2 along with |
| 76 | * an implementation defined struct to track the properties of a DMA capable |
| 77 | * device that has access to this memory region. |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 78 | */ |
| 79 | struct memory_region { |
| 80 | struct string name; |
| 81 | /** |
| 82 | * Specify PA, VA for S-EL0 partitions or IPA |
| 83 | * for S-EL1 partitions - optional. |
| 84 | */ |
| 85 | uintptr_t base_address; |
| 86 | /** Page count - mandatory */ |
| 87 | uint32_t page_count; |
| 88 | /** Memory attributes - mandatory */ |
| 89 | uint32_t attributes; |
Madhukar Pappireddy | 3c2b791 | 2023-10-11 14:47:27 -0500 | [diff] [blame] | 90 | /** DMA device properties - optional */ |
| 91 | struct dma_device_properties dma_prop; |
Madhukar Pappireddy | 9c764b3 | 2024-06-20 14:36:55 -0500 | [diff] [blame] | 92 | /** Instruction and data access permissions for DMA device - optional */ |
| 93 | uint32_t dma_access_permissions; |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | struct interrupt_info { |
| 97 | uint32_t id; |
| 98 | uint32_t attributes; |
| 99 | bool mpidr_valid; |
| 100 | uint64_t mpidr; |
| 101 | }; |
| 102 | |
| 103 | /** |
Madhukar Pappireddy | 3c2b791 | 2023-10-11 14:47:27 -0500 | [diff] [blame] | 104 | * Partition Device region as described in FFA v1.2 spec, Table 5.3 along with |
| 105 | * few implementation defined fields. |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 106 | */ |
| 107 | struct device_region { |
| 108 | /** Device base PA - mandatory */ |
| 109 | uintptr_t base_address; |
| 110 | /** Page count - mandatory */ |
| 111 | uint32_t page_count; |
| 112 | /** Memory attributes - mandatory */ |
| 113 | uint32_t attributes; |
| 114 | /** List of physical interrupt ID's and their attributes - optional */ |
| 115 | struct interrupt_info interrupts[PARTITION_MAX_INTERRUPTS_PER_DEVICE]; |
| 116 | /** Count of physical interrupts - optional */ |
| 117 | uint8_t interrupt_count; |
Madhukar Pappireddy | 9c764b3 | 2024-06-20 14:36:55 -0500 | [diff] [blame] | 118 | /** DMA device properties - optional */ |
| 119 | struct dma_device_properties dma_prop; |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 120 | /** Exclusive access to an endpoint - optional */ |
| 121 | bool exclusive_access; |
| 122 | /** Name of Device region - optional */ |
| 123 | struct string name; |
| 124 | }; |
| 125 | |
| 126 | /** |
| 127 | * RX/TX buffer, reference to memory-region entries that describe RX/TX |
| 128 | * buffers in partition manifest. |
| 129 | */ |
| 130 | struct rx_tx { |
| 131 | bool available; |
| 132 | uint32_t rx_phandle; |
| 133 | uint32_t tx_phandle; |
| 134 | struct memory_region *rx_buffer; |
| 135 | struct memory_region *tx_buffer; |
| 136 | }; |
| 137 | |
| 138 | /** |
| 139 | * Partition manifest as described in FF-A v1.0 spec section 3.1 |
| 140 | */ |
| 141 | struct ffa_partition_manifest { |
| 142 | /** FF-A expected version - mandatory */ |
Karl Meakin | 0e617d9 | 2024-04-05 12:55:22 +0100 | [diff] [blame] | 143 | enum ffa_version ffa_version; |
Kathleen Capella | 422b10b | 2023-06-30 18:28:27 -0400 | [diff] [blame] | 144 | /** UUID - at least one UUID mandatory */ |
| 145 | uint16_t uuid_count; |
| 146 | struct ffa_uuid uuids[PARTITION_MAX_UUIDS]; |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 147 | /** Partition id - optional */ |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 148 | ffa_id_t id; |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 149 | /** Aux ids for mem transactions - optional */ |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 150 | ffa_id_t aux_id; |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 151 | |
| 152 | /* NOTE: optional name field maps to VM debug_name field */ |
| 153 | |
| 154 | /** mandatory */ |
| 155 | ffa_vcpu_count_t execution_ctx_count; |
| 156 | /** EL1 or secure EL1, secure EL0 - mandatory */ |
| 157 | enum run_time_el run_time_el; |
| 158 | /** AArch32 / AArch64 - mandatory */ |
| 159 | enum execution_state execution_state; |
| 160 | /** optional */ |
| 161 | uintpaddr_t load_addr; |
| 162 | /** optional */ |
| 163 | size_t ep_offset; |
| 164 | /** 4/16/64KB - optional */ |
| 165 | enum xlat_granule xlat_granule; |
| 166 | /** Register id from w0/x0-w3/x3 - optional. */ |
| 167 | uint32_t gp_register_num; |
| 168 | /** |
| 169 | * Flags the presence of the optional IMPDEF node to define Partition's |
| 170 | * Boot Info. |
| 171 | */ |
| 172 | bool boot_info; |
| 173 | /** optional */ |
| 174 | uint16_t boot_order; |
| 175 | |
| 176 | /** Optional RX/TX buffers */ |
| 177 | struct rx_tx rxtx; |
| 178 | |
| 179 | /** mandatory - direct/indirect msg or both */ |
Kathleen Capella | f71dee4 | 2023-08-08 16:24:14 -0400 | [diff] [blame] | 180 | uint16_t messaging_method; |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 181 | /** mandatory - action in response to non secure interrupt */ |
| 182 | uint8_t ns_interrupts_action; |
| 183 | /** optional - managed exit signaled through vIRQ */ |
| 184 | bool me_signal_virq; |
| 185 | /** optional - receipt of notifications. */ |
| 186 | bool notification_support; |
| 187 | /** |
| 188 | * optional - power management messages bitfield. |
| 189 | * |
| 190 | * See [1] power-management-messages manifest field. |
| 191 | * |
| 192 | * The Hafnium supported combinations for a MP SP are: |
| 193 | * Bit 0 - relay PSCI cpu off message to the SP. |
| 194 | * Bit 3 - relay PSCI cpu on to the SP. |
| 195 | * |
| 196 | * [1] |
| 197 | * https://trustedfirmware-a.readthedocs.io/en/latest/components/ffa-manifest-binding.html#partition-properties |
| 198 | */ |
| 199 | uint32_t power_management; |
| 200 | /** optional */ |
| 201 | bool has_primary_scheduler; |
| 202 | /** optional - tuples SEPID/SMMUID/streamId */ |
| 203 | uint32_t stream_ep_ids[1]; |
| 204 | |
| 205 | /** Memory regions */ |
| 206 | uint16_t mem_region_count; |
| 207 | struct memory_region mem_regions[PARTITION_MAX_MEMORY_REGIONS]; |
| 208 | /** Device regions */ |
| 209 | uint16_t dev_region_count; |
| 210 | struct device_region dev_regions[PARTITION_MAX_DEVICE_REGIONS]; |
Madhukar Pappireddy | e032af5 | 2023-10-11 14:52:58 -0500 | [diff] [blame] | 211 | /** DMA device count. */ |
| 212 | uint8_t dma_device_count; |
| 213 | |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 214 | /** optional - action in response to Other-Secure interrupt */ |
| 215 | uint8_t other_s_interrupts_action; |
| 216 | }; |