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