are there any system for linux-generic platform where dlopen is not
supported?
I think that we don't need ifdefs.
Maxim.
On 11/07/16 14:15, Christophe Milard wrote:
Implementation of the driver loading function, of north API
Signed-off-by: Christophe Milard <christophe.mil...@linaro.org>
---
configure.ac | 4 ++--
platform/linux-generic/include/.gitignore | 1 +
.../linux-generic/include/odp_platform_config.h.in | 11 +++++++++++
platform/linux-generic/m4/configure.m4 | 1 +
platform/linux-generic/m4/odp_drivers.m4 | 16 ++++++++++++++++
platform/linux-generic/odp_init.c | 22 ++++++++++++++++++++++
6 files changed, 53 insertions(+), 2 deletions(-)
create mode 100644 platform/linux-generic/include/.gitignore
create mode 100644 platform/linux-generic/include/odp_platform_config.h.in
create mode 100644 platform/linux-generic/m4/odp_drivers.m4
diff --git a/configure.ac b/configure.ac
index 8942894..a92469c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -47,7 +47,7 @@ AC_PROG_MAKE_SET
AM_PROG_AR
#Use libtool
-LT_INIT([])
+LT_INIT([dlopen])
AC_SUBST([LIBTOOL_DEPS])
AM_PROG_LIBTOOL
@@ -58,7 +58,7 @@ AC_CHECK_FUNCS([bzero clock_gettime gethostbyname getpagesize gettimeofday memse
# Checks for header files.
AC_HEADER_RESOLV
-AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h limits.h netdb.h netinet/in.h
stddef.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h
unistd.h])
+AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h limits.h netdb.h netinet/in.h
stddef.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h
unistd.h dlfcn.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
diff --git a/platform/linux-generic/include/.gitignore
b/platform/linux-generic/include/.gitignore
new file mode 100644
index 0000000..a32f733
--- /dev/null
+++ b/platform/linux-generic/include/.gitignore
@@ -0,0 +1 @@
+odp_platform_config.h
diff --git a/platform/linux-generic/include/odp_platform_config.h.in
b/platform/linux-generic/include/odp_platform_config.h.in
new file mode 100644
index 0000000..3b0ed2c
--- /dev/null
+++ b/platform/linux-generic/include/odp_platform_config.h.in
@@ -0,0 +1,11 @@
+/* Copyright (c) 2016, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/* the .h.in file is parsed by automake which performs substitutions
+ * according to the AC_SUBST macro given in m4 files.
+ */
+
+#define HAVE_DLFCN_H @HAVE_DLFCN_H@
diff --git a/platform/linux-generic/m4/configure.m4
b/platform/linux-generic/m4/configure.m4
index d3e5528..487f21e 100644
--- a/platform/linux-generic/m4/configure.m4
+++ b/platform/linux-generic/m4/configure.m4
@@ -35,6 +35,7 @@ m4_include([platform/linux-generic/m4/odp_netmap.m4])
m4_include([platform/linux-generic/m4/odp_dpdk.m4])
m4_include([platform/linux-generic/m4/odp_ipc.m4])
m4_include([platform/linux-generic/m4/odp_schedule.m4])
+m4_include([platform/linux-generic/m4/odp_drivers.m4])
AC_CONFIG_FILES([platform/linux-generic/Makefile
platform/linux-generic/include/odp/api/plat/static_inline.h])
diff --git a/platform/linux-generic/m4/odp_drivers.m4
b/platform/linux-generic/m4/odp_drivers.m4
new file mode 100644
index 0000000..f0ceccc
--- /dev/null
+++ b/platform/linux-generic/m4/odp_drivers.m4
@@ -0,0 +1,16 @@
+##########################################################################
+# Check for dlopen and lt equivalent availability
+##########################################################################
+
+AC_SEARCH_LIBS([dlopen], [dl dld],
+ [
+ HAVE_DLFCN_H=1
+ AM_LDFLAGS="$AM_LDFLAGS -ldl"
+ ],
+ [
+ echo "Warning! dlopen not available: won't be able to load drivers!"
+ HAVE_DLFCN_H=0
+ ])
+
+AC_SUBST(HAVE_DLFCN_H)
+AC_CONFIG_FILES([platform/linux-generic/include/odp_platform_config.h])
diff --git a/platform/linux-generic/odp_init.c
b/platform/linux-generic/odp_init.c
index d4a8e09..3dfbbc6 100644
--- a/platform/linux-generic/odp_init.c
+++ b/platform/linux-generic/odp_init.c
@@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include <odp_platform_config.h>
#include <odp/api/init.h>
#include <odp_debug_internal.h>
#include <odp/api/debug.h>
@@ -11,6 +12,10 @@
#include <odp_schedule_if.h>
#include <string.h>
+#if HAVE_DLFCN_H
+# include <dlfcn.h>
+#endif
+
struct odp_global_data_s odp_global_data;
int odp_init_global(odp_instance_t *instance,
@@ -374,3 +379,20 @@ int _odp_term_local(enum init_stage stage)
return rc;
}
+
+int odp_load_driver(const char *filename)
+{
+/*
+ * If dlopen is not available, then dynamic loading is not available:
+ * return error.
+ */
+#if HAVE_DLFCN_H
+ if (dlopen(filename, RTLD_NOW) == NULL) {
+ ODP_ERR("dlopen failed:%s\n", dlerror());
+ return -1;
+ }
+ return 0;
+
+#endif
+ return -1;
+}