xref: /rk3399_ARM-atf/services/std_svc/spm/el3_spmc/spmc_shared_mem.h (revision ae4b70d60cfa758d13b17e13f65a1a7ba7de07c6)
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 extern int plat_spmc_shmem_begin(struct ffa_mtd *desc);
52 extern int plat_spmc_shmem_reclaim(struct ffa_mtd *desc);
53 
54 bool spmc_compatible_version(uint32_t ffa_version, uint16_t major,
55 			     uint16_t minor);
56 
57 long spmc_ffa_mem_send(uint32_t smc_fid,
58 		       bool secure_origin,
59 		       uint64_t total_length,
60 		       uint32_t fragment_length,
61 		       uint64_t address,
62 		       uint32_t page_count,
63 		       void *cookie,
64 		       void *handle,
65 		       uint64_t flags);
66 
67 long spmc_ffa_mem_frag_tx(uint32_t smc_fid,
68 			  bool secure_origin,
69 			  uint64_t handle_low,
70 			  uint64_t handle_high,
71 			  uint32_t fragment_length,
72 			  uint32_t sender_id,
73 			  void *cookie,
74 			  void *handle,
75 			  uint64_t flags);
76 
77 long spmc_ffa_mem_retrieve_req(uint32_t smc_fid,
78 			       bool secure_origin,
79 			       uint32_t total_length,
80 			       uint32_t fragment_length,
81 			       uint64_t address,
82 			       uint32_t page_count,
83 			       void *cookie,
84 			       void *handle,
85 			       uint64_t flags);
86 
87 long spmc_ffa_mem_frag_rx(uint32_t smc_fid,
88 			  bool secure_origin,
89 			  uint32_t handle_low,
90 			  uint32_t handle_high,
91 			  uint32_t fragment_offset,
92 			  uint32_t sender_id,
93 			  void *cookie,
94 			  void *handle,
95 			  uint64_t flags);
96 
97 
98 int spmc_ffa_mem_relinquish(uint32_t smc_fid,
99 			    bool secure_origin,
100 			    uint32_t handle_low,
101 			    uint32_t handle_high,
102 			    uint32_t fragment_offset,
103 			    uint32_t sender_id,
104 			    void *cookie,
105 			    void *handle,
106 			    uint64_t flags);
107 
108 int spmc_ffa_mem_reclaim(uint32_t smc_fid,
109 			 bool secure_origin,
110 			 uint32_t handle_low,
111 			 uint32_t handle_high,
112 			 uint32_t mem_flags,
113 			 uint64_t x4,
114 			 void *cookie,
115 			 void *handle,
116 			 uint64_t flags);
117 
118 #endif /* SPMC_SHARED_MEM_H */
119