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

[Minios-devel] [UNIKRAFT PATCH 09/10] plat/xen/drivers/cons: Read from Consfront



Signed-off-by: Birlea Costin <costin.birlea@xxxxxxxxx>
---
 plat/xen/drivers/cons/consfront.c | 69 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/plat/xen/drivers/cons/consfront.c 
b/plat/xen/drivers/cons/consfront.c
index 5e1aa063..6dd8a6f8 100644
--- a/plat/xen/drivers/cons/consfront.c
+++ b/plat/xen/drivers/cons/consfront.c
@@ -313,6 +313,74 @@ static unsigned int consfront_write(struct uk_consdev *dev,
        return pvconsole_output(cfdev, buf, len);
 }
 
+static unsigned int pvconsole_input(struct consfront_dev *cfdev,
+                               char *buf, unsigned int len)
+{
+       struct xencons_interface *intf;
+       XENCONS_RING_IDX cons, prod;
+       unsigned int read = 0;
+       unsigned int index;
+
+       intf = cfdev->ring;
+       UK_ASSERT(intf);
+
+       cons = intf->in_cons;
+       prod = intf->in_prod;
+
+       /* Make sure we have cons & prod before touching the ring */
+       mb();
+       UK_BUGON((prod - cons) > sizeof(intf->in));
+
+       while ((read < len) && (cons != prod)) {
+               index = MASK_XENCONS_IDX(cons++, intf->in);
+               *(buf + read) = *(intf->in + index);
+               read++;
+       }
+
+       /* Ensure characters are written before increasing in_cons */
+       mb();
+       intf->in_cons = cons;
+
+       return read;
+}
+
+static unsigned int consfront_read(struct uk_consdev *dev,
+                               char *buf, unsigned int len)
+{
+       struct consfront_dev *cfdev;
+       struct xencons_interface *intf;
+       XENCONS_RING_IDX cons, prod;
+       unsigned int sent = 0;
+       unsigned int available = 0;
+
+       UK_ASSERT(dev);
+
+       cfdev = to_consfront(dev);
+       UK_ASSERT(cfdev);
+
+       intf = cfdev->ring;
+       UK_ASSERT(intf);
+
+       cons = intf->in_cons;
+       prod = intf->in_prod;
+
+       /* Make sure we have cons & prod */
+       mb();
+       UK_BUGON((prod - cons) > sizeof(intf->in));
+
+       available = prod - cons;
+
+       if (!available)
+               return sent;
+
+       if (available < len)
+               sent = pvconsole_input(cfdev, buf, available);
+       else
+               sent = pvconsole_input(cfdev, buf, len);
+
+       return sent;
+}
+
 static void consfront_close(struct uk_consdev *dev)
 {
        struct consfront_dev *cfdev;
@@ -340,6 +408,7 @@ static const struct uk_consdev_ops consfront_ops = {
        .start = consfront_start,
        .stop = consfront_stop,
        .write = consfront_write,
+       .read = consfront_read,
        .close = consfront_close,
 };
 
-- 
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®.