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" |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 14 | #include "hf/ffa_partition_manifest.h" |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 15 | #include "hf/memiter.h" |
David Brazdil | 136f294 | 2019-09-23 14:11:03 +0100 | [diff] [blame] | 16 | #include "hf/string.h" |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 17 | #include "hf/vm.h" |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 18 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 19 | /** |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 20 | * Holds information about one of the VMs described in the manifest. |
| 21 | */ |
| 22 | struct manifest_vm { |
| 23 | /* Properties defined for both primary and secondary VMs. */ |
David Brazdil | 136f294 | 2019-09-23 14:11:03 +0100 | [diff] [blame] | 24 | struct string debug_name; |
| 25 | struct string kernel_filename; |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 26 | struct smc_whitelist smc_whitelist; |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 27 | bool is_ffa_partition; |
Raghu Krishnamurthy | b49549e | 2021-07-02 08:27:38 -0700 | [diff] [blame] | 28 | bool is_hyp_loaded; |
J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 29 | struct ffa_partition_manifest partition; |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 30 | |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 31 | union { |
| 32 | /* Properties specific to the primary VM. */ |
| 33 | struct { |
David Brazdil | 080ee31 | 2020-02-25 15:30:30 -0800 | [diff] [blame] | 34 | uint64_t boot_address; |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 35 | struct string ramdisk_filename; |
| 36 | } primary; |
| 37 | /* Properties specific to secondary VMs. */ |
| 38 | struct { |
| 39 | uint64_t mem_size; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 40 | ffa_vcpu_count_t vcpu_count; |
Fuad Tabba | 50469e0 | 2020-06-30 15:14:28 +0100 | [diff] [blame] | 41 | struct string fdt_filename; |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 42 | } secondary; |
| 43 | }; |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | /** |
| 47 | * Hafnium manifest parsed from FDT. |
| 48 | */ |
| 49 | struct manifest { |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 50 | bool ffa_tee_enabled; |
| 51 | ffa_vm_count_t vm_count; |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 52 | struct manifest_vm vm[MAX_VMS]; |
| 53 | }; |
| 54 | |
| 55 | enum manifest_return_code { |
| 56 | MANIFEST_SUCCESS = 0, |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 57 | MANIFEST_ERROR_FILE_SIZE, |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 58 | MANIFEST_ERROR_MALFORMED_DTB, |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 59 | MANIFEST_ERROR_NO_ROOT_NODE, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 60 | MANIFEST_ERROR_NO_HYPERVISOR_FDT_NODE, |
David Brazdil | 74e9c3b | 2019-08-28 11:09:08 +0100 | [diff] [blame] | 61 | MANIFEST_ERROR_NOT_COMPATIBLE, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 62 | MANIFEST_ERROR_RESERVED_VM_ID, |
| 63 | MANIFEST_ERROR_NO_PRIMARY_VM, |
| 64 | MANIFEST_ERROR_TOO_MANY_VMS, |
| 65 | MANIFEST_ERROR_PROPERTY_NOT_FOUND, |
| 66 | MANIFEST_ERROR_MALFORMED_STRING, |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 67 | MANIFEST_ERROR_STRING_TOO_LONG, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 68 | MANIFEST_ERROR_MALFORMED_INTEGER, |
| 69 | MANIFEST_ERROR_INTEGER_OVERFLOW, |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 70 | MANIFEST_ERROR_MALFORMED_INTEGER_LIST, |
Andrew Scull | b2c3a24 | 2019-11-04 13:52:36 +0000 | [diff] [blame] | 71 | MANIFEST_ERROR_MALFORMED_BOOLEAN, |
J-Alves | 3531578 | 2022-01-25 17:58:32 +0000 | [diff] [blame] | 72 | MANIFEST_ERROR_ARGUMENTS_LIST_EMPTY, |
Manish Pandey | 6542f5c | 2020-04-27 14:37:46 +0100 | [diff] [blame] | 73 | MANIFEST_ERROR_MEMORY_REGION_NODE_EMPTY, |
Manish Pandey | e68e793 | 2020-04-23 15:29:28 +0100 | [diff] [blame] | 74 | MANIFEST_ERROR_DEVICE_REGION_NODE_EMPTY, |
Manish Pandey | f06c907 | 2020-09-29 15:41:58 +0100 | [diff] [blame] | 75 | MANIFEST_ERROR_RXTX_SIZE_MISMATCH, |
Varun Wadekar | 4afbfd7 | 2022-10-13 14:30:18 +0100 | [diff] [blame] | 76 | MANIFEST_ERROR_MEM_REGION_EMPTY, |
Daniel Boulby | c1a613d | 2022-10-18 11:26:17 +0100 | [diff] [blame] | 77 | MANIFEST_ERROR_MEM_REGION_UNALIGNED, |
Daniel Boulby | a7e9e18 | 2022-06-27 14:21:01 +0100 | [diff] [blame] | 78 | MANIFEST_ERROR_MEM_REGION_OVERLAP, |
Raghu Krishnamurthy | 384693c | 2021-10-11 13:56:24 -0700 | [diff] [blame] | 79 | MANIFEST_ERROR_INVALID_MEM_PERM, |
Daniel Boulby | 801f8ef | 2022-06-27 14:21:01 +0100 | [diff] [blame] | 80 | MANIFEST_ERROR_INTERRUPT_ID_REPEATED, |
Madhukar Pappireddy | 5c04a38 | 2022-12-28 11:29:26 -0600 | [diff] [blame] | 81 | MANIFEST_ERROR_ILLEGAL_NS_INT_ACTION, |
Raghu Krishnamurthy | 98da1ca | 2022-10-04 08:59:01 -0700 | [diff] [blame] | 82 | MANIFEST_ERROR_INTERRUPT_ID_NOT_IN_LIST, |
Madhukar Pappireddy | 5c04a38 | 2022-12-28 11:29:26 -0600 | [diff] [blame] | 83 | MANIFEST_ERROR_ILLEGAL_OTHER_S_INT_ACTION, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 84 | }; |
| 85 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 86 | enum manifest_return_code manifest_init(struct mm_stage1_locked stage1_locked, |
Olivier Deprez | 9364465 | 2022-09-09 11:01:12 +0200 | [diff] [blame] | 87 | struct manifest **manifest, |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 88 | struct memiter *manifest_fdt, |
| 89 | struct mpool *ppool); |
Daniel Boulby | 801f8ef | 2022-06-27 14:21:01 +0100 | [diff] [blame] | 90 | void manifest_deinit(struct mpool *ppool); |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 91 | |
Raghu Krishnamurthy | b49549e | 2021-07-02 08:27:38 -0700 | [diff] [blame] | 92 | enum manifest_return_code parse_ffa_manifest(struct fdt *fdt, |
J-Alves | 3531578 | 2022-01-25 17:58:32 +0000 | [diff] [blame] | 93 | struct manifest_vm *vm, |
| 94 | struct fdt_node *boot_info); |
| 95 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 96 | void manifest_dump(struct manifest_vm *vm); |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 97 | |
| 98 | const char *manifest_strerror(enum manifest_return_code ret_code); |