xref: /rk3399_ARM-atf/include/services/el3_spmc_ffa_memory.h (revision 7e804f9695c48681c91e9e6fc6175eb6997df867)
1 /*
2  * Copyright (c) 2022, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef EL3_SPMC_FFA_MEM_H
8 #define EL3_SPMC_FFA_MEM_H
9 
10 #include <assert.h>
11 
12 /*
13  * Subset of Arm Firmware Framework for Armv8-A
14  * (https://developer.arm.com/docs/den0077/a) needed for shared memory.
15  */
16 
17 /**
18  * typedef ffa_endpoint_id16_t - Endpoint ID
19  *
20  * Current implementation only supports VM IDs. FF-A spec also support stream
21  * endpoint ids.
22  */
23 typedef uint16_t ffa_endpoint_id16_t;
24 
25 /**
26  * struct ffa_cons_mrd - Constituent memory region descriptor
27  * @address:
28  *         Start address of contiguous memory region. Must be 4K page aligned.
29  * @page_count:
30  *         Number of 4K pages in region.
31  * @reserved_12_15:
32  *         Reserve bytes 12-15 to pad struct size to 16 bytes.
33  */
34 struct ffa_cons_mrd {
35 	uint64_t address;
36 	uint32_t page_count;
37 	uint32_t reserved_12_15;
38 };
39 CASSERT(sizeof(struct ffa_cons_mrd) == 16, assert_ffa_cons_mrd_size_mismatch);
40 
41 /**
42  * struct ffa_comp_mrd - Composite memory region descriptor
43  * @total_page_count:
44  *         Number of 4k pages in memory region. Must match sum of
45  *         @address_range_array[].page_count.
46  * @address_range_count:
47  *         Number of entries in @address_range_array.
48  * @reserved_8_15:
49  *         Reserve bytes 8-15 to pad struct size to 16 byte alignment and
50  *         make @address_range_array 16 byte aligned.
51  * @address_range_array:
52  *         Array of &struct ffa_cons_mrd entries.
53  */
54 struct ffa_comp_mrd {
55 	uint32_t total_page_count;
56 	uint32_t address_range_count;
57 	uint64_t reserved_8_15;
58 	struct ffa_cons_mrd address_range_array[];
59 };
60 CASSERT(sizeof(struct ffa_comp_mrd) == 16, assert_ffa_comp_mrd_size_mismatch);
61 
62 /**
63  * typedef ffa_mem_attr8_t - Memory region attributes v1.0.
64  * typedef ffa_mem_attr16_t - Memory region attributes v1.1.
65  *
66  * * @FFA_MEM_ATTR_DEVICE_NGNRNE:
67  *     Device-nGnRnE.
68  * * @FFA_MEM_ATTR_DEVICE_NGNRE:
69  *     Device-nGnRE.
70  * * @FFA_MEM_ATTR_DEVICE_NGRE:
71  *     Device-nGRE.
72  * * @FFA_MEM_ATTR_DEVICE_GRE:
73  *     Device-GRE.
74  * * @FFA_MEM_ATTR_NORMAL_MEMORY_UNCACHED
75  *     Normal memory. Non-cacheable.
76  * * @FFA_MEM_ATTR_NORMAL_MEMORY_CACHED_WB
77  *     Normal memory. Write-back cached.
78  * * @FFA_MEM_ATTR_NON_SHAREABLE
79  *     Non-shareable. Combine with FFA_MEM_ATTR_NORMAL_MEMORY_*.
80  * * @FFA_MEM_ATTR_OUTER_SHAREABLE
81  *     Outer Shareable. Combine with FFA_MEM_ATTR_NORMAL_MEMORY_*.
82  * * @FFA_MEM_ATTR_INNER_SHAREABLE
83  *     Inner Shareable. Combine with FFA_MEM_ATTR_NORMAL_MEMORY_*.
84  */
85 typedef uint8_t ffa_mem_attr8_t;
86 typedef uint16_t ffa_mem_attr16_t;
87 #define FFA_MEM_ATTR_DEVICE_NGNRNE		((1U << 4) | (0x0U << 2))
88 #define FFA_MEM_ATTR_DEVICE_NGNRE		((1U << 4) | (0x1U << 2))
89 #define FFA_MEM_ATTR_DEVICE_NGRE		((1U << 4) | (0x2U << 2))
90 #define FFA_MEM_ATTR_DEVICE_GRE			((1U << 4) | (0x3U << 2))
91 #define FFA_MEM_ATTR_NORMAL_MEMORY_UNCACHED	((2U << 4) | (0x1U << 2))
92 #define FFA_MEM_ATTR_NORMAL_MEMORY_CACHED_WB	((2U << 4) | (0x3U << 2))
93 #define FFA_MEM_ATTR_NON_SHAREABLE		(0x0U << 0)
94 #define FFA_MEM_ATTR_OUTER_SHAREABLE		(0x2U << 0)
95 #define FFA_MEM_ATTR_INNER_SHAREABLE		(0x3U << 0)
96 
97 /**
98  * typedef ffa_mem_perm8_t - Memory access permissions
99  *
100  * * @FFA_MEM_ATTR_RO
101  *     Request or specify read-only mapping.
102  * * @FFA_MEM_ATTR_RW
103  *     Request or allow read-write mapping.
104  * * @FFA_MEM_PERM_NX
105  *     Deny executable mapping.
106  * * @FFA_MEM_PERM_X
107  *     Request executable mapping.
108  */
109 typedef uint8_t ffa_mem_perm8_t;
110 #define FFA_MEM_PERM_RO		(1U << 0)
111 #define FFA_MEM_PERM_RW		(1U << 1)
112 #define FFA_MEM_PERM_NX		(1U << 2)
113 #define FFA_MEM_PERM_X		(1U << 3)
114 
115 /**
116  * typedef ffa_mem_flag8_t - Endpoint memory flags
117  *
118  * * @FFA_MEM_FLAG_NON_RETRIEVAL_BORROWER
119  *     Non-retrieval Borrower. Memory region must not be or was not retrieved on
120  *     behalf of this endpoint.
121  */
122 typedef uint8_t ffa_mem_flag8_t;
123 #define FFA_MEM_FLAG_NON_RETRIEVAL_BORROWER	(1U << 0)
124 
125 /**
126  * typedef ffa_mtd_flag32_t - Memory transaction descriptor flags
127  *
128  * * @FFA_MTD_FLAG_ZERO_MEMORY
129  *     Zero memory after unmapping from sender (must be 0 for share).
130  * * @FFA_MTD_FLAG_TIME_SLICING
131  *     Not supported by this implementation.
132  * * @FFA_MTD_FLAG_ZERO_MEMORY_AFTER_RELINQUISH
133  *     Zero memory after unmapping from borrowers (must be 0 for share).
134  * * @FFA_MTD_FLAG_TYPE_MASK
135  *     Bit-mask to extract memory management transaction type from flags.
136  * * @FFA_MTD_FLAG_TYPE_SHARE_MEMORY
137  *     Share memory transaction flag.
138  *     Used by @SMC_FC_FFA_MEM_RETRIEVE_RESP to indicate that memory came from
139  *     @SMC_FC_FFA_MEM_SHARE and by @SMC_FC_FFA_MEM_RETRIEVE_REQ to specify that
140  *     it must have.
141  * * @FFA_MTD_FLAG_ADDRESS_RANGE_ALIGNMENT_HINT_MASK
142  *     Not supported by this implementation.
143  */
144 typedef uint32_t ffa_mtd_flag32_t;
145 #define FFA_MTD_FLAG_ZERO_MEMORY			(1U << 0)
146 #define FFA_MTD_FLAG_TIME_SLICING			(1U << 1)
147 #define FFA_MTD_FLAG_ZERO_MEMORY_AFTER_RELINQUISH	(1U << 2)
148 #define FFA_MTD_FLAG_TYPE_MASK				(3U << 3)
149 #define FFA_MTD_FLAG_TYPE_SHARE_MEMORY			(1U << 3)
150 #define FFA_MTD_FLAG_TYPE_LEND_MEMORY			(1U << 4)
151 #define FFA_MTD_FLAG_ADDRESS_RANGE_ALIGNMENT_HINT_MASK	(0x1FU << 5)
152 
153 /**
154  * struct ffa_mapd - Memory access permissions descriptor
155  * @endpoint_id:
156  *         Endpoint id that @memory_access_permissions and @flags apply to.
157  *         (&typedef ffa_endpoint_id16_t).
158  * @memory_access_permissions:
159  *         FFA_MEM_PERM_* values or'ed together (&typedef ffa_mem_perm8_t).
160  * @flags:
161  *         FFA_MEM_FLAG_* values or'ed together (&typedef ffa_mem_flag8_t).
162  */
163 struct ffa_mapd {
164 	ffa_endpoint_id16_t endpoint_id;
165 	ffa_mem_perm8_t memory_access_permissions;
166 	ffa_mem_flag8_t flags;
167 };
168 CASSERT(sizeof(struct ffa_mapd) == 4, assert_ffa_mapd_size_mismatch);
169 
170 /**
171  * struct ffa_emad_v1_0 - Endpoint memory access descriptor.
172  * @mapd:  &struct ffa_mapd.
173  * @comp_mrd_offset:
174  *         Offset of &struct ffa_comp_mrd from start of &struct ffa_mtd_v1_0.
175  * @reserved_8_15:
176  *         Reserved bytes 8-15. Must be 0.
177  */
178 struct ffa_emad_v1_0 {
179 	struct ffa_mapd mapd;
180 	uint32_t comp_mrd_offset;
181 	uint64_t reserved_8_15;
182 };
183 CASSERT(sizeof(struct ffa_emad_v1_0) == 16, assert_ffa_emad_v1_0_size_mismatch);
184 
185 /**
186  * struct ffa_mtd_v1_0 - Memory transaction descriptor.
187  * @sender_id:
188  *         Sender endpoint id.
189  * @memory_region_attributes:
190  *         FFA_MEM_ATTR_* values or'ed together (&typedef ffa_mem_attr8_t).
191  * @reserved_3:
192  *         Reserved bytes 3. Must be 0.
193  * @flags:
194  *         FFA_MTD_FLAG_* values or'ed together (&typedef ffa_mtd_flag32_t).
195  * @handle:
196  *         Id of shared memory object. Must be 0 for MEM_SHARE or MEM_LEND.
197  * @tag:   Client allocated tag. Must match original value.
198  * @reserved_24_27:
199  *         Reserved bytes 24-27. Must be 0.
200  * @emad_count:
201  *         Number of entries in @emad.
202  * @emad:
203  *         Endpoint memory access descriptor array (see @struct ffa_emad_v1_0).
204  */
205 struct ffa_mtd_v1_0 {
206 	ffa_endpoint_id16_t sender_id;
207 	ffa_mem_attr8_t memory_region_attributes;
208 	uint8_t reserved_3;
209 	ffa_mtd_flag32_t flags;
210 	uint64_t handle;
211 	uint64_t tag;
212 	uint32_t reserved_24_27;
213 	uint32_t emad_count;
214 	struct ffa_emad_v1_0 emad[];
215 };
216 CASSERT(sizeof(struct ffa_mtd_v1_0) == 32, assert_ffa_mtd_size_v1_0_mismatch);
217 
218 /**
219  * struct ffa_mtd - Memory transaction descriptor for FF-A v1.1.
220  * @sender_id:
221  *         Sender endpoint id.
222  * @memory_region_attributes:
223  *         FFA_MEM_ATTR_* values or'ed together (&typedef ffa_mem_attr16_t).
224  * @flags:
225  *         FFA_MTD_FLAG_* values or'ed together (&typedef ffa_mtd_flag32_t).
226  * @handle:
227  *         Id of shared memory object. Must be 0 for MEM_SHARE or MEM_LEND.
228  * @tag:   Client allocated tag. Must match original value.
229  * @emad_size:
230  *         Size of the emad descriptor.
231  * @emad_count:
232  *         Number of entries in the emad array.
233  * @emad_offset:
234  *         Offset from the beginning of the descriptor to the location of the
235  *         memory access descriptor array (see @struct ffa_emad_v1_0).
236  * @reserved_36_39:
237  *         Reserved bytes 36-39. Must be 0.
238  * @reserved_40_47:
239  *         Reserved bytes 44-47. Must be 0.
240  */
241 struct ffa_mtd {
242 	ffa_endpoint_id16_t sender_id;
243 	ffa_mem_attr16_t memory_region_attributes;
244 	ffa_mtd_flag32_t flags;
245 	uint64_t handle;
246 	uint64_t tag;
247 	uint32_t emad_size;
248 	uint32_t emad_count;
249 	uint32_t emad_offset;
250 	uint32_t reserved_36_39;
251 	uint64_t reserved_40_47;
252 };
253 CASSERT(sizeof(struct ffa_mtd) == 48, assert_ffa_mtd_size_mismatch);
254 
255 #endif /* EL3_SPMC_FFA_MEM_H */
256