|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH 1/2] lib/ukbus: Introduce libukbus
This library creates infrastructure to support different bus within Unikraft.
Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
Signed-off-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx>
---
include/uk/essentials.h | 8 +++
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 | 78 +++++++++++++++++++++++++++++
lib/ukbus/export.syms | 4 ++
lib/ukbus/include/uk/bus.h | 120 +++++++++++++++++++++++++++++++++++++++++++++
9 files changed, 236 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/include/uk/essentials.h b/include/uk/essentials.h
index 1cabb20..bcd6996 100644
--- a/include/uk/essentials.h
+++ b/include/uk/essentials.h
@@ -97,6 +97,14 @@ extern "C" {
#define __constructor_prio(lvl) __attribute__ ((constructor (lvl)))
#endif
+#define UK_CTOR_REGISTER(func, priority, libname, ...) \
+ static __constructor_prio(priority) \
+ void __##func##libname(void); \
+ static \
+ void __##func##libname(void) \
+ { \
+ _##func(__VA_ARGS__); \
+ }
#else
/* TO BE DEFINED */
#endif /* __GNUC__ */
diff --git a/lib/Config.uk b/lib/Config.uk
index dafb80d..4154051 100644
--- a/lib/Config.uk
+++ b/lib/Config.uk
@@ -36,3 +36,4 @@ source "lib/fdt/Config.uk"
source "lib/ukmpi/Config.uk"
source "lib/uklock/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 aad9740..f235cba 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: We have 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..ce5458f
--- /dev/null
+++ b/lib/ukbus/bus.c
@@ -0,0 +1,78 @@
+/* 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;
+}
+
+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..5b0910f
--- /dev/null
+++ b/lib/ukbus/export.syms
@@ -0,0 +1,4 @@
+uk_bus_count
+uk_bus_init
+uk_bus_probe
+_uk_bus_register
diff --git a/lib/ukbus/include/uk/bus.h b/lib/ukbus/include/uk/bus.h
new file mode 100644
index 0000000..9da4c00
--- /dev/null
+++ b/lib/ukbus/include/uk/bus.h
@@ -0,0 +1,120 @@
+/* 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)
+
+unsigned int uk_bus_count(void);
+int uk_bus_init(struct uk_bus *b, struct uk_alloc *a);
+int uk_bus_probe(struct uk_bus *b);
+
+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(%d) to initialize the "
+ "driver\n", status);
+ /* Removing the failed driver from the list */
+ UK_TAILQ_REMOVE(&uk_bus_list, b, next);
+ }
+ }
+ return ret;
+}
+
+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;
+}
+
+#define UK_BUS_REGISTER(b, priority) \
+ _UK_BUS_REGISTER(b, priority, __LIBNAME__)
+
+#define _UK_BUS_REGISTER(b, priority, libname) \
+ UK_CTOR_REGISTER(uk_bus_register, priority, libname, b)
+
+void _uk_bus_register(struct uk_bus *b); /* use UK_BUS_REGISTER()! */
+
+#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 |