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
21#define RPMSG_ADDR_ANY 0xFFFFFFFF
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
50struct rpmsg_device {
51 struct device dev;
52 struct rpmsg_device_id id;
53 char *driver_override;
54 u32 src;
55 u32 dst;
56 struct rpmsg_endpoint *ept;
57 bool announce;
58
59 const struct rpmsg_device_ops *ops;
60};
61
62typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32);
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87struct rpmsg_endpoint {
88 struct rpmsg_device *rpdev;
89 struct kref refcount;
90 rpmsg_rx_cb_t cb;
91 struct mutex cb_lock;
92 u32 addr;
93 void *priv;
94
95 const struct rpmsg_endpoint_ops *ops;
96};
97
98
99
100
101
102
103
104
105
106struct rpmsg_driver {
107 struct device_driver drv;
108 const struct rpmsg_device_id *id_table;
109 int (*probe)(struct rpmsg_device *dev);
110 void (*remove)(struct rpmsg_device *dev);
111 int (*callback)(struct rpmsg_device *, void *, int, void *, u32);
112};
113
114#if IS_ENABLED(CONFIG_RPMSG)
115
116int register_rpmsg_device(struct rpmsg_device *dev);
117void unregister_rpmsg_device(struct rpmsg_device *dev);
118int __register_rpmsg_driver(struct rpmsg_driver *drv, struct module *owner);
119void unregister_rpmsg_driver(struct rpmsg_driver *drv);
120void rpmsg_destroy_ept(struct rpmsg_endpoint *);
121struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *,
122 rpmsg_rx_cb_t cb, void *priv,
123 struct rpmsg_channel_info chinfo);
124
125int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len);
126int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
127int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
128 void *data, int len);
129
130int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len);
131int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
132int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
133 void *data, int len);
134
135__poll_t rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp,
136 poll_table *wait);
137
138#else
139
140static inline int register_rpmsg_device(struct rpmsg_device *dev)
141{
142 return -ENXIO;
143}
144
145static inline void unregister_rpmsg_device(struct rpmsg_device *dev)
146{
147
148 WARN_ON(1);
149}
150
151static inline int __register_rpmsg_driver(struct rpmsg_driver *drv,
152 struct module *owner)
153{
154
155 WARN_ON(1);
156
157 return -ENXIO;
158}
159
160static inline void unregister_rpmsg_driver(struct rpmsg_driver *drv)
161{
162
163 WARN_ON(1);
164}
165
166static inline void rpmsg_destroy_ept(struct rpmsg_endpoint *ept)
167{
168
169 WARN_ON(1);
170}
171
172static inline struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev,
173 rpmsg_rx_cb_t cb,
174 void *priv,
175 struct rpmsg_channel_info chinfo)
176{
177
178 WARN_ON(1);
179
180 return ERR_PTR(-ENXIO);
181}
182
183static inline int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len)
184{
185
186 WARN_ON(1);
187
188 return -ENXIO;
189}
190
191static inline int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len,
192 u32 dst)
193{
194
195 WARN_ON(1);
196
197 return -ENXIO;
198
199}
200
201static inline int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src,
202 u32 dst, void *data, int len)
203{
204
205 WARN_ON(1);
206
207 return -ENXIO;
208}
209
210static inline int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len)
211{
212
213 WARN_ON(1);
214
215 return -ENXIO;
216}
217
218static inline int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data,
219 int len, u32 dst)
220{
221
222 WARN_ON(1);
223
224 return -ENXIO;
225}
226
227static inline int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src,
228 u32 dst, void *data, int len)
229{
230
231 WARN_ON(1);
232
233 return -ENXIO;
234}
235
236static inline __poll_t rpmsg_poll(struct rpmsg_endpoint *ept,
237 struct file *filp, poll_table *wait)
238{
239
240 WARN_ON(1);
241
242 return 0;
243}
244
245#endif
246
247
248#define register_rpmsg_driver(drv) \
249 __register_rpmsg_driver(drv, THIS_MODULE)
250
251
252
253
254
255
256
257
258
259#define module_rpmsg_driver(__rpmsg_driver) \
260 module_driver(__rpmsg_driver, register_rpmsg_driver, \
261 unregister_rpmsg_driver)
262
263#endif
264