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" |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 12 | #include "hf/ffa.h" |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 13 | #include "hf/memiter.h" |
David Brazdil | 136f294 | 2019-09-23 14:11:03 +0100 | [diff] [blame] | 14 | #include "hf/string.h" |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 15 | #include "hf/vm.h" |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 16 | |
David Brazdil | 080ee31 | 2020-02-25 15:30:30 -0800 | [diff] [blame] | 17 | #define MANIFEST_INVALID_ADDRESS UINT64_MAX |
| 18 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 19 | #define SP_PKG_HEADER_MAGIC (0x474b5053) |
| 20 | #define SP_PKG_HEADER_VERSION (0x1) |
| 21 | |
| 22 | #define SP_RTX_BUF_NAME_SIZE 10 |
| 23 | |
Manish Pandey | 6542f5c | 2020-04-27 14:37:46 +0100 | [diff] [blame^] | 24 | #define SP_MAX_MEMORY_REGIONS 8 |
| 25 | |
| 26 | /** Mask for getting read/write/execute permission */ |
| 27 | #define MM_PERM_MASK 0x7 |
| 28 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 29 | enum run_time_el { |
| 30 | EL1 = 0, |
| 31 | S_EL0, |
| 32 | S_EL1, |
| 33 | SUPERVISOR_MODE, |
| 34 | SECURE_USER_MODE, |
| 35 | SECURE_SUPERVISOR_MODE |
| 36 | }; |
| 37 | |
| 38 | enum execution_state { AARCH64 = 0, AARCH32 }; |
| 39 | |
| 40 | enum xlat_granule { PAGE_4KB = 0, PAGE_16KB, PAGE_64KB }; |
| 41 | |
| 42 | enum messaging_method { |
| 43 | DIRECT_MESSAGING = 0, |
| 44 | INDIRECT_MESSAGING, |
| 45 | BOTH_MESSAGING |
| 46 | }; |
| 47 | |
| 48 | /** |
Manish Pandey | 6542f5c | 2020-04-27 14:37:46 +0100 | [diff] [blame^] | 49 | * Partition Memory region as described in PSA FFA v1.0 spec, Table 10 |
| 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 | |
| 65 | /** |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 66 | * Partition manifest as described in PSA FF-A v1.0 spec section 3.1 |
| 67 | */ |
| 68 | struct sp_manifest { |
| 69 | /** PSA-FF-A expected version - mandatory */ |
| 70 | uint32_t ffa_version; |
| 71 | /** UUID - mandatory */ |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 72 | struct ffa_uuid uuid; |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 73 | /** Partition id - optional */ |
| 74 | ffa_vm_id_t id; |
| 75 | /** Aux ids for mem transactions - optional */ |
| 76 | ffa_vm_id_t aux_id; |
| 77 | |
| 78 | /* NOTE: optional name field maps to VM debug_name field */ |
| 79 | |
| 80 | /** mandatory */ |
| 81 | ffa_vcpu_count_t execution_ctx_count; |
| 82 | /** EL1 or secure EL1, secure EL0 - mandatory */ |
| 83 | enum run_time_el run_time_el; |
| 84 | /** AArch32 / AArch64 - mandatory */ |
| 85 | enum execution_state execution_state; |
| 86 | /** optional */ |
| 87 | uintpaddr_t load_addr; |
| 88 | /** optional */ |
| 89 | size_t ep_offset; |
| 90 | /** 4/16/64KB - mandatory */ |
| 91 | enum xlat_granule xlat_granule; |
| 92 | /** optional */ |
| 93 | uint16_t boot_order; |
| 94 | |
| 95 | /** Optional RX/TX buffers */ |
| 96 | struct { |
| 97 | bool rxtx_found; |
| 98 | /** optional */ |
| 99 | uint64_t base_address; |
| 100 | /** optional */ |
| 101 | uint16_t pages_count; |
| 102 | /** mandatory */ |
| 103 | uint16_t attributes; |
| 104 | /** Optional */ |
| 105 | char name[SP_RTX_BUF_NAME_SIZE]; |
| 106 | } rxtx; |
| 107 | |
| 108 | /** mandatory - direct/indirect msg or both */ |
| 109 | enum messaging_method messaging_method; |
| 110 | /** optional */ |
| 111 | bool has_primary_scheduler; |
| 112 | /** optional - preemptible / run to completion */ |
| 113 | uint8_t runtime_model; |
| 114 | /** optional */ |
| 115 | bool time_slice_mem; |
| 116 | /** optional - tuples SEPID/SMMUID/streamId */ |
| 117 | uint32_t stream_ep_ids[1]; |
Manish Pandey | 6542f5c | 2020-04-27 14:37:46 +0100 | [diff] [blame^] | 118 | |
| 119 | /** Memory regions */ |
| 120 | struct memory_region mem_regions[SP_MAX_MEMORY_REGIONS]; |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | /** |
| 124 | * Header for a PSA FF-A partition package. |
| 125 | */ |
| 126 | struct sp_pkg_header { |
| 127 | /** Magic used to identify a SP package. Value is "SPKG" */ |
| 128 | uint32_t magic; |
| 129 | /** Version number of the header */ |
| 130 | uint32_t version; |
| 131 | /** Offset in bytes to the partition manifest */ |
| 132 | uint32_t pm_offset; |
| 133 | /** Size in bytes of the partition manifest */ |
| 134 | uint32_t pm_size; |
| 135 | /** Offset in bytes to the base address of the partition binary */ |
| 136 | uint32_t img_offset; |
| 137 | /** Size in bytes of the partition binary */ |
| 138 | uint32_t img_size; |
| 139 | }; |
| 140 | |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 141 | /** |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 142 | * Holds information about one of the VMs described in the manifest. |
| 143 | */ |
| 144 | struct manifest_vm { |
| 145 | /* Properties defined for both primary and secondary VMs. */ |
David Brazdil | 136f294 | 2019-09-23 14:11:03 +0100 | [diff] [blame] | 146 | struct string debug_name; |
| 147 | struct string kernel_filename; |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 148 | struct smc_whitelist smc_whitelist; |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 149 | bool is_ffa_partition; |
| 150 | struct sp_manifest sp; |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 151 | |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 152 | union { |
| 153 | /* Properties specific to the primary VM. */ |
| 154 | struct { |
David Brazdil | 080ee31 | 2020-02-25 15:30:30 -0800 | [diff] [blame] | 155 | uint64_t boot_address; |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 156 | struct string ramdisk_filename; |
| 157 | } primary; |
| 158 | /* Properties specific to secondary VMs. */ |
| 159 | struct { |
| 160 | uint64_t mem_size; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 161 | ffa_vcpu_count_t vcpu_count; |
Fuad Tabba | 50469e0 | 2020-06-30 15:14:28 +0100 | [diff] [blame] | 162 | struct string fdt_filename; |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 163 | } secondary; |
| 164 | }; |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | /** |
| 168 | * Hafnium manifest parsed from FDT. |
| 169 | */ |
| 170 | struct manifest { |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 171 | bool ffa_tee_enabled; |
| 172 | ffa_vm_count_t vm_count; |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 173 | struct manifest_vm vm[MAX_VMS]; |
| 174 | }; |
| 175 | |
| 176 | enum manifest_return_code { |
| 177 | MANIFEST_SUCCESS = 0, |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 178 | MANIFEST_ERROR_FILE_SIZE, |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 179 | MANIFEST_ERROR_MALFORMED_DTB, |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 180 | MANIFEST_ERROR_NO_ROOT_NODE, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 181 | MANIFEST_ERROR_NO_HYPERVISOR_FDT_NODE, |
David Brazdil | 74e9c3b | 2019-08-28 11:09:08 +0100 | [diff] [blame] | 182 | MANIFEST_ERROR_NOT_COMPATIBLE, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 183 | MANIFEST_ERROR_RESERVED_VM_ID, |
| 184 | MANIFEST_ERROR_NO_PRIMARY_VM, |
| 185 | MANIFEST_ERROR_TOO_MANY_VMS, |
| 186 | MANIFEST_ERROR_PROPERTY_NOT_FOUND, |
| 187 | MANIFEST_ERROR_MALFORMED_STRING, |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 188 | MANIFEST_ERROR_STRING_TOO_LONG, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 189 | MANIFEST_ERROR_MALFORMED_INTEGER, |
| 190 | MANIFEST_ERROR_INTEGER_OVERFLOW, |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 191 | MANIFEST_ERROR_MALFORMED_INTEGER_LIST, |
Andrew Scull | b2c3a24 | 2019-11-04 13:52:36 +0000 | [diff] [blame] | 192 | MANIFEST_ERROR_MALFORMED_BOOLEAN, |
Manish Pandey | 6542f5c | 2020-04-27 14:37:46 +0100 | [diff] [blame^] | 193 | MANIFEST_ERROR_MEMORY_REGION_NODE_EMPTY, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 194 | }; |
| 195 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 196 | enum manifest_return_code manifest_init(struct mm_stage1_locked stage1_locked, |
| 197 | struct manifest *manifest, |
| 198 | struct memiter *manifest_fdt, |
| 199 | struct mpool *ppool); |
| 200 | |
| 201 | void manifest_dump(struct manifest_vm *vm); |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 202 | |
| 203 | const char *manifest_strerror(enum manifest_return_code ret_code); |