Skip to content

Commit 84d5813

Browse files
committed
rpmsg: Introduce "poll" to endpoint ops
This allows rpmsg backends to implement polling of the outgoing buffer, which provides poll support to user space when using the rpmsg character device. Signed-off-by: Bjorn Andersson <[email protected]>
1 parent 5e53c42 commit 84d5813

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

drivers/rpmsg/rpmsg_core.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,26 @@ int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)
239239
}
240240
EXPORT_SYMBOL(rpmsg_trysendto);
241241

242+
/**
243+
* rpmsg_poll() - poll the endpoint's send buffers
244+
* @ept: the rpmsg endpoint
245+
* @filp: file for poll_wait()
246+
* @wait: poll_table for poll_wait()
247+
*
248+
* Returns mask representing the current state of the endpoint's send buffers
249+
*/
250+
unsigned int rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp,
251+
poll_table *wait)
252+
{
253+
if (WARN_ON(!ept))
254+
return 0;
255+
if (!ept->ops->poll)
256+
return 0;
257+
258+
return ept->ops->poll(ept, filp, wait);
259+
}
260+
EXPORT_SYMBOL(rpmsg_poll);
261+
242262
/**
243263
* rpmsg_send_offchannel() - send a message using explicit src/dst addresses
244264
* @ept: the rpmsg endpoint

drivers/rpmsg/rpmsg_internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define __RPMSG_INTERNAL_H__
2222

2323
#include <linux/rpmsg.h>
24+
#include <linux/poll.h>
2425

2526
#define to_rpmsg_device(d) container_of(d, struct rpmsg_device, dev)
2627
#define to_rpmsg_driver(d) container_of(d, struct rpmsg_driver, drv)
@@ -70,6 +71,8 @@ struct rpmsg_endpoint_ops {
7071
int (*trysendto)(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
7172
int (*trysend_offchannel)(struct rpmsg_endpoint *ept, u32 src, u32 dst,
7273
void *data, int len);
74+
unsigned int (*poll)(struct rpmsg_endpoint *ept, struct file *filp,
75+
poll_table *wait);
7376
};
7477

7578
int rpmsg_register_device(struct rpmsg_device *rpdev);

include/linux/rpmsg.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <linux/mod_devicetable.h>
4242
#include <linux/kref.h>
4343
#include <linux/mutex.h>
44+
#include <linux/poll.h>
4445

4546
#define RPMSG_ADDR_ANY 0xFFFFFFFF
4647

@@ -156,6 +157,9 @@ int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
156157
int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
157158
void *data, int len);
158159

160+
unsigned int rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp,
161+
poll_table *wait);
162+
159163
#else
160164

161165
static inline int register_rpmsg_device(struct rpmsg_device *dev)
@@ -254,6 +258,15 @@ static inline int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src,
254258
return -ENXIO;
255259
}
256260

261+
static inline unsigned int rpmsg_poll(struct rpmsg_endpoint *ept,
262+
struct file *filp, poll_table *wait)
263+
{
264+
/* This shouldn't be possible */
265+
WARN_ON(1);
266+
267+
return 0;
268+
}
269+
257270
#endif /* IS_ENABLED(CONFIG_RPMSG) */
258271

259272
/* use a macro to avoid include chaining to get THIS_MODULE */

0 commit comments

Comments
 (0)