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

[Minios-devel] [UNIKRAFT PATCH 06/10] plat/xen/drivers/cons: Configure Consfront



This patch provides configure which and intializes
the ring. Grants access to backend.

Signed-off-by: Birlea Costin <costin.birlea@xxxxxxxxx>
---
 plat/xen/drivers/cons/consfront.c | 130 ++++++++++++++++++++++++++++++++++++++
 plat/xen/drivers/cons/consfront.h |   6 ++
 2 files changed, 136 insertions(+)

diff --git a/plat/xen/drivers/cons/consfront.c 
b/plat/xen/drivers/cons/consfront.c
index 33adabf7..cdbed0f5 100644
--- a/plat/xen/drivers/cons/consfront.c
+++ b/plat/xen/drivers/cons/consfront.c
@@ -60,6 +60,21 @@
 
 static struct uk_alloc *drv_allocator;
 
+static void consfront_rx_handler(evtchn_port_t port __unused,
+               struct __regs *regs __unused,
+               void *data __unused)
+{
+       struct uk_consdev *dev = (struct uk_consdev *) data;
+       struct consfront_dev *cfdev;
+
+       cfdev = to_consfront(dev);
+       UK_ASSERT(cfdev);
+
+       mask_evtchn(cfdev->evtchn);
+
+       uk_consdev_drv_rx_event(dev);
+}
+
 static void consfront_info_get(struct uk_consdev *dev __unused,
                struct uk_consdev_info *dev_info)
 {
@@ -90,6 +105,117 @@ static int consfront_tx_info_get(struct uk_consdev *dev 
__unused,
        return 0;
 }
 
+static int consfront_ring_init(struct consfront_dev *cfdev)
+{
+       struct xenbus_device *xendev;
+
+       xendev = cfdev->xendev;
+
+       cfdev->ring = uk_malloc_page(drv_allocator);
+       if (!cfdev->ring)
+               return -ENOMEM;
+       memset(cfdev->ring, 0, PAGE_SIZE);
+
+       cfdev->ring_ref = gnttab_grant_access(xendev->otherend_id,
+                       virt_to_mfn(cfdev->ring), 0);
+       UK_ASSERT(cfdev->ring_ref != GRANT_INVALID_REF);
+
+       return 0;
+}
+
+static int consfront_configure(struct uk_consdev *dev,
+               const struct uk_consdev_conf *dev_conf)
+{
+       struct consfront_dev *cfdev;
+       int rc = 0;
+
+       UK_ASSERT(dev);
+       UK_ASSERT(dev_conf);
+
+       cfdev = to_consfront(dev);
+       UK_ASSERT(cfdev);
+
+       rc = consfront_ring_init(cfdev);
+
+       return rc;
+}
+
+static int consfront_rx_configure(struct uk_consdev *dev,
+               uint16_t nb_desc,
+               const struct uk_consdev_rx_conf *rx_conf __unused)
+{
+       struct consfront_dev *cfdev;
+       struct xenbus_device *xendev;
+       int rc = 0;
+
+       cfdev = to_consfront(dev);
+       UK_ASSERT(cfdev);
+
+       xendev = cfdev->xendev;
+       UK_ASSERT(xendev);
+
+       if ((nb_desc != 0) &&
+               (nb_desc != XEN_CONSFRONT_SIZE_IN))
+               return -EINVAL;
+
+       rc = evtchn_alloc_unbound(xendev->otherend_id,
+               consfront_rx_handler, dev, &cfdev->evtchn);
+       if (rc < 0) {
+               uk_pr_err("Error creating event channel: %d.\n", rc);
+               return rc;
+       }
+
+       /* Start with interrupts disabled, API user should enable them */
+       mask_evtchn(cfdev->evtchn);
+
+       return rc;
+}
+
+static int consfront_tx_configure(struct uk_consdev *dev __unused,
+               uint16_t nb_desc,
+               const struct uk_consdev_tx_conf *tx_conf __unused)
+{
+       /* Although we don't use nb_desc, user still has to abide the API */
+       if ((nb_desc != 0) &&
+               (nb_desc != XEN_CONSFRONT_SIZE_OUT))
+               return -EINVAL;
+
+       return 0;
+}
+
+static void consfront_ring_release(struct consfront_dev *cfdev)
+{
+       int rc = 0;
+
+       /* Release ring */
+       if (cfdev->ring_ref != GRANT_INVALID_REF) {
+               rc = gnttab_end_access(cfdev->ring_ref);
+               UK_ASSERT(rc);
+       }
+
+       if (cfdev->ring) {
+               uk_free_page(drv_allocator, cfdev->ring);
+               cfdev->ring = NULL;
+       }
+}
+
+static int consfront_release(struct uk_consdev *dev)
+{
+       struct consfront_dev *cfdev;
+
+       UK_ASSERT(dev);
+
+       cfdev = to_consfront(dev);
+       UK_ASSERT(cfdev);
+
+       mask_evtchn(cfdev->evtchn);
+       unbind_evtchn(cfdev->evtchn);
+
+       consfront_ring_release(cfdev);
+
+       return 0;
+}
+
 static void consfront_close(struct uk_consdev *dev)
 {
        struct consfront_dev *cfdev;
@@ -110,6 +236,10 @@ static const struct uk_consdev_ops consfront_ops = {
        .info_get = consfront_info_get,
        .rx_info_get = consfront_rx_info_get,
        .tx_info_get = consfront_tx_info_get,
+       .configure = consfront_configure,
+       .rx_configure = consfront_rx_configure,
+       .tx_configure = consfront_tx_configure,
+       .release = consfront_release,
        .close = consfront_close,
 };
 
diff --git a/plat/xen/drivers/cons/consfront.h 
b/plat/xen/drivers/cons/consfront.h
index 3772c7a1..61cb2df4 100644
--- a/plat/xen/drivers/cons/consfront.h
+++ b/plat/xen/drivers/cons/consfront.h
@@ -47,6 +47,12 @@ struct consfront_dev {
        struct xenbus_device *xendev;
        /* Consdev Device. */
        struct uk_consdev consdev;
+       /* Xen Console Ring */
+       struct xencons_interface *ring;
+       /* Grant ref pointing at the front ring. */
+       grant_ref_t ring_ref;
+       /* Event channel for the front ring. */
+       evtchn_port_t evtchn;
        /* The consdev identifier */
        __u16 uid;
 };
-- 
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®.