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

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


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Thu, 23 Aug 2018 13:59:34 +0300
  • Cc: simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx, sharan.santhanam@xxxxxxxxx
  • Delivery-date: Thu, 23 Aug 2018 10:59:53 +0000
  • Ironport-phdr: 9a23:dyXnmhS/3y8FUamWfJPNwtH48tpsv+yvbD5Q0YIujvd0So/mwa6zZxKN2/xhgRfzUJnB7Loc0qyK6/+mATRIyK3CmUhKSIZLWR4BhJdetC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TW94jEIBxrwKxd+KPjrFY7OlcS30P2594HObwlSizexfbF/IA+qoQnNq8IbnZZsJqEtxxXTv3BGYf5WxWRmJVKSmxbz+MK994N9/ipTpvws6ddOXb31cKokQ7NYCi8mM30u683wqRbDVwqP6WACXWgQjxFFHhLK7BD+Xpf2ryv6qu9w0zSUMMHqUbw5Xymp4qF2QxHqlSgHLSY0/mHJhMJtgqxVoxWvqB5xw4PPfI2ZKOBzcr/HcN8GWWZMWNtaWSxbAoO7aosCF/QMPeFDr4nhplsOqwa1Cw+xBOP31z9Dm3j70rE90+Q6DQHG3QogE8gKsHTJtNX1KbwfXvyuzKXS1TXDcuhZ1S3n6IjPax0sp+yHU7FoccfJ1EUiGB7Jgk+TpIHlJT+ZyPoBvmqB4+duTe6jlmEqpxxrrjWsxsogkJfFi4wbx1ze6Cl0z5g5KNulQ0Bhe9GkCoFftySCOotzRcMtXn9ntT4hyr0DpZ67ZC8KyIk7xxLHa/yIbYyI4hX7WeaPJDd3nnNleLalixmu6kis0PX8VtSv31pQtCpFlcHAtnEL1xPN9siKUuZx80i81TqV1A3e6vtILV4qmafZMZIszKY8lp8JvkTCGi/2ll/2jKiTdkg85ueo7P/nYqnnpp+aLYN0jhz+MrwzmsGkHes4KRICX3CG+eunzrHj50r5TK1QjvIqiqnZrIzaJcMDq668Ag9V1Icj6xGkDzu/zdsXg2cHI0xBeB+ci4jpOkrOIOzjDfuljFWjjjFry+rBPr37DZXHNmLDn6v5fbZh905czxI+zctf551OELEOOvTzVlXqtNPCCB85Lwy0zPzhCNpn04MTQmSPDbGFP6PWq1CH/fgjLPeRZIUNojbyN+Al5+LyjX8+gVIdZqip3Z4QaHC+BPhmIFiZbmTqgtYAD2gKpBEzTOr0h1KeVT5cfW29U7gi6TEmEIimF5vMRpixgLyd2ye2Bp1XZn1cClCNC3voaYKEW/MQZyKSIc9hlSIEWKOnS4A/yR6usBX1xKF9IuXK5y1L/a7kgd104ezUjlQ++CJ5C+yZ0nqRVCdkk2VOQCU5j45lpkko4VCYzal+y9hFDcEbs/hOSRs7M9jY0vRnI9vpHBrcdJGTTwD1EZ2dHTgtQ4dpkJc1aEFnFoD6gw==
  • 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>
---
 plat/xen/Makefile.uk             |  1 +
 plat/xen/include/xenbus/client.h | 68 +++++++++++++++++++++++++++++
 plat/xen/xenbus/client.c         | 92 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 161 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 63cc42b..1c97d8c 100644
--- a/plat/xen/Makefile.uk
+++ b/plat/xen/Makefile.uk
@@ -79,6 +79,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;
+}
-- 
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®.