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

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


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 10 Sep 2018 12:05:55 +0300
  • Cc: simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx
  • Delivery-date: Mon, 10 Sep 2018 09:06:22 +0000
  • Ironport-phdr: 9a23:FbxYgBfDsCzqqpqU+/tRs7mmlGMj4u6mDksu8pMizoh2WeGdxcS8bB7h7PlgxGXEQZ/co6odzbaO7Oa4ASQp2tWoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6nK94iQPFRrhKAF7Ovr6GpLIj8Swyuu+54Dfbx9HiTahY75+Ngm6oRnMvcQKnIVuLbo8xAHUqXVSYeRWwm1oJVOXnxni48q74YBu/SdNtf8/7sBMSar1cbg2QrxeFzQmLns65Nb3uhnZTAuA/WUTX2MLmRdVGQfF7RX6XpDssivms+d2xSeXMdHqQb0yRD+v6bpgRh31hycdLzM38H/ZhNF+gqxYpxyupRJ/zpXIbI2JLvdyYrnQcc8GSWdHQ81fVzZBAoS5b4YXEecBOv1Yr5X8p1sIsBCwAxSsBPvyyjRVgXL5wao60/89EQHH2gwsBdYOsGnMrNXoL6odTfu1wLPQzTXedPxawy396I/Rfx0nvPqCXqpwfNLMxUQgCg/JlFadpIz/Mz+LyOgAsXKX4uR4We6yhGMrtht9rzuvy8s2lIXEiIwYxkrZ+Sh23oo4I8CzRlRhbt6+CpRQsjmXN45xQsw/XW5loD06yrgauZ6jeygK1Ygnywbfa/OZd4iI5QruVPiUIThihXJlfKiziAqp8US60u38S9K73ExQripCitXMt3YN2ALP6sWfV/dw8Vqt1SyM2g3T8O1IP144mKjBJ5Mv2rIwk4AcsUXHHi/4gkX2i6qWe1049eiv8OTnfrTmppmGO49wlwH+Krkul9ejDuQjKAQOR3Wb9v+m2L35+k31WK9KgeEukqnFrJDaItwWpqu4Aw9T04Yj7A2/Ay6739sGg3kIMlZFdQmDj4joIFHOPOv4Ae2wgluyljdn3ffGPqfuAp/VNHjMjK/hfaph605b0Acz1tFf55dTCrEHOv7zWVLxu8LeDh44LQO02f3qCNNj2YwCXWKAGLSWPLnMvl+V/ugvOfWDZJcJuDbhLPgo//7vjWIjmV8cZ6Wpw5wXaHSkEfRmIEWZZmTsj8wHEWgUogU+SPblh0aYXTFNenbhF547szQ6DoOhFsLPS56ghJSF3TynBdtGa2YADUqDQlnycIDRcPAXdCOUaut8iiFMAbOmUJMg01eqqRfn47F8aPLJ8GsCssSwh5BO++TPmERqpnRPBMOH3jTVQg==
  • 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>
Reviewed-by: Yuri Volchkov <yuri.volchkov@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®.