1
2
3
4
5
6
7
8
9
10#ifndef _LINUX_RPMSG_H
11#define _LINUX_RPMSG_H
12
13#include <linux/types.h>
14#include <linux/device.h>
15#include <linux/err.h>
16#include <linux/mod_devicetable.h>
17#include <linux/kref.h>
18#include <linux/mutex.h>
19#include <linux/poll.h>
20#include <linux/rpmsg/byteorder.h>
21#include <uapi/linux/rpmsg.h>
22
23struct rpmsg_device;
24struct rpmsg_endpoint;
25struct rpmsg_device_ops;
26struct rpmsg_endpoint_ops;
27
28
29
30
31
32
33
34struct rpmsg_channel_info {
35 char name[RPMSG_NAME_SIZE];
36 u32 src;
37 u32 dst;
38};
39
40
41
42
43
44
45
46
47
48
49
50
51struct rpmsg_device {
52 struct device dev;
53 struct rpmsg_device_id id;
54 char *driver_override;
55 u32 src;
56 u32 dst;
57 struct rpmsg_endpoint *ept;
58 bool announce;
59 bool little_endian;
60
61 const struct rpmsg_device_ops *ops;
62};
63
64typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32);
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89struct rpmsg_endpoint {
90 struct rpmsg_device *rpdev;
91 struct kref refcount;
92 rpmsg_rx_cb_t cb;
93 struct mutex cb_lock;
94 u32 addr;
95 void *priv;
96
97 const struct rpmsg_endpoint_ops *ops;
98};
99
100
101
102
103
104
105
106
107
108struct rpmsg_driver {
109 struct device_driver drv;
110 const struct rpmsg_device_id *id_table;
111 int (*probe)(struct rpmsg_device *dev);
112 void (*remove)(struct rpmsg_device *dev);
113 int (*callback)(struct rpmsg_device *, void *, int, void *, u32);
114};
115
116static inline u16 rpmsg16_to_cpu(struct rpmsg_device *rpdev, __rpmsg16 val)
117{
118 if (!rpdev)
119 return __rpmsg16_to_cpu(rpmsg_is_little_endian(), val);
120 else
121 return __rpmsg16_to_cpu(rpdev->little_endian, val);
122}
123
124static inline __rpmsg16 cpu_to_rpmsg16(struct rpmsg_device *rpdev, u16 val)
125{
126 if (!rpdev)
127 return __cpu_to_rpmsg16(rpmsg_is_little_endian(), val);
128 else
129 return __cpu_to_rpmsg16(rpdev->little_endian, val);
130}
131
132static inline u32 rpmsg32_to_cpu(struct rpmsg_device *rpdev, __rpmsg32 val)
133{
134 if (!rpdev)
135 return __rpmsg32_to_cpu(rpmsg_is_little_endian(), val);
136 else
137 return __rpmsg32_to_cpu(rpdev->little_endian, val);
138}
139
140static inline __rpmsg32 cpu_to_rpmsg32(struct rpmsg_device *rpdev, u32 val)
141{
142 if (!rpdev)
143 return __cpu_to_rpmsg32(rpmsg_is_little_endian(), val);
144 else
145 return __cpu_to_rpmsg32(rpdev->little_endian, val);
146}
147
148static inline u64 rpmsg64_to_cpu(struct rpmsg_device *rpdev, __rpmsg64 val)
149{
150 if (!rpdev)
151 return __rpmsg64_to_cpu(rpmsg_is_little_endian(), val);
152 else
153 return __rpmsg64_to_cpu(rpdev->little_endian, val);
154}
155
156static inline __rpmsg64 cpu_to_rpmsg64(struct rpmsg_device *rpdev, u64 val)
157{
158 if (!rpdev)
159 return __cpu_to_rpmsg64(rpmsg_is_little_endian(), val);
160 else
161 return __cpu_to_rpmsg64(rpdev->little_endian, val);
162}
163
164#if IS_ENABLED(CONFIG_RPMSG)
165
166int rpmsg_register_device(struct rpmsg_device *rpdev);
167int rpmsg_unregister_device(struct device *parent,
168 struct rpmsg_channel_info *chinfo);
169int __register_rpmsg_driver(struct rpmsg_driver *drv, struct module *owner);
170void unregister_rpmsg_driver(struct rpmsg_driver *drv);
171void rpmsg_destroy_ept(struct rpmsg_endpoint *);
172struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *,
173 rpmsg_rx_cb_t cb, void *priv,
174 struct rpmsg_channel_info chinfo);
175
176int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len);
177int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
178int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
179 void *data, int len);
180
181int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len);
182int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
183int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
184 void *data, int len);
185
186__poll_t rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp,
187 poll_table *wait);
188
189#else
190
191static inline int rpmsg_register_device(struct rpmsg_device *rpdev)
192{
193 return -ENXIO;
194}
195
196static inline int rpmsg_unregister_device(struct device *parent,
197 struct rpmsg_channel_info *chinfo)
198{
199
200 WARN_ON(1);
201
202 return -ENXIO;
203}
204
205static inline int __register_rpmsg_driver(struct rpmsg_driver *drv,
206 struct module *owner)
207{
208
209 WARN_ON(1);
210
211 return -ENXIO;
212}
213
214static inline void unregister_rpmsg_driver(struct rpmsg_driver *drv)
215{
216
217 WARN_ON(1);
218}
219
220static inline void rpmsg_destroy_ept(struct rpmsg_endpoint *ept)
221{
222
223 WARN_ON(1);
224}
225
226static inline struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev,
227 rpmsg_rx_cb_t cb,
228 void *priv,
229 struct rpmsg_channel_info chinfo)
230{
231
232 WARN_ON(1);
233
234 return ERR_PTR(-ENXIO);
235}
236
237static inline int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len)
238{
239
240 WARN_ON(1);
241
242 return -ENXIO;
243}
244
245static inline int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len,
246 u32 dst)
247{
248
249 WARN_ON(1);
250
251 return -ENXIO;
252
253}
254
255static inline int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src,
256 u32 dst, void *data, int len)
257{
258
259 WARN_ON(1);
260
261 return -ENXIO;
262}
263
264static inline int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len)
265{
266
267 WARN_ON(1);
268
269 return -ENXIO;
270}
271
272static inline int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data,
273 int len, u32 dst)
274{
275
276 WARN_ON(1);
277
278 return -ENXIO;
279}
280
281static inline int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src,
282 u32 dst, void *data, int len)
283{
284
285 WARN_ON(1);
286
287 return -ENXIO;
288}
289
290static inline __poll_t rpmsg_poll(struct rpmsg_endpoint *ept,
291 struct file *filp, poll_table *wait)
292{
293
294 WARN_ON(1);
295
296 return 0;
297}
298
299#endif
300
301
302#define register_rpmsg_driver(drv) \
303 __register_rpmsg_driver(drv, THIS_MODULE)
304
305
306
307
308
309
310
311
312
313#define module_rpmsg_driver(__rpmsg_driver) \
314 module_driver(__rpmsg_driver, register_rpmsg_driver, \
315 unregister_rpmsg_driver)
316
317#endif
318