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

[Minios-devel] [UNIKRAFT PATCH 4/5] plat/drivers: Add 9P transport for virtio 9P



This patch adds the 9P transport driver skeleton for virtio 9P devices,
by providing the required connect, disconnect and request callbacks. The
request callback is left as a stub to be implemented in the following
patches.

Signed-off-by: Cristian Banu <cristb@xxxxxxxxx>
---
 plat/drivers/virtio/virtio_9p.c | 84 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff --git a/plat/drivers/virtio/virtio_9p.c b/plat/drivers/virtio/virtio_9p.c
index ab3a1b1679de..08b2eb62a273 100644
--- a/plat/drivers/virtio/virtio_9p.c
+++ b/plat/drivers/virtio/virtio_9p.c
@@ -35,6 +35,7 @@
 #include <inttypes.h>
 #include <uk/alloc.h>
 #include <uk/essentials.h>
+#include <uk/9pdev_trans.h>
 #include <virtio/virtio_bus.h>
 #include <virtio/virtio_9p.h>
 #include <uk/plat/spinlock.h>
@@ -58,6 +59,86 @@ struct virtio_9p_device {
        struct virtqueue *vq;
        /* Hw queue identifier. */
        uint16_t hwvq_id;
+       /* libuk9p associated device (NULL if the device is not in use). */
+       struct uk_9pdev *p9dev;
+};
+
+static int virtio_9p_connect(struct uk_9pdev *p9dev,
+                            const char *device_identifier,
+                            const char *mount_args __unused)
+{
+       struct virtio_9p_device *dev = NULL;
+       int rc = 0;
+       int found = 0;
+       unsigned long flags;
+
+       ukplat_spin_lock_irqsave(&virtio_9p_device_list_lock, flags);
+       uk_list_for_each_entry(dev, &virtio_9p_device_list, _list) {
+               if (!strcmp(dev->tag, device_identifier)) {
+                       if (dev->p9dev != NULL) {
+                               rc = -EBUSY;
+                               goto out;
+                       }
+                       found = 1;
+                       break;
+               }
+       }
+
+       if (!found) {
+               rc = -EINVAL;
+               goto out;
+       }
+
+       /*
+        * The maximum message size is given by the number of segments.
+        *
+        * For read requests, the reply will be able to make use of the large
+        * msize, and the request will not exceed one segment.
+        * Similarly for write requests, but in reverse. Other requests should
+        * not exceed one page for both recv and xmit fcalls.
+        */
+       p9dev->msize = (NUM_SEGMENTS - 1) * __PAGE_SIZE;
+
+       dev->p9dev = p9dev;
+       p9dev->priv = dev;
+
+out:
+       ukplat_spin_unlock_irqrestore(&virtio_9p_device_list_lock, flags);
+       return rc;
+}
+
+static int virtio_9p_disconnect(struct uk_9pdev *p9dev)
+{
+       struct virtio_9p_device *dev;
+       unsigned long flags;
+
+       UK_ASSERT(p9dev);
+       dev = p9dev->priv;
+
+       ukplat_spin_lock_irqsave(&virtio_9p_device_list_lock, flags);
+       dev->p9dev = NULL;
+       ukplat_spin_unlock_irqrestore(&virtio_9p_device_list_lock, flags);
+
+       return 0;
+}
+
+static int virtio_9p_request(struct uk_9pdev *p9dev __unused,
+                            struct uk_9preq *req __unused)
+{
+       return -EOPNOTSUPP;
+}
+
+static const struct uk_9pdev_trans_ops v9p_trans_ops = {
+       .connect        = virtio_9p_connect,
+       .disconnect     = virtio_9p_disconnect,
+       .request        = virtio_9p_request
+};
+
+static struct uk_9pdev_trans v9p_trans = {
+       .name           = "virtio",
+       .ops            = &v9p_trans_ops,
+       .is_default     = 1,
+       .a              = NULL /* Set by the driver initialization. */
 };
 
 static int virtio_9p_recv(struct virtqueue *vq __unused, void *priv __unused)
@@ -224,6 +305,9 @@ static int virtio_9p_drv_init(struct uk_alloc 
*drv_allocator)
        }
 
        a = drv_allocator;
+       v9p_trans.a = a;
+
+       rc = uk_9pdev_trans_register(&v9p_trans);
 out:
        return rc;
 }
-- 
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®.