1 /* 2 * Copyright (c) 2022, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef SPMC_SHARED_MEM_H 8 #define SPMC_SHARED_MEM_H 9 10 #include <services/el3_spmc_ffa_memory.h> 11 12 /** 13 * struct ffa_mem_relinquish_descriptor - Relinquish request descriptor. 14 * @handle: 15 * Id of shared memory object to relinquish. 16 * @flags: 17 * If bit 0 is set clear memory after unmapping from borrower. Must be 0 18 * for share. Bit[1]: Time slicing. Not supported, must be 0. All other 19 * bits are reserved 0. 20 * @endpoint_count: 21 * Number of entries in @endpoint_array. 22 * @endpoint_array: 23 * Array of endpoint ids. 24 */ 25 struct ffa_mem_relinquish_descriptor { 26 uint64_t handle; 27 uint32_t flags; 28 uint32_t endpoint_count; 29 ffa_endpoint_id16_t endpoint_array[]; 30 }; 31 CASSERT(sizeof(struct ffa_mem_relinquish_descriptor) == 16, 32 assert_ffa_mem_relinquish_descriptor_size_mismatch); 33 34 /** 35 * struct spmc_shmem_obj_state - Global state. 36 * @data: Backing store for spmc_shmem_obj objects. 37 * @data_size: The size allocated for the backing store. 38 * @allocated: Number of bytes allocated in @data. 39 * @next_handle: Handle used for next allocated object. 40 * @lock: Lock protecting all state in this file. 41 */ 42 struct spmc_shmem_obj_state { 43 uint8_t *data; 44 size_t data_size; 45 size_t allocated; 46 uint64_t next_handle; 47 spinlock_t lock; 48 }; 49 50 extern struct spmc_shmem_obj_state spmc_shmem_obj_state; 51 52 long spmc_ffa_mem_send(uint32_t smc_fid, 53 bool secure_origin, 54 uint64_t total_length, 55 uint32_t fragment_length, 56 uint64_t address, 57 uint32_t page_count, 58 void *cookie, 59 void *handle, 60 uint64_t flags); 61 62 long spmc_ffa_mem_frag_tx(uint32_t smc_fid, 63 bool secure_origin, 64 uint64_t handle_low, 65 uint64_t handle_high, 66 uint32_t fragment_length, 67 uint32_t sender_id, 68 void *cookie, 69 void *handle, 70 uint64_t flags); 71 72 long spmc_ffa_mem_retrieve_req(uint32_t smc_fid, 73 bool secure_origin, 74 uint32_t total_length, 75 uint32_t fragment_length, 76 uint64_t address, 77 uint32_t page_count, 78 void *cookie, 79 void *handle, 80 uint64_t flags); 81 82 long spmc_ffa_mem_frag_rx(uint32_t smc_fid, 83 bool secure_origin, 84 uint32_t handle_low, 85 uint32_t handle_high, 86 uint32_t fragment_offset, 87 uint32_t sender_id, 88 void *cookie, 89 void *handle, 90 uint64_t flags); 91 92 93 int spmc_ffa_mem_relinquish(uint32_t smc_fid, 94 bool secure_origin, 95 uint32_t handle_low, 96 uint32_t handle_high, 97 uint32_t fragment_offset, 98 uint32_t sender_id, 99 void *cookie, 100 void *handle, 101 uint64_t flags); 102 103 int spmc_ffa_mem_reclaim(uint32_t smc_fid, 104 bool secure_origin, 105 uint32_t handle_low, 106 uint32_t handle_high, 107 uint32_t mem_flags, 108 uint64_t x4, 109 void *cookie, 110 void *handle, 111 uint64_t flags); 112 113 #endif /* SPMC_SHARED_MEM_H */ 114