@@ -96,8 +96,10 @@ enum rpmsg_ns_flags {
9696#define RPMSG_ADDR_ANY 0xFFFFFFFF
9797
9898struct virtproc_info ;
99+ struct rpmsg_device ;
99100struct rpmsg_endpoint ;
100101struct rpmsg_device_ops ;
102+ struct rpmsg_endpoint_ops ;
101103
102104/**
103105 * struct rpmsg_channel_info - channel info representation
@@ -184,6 +186,36 @@ struct rpmsg_endpoint {
184186 struct mutex cb_lock ;
185187 u32 addr ;
186188 void * priv ;
189+
190+ const struct rpmsg_endpoint_ops * ops ;
191+ };
192+
193+ /**
194+ * struct rpmsg_endpoint_ops - indirection table for rpmsg_endpoint operations
195+ * @destroy_ept: destroy the given endpoint, required
196+ * @send: see @rpmsg_send(), required
197+ * @sendto: see @rpmsg_sendto(), optional
198+ * @send_offchannel: see @rpmsg_send_offchannel(), optional
199+ * @trysend: see @rpmsg_trysend(), required
200+ * @trysendto: see @rpmsg_trysendto(), optional
201+ * @trysend_offchannel: see @rpmsg_trysend_offchannel(), optional
202+ *
203+ * Indirection table for the operations that a rpmsg backend should implement.
204+ * In addition to @destroy_ept, the backend must at least implement @send and
205+ * @trysend, while the variants sending data off-channel are optional.
206+ */
207+ struct rpmsg_endpoint_ops {
208+ void (* destroy_ept )(struct rpmsg_endpoint * ept );
209+
210+ int (* send )(struct rpmsg_endpoint * ept , void * data , int len );
211+ int (* sendto )(struct rpmsg_endpoint * ept , void * data , int len , u32 dst );
212+ int (* send_offchannel )(struct rpmsg_endpoint * ept , u32 src , u32 dst ,
213+ void * data , int len );
214+
215+ int (* trysend )(struct rpmsg_endpoint * ept , void * data , int len );
216+ int (* trysendto )(struct rpmsg_endpoint * ept , void * data , int len , u32 dst );
217+ int (* trysend_offchannel )(struct rpmsg_endpoint * ept , u32 src , u32 dst ,
218+ void * data , int len );
187219};
188220
189221/**
@@ -210,8 +242,6 @@ void rpmsg_destroy_ept(struct rpmsg_endpoint *);
210242struct rpmsg_endpoint * rpmsg_create_ept (struct rpmsg_device * ,
211243 rpmsg_rx_cb_t cb , void * priv ,
212244 struct rpmsg_channel_info chinfo );
213- int
214- rpmsg_send_offchannel_raw (struct rpmsg_device * , u32 , u32 , void * , int , bool );
215245
216246/* use a macro to avoid include chaining to get THIS_MODULE */
217247#define register_rpmsg_driver (drv ) \
@@ -249,10 +279,7 @@ rpmsg_send_offchannel_raw(struct rpmsg_device *, u32, u32, void *, int, bool);
249279 */
250280static inline int rpmsg_send (struct rpmsg_endpoint * ept , void * data , int len )
251281{
252- struct rpmsg_device * rpdev = ept -> rpdev ;
253- u32 src = ept -> addr , dst = rpdev -> dst ;
254-
255- return rpmsg_send_offchannel_raw (rpdev , src , dst , data , len , true);
282+ return ept -> ops -> send (ept , data , len );
256283}
257284
258285/**
@@ -276,10 +303,7 @@ static inline int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len)
276303static inline
277304int rpmsg_sendto (struct rpmsg_endpoint * ept , void * data , int len , u32 dst )
278305{
279- struct rpmsg_device * rpdev = ept -> rpdev ;
280- u32 src = ept -> addr ;
281-
282- return rpmsg_send_offchannel_raw (rpdev , src , dst , data , len , true);
306+ return ept -> ops -> sendto (ept , data , len , dst );
283307}
284308
285309/**
@@ -306,9 +330,7 @@ static inline
306330int rpmsg_send_offchannel (struct rpmsg_endpoint * ept , u32 src , u32 dst ,
307331 void * data , int len )
308332{
309- struct rpmsg_device * rpdev = ept -> rpdev ;
310-
311- return rpmsg_send_offchannel_raw (rpdev , src , dst , data , len , true);
333+ return ept -> ops -> send_offchannel (ept , src , dst , data , len );
312334}
313335
314336/**
@@ -331,10 +353,7 @@ int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
331353static inline
332354int rpmsg_trysend (struct rpmsg_endpoint * ept , void * data , int len )
333355{
334- struct rpmsg_device * rpdev = ept -> rpdev ;
335- u32 src = ept -> addr , dst = rpdev -> dst ;
336-
337- return rpmsg_send_offchannel_raw (rpdev , src , dst , data , len , false);
356+ return ept -> ops -> trysend (ept , data , len );
338357}
339358
340359/**
@@ -357,10 +376,7 @@ int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len)
357376static inline
358377int rpmsg_trysendto (struct rpmsg_endpoint * ept , void * data , int len , u32 dst )
359378{
360- struct rpmsg_device * rpdev = ept -> rpdev ;
361- u32 src = ept -> addr ;
362-
363- return rpmsg_send_offchannel_raw (rpdev , src , dst , data , len , false);
379+ return ept -> ops -> trysendto (ept , data , len , dst );
364380}
365381
366382/**
@@ -386,9 +402,7 @@ static inline
386402int rpmsg_trysend_offchannel (struct rpmsg_endpoint * ept , u32 src , u32 dst ,
387403 void * data , int len )
388404{
389- struct rpmsg_device * rpdev = ept -> rpdev ;
390-
391- return rpmsg_send_offchannel_raw (rpdev , src , dst , data , len , false);
405+ return ept -> ops -> trysend_offchannel (ept , src , dst , data , len );
392406}
393407
394408#endif /* _LINUX_RPMSG_H */
0 commit comments