[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
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
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |