From patchwork Mon Nov 7 11:15:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 81028 Delivered-To: patch@linaro.org Received: by 10.182.113.165 with SMTP id iz5csp1030132obb; Mon, 7 Nov 2016 02:18:25 -0800 (PST) X-Received: by 10.233.239.65 with SMTP id d62mr6514682qkg.122.1478513905457; Mon, 07 Nov 2016 02:18:25 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id y187si15599702qkd.87.2016.11.07.02.18.25; Mon, 07 Nov 2016 02:18:25 -0800 (PST) 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 29A04607D2; Mon, 7 Nov 2016 10:18:25 +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=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 F34FD60D2C; Mon, 7 Nov 2016 10:16:34 +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 A9A8160CF3; Mon, 7 Nov 2016 10:16:17 +0000 (UTC) Received: from mail-lf0-f48.google.com (mail-lf0-f48.google.com [209.85.215.48]) by lists.linaro.org (Postfix) with ESMTPS id B0D6E6096A for ; Mon, 7 Nov 2016 10:16:14 +0000 (UTC) Received: by mail-lf0-f48.google.com with SMTP id c13so109177034lfg.0 for ; Mon, 07 Nov 2016 02:16:14 -0800 (PST) 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=WDQ8uJH+eBd+2K4N3wkyy7GXxHXy8bc88uXyG0e7yNWbhLRjOFHy4xo+QFNbiuijvl 18tnUTOMCDTCyyy4G5un40mV/wfF/kXmR8DX/dlSnxYl5B1l7UIcBzU1W09BWB2XlCEi ir9fB/Cu3v8EFwKI+FbMzxEBwzLF/0LP6bu1LZLAM/XK4VG+Golp0Rldnwew6UxhIZ4s vKBOAE8f2R7GaHMLzYiTNQZBGBpRO4G6h5gUK+PbJqfT2S9nY++MrF5kynubINRBpHJs 37WDj0tC6WeydclB3oIReTY7I7HZFt8x88Ys55pXUxYdfghNwuUvxUjiFvXaJFFpmEZh R2rg== X-Gm-Message-State: ABUngvfrFl2oa/GBf4tJJwBjXe33rS7Jd9/PeFiQTUI0RYDuj/aRsHYPk8CkakIQcz4rLKRiGVQ= X-Received: by 10.25.56.94 with SMTP id d30mr3039341lfj.2.1478513773393; Mon, 07 Nov 2016 02:16:13 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id w67sm4932592lff.16.2016.11.07.02.16.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Nov 2016 02:16:12 -0800 (PST) From: Christophe Milard To: yi.he@linaro.org, mike.holmes@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Mon, 7 Nov 2016 12:15:23 +0100 Message-Id: <1478517324-11324-5-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1478517324-11324-1-git-send-email-christophe.milard@linaro.org> References: <1478517324-11324-1-git-send-email-christophe.milard@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv2 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; +}