[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH v3 1/2] lib/ukbus: Introduce abstraction for device buses
From: Sharan Santhanam <sharan.santhanam@xxxxxxxxx> This library creates infrastructure to support different devices buses within Unikraft. It provides a generic interface for operating registered device bus implementation. Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx> Signed-off-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx> --- lib/Config.uk | 1 + lib/Makefile.uk | 1 + lib/ukboot/boot.c | 10 ++++ lib/ukbus/Config.uk | 8 +++ lib/ukbus/Makefile.uk | 6 ++ lib/ukbus/bus.c | 88 +++++++++++++++++++++++++++++ lib/ukbus/export.syms | 5 ++ lib/ukbus/include/uk/bus.h | 137 +++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 256 insertions(+) create mode 100644 lib/ukbus/Config.uk create mode 100644 lib/ukbus/Makefile.uk create mode 100644 lib/ukbus/bus.c create mode 100644 lib/ukbus/export.syms create mode 100644 lib/ukbus/include/uk/bus.h diff --git a/lib/Config.uk b/lib/Config.uk index 2f47fde..e438603 100644 --- a/lib/Config.uk +++ b/lib/Config.uk @@ -36,3 +36,4 @@ source "lib/fdt/Config.uk" source "lib/uklock/Config.uk" source "lib/ukmpi/Config.uk" source "lib/ukswrand/Config.uk" +source "lib/ukbus/Config.uk" diff --git a/lib/Makefile.uk b/lib/Makefile.uk index a632336..40c65d0 100644 --- a/lib/Makefile.uk +++ b/lib/Makefile.uk @@ -18,3 +18,4 @@ $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/fdt)) $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/vfscore)) $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uklock)) $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukmpi)) +$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukbus)) diff --git a/lib/ukboot/boot.c b/lib/ukboot/boot.c index 807931e..d7214fe 100644 --- a/lib/ukboot/boot.c +++ b/lib/ukboot/boot.c @@ -56,6 +56,9 @@ #include <uk/essentials.h> #include <uk/print.h> #include <uk/argparse.h> +#if CONFIG_LIBUKBUS +#include <uk/bus.h> +#endif /* CONFIG_LIBUKBUS */ int main(int argc, char *argv[]) __weak; #ifdef CONFIG_LIBLWIP @@ -83,6 +86,13 @@ static void main_thread_func(void *arg) } uk_printd(DLVL_INFO, "])\n"); +#ifdef CONFIG_LIBUKBUS + uk_printd(DLVL_INFO, "Initialize bus handlers...\n"); + uk_bus_init_all(uk_alloc_get_default()); + uk_printd(DLVL_INFO, "Probe buses...\n"); + uk_bus_probe_all(); +#endif /* CONFIG_LIBUKBUS */ + #ifdef CONFIG_LIBLWIP /* * TODO: This is an initial implementation where we call the diff --git a/lib/ukbus/Config.uk b/lib/ukbus/Config.uk new file mode 100644 index 0000000..49f20c4 --- /dev/null +++ b/lib/ukbus/Config.uk @@ -0,0 +1,8 @@ +menuconfig LIBUKBUS + bool "ukbus: Abstraction for device buses" + default n + select LIBUKDEBUG + select LIBUKALLOC + +if LIBUKBUS +endif diff --git a/lib/ukbus/Makefile.uk b/lib/ukbus/Makefile.uk new file mode 100644 index 0000000..b4f0d79 --- /dev/null +++ b/lib/ukbus/Makefile.uk @@ -0,0 +1,6 @@ +$(eval $(call addlib_s,libukbus,$(CONFIG_LIBUKBUS))) + +CINCLUDES-$(CONFIG_LIBUKBUS) += -I$(LIBUKBUS_BASE)/include +CXXINCLUDES-$(CONFIG_LIBUKBUS) += -I$(LIBUKBUS_BASE)/include + +LIBUKBUS_SRCS-$(CONFIG_LIBUKBUS) += $(LIBUKBUS_BASE)/bus.c diff --git a/lib/ukbus/bus.c b/lib/ukbus/bus.c new file mode 100644 index 0000000..4d8f343 --- /dev/null +++ b/lib/ukbus/bus.c @@ -0,0 +1,88 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Authors: Simon Kuenzer <simon.kuenzer@xxxxxxxxx> + * + * Copyright (c) 2017, 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 <uk/bus.h> +#include <uk/assert.h> +#include <uk/print.h> + +struct uk_bus_list uk_bus_list; +static unsigned int bus_count; + +void _uk_bus_register(struct uk_bus *b) +{ + UK_ASSERT(b != NULL); + UK_ASSERT(b->probe != NULL); + + if (bus_count == 0) + UK_TAILQ_INIT(&uk_bus_list); + + uk_printd(DLVL_EXTRA, "Register bus handler: %p\n", b); + UK_TAILQ_INSERT_TAIL(&uk_bus_list, b, next); + ++bus_count; +} + +void _uk_bus_unregister(struct uk_bus *b) +{ + UK_ASSERT(b != NULL); + UK_ASSERT(bus_count > 0); + + uk_printd(DLVL_EXTRA, "Unregister bus handler: %p\n", b); + UK_TAILQ_REMOVE(&uk_bus_list, b, next); + bus_count--; +} + +unsigned int uk_bus_count(void) +{ + return bus_count; +} + +int uk_bus_init(struct uk_bus *b, struct uk_alloc *a) +{ + UK_ASSERT(b != NULL); + + uk_printd(DLVL_EXTRA, "Initialize bus handler %p...\n", b); + if (!b->init) + return 0; + return b->init(a); +} + + +int uk_bus_probe(struct uk_bus *b) +{ + UK_ASSERT(b != NULL); + UK_ASSERT(b->probe != NULL); + + uk_printd(DLVL_EXTRA, "Probe bus %p...\n", b); + return b->probe(); +} diff --git a/lib/ukbus/export.syms b/lib/ukbus/export.syms new file mode 100644 index 0000000..db4476d --- /dev/null +++ b/lib/ukbus/export.syms @@ -0,0 +1,5 @@ +uk_bus_count +uk_bus_init +uk_bus_probe +_uk_bus_register +_uk_bus_unregister diff --git a/lib/ukbus/include/uk/bus.h b/lib/ukbus/include/uk/bus.h new file mode 100644 index 0000000..57668e4 --- /dev/null +++ b/lib/ukbus/include/uk/bus.h @@ -0,0 +1,137 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Authors: Simon Kuenzer <simon.kuenzer@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 __UK_BUS__ +#define __UK_BUS__ + +#include <stddef.h> +#include <uk/list.h> +#include <uk/alloc.h> +#include <uk/plat/ctors.h> + +#ifdef __cplusplus +extern "C" { +#endif + +struct uk_bus; +UK_TAILQ_HEAD(uk_bus_list, struct uk_bus); +extern struct uk_bus_list uk_bus_list; + +typedef int (*uk_bus_init_func_t)(struct uk_alloc *a); +typedef int (*uk_bus_probe_func_t)(void); + +struct uk_bus { + UK_TAILQ_ENTRY(struct uk_bus) next; + uk_bus_init_func_t init; /**< Initialize bus handler (optional) */ + uk_bus_probe_func_t probe; /**< Probe for devices attached to the bus */ +}; + +#define UK_BUS_LIST_FOREACH(b) \ + UK_TAILQ_FOREACH(b, &uk_bus_list, next) + +#define UK_BUS_LIST_FOREACH_SAFE(b, b_next) \ + UK_TAILQ_FOREACH_SAFE(b, &uk_bus_list, next, b_next) + +/* Returns the number of registered buses */ +unsigned int uk_bus_count(void); + +/* Do not use this function directly: */ +void _uk_bus_register(struct uk_bus *b); +/* Do not use this function directly: */ +void _uk_bus_unregister(struct uk_bus *b); + +/* Initializes a bus driver */ +int uk_bus_init(struct uk_bus *b, struct uk_alloc *a); + +/* Scan for devices on the bus */ +int uk_bus_probe(struct uk_bus *b); + +/* Returns the number of successfully initialized device buses */ +static inline unsigned int uk_bus_init_all(struct uk_alloc *a) +{ + struct uk_bus *b, *b_next; + unsigned int ret = 0; + int status = 0; + + if (uk_bus_count() == 0) + return 0; + + UK_BUS_LIST_FOREACH_SAFE(b, b_next) { + if ((status = uk_bus_init(b, a)) >= 0) { + ++ret; + } else { + uk_printd(DLVL_ERR, "Failed to initialize bus driver %p: %d\n", + b, status); + + /* Remove the failed driver from the list */ + _uk_bus_unregister(b); + } + } + return ret; +} + +/* Returns the number of successfully probed device buses */ +static inline unsigned int uk_bus_probe_all(void) +{ + struct uk_bus *b; + unsigned int ret = 0; + + if (uk_bus_count() == 0) + return 0; + + UK_BUS_LIST_FOREACH(b) { + if (uk_bus_probe(b) >= 0) + ++ret; + } + return ret; +} + +/* registers a bus driver to the bus system */ +#define UK_BUS_REGISTER(b) \ + _UK_BUS_REGISTER(__LIBNAME__, b) + +#define _UK_BUS_REGFNNAME(x, y) x##y + +#define _UK_BUS_REGISTER(libname, b) \ + static void __constructor_prio(102) \ + _UK_BUS_REGFNNAME(libname, _uk_bus_register)(void) \ + { \ + _uk_bus_register((b)); \ + } + +#ifdef __cplusplus +} +#endif + +#endif /* __UK_BUS__ */ -- 2.7.4 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |