[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v2 6/7] lib/ukconsdev: Receive/Transmit from console



Signed-off-by: Birlea Costin <costin.birlea@xxxxxxxxx>
---
 lib/ukconsdev/consdev.c                 | 30 +++++++++++++++++++++++++
 lib/ukconsdev/exportsyms.uk             |  2 ++
 lib/ukconsdev/include/uk/consdev.h      | 40 +++++++++++++++++++++++++++++++++
 lib/ukconsdev/include/uk/consdev_core.h | 10 +++++++++
 4 files changed, 82 insertions(+)

diff --git a/lib/ukconsdev/consdev.c b/lib/ukconsdev/consdev.c
index 1de68b77..774199dc 100644
--- a/lib/ukconsdev/consdev.c
+++ b/lib/ukconsdev/consdev.c
@@ -347,6 +347,34 @@ out:
        return rc;
 }
 
+unsigned int uk_consdev_transmit(struct uk_consdev *dev,
+               const char *buf, unsigned int len)
+{
+       UK_ASSERT(dev);
+       UK_ASSERT(dev->_data);
+       UK_ASSERT(dev->ops);
+       UK_ASSERT(dev->ops->transmit);
+
+       if (dev->_data->state != UK_CONSDEV_RUNNING)
+               return -EINVAL;
+
+       return dev->ops->transmit(dev, buf, len);
+}
+
+unsigned int uk_consdev_receive(struct uk_consdev *dev,
+               char *buf, unsigned int len)
+{
+       UK_ASSERT(dev);
+       UK_ASSERT(dev->_data);
+       UK_ASSERT(dev->ops);
+       UK_ASSERT(dev->ops->receive);
+
+       if (dev->_data->state != UK_CONSDEV_RUNNING)
+               return -EINVAL;
+
+       return dev->ops->receive(dev, buf, len);
+}
+
 unsigned int uk_consdev_count(void)
 {
        return (unsigned int) consdev_count;
@@ -423,6 +451,8 @@ int uk_consdev_drv_register(struct uk_consdev *dev, struct 
uk_alloc *a,
        UK_ASSERT(dev->ops->unconfigure);
        UK_ASSERT(dev->ops->start);
        UK_ASSERT(dev->ops->stop);
+       UK_ASSERT(dev->ops->transmit);
+       UK_ASSERT(dev->ops->receive);
 
        dev->_data = _alloc_data(a, consdev_count, drv_name);
        if (!dev->_data)
diff --git a/lib/ukconsdev/exportsyms.uk b/lib/ukconsdev/exportsyms.uk
index 55e744fd..dec7a21d 100644
--- a/lib/ukconsdev/exportsyms.uk
+++ b/lib/ukconsdev/exportsyms.uk
@@ -7,6 +7,8 @@ uk_consdev_txq_configure
 uk_consdev_unconfigure
 uk_consdev_start
 uk_consdev_stop
+uk_consdev_transmit
+uk_consdev_receive
 uk_consdev_count
 uk_consdev_get
 uk_consdev_id_get
diff --git a/lib/ukconsdev/include/uk/consdev.h 
b/lib/ukconsdev/include/uk/consdev.h
index 24ac21b9..3fcfb9ae 100644
--- a/lib/ukconsdev/include/uk/consdev.h
+++ b/lib/ukconsdev/include/uk/consdev.h
@@ -219,6 +219,46 @@ int uk_consdev_start(struct uk_consdev *dev);
 int uk_consdev_stop(struct uk_consdev *dev);
 
 /**
+ * Transmit to a Console Device - Asynchronous
+ *
+ * @param dev
+ *  The Unikraft Console Device in running state.
+ * @param buf
+ *  Pointer from which to transmit to the queue.
+ * @param len
+ *  How many bytes to take from buf and transmit to queue.
+ * @return
+ *     - (0): Queue is full.
+ *     - (>0): Number of bytes transmitted.
+ *     - (<0): Error code of the driver device, transmit failed.
+ */
+unsigned int uk_consdev_transmit(struct uk_consdev *dev,
+               const char *buf, unsigned int len);
+
+/**
+ * Receive from a Console Device - Asynchronous
+ *
+ * Interrupts have to be disabled when calling receive.
+ * If callback is provided, interrupts are disabled when
+ * entering the callback.
+ * uk_consdev_receive() is going to enable interrupts when
+ * returning received data.
+ *
+ * @param dev
+ *  The Unikraft Console Device in running state.
+ * @param buf
+ *  Pointer where to put bytes received from queue.
+ * @param len
+ *  How many bytes to receive from queue.
+ * @return
+ *     - (0): Queue is empty.
+ *     - (>0): Number of bytes received.
+ *     - (<0): Error code of the driver device, receive failed.
+ */
+unsigned int uk_consdev_receive(struct uk_consdev *dev,
+               char *buf, unsigned int len);
+
+/**
  * Get the number of available Unikraft Console devices.
  *
  * @return
diff --git a/lib/ukconsdev/include/uk/consdev_core.h 
b/lib/ukconsdev/include/uk/consdev_core.h
index a8353d10..35660653 100644
--- a/lib/ukconsdev/include/uk/consdev_core.h
+++ b/lib/ukconsdev/include/uk/consdev_core.h
@@ -176,6 +176,14 @@ typedef int (*uk_consdev_start_t)(struct uk_consdev *dev);
 /** Driver callback type to stop a running Unikraft console device. */
 typedef int (*uk_consdev_stop_t)(struct uk_consdev *dev);
 
+/** Driver callback type to transmit to a running Unikraft console device. */
+typedef unsigned int (*uk_consdev_transmit_t)(struct uk_consdev *dev,
+               const char *buf, unsigned int len);
+
+/** Driver callback type to receive to a running Unikraft console device. */
+typedef unsigned int (*uk_consdev_receive_t)(struct uk_consdev *dev,
+               char *buf, unsigned int len);
+
 struct uk_consdev_ops {
        uk_consdev_info_t                   info_get;
        uk_consdev_configure_t              configure;
@@ -186,6 +194,8 @@ struct uk_consdev_ops {
        uk_consdev_unconfigure_t            unconfigure;
        uk_consdev_start_t                  start;
        uk_consdev_stop_t                   stop;
+       uk_consdev_transmit_t               transmit;
+       uk_consdev_receive_t                receive;
 };
 
 /**
-- 
2.11.0


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.