David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Hafnium Authors. |
| 3 | * |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 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. |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #pragma once |
| 10 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 11 | #include "hf/addr.h" |
Raghu Krishnamurthy | b49549e | 2021-07-02 08:27:38 -0700 | [diff] [blame] | 12 | #include "hf/fdt.h" |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 13 | #include "hf/ffa.h" |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 14 | #include "hf/memiter.h" |
David Brazdil | 136f294 | 2019-09-23 14:11:03 +0100 | [diff] [blame] | 15 | #include "hf/string.h" |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 16 | #include "hf/vm.h" |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 17 | |
David Brazdil | 080ee31 | 2020-02-25 15:30:30 -0800 | [diff] [blame] | 18 | #define MANIFEST_INVALID_ADDRESS UINT64_MAX |
Madhukar Pappireddy | 54680c7 | 2020-10-23 15:02:38 -0500 | [diff] [blame] | 19 | #define MANIFEST_INVALID_ID UINT32_MAX |
David Brazdil | 080ee31 | 2020-02-25 15:30:30 -0800 | [diff] [blame] | 20 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 21 | #define SP_RTX_BUF_NAME_SIZE 10 |
| 22 | |
Manish Pandey | 6542f5c | 2020-04-27 14:37:46 +0100 | [diff] [blame] | 23 | #define SP_MAX_MEMORY_REGIONS 8 |
Manish Pandey | e68e793 | 2020-04-23 15:29:28 +0100 | [diff] [blame] | 24 | #define SP_MAX_DEVICE_REGIONS 8 |
| 25 | #define SP_MAX_INTERRUPTS_PER_DEVICE 4 |
| 26 | #define SP_MAX_STREAMS_PER_DEVICE 4 |
Manish Pandey | 6542f5c | 2020-04-27 14:37:46 +0100 | [diff] [blame] | 27 | |
| 28 | /** Mask for getting read/write/execute permission */ |
| 29 | #define MM_PERM_MASK 0x7 |
| 30 | |
J-Alves | beeb6dc | 2021-12-08 18:21:32 +0000 | [diff] [blame] | 31 | /* Highest possible value for the boot-order field. */ |
| 32 | #define DEFAULT_BOOT_ORDER 0xFFFF |
J-Alves | 3531578 | 2022-01-25 17:58:32 +0000 | [diff] [blame^] | 33 | #define DEFAULT_BOOT_GP_REGISTER UINT32_C(-1) |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 34 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 35 | enum run_time_el { |
| 36 | EL1 = 0, |
| 37 | S_EL0, |
| 38 | S_EL1, |
| 39 | SUPERVISOR_MODE, |
| 40 | SECURE_USER_MODE, |
| 41 | SECURE_SUPERVISOR_MODE |
| 42 | }; |
| 43 | |
| 44 | enum execution_state { AARCH64 = 0, AARCH32 }; |
| 45 | |
| 46 | enum xlat_granule { PAGE_4KB = 0, PAGE_16KB, PAGE_64KB }; |
| 47 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 48 | /** |
Olivier Deprez | c13a869 | 2022-04-08 17:47:14 +0200 | [diff] [blame] | 49 | * Partition Memory region as described in FFA v1.0 spec, Table 10 |
Manish Pandey | 6542f5c | 2020-04-27 14:37:46 +0100 | [diff] [blame] | 50 | */ |
| 51 | struct memory_region { |
| 52 | /** |
| 53 | * Specify PA, VA for S-EL0 partitions or IPA |
| 54 | * for S-EL1 partitions - optional. |
| 55 | */ |
| 56 | uintptr_t base_address; |
| 57 | /** Page count - mandatory */ |
| 58 | uint32_t page_count; |
| 59 | /** Memory attributes - mandatory */ |
| 60 | uint32_t attributes; |
| 61 | /** Name of memory region - optional */ |
| 62 | struct string name; |
| 63 | }; |
| 64 | |
Manish Pandey | e68e793 | 2020-04-23 15:29:28 +0100 | [diff] [blame] | 65 | struct interrupt { |
| 66 | uint32_t id; |
| 67 | uint32_t attributes; |
| 68 | }; |
| 69 | |
| 70 | /** |
Olivier Deprez | c13a869 | 2022-04-08 17:47:14 +0200 | [diff] [blame] | 71 | * Partition Device region as described in FFA v1.0 spec, Table 11 |
Manish Pandey | e68e793 | 2020-04-23 15:29:28 +0100 | [diff] [blame] | 72 | */ |
| 73 | struct device_region { |
| 74 | /** Device base PA - mandatory */ |
| 75 | uintptr_t base_address; |
| 76 | /** Page count - mandatory */ |
| 77 | uint32_t page_count; |
| 78 | /** Memory attributes - mandatory */ |
| 79 | uint32_t attributes; |
| 80 | /** List of physical interrupt ID's and their attributes - optional */ |
| 81 | struct interrupt interrupts[SP_MAX_INTERRUPTS_PER_DEVICE]; |
Madhukar Pappireddy | 5fc8be1 | 2021-08-03 11:42:53 -0500 | [diff] [blame] | 82 | /** Count of physical interrupts - optional */ |
| 83 | uint8_t interrupt_count; |
Manish Pandey | e68e793 | 2020-04-23 15:29:28 +0100 | [diff] [blame] | 84 | /** SMMU ID - optional */ |
| 85 | uint32_t smmu_id; |
Madhukar Pappireddy | 54680c7 | 2020-10-23 15:02:38 -0500 | [diff] [blame] | 86 | /** Count of Stream IDs assigned to device - optional */ |
| 87 | uint8_t stream_count; |
Manish Pandey | e68e793 | 2020-04-23 15:29:28 +0100 | [diff] [blame] | 88 | /** List of Stream IDs assigned to device - optional */ |
| 89 | uint32_t stream_ids[SP_MAX_STREAMS_PER_DEVICE]; |
| 90 | /** Exclusive access to an endpoint - optional */ |
| 91 | bool exclusive_access; |
| 92 | /** Name of Device region - optional */ |
| 93 | struct string name; |
| 94 | }; |
| 95 | |
Manish Pandey | 6542f5c | 2020-04-27 14:37:46 +0100 | [diff] [blame] | 96 | /** |
Manish Pandey | fa1f291 | 2020-05-05 12:57:01 +0100 | [diff] [blame] | 97 | * RX/TX buffer, reference to memory-region entries that describe RX/TX |
| 98 | * buffers in partition manifest. |
| 99 | */ |
| 100 | struct rx_tx { |
| 101 | bool available; |
| 102 | uint32_t rx_phandle; |
| 103 | uint32_t tx_phandle; |
| 104 | struct memory_region *rx_buffer; |
| 105 | struct memory_region *tx_buffer; |
| 106 | }; |
| 107 | |
| 108 | /** |
Olivier Deprez | c13a869 | 2022-04-08 17:47:14 +0200 | [diff] [blame] | 109 | * Partition manifest as described in FF-A v1.0 spec section 3.1 |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 110 | */ |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 111 | struct partition_manifest { |
Olivier Deprez | c13a869 | 2022-04-08 17:47:14 +0200 | [diff] [blame] | 112 | /** FF-A expected version - mandatory */ |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 113 | uint32_t ffa_version; |
| 114 | /** UUID - mandatory */ |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 115 | struct ffa_uuid uuid; |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 116 | /** Partition id - optional */ |
| 117 | ffa_vm_id_t id; |
| 118 | /** Aux ids for mem transactions - optional */ |
| 119 | ffa_vm_id_t aux_id; |
| 120 | |
| 121 | /* NOTE: optional name field maps to VM debug_name field */ |
| 122 | |
| 123 | /** mandatory */ |
| 124 | ffa_vcpu_count_t execution_ctx_count; |
| 125 | /** EL1 or secure EL1, secure EL0 - mandatory */ |
| 126 | enum run_time_el run_time_el; |
| 127 | /** AArch32 / AArch64 - mandatory */ |
| 128 | enum execution_state execution_state; |
| 129 | /** optional */ |
| 130 | uintpaddr_t load_addr; |
| 131 | /** optional */ |
| 132 | size_t ep_offset; |
J-Alves | 4369bd9 | 2020-08-07 16:35:36 +0100 | [diff] [blame] | 133 | /** 4/16/64KB - optional */ |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 134 | enum xlat_granule xlat_granule; |
J-Alves | 3531578 | 2022-01-25 17:58:32 +0000 | [diff] [blame^] | 135 | /** Register id from w0/x0-w3/x3 - optional. */ |
| 136 | uint32_t gp_register_num; |
| 137 | /** |
| 138 | * Flags the presence of the optional IMPDEF node to define Partition's |
| 139 | * Boot Info. |
| 140 | */ |
| 141 | bool boot_info; |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 142 | /** optional */ |
| 143 | uint16_t boot_order; |
| 144 | |
| 145 | /** Optional RX/TX buffers */ |
Manish Pandey | fa1f291 | 2020-05-05 12:57:01 +0100 | [diff] [blame] | 146 | struct rx_tx rxtx; |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 147 | |
| 148 | /** mandatory - direct/indirect msg or both */ |
Maksims Svecovs | b596eab | 2021-04-27 00:52:27 +0100 | [diff] [blame] | 149 | uint8_t messaging_method; |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 150 | /** optional */ |
Maksims Svecovs | 9ddf86a | 2021-05-06 17:17:21 +0100 | [diff] [blame] | 151 | bool managed_exit; |
J-Alves | a4730db | 2021-11-02 10:31:01 +0000 | [diff] [blame] | 152 | /** optional - receipt of notifications. */ |
| 153 | bool notification_support; |
Maksims Svecovs | 9ddf86a | 2021-05-06 17:17:21 +0100 | [diff] [blame] | 154 | /** optional */ |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 155 | bool has_primary_scheduler; |
| 156 | /** optional - preemptible / run to completion */ |
| 157 | uint8_t runtime_model; |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 158 | /** optional - tuples SEPID/SMMUID/streamId */ |
| 159 | uint32_t stream_ep_ids[1]; |
Manish Pandey | 6542f5c | 2020-04-27 14:37:46 +0100 | [diff] [blame] | 160 | |
| 161 | /** Memory regions */ |
Manish Pandey | 2145c21 | 2020-05-01 16:04:22 +0100 | [diff] [blame] | 162 | uint8_t mem_region_count; |
Manish Pandey | 6542f5c | 2020-04-27 14:37:46 +0100 | [diff] [blame] | 163 | struct memory_region mem_regions[SP_MAX_MEMORY_REGIONS]; |
Manish Pandey | e68e793 | 2020-04-23 15:29:28 +0100 | [diff] [blame] | 164 | /** Device regions */ |
Manish Pandey | 2145c21 | 2020-05-01 16:04:22 +0100 | [diff] [blame] | 165 | uint8_t dev_region_count; |
Manish Pandey | e68e793 | 2020-04-23 15:29:28 +0100 | [diff] [blame] | 166 | struct device_region dev_regions[SP_MAX_DEVICE_REGIONS]; |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | /** |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 170 | * Holds information about one of the VMs described in the manifest. |
| 171 | */ |
| 172 | struct manifest_vm { |
| 173 | /* Properties defined for both primary and secondary VMs. */ |
David Brazdil | 136f294 | 2019-09-23 14:11:03 +0100 | [diff] [blame] | 174 | struct string debug_name; |
| 175 | struct string kernel_filename; |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 176 | struct smc_whitelist smc_whitelist; |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 177 | bool is_ffa_partition; |
Raghu Krishnamurthy | b49549e | 2021-07-02 08:27:38 -0700 | [diff] [blame] | 178 | bool is_hyp_loaded; |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 179 | struct partition_manifest partition; |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 180 | |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 181 | union { |
| 182 | /* Properties specific to the primary VM. */ |
| 183 | struct { |
David Brazdil | 080ee31 | 2020-02-25 15:30:30 -0800 | [diff] [blame] | 184 | uint64_t boot_address; |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 185 | struct string ramdisk_filename; |
| 186 | } primary; |
| 187 | /* Properties specific to secondary VMs. */ |
| 188 | struct { |
| 189 | uint64_t mem_size; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 190 | ffa_vcpu_count_t vcpu_count; |
Fuad Tabba | 50469e0 | 2020-06-30 15:14:28 +0100 | [diff] [blame] | 191 | struct string fdt_filename; |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 192 | } secondary; |
| 193 | }; |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 194 | }; |
| 195 | |
| 196 | /** |
| 197 | * Hafnium manifest parsed from FDT. |
| 198 | */ |
| 199 | struct manifest { |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 200 | bool ffa_tee_enabled; |
| 201 | ffa_vm_count_t vm_count; |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 202 | struct manifest_vm vm[MAX_VMS]; |
| 203 | }; |
| 204 | |
| 205 | enum manifest_return_code { |
| 206 | MANIFEST_SUCCESS = 0, |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 207 | MANIFEST_ERROR_FILE_SIZE, |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 208 | MANIFEST_ERROR_MALFORMED_DTB, |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 209 | MANIFEST_ERROR_NO_ROOT_NODE, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 210 | MANIFEST_ERROR_NO_HYPERVISOR_FDT_NODE, |
David Brazdil | 74e9c3b | 2019-08-28 11:09:08 +0100 | [diff] [blame] | 211 | MANIFEST_ERROR_NOT_COMPATIBLE, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 212 | MANIFEST_ERROR_RESERVED_VM_ID, |
| 213 | MANIFEST_ERROR_NO_PRIMARY_VM, |
| 214 | MANIFEST_ERROR_TOO_MANY_VMS, |
| 215 | MANIFEST_ERROR_PROPERTY_NOT_FOUND, |
| 216 | MANIFEST_ERROR_MALFORMED_STRING, |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 217 | MANIFEST_ERROR_STRING_TOO_LONG, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 218 | MANIFEST_ERROR_MALFORMED_INTEGER, |
| 219 | MANIFEST_ERROR_INTEGER_OVERFLOW, |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 220 | MANIFEST_ERROR_MALFORMED_INTEGER_LIST, |
Andrew Scull | b2c3a24 | 2019-11-04 13:52:36 +0000 | [diff] [blame] | 221 | MANIFEST_ERROR_MALFORMED_BOOLEAN, |
J-Alves | 3531578 | 2022-01-25 17:58:32 +0000 | [diff] [blame^] | 222 | MANIFEST_ERROR_ARGUMENTS_LIST_EMPTY, |
Manish Pandey | 6542f5c | 2020-04-27 14:37:46 +0100 | [diff] [blame] | 223 | MANIFEST_ERROR_MEMORY_REGION_NODE_EMPTY, |
Manish Pandey | e68e793 | 2020-04-23 15:29:28 +0100 | [diff] [blame] | 224 | MANIFEST_ERROR_DEVICE_REGION_NODE_EMPTY, |
Manish Pandey | f06c907 | 2020-09-29 15:41:58 +0100 | [diff] [blame] | 225 | MANIFEST_ERROR_RXTX_SIZE_MISMATCH, |
Raghu Krishnamurthy | 384693c | 2021-10-11 13:56:24 -0700 | [diff] [blame] | 226 | MANIFEST_ERROR_INVALID_MEM_PERM, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 227 | }; |
| 228 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 229 | enum manifest_return_code manifest_init(struct mm_stage1_locked stage1_locked, |
| 230 | struct manifest *manifest, |
| 231 | struct memiter *manifest_fdt, |
| 232 | struct mpool *ppool); |
| 233 | |
Raghu Krishnamurthy | b49549e | 2021-07-02 08:27:38 -0700 | [diff] [blame] | 234 | enum manifest_return_code parse_ffa_manifest(struct fdt *fdt, |
J-Alves | 3531578 | 2022-01-25 17:58:32 +0000 | [diff] [blame^] | 235 | struct manifest_vm *vm, |
| 236 | struct fdt_node *boot_info); |
| 237 | |
Raghu Krishnamurthy | b49549e | 2021-07-02 08:27:38 -0700 | [diff] [blame] | 238 | enum manifest_return_code sanity_check_ffa_manifest(struct manifest_vm *vm); |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 239 | void manifest_dump(struct manifest_vm *vm); |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 240 | |
| 241 | const char *manifest_strerror(enum manifest_return_code ret_code); |