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

[Minios-devel] [UNIKRAFT PATCH v3 06/10] plat/xen: Introduce client API for Xenbus drivers


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 10 Sep 2018 12:05:58 +0300
  • Cc: simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx
  • Delivery-date: Mon, 10 Sep 2018 09:06:22 +0000
  • Ironport-phdr: 9a23:7Fh7+hwfebmEMlHXCy+O+j09IxM/srCxBDY+r6Qd2+weIJqq85mqBkHD//Il1AaPAd2Eraocw8Pt8InYEVQa5piAtH1QOLdtbDQizfssogo7HcSeAlf6JvO5JwYzHcBFSUM3tyrjaRsdF8nxfUDdrWOv5jAOBBr/KRB1JuPoEYLOksi7ze+/94HRbglSmDaxfa55IQmrownWqsQYm5ZpJLwryhvOrHtIeuBWyn1tKFmOgRvy5dq+8YB6/ShItP0v68BPUaPhf6QlVrNYFygpM3o05MLwqxbOSxaE62YGXWUXlhpIBBXF7A3/U5zsvCb2qvZx1S+HNsDwULs6Wymt771zRRHolikJKjA3/mLQhMNygqJWuw6tqwBlzoLIeoyZKOZyc6XAdt0aX2pBWcNRWjRfD4O7dIsPE+sBPeBFpIf7ulsOtQa+DhSrCezzzT9InWP23aw80+g7FQHGwRQgH88VvXvIt9X5Lr8SUf2uw6XS1zXDaOpb1DHg44bLahAsueyAUL1tfcbLykQiFxnJgkuOpYHnJT+Y2PwBv3WU4uZ9T+6iiG4qpxtvrjWhyMogkJTFi40Lxl3C6C532pw6JceiR05+edOkFZxQuDyEOIZuWcMiRn1ouD49yr0bpZ63ZCgKx4ojxx7Yc/GHbY2I7QjiVOaVOzt3mGlldKinhxav6kes0Pf8Vs6s3FZLqCpKjMXMu2gQ2xHc98SLUPhw80e71TqRyQze6PtILE4smareMZEhw7owlpQJsUTEGy/7gFn5jKiNdkU4++io7f7rYrH7pp+EKo95kR3xMr80lsynHOQ3KRICX3Kc+eikzr3s4VX5QKlWjv0xiqTZtZHaJcIapq6+GA9Zy5ss5AihDzi41NQVhn0HLFNeeBKblIjlIV7PL+7+DfulhFSsijhrzejcPrL9GpXNMmTDkLD5cLZm6k5czQ0zzdZF65JXF7EOPvTzW07vu9zCFRI5NRK7zPrjCNpnzYwSQ3yAArKBOqPIrVCI/v4vI/WLZIINuDf9NuIl5//0gX8nnl8debWm3ZsUaHC/APRrOEOZbmTwjdcFC2gFpRAyQ/L3iA7KbTkGYne0XqUnoz02Fo+iJYPCXZy2xqyM2mG8BJIFSHpBDwWnFmz0doPMf+oUdWrGKch6jj0CE7y8U5IJ3grorBLwjaBgeLmHshYEvI7ugYAmr9bYkgs/oGR5
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

Introduce the API needed by frontend drivers that require
communication with their backend counteparts.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
Reviewed-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>
---
 plat/xen/Makefile.uk             |  1 +
 plat/xen/include/xenbus/client.h | 68 +++++++++++++++++++++++++++++
 plat/xen/xenbus/client.c         | 92 ++++++++++++++++++++++++++++++++++++++++
 plat/xen/xenbus/exportsyms.uk    |  6 +++
 4 files changed, 167 insertions(+)
 create mode 100644 plat/xen/include/xenbus/client.h
 create mode 100644 plat/xen/xenbus/client.c

diff --git a/plat/xen/Makefile.uk b/plat/xen/Makefile.uk
index 5578194..be121bb 100644
--- a/plat/xen/Makefile.uk
+++ b/plat/xen/Makefile.uk
@@ -80,6 +80,7 @@ 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
+LIBXENBUS_SRCS-y               += $(LIBXENPLAT_BASE)/xenbus/client.c
 LIBXENBUS_SRCS-y               += $(LIBXENPLAT_BASE)/xenbus/xs_comms.c
 LIBXENBUS_SRCS-y               += $(LIBXENPLAT_BASE)/xenbus/xs.c
 endif
diff --git a/plat/xen/include/xenbus/client.h b/plat/xen/include/xenbus/client.h
new file mode 100644
index 0000000..964592d
--- /dev/null
+++ b/plat/xen/include/xenbus/client.h
@@ -0,0 +1,68 @@
+/* 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.
+ */
+/*
+ * Client interface between the device and the Xenbus driver.
+ * Ported from Mini-OS xenbus.c
+ */
+
+#ifndef __XENBUS_CLIENT_H__
+#define __XENBUS_CLIENT_H__
+
+#include <xenbus/xenbus.h>
+
+/*
+ * Returns the name of the state for tracing/debugging purposes.
+ *
+ * @param state The Xenbus state
+ * @return A string representing the state name
+ */
+const char *xenbus_state_to_str(XenbusState state);
+
+/*
+ * Converts a device type value to name
+ *
+ * @param devtype The Xenbus device type
+ * @return A string representing the device type name
+ */
+const char *xenbus_devtype_to_str(enum xenbus_dev_type devtype);
+
+/*
+ * Converts a device type name to value
+ *
+ * @param devtypestr The Xenbus device type name
+ * @return The Xenbus device type
+ */
+enum xenbus_dev_type xenbus_str_to_devtype(const char *devtypestr);
+
+#endif /* __XENBUS_CLIENT_H__ */
diff --git a/plat/xen/xenbus/client.c b/plat/xen/xenbus/client.c
new file mode 100644
index 0000000..3ddae5e
--- /dev/null
+++ b/plat/xen/xenbus/client.c
@@ -0,0 +1,92 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Steven Smith (sos22@xxxxxxxxx)
+ *          Grzegorz Milos (gm281@xxxxxxxxx)
+ *          John D. Ramsdell
+ *          Costin Lupu <costin.lupu@xxxxxxxxx>
+ *
+ * Copyright (c) 2006, Cambridge University
+ *               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.
+ */
+/*
+ * Client interface between the device and the Xenbus driver.
+ * Ported from Mini-OS xenbus.c
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <uk/errptr.h>
+#include <uk/wait.h>
+#include <xenbus/client.h>
+
+
+#define XENBUS_STATE_ENTRY(name) \
+       [XenbusState##name] = #name
+
+static const char *const xb_state_tbl[] = {
+       XENBUS_STATE_ENTRY(Unknown),
+       XENBUS_STATE_ENTRY(Initialising),
+       XENBUS_STATE_ENTRY(InitWait),
+       XENBUS_STATE_ENTRY(Initialised),
+       XENBUS_STATE_ENTRY(Connected),
+       XENBUS_STATE_ENTRY(Closing),
+       XENBUS_STATE_ENTRY(Closed),
+       XENBUS_STATE_ENTRY(Reconfiguring),
+       XENBUS_STATE_ENTRY(Reconfigured),
+};
+
+const char *xenbus_state_to_str(XenbusState state)
+{
+       return (state < ARRAY_SIZE(xb_state_tbl)) ?
+               xb_state_tbl[state] : "INVALID";
+}
+
+#define XENBUS_DEVTYPE_ENTRY(name) \
+       [xenbus_dev_##name] = #name
+
+static const char *const xb_devtype_tbl[] = {
+       XENBUS_DEVTYPE_ENTRY(none),
+};
+
+const char *xenbus_devtype_to_str(enum xenbus_dev_type devtype)
+{
+       return (devtype < ARRAY_SIZE(xb_devtype_tbl)) ?
+               xb_devtype_tbl[devtype] : "INVALID";
+}
+
+enum xenbus_dev_type xenbus_str_to_devtype(const char *devtypestr)
+{
+       for (int i = 0; i < (int) ARRAY_SIZE(xb_devtype_tbl); i++) {
+               if (!strcmp(xb_devtype_tbl[i], devtypestr))
+                       return (enum xenbus_dev_type) i;
+       }
+
+       return xenbus_dev_none;
+}
diff --git a/plat/xen/xenbus/exportsyms.uk b/plat/xen/xenbus/exportsyms.uk
index 5d9729e..e58bcf8 100644
--- a/plat/xen/xenbus/exportsyms.uk
+++ b/plat/xen/xenbus/exportsyms.uk
@@ -19,3 +19,9 @@ xs_read_integer
 xs_scanf
 xs_printf
 xs_get_self_id
+
+# Client API
+xenbus_state_to_str
+xenbus_devtype_to_str
+xenbus_str_to_devtype
+
-- 
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®.