David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Hafnium Authors. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame^] | 19 | #include "hf/addr.h" |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 20 | #include "hf/ffa.h" |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 21 | #include "hf/memiter.h" |
David Brazdil | 136f294 | 2019-09-23 14:11:03 +0100 | [diff] [blame] | 22 | #include "hf/string.h" |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 23 | #include "hf/vm.h" |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 24 | |
David Brazdil | 080ee31 | 2020-02-25 15:30:30 -0800 | [diff] [blame] | 25 | #define MANIFEST_INVALID_ADDRESS UINT64_MAX |
| 26 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame^] | 27 | #define SP_PKG_HEADER_MAGIC (0x474b5053) |
| 28 | #define SP_PKG_HEADER_VERSION (0x1) |
| 29 | |
| 30 | #define SP_RTX_BUF_NAME_SIZE 10 |
| 31 | |
| 32 | enum run_time_el { |
| 33 | EL1 = 0, |
| 34 | S_EL0, |
| 35 | S_EL1, |
| 36 | SUPERVISOR_MODE, |
| 37 | SECURE_USER_MODE, |
| 38 | SECURE_SUPERVISOR_MODE |
| 39 | }; |
| 40 | |
| 41 | enum execution_state { AARCH64 = 0, AARCH32 }; |
| 42 | |
| 43 | enum xlat_granule { PAGE_4KB = 0, PAGE_16KB, PAGE_64KB }; |
| 44 | |
| 45 | enum messaging_method { |
| 46 | DIRECT_MESSAGING = 0, |
| 47 | INDIRECT_MESSAGING, |
| 48 | BOTH_MESSAGING |
| 49 | }; |
| 50 | |
| 51 | /** |
| 52 | * Partition manifest as described in PSA FF-A v1.0 spec section 3.1 |
| 53 | */ |
| 54 | struct sp_manifest { |
| 55 | /** PSA-FF-A expected version - mandatory */ |
| 56 | uint32_t ffa_version; |
| 57 | /** UUID - mandatory */ |
| 58 | uint32_t uuid[4]; |
| 59 | /** Partition id - optional */ |
| 60 | ffa_vm_id_t id; |
| 61 | /** Aux ids for mem transactions - optional */ |
| 62 | ffa_vm_id_t aux_id; |
| 63 | |
| 64 | /* NOTE: optional name field maps to VM debug_name field */ |
| 65 | |
| 66 | /** mandatory */ |
| 67 | ffa_vcpu_count_t execution_ctx_count; |
| 68 | /** EL1 or secure EL1, secure EL0 - mandatory */ |
| 69 | enum run_time_el run_time_el; |
| 70 | /** AArch32 / AArch64 - mandatory */ |
| 71 | enum execution_state execution_state; |
| 72 | /** optional */ |
| 73 | uintpaddr_t load_addr; |
| 74 | /** optional */ |
| 75 | size_t ep_offset; |
| 76 | /** 4/16/64KB - mandatory */ |
| 77 | enum xlat_granule xlat_granule; |
| 78 | /** optional */ |
| 79 | uint16_t boot_order; |
| 80 | |
| 81 | /** Optional RX/TX buffers */ |
| 82 | struct { |
| 83 | bool rxtx_found; |
| 84 | /** optional */ |
| 85 | uint64_t base_address; |
| 86 | /** optional */ |
| 87 | uint16_t pages_count; |
| 88 | /** mandatory */ |
| 89 | uint16_t attributes; |
| 90 | /** Optional */ |
| 91 | char name[SP_RTX_BUF_NAME_SIZE]; |
| 92 | } rxtx; |
| 93 | |
| 94 | /** mandatory - direct/indirect msg or both */ |
| 95 | enum messaging_method messaging_method; |
| 96 | /** optional */ |
| 97 | bool has_primary_scheduler; |
| 98 | /** optional - preemptible / run to completion */ |
| 99 | uint8_t runtime_model; |
| 100 | /** optional */ |
| 101 | bool time_slice_mem; |
| 102 | /** optional - tuples SEPID/SMMUID/streamId */ |
| 103 | uint32_t stream_ep_ids[1]; |
| 104 | }; |
| 105 | |
| 106 | /** |
| 107 | * Header for a PSA FF-A partition package. |
| 108 | */ |
| 109 | struct sp_pkg_header { |
| 110 | /** Magic used to identify a SP package. Value is "SPKG" */ |
| 111 | uint32_t magic; |
| 112 | /** Version number of the header */ |
| 113 | uint32_t version; |
| 114 | /** Offset in bytes to the partition manifest */ |
| 115 | uint32_t pm_offset; |
| 116 | /** Size in bytes of the partition manifest */ |
| 117 | uint32_t pm_size; |
| 118 | /** Offset in bytes to the base address of the partition binary */ |
| 119 | uint32_t img_offset; |
| 120 | /** Size in bytes of the partition binary */ |
| 121 | uint32_t img_size; |
| 122 | }; |
| 123 | |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 124 | /** |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 125 | * Holds information about one of the VMs described in the manifest. |
| 126 | */ |
| 127 | struct manifest_vm { |
| 128 | /* Properties defined for both primary and secondary VMs. */ |
David Brazdil | 136f294 | 2019-09-23 14:11:03 +0100 | [diff] [blame] | 129 | struct string debug_name; |
| 130 | struct string kernel_filename; |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 131 | struct smc_whitelist smc_whitelist; |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame^] | 132 | bool is_ffa_partition; |
| 133 | struct sp_manifest sp; |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 134 | |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 135 | union { |
| 136 | /* Properties specific to the primary VM. */ |
| 137 | struct { |
David Brazdil | 080ee31 | 2020-02-25 15:30:30 -0800 | [diff] [blame] | 138 | uint64_t boot_address; |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 139 | struct string ramdisk_filename; |
| 140 | } primary; |
| 141 | /* Properties specific to secondary VMs. */ |
| 142 | struct { |
| 143 | uint64_t mem_size; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 144 | ffa_vcpu_count_t vcpu_count; |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 145 | } secondary; |
| 146 | }; |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | /** |
| 150 | * Hafnium manifest parsed from FDT. |
| 151 | */ |
| 152 | struct manifest { |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 153 | bool ffa_tee_enabled; |
| 154 | ffa_vm_count_t vm_count; |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 155 | struct manifest_vm vm[MAX_VMS]; |
| 156 | }; |
| 157 | |
| 158 | enum manifest_return_code { |
| 159 | MANIFEST_SUCCESS = 0, |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 160 | MANIFEST_ERROR_FILE_SIZE, |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame^] | 161 | MANIFEST_ERROR_MALFORMED_DTB, |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 162 | MANIFEST_ERROR_NO_ROOT_NODE, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 163 | MANIFEST_ERROR_NO_HYPERVISOR_FDT_NODE, |
David Brazdil | 74e9c3b | 2019-08-28 11:09:08 +0100 | [diff] [blame] | 164 | MANIFEST_ERROR_NOT_COMPATIBLE, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 165 | MANIFEST_ERROR_RESERVED_VM_ID, |
| 166 | MANIFEST_ERROR_NO_PRIMARY_VM, |
| 167 | MANIFEST_ERROR_TOO_MANY_VMS, |
| 168 | MANIFEST_ERROR_PROPERTY_NOT_FOUND, |
| 169 | MANIFEST_ERROR_MALFORMED_STRING, |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 170 | MANIFEST_ERROR_STRING_TOO_LONG, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 171 | MANIFEST_ERROR_MALFORMED_INTEGER, |
| 172 | MANIFEST_ERROR_INTEGER_OVERFLOW, |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 173 | MANIFEST_ERROR_MALFORMED_INTEGER_LIST, |
Andrew Scull | b2c3a24 | 2019-11-04 13:52:36 +0000 | [diff] [blame] | 174 | MANIFEST_ERROR_MALFORMED_BOOLEAN, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 175 | }; |
| 176 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame^] | 177 | enum manifest_return_code manifest_init(struct mm_stage1_locked stage1_locked, |
| 178 | struct manifest *manifest, |
| 179 | struct memiter *manifest_fdt, |
| 180 | struct mpool *ppool); |
| 181 | |
| 182 | void manifest_dump(struct manifest_vm *vm); |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 183 | |
| 184 | const char *manifest_strerror(enum manifest_return_code ret_code); |