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

[Minios-devel] [UNIKRAFT PATCH v2 03/10] plat/xen: Add Xenbus driver registration support


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Thu, 23 Aug 2018 13:59:31 +0300
  • Cc: simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx, sharan.santhanam@xxxxxxxxx
  • Delivery-date: Thu, 23 Aug 2018 10:59:51 +0000
  • Ironport-phdr: 9a23:u4w4WxFzNMPdfHDYFnnVlZ1GYnF86YWxBRYc798ds5kLTJ7ypMqwAkXT6L1XgUPTWs2DsrQY07WQ6/iocFdDyK7JiGoFfp1IWk1NouQttCtkPvS4D1bmJuXhdS0wEZcKflZk+3amLRodQ56mNBXdrXKo8DEdBAj0OxZrKeTpAI7SiNm82/yv95HJbAhEmDiwbaluIBmqsA7cqtQYjYx+J6gr1xDHuGFIe+NYxWNpIVKcgRPx7dqu8ZBg7ipdpesv+9ZPXqvmcas4S6dYDCk9PGAu+MLrrxjDQhCR6XYaT24bjwBHAwnB7BH9Q5fxri73vfdz1SWGIcH7S60/VDK/5KlpVRDokj8KOT4n/m/KhMJ+j6VVrxCvpxFk34LYfJuYOOZkc6/BYd8XQ3dKUMZLVyxGB4Oxd5UCD+0aPeZEron9oUYFox2jBQm0GePk1zhFiWPx3a0hz+QhEAfG0BYkH9ITqHTUsc74O7sJUeyv1KnI0C7MY+lM2Tf68YXFdA0qr/KUXb9obMbcxlQjGxnGg1iQs4DpIS2Z2+YXv2WV9+ZsSO2ih3M9pwxyojWj3Nkgh4fHi44P11zJ+jt1zYAoLtOiUkF7e8SrEJ5IuiGfMIt5X90tTnlzuCY/1r0GoZm7fDUWyJg/xx7QdfiHc4+Q7xL9UeaeOzZ4hHZ/dL2jnBa+61CgyvDnWcWuylZKqTJJktjKtn8Tyxze8tWLR/Rg8ku72juC1xrf5v9aLU02j6bWJYYtwrsqmZoStUTDEDX2mELzjKKOakok/fOo6/jmYrXgvJOcM5J0ihnjMqk1hsO/Gv40MhATX2eA4+i8zrrj8VXjQLpWlv02jrXZsJfCKMQep665BQ5V0oE46xqmEjipzsoYkmcDLF9efBKHjpPpO03VIPziAvawnVKsnC1sx/DcMb3rGo/NIWTbkLf9YbZ97FZRyBEzzd9F/ZJbELcBLOjoWkDrstzYEh85PBayw+n9DdVwzYUeVnyTDa+dKqzdqkWE6fwyI+OUfo8apC79K+Q55/7plXI5gl4dfayu3ZsRcny4HelmLFufYXvtnNgBC3wHvgwgQ+P2jF2NSyVca2ysUKIh/js7Ep6pDZ/fRoCxh7yMxCe6HoBMZmBHEFyMD3Dod4GYVPcMayKSJdFhnycCVbe/V4Ah0QuhuxTgx7V5M+qHshEf4Jfi0tly/KjfmA8/8RRwDt+ByCedQmcymXkHFBEs26Uqiktm1laFmYxlm+EQQddU/O9IVEE+KIbB5+dhTcjvUETbeYHaGx6dXty6DGRpHZoKyNgUbhMlFg==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

Add basic functionality for Xenbus drivers registration.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 plat/xen/Config.uk               |   8 +++
 plat/xen/Makefile.uk             |  10 +++-
 plat/xen/include/xenbus/xenbus.h | 118 ++++++++++++++++++++++++++++++++++++++
 plat/xen/xenbus/xenbus.c         | 120 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 255 insertions(+), 1 deletion(-)
 create mode 100644 plat/xen/include/xenbus/xenbus.h
 create mode 100644 plat/xen/xenbus/xenbus.c

diff --git a/plat/xen/Config.uk b/plat/xen/Config.uk
index 9c398f1..d0143e9 100644
--- a/plat/xen/Config.uk
+++ b/plat/xen/Config.uk
@@ -20,4 +20,12 @@ if (PLAT_XEN)
                instead of the hypervisor console. When this
                option is enabled the hypervisor console is used
                for kernel messages only.
+
+menuconfig XEN_XENBUS
+       bool "Xenbus Driver"
+       default n
+       depends on (ARCH_X86_64)
+       select LIBUKBUS
+       help
+               Register a Xenbus driver as uk_bus
 endif
diff --git a/plat/xen/Makefile.uk b/plat/xen/Makefile.uk
index 45096cb..b8c70e1 100644
--- a/plat/xen/Makefile.uk
+++ b/plat/xen/Makefile.uk
@@ -9,7 +9,7 @@ $(eval $(call addplat_s,xen,$(CONFIG_PLAT_XEN)))
 ## Xen platform library registration
 ##
 $(eval $(call addplatlib,xen,libxenplat))
-$(eval $(call addplatlib_s,xen,libxenbus,$(XEN_XENBUS)))
+$(eval $(call addplatlib_s,xen,libxenbus,$(CONFIG_XEN_XENBUS)))
 
 ##
 ## Xen platform compilation settings
@@ -72,3 +72,11 @@ LIBXENPLAT_SRCS-y              += 
$(LIBXENPLAT_BASE)/console.c
 LIBXENPLAT_SRCS-y              += $(LIBXENPLAT_BASE)/shutdown.c
 LIBXENPLAT_SRCS-y              += $(LIBXENPLAT_BASE)/events.c
 LIBXENPLAT_SRCS-y              += $(LIBXENPLAT_BASE)/gnttab.c
+
+ifeq ($(CONFIG_XEN_XENBUS),y)
+LIBXENBUS_ASFLAGS-y            += $(LIBXENPLAT_ASFLAGS-y)
+LIBXENBUS_ASINCLUDES-y         += $(LIBXENPLAT_ASINCLUDES-y)
+LIBXENBUS_CFLAGS-y             += $(LIBXENPLAT_CFLAGS-y)
+LIBXENBUS_CINCLUDES-y          += $(LIBXENPLAT_CINCLUDES-y)
+LIBXENBUS_SRCS-y               += $(LIBXENPLAT_BASE)/xenbus/xenbus.c
+endif
diff --git a/plat/xen/include/xenbus/xenbus.h b/plat/xen/include/xenbus/xenbus.h
new file mode 100644
index 0000000..970b96a
--- /dev/null
+++ b/plat/xen/include/xenbus/xenbus.h
@@ -0,0 +1,118 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Costin Lupu <costin.lupu@xxxxxxxxx>
+ *
+ * Copyright (c) 2018, NEC Europe Ltd., NEC Corporation. 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 __XENBUS_H__
+#define __XENBUS_H__
+
+#include <uk/arch/spinlock.h>
+#include <uk/bus.h>
+#include <uk/alloc.h>
+#include <uk/wait.h>
+#include <xen/xen.h>
+#include <xen/io/xenbus.h>
+
+
+/*
+ * Supported device types
+ */
+typedef enum xenbus_dev_type {
+       xenbus_dev_none = 0,
+} xenbus_dev_type_t;
+
+struct xenbus_device;
+
+/*
+ * Xenbus driver
+ */
+
+typedef int (*xenbus_driver_init_func_t)(struct uk_alloc *a);
+typedef int (*xenbus_driver_add_func_t)(struct xenbus_device *dev);
+
+
+struct xenbus_driver {
+       UK_TAILQ_ENTRY(struct xenbus_driver) next;
+       const xenbus_dev_type_t *device_types;
+
+       xenbus_driver_init_func_t init;
+       xenbus_driver_add_func_t add_dev;
+};
+UK_TAILQ_HEAD(xenbus_driver_list, struct xenbus_driver);
+
+
+#define XENBUS_REGISTER_DRIVER(b) \
+       _XENBUS_REGISTER_DRIVER(__LIBNAME__, (b))
+
+#define _XENBUS_REGFNNAME(x, y)      x##y
+
+#define _XENBUS_REGISTER_DRIVER(libname, b) \
+       static void __constructor_prio(104) \
+       _XENBUS_REGFNNAME(libname, _xenbus_register_driver)(void) \
+       { \
+               _xenbus_register_driver((b)); \
+       }
+
+/* Do not use this function directly: */
+void _xenbus_register_driver(struct xenbus_driver *drv);
+
+typedef unsigned long xenbus_transaction_t;
+#define XBT_NIL ((xenbus_transaction_t) 0)
+
+
+/*
+ * Xenbus device
+ */
+
+struct xenbus_device {
+
+};
+UK_TAILQ_HEAD(xenbus_device_list, struct xenbus_device);
+
+
+/*
+ * Xenbus handler
+ */
+
+struct xenbus_handler {
+       struct uk_bus b;
+       struct uk_alloc *a;
+       struct xenbus_driver_list drv_list;  /**< List of Xenbus drivers */
+       struct xenbus_device_list dev_list;  /**< List of Xenbus devices */
+};
+
+/* Helper functions for Xenbus related allocations */
+void *uk_xb_malloc(size_t size);
+void *uk_xb_calloc(size_t nmemb, size_t size);
+void  uk_xb_free(void *ptr);
+
+#endif /* __XENBUS_H__ */
diff --git a/plat/xen/xenbus/xenbus.c b/plat/xen/xenbus/xenbus.c
new file mode 100644
index 0000000..1bc57c3
--- /dev/null
+++ b/plat/xen/xenbus/xenbus.c
@@ -0,0 +1,120 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Costin Lupu <costin.lupu@xxxxxxxxx>
+ *
+ * Copyright (c) 2018, NEC Europe Ltd., NEC Corporation. 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.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <inttypes.h>
+#include <string.h>
+#include <uk/essentials.h>
+#include <uk/list.h>
+#include <uk/bus.h>
+#include <uk/print.h>
+#include <uk/errptr.h>
+#include <uk/assert.h>
+#include <xenbus/xenbus.h>
+
+static struct xenbus_handler xbh;
+
+
+/* Helper functions for Xenbus related allocations */
+void *uk_xb_malloc(size_t size)
+{
+       UK_ASSERT(xbh.a != NULL);
+       return uk_malloc(xbh.a, size);
+}
+
+void *uk_xb_calloc(size_t nmemb, size_t size)
+{
+       UK_ASSERT(xbh.a != NULL);
+       return uk_calloc(xbh.a, nmemb, size);
+}
+
+void uk_xb_free(void *ptr)
+{
+       UK_ASSERT(xbh.a != NULL);
+       uk_free(xbh.a, ptr);
+}
+
+static int xenbus_probe(void)
+{
+       int err = 0;
+
+       uk_printd(DLVL_INFO, "Probe Xenbus\n");
+
+       /* TODO */
+
+       return err;
+}
+
+static int xenbus_init(struct uk_alloc *a)
+{
+       struct xenbus_driver *drv, *drv_next;
+       int ret = 0;
+
+       UK_ASSERT(a != NULL);
+
+       xbh.a = a;
+
+       UK_TAILQ_FOREACH_SAFE(drv, &xbh.drv_list, next, drv_next) {
+               if (drv->init) {
+                       ret = drv->init(a);
+                       if (ret == 0)
+                               continue;
+                       uk_printd(DLVL_ERR,
+                               "Failed to initialize driver %p: %d\n",
+                               drv, ret);
+                       UK_TAILQ_REMOVE(&xbh.drv_list, drv, next);
+               }
+       }
+
+       return 0;
+}
+
+void _xenbus_register_driver(struct xenbus_driver *drv)
+{
+       UK_ASSERT(drv != NULL);
+       UK_TAILQ_INSERT_TAIL(&xbh.drv_list, drv, next);
+}
+
+/*
+ * Register this bus driver to libukbus:
+ */
+static struct xenbus_handler xbh = {
+       .b.init  = xenbus_init,
+       .b.probe = xenbus_probe,
+       .drv_list = UK_TAILQ_HEAD_INITIALIZER(xbh.drv_list),
+       .dev_list = UK_TAILQ_HEAD_INITIALIZER(xbh.dev_list),
+};
+
+UK_BUS_REGISTER(&xbh.b);
-- 
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®.