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

[Minios-devel] [UNIKRAFT PATCH v4 3/7] plat/xen: Introduce client API for Xenbus drivers


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 17 Sep 2018 13:32:27 +0300
  • Cc: yuri.volchkov@xxxxxxxxx
  • Delivery-date: Mon, 17 Sep 2018 10:32:45 +0000
  • Ironport-phdr: 9a23:gQhLlBOWCZAQnDvouKEl6mtUPXoX/o7sNwtQ0KIMzox0Ivz9rarrMEGX3/hxlliBBdydt6obzbKO+4nbGkU4qa6bt34DdJEeHzQksu4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2aFLduGC94iAPERvjKwV1Ov71GonPhMiryuy+4ZLebxlKiTanfb9+MAi9oBnMuMURnYZsMLs6xAHTontPdeRWxGdoKkyWkh3h+Mq+/4Nt/jpJtf45+MFOTav1f6IjTbxFFzsmKHw65NfqtRbYUwSC4GYXX3gMnRpJBwjF6wz6Xov0vyDnuOdxxDWWMMvrRr0yRD+s7bpkSAXwhSkHKTA37W/ZhM93gq1ZrhKsvABzz5LObY2JLvdyYr/RcNUHTmRBRMZRUClBD5uiYosIFOoBIedYr4/grFUIsBu+HRSsD/7oxzBUgX/2xrE60+UnEQ3c2AwgAsoOsGnPodrpL6ceS/i1zLTTwjnZdfNW3i7w5Y7VeR4iufGBRa98fMXMxUU1FA7Ijk+cpZL7Mz6XzOgAvXCX4/dvWO6ykWIqqAF8riKxysoihITFnJ8Zx1/a+Sh/3Y07P8e3SFRhbt6hCJZQsiaaOJZoTc46WGFovTo6yqUBuZ6mYCgG0JQnyADba/yAa4WI/BfjW/yQITd8nn5qZKm/iwyq8Ui90eLwTNO00FFSoipElNnDqGwN2gTO5sWIV/dx5ESs1DaV2wzN9O1JI1o4mKTDJ54k2LEwl54TsUrZHi/xnUX7lLOZdkI/+ui06uTnZK/qppuBN49slwHzKbghmtelDeQgLwgBRHKX+f671LH75032XK1KjuEqkqneqJ3aIMUbpqi4Aw9SyYYv8guwACm40NsGmXkKN1ZFeBOcj4j1IFHCOv/5Aum5g1i2lzdr3f/GNKX7AprRNnjDjKvhfbFl5k9c1Qoz19Ff64hKCrEGJPL8Rk/xtN/fDh8nKAG0xfjoB8l51owEQm2DGLGWML6B+WOPs+cuJeiLf8oZtSjwL9Ah5uXyljkplFlberOmjrUNb3XtNfN9P0SfKV7xmspJRWwNpRY/SqrulUWfeTVIIW6vVeQm4WdoW8qdEY7fS9X10/S61yChE8gOaw==
  • 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®.