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

[Minios-devel] [UNIKRAFT PATCH 03/10] plat/xen/drivers/cons: Register consfront with libukconsdev



Introduces add consfront device, used for registering the driver.

Signed-off-by: Birlea Costin <costin.birlea@xxxxxxxxx>
---
 plat/xen/drivers/cons/consfront.c | 59 +++++++++++++++++++++++++++++++++++++++
 plat/xen/drivers/cons/consfront.h | 52 ++++++++++++++++++++++++++++++++++
 2 files changed, 111 insertions(+)
 create mode 100644 plat/xen/drivers/cons/consfront.h

diff --git a/plat/xen/drivers/cons/consfront.c 
b/plat/xen/drivers/cons/consfront.c
index 19abcd09..88949da3 100644
--- a/plat/xen/drivers/cons/consfront.c
+++ b/plat/xen/drivers/cons/consfront.c
@@ -32,19 +32,78 @@
  *
  * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
  */
+#include <inttypes.h>
+#include <string.h>
+#include <uk/arch/lcpu.h>
+#include <uk/assert.h>
+#include <uk/essentials.h>
+#include <uk/config.h>
+#include <uk/consdev.h>
+#include <uk/consdev_driver.h>
+#include <xen-x86/mm.h>
+#include <xen/io/console.h>
 #include <xenbus/xenbus.h>
 
+#include "consfront.h"
+
 #define DRIVER_NAME           "xen-consfront"
 
+/* Get consfront_dev* which contains consdev */
+#define to_consfront(dev) \
+               __containerof(dev, struct consfront_dev, consdev)
+
 static struct uk_alloc *drv_allocator;
 
+static void consfront_close(struct uk_consdev *dev)
+{
+       struct consfront_dev *cfdev;
+
+       UK_ASSERT(dev);
+
+       cfdev = to_consfront(dev);
+       UK_ASSERT(cfdev);
+
+       uk_consdev_drv_unregister(dev);
+       uk_free(drv_allocator, cfdev);
+
+       uk_pr_info(DRIVER_NAME": %"PRIu16" closed\n", cfdev->uid);
+}
+
+static const struct uk_consdev_ops consfront_ops = {
+       .close = consfront_close,
+};
+
 static int consfront_add_dev(struct xenbus_device *xendev)
 {
+       struct consfront_dev *cfdev;
        int rc = 0;
 
        UK_ASSERT(xendev);
 
+       cfdev = uk_calloc(drv_allocator, 1, sizeof(struct consfront_dev));
+       if (!cfdev) {
+               rc = -ENOMEM;
+               goto out;
+       }
+
+       cfdev->consdev.ops = &consfront_ops;
+
+       /* Register consdev */
+       rc = uk_consdev_drv_register(&cfdev->consdev,
+                                       drv_allocator, DRIVER_NAME);
+       if (rc < 0) {
+               uk_pr_err("Failed to register %s device with libukconsdev\n",
+                       DRIVER_NAME);
+               goto err_register;
+       }
+       cfdev->uid = rc;
+       rc = 0;
+
+out:
        return rc;
+err_register:
+       uk_free(drv_allocator, cfdev);
+       goto out;
 }
 
 static int consfront_drv_init(struct uk_alloc *allocator)
diff --git a/plat/xen/drivers/cons/consfront.h 
b/plat/xen/drivers/cons/consfront.h
new file mode 100644
index 00000000..001ee12b
--- /dev/null
+++ b/plat/xen/drivers/cons/consfront.h
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Costin Birlea <costin.birlea@xxxxxxxxx>
+ *
+ * Copyright (c) 2019, University Politehnica of Bucharest.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+#ifndef __CONSFRONT_H__
+#define __CONSFRONT_H__
+
+#include <uk/consdev.h>
+#include <common/gnttab.h>
+#include <common/events.h>
+
+/**
+ * Structure used to describe the Consfront device.
+ */
+struct consfront_dev {
+       /* Consdev Device. */
+       struct uk_consdev consdev;
+       /* The consdev identifier */
+       __u16 uid;
+};
+
+#endif //__CONSFRONT_H__
-- 
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®.