bindings: Add mctp_*_init_pollfd() API

The new API allows the binding to own the poll(2) parameters, providing
the opportunity for it to properly idle when it's unable to send control
messages. Despite this, we hold off on adjusting the behaviour directly
in this commit, as it would constitute a regression until
mctp-demux-daemon has also been converted to exploit the new API.

Change-Id: Ic5a7c5a943566a0f36695daa64457440886fb2ab
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/astlpc.c b/astlpc.c
index 8d316e3..4e9e349 100644
--- a/astlpc.c
+++ b/astlpc.c
@@ -30,6 +30,7 @@
 
 #include <unistd.h>
 #include <fcntl.h>
+#include <poll.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <linux/aspeed-lpc-ctrl.h>
@@ -1311,6 +1312,15 @@
 	return astlpc->kcs_fd;
 }
 
+int mctp_astlpc_init_pollfd(struct mctp_binding_astlpc *astlpc,
+			    struct pollfd *pollfd)
+{
+	pollfd->fd = astlpc->kcs_fd;
+	pollfd->events = POLLIN;
+
+	return 0;
+}
+
 struct mctp_binding_astlpc *mctp_astlpc_init_fileio(void)
 {
 	struct mctp_binding_astlpc *astlpc;
@@ -1359,4 +1369,11 @@
 	mctp_prlog(MCTP_LOG_ERR, "%s: Missing support for file IO", __func__);
 	return -1;
 }
+
+int mctp_astlpc_init_pollfd(struct mctp_binding_astlpc *astlpc __unused,
+			    struct pollfd *pollfd __unused)
+{
+	mctp_prlog(MCTP_LOG_ERR, "%s: Missing support for file IO", __func__);
+	return -1;
+}
 #endif
diff --git a/libmctp-astlpc.h b/libmctp-astlpc.h
index f324b90..243ddd7 100644
--- a/libmctp-astlpc.h
+++ b/libmctp-astlpc.h
@@ -47,6 +47,10 @@
 struct mctp_binding_astlpc *mctp_astlpc_init_fileio(void);
 int mctp_astlpc_get_fd(struct mctp_binding_astlpc *astlpc);
 
+struct pollfd;
+int mctp_astlpc_init_pollfd(struct mctp_binding_astlpc *astlpc,
+			    struct pollfd *pollfd);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/libmctp-serial.h b/libmctp-serial.h
index 8a70101..7d3d6cb 100644
--- a/libmctp-serial.h
+++ b/libmctp-serial.h
@@ -18,6 +18,11 @@
 
 /* file-based IO */
 int mctp_serial_get_fd(struct mctp_binding_serial *serial);
+
+struct pollfd;
+int mctp_serial_init_pollfd(struct mctp_binding_serial *serial,
+			    struct pollfd *pollfd);
+
 int mctp_serial_read(struct mctp_binding_serial *serial);
 int mctp_serial_open_path(struct mctp_binding_serial *serial,
 		const char *path);
diff --git a/serial.c b/serial.c
index ac91eb4..b12fcfb 100644
--- a/serial.c
+++ b/serial.c
@@ -10,8 +10,9 @@
 #endif
 
 #ifdef MCTP_HAVE_FILEIO
-#include <unistd.h>
 #include <fcntl.h>
+#include <poll.h>
+#include <unistd.h>
 #else
 static const size_t write(int fd, void *buf, size_t len)
 {
@@ -41,9 +42,9 @@
 #include "container_of.h"
 
 struct mctp_binding_serial {
-	struct mctp_binding	binding;
-	int			fd;
-	unsigned long		bus_id;
+	struct mctp_binding binding;
+	int fd;
+	unsigned long bus_id;
 
 	mctp_serial_tx_fn	tx_fn;
 	void			*tx_fn_data;
@@ -291,6 +292,15 @@
 	return serial->fd;
 }
 
+int mctp_serial_init_pollfd(struct mctp_binding_serial *serial,
+			    struct pollfd *pollfd)
+{
+	pollfd->fd = serial->fd;
+	pollfd->events = POLLIN;
+
+	return 0;
+}
+
 int mctp_serial_open_path(struct mctp_binding_serial *serial,
 		const char *device)
 {