1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2021, Arm Limited. 4 */ 5 6 #ifndef __MM_SP_MEM_H 7 #define __MM_SP_MEM_H 8 9 #include <ffa.h> 10 #include <mm/fobj.h> 11 #include <sys/queue.h> 12 13 struct sp_mem_receiver; 14 struct sp_mem; 15 16 /* 17 * struct sp_mem_receiver - Memory object instance for a FF-A receiver endpoint 18 * 19 * @perm: Receiver permission on the shared memory 20 * @ref_count: Count retrieve requests from endpoint 21 * @smem: Shared memory reference 22 * @link: Link in related list 23 */ 24 struct sp_mem_receiver { 25 struct ffa_mem_access_perm perm; 26 uint8_t ref_count; 27 struct sp_mem *smem; 28 29 SLIST_ENTRY(sp_mem_receiver) link; 30 }; 31 32 /* 33 * sp_mem_map_region represents the memory address when using FF-A shares. 34 * Instead of storing the physical addresses and the size of the region, we use 35 * the mobj's which were already used by the SPs. The offset is used to point 36 * to the specific location inside the mobj memory range. 37 */ 38 struct sp_mem_map_region { 39 struct mobj *mobj; 40 /* 41 * Offset (in pages) inside the mobj which is used to retrieve the 42 * location. 43 */ 44 uint32_t page_offset; 45 uint32_t page_count; 46 47 SLIST_ENTRY(sp_mem_map_region) link; 48 }; 49 50 SLIST_HEAD(sp_mem_receiver_head, sp_mem_receiver); 51 SLIST_HEAD(sp_mem_regions_head, sp_mem_map_region); 52 53 /* 54 * sp_mem is used as the main place to store the FF-A shares information. 55 * For each FFA_SHARE message a new sp_mem object is created. 56 * The receivers field is used to store all receiver specific information. 57 * The regions field is used to store all data needed for retrieving the 58 * shared addresses. 59 */ 60 struct sp_mem { 61 struct sp_mem_regions_head regions; 62 struct sp_mem_receiver_head receivers; 63 /* Data which was passed inside struct ffa_mem_transaction*/ 64 uint16_t sender_id; 65 uint8_t mem_reg_attr; 66 uint32_t flags; 67 uint64_t global_handle; 68 uint64_t tag; 69 70 SLIST_ENTRY(sp_mem) link; 71 }; 72 73 struct sp_mem *sp_mem_new(void); 74 struct sp_mem_receiver *sp_mem_get_receiver(uint32_t s_id, struct sp_mem *smem); 75 struct sp_mem *sp_mem_get(uint64_t handle); 76 77 bool sp_mem_is_shared(struct sp_mem_map_region *new_reg); 78 void *sp_mem_get_va(const struct user_mode_ctx *uctx, size_t offset, 79 struct mobj *mobj); 80 void sp_mem_remove(struct sp_mem *s_mem); 81 void sp_mem_add(struct sp_mem *smem); 82 #endif /*__MM_SP_MEM_H*/ 83