From patchwork Mon Oct 31 18:58:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 80262 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp268845qge; Mon, 31 Oct 2016 12:01:07 -0700 (PDT) X-Received: by 10.55.165.10 with SMTP id o10mr24877777qke.233.1477940467251; Mon, 31 Oct 2016 12:01:07 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id t7si6165814qtc.66.2016.10.31.12.01.06; Mon, 31 Oct 2016 12:01:07 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id D9B7D61740; Mon, 31 Oct 2016 19:01:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 9FFF161797; Mon, 31 Oct 2016 18:59:08 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 3A8A860DF5; Mon, 31 Oct 2016 18:58:56 +0000 (UTC) Received: from mail-lf0-f42.google.com (mail-lf0-f42.google.com [209.85.215.42]) by lists.linaro.org (Postfix) with ESMTPS id BF80660967 for ; Mon, 31 Oct 2016 18:58:53 +0000 (UTC) Received: by mail-lf0-f42.google.com with SMTP id t196so24487883lff.3 for ; Mon, 31 Oct 2016 11:58:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=z9dyBUWvpfVV8ycBWtFUaLpHPbs89sfqGeJRyfz0Elo=; b=adwB64qbd0eep4XJwLFLW0KIz1Tx6I1M6nuzjqixWbSrp4AsFRZdiF606iGlIZhqys X8RWA1n0cWZVa5mAodKVe9vmDEu/GUQi0FAHBm2MigdgDsdDS6Ll0X6owHRT9LFjxOfU QcFcsXL0Z3rvJt2idRTsy7wBccR5l7GPq8NrZUiXtlOtfvbpH1tLgJtxICGNXCs6pWnn L7xrHINITvheyR+m0Zu/JQ/S0pSI0B08b08bte9FrSnQIqdvRiUZrz9uarfSFcrjylvw 74U4aaFZ2+zNKpFLQ97487b2gvhw11BwwEQanYTnu7JqXnrFojSkkOuUv5qR6zk4ksiI W06w== X-Gm-Message-State: ABUngvfeIheXQkUb7EBZdHHLCtTh6NEsnXYkYnMn7dA1TSSG7TDzeKWTKzYh60u3Lhj8E+CuwPE= X-Received: by 10.25.23.154 with SMTP id 26mr18547008lfx.86.1477940332430; Mon, 31 Oct 2016 11:58:52 -0700 (PDT) Received: from localhost.localdomain (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id b29sm4792417lfh.8.2016.10.31.11.58.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 31 Oct 2016 11:58:51 -0700 (PDT) From: Christophe Milard To: mike.holmes@linaro.org, bill.fischofer@linaro.org, brian.brooks@linaro.org, lng-odp@lists.linaro.org Date: Mon, 31 Oct 2016 19:58:42 +0100 Message-Id: <1477940323-7278-5-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477940323-7278-1-git-send-email-christophe.milard@linaro.org> References: <1477940323-7278-1-git-send-email-christophe.milard@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH 4/5] linux-gen: implementation of odp_load_driver function X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Implementation of the driver loading function, of north API Signed-off-by: Christophe Milard --- 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 -- 2.7.4 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 #include #include #include @@ -11,6 +12,10 @@ #include #include +#if HAVE_DLFCN_H +# include +#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; +}