Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 1 | /* |
J-Alves | 32ccd2b | 2021-12-14 14:59:51 +0000 | [diff] [blame] | 2 | * Copyright (c) 2021-2022, Arm Limited. All rights reserved. |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef SPM_COMMON_H |
| 8 | #define SPM_COMMON_H |
| 9 | |
J-Alves | 79c08f1 | 2021-10-27 15:15:16 +0100 | [diff] [blame] | 10 | #include <plat/common/platform.h> |
| 11 | |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 12 | #include <stdint.h> |
| 13 | #include <string.h> |
| 14 | |
J-Alves | 79c08f1 | 2021-10-27 15:15:16 +0100 | [diff] [blame] | 15 | #include <ffa_helpers.h> |
| 16 | |
Olivier Deprez | 569be40 | 2022-07-08 10:24:39 +0200 | [diff] [blame^] | 17 | #include <lib/extensions/sve.h> |
| 18 | |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 19 | /* Hypervisor ID at physical FFA instance */ |
| 20 | #define HYP_ID (0) |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 21 | /* SPMC ID */ |
| 22 | #define SPMC_ID U(0x8000) |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 23 | |
Olivier Deprez | 6967c24 | 2021-04-09 09:24:08 +0200 | [diff] [blame] | 24 | /* ID for the first Secure Partition. */ |
| 25 | #define SPM_VM_ID_FIRST SP_ID(1) |
| 26 | |
Manish Pandey | f7aafef | 2021-03-03 11:31:47 +0000 | [diff] [blame] | 27 | /* INTID for the managed exit virtual interrupt. */ |
| 28 | #define MANAGED_EXIT_INTERRUPT_ID U(4) |
| 29 | |
J-Alves | 4439ece | 2021-11-05 11:52:54 +0000 | [diff] [blame] | 30 | /* INTID for the notification pending interrupt. */ |
| 31 | #define NOTIFICATION_PENDING_INTERRUPT_INTID 5 |
| 32 | |
Manish Pandey | 58971b6 | 2020-09-21 21:10:38 +0100 | [diff] [blame] | 33 | /** IRQ/FIQ pin used for signaling a virtual interrupt. */ |
| 34 | enum interrupt_pin { |
| 35 | INTERRUPT_TYPE_IRQ, |
| 36 | INTERRUPT_TYPE_FIQ, |
| 37 | }; |
| 38 | |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 39 | /* |
| 40 | * The bit 15 of the FF-A ID indicates whether the partition is executing |
| 41 | * in the normal world, in case it is a Virtual Machine (VM); or in the |
| 42 | * secure world, in case it is a Secure Partition (SP). |
| 43 | * |
| 44 | * If bit 15 is set partition is an SP; if bit 15 is clear partition is |
| 45 | * a VM. |
| 46 | */ |
| 47 | #define SP_ID_MASK U(1 << 15) |
| 48 | #define SP_ID(x) ((x) | SP_ID_MASK) |
J-Alves | d5d8715 | 2021-10-29 11:48:37 +0100 | [diff] [blame] | 49 | #define VM_ID(x) (x & ~SP_ID_MASK) |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 50 | #define IS_SP_ID(x) ((x & SP_ID_MASK) != 0U) |
| 51 | |
Daniel Boulby | 4a2888a | 2022-05-31 16:07:36 +0100 | [diff] [blame] | 52 | #define NULL_UUID (const struct ffa_uuid) { .uuid = {0} } |
| 53 | |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 54 | struct ffa_features_test { |
| 55 | const char *test_name; |
| 56 | unsigned int feature; |
| 57 | unsigned int expected_ret; |
Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 58 | unsigned int version_added; |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 59 | }; |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 60 | |
| 61 | struct mailbox_buffers { |
| 62 | void *recv; |
| 63 | void *send; |
| 64 | }; |
| 65 | |
| 66 | #define CONFIGURE_MAILBOX(mb_name, buffers_size) \ |
| 67 | do { \ |
| 68 | /* Declare RX/TX buffers at virtual FF-A instance */ \ |
| 69 | static struct { \ |
| 70 | uint8_t rx[buffers_size]; \ |
| 71 | uint8_t tx[buffers_size]; \ |
| 72 | } __aligned(PAGE_SIZE) mb_buffers; \ |
| 73 | mb_name.recv = (void *)mb_buffers.rx; \ |
| 74 | mb_name.send = (void *)mb_buffers.tx; \ |
| 75 | } while (false) |
| 76 | |
| 77 | #define CONFIGURE_AND_MAP_MAILBOX(mb_name, buffers_size, smc_ret) \ |
| 78 | do { \ |
| 79 | CONFIGURE_MAILBOX(mb_name, buffers_size); \ |
| 80 | smc_ret = ffa_rxtx_map( \ |
| 81 | (uintptr_t)mb_name.send, \ |
J-Alves | 43887ec | 2021-02-22 12:21:44 +0000 | [diff] [blame] | 82 | (uintptr_t)mb_name.recv, \ |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 83 | buffers_size / PAGE_SIZE \ |
| 84 | ); \ |
| 85 | } while (false) |
| 86 | |
J-Alves | 43887ec | 2021-02-22 12:21:44 +0000 | [diff] [blame] | 87 | /** |
| 88 | * Helpers to evaluate returns of FF-A calls. |
| 89 | */ |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 90 | bool is_ffa_call_error(struct ffa_value val); |
| 91 | bool is_expected_ffa_error(struct ffa_value ret, int32_t error_code); |
| 92 | bool is_ffa_direct_response(struct ffa_value ret); |
| 93 | bool is_expected_ffa_return(struct ffa_value ret, uint32_t func_id); |
| 94 | bool is_expected_cactus_response(struct ffa_value ret, uint32_t expected_resp, |
J-Alves | 227065a | 2021-03-11 10:01:36 +0000 | [diff] [blame] | 95 | uint32_t arg); |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 96 | void dump_ffa_value(struct ffa_value ret); |
J-Alves | 43887ec | 2021-02-22 12:21:44 +0000 | [diff] [blame] | 97 | |
Olivier Deprez | 881b199 | 2020-12-01 15:34:34 +0100 | [diff] [blame] | 98 | /* |
Olivier Deprez | 569be40 | 2022-07-08 10:24:39 +0200 | [diff] [blame^] | 99 | * Max. vector length: |
Olivier Deprez | 881b199 | 2020-12-01 15:34:34 +0100 | [diff] [blame] | 100 | * SIMD: 128 bits = 16 bytes |
| 101 | */ |
| 102 | #define SIMD_VECTOR_LEN_BYTES 16 |
Max Shvetsov | 959be33 | 2021-03-16 14:18:13 +0000 | [diff] [blame] | 103 | |
Olivier Deprez | 881b199 | 2020-12-01 15:34:34 +0100 | [diff] [blame] | 104 | #define SIMD_NUM_VECTORS 32 |
Olivier Deprez | 569be40 | 2022-07-08 10:24:39 +0200 | [diff] [blame^] | 105 | |
Olivier Deprez | 881b199 | 2020-12-01 15:34:34 +0100 | [diff] [blame] | 106 | typedef uint8_t simd_vector_t[SIMD_VECTOR_LEN_BYTES]; |
| 107 | |
| 108 | /* |
Max Shvetsov | 959be33 | 2021-03-16 14:18:13 +0000 | [diff] [blame] | 109 | * Fills SIMD/SVE registers with the content of the container v. |
| 110 | * Number of vectors is assumed to be SIMD/SVE_NUM_VECTORS. |
Olivier Deprez | 881b199 | 2020-12-01 15:34:34 +0100 | [diff] [blame] | 111 | */ |
| 112 | void fill_simd_vector_regs(const simd_vector_t v[SIMD_NUM_VECTORS]); |
Max Shvetsov | 959be33 | 2021-03-16 14:18:13 +0000 | [diff] [blame] | 113 | void fill_sve_vector_regs(const sve_vector_t v[SVE_NUM_VECTORS]); |
Olivier Deprez | 881b199 | 2020-12-01 15:34:34 +0100 | [diff] [blame] | 114 | |
| 115 | /* |
Max Shvetsov | 959be33 | 2021-03-16 14:18:13 +0000 | [diff] [blame] | 116 | * Reads contents of SIMD/SVE registers into the provided container v. |
| 117 | * Number of vectors is assumed to be SIMD/SVE_NUM_VECTORS. |
Olivier Deprez | 881b199 | 2020-12-01 15:34:34 +0100 | [diff] [blame] | 118 | */ |
| 119 | void read_simd_vector_regs(simd_vector_t v[SIMD_NUM_VECTORS]); |
Max Shvetsov | 959be33 | 2021-03-16 14:18:13 +0000 | [diff] [blame] | 120 | void read_sve_vector_regs(sve_vector_t v[SVE_NUM_VECTORS]); |
Olivier Deprez | 881b199 | 2020-12-01 15:34:34 +0100 | [diff] [blame] | 121 | |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 122 | bool check_spmc_execution_level(void); |
| 123 | |
Olivier Deprez | 881b199 | 2020-12-01 15:34:34 +0100 | [diff] [blame] | 124 | unsigned int get_ffa_feature_test_target(const struct ffa_features_test **test_target); |
| 125 | |
J-Alves | be1519a | 2021-02-19 14:33:54 +0000 | [diff] [blame] | 126 | /** |
| 127 | * Helper to conduct a memory retrieve. This is to be called by the receiver |
| 128 | * of a memory share operation. |
| 129 | */ |
| 130 | bool memory_retrieve(struct mailbox_buffers *mb, |
| 131 | struct ffa_memory_region **retrieved, uint64_t handle, |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 132 | ffa_id_t sender, ffa_id_t receiver, |
Olivier Deprez | 20b9b17 | 2021-04-22 14:39:54 +0200 | [diff] [blame] | 133 | ffa_memory_region_flags_t flags); |
J-Alves | be1519a | 2021-02-19 14:33:54 +0000 | [diff] [blame] | 134 | |
| 135 | /** |
| 136 | * Helper to conduct a memory relinquish. The caller is usually the receiver, |
| 137 | * after it being done with the memory shared, identified by the 'handle'. |
| 138 | */ |
| 139 | bool memory_relinquish(struct ffa_mem_relinquish *m, uint64_t handle, |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 140 | ffa_id_t id); |
J-Alves | be1519a | 2021-02-19 14:33:54 +0000 | [diff] [blame] | 141 | |
| 142 | ffa_memory_handle_t memory_send( |
| 143 | struct ffa_memory_region *memory_region, uint32_t mem_func, |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 144 | uint32_t fragment_length, uint32_t total_length, struct ffa_value *ret); |
J-Alves | be1519a | 2021-02-19 14:33:54 +0000 | [diff] [blame] | 145 | |
| 146 | ffa_memory_handle_t memory_init_and_send( |
| 147 | struct ffa_memory_region *memory_region, size_t memory_region_max_size, |
Daniel Boulby | e79d207 | 2021-03-03 11:34:53 +0000 | [diff] [blame] | 148 | ffa_id_t sender, ffa_id_t receiver, |
J-Alves | be1519a | 2021-02-19 14:33:54 +0000 | [diff] [blame] | 149 | const struct ffa_memory_region_constituent* constituents, |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 150 | uint32_t constituents_count, uint32_t mem_func, struct ffa_value *ret); |
J-Alves | be1519a | 2021-02-19 14:33:54 +0000 | [diff] [blame] | 151 | |
Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 152 | bool ffa_partition_info_helper(struct mailbox_buffers *mb, |
| 153 | const struct ffa_uuid uuid, |
| 154 | const struct ffa_partition_info *expected, |
| 155 | const uint16_t expected_size); |
| 156 | |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 157 | #endif /* SPM_COMMON_H */ |