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