1
2
3
4
5
6#ifndef _LINUX_ARM_FFA_H
7#define _LINUX_ARM_FFA_H
8
9#include <linux/device.h>
10#include <linux/module.h>
11#include <linux/types.h>
12#include <linux/uuid.h>
13
14
15struct ffa_device {
16 int vm_id;
17 bool mode_32bit;
18 uuid_t uuid;
19 struct device dev;
20};
21
22#define to_ffa_dev(d) container_of(d, struct ffa_device, dev)
23
24struct ffa_device_id {
25 uuid_t uuid;
26};
27
28struct ffa_driver {
29 const char *name;
30 int (*probe)(struct ffa_device *sdev);
31 void (*remove)(struct ffa_device *sdev);
32 const struct ffa_device_id *id_table;
33
34 struct device_driver driver;
35};
36
37#define to_ffa_driver(d) container_of(d, struct ffa_driver, driver)
38
39static inline void ffa_dev_set_drvdata(struct ffa_device *fdev, void *data)
40{
41 fdev->dev.driver_data = data;
42}
43
44#if IS_REACHABLE(CONFIG_ARM_FFA_TRANSPORT)
45struct ffa_device *ffa_device_register(const uuid_t *uuid, int vm_id);
46void ffa_device_unregister(struct ffa_device *ffa_dev);
47int ffa_driver_register(struct ffa_driver *driver, struct module *owner,
48 const char *mod_name);
49void ffa_driver_unregister(struct ffa_driver *driver);
50bool ffa_device_is_valid(struct ffa_device *ffa_dev);
51const struct ffa_dev_ops *ffa_dev_ops_get(struct ffa_device *dev);
52
53#else
54static inline
55struct ffa_device *ffa_device_register(const uuid_t *uuid, int vm_id)
56{
57 return NULL;
58}
59
60static inline void ffa_device_unregister(struct ffa_device *dev) {}
61
62static inline int
63ffa_driver_register(struct ffa_driver *driver, struct module *owner,
64 const char *mod_name)
65{
66 return -EINVAL;
67}
68
69static inline void ffa_driver_unregister(struct ffa_driver *driver) {}
70
71static inline
72bool ffa_device_is_valid(struct ffa_device *ffa_dev) { return false; }
73
74static inline
75const struct ffa_dev_ops *ffa_dev_ops_get(struct ffa_device *dev)
76{
77 return NULL;
78}
79#endif
80
81#define ffa_register(driver) \
82 ffa_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
83#define ffa_unregister(driver) \
84 ffa_driver_unregister(driver)
85
86
87
88
89
90
91
92
93
94#define module_ffa_driver(__ffa_driver) \
95 module_driver(__ffa_driver, ffa_register, ffa_unregister)
96
97
98struct ffa_partition_info {
99 u16 id;
100 u16 exec_ctxt;
101
102#define FFA_PARTITION_DIRECT_RECV BIT(0)
103
104#define FFA_PARTITION_DIRECT_SEND BIT(1)
105
106#define FFA_PARTITION_INDIRECT_MSG BIT(2)
107 u32 properties;
108};
109
110
111struct ffa_send_direct_data {
112 unsigned long data0;
113 unsigned long data1;
114 unsigned long data2;
115 unsigned long data3;
116 unsigned long data4;
117};
118
119struct ffa_mem_region_addr_range {
120
121 u64 address;
122
123 u32 pg_cnt;
124 u32 reserved;
125};
126
127struct ffa_composite_mem_region {
128
129
130
131
132
133 u32 total_pg_cnt;
134
135 u32 addr_range_cnt;
136 u64 reserved;
137
138 struct ffa_mem_region_addr_range constituents[];
139};
140
141struct ffa_mem_region_attributes {
142
143 u16 receiver;
144
145
146
147
148#define FFA_MEM_EXEC BIT(3)
149#define FFA_MEM_NO_EXEC BIT(2)
150#define FFA_MEM_RW BIT(1)
151#define FFA_MEM_RO BIT(0)
152 u8 attrs;
153
154
155
156
157#define FFA_MEM_RETRIEVE_SELF_BORROWER BIT(0)
158 u8 flag;
159 u32 composite_off;
160
161
162
163
164 u64 reserved;
165};
166
167struct ffa_mem_region {
168
169 u16 sender_id;
170#define FFA_MEM_NORMAL BIT(5)
171#define FFA_MEM_DEVICE BIT(4)
172
173#define FFA_MEM_WRITE_BACK (3 << 2)
174#define FFA_MEM_NON_CACHEABLE (1 << 2)
175
176#define FFA_DEV_nGnRnE (0 << 2)
177#define FFA_DEV_nGnRE (1 << 2)
178#define FFA_DEV_nGRE (2 << 2)
179#define FFA_DEV_GRE (3 << 2)
180
181#define FFA_MEM_NON_SHAREABLE (0)
182#define FFA_MEM_OUTER_SHAREABLE (2)
183#define FFA_MEM_INNER_SHAREABLE (3)
184 u8 attributes;
185 u8 reserved_0;
186
187
188
189
190#define FFA_MEM_CLEAR BIT(0)
191
192
193
194
195#define FFA_TIME_SLICE_ENABLE BIT(1)
196
197#define FFA_MEM_RETRIEVE_TYPE_IN_RESP (0 << 3)
198#define FFA_MEM_RETRIEVE_TYPE_SHARE (1 << 3)
199#define FFA_MEM_RETRIEVE_TYPE_LEND (2 << 3)
200#define FFA_MEM_RETRIEVE_TYPE_DONATE (3 << 3)
201
202#define FFA_MEM_RETRIEVE_ADDR_ALIGN_HINT BIT(9)
203#define FFA_MEM_RETRIEVE_ADDR_ALIGN(x) ((x) << 5)
204
205 u32 flags;
206#define HANDLE_LOW_MASK GENMASK_ULL(31, 0)
207#define HANDLE_HIGH_MASK GENMASK_ULL(63, 32)
208#define HANDLE_LOW(x) ((u32)(FIELD_GET(HANDLE_LOW_MASK, (x))))
209#define HANDLE_HIGH(x) ((u32)(FIELD_GET(HANDLE_HIGH_MASK, (x))))
210
211#define PACK_HANDLE(l, h) \
212 (FIELD_PREP(HANDLE_LOW_MASK, (l)) | FIELD_PREP(HANDLE_HIGH_MASK, (h)))
213
214
215
216
217 u64 handle;
218
219
220
221
222 u64 tag;
223 u32 reserved_1;
224
225
226
227
228 u32 ep_count;
229
230
231
232
233
234
235 struct ffa_mem_region_attributes ep_mem_access[];
236};
237
238#define COMPOSITE_OFFSET(x) \
239 (offsetof(struct ffa_mem_region, ep_mem_access[x]))
240#define CONSTITUENTS_OFFSET(x) \
241 (offsetof(struct ffa_composite_mem_region, constituents[x]))
242#define COMPOSITE_CONSTITUENTS_OFFSET(x, y) \
243 (COMPOSITE_OFFSET(x) + CONSTITUENTS_OFFSET(y))
244
245struct ffa_mem_ops_args {
246 bool use_txbuf;
247 u32 nattrs;
248 u32 flags;
249 u64 tag;
250 u64 g_handle;
251 struct scatterlist *sg;
252 struct ffa_mem_region_attributes *attrs;
253};
254
255struct ffa_dev_ops {
256 u32 (*api_version_get)(void);
257 int (*partition_info_get)(const char *uuid_str,
258 struct ffa_partition_info *buffer);
259 void (*mode_32bit_set)(struct ffa_device *dev);
260 int (*sync_send_receive)(struct ffa_device *dev,
261 struct ffa_send_direct_data *data);
262 int (*memory_reclaim)(u64 g_handle, u32 flags);
263 int (*memory_share)(struct ffa_device *dev,
264 struct ffa_mem_ops_args *args);
265};
266
267#endif
268