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

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



Reviewed-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>

Costin Lupu <costin.lupu@xxxxxxxxx> writes:

> Add basic functionality for Xenbus drivers registration.
>
> Signed-off-by: Costin Lupu <costin.lupu@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
>

-- 
Yuri Volchkov
Software Specialist

NEC Europe Ltd
Kurfürsten-Anlage 36
D-69115 Heidelberg

_______________________________________________
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®.