From patchwork Wed Mar 22 14:48:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95724 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp224409obz; Wed, 22 Mar 2017 06:49:26 -0700 (PDT) X-Received: by 10.200.47.47 with SMTP id j44mr32601791qta.244.1490190566656; Wed, 22 Mar 2017 06:49:26 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id z47si1120627qta.254.2017.03.22.06.49.26; Wed, 22 Mar 2017 06:49:26 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 2DC26642C5; Wed, 22 Mar 2017 13:49:26 +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, URIBL_BLOCKED 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 BF7B6642B5; Wed, 22 Mar 2017 13:49:20 +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 D5AB662DC6; Wed, 22 Mar 2017 13:49:17 +0000 (UTC) Received: from mail-wm0-f45.google.com (mail-wm0-f45.google.com [74.125.82.45]) by lists.linaro.org (Postfix) with ESMTPS id CF1E962DC6 for ; Wed, 22 Mar 2017 13:49:15 +0000 (UTC) Received: by mail-wm0-f45.google.com with SMTP id t189so38376061wmt.1 for ; Wed, 22 Mar 2017 06:49:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aQNQcLKglV4cnYzH/g9PoUh8f2G0F/V28rBpUv8EBAA=; b=DB+Jn5LwpTXQMdVsY/Dpn8rd2M3FhlTRornRF6dvBjoCinyAE6rngz+ww8NSqw1Kbr BMztPaQisKcNSrBzmciSUudGUeJ6zWPuy5+JNRViWB7o0qHHQXO3XXQABfLjOQwy62qW 0mkxVg3dUti05VM6LwXWgsZe3JoZo67f2QdoT51BAB1hTmtFTEK3/AvWhi04RMVw09qv nfLc1wAmb+RJCJd/XvgAyA/0TMQmxmUpm2iG9MgmKqAdtbyd7UPPeO6wzBUWUyGWhsQ6 5qJsqPtrRfVuhzrT0F27Bg3PmnDBpJ4R7y5wPH0UX0BDuENVJDy6VluOygYsz/wUMkHu gKeA== X-Gm-Message-State: AFeK/H2YpD8y4OCwUuH9bDEEcEWH1ZZMdyZfW/QJuUOc1fx0DjjbGQyc94i9A7hP9ixdDjwNmK3nPDjk X-Received: by 10.25.196.207 with SMTP id u198mr12170846lff.88.1490190554701; Wed, 22 Mar 2017 06:49:14 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:14 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:08 +0100 Message-Id: <1490194110-40168-2-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 01/23] drv: adding compiler hints in the driver interface 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" Largely inspired from its north api counterpart, the drv/spec/hint.h file is added. Also includes the __constructor__ attributes that many driver interface items will need. Signed-off-by: Christophe Milard --- include/odp/drv/spec/hints.h | 119 +++++++++++++++++++++++++++++++++++++++++++ platform/Makefile.inc | 1 + 2 files changed, 120 insertions(+) create mode 100644 include/odp/drv/spec/hints.h -- 2.7.4 diff --git a/include/odp/drv/spec/hints.h b/include/odp/drv/spec/hints.h new file mode 100644 index 0000000..ddae22e --- /dev/null +++ b/include/odp/drv/spec/hints.h @@ -0,0 +1,119 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODPDRV compiler hints + */ + +#ifndef ODPDRV_API_HINTS_H_ +#define ODPDRV_API_HINTS_H_ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup odpdrv_compiler_optim + * Macros that will give hints to the compiler. + * @{ + */ + +#ifdef __GNUC__ + +/** Define a function that should be run at early init (constructor) + */ +#define ODPDRV_CONSTRUCTOR __attribute__((__constructor__)) + +/** Define a function that does not return + */ +#define ODPDRV_NORETURN __attribute__((__noreturn__)) + +/** Define a weak symbol + * This is primarily useful in defining library functions that can be + * overridden in user code. + */ +#define ODPDRV_WEAK_SYMBOL __attribute__((__weak__)) + +/** + * Hot code section + */ +#define ODPDRV_HOT_CODE __attribute__((__hot__)) + +/** + * Cold code section + */ +#define ODPDRV_COLD_CODE __attribute__((__cold__)) + +/** + * Printf format attribute + */ +#define ODPDRV_PRINTF_FORMAT(x, y) __attribute__((format(printf, (x), (y)))) + +/** + * Indicate deprecated variables, functions or types + */ +#define ODPDRV_DEPRECATED __attribute__((__deprecated__)) + +/** + * Intentionally unused variables of functions + */ +#define ODPDRV_UNUSED __attribute__((__unused__)) + +/** + * Branch likely taken + */ +#define odpdrv_likely(x) __builtin_expect((x), 1) + +/** + * Branch unlikely taken + */ +#define odpdrv_unlikely(x) __builtin_expect((x), 0) + +/* + * __builtin_prefetch (const void *addr, rw, locality) + * + * rw 0..1 (0: read, 1: write) + * locality 0..3 (0: don't leave to cache, 3: leave on all cache levels) + */ + +/** + * Cache prefetch address + */ +#define odpdrv_prefetch(x) __builtin_prefetch((x), 0, 3) + +/** + * Cache prefetch address for storing + */ +#define odpdrv_prefetch_store(x) __builtin_prefetch((x), 1, 3) + +#else + +#define ODPDRV_CONSTRUCTOR +#define ODPDRV_NORETURN +#define ODPDRV_WEAK_SYMBOL +#define ODPDRV_HOT_CODE +#define ODPDRV_COLD_CODE +#define ODPDRV_DEPRECATED +#define ODPDRV_UNUSED +#define odpdrv_likely(x) +#define odpdrv_unlikely(x) +#define odpdrv_prefetch(x) +#define odpdrv_prefetch_store(x) + +#endif + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#include +#endif diff --git a/platform/Makefile.inc b/platform/Makefile.inc index 874cf88..e439e3c 100644 --- a/platform/Makefile.inc +++ b/platform/Makefile.inc @@ -69,6 +69,7 @@ odpdrvspecinclude_HEADERS = \ $(top_srcdir)/include/odp/drv/spec/byteorder.h \ $(top_srcdir)/include/odp/drv/spec/compiler.h \ $(top_srcdir)/include/odp/drv/spec/driver.h \ + $(top_srcdir)/include/odp/drv/spec/hints.h \ $(top_srcdir)/include/odp/drv/spec/shm.h \ $(top_srcdir)/include/odp/drv/spec/spinlock.h \ $(top_srcdir)/include/odp/drv/spec/std_types.h \ From patchwork Wed Mar 22 14:48:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95726 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp224948obz; Wed, 22 Mar 2017 06:50:53 -0700 (PDT) X-Received: by 10.55.39.216 with SMTP id n207mr35654246qkn.315.1490190653062; Wed, 22 Mar 2017 06:50:53 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id q7si1116155qtq.328.2017.03.22.06.50.52; Wed, 22 Mar 2017 06:50:53 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id B5425609C2; Wed, 22 Mar 2017 13:50:52 +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, URIBL_BLOCKED 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 9093B642C5; Wed, 22 Mar 2017 13:49:27 +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 42F47642B5; Wed, 22 Mar 2017 13:49:19 +0000 (UTC) Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by lists.linaro.org (Postfix) with ESMTPS id CB71C642B0 for ; Wed, 22 Mar 2017 13:49:17 +0000 (UTC) Received: by mail-wm0-f48.google.com with SMTP id n11so37215943wma.1 for ; Wed, 22 Mar 2017 06:49:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fJ9WtKkRT4+PoBCMMCw6g0Vn7SgAONzb25uo+63NISw=; b=YJVqBh6iTM2mvxBsPuQnZK8S0M8zBy4e3f7qwOapag0oKrz20woWpMQBFSXCTeq1Vr my8O3SxJjJA2WYh2IstYRa2JVC4D8mpd9EVnSv9fRhnMxztXbFhsbLZ7Otl28xaGADye 0ub0K+YRqqdLqYgXOzxGt5k1mDajgBzlZs3M+p4AUwVFL+sgbsEA0a1EuQ+vMWLGIVS1 jwsp/zE/kU1jD99qqXUu14vM9Eg7ULCTkVpT/9Circ+40yFSn8r0c6d4tI+9IOKqIbxx NoZP7iu3YinIJOvh/0sHZ+MEqrlAKQEWiT0AhHw7cn3Ybr46S++DEYthNTH6WUa95PCE 9rYg== X-Gm-Message-State: AFeK/H38e+YdbnK+tkmn/pNio8hKCInSiBtI6mUSEZLwLqE/BLBqbZxEu50vlkApgcXnjp6jF9k= X-Received: by 10.25.193.8 with SMTP id r8mr10265749lff.127.1490190555709; Wed, 22 Mar 2017 06:49:15 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:15 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:09 +0100 Message-Id: <1490194110-40168-3-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 02/23] linux-gen: adding compiler hints in the driver interface 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" Just including the spec file from the linux-generic side, as usual. Signed-off-by: Christophe Milard --- include/odp_drv.h | 1 + platform/linux-generic/include/odp/drv/hints.h | 34 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 platform/linux-generic/include/odp/drv/hints.h -- 2.7.4 diff --git a/include/odp_drv.h b/include/odp_drv.h index 96d81ba..cdba226 100644 --- a/include/odp_drv.h +++ b/include/odp_drv.h @@ -24,6 +24,7 @@ extern C { #include #include #include +#include #include #include #include diff --git a/platform/linux-generic/include/odp/drv/hints.h b/platform/linux-generic/include/odp/drv/hints.h new file mode 100644 index 0000000..808c22c --- /dev/null +++ b/platform/linux-generic/include/odp/drv/hints.h @@ -0,0 +1,34 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODPDRV compiler hints + */ + +#ifndef ODPDRV_PLAT_HINTS_H_ +#define ODPDRV_PLAT_HINTS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** @ingroup odpdrv_compiler_optim + * @{ + */ + +/** + * @} + */ + +#include + +#ifdef __cplusplus +} +#endif + +#endif From patchwork Wed Mar 22 14:48:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95727 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp225165obz; Wed, 22 Mar 2017 06:51:30 -0700 (PDT) X-Received: by 10.200.36.194 with SMTP id t2mr39016170qtt.61.1490190690182; Wed, 22 Mar 2017 06:51:30 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id t18si1117143qtc.335.2017.03.22.06.51.29; Wed, 22 Mar 2017 06:51:30 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id D77286431C; Wed, 22 Mar 2017 13:51:29 +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, URIBL_BLOCKED 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 C1551642CA; Wed, 22 Mar 2017 13:49:28 +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 AB049642BE; Wed, 22 Mar 2017 13:49:21 +0000 (UTC) Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) by lists.linaro.org (Postfix) with ESMTPS id F11C8642B1 for ; Wed, 22 Mar 2017 13:49:17 +0000 (UTC) Received: by mail-wm0-f46.google.com with SMTP id n11so38299038wma.0 for ; Wed, 22 Mar 2017 06:49:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8DsWC5dRlZzr+gxZ+hx22Ksx115HAR4IUL2mY27dtHA=; b=G87s1MovkP4cJo83RLwzbaEElu57SLcIxNCFzQYTSnxpJNtlPaD2UFsVg/XymLtKXW BnwYljrER8NPsDGv8Zf/VIOB/QAemZtpuBjXm/j0rjO1akz42PuSMBFKu/N0Q+HwfTp6 6W+tmdBldKwiJh981ToEnTiCMA4UOXUzstoCbSmZxU8MUdy9gIen+wGDcocjVJw1YTit EARbfd7EVePWGb4L3RFgR9bTrbrsOCFy60L3eJyfES972Hl+dLByfdN6faK0iZa3kTv2 4w2Pgt5ZD3PTLE/7h3rpbqEoAypk3bSIoibU1U3nXbHgt22uH4TmNSqpAnSsCna6K7q5 BSBw== X-Gm-Message-State: AFeK/H2mBCK2t59qxMKXtYLWj5T9ZmCNkC1NDuVWLkC+yOAMoIxo0N1sc0mCZ5+CH/JzuU6jguY= X-Received: by 10.25.25.80 with SMTP id 77mr10439289lfz.64.1490190556731; Wed, 22 Mar 2017 06:49:16 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:16 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:10 +0100 Message-Id: <1490194110-40168-4-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 03/23] drv: making parameter strings dynamically computable 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" Declaring strings as const in the driver API prevents dynamic calculation of these strings, which is a drawback. For instance, the device addresses (string) are typically calculated by enumerators, and should therefore not be const... Other strings may also be the result of a computation. This change is made to allow this. Signed-off-by: Christophe Milard --- include/odp/drv/spec/driver.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) -- 2.7.4 diff --git a/include/odp/drv/spec/driver.h b/include/odp/drv/spec/driver.h index d83e907..b08d7fb 100644 --- a/include/odp/drv/spec/driver.h +++ b/include/odp/drv/spec/driver.h @@ -170,7 +170,7 @@ struct odpdrv_enumr_class_param_t { /** Enumerator name: mostly used for debug purpose. * Name must be unique (e.g. "PCI-DPAA2") */ - const char name[ODPDRV_NAME_SIZE]; + char name[ODPDRV_NAME_SIZE]; /** Probe function: * Called by ODP to get the enumerator class instances registered @@ -198,7 +198,7 @@ struct odpdrv_enumr_param_t { * The format of the enum_dev part for the odpdrv_device_param_t * structure is identified by the api-name and version below */ - const char api_name[ODPDRV_NAME_SIZE]; + char api_name[ODPDRV_NAME_SIZE]; uint32_t api_version; /**<< the version of the provided API */ /** Probe function: @@ -240,7 +240,7 @@ struct odpdrv_device_param_t { * e.g. "0000.23.12.1" for PCI domain 0, bus 23, device 12, function 1. * This string identifies the device uniquely. */ - const char address[ODPDRV_NAME_ADDR_SZ]; + char address[ODPDRV_NAME_ADDR_SZ]; /** Enumerator dependent part * This part is allocated by the enumerator and is enumerator dependent @@ -260,13 +260,13 @@ struct odpdrv_devio_param_t { * with same provided interface should refer to a common enumerator * class) */ - const char api_name[ODPDRV_NAME_SIZE]; + char api_name[ODPDRV_NAME_SIZE]; uint32_t api_version; /**<< the version of the provided API */ /** Enumerator interface name and version * The enumerator interface this devio needs. */ - const char enumr_api_name[ODPDRV_NAME_SIZE]; + char enumr_api_name[ODPDRV_NAME_SIZE]; uint32_t enumr_api_version; /**<< required enumerator API version */ /** Ops @@ -283,14 +283,14 @@ struct odpdrv_driver_param_t { * The driver name (the pair {driver-name, enum-api-name} must * be unique) */ - const char name[ODPDRV_NAME_SIZE]; + char name[ODPDRV_NAME_SIZE]; /** Supported devios: * The list of supported devio: one of the following devio * (with correct version) must be available for the driver to work: */ struct { - const char api_name[ODPDRV_NAME_SIZE]; /**<< devio API name */ + char api_name[ODPDRV_NAME_SIZE]; /**<< devio API name */ uint32_t api_version; /**<< devio API version */ } devios[ODPDRV_MAX_DEVIOS]; From patchwork Wed Mar 22 14:48:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95728 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp225379obz; Wed, 22 Mar 2017 06:52:15 -0700 (PDT) X-Received: by 10.107.180.70 with SMTP id d67mr42801586iof.21.1490190735374; Wed, 22 Mar 2017 06:52:15 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id v11si1832176iti.19.2017.03.22.06.52.15; Wed, 22 Mar 2017 06:52:15 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id DF3216432F; Wed, 22 Mar 2017 13:52:14 +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, URIBL_BLOCKED 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 46B67642D4; Wed, 22 Mar 2017 13:49:33 +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 0BAB1642BD; Wed, 22 Mar 2017 13:49:22 +0000 (UTC) Received: from mail-wm0-f51.google.com (mail-wm0-f51.google.com [74.125.82.51]) by lists.linaro.org (Postfix) with ESMTPS id 3207762D78 for ; Wed, 22 Mar 2017 13:49:19 +0000 (UTC) Received: by mail-wm0-f51.google.com with SMTP id t189so38377395wmt.1 for ; Wed, 22 Mar 2017 06:49:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GsFNXwoVD1G5SQfpF0ehhkF214t2SuT6kvLVxDXLCZ8=; b=NKmRQBzL90EDK0wVFWpAWYbrB41Zt2NjE+XWJvfEDN8Znt3ugmQGyavFpOfes+/uyW XPZn8GdnjeRPUuyoHhNKrMyIPo8tyovqOmJbTF0wVpeMocj+wiqRJXMN+2QKPkrz+wl5 FmKA9JC+Xr1UZvWb6chzW2RBh2FxrkVqtbrHTSDJKz7sdewlzlzkidPAcaIB6v19AJtD NESjj5sJRYxLFOtdUWtJ/uRo8S6QfDM5gUdiSZfu47/sxSk983Ojd49cvQuFSVCCAd26 qOiUeZp0+MczNaoIujjsh+77R9K8qtZe+Jr/ZVppw7b4idSGDaxQopD8WK4mDQXJVYhM CLUQ== X-Gm-Message-State: AFeK/H2rSpppzXY9qmZ/8V6ykoFzD2sQgx1zZ+mOPtDIAEgp7IGzbn//8X1xKY79LXWBC5DK1eDPEEyp X-Received: by 10.25.198.19 with SMTP id w19mr11718833lff.175.1490190557901; Wed, 22 Mar 2017 06:49:17 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:17 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:11 +0100 Message-Id: <1490194110-40168-5-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 04/23] linux-gen: drv: enumerator_class registration 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" The functions to register and probe enumerator classes are added. Signed-off-by: Christophe Milard --- platform/linux-generic/Makefile.am | 1 + platform/linux-generic/_modules.c | 4 + platform/linux-generic/drv_driver.c | 212 ++++++++++++++++++++- .../linux-generic/include/drv_driver_internal.h | 22 +++ platform/linux-generic/include/odp_internal.h | 5 + platform/linux-generic/odp_init.c | 21 +- 6 files changed, 260 insertions(+), 5 deletions(-) create mode 100644 platform/linux-generic/include/drv_driver_internal.h -- 2.7.4 diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index deab284..02f13fe 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -133,6 +133,7 @@ noinst_HEADERS = \ ${srcdir}/include/_ishm_internal.h \ ${srcdir}/include/_ishmphy_internal.h \ ${srcdir}/include/_ishmpool_internal.h \ + ${srcdir}/include/drv_driver_internal.h\ ${srcdir}/include/odp_align_internal.h \ ${srcdir}/include/odp_atomic_internal.h \ ${srcdir}/include/odp_buffer_inlines.h \ diff --git a/platform/linux-generic/_modules.c b/platform/linux-generic/_modules.c index 6bb854e..b23c81f 100644 --- a/platform/linux-generic/_modules.c +++ b/platform/linux-generic/_modules.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,9 @@ static int load_modules(void) ODP_DBG("module %s loaded.\n", module_name); } + /* give a chance top the driver interface to probe for new things: */ + _odpdrv_driver_probe_drv_items(); + return 0; } diff --git a/platform/linux-generic/drv_driver.c b/platform/linux-generic/drv_driver.c index 529da48..50956a7 100644 --- a/platform/linux-generic/drv_driver.c +++ b/platform/linux-generic/drv_driver.c @@ -4,20 +4,131 @@ * SPDX-License-Identifier: BSD-3-Clause */ +#include + #include +#include <_ishmpool_internal.h> #include #include +#include #include +#include #include +#include + +static enum {UNDONE, IN_PROGRESS, DONE} init_global_status; + +/* pool from which different list elements are alocated: */ +#define ELT_POOL_SIZE (1 << 20) /* 1Mb */ +static _odp_ishm_pool_t *list_elt_pool; + +typedef struct _odpdrv_enumr_class_s _odpdrv_enumr_class_t; + +/* an enumerator class (list element) */ +struct _odpdrv_enumr_class_s { + odpdrv_enumr_class_param_t param; + int probed; + _odp_ishm_pool_t *pool; + struct _odpdrv_enumr_class_s *next; +}; + +/* the enumerator class list: */ +typedef struct _odpdrv_enumr_class_lst_t { + odp_rwlock_recursive_t lock; + _odpdrv_enumr_class_t *head; +} _odpdrv_enumr_class_lst_t; +static struct _odpdrv_enumr_class_lst_t enumr_class_lst; + +/* some driver elements (such as enumeraor classes, drivers, devio) may + * register before init_global and init_local complete. Mutex will fail + * in this cases but should be used later on. + * These functions disable the usage of Mutex while it is global init i.e. + * while single threaded*/ +static void enumr_class_list_read_lock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_read_lock(&enumr_class_lst.lock); +} + +static void enumr_class_list_read_unlock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_read_unlock(&enumr_class_lst.lock); +} + +static void enumr_class_list_write_lock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_write_lock(&enumr_class_lst.lock); +} + +static void enumr_class_list_write_unlock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_write_unlock(&enumr_class_lst.lock); +} + odpdrv_enumr_class_t odpdrv_enumr_class_register(odpdrv_enumr_class_param_t *param) { - ODP_ERR("NOT Supported yet! Enumerator Class %s Registration!\n.", - param->name); + _odpdrv_enumr_class_t *enumr_c; - return ODPDRV_ENUMR_CLASS_INVALID; + /* parse the list of already registered enumerator class to make + * sure no enumerator with identical name already exists: + */ + enumr_class_list_read_lock(); + enumr_c = enumr_class_lst.head; + while (enumr_c) { + if (strncmp(param->name, enumr_c->param.name, + ODPDRV_NAME_SIZE) == 0) { + ODP_ERR("enumerator class %s already exists!\n", + param->name); + enumr_class_list_read_unlock(); + return ODPDRV_ENUMR_CLASS_INVALID; + } + enumr_c = enumr_c->next; + } + enumr_class_list_read_unlock(); + + /* allocate memory for the new enumerator class: + * If init_global has not been done yet, then, we cannot allocate + * from any _ishm pool (ishm has not even been initialised at this + * stage...this happens when statically linked enumerator classes + * register: their __constructor__ function is run before main() + * is called). But any malloc performed here(before init_global) + * will be inherited by any odpthreads (process or pthreads) as we + * are still running in the ODP instantiation processes and all + * other processes are guaranteed to be descendent of this one... + * If init_global has been done, then we allocate from the _ishm pool + * to guarantee visibility from any ODP thread. + */ + + if (init_global_status == UNDONE) { + enumr_c = malloc(sizeof(_odpdrv_enumr_class_t)); + if (!enumr_c) + return ODPDRV_ENUMR_CLASS_INVALID; + enumr_c->pool = NULL; + } else { + enumr_c = _odp_ishm_pool_alloc(list_elt_pool, + sizeof(_odpdrv_enumr_class_t)); + if (!enumr_c) { + ODP_ERR("_odp_ishm_pool_alloc failed!\n"); + return ODPDRV_ENUMR_CLASS_INVALID; + } + enumr_c->pool = list_elt_pool; + } + + /* save init parameters and insert enumerator class in list */ + enumr_c->param = *param; + enumr_c->probed = 0; + enumr_class_list_write_lock(); + enumr_c->next = enumr_class_lst.head; + enumr_class_lst.head = enumr_c; + enumr_class_list_write_unlock(); + + return (odpdrv_enumr_class_t)enumr_c; } odpdrv_enumr_t odpdrv_enumr_register(odpdrv_enumr_param_t *param) @@ -57,8 +168,101 @@ odpdrv_driver_t odpdrv_driver_register(odpdrv_driver_param_t *param) return ODPDRV_DRIVER_INVALID; } +/* the following function is called each time probing is needed, i.e. + * at init or after loading a new module as a module can be anything, + * including enumerators or drivers */ +void _odpdrv_driver_probe_drv_items(void) +{ + _odpdrv_enumr_class_t *enumr_c; + + /* probe unprobed enumerators: */ + enumr_class_list_read_lock(); + enumr_c = enumr_class_lst.head; + while (enumr_c) { + if (!enumr_c->probed) { + enumr_c->param.probe(); + enumr_c->probed = 1; + } + enumr_c = enumr_c->next; + } + enumr_class_list_read_unlock(); +} + int odpdrv_print_all(void) { - ODP_ERR("odpdrv_print_all not Supported yet!\n."); + _odpdrv_enumr_class_t *enumr_c; + + /* we cannot use ODP_DBG before ODP init... */ + if (init_global_status == UNDONE) + return 0; + + ODP_DBG("ODP Driver status:\n"); + + /* print the list of registered enumerator classes: */ + enumr_class_list_read_lock(); + enumr_c = enumr_class_lst.head; + ODP_DBG("The following enumerator classes have been registered:\n"); + while (enumr_c) { + ODP_DBG(" class: %s\n", enumr_c->param.name); + enumr_c = enumr_c->next; + } + enumr_class_list_read_unlock(); + return 0; +} + +int _odpdrv_driver_init_global(void) +{ + /* create a memory pool to for list elements: */ + list_elt_pool = _odp_ishm_pool_create(NULL, ELT_POOL_SIZE, + 0, ELT_POOL_SIZE, 0); + + /* remember that init global is being done so the further list allocs + * are made from the list_elt_pool: */ + init_global_status = IN_PROGRESS; + + /* from now, we want to ensure mutex on the list: init lock: */ + odp_rwlock_recursive_init(&enumr_class_lst.lock); + + /* probe things... */ + _odpdrv_driver_probe_drv_items(); + + return 0; +} + +int _odpdrv_driver_init_local(void) +{ + /* remember that init global is done, so list mutexes are used from + * now */ + init_global_status = DONE; + return 0; +} + +int _odpdrv_driver_term_global(void) +{ + _odpdrv_enumr_class_t *enumr_c; + + if (init_global_status == UNDONE) + return 0; + + /* remove all enumerator classes which are registered: */ + enumr_class_list_write_lock(); + while (enumr_class_lst.head) { + enumr_c = enumr_class_lst.head; + if (enumr_c->param.remove) { /* run remove callback, if any */ + if (enumr_c->param.remove()) + ODP_ERR("Enumerator class %s removal failed.\n", + enumr_c->param.name); + } + enumr_class_lst.head = enumr_c->next; + if (enumr_c->pool) + _odp_ishm_pool_free(list_elt_pool, enumr_c); + else + free(enumr_c); + } + enumr_class_list_write_unlock(); + + /* destroy the list element pool: */ + _odp_ishm_pool_destroy(list_elt_pool); + return 0; } diff --git a/platform/linux-generic/include/drv_driver_internal.h b/platform/linux-generic/include/drv_driver_internal.h new file mode 100644 index 0000000..eb06c1b --- /dev/null +++ b/platform/linux-generic/include/drv_driver_internal.h @@ -0,0 +1,22 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef DRV_DRIVER_INTERNAL_H_ +#define DRV_DRIVER_INTERNAL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void _odpdrv_driver_probe_drv_items(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index 05c8a42..1760b56 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -71,6 +71,7 @@ enum init_stage { CLASSIFICATION_INIT, TRAFFIC_MNGR_INIT, NAME_TABLE_INIT, + DRIVER_INIT, MODULES_INIT, ALL_INIT /* All init stages completed */ }; @@ -130,6 +131,10 @@ int _odp_ishm_init_local(void); int _odp_ishm_term_global(void); int _odp_ishm_term_local(void); +int _odpdrv_driver_init_global(void); +int _odpdrv_driver_init_local(void); +int _odpdrv_driver_term_global(void); + int _odp_modules_init_global(void); int cpuinfo_parser(FILE *file, system_info_t *sysinfo); diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index 685e02f..c59cc28 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -266,6 +266,12 @@ int odp_init_global(odp_instance_t *instance, } stage = NAME_TABLE_INIT; + if (_odpdrv_driver_init_global()) { + ODP_ERR("ODP drivers init failed\n"); + goto init_failed; + } + stage = DRIVER_INIT; + if (_odp_modules_init_global()) { ODP_ERR("ODP modules init failed\n"); goto init_failed; @@ -296,6 +302,13 @@ int _odp_term_global(enum init_stage stage) switch (stage) { case ALL_INIT: case MODULES_INIT: + case DRIVER_INIT: + if (_odpdrv_driver_term_global()) { + ODP_ERR("driver term failed.\n"); + rc = -1; + } + /* Fall through */ + case NAME_TABLE_INIT: if (_odp_int_name_tbl_term_global()) { ODP_ERR("Name table term failed.\n"); @@ -445,7 +458,13 @@ int odp_init_local(odp_instance_t instance, odp_thread_type_t thr_type) ODP_ERR("ODP schedule local init failed.\n"); goto init_fail; } - /* stage = SCHED_INIT; */ + stage = SCHED_INIT; + + if (_odpdrv_driver_init_local()) { + ODP_ERR("ODP driver local init failed.\n"); + goto init_fail; + } + /* stage = DRIVER_INIT; */ return 0; From patchwork Wed Mar 22 14:48:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95729 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp225789obz; Wed, 22 Mar 2017 06:53:26 -0700 (PDT) X-Received: by 10.200.39.136 with SMTP id w8mr38261190qtw.284.1490190806722; Wed, 22 Mar 2017 06:53:26 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id v86si1130138qkv.236.2017.03.22.06.53.26; Wed, 22 Mar 2017 06:53:26 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 453C8608B3; Wed, 22 Mar 2017 13:53:26 +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.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED,URI_NOVOWEL 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 A90F9642E1; Wed, 22 Mar 2017 13:49:37 +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 69271642CD; Wed, 22 Mar 2017 13:49:28 +0000 (UTC) Received: from mail-wm0-f53.google.com (mail-wm0-f53.google.com [74.125.82.53]) by lists.linaro.org (Postfix) with ESMTPS id 53F2862DC6 for ; Wed, 22 Mar 2017 13:49:20 +0000 (UTC) Received: by mail-wm0-f53.google.com with SMTP id t189so38377850wmt.1 for ; Wed, 22 Mar 2017 06:49:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=STowojhA7UU72B3nnawC88ViACf2cTVUfxtinB+8oxo=; b=Eu8adMPVWYD2dDcm2U0RIpeRrzixwOaQDE9A3ghwM7PKf9qaKlwi9Etg5VzNQ9lOXP P36vgYgGVJUuOxc/XGi4voBdhR+eIPc1yO6zuu+Wrn/vIQ2K+IdDJ8FCum6m9O/E4eCm f0yq8yt2Ipmj0zL9ldt/O27YnXDPp/AoQbYSuTJgNuaow6soNqT1yJ5IO+awmVybJXA9 bOEaUnFyhFL6uhe5oUSrNKJGJqBkTAzMf6Qvmm/TXbj8RQFk28mb2XrXOQV3KDhsBLPI kzg9/g1kjl86l2L7kYB5WysY7fJ2K6HZqgJ39VzaoPtpjoMfK+nyVWtif2YQQzgRel4s SyZA== X-Gm-Message-State: AFeK/H0YP/rtb8dpbTs3EUNMK0hTH93Q+Wm8ekIWlPEFzOQgDKxnX4CrF8mgupssCuSOXcGe/c1UpHRn X-Received: by 10.25.234.219 with SMTP id y88mr11003111lfi.35.1490190559130; Wed, 22 Mar 2017 06:49:19 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:18 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:12 +0100 Message-Id: <1490194110-40168-6-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 05/23] test: drv: enumerator_class registration tests 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" Testing that enumerators classes can register properly. Saddly restricted to statically linked enumerators classes, as testing with modules in autotools seems to be an issue so far. Signed-off-by: Christophe Milard --- test/common_plat/m4/configure.m4 | 1 + test/common_plat/validation/drv/Makefile.am | 1 + .../validation/drv/drvdriver/.gitignore | 1 + .../validation/drv/drvdriver/Makefile.am | 16 ++ .../drv/drvdriver/drvdriver_enumr_class.c | 174 +++++++++++++++++++++ .../drv/drvdriver/drvdriver_enumr_class.h | 24 +++ .../drv/drvdriver/drvdriver_enumr_class_main.c | 12 ++ test/linux-generic/Makefile.am | 1 + 8 files changed, 230 insertions(+) create mode 100644 test/common_plat/validation/drv/drvdriver/.gitignore create mode 100644 test/common_plat/validation/drv/drvdriver/Makefile.am create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.c create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.h create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class_main.c -- 2.7.4 diff --git a/test/common_plat/m4/configure.m4 b/test/common_plat/m4/configure.m4 index 13a13bd..400750c 100644 --- a/test/common_plat/m4/configure.m4 +++ b/test/common_plat/m4/configure.m4 @@ -34,4 +34,5 @@ AC_CONFIG_FILES([test/common_plat/Makefile test/common_plat/validation/api/traffic_mngr/Makefile test/common_plat/validation/drv/Makefile test/common_plat/validation/drv/drvatomic/Makefile + test/common_plat/validation/drv/drvdriver/Makefile test/common_plat/validation/drv/drvshmem/Makefile]) diff --git a/test/common_plat/validation/drv/Makefile.am b/test/common_plat/validation/drv/Makefile.am index bcdb92e..7329a89 100644 --- a/test/common_plat/validation/drv/Makefile.am +++ b/test/common_plat/validation/drv/Makefile.am @@ -1,4 +1,5 @@ ODPDRV_MODULES = drvatomic \ + drvdriver \ drvshmem SUBDIRS = $(ODPDRV_MODULES) diff --git a/test/common_plat/validation/drv/drvdriver/.gitignore b/test/common_plat/validation/drv/drvdriver/.gitignore new file mode 100644 index 0000000..9268315 --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/.gitignore @@ -0,0 +1 @@ +drvdriver_enumr_class_main diff --git a/test/common_plat/validation/drv/drvdriver/Makefile.am b/test/common_plat/validation/drv/drvdriver/Makefile.am new file mode 100644 index 0000000..9e941ee --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/Makefile.am @@ -0,0 +1,16 @@ +include ../Makefile.inc + +# because most of driver activity occurs at init time, and due to the +# fact that many sequential ODP runs are not allowed from the same process, +# we need different binaries for each things being tested (as API init) + +#tests for enumerator class registration: +noinst_LTLIBRARIES = libtestdrvdriverenumrclass.la +libtestdrvdriverenumrclass_la_SOURCES = drvdriver_enumr_class.c + +test_PROGRAMS = drvdriver_enumr_class_main$(EXEEXT) +dist_drvdriver_enumr_class_main_SOURCES = drvdriver_enumr_class_main.c +drvdriver_enumr_class_main_LDADD = libtestdrvdriverenumrclass.la \ + $(LIBCUNIT_COMMON) $(LIBODP) + +EXTRA_DIST = drvdriver_enumr_class.h diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.c b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.c new file mode 100644 index 0000000..f7dd42c --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.c @@ -0,0 +1,174 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include +#include "drvdriver_enumr_class.h" +#include + +static odp_instance_t odp_instance; + +static int enumr_class1_probed; +static int enumr_class2_probed; + +/* forward declaration */ +static int enumr_class1_probe(void); +static int enumr_class2_probe(void); + +static int enumr_class1_remove(void); +static int enumr_class2_remove(void); + +/* because many things to be checked are performed during ODP initialisation, + * the initialisation functions have to be a part of the test + */ +static int tests_global_init(void) +{ + if (0 != odp_init_global(&odp_instance, NULL, NULL)) { + fprintf(stderr, "error: odp_init_global() failed.\n"); + return -1; + } + if (0 != odp_init_local(odp_instance, ODP_THREAD_CONTROL)) { + fprintf(stderr, "error: odp_init_local() failed.\n"); + return -1; + } + + return 0; +} + +static int tests_global_term(void) +{ + if (0 != odp_term_local()) { + fprintf(stderr, "error: odp_term_local() failed.\n"); + return -1; + } + + if (0 != odp_term_global(odp_instance)) { + fprintf(stderr, "error: odp_term_global() failed.\n"); + return -1; + } + + return 0; +} + +/*enumerator class register functions, all "statically linked" + *(i.e. directely run at start), due to the fact that platorm independent + * shared lib loading in autotools is a mess */ +static void ODPDRV_CONSTRUCTOR enumr_class1_register(void) +{ + odpdrv_enumr_class_param_t param = { + .name = "Enumerator_class1", + .probe = enumr_class1_probe, + .remove = enumr_class1_remove + }; + + odpdrv_enumr_class_register(¶m); +} + +static void ODPDRV_CONSTRUCTOR enumr_class2_register(void) +{ + odpdrv_enumr_class_param_t param = { + .name = "Enumerator_class2", + .probe = enumr_class2_probe, + .remove = enumr_class2_remove + }; + + odpdrv_enumr_class_register(¶m); +} + +static odpdrv_enumr_class_t enumr_class2_register_retry(void) +{ + odpdrv_enumr_class_param_t param = { + .name = "Enumerator_class2", + .probe = enumr_class2_probe, + .remove = enumr_class2_remove + }; + + return odpdrv_enumr_class_register(¶m); +} + +/*enumerator class probe functions, just making sure they have been run: */ +static int enumr_class1_probe(void) +{ + enumr_class1_probed = 1; + return 0; +} + +static int enumr_class2_probe(void) +{ + enumr_class2_probed = 1; + return 0; +} + +/*enumerator class remove functions, just making sure they have been run: */ +static int enumr_class1_remove(void) +{ + enumr_class1_probed = -1; + return 0; +} + +static int enumr_class2_remove(void) +{ + enumr_class2_probed = -1; + return 0; +} + +void drvdriver_test_enumr_class_register(void) +{ + CU_ASSERT(enumr_class1_probed == 0); + CU_ASSERT(enumr_class2_probed == 0); + + CU_ASSERT(tests_global_init() == 0); + + /* at this point (after odp init), the constructor + * enumerator classes should have registered and been probed: + */ + CU_ASSERT(odpdrv_print_all() == 0); + + CU_ASSERT(enumr_class1_probed == 1); + CU_ASSERT(enumr_class2_probed == 1); + CU_ASSERT(odpdrv_print_all() == 0); + + /* re-register enumr_class2: this should be kicked-out! */ + CU_ASSERT(enumr_class2_register_retry() == ODPDRV_ENUMR_CLASS_INVALID); + + CU_ASSERT(tests_global_term() == 0); + + /* after ODP termination completion, all enumerators should be removed*/ + CU_ASSERT(enumr_class1_probed == -1); + CU_ASSERT(enumr_class2_probed == -1); +} + +odp_testinfo_t drvdriver_suite_enumr_class[] = { + ODP_TEST_INFO(drvdriver_test_enumr_class_register), + ODP_TEST_INFO_NULL, +}; + +odp_suiteinfo_t drvdriver_suites_enumr_class[] = { + {"Enumerator registration", NULL, NULL, drvdriver_suite_enumr_class}, + ODP_SUITE_INFO_NULL, +}; + +int drvdriver_enumr_class_main(int argc, char *argv[]) +{ + int ret; + + /* parse common options: */ + if (odp_cunit_parse_options(argc, argv)) + return -1; + + /* prevent default ODP init: */ + odp_cunit_register_global_init(NULL); + odp_cunit_register_global_term(NULL); + + /* register the tests: */ + ret = odp_cunit_register(drvdriver_suites_enumr_class); + + if (ret == 0) + ret = odp_cunit_run(); + + return ret; +} diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.h b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.h new file mode 100644 index 0000000..a4f6cdc --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.h @@ -0,0 +1,24 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_DRVDRIVER_ENUMR_CLASS_H_ +#define _ODP_TEST_DRVDRIVER_ENUMR_CLASS_H_ + +#include + +/* test functions: */ +void drvdriver_test_enumr_class_register(void); + +/* test arrays: */ +extern odp_testinfo_t drvdriver_suite_enumr_class[]; + +/* test registry: */ +extern odp_suiteinfo_t drvdriver_suites_enumr_class[]; + +/* main test program: */ +int drvdriver_enumr_class_main(int argc, char *argv[]); + +#endif diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class_main.c b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class_main.c new file mode 100644 index 0000000..45a4c1a --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class_main.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "drvdriver_enumr_class.h" + +int main(int argc, char *argv[]) +{ + return drvdriver_enumr_class_main(argc, argv); +} diff --git a/test/linux-generic/Makefile.am b/test/linux-generic/Makefile.am index 26d39cc..16a5cb6 100644 --- a/test/linux-generic/Makefile.am +++ b/test/linux-generic/Makefile.am @@ -36,6 +36,7 @@ TESTS = validation/api/pktio/pktio_run.sh \ $(ALL_API_VALIDATION_DIR)/shmem/shmem_main$(EXEEXT) \ $(ALL_API_VALIDATION_DIR)/system/system_main$(EXEEXT) \ $(ALL_DRV_VALIDATION_DIR)/drvatomic/drvatomic_main$(EXEEXT) \ + $(ALL_DRV_VALIDATION_DIR)/drvdriver/drvdriver_enumr_class_main$(EXEEXT)\ $(ALL_DRV_VALIDATION_DIR)/drvshmem/drvshmem_main$(EXEEXT) \ ring/ring_main$(EXEEXT) From patchwork Wed Mar 22 14:48:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95730 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp226286obz; Wed, 22 Mar 2017 06:54:48 -0700 (PDT) X-Received: by 10.233.222.69 with SMTP id s66mr17227943qkf.126.1490190888469; Wed, 22 Mar 2017 06:54:48 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id q48si1131178qta.270.2017.03.22.06.54.48; Wed, 22 Mar 2017 06:54:48 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 23467608B3; Wed, 22 Mar 2017 13:54:48 +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, URIBL_BLOCKED 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 69A8C642DB; Wed, 22 Mar 2017 13:50:03 +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 2C8FA642E9; Wed, 22 Mar 2017 13:49:58 +0000 (UTC) Received: from mail-wm0-f50.google.com (mail-wm0-f50.google.com [74.125.82.50]) by lists.linaro.org (Postfix) with ESMTPS id 58582642BC for ; Wed, 22 Mar 2017 13:49:21 +0000 (UTC) Received: by mail-wm0-f50.google.com with SMTP id n11so37217914wma.1 for ; Wed, 22 Mar 2017 06:49:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=W7YwWi3bxVYUn75lXHMSnvXUgdwYvnP2/e67v7fC+x8=; b=tjHVosQpXz+xXqW9L+U46k1nZa8Y2PhvlvMv3kwIxg6I1UifkA7vHU3HSe22wpi9I2 NtOZO4f8ilRmAZg0QeL4uGI0eRRz6sEkNvcDZvxWF0qWIeAzg/zDBhm8huWpLexTIfRc 8cE/e5gHsD5e1bGQ/nO4Ts50FywSLjtY3YtbmMko5v6RUqgjRDBRwQc7pwlp45bSHAqk Yq+hpiKf43tmKTesqZbfMUJbpKBMTJ2Ok/f94p9xG/0aWZdOy67HLfqtlvJhAwq/9w/P 33ZA398D+D74hVoQ2VJZ7CqVrbHOIJE5p9YFCu9vG/rd2xrYN9wEMFCynOQePZG18xUD +aPw== X-Gm-Message-State: AFeK/H2/mc7/FCvTvZXRh5KGjngKbHdOnWOFnU3xiRvrm2qDuCqw3e4VzI9IVjuE0NB3g1lB/Tw= X-Received: by 10.25.115.19 with SMTP id o19mr994965lfc.162.1490190560169; Wed, 22 Mar 2017 06:49:20 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:19 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:13 +0100 Message-Id: <1490194110-40168-7-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 06/23] linux-gen: drv: enumerator registration 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" The enumerator registration functions for the linux-gen ODP implementation. Signed-off-by: Christophe Milard --- platform/linux-generic/drv_driver.c | 139 +++++++++++++++++++++++++++++++++++- 1 file changed, 136 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/platform/linux-generic/drv_driver.c b/platform/linux-generic/drv_driver.c index 50956a7..35473bd 100644 --- a/platform/linux-generic/drv_driver.c +++ b/platform/linux-generic/drv_driver.c @@ -24,6 +24,7 @@ static enum {UNDONE, IN_PROGRESS, DONE} init_global_status; static _odp_ishm_pool_t *list_elt_pool; typedef struct _odpdrv_enumr_class_s _odpdrv_enumr_class_t; +typedef struct _odpdrv_enumr_s _odpdrv_enumr_t; /* an enumerator class (list element) */ struct _odpdrv_enumr_class_s { @@ -40,6 +41,20 @@ typedef struct _odpdrv_enumr_class_lst_t { } _odpdrv_enumr_class_lst_t; static struct _odpdrv_enumr_class_lst_t enumr_class_lst; +/* an enumerator (list element) */ +struct _odpdrv_enumr_s { + odpdrv_enumr_param_t param; + int probed; + struct _odpdrv_enumr_s *next; +}; + +/* the enumerator list: */ +typedef struct _odpdrv_enumr_lst_t { + odp_rwlock_recursive_t lock; + _odpdrv_enumr_t *head; +} _odpdrv_enumr_lst_t; +static struct _odpdrv_enumr_lst_t enumr_lst; + /* some driver elements (such as enumeraor classes, drivers, devio) may * register before init_global and init_local complete. Mutex will fail * in this cases but should be used later on. @@ -69,6 +84,35 @@ static void enumr_class_list_write_unlock(void) odp_rwlock_recursive_write_unlock(&enumr_class_lst.lock); } +static void enumr_list_read_lock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_read_lock(&enumr_lst.lock); +} + +static void enumr_list_read_unlock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_read_unlock(&enumr_lst.lock); +} + +static void enumr_list_write_lock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_write_lock(&enumr_lst.lock); +} + +static void enumr_list_write_unlock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_write_unlock(&enumr_lst.lock); +} + +/* some functions to get internal pointers from handles... */ +static inline _odpdrv_enumr_class_t *get_enumr_class(odpdrv_enumr_class_t class) +{ + return (_odpdrv_enumr_class_t *)(void *)class; +} odpdrv_enumr_class_t odpdrv_enumr_class_register(odpdrv_enumr_class_param_t *param) @@ -133,10 +177,52 @@ odpdrv_enumr_class_t odpdrv_enumr_class_register(odpdrv_enumr_class_param_t odpdrv_enumr_t odpdrv_enumr_register(odpdrv_enumr_param_t *param) { - ODP_ERR("NOT Supported yet! Enumerator API %s Registration!\n.", - param->api_name); + _odpdrv_enumr_t *enumr; + _odpdrv_enumr_class_t *enumr_c; + int found_class = 0; - return ODPDRV_ENUMR_INVALID; + /* make sure that the provided enumerator_class does indeed exist: */ + enumr_class_list_read_lock(); + enumr_c = enumr_class_lst.head; + while (enumr_c) { + if (get_enumr_class(param->enumr_class) == enumr_c) { + found_class = 1; + break; + } + enumr_c = enumr_c->next; + } + enumr_class_list_read_unlock(); + if (!found_class) { + ODP_ERR("invalid enumerator class provided!\n"); + return ODPDRV_ENUMR_INVALID; + } + + /* allocate memory for the new enumerator: + * If init_global has not been done yet, we have a big issue, + * as none of the enumerator classes should be probed before that! + * We cannot even issue an error as ODP_* functions have not been + * initialised yet, but this is no good... + */ + + if (init_global_status == UNDONE) + return ODPDRV_ENUMR_INVALID; + + enumr = _odp_ishm_pool_alloc(list_elt_pool, + sizeof(_odpdrv_enumr_t)); + if (!enumr) { + ODP_ERR("_odp_ishm_pool_alloc failed!\n"); + return ODPDRV_ENUMR_INVALID; + } + + /* save init parameters and insert enumerator in list */ + enumr->param = *param; + enumr->probed = 0; + enumr_list_write_lock(); + enumr->next = enumr_lst.head; + enumr_lst.head = enumr; + enumr_list_write_unlock(); + + return (odpdrv_enumr_t)enumr; } odpdrv_device_t odpdrv_device_create(odpdrv_device_param_t *param) @@ -174,6 +260,7 @@ odpdrv_driver_t odpdrv_driver_register(odpdrv_driver_param_t *param) void _odpdrv_driver_probe_drv_items(void) { _odpdrv_enumr_class_t *enumr_c; + _odpdrv_enumr_t *enumr; /* probe unprobed enumerators: */ enumr_class_list_read_lock(); @@ -186,11 +273,26 @@ void _odpdrv_driver_probe_drv_items(void) enumr_c = enumr_c->next; } enumr_class_list_read_unlock(); + + /* go through the list of registered enumerator probing the new + * (never probed) ones: + */ + enumr_list_read_lock(); + enumr = enumr_lst.head; + while (enumr) { + if (!enumr->probed) { + enumr->param.probe(); + enumr->probed = 1; + } + enumr = enumr->next; + } + enumr_list_read_unlock(); } int odpdrv_print_all(void) { _odpdrv_enumr_class_t *enumr_c; + _odpdrv_enumr_t *enumr; /* we cannot use ODP_DBG before ODP init... */ if (init_global_status == UNDONE) @@ -207,6 +309,21 @@ int odpdrv_print_all(void) enumr_c = enumr_c->next; } enumr_class_list_read_unlock(); + + /* print the list of registered enumerators: */ + enumr_list_read_lock(); + enumr = enumr_lst.head; + ODP_DBG("The following enumerators have been registered:\n"); + while (enumr) { + enumr_c = get_enumr_class(enumr->param.enumr_class); + ODP_DBG(" enumerator: class: %s, API: %s, Version: %d\n", + enumr_c->param.name, + enumr->param.api_name, + enumr->param.api_version); + enumr = enumr->next; + } + enumr_list_read_unlock(); + return 0; } @@ -222,6 +339,7 @@ int _odpdrv_driver_init_global(void) /* from now, we want to ensure mutex on the list: init lock: */ odp_rwlock_recursive_init(&enumr_class_lst.lock); + odp_rwlock_recursive_init(&enumr_lst.lock); /* probe things... */ _odpdrv_driver_probe_drv_items(); @@ -240,10 +358,25 @@ int _odpdrv_driver_init_local(void) int _odpdrv_driver_term_global(void) { _odpdrv_enumr_class_t *enumr_c; + _odpdrv_enumr_t *enumr; if (init_global_status == UNDONE) return 0; + /* remove all enumerators which are registered: */ + enumr_list_write_lock(); + while (enumr_lst.head) { + enumr = enumr_lst.head; + if (enumr->param.remove) { /* run remove callback, if any */ + if (enumr->param.remove()) + ODP_ERR("Enumerator (API %s) removal failed.\n", + enumr->param.api_name); + } + enumr_lst.head = enumr->next; + _odp_ishm_pool_free(list_elt_pool, enumr); + } + enumr_list_write_unlock(); + /* remove all enumerator classes which are registered: */ enumr_class_list_write_lock(); while (enumr_class_lst.head) { From patchwork Wed Mar 22 14:48:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95731 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp226834obz; Wed, 22 Mar 2017 06:56:13 -0700 (PDT) X-Received: by 10.200.52.65 with SMTP id v1mr41417284qtb.166.1490190973055; Wed, 22 Mar 2017 06:56:13 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 6si1140329qke.169.2017.03.22.06.56.12; Wed, 22 Mar 2017 06:56:13 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id A0259642C6; Wed, 22 Mar 2017 13:56:12 +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.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED,URI_NOVOWEL 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 19FA7642BD; Wed, 22 Mar 2017 13:50:12 +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 D7F0662D78; Wed, 22 Mar 2017 13:50:05 +0000 (UTC) Received: from mail-wm0-f49.google.com (mail-wm0-f49.google.com [74.125.82.49]) by lists.linaro.org (Postfix) with ESMTPS id 8283962D78 for ; Wed, 22 Mar 2017 13:49:22 +0000 (UTC) Received: by mail-wm0-f49.google.com with SMTP id u132so37320080wmg.0 for ; Wed, 22 Mar 2017 06:49:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rsYQXZmpjwI37hERX/iY4FgToZhHRVcZPRmThnD0Sqg=; b=tUqTzJgryQ/d5Zl4iehILonrykt/N/s5J+SiFxq9k5fzyKVlqy7YypDAWGNfUR+KJk ZP1mjiXltoEPey3Dz7oo7VpyVkJ4sC3JZpnO2TM7DzEKJaIWsQuVIckabNtJYjsumBi5 9mbPhbgwiREbMgYUidO5tcF7pnGU/v4DmivmuOU27C7coEf7Iu0aMduNYE17fe69u5wI LgyBGSsV/oUCAZZ6Jo2DmhnXkhGu1XplHj0U0Kz0e3TgZEB9XDq6zO1vsOn3CzeR8FvV cy/tpWpYnsuSHjdEQmeWs316F3gxvAW/YDoJfnFTHeg4JHeF/cDsCSpU7tcwHapBuZGE rVzg== X-Gm-Message-State: AFeK/H0vaBGdnLpF3iuGcWJsola9zEo30zlRN7TgkK0QxKMFD2kV59WzdclJsc4SLK2JMVFnPvyuPfmj X-Received: by 10.25.212.144 with SMTP id l138mr10685259lfg.26.1490190561239; Wed, 22 Mar 2017 06:49:21 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:20 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:14 +0100 Message-Id: <1490194110-40168-8-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 07/23] test: drv: enumerator registration tests 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" making sure that enumerators are probed. Signed-off-by: Christophe Milard --- .../validation/drv/drvdriver/.gitignore | 1 + .../validation/drv/drvdriver/Makefile.am | 11 + .../validation/drv/drvdriver/drvdriver_enumr.c | 303 +++++++++++++++++++++ .../validation/drv/drvdriver/drvdriver_enumr.h | 24 ++ .../drv/drvdriver/drvdriver_enumr_main.c | 12 + test/linux-generic/Makefile.am | 1 + 6 files changed, 352 insertions(+) create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_enumr.c create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_enumr.h create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_enumr_main.c -- 2.7.4 diff --git a/test/common_plat/validation/drv/drvdriver/.gitignore b/test/common_plat/validation/drv/drvdriver/.gitignore index 9268315..a842448 100644 --- a/test/common_plat/validation/drv/drvdriver/.gitignore +++ b/test/common_plat/validation/drv/drvdriver/.gitignore @@ -1 +1,2 @@ drvdriver_enumr_class_main +drvdriver_enumr_main diff --git a/test/common_plat/validation/drv/drvdriver/Makefile.am b/test/common_plat/validation/drv/drvdriver/Makefile.am index 9e941ee..3476c50 100644 --- a/test/common_plat/validation/drv/drvdriver/Makefile.am +++ b/test/common_plat/validation/drv/drvdriver/Makefile.am @@ -14,3 +14,14 @@ drvdriver_enumr_class_main_LDADD = libtestdrvdriverenumrclass.la \ $(LIBCUNIT_COMMON) $(LIBODP) EXTRA_DIST = drvdriver_enumr_class.h + +#tests for enumerator registration: +noinst_LTLIBRARIES += libtestdrvdriverenumr.la +libtestdrvdriverenumr_la_SOURCES = drvdriver_enumr.c + +test_PROGRAMS += drvdriver_enumr_main$(EXEEXT) +dist_drvdriver_enumr_main_SOURCES = drvdriver_enumr_main.c +drvdriver_enumr_main_LDADD = libtestdrvdriverenumr.la \ + $(LIBCUNIT_COMMON) $(LIBODP) + +EXTRA_DIST += drvdriver_enumr.h diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_enumr.c b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr.c new file mode 100644 index 0000000..38aac3d --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr.c @@ -0,0 +1,303 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include +#include "drvdriver_enumr.h" +#include + +static odp_instance_t odp_instance; +static odpdrv_enumr_class_t enumr_class1, enumr_class2; + +/* markers showing that different stages have been run */ +static int enumr1_probed; +static int enumr2_probed; +static int enumr3_probed; +static int enumr4_probed; + +/* forward declaration */ +static int enumr1_probe(void); +static int enumr2_probe(void); +static int enumr3_probe(void); +static int enumr4_probe(void); + +static int enumr1_remove(void); +static int enumr2_remove(void); +static int enumr3_remove(void); +static int enumr4_remove(void); + +static int enumr_class1_probe(void); +static int enumr_class2_probe(void); + +static int enumr_class1_remove(void); +static int enumr_class2_remove(void); + +/* because many things to be checked are performed during ODP initialisation, + * the initialisation functions have to be a part of the test + */ +static int tests_global_init(void) +{ + if (0 != odp_init_global(&odp_instance, NULL, NULL)) { + fprintf(stderr, "error: odp_init_global() failed.\n"); + return -1; + } + if (0 != odp_init_local(odp_instance, ODP_THREAD_CONTROL)) { + fprintf(stderr, "error: odp_init_local() failed.\n"); + return -1; + } + + return 0; +} + +static int tests_global_term(void) +{ + if (0 != odp_term_local()) { + fprintf(stderr, "error: odp_term_local() failed.\n"); + return -1; + } + + if (0 != odp_term_global(odp_instance)) { + fprintf(stderr, "error: odp_term_global() failed.\n"); + return -1; + } + + return 0; +} + +/*enumerator register functions */ +static odpdrv_enumr_t enumr1_register(void) +{ + odpdrv_enumr_param_t param = { + .enumr_class = enumr_class1, + .api_name = "Enumerator_interface_1", + .api_version = 1, + .probe = enumr1_probe, + .remove = enumr1_remove, + .register_notifier = NULL + }; + + return odpdrv_enumr_register(¶m); +} + +static odpdrv_enumr_t enumr2_register(void) +{ + odpdrv_enumr_param_t param = { + .enumr_class = enumr_class1, + .api_name = "Enumerator_interface_2", + .api_version = 1, + .probe = enumr2_probe, + .remove = enumr2_remove, + .register_notifier = NULL + }; + + return odpdrv_enumr_register(¶m); +} + +static odpdrv_enumr_t enumr3_register(void) +{ + odpdrv_enumr_param_t param = { + .enumr_class = enumr_class1, + .api_name = "Enumerator_interface_3", + .api_version = 1, + .probe = enumr3_probe, + .remove = enumr3_remove, + .register_notifier = NULL + }; + + return odpdrv_enumr_register(¶m); +} + +static odpdrv_enumr_t enumr4_register(void) +{ + odpdrv_enumr_param_t param = { + .enumr_class = enumr_class2, + .api_name = "Enumerator_interface_4", + .api_version = 1, + .probe = enumr4_probe, + .remove = enumr4_remove, + .register_notifier = NULL + }; + + return odpdrv_enumr_register(¶m); +} + +static odpdrv_enumr_t enumr_invalid_register(void) +{ + odpdrv_enumr_param_t param = { + .enumr_class = NULL, + .api_name = "Enumerator_interface_invalid", + .api_version = 1, + .probe = enumr4_probe, + .remove = enumr4_remove, + .register_notifier = NULL + }; + + return odpdrv_enumr_register(¶m); +} + +/*enumerator probe functions, just making sure they have been run: */ +static int enumr1_probe(void) +{ + enumr1_probed = 1; + return 0; +} + +static int enumr2_probe(void) +{ + enumr2_probed = 1; + return 0; +} + +static int enumr3_probe(void) +{ + enumr3_probed = 1; + return 0; +} + +static int enumr4_probe(void) +{ + enumr4_probed = 1; + return 0; +} + +/*enumerator remove functions, just making sure they have been run: */ +static int enumr1_remove(void) +{ + enumr1_probed = -1; + return 0; +} + +static int enumr2_remove(void) +{ + enumr2_probed = -1; + return 0; +} + +static int enumr3_remove(void) +{ + enumr3_probed = -1; + return 0; +} + +static int enumr4_remove(void) +{ + enumr4_probed = -1; + return 0; +} + +/*enumerator class register functions, all "statically linked" + *(i.e. directely run at start), due to the fact that platorm independent + * shared lib loading in autotools is a mess */ +static void ODPDRV_CONSTRUCTOR enumr_class1_register(void) +{ + odpdrv_enumr_class_param_t param = { + .name = "Enumerator_class1", + .probe = enumr_class1_probe, + .remove = enumr_class1_remove + }; + + enumr_class1 = odpdrv_enumr_class_register(¶m); +} + +static void ODPDRV_CONSTRUCTOR enumr_class2_register(void) +{ + odpdrv_enumr_class_param_t param = { + .name = "Enumerator_class2", + .probe = enumr_class2_probe, + .remove = enumr_class2_remove + }; + + enumr_class2 = odpdrv_enumr_class_register(¶m); +} + +/*enumerator class probe functions, registering enumerators: */ +static int enumr_class1_probe(void) +{ + CU_ASSERT(enumr1_register() != ODPDRV_ENUMR_INVALID); + CU_ASSERT(enumr2_register() != ODPDRV_ENUMR_INVALID); + CU_ASSERT(enumr3_register() != ODPDRV_ENUMR_INVALID); + + CU_ASSERT(enumr_invalid_register() == ODPDRV_ENUMR_INVALID); + + return 0; +} + +static int enumr_class2_probe(void) +{ + CU_ASSERT(enumr4_register() != ODPDRV_ENUMR_INVALID); + return 0; +} + +/*enumerator class remove functions, just making sure they have been run: */ +static int enumr_class1_remove(void) +{ + return 0; +} + +static int enumr_class2_remove(void) +{ + return 0; +} + +void drvdriver_test_enumr_register(void) +{ + CU_ASSERT(enumr1_probed == 0); + CU_ASSERT(enumr2_probed == 0); + CU_ASSERT(enumr3_probed == 0); + CU_ASSERT(enumr4_probed == 0); + + CU_ASSERT(tests_global_init() == 0); + + /* at this point (after odp init), the constructor + * enumerator classes should have registered and been probed: + */ + CU_ASSERT(odpdrv_print_all() == 0); + + CU_ASSERT(enumr1_probed == 1); + CU_ASSERT(enumr2_probed == 1); + CU_ASSERT(enumr3_probed == 1); + CU_ASSERT(enumr4_probed == 1); + + CU_ASSERT(tests_global_term() == 0); + + /* after ODP termination completion, all enumerators should be removed*/ + CU_ASSERT(enumr1_probed == -1); + CU_ASSERT(enumr2_probed == -1); + CU_ASSERT(enumr3_probed == -1); + CU_ASSERT(enumr4_probed == -1); +} + +odp_testinfo_t drvdriver_suite_enumr[] = { + ODP_TEST_INFO(drvdriver_test_enumr_register), + ODP_TEST_INFO_NULL, +}; + +odp_suiteinfo_t drvdriver_suites_enumr[] = { + {"Enumerator registration", NULL, NULL, drvdriver_suite_enumr}, + ODP_SUITE_INFO_NULL, +}; + +int drvdriver_enumr_main(int argc, char *argv[]) +{ + int ret; + + /* parse common options: */ + if (odp_cunit_parse_options(argc, argv)) + return -1; + + /* prevent default ODP init: */ + odp_cunit_register_global_init(NULL); + odp_cunit_register_global_term(NULL); + + /* register the tests: */ + ret = odp_cunit_register(drvdriver_suites_enumr); + + if (ret == 0) + ret = odp_cunit_run(); + + return ret; +} diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_enumr.h b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr.h new file mode 100644 index 0000000..afe814a --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr.h @@ -0,0 +1,24 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_DRVDRIVER_ENUMR_H_ +#define _ODP_TEST_DRVDRIVER_ENUMR_H_ + +#include + +/* test functions: */ +void drvdriver_test_enumr_register(void); + +/* test arrays: */ +extern odp_testinfo_t drvdriver_suite_enumr[]; + +/* test registry: */ +extern odp_suiteinfo_t drvdriver_suites_enumr[]; + +/* main test program: */ +int drvdriver_enumr_main(int argc, char *argv[]); + +#endif diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_main.c b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_main.c new file mode 100644 index 0000000..53bc192 --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_main.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "drvdriver_enumr.h" + +int main(int argc, char *argv[]) +{ + return drvdriver_enumr_main(argc, argv); +} diff --git a/test/linux-generic/Makefile.am b/test/linux-generic/Makefile.am index 16a5cb6..a0606f3 100644 --- a/test/linux-generic/Makefile.am +++ b/test/linux-generic/Makefile.am @@ -37,6 +37,7 @@ TESTS = validation/api/pktio/pktio_run.sh \ $(ALL_API_VALIDATION_DIR)/system/system_main$(EXEEXT) \ $(ALL_DRV_VALIDATION_DIR)/drvatomic/drvatomic_main$(EXEEXT) \ $(ALL_DRV_VALIDATION_DIR)/drvdriver/drvdriver_enumr_class_main$(EXEEXT)\ + $(ALL_DRV_VALIDATION_DIR)/drvdriver/drvdriver_enumr_main$(EXEEXT)\ $(ALL_DRV_VALIDATION_DIR)/drvshmem/drvshmem_main$(EXEEXT) \ ring/ring_main$(EXEEXT) From patchwork Wed Mar 22 14:48:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95733 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp227432obz; Wed, 22 Mar 2017 06:57:51 -0700 (PDT) X-Received: by 10.55.161.13 with SMTP id k13mr40106307qke.265.1490191071772; Wed, 22 Mar 2017 06:57:51 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id b62si1130732qkb.312.2017.03.22.06.57.51; Wed, 22 Mar 2017 06:57:51 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 57671642BF; Wed, 22 Mar 2017 13:57:51 +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, URIBL_BLOCKED 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 96B7D642C3; Wed, 22 Mar 2017 13:50:17 +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 C6A4A642BD; Wed, 22 Mar 2017 13:50:09 +0000 (UTC) Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by lists.linaro.org (Postfix) with ESMTPS id 704D1642B1 for ; Wed, 22 Mar 2017 13:49:23 +0000 (UTC) Received: by mail-wm0-f43.google.com with SMTP id u132so37320494wmg.0 for ; Wed, 22 Mar 2017 06:49:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sBmR9G8Mrg460MDOAvY2r+3/Ru4VE8dPsAd3NCdso5U=; b=VzC1bSYTAWKg3GL0s2OC/+VXs+tLltEl7hjX56vScLIg+5qW6CutT86jsMHNUizhce 8rqMNMP8Fk0vdqftz54VqgPtc6su3V1jTkgiuhCjWBHBtSXtsdoDQ4Kb+iv3tOReCPYF sg+ah7DuKm9asN8DAxSA7dZvEioWS3S4QFjjFi/VR8tp7qPIHjagDA1NvWC0TusZBr8Y 2fgp1bRtpbnjl5abM2Mb4UDqUfrcRDOfTZqZFMSx7VNL/74y371/xQQ/ZzENZUCZVRRT TAwF6/NNgKf835X29Rey+QakUAwcxS2mggj5KmfYuIVgAhFgJ3Fwk6jrVhi6AASkQy6r psEw== X-Gm-Message-State: AFeK/H0ljvv3MhcMLol7PsDSe7ft1iIBHFG7BQpy2RCop2++CpnfTCIolCmollwdMHt8aBI2vtKGtNTc X-Received: by 10.25.19.90 with SMTP id j87mr11464159lfi.182.1490190562319; Wed, 22 Mar 2017 06:49:22 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:21 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:15 +0100 Message-Id: <1490194110-40168-9-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 08/23] drv: driver: change drv unbind function name and pass correct parameter 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" The driver removal function expects a device, of course... Also unbind seems a better name to disconnect from a device since remove has been used for removing the object itself for enumerators. Some extra parameters to allow for graceful unbinding are also added. Signed-off-by: Christophe Milard --- include/odp/drv/spec/driver.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/include/odp/drv/spec/driver.h b/include/odp/drv/spec/driver.h index b08d7fb..8ff856c 100644 --- a/include/odp/drv/spec/driver.h +++ b/include/odp/drv/spec/driver.h @@ -300,14 +300,29 @@ struct odpdrv_driver_param_t { */ int (*probe)(odpdrv_device_t *dev); - /** Remove function: + /** unbind function: * Only called with devices whose probe() returned true * + * dev: the device to unbind + * callback: if flag ODPDRV_DRV_UNBIND_IMMEDIATE is not specified, + * unbind should be attempted gracefully, meaning that some IO may need + * to terminate before the driver is really unbound from the device: + * In this case (when the flag is not set), the driver is due to call + * the callback function when the driver is unbound from the device. + * This callback may occurs within the unbind() call if the driver + * does unbind immediately. + * If the ODPDRV_DRV_UNBIND_IMMEDIATE is specified, the driver is due + * to release the device immediately (poosibly less gracefully). + * The callback must be called immediately in this case. */ - int (*remove)(odpdrv_device_param_t *dev); - + int (*unbind)(odpdrv_device_t dev, + void (*callback)(odpdrv_device_t dev), + uint32_t flags); }; +/** The callback function must be called mmediately by the current ODP thread */ +#define ODPDRV_DRV_UNBIND_IMMEDIATE 0x00000001 + /** * Register an enumerator class. * Each enumerator class calls this function at init time. From patchwork Wed Mar 22 14:48:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95732 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp227171obz; Wed, 22 Mar 2017 06:57:11 -0700 (PDT) X-Received: by 10.107.129.214 with SMTP id l83mr35910494ioi.168.1490191031209; Wed, 22 Mar 2017 06:57:11 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id s6si1828085ioe.173.2017.03.22.06.57.10; Wed, 22 Mar 2017 06:57:11 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id BC214642C1; Wed, 22 Mar 2017 13:57:10 +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, URIBL_BLOCKED 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 52BDE642F3; Wed, 22 Mar 2017 13:50:15 +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 5638F642F1; Wed, 22 Mar 2017 13:50:08 +0000 (UTC) Received: from mail-wm0-f51.google.com (mail-wm0-f51.google.com [74.125.82.51]) by lists.linaro.org (Postfix) with ESMTPS id 97863642BD for ; Wed, 22 Mar 2017 13:49:24 +0000 (UTC) Received: by mail-wm0-f51.google.com with SMTP id n11so37219454wma.1 for ; Wed, 22 Mar 2017 06:49:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=I+IMdGl70yBYUDW+9xwHlnf0i82Bc2p+qxUJKy3cZGw=; b=LMRC/2I3MQvJOKfmYFrL9S0oraKl6+RgVbjdlmykMgBfFRvotIOd7CtuKFyk1KnA09 wxd+yz1O95375lY61OYPYsGIBtlj4bVRPQBY7ap8bL/JnhccFL5hLEI62X/QlIx89aHF m1+x25o8fn8ap/k3TP6xiRGcXOFIbsECw9/8CLrvO6HAfG6QXp2S/3+5FtA4kPiWiwRP Acyccl9D9MfnKNdzcT/o6FmMCtvkgxesOjIt0IOvf9kJmWxn614PiHdT0YTBBqvUkX5o ND0DGYuYxJwAZxx6jhdEkGORaiBLx3mFpoiRhm3Zt+g2B1pUsp8kezzEOBJEyHZQMMrm 8tHg== X-Gm-Message-State: AFeK/H3Zqrbt0M0nFPrW02m3guBbX7UPM59cKGMI+Duxe9SpRuHwtHxwRdxTLTdTHi4UDSqmEFBO1n/V X-Received: by 10.25.167.203 with SMTP id q194mr11285512lfe.138.1490190563381; Wed, 22 Mar 2017 06:49:23 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:22 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:16 +0100 Message-Id: <1490194110-40168-10-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 09/23] drv: driver: add callback function for device destruction 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" When a device is destroyed by an enumerator, odpdrv_device_destroy() is called. However, the complete device destruction may require waiting for IO to be completed: the device destruction is therefore divided in 2 steps: odpdrv_device_destroy() starts the device destruction, and the provided callback function is called when the device can be fully removed, i.e. when it no longer has any driver bound to it. An extra flag is also added to select the destruction type: The default is a graceful destruction, letting the time for any attached driver to terminate. This may imply that the callback function is called from another ODP thread, later on. ODPDRV_DEV_DESTROY_IMMEDIATE forces an immediate device destruction, possibly terminating things abrubtly, but it guarantees that the callback is performed by the same ODP thread. This is to be used at ODP terminaison time. Signed-off-by: Christophe Milard --- include/odp/drv/spec/driver.h | 31 +++++++++++++++++++++++++++---- platform/linux-generic/drv_driver.c | 9 ++++++++- 2 files changed, 35 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/include/odp/drv/spec/driver.h b/include/odp/drv/spec/driver.h index 8ff856c..9643268 100644 --- a/include/odp/drv/spec/driver.h +++ b/include/odp/drv/spec/driver.h @@ -357,12 +357,35 @@ odpdrv_device_t odpdrv_device_create(odpdrv_device_param_t *param); /** * Destroy a device -* Called by each enumerator at probe time, or anytime later, for each -* destroyed created device +* Called by each enumerator after probe time, for each device to be +* destroyed. +* Destroying a device may require tearing down a driver and waiting for some IO +* to terminate: The device destruction is therefore done in 2 steps: +* Calling this function starts the device destruction: when the device has +* no driver attached any longer, ODP calls the provided callback() +* function which should free the enumerator-allocated resources for +* this device. +* If the flag ODPDRV_DEV_DESTROY_IMMEDIATE is given, the device destruction +* is immediate, i.e. the callback function is guaranteed to be called by the +* same ODP thread: This might however not let the time for the bound driver +* (if any) to terminate gracefully. This would typically be used at ODP +* terminaison. By default, the callback may be called later, when the driver +* has gracefully terminated, hence possibly from another ODP thread. * @param dev A odpdrv device handle as returned by odpdrv_device_create. -* @return 0 on success or a negative value on error. +* @param callback a pointer to a function to be called when the device is +* freed (no more driver). The parameter to the callback function is +* the pointer to the enumerator specific part of the device as provided +* at device creation time (void *enum_dev). The callback function +* should release these resources. +* @param flags 0 or ODPDRV_DEV_DESTROY_IMMEDIATE for immediate shut down +* @return 0 on success or a negative value on error. On error, the callback +* function is not called. */ -void odpdrv_device_destroy(odpdrv_device_t dev); +int odpdrv_device_destroy(odpdrv_device_t dev, + void (*callback)(void *enum_dev), uint32_t flags); + +/** The callback function must be called by the current ODP thread */ +#define ODPDRV_DEV_DESTROY_IMMEDIATE 0x00000001 /** * Register an devio. diff --git a/platform/linux-generic/drv_driver.c b/platform/linux-generic/drv_driver.c index 35473bd..4ade3c3 100644 --- a/platform/linux-generic/drv_driver.c +++ b/platform/linux-generic/drv_driver.c @@ -232,10 +232,17 @@ odpdrv_device_t odpdrv_device_create(odpdrv_device_param_t *param) return ODPDRV_DEVICE_INVALID; } -void odpdrv_device_destroy(odpdrv_device_t dev) +int odpdrv_device_destroy(odpdrv_device_t dev, + void (*callback)(void *enum_dev), uint32_t flags) { if (dev == ODPDRV_DEVICE_INVALID) ODP_ERR("Invalid device\n"); + if (callback != NULL) + ODP_ERR("Callback not supported yet\n"); + if (flags != 0) + ODP_ERR("flags not supported yet\n"); + + return 0; } odpdrv_devio_t odpdrv_devio_register(odpdrv_devio_param_t *param) From patchwork Wed Mar 22 14:48:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95735 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp227919obz; Wed, 22 Mar 2017 06:59:15 -0700 (PDT) X-Received: by 10.36.71.209 with SMTP id t200mr7616498itb.109.1490191155863; Wed, 22 Mar 2017 06:59:15 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id e196si17585143itc.28.2017.03.22.06.59.15; Wed, 22 Mar 2017 06:59:15 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 6763B642C6; Wed, 22 Mar 2017 13:59:15 +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, URIBL_BLOCKED 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 7B4456067B; Wed, 22 Mar 2017 13:50:47 +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 8C06A60D50; Wed, 22 Mar 2017 13:50:38 +0000 (UTC) Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by lists.linaro.org (Postfix) with ESMTPS id C9BF4642C4 for ; Wed, 22 Mar 2017 13:49:25 +0000 (UTC) Received: by mail-wm0-f43.google.com with SMTP id v203so8915131wmg.0 for ; Wed, 22 Mar 2017 06:49:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8fWtI8Tl1arAm18oNmkunUfFdWtD9NEQ+HpJNyZVwfc=; b=aSPobxzJpqHiHNA/iCfToT70yWf1wXcLchyIxOigQa18JMtJlhzIeNWfLQA7Tej4tX AnouaSrhGpZpT9hPh/NqjvyriE+kLxa5K/avCFD9LT3oNHcV82VR1e69AtOzrhivWx+u Qq6VoqoPjMBaFnJRH9sReXEGLW6I4uQU/PGPXDaD5QQeihkGdIUVM77nr4JD5r/zN+VP Mcu6rmweGJB/OWADYxd6dS4J4iZCDPQZ0Eknrxfr2h+0M4Vf3ApPqwyz1jLYfZHmL/2F DzP0nc2a39dzPhQsdI/0O21SaDJhfX7LyOtIMo1LVIWGkA79JGydMLyGUCtgUvrGB11i kz9A== X-Gm-Message-State: AFeK/H0NwC55see6cA78q0UxGmp9dnhvfUqu4xXPsHZgLcNtGIGplZFlWB6+V4iAgSdRyJ5ojL4hjNpN X-Received: by 10.25.170.1 with SMTP id t1mr11957126lfe.105.1490190564528; Wed, 22 Mar 2017 06:49:24 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:23 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:17 +0100 Message-Id: <1490194110-40168-11-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 10/23] linux-gen: drv: device creation and deletion 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" Functions to create and remove devices are populated to do more proper things. Signed-off-by: Christophe Milard --- platform/linux-generic/drv_driver.c | 181 ++++++++++++++++++++++++++++++++++-- 1 file changed, 173 insertions(+), 8 deletions(-) -- 2.7.4 diff --git a/platform/linux-generic/drv_driver.c b/platform/linux-generic/drv_driver.c index 4ade3c3..60edde1 100644 --- a/platform/linux-generic/drv_driver.c +++ b/platform/linux-generic/drv_driver.c @@ -19,12 +19,15 @@ static enum {UNDONE, IN_PROGRESS, DONE} init_global_status; +static void device_destroy_terminate(odpdrv_device_t device); + /* pool from which different list elements are alocated: */ #define ELT_POOL_SIZE (1 << 20) /* 1Mb */ static _odp_ishm_pool_t *list_elt_pool; typedef struct _odpdrv_enumr_class_s _odpdrv_enumr_class_t; typedef struct _odpdrv_enumr_s _odpdrv_enumr_t; +typedef struct _odpdrv_device_s _odpdrv_device_t; /* an enumerator class (list element) */ struct _odpdrv_enumr_class_s { @@ -55,6 +58,20 @@ typedef struct _odpdrv_enumr_lst_t { } _odpdrv_enumr_lst_t; static struct _odpdrv_enumr_lst_t enumr_lst; +/* a device (list element) */ +struct _odpdrv_device_s { + odpdrv_device_param_t param; + void (*enumr_destroy_callback)(void *enum_dev);/*dev destroy callback */ + struct _odpdrv_device_s *next; +} _odpdrv_device_s; + +/* the device list (all devices, from all enumerators): */ +typedef struct _odpdrv_device_lst_t { + odp_rwlock_recursive_t lock; + _odpdrv_device_t *head; +} _odpdrv_device_lst_t; +static struct _odpdrv_device_lst_t device_lst; + /* some driver elements (such as enumeraor classes, drivers, devio) may * register before init_global and init_local complete. Mutex will fail * in this cases but should be used later on. @@ -108,12 +125,46 @@ static void enumr_list_write_unlock(void) odp_rwlock_recursive_write_unlock(&enumr_lst.lock); } +static void dev_list_read_lock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_read_lock(&device_lst.lock); +} + +static void dev_list_read_unlock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_read_unlock(&device_lst.lock); +} + +static void dev_list_write_lock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_write_lock(&device_lst.lock); +} + +static void dev_list_write_unlock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_write_unlock(&device_lst.lock); +} + /* some functions to get internal pointers from handles... */ static inline _odpdrv_enumr_class_t *get_enumr_class(odpdrv_enumr_class_t class) { return (_odpdrv_enumr_class_t *)(void *)class; } +static inline _odpdrv_enumr_t *get_enumr(odpdrv_enumr_t enumr) +{ + return (_odpdrv_enumr_t *)(void *)enumr; +} + +static inline _odpdrv_device_t *get_device(odpdrv_device_t dev) +{ + return (_odpdrv_device_t *)(void *)dev; +} + odpdrv_enumr_class_t odpdrv_enumr_class_register(odpdrv_enumr_class_param_t *param) { @@ -227,24 +278,119 @@ odpdrv_enumr_t odpdrv_enumr_register(odpdrv_enumr_param_t *param) odpdrv_device_t odpdrv_device_create(odpdrv_device_param_t *param) { - ODP_ERR("odpdrv_device_create not Supported yet! devaddress: %s\n.", - param->address); - return ODPDRV_DEVICE_INVALID; + _odpdrv_device_t *dev; + + /* If init_global has not been done yet, we have a big issue. */ + if (init_global_status == UNDONE) + return ODPDRV_DEVICE_INVALID; + + /* make sure that the provided device address does not already exist: */ + dev_list_read_lock(); + dev = device_lst.head; + while (dev) { + if (strcmp(param->address, dev->param.address) == 0) { + ODP_ERR("device already exists!\n"); + dev_list_read_unlock(); + return ODPDRV_DEVICE_INVALID; + } + dev = dev->next; + } + dev_list_read_unlock(); + + dev = _odp_ishm_pool_alloc(list_elt_pool, + sizeof(_odpdrv_device_t)); + if (!dev) { + ODP_ERR("_odp_ishm_pool_alloc failed!\n"); + return ODPDRV_DEVICE_INVALID; + } + + /* save and set dev init parameters and insert new device in list */ + dev->param = *param; + dev->enumr_destroy_callback = NULL; + dev_list_write_lock(); + dev->next = device_lst.head; + device_lst.head = dev; + dev_list_write_unlock(); + + /* todo: probe for drivers */ + + return (odpdrv_device_t)dev; } int odpdrv_device_destroy(odpdrv_device_t dev, void (*callback)(void *enum_dev), uint32_t flags) { - if (dev == ODPDRV_DEVICE_INVALID) + _odpdrv_device_t *device = get_device(dev); + _odpdrv_device_t *_dev; + _odpdrv_device_t *target = NULL; + + if (dev == ODPDRV_DEVICE_INVALID) { ODP_ERR("Invalid device\n"); - if (callback != NULL) - ODP_ERR("Callback not supported yet\n"); - if (flags != 0) - ODP_ERR("flags not supported yet\n"); + return -1; + } + + if (flags & ODPDRV_DEV_DESTROY_IMMEDIATE) + ODP_ERR("ODPDRV_DEV_DESTROY_IMMEDIATE not supported yet\n"); + + /* remove the device from the device list (but keep the device): */ + dev_list_write_lock(); + if (device == device_lst.head) { + target = device; + device_lst.head = device_lst.head->next; + } else { + _dev = device_lst.head; + while (_dev) { + if (_dev->next == device) { + target = device; + _dev->next = _dev->next->next; + break; + } + _dev = _dev->next; + } + } + dev_list_write_unlock(); + + if (!target) { + ODP_ERR("Unknown device (cannot be removed)!\n"); + return -1; + } + + /* save the enumerator callback function which should be called + * when the driver is unbound (for gracious removal): + */ + target->enumr_destroy_callback = callback; + + /* TODO: if a driver is bound to the device, unbind it! + * passing the flag andf device_destroy_terminate() as a callback */ + + /* no driver is handling this device, or no callback was + * provided: continue removing the device: */ + device_destroy_terminate(dev); return 0; } +/* This function is called as a callback from the driver, when unbindind + * a device, or directely from odpdrv_device_destroy() if no driver + * was bound to the device. + * just call the enumerator callback to cleanup the enumerator part + * and free device memory */ +static void device_destroy_terminate(odpdrv_device_t drv_device) +{ + _odpdrv_device_t *device = get_device(drv_device); + void (*callback)(void *enum_dev); + + /* get the enumerator callback function */ + callback = device->enumr_destroy_callback; + + /* let the enumerator cleanup his part: */ + if (callback != NULL) + callback(device->param.enum_dev); + + /* free device memory: */ + _odp_ishm_pool_free(list_elt_pool, device); +} + odpdrv_devio_t odpdrv_devio_register(odpdrv_devio_param_t *param) { ODP_ERR("NOT Supported yet! Driver %s Registration!\n.", @@ -300,6 +446,7 @@ int odpdrv_print_all(void) { _odpdrv_enumr_class_t *enumr_c; _odpdrv_enumr_t *enumr; + _odpdrv_device_t *dev; /* we cannot use ODP_DBG before ODP init... */ if (init_global_status == UNDONE) @@ -331,6 +478,23 @@ int odpdrv_print_all(void) } enumr_list_read_unlock(); + /* print the list of registered devices: */ + dev_list_read_lock(); + dev = device_lst.head; + ODP_DBG("The following devices have been registered:\n"); + while (dev) { + enumr = get_enumr(dev->param.enumerator); + enumr_c = get_enumr_class(enumr->param.enumr_class); + ODP_DBG(" device: address: %s, from enumerator class: %s " + " API: %s, Version: %d\n", + dev->param.address, + enumr_c->param.name, + enumr->param.api_name, + enumr->param.api_version); + dev = dev->next; + } + dev_list_read_unlock(); + return 0; } @@ -347,6 +511,7 @@ int _odpdrv_driver_init_global(void) /* from now, we want to ensure mutex on the list: init lock: */ odp_rwlock_recursive_init(&enumr_class_lst.lock); odp_rwlock_recursive_init(&enumr_lst.lock); + odp_rwlock_recursive_init(&device_lst.lock); /* probe things... */ _odpdrv_driver_probe_drv_items(); From patchwork Wed Mar 22 14:48:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95734 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp227673obz; Wed, 22 Mar 2017 06:58:36 -0700 (PDT) X-Received: by 10.36.92.84 with SMTP id q81mr8407351itb.46.1490191116882; Wed, 22 Mar 2017 06:58:36 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id f72si1841530iod.55.2017.03.22.06.58.36; Wed, 22 Mar 2017 06:58:36 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 4534C642C6; Wed, 22 Mar 2017 13:58:36 +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, URIBL_BLOCKED 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 36DB8642C4; Wed, 22 Mar 2017 13:50:44 +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 C87A3609C2; Wed, 22 Mar 2017 13:50:37 +0000 (UTC) Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) by lists.linaro.org (Postfix) with ESMTPS id A65DE642BE for ; Wed, 22 Mar 2017 13:49:26 +0000 (UTC) Received: by mail-wm0-f46.google.com with SMTP id t189so38380439wmt.1 for ; Wed, 22 Mar 2017 06:49:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IL9D3/o2XEsxccXyL0kyF5/AMxxG5nWAuB3SU3pOTNI=; b=Ayeo8knPVeBZ5cQcdXOLOiDl/ZR7+/grZqw2lQ8sX69Y2vWlRRFUIwTsCANTu+d1tx lr52qmhFyRKAwS707QuL3ALxlAsiGGT/Dl8xQlNevryZuwfDxtGau3r3xoo265h/WoKU R+duDXTkpAxlbes1N1JSqR++oe8ljOeMDdoQHvJPyr9L6KkDnVsS31zUZuq+BqRo8NKl elhdXRjgsS2mUAu0j8uR1XWIHb9ADkhGI6PZ+dURlHRRFL50/aPHCOYecVfLdIVRwsAu kE84x6DsZxvgaiAGmyG58uyj1Q+oxrKd3Ef0qWmZORC6vAJjZKx0wMVYB/8EzTreHFWR 6GHQ== X-Gm-Message-State: AFeK/H2HDx+p89XjlFnG8R805LEtDlRP2LuyDZKSOlisfSlx7Bo7Gf7mdZLvhNGruQOLfIfecVQ= X-Received: by 10.25.79.69 with SMTP id a5mr11342947lfk.58.1490190565602; Wed, 22 Mar 2017 06:49:25 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:25 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:18 +0100 Message-Id: <1490194110-40168-12-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 11/23] drv: driver: adding device query 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" Adding a function for querying a list of devices: this function may be used by enumerators to query for the list of their registered devices or for a subset of them. Note that this function returns a malloc'd list of devices which is to be freed by the caller. Signed-off-by: Christophe Milard --- include/odp/drv/spec/driver.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) -- 2.7.4 diff --git a/include/odp/drv/spec/driver.h b/include/odp/drv/spec/driver.h index 9643268..e861396 100644 --- a/include/odp/drv/spec/driver.h +++ b/include/odp/drv/spec/driver.h @@ -387,6 +387,18 @@ int odpdrv_device_destroy(odpdrv_device_t dev, /** The callback function must be called by the current ODP thread */ #define ODPDRV_DEV_DESTROY_IMMEDIATE 0x00000001 +/** query for a list of devices + * Enumerators are responsable for device creation and destruction. + * Upon request, ODP can build a list of devices belonging to a given enumerator + * and possibly having a specific address. + * This function builds this list. + * @param enumr The enumerator which created the device + * @param address The device address (or NULL if don't care) + * @return A malloc'd ODPDRV_DEVICE_INVALID terminated array of odpdrv_device_t + * This array MUST BE FREED by the caller! + */ +odpdrv_device_t *odpdrv_device_query(odpdrv_enumr_t enumr, const char *address); + /** * Register an devio. * Each devio calls this function at init time. From patchwork Wed Mar 22 14:48:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95736 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp228224obz; Wed, 22 Mar 2017 07:00:05 -0700 (PDT) X-Received: by 10.107.203.7 with SMTP id b7mr37383222iog.115.1490191205697; Wed, 22 Mar 2017 07:00:05 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id w12si1841484ioe.193.2017.03.22.07.00.05; Wed, 22 Mar 2017 07:00:05 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 40739642BB; Wed, 22 Mar 2017 14:00:02 +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, URIBL_BLOCKED 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 D3020607E6; Wed, 22 Mar 2017 13:50:49 +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 EB39F642C4; Wed, 22 Mar 2017 13:50:43 +0000 (UTC) Received: from mail-wm0-f45.google.com (mail-wm0-f45.google.com [74.125.82.45]) by lists.linaro.org (Postfix) with ESMTPS id B4467642C7 for ; Wed, 22 Mar 2017 13:49:27 +0000 (UTC) Received: by mail-wm0-f45.google.com with SMTP id n11so38303182wma.0 for ; Wed, 22 Mar 2017 06:49:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SaZjy+s4d9kSlftWAdHJEcQOK/+e1Q18nL0qSxs/MJc=; b=KHPGg7Qslh2Oi31SHzbGcu2N8xfRXBo2sVjz5Niy22cnuWYKl5MGMTRppTy7RnuiXR wj8VkxeLXCrw7G9EK5Vy8Q1utCUo09nq9TZPShWQYC9SH9A5EfIUD6ViqXm/K8+Vi3So a/J1n+EfXujBZbNnnwfL/gDb6LXxjMiixlwH/2G4sqBJqi4hUlH4yo2QaZNWSfKUfkAA Le7dTOOnzxLfGMnJt474fSeVnA72WqAGOGH3pBtayrLG8YqYLPdl4HEQScdPBCWPd7qp OQkR10MwO+tPrCkW1yIzeYAxd8l0MUhmhV+nnOTKNAo5GtZQ3Cvvr3sviSLOaUvrCQ0z x9gA== X-Gm-Message-State: AFeK/H2wQkRpTWMQUc2FBX8A1lmp7Io2/tUbAbpoKcd5J5mqsInBVxOvVuB/+B6qL8v/JW0JDns= X-Received: by 10.25.193.194 with SMTP id r185mr11099309lff.158.1490190566585; Wed, 22 Mar 2017 06:49:26 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:26 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:19 +0100 Message-Id: <1490194110-40168-13-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 12/23] linux-gen: drv: driver: adding device querry 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 device query function for the linux-gen ODP. Signed-off-by: Christophe Milard --- platform/linux-generic/drv_driver.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) -- 2.7.4 diff --git a/platform/linux-generic/drv_driver.c b/platform/linux-generic/drv_driver.c index 60edde1..3e4780b 100644 --- a/platform/linux-generic/drv_driver.c +++ b/platform/linux-generic/drv_driver.c @@ -391,6 +391,43 @@ static void device_destroy_terminate(odpdrv_device_t drv_device) _odp_ishm_pool_free(list_elt_pool, device); } +odpdrv_device_t *odpdrv_device_query(odpdrv_enumr_t enumr, const char *address) +{ + _odpdrv_device_t *dev; + odpdrv_device_t *res; + int index = 0; + + int size = sizeof(odpdrv_device_t); /* for the ODPDRV_DEVICE_INVALID */ + + /* parse the list of device a first time to determine the size of + * the memory to be allocated: + */ + dev_list_read_lock(); + dev = device_lst.head; + while (dev) { + if ((dev->param.enumerator == enumr) && + ((address == NULL) || + (strcmp(dev->param.address, address) == 0))) + size += sizeof(odpdrv_device_t); + dev = dev->next; + } + + /* then fill the list: */ + res = (odpdrv_device_t *)malloc(size); + dev = device_lst.head; + while (dev) { + if ((dev->param.enumerator == enumr) && + ((address == NULL) || + (strcmp(dev->param.address, address) == 0))) + res[index++] = (odpdrv_device_t)dev; + dev = dev->next; + } + dev_list_read_unlock(); + res[index++] = ODPDRV_DEVICE_INVALID; + + return res; /* must be freed by caller! */ +} + odpdrv_devio_t odpdrv_devio_register(odpdrv_devio_param_t *param) { ODP_ERR("NOT Supported yet! Driver %s Registration!\n.", From patchwork Wed Mar 22 14:48:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95737 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp228756obz; Wed, 22 Mar 2017 07:01:16 -0700 (PDT) X-Received: by 10.55.60.137 with SMTP id j131mr32087813qka.19.1490191276757; Wed, 22 Mar 2017 07:01:16 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id u63si487526qkf.173.2017.03.22.07.01.16; Wed, 22 Mar 2017 07:01:16 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 573B462D5D; Wed, 22 Mar 2017 14:01:16 +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.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED,URI_NOVOWEL 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 566C2608DE; Wed, 22 Mar 2017 13:51:01 +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 C3A8D6094C; Wed, 22 Mar 2017 13:50:55 +0000 (UTC) Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by lists.linaro.org (Postfix) with ESMTPS id E9BBB642CB for ; Wed, 22 Mar 2017 13:49:28 +0000 (UTC) Received: by mail-wm0-f52.google.com with SMTP id v203so8915479wmg.0 for ; Wed, 22 Mar 2017 06:49:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7+6db+8yd1186qqQEIT+e7bLEfk8u2CqxA2HM6rq4Aw=; b=mxBrlB1+pcP4tTGn8gTet4nX+QC49k68B2rdml+0TzVVL1EYKhVyuX3r8pmSIX0Sig i3ML8wijZ6OwX/5EI62rSoewLkeEyCdWfTv0V1FQGMlJH6DJ0Dvucsu0sENPD+02jdLn w63kP2UuVCI7rhjF1+fQwBnXrEef2fEy4W85b9O9dGGtF5/WFP7mHkDyxkNkkb1H2vL0 +yLVJ/FRbosNEwdMX803Fh2bs7LJmTPc3r9xtrhP+wbWQGQgCB6bctr3tTj38sCKZyjY U/mS3Abc+W5aYqlfh6ZLoslIxUvXrprki1QAv9pYdFT+lYKYz0RXd94olGQc/hkstRe8 RIsA== X-Gm-Message-State: AFeK/H1hPq/8AR94RT/XRNJjVRZ5ln82Sv2t+EZU0zN6NCQxGRXro+tICsKvtR2CIddfEGlPlSI= X-Received: by 10.25.99.27 with SMTP id x27mr11343363lfb.104.1490190567684; Wed, 22 Mar 2017 06:49:27 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:27 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:20 +0100 Message-Id: <1490194110-40168-14-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 13/23] test: drv: device creation and destruction 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" Testing that devices can be created and removed from ODP. Signed-off-by: Christophe Milard --- .../validation/drv/drvdriver/.gitignore | 1 + .../validation/drv/drvdriver/Makefile.am | 11 ++ .../validation/drv/drvdriver/drvdriver_device.c | 218 +++++++++++++++++++++ .../validation/drv/drvdriver/drvdriver_device.h | 24 +++ .../drv/drvdriver/drvdriver_device_main.c | 12 ++ test/linux-generic/Makefile.am | 1 + 6 files changed, 267 insertions(+) create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_device.c create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_device.h create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_device_main.c -- 2.7.4 diff --git a/test/common_plat/validation/drv/drvdriver/.gitignore b/test/common_plat/validation/drv/drvdriver/.gitignore index a842448..97b4312 100644 --- a/test/common_plat/validation/drv/drvdriver/.gitignore +++ b/test/common_plat/validation/drv/drvdriver/.gitignore @@ -1,2 +1,3 @@ drvdriver_enumr_class_main drvdriver_enumr_main +drvdriver_device_main diff --git a/test/common_plat/validation/drv/drvdriver/Makefile.am b/test/common_plat/validation/drv/drvdriver/Makefile.am index 3476c50..544586c 100644 --- a/test/common_plat/validation/drv/drvdriver/Makefile.am +++ b/test/common_plat/validation/drv/drvdriver/Makefile.am @@ -25,3 +25,14 @@ drvdriver_enumr_main_LDADD = libtestdrvdriverenumr.la \ $(LIBCUNIT_COMMON) $(LIBODP) EXTRA_DIST += drvdriver_enumr.h + +#tests for device creation: +noinst_LTLIBRARIES += libtestdrvdriverdevice.la +libtestdrvdriverdevice_la_SOURCES = drvdriver_device.c + +test_PROGRAMS += drvdriver_device_main$(EXEEXT) +dist_drvdriver_device_main_SOURCES = drvdriver_device_main.c +drvdriver_device_main_LDADD = libtestdrvdriverdevice.la \ + $(LIBCUNIT_COMMON) $(LIBODP) + +EXTRA_DIST += drvdriver_device.h diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_device.c b/test/common_plat/validation/drv/drvdriver/drvdriver_device.c new file mode 100644 index 0000000..d010026 --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_device.c @@ -0,0 +1,218 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include +#include "drvdriver_device.h" +#include + +static odp_instance_t odp_instance; +static odpdrv_enumr_class_t enumr_class1; +static odpdrv_enumr_t enumr1; + +typedef struct dev_enumr_data_t { /* enumerator data for registered devices */ + odpdrv_shm_t shm_handle; + int device_number; +} dev_enumr_data_t; + +#define NB_DEVICES 5 + +/* forward declaration */ +static int enumr1_probe(void); +static int enumr1_remove(void); +static int enumr_class1_probe(void); +static int enumr_class1_remove(void); + +/* because many things to be checked are performed during ODP initialisation, + * the initialisation functions have to be a part of the test + */ +static int tests_global_init(void) +{ + if (0 != odp_init_global(&odp_instance, NULL, NULL)) { + fprintf(stderr, "error: odp_init_global() failed.\n"); + return -1; + } + if (0 != odp_init_local(odp_instance, ODP_THREAD_CONTROL)) { + fprintf(stderr, "error: odp_init_local() failed.\n"); + return -1; + } + + return 0; +} + +static int tests_global_term(void) +{ + if (0 != odp_term_local()) { + fprintf(stderr, "error: odp_term_local() failed.\n"); + return -1; + } + + if (0 != odp_term_global(odp_instance)) { + fprintf(stderr, "error: odp_term_global() failed.\n"); + return -1; + } + + return 0; +} + +/*enumerator register functions */ +static odpdrv_enumr_t enumr1_register(void) +{ + odpdrv_enumr_param_t param = { + .enumr_class = enumr_class1, + .api_name = "Enumerator_interface_1", + .api_version = 1, + .probe = enumr1_probe, + .remove = enumr1_remove, + .register_notifier = NULL + }; + + enumr1 = odpdrv_enumr_register(¶m); + return enumr1; +} + +/*enumerator probe functions, just making sure they have been run: */ +static int enumr1_probe(void) +{ + int dev; + odpdrv_shm_t shm; + dev_enumr_data_t *dev_data; + + odpdrv_device_param_t param = { + .enumerator = enumr1, + .address = "00:00:0X", + .enum_dev = NULL + }; + + /* create 5 devices: */ + for (dev = 0; dev < NB_DEVICES; dev++) { + shm = odpdrv_shm_reserve(NULL, sizeof(dev_enumr_data_t), + 0, ODPDRV_SHM_SINGLE_VA); + CU_ASSERT(ODPDRV_SHM_INVALID != shm); + dev_data = odpdrv_shm_addr(shm); + CU_ASSERT_PTR_NOT_NULL(dev_data); + + dev_data->shm_handle = shm; + dev_data->device_number = dev; + + param.address[7] = '0' + dev; /* change X in the address */ + param.enum_dev = dev_data; + + CU_ASSERT(odpdrv_device_create(¶m) != + ODPDRV_DEVICE_INVALID); + } + + CU_ASSERT(odpdrv_print_all() == 0); + + return 0; +} + +/* enumerator device removal callback function: */ +static void enumr5_device_destroy_terminate(void *priv_data) +{ + dev_enumr_data_t *dev_data; + int dev_nb; + odpdrv_shm_t shm; + + dev_data = (dev_enumr_data_t *)priv_data; + dev_nb = dev_data->device_number; + printf("removing device number: %d\n", dev_nb); + CU_ASSERT(dev_nb < NB_DEVICES); + CU_ASSERT(dev_nb >= 0); + shm = dev_data->shm_handle; + CU_ASSERT(!odpdrv_shm_free_by_handle(shm)); +} + +/*enumerator remove functions, to remove the enumerated devices: */ +static int enumr1_remove(void) +{ + odpdrv_device_t *my_devices; + odpdrv_device_t *dev; + int count = 0; + + /* destroy all devices created by enumerator 5: */ + my_devices = odpdrv_device_query(enumr1, NULL); + + for (dev = my_devices; *dev != ODPDRV_DEVICE_INVALID; dev++) { + odpdrv_device_destroy(*dev, enumr5_device_destroy_terminate, 0); + count++; + } + + CU_ASSERT(count == NB_DEVICES); + + free(my_devices); + return 0; +} + +/*enumerator class register functions, all "statically linked" + *(i.e. directely run at start), due to the fact that platorm independent + * shared lib loading in autotools is a mess */ +static void ODPDRV_CONSTRUCTOR enumr_class1_register(void) +{ + odpdrv_enumr_class_param_t param = { + .name = "Enumerator_class1", + .probe = enumr_class1_probe, + .remove = enumr_class1_remove + }; + + enumr_class1 = odpdrv_enumr_class_register(¶m); +} + +/*enumerator class probe functions, registering enumerators: */ +static int enumr_class1_probe(void) +{ + CU_ASSERT(enumr1_register() != ODPDRV_ENUMR_INVALID); + return 0; +} + +/*enumerator class remove functions, just making sure they have been run: */ +static int enumr_class1_remove(void) +{ + return 0; +} + +void drvdriver_test_device_register(void) +{ + CU_ASSERT(tests_global_init() == 0); + + /* at this point (after odp init), the 5 devices should be there: + */ + CU_ASSERT(odpdrv_print_all() == 0); + + CU_ASSERT(tests_global_term() == 0); +} + +odp_testinfo_t drvdriver_suite_device[] = { + ODP_TEST_INFO(drvdriver_test_device_register), + ODP_TEST_INFO_NULL, +}; + +odp_suiteinfo_t drvdriver_suites_device[] = { + {"Enumerator registration", NULL, NULL, drvdriver_suite_device}, + ODP_SUITE_INFO_NULL, +}; + +int drvdriver_device_main(int argc, char *argv[]) +{ + int ret; + + /* parse common options: */ + if (odp_cunit_parse_options(argc, argv)) + return -1; + + /* prevent default ODP init: */ + odp_cunit_register_global_init(NULL); + odp_cunit_register_global_term(NULL); + + /* register the tests: */ + ret = odp_cunit_register(drvdriver_suites_device); + + if (ret == 0) + ret = odp_cunit_run(); + + return ret; +} diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_device.h b/test/common_plat/validation/drv/drvdriver/drvdriver_device.h new file mode 100644 index 0000000..afc04c5 --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_device.h @@ -0,0 +1,24 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_DRVDRIVER_DEVICE_H_ +#define _ODP_TEST_DRVDRIVER_DEVICE_H_ + +#include + +/* test functions: */ +void drvdriver_test_device_register(void); + +/* test arrays: */ +extern odp_testinfo_t drvdriver_suite_device[]; + +/* test registry: */ +extern odp_suiteinfo_t drvdriver_suites_device[]; + +/* main test program: */ +int drvdriver_device_main(int argc, char *argv[]); + +#endif diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_device_main.c b/test/common_plat/validation/drv/drvdriver/drvdriver_device_main.c new file mode 100644 index 0000000..27de9c5 --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_device_main.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "drvdriver_device.h" + +int main(int argc, char *argv[]) +{ + return drvdriver_device_main(argc, argv); +} diff --git a/test/linux-generic/Makefile.am b/test/linux-generic/Makefile.am index a0606f3..c95449a 100644 --- a/test/linux-generic/Makefile.am +++ b/test/linux-generic/Makefile.am @@ -36,6 +36,7 @@ TESTS = validation/api/pktio/pktio_run.sh \ $(ALL_API_VALIDATION_DIR)/shmem/shmem_main$(EXEEXT) \ $(ALL_API_VALIDATION_DIR)/system/system_main$(EXEEXT) \ $(ALL_DRV_VALIDATION_DIR)/drvatomic/drvatomic_main$(EXEEXT) \ + $(ALL_DRV_VALIDATION_DIR)/drvdriver/drvdriver_device_main$(EXEEXT)\ $(ALL_DRV_VALIDATION_DIR)/drvdriver/drvdriver_enumr_class_main$(EXEEXT)\ $(ALL_DRV_VALIDATION_DIR)/drvdriver/drvdriver_enumr_main$(EXEEXT)\ $(ALL_DRV_VALIDATION_DIR)/drvshmem/drvshmem_main$(EXEEXT) \ From patchwork Wed Mar 22 14:48:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95739 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp229194obz; Wed, 22 Mar 2017 07:02:09 -0700 (PDT) X-Received: by 10.107.8.91 with SMTP id 88mr35420787ioi.142.1490191329787; Wed, 22 Mar 2017 07:02:09 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 134si1847763ion.113.2017.03.22.07.02.09; Wed, 22 Mar 2017 07:02:09 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 544CF642B0; Wed, 22 Mar 2017 14:02:09 +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, URIBL_BLOCKED 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 A191B64300; Wed, 22 Mar 2017 13:51:03 +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 89DCA608DE; Wed, 22 Mar 2017 13:50:59 +0000 (UTC) Received: from mail-wm0-f45.google.com (mail-wm0-f45.google.com [74.125.82.45]) by lists.linaro.org (Postfix) with ESMTPS id F03D3642B0 for ; Wed, 22 Mar 2017 13:49:29 +0000 (UTC) Received: by mail-wm0-f45.google.com with SMTP id t189so38381840wmt.1 for ; Wed, 22 Mar 2017 06:49:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uacfQHC0g30ruIowJ8+3nHgR3noJHEBRo2mG9HEfarY=; b=Ikx7l5WGTY55jbrliynrJIkGRDPzKWW1uE7i5bLWzOAWmufv1GSDMrB1rFFSJRH/Ui hpDZCLYw0L9GINE2LWbbzCYVYGaM85cW70P0BTVvdhrpjTDfMOPCt7EbUzR5NAHtkKdq pCjbsRaGuCO9yAx7UotzrhMCtrM1HuU9Tg5w73G+MZQ0gl5SYJO9pm9APnSAtquZ1CP1 MxYNJvM9YTj0vov6oFnZSGV9MnKVFc9VzImys36J9QyZBmtxkuc98IFPHW29e3wehPG5 pIyeqt5Pom7EdzqyD6Sc1vNXcQKSaPBtFn5Tig5ftMfHFhneiB4NGl0MxXf96X7VMnAE UE+Q== X-Gm-Message-State: AFeK/H2OHvkUgq5t/YbOcJrZqyQkINKxv6VoEQ6dQ2SY+iF3OLe4RUWflmwaxU+2AdwlHT+0rOI= X-Received: by 10.25.56.91 with SMTP id d27mr11380951lfj.30.1490190568919; Wed, 22 Mar 2017 06:49:28 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:28 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:21 +0100 Message-Id: <1490194110-40168-15-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 14/23] drv: driver: adding a probe and remove callback for devio 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" Needed to delete the resources needed for the devio. That is possibly the memory allocated for its "ops" part if it was allocated. May be NULL if nothing needs to be done at devio deletion time. Signed-off-by: Christophe Milard --- include/odp/drv/spec/driver.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) -- 2.7.4 diff --git a/include/odp/drv/spec/driver.h b/include/odp/drv/spec/driver.h index e861396..f89c282 100644 --- a/include/odp/drv/spec/driver.h +++ b/include/odp/drv/spec/driver.h @@ -269,6 +269,24 @@ struct odpdrv_devio_param_t { char enumr_api_name[ODPDRV_NAME_SIZE]; uint32_t enumr_api_version; /**<< required enumerator API version */ + /** Probe function: + * Tell whether this devio can handle the given device. + * The devio is hence given a chance to reject a given device for + * any reason. No binding occurs here. binding occurs when the + * driver is probed. + * returns 0 if this devio can handle the given device, or a negative + * value if not. + * If left to NULL, a 0 returned value is assumed + */ + int (*probe)(odpdrv_device_t dev); + + /** Remove function: + * Should destroy the memory allocated for ops and anything else + * under it, or any resource for this devio. + * Returns 0 on success or a negative value on error. + */ + int (*remove)(void); + /** Ops * Pointer to a devio ops structure (specific to each devio) */ From patchwork Wed Mar 22 14:48:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95740 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp229920obz; Wed, 22 Mar 2017 07:03:43 -0700 (PDT) X-Received: by 10.55.5.146 with SMTP id 140mr39107914qkf.202.1490191423013; Wed, 22 Mar 2017 07:03:43 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id q68si1141257qka.332.2017.03.22.07.03.42; Wed, 22 Mar 2017 07:03:43 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 8F563642B5; Wed, 22 Mar 2017 14:03:42 +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, URIBL_BLOCKED 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 3CCFD6430D; Wed, 22 Mar 2017 13:51:14 +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 3B3156430E; Wed, 22 Mar 2017 13:51:09 +0000 (UTC) Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by lists.linaro.org (Postfix) with ESMTPS id 14E5C642CE for ; Wed, 22 Mar 2017 13:49:31 +0000 (UTC) Received: by mail-wm0-f43.google.com with SMTP id u132so37324083wmg.0 for ; Wed, 22 Mar 2017 06:49:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=l/Tld7kbDU4jHu5GjzVTPpdgwDPcFpRJcqElT4ipGBg=; b=bivu4oAnoJpZiEf0cZlhnQPDPWeXILu7J2dynExPHbN5474t9tbMnASLXz5eGBMf3d RiUIwKtDCEKo+4EiSuy007LPaondQWYEHZEEvoNWl2kHf02SXDdbgJviA83SHbc2WI3r dazCXWZpNhhMuW9n0lIoPVmUQF6g+sxfRUu8SjaMsb6oYtZo21t5szlFz8eTLD17lFVv YtsCnH9T8DNo4VgSVT8dcYABma0Jk7vpUZz70zrU8TtaIVIGph/x473oDvVyuCTIw2in YkOMCCVm08zd79fLmU/Fsv+vfJVrcK8YGL6XarqTteq7qe8EF3NYIoj6kEG2VXQS1gc/ Vyvg== X-Gm-Message-State: AFeK/H01kiNZTDl9kKpaI4Wliru1jXgexOdOBh6b2jYwbWRnorKKLyXSogFJrjbRWOBuXUIs5yc= X-Received: by 10.25.198.19 with SMTP id w19mr11719203lff.175.1490190569961; Wed, 22 Mar 2017 06:49:29 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:29 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:22 +0100 Message-Id: <1490194110-40168-16-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 15/23] linux-gen: drv: devio registration 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" devios (dev IO) provide a interface for drivers to access a device: Devices enumerated by enumerators may be accessed in by different mechanisms (depending on iommu presence or other factors). This extra abstraction is provided by devios, which provide a sets of methods to access the devices of a given type (i.e. registred enumerator(s) enumerating devices of the same kind (e.g. PCI)). This patch just implements the devio registration method provided by the driver API. Signed-off-by: Christophe Milard --- platform/linux-generic/drv_driver.c | 134 +++++++++++++++++++++++++++++++++++- 1 file changed, 131 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/platform/linux-generic/drv_driver.c b/platform/linux-generic/drv_driver.c index 3e4780b..873ec3c 100644 --- a/platform/linux-generic/drv_driver.c +++ b/platform/linux-generic/drv_driver.c @@ -28,6 +28,7 @@ static _odp_ishm_pool_t *list_elt_pool; typedef struct _odpdrv_enumr_class_s _odpdrv_enumr_class_t; typedef struct _odpdrv_enumr_s _odpdrv_enumr_t; typedef struct _odpdrv_device_s _odpdrv_device_t; +typedef struct _odpdrv_devio_s _odpdrv_devio_t; /* an enumerator class (list element) */ struct _odpdrv_enumr_class_s { @@ -72,6 +73,20 @@ typedef struct _odpdrv_device_lst_t { } _odpdrv_device_lst_t; static struct _odpdrv_device_lst_t device_lst; +/* a devio (list element) */ +struct _odpdrv_devio_s { + odpdrv_devio_param_t param; + _odp_ishm_pool_t *pool; + struct _odpdrv_devio_s *next; +} _odpdrv_devio_s; + +/* the devio list: */ +typedef struct _odpdrv_devio_lst_t { + odp_rwlock_recursive_t lock; + _odpdrv_devio_t *head; +} _odpdrv_devio_lst_t; +static struct _odpdrv_devio_lst_t devio_lst; + /* some driver elements (such as enumeraor classes, drivers, devio) may * register before init_global and init_local complete. Mutex will fail * in this cases but should be used later on. @@ -149,6 +164,30 @@ static void dev_list_write_unlock(void) odp_rwlock_recursive_write_unlock(&device_lst.lock); } +static void devio_list_read_lock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_read_lock(&devio_lst.lock); +} + +static void devio_list_read_unlock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_read_unlock(&devio_lst.lock); +} + +static void devio_list_write_lock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_write_lock(&devio_lst.lock); +} + +static void devio_list_write_unlock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_write_unlock(&devio_lst.lock); +} + /* some functions to get internal pointers from handles... */ static inline _odpdrv_enumr_class_t *get_enumr_class(odpdrv_enumr_class_t class) { @@ -430,10 +469,65 @@ odpdrv_device_t *odpdrv_device_query(odpdrv_enumr_t enumr, const char *address) odpdrv_devio_t odpdrv_devio_register(odpdrv_devio_param_t *param) { - ODP_ERR("NOT Supported yet! Driver %s Registration!\n.", - param->api_name); + _odpdrv_devio_t *devio; + + /* parse the list of already registered devios to make + * sure no devio providing the same interface using th esame enumerator + * already exists: + */ + devio_list_read_lock(); + devio = devio_lst.head; + while (devio) { + if ((strncmp(param->api_name, devio->param.api_name, + ODPDRV_NAME_SIZE) == 0) && + (strncmp(param->enumr_api_name, devio->param.enumr_api_name, + ODPDRV_NAME_SIZE) == 0)) { + ODP_ERR("a devio providing interface '%s' for devices " + "of type '%s' is already registered\n!", + param->api_name, param->enumr_api_name); + devio_list_read_unlock(); + return ODPDRV_DEVIO_INVALID; + } + devio = devio->next; + } + devio_list_read_unlock(); - return ODPDRV_DEVIO_INVALID; + /* allocate memory for the new devio: + * If init_global has not been done yet, then, we cannot allocate + * from any _ishm pool (ishm has not even been initialised at this + * stage...this happens when statically linked devios + * register: their __constructor__ function is run before main() + * is called). But any malloc performed here(before init_global) + * will be inherited by any odpthreads (process or pthreads) as we + * are still running in the ODP instantiation processes and all + * other processes are guaranteed to be descendent of this one... + * If init_global has been done, then we allocate from the _ishm pool + * to guarantee visibility from any ODP thread. + */ + + if (init_global_status == UNDONE) { + devio = malloc(sizeof(_odpdrv_devio_t)); + if (!devio) + return ODPDRV_DEVIO_INVALID; + devio->pool = NULL; + } else { + devio = _odp_ishm_pool_alloc(list_elt_pool, + sizeof(_odpdrv_devio_t)); + if (!devio) { + ODP_ERR("_odp_ishm_pool_alloc failed!\n"); + return ODPDRV_DEVIO_INVALID; + } + devio->pool = list_elt_pool; + } + + /* save init parameters and insert devio in list */ + devio->param = *param; + devio_list_write_lock(); + devio->next = devio_lst.head; + devio_lst.head = devio; + devio_list_write_unlock(); + + return (odpdrv_devio_t)devio; } odpdrv_driver_t odpdrv_driver_register(odpdrv_driver_param_t *param) @@ -484,6 +578,7 @@ int odpdrv_print_all(void) _odpdrv_enumr_class_t *enumr_c; _odpdrv_enumr_t *enumr; _odpdrv_device_t *dev; + _odpdrv_devio_t *devio; /* we cannot use ODP_DBG before ODP init... */ if (init_global_status == UNDONE) @@ -532,6 +627,21 @@ int odpdrv_print_all(void) } dev_list_read_unlock(); + /* print the list of registered devios: */ + devio_list_read_lock(); + devio = devio_lst.head; + ODP_DBG("The following dev IOs have been registered:\n"); + while (devio) { + ODP_DBG(" devio providing interface: '%s' (version %d) for " + " devices of type '%s' (version %d)\n", + devio->param.api_name, + devio->param.api_version, + devio->param.enumr_api_name, + devio->param.enumr_api_version); + devio = devio->next; + } + devio_list_read_unlock(); + return 0; } @@ -549,6 +659,7 @@ int _odpdrv_driver_init_global(void) odp_rwlock_recursive_init(&enumr_class_lst.lock); odp_rwlock_recursive_init(&enumr_lst.lock); odp_rwlock_recursive_init(&device_lst.lock); + odp_rwlock_recursive_init(&devio_lst.lock); /* probe things... */ _odpdrv_driver_probe_drv_items(); @@ -566,12 +677,29 @@ int _odpdrv_driver_init_local(void) int _odpdrv_driver_term_global(void) { + _odpdrv_devio_t *devio; _odpdrv_enumr_class_t *enumr_c; _odpdrv_enumr_t *enumr; if (init_global_status == UNDONE) return 0; + /* remove all devios which are registered: */ + devio_list_write_lock(); + while (devio_lst.head) { + devio = devio_lst.head; /* run removal function, if any */ + if (devio->param.remove) { + if (devio->param.remove()) + ODP_ERR("devio removal indicated failure!\n"); + } + devio_lst.head = devio->next; + if (devio->pool) + _odp_ishm_pool_free(list_elt_pool, devio); + else + free(devio); + } + devio_list_write_unlock(); + /* remove all enumerators which are registered: */ enumr_list_write_lock(); while (enumr_lst.head) { From patchwork Wed Mar 22 14:48:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95744 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp230281obz; Wed, 22 Mar 2017 07:04:29 -0700 (PDT) X-Received: by 10.55.45.133 with SMTP id t127mr34871186qkh.218.1490191469104; Wed, 22 Mar 2017 07:04:29 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id k38si1145816qtk.329.2017.03.22.07.04.28; Wed, 22 Mar 2017 07:04:29 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id BD75664011; Wed, 22 Mar 2017 14:04:28 +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.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED,URI_NOVOWEL 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 8294B6430C; Wed, 22 Mar 2017 13:51:19 +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 5F6D5642CF; Wed, 22 Mar 2017 13:51:11 +0000 (UTC) Received: from mail-wm0-f41.google.com (mail-wm0-f41.google.com [74.125.82.41]) by lists.linaro.org (Postfix) with ESMTPS id 38551642CF for ; Wed, 22 Mar 2017 13:49:32 +0000 (UTC) Received: by mail-wm0-f41.google.com with SMTP id n11so37222883wma.1 for ; Wed, 22 Mar 2017 06:49:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rf8v03NHTd+8VR0GkSfVAETOEKqCy/0CbYMh5Qv37Uw=; b=kIFDkWFwNCvoNpMHZ2Pmd7Fe5e+yM3n1MKWQH+pXaoIe6+sLPOMub9ah40bgryVSgo k4yaSxXaMnp/f1eZr/pZ2UZc8qi53fgWDZheihJF8Ip+o70LWGjaf+VVq6fVTLg67gaG yqn1Hu7VtKgGWT86hRgrAk9WSzBf5yiNfAqlGgTy0u6abwkfdChc8iDVPrLp8UuTpner t4TT5K3wZ69zJZdy6zjhk19uRx1k5Bpo5tQup58lRsOeORsfXc4d/fbQwjOwEeEQVM2d AZHbDuKFbVGjgWBzGQqXD5DUsercG5DOBC2n83XE1jf7DEPEHP1j1YvYFssSoH+caRYm w3OQ== X-Gm-Message-State: AFeK/H1GUK49gpnNQk8jlAGFTDMWGmihirBwcpCnZ0qHcqDE0XEfbiIwiJUbHWX/Z3uf9b6S+KU= X-Received: by 10.25.21.74 with SMTP id l71mr11527211lfi.93.1490190570954; Wed, 22 Mar 2017 06:49:30 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:30 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:23 +0100 Message-Id: <1490194110-40168-17-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 16/23] test: drv: devio creation and destruction 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" Testing that devios can be registered and removed in/from ODP. Signed-off-by: Christophe Milard --- .../validation/drv/drvdriver/.gitignore | 1 + .../validation/drv/drvdriver/Makefile.am | 11 ++ .../validation/drv/drvdriver/drvdriver_devio.c | 209 +++++++++++++++++++++ .../validation/drv/drvdriver/drvdriver_devio.h | 24 +++ .../drv/drvdriver/drvdriver_devio_main.c | 12 ++ test/linux-generic/Makefile.am | 1 + 6 files changed, 258 insertions(+) create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_devio.c create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_devio.h create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_devio_main.c -- 2.7.4 diff --git a/test/common_plat/validation/drv/drvdriver/.gitignore b/test/common_plat/validation/drv/drvdriver/.gitignore index 97b4312..829c8b4 100644 --- a/test/common_plat/validation/drv/drvdriver/.gitignore +++ b/test/common_plat/validation/drv/drvdriver/.gitignore @@ -1,3 +1,4 @@ drvdriver_enumr_class_main drvdriver_enumr_main drvdriver_device_main +drvdriver_devio_main diff --git a/test/common_plat/validation/drv/drvdriver/Makefile.am b/test/common_plat/validation/drv/drvdriver/Makefile.am index 544586c..8e695ba 100644 --- a/test/common_plat/validation/drv/drvdriver/Makefile.am +++ b/test/common_plat/validation/drv/drvdriver/Makefile.am @@ -36,3 +36,14 @@ drvdriver_device_main_LDADD = libtestdrvdriverdevice.la \ $(LIBCUNIT_COMMON) $(LIBODP) EXTRA_DIST += drvdriver_device.h + +#tests for devio creation: +noinst_LTLIBRARIES += libtestdrvdriverdevio.la +libtestdrvdriverdevio_la_SOURCES = drvdriver_devio.c + +test_PROGRAMS += drvdriver_devio_main$(EXEEXT) +dist_drvdriver_devio_main_SOURCES = drvdriver_devio_main.c +drvdriver_devio_main_LDADD = libtestdrvdriverdevio.la \ + $(LIBCUNIT_COMMON) $(LIBODP) + +EXTRA_DIST += drvdriver_devio.h diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_devio.c b/test/common_plat/validation/drv/drvdriver/drvdriver_devio.c new file mode 100644 index 0000000..cf7c7c9 --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_devio.c @@ -0,0 +1,209 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include +#include "drvdriver_devio.h" +#include + +static odp_instance_t odp_instance; + +static int devio1_removed; +static int devio2_removed; +static int devio3_removed; +static int devio4_removed; + +static int devio1_remove(void); +static int devio2_remove(void); +static int devio3_remove(void); + +/* because many things to be checked are performed during ODP initialisation, + * the initialisation functions have to be a part of the test + */ +static int tests_global_init(void) +{ + if (0 != odp_init_global(&odp_instance, NULL, NULL)) { + fprintf(stderr, "error: odp_init_global() failed.\n"); + return -1; + } + if (0 != odp_init_local(odp_instance, ODP_THREAD_CONTROL)) { + fprintf(stderr, "error: odp_init_local() failed.\n"); + return -1; + } + + return 0; +} + +static int tests_global_term(void) +{ + if (0 != odp_term_local()) { + fprintf(stderr, "error: odp_term_local() failed.\n"); + return -1; + } + + if (0 != odp_term_global(odp_instance)) { + fprintf(stderr, "error: odp_term_global() failed.\n"); + return -1; + } + + return 0; +} + +/*devio register functions, all "statically linked" + *(i.e. directely run at start), due to the fact that platorm independent + * shared lib loading in autotools is a mess */ +static void ODPDRV_CONSTRUCTOR devio1_register(void) +{ + odpdrv_devio_param_t param = { + .api_name = "devio_api_1", + .api_version = 1, + .enumr_api_name = "Enumerator_interface_1", + .enumr_api_version = 1, + .remove = devio1_remove, + .ops = NULL, + }; + + odpdrv_devio_register(¶m); +} + +static void ODPDRV_CONSTRUCTOR devio2_register(void) +{ + odpdrv_devio_param_t param = { + .api_name = "devio_api_2", + .api_version = 1, + .enumr_api_name = "Enumerator_interface_1", + .enumr_api_version = 1, + .probe = NULL, + .remove = devio2_remove, + .ops = NULL, + }; + + odpdrv_devio_register(¶m); +} + +static odpdrv_devio_t devio2_register_retry(void) +{ + odpdrv_devio_param_t param = { + .api_name = "devio_api_2", + .api_version = 1, + .enumr_api_name = "Enumerator_interface_1", + .enumr_api_version = 1, + .probe = NULL, + .remove = NULL, + .ops = NULL, + }; + + return odpdrv_devio_register(¶m); +} + +static void ODPDRV_CONSTRUCTOR devio3_register(void) +{ + odpdrv_devio_param_t param = { + .api_name = "devio_api_2", + .api_version = 1, + .enumr_api_name = "Enumerator_interface_2", + .enumr_api_version = 1, + .probe = NULL, + .remove = devio3_remove, + .ops = NULL, + }; + + odpdrv_devio_register(¶m); +} + +static void ODPDRV_CONSTRUCTOR devio4_register(void) +{ + odpdrv_devio_param_t param = { + .api_name = "devio_api_3", + .api_version = 1, + .enumr_api_name = "Enumerator_interface_3", + .enumr_api_version = 1, + .probe = NULL, + .remove = NULL, + .ops = NULL, + }; + + odpdrv_devio_register(¶m); +} + +/*devio remove functions, just making sure they have been run: */ +static int devio1_remove(void) +{ + devio1_removed = 1; + return 0; +} + +/*devio remove functions, just making sure they have been run: */ +static int devio2_remove(void) +{ + devio2_removed = 1; + return 0; +} + +/*devio remove functions, just making sure they have been run: */ +static int devio3_remove(void) +{ + devio3_removed = 1; + return 0; +} + +void drvdriver_test_devio_register(void) +{ + CU_ASSERT(devio1_removed == 0); + CU_ASSERT(devio2_removed == 0); + CU_ASSERT(devio3_removed == 0); + CU_ASSERT(devio4_removed == 0); + + CU_ASSERT(tests_global_init() == 0); + + /* at this point (after odp init), the constructor + * devios should have registered. just print them: + */ + CU_ASSERT(odpdrv_print_all() == 0); + + /* re-register devio2: this should be kicked-out! */ + CU_ASSERT(devio2_register_retry() == ODPDRV_DEVIO_INVALID); + + CU_ASSERT(tests_global_term() == 0); + + /* after ODP termination completion, all devios have been removed*/ + CU_ASSERT(devio1_removed == 1); + CU_ASSERT(devio2_removed == 1); + CU_ASSERT(devio3_removed == 1); + CU_ASSERT(devio4_removed == 0); /* has no remove function */ +} + +odp_testinfo_t drvdriver_suite_devio[] = { + ODP_TEST_INFO(drvdriver_test_devio_register), + ODP_TEST_INFO_NULL, +}; + +odp_suiteinfo_t drvdriver_suites_devio[] = { + {"Devio registration", NULL, NULL, drvdriver_suite_devio}, + ODP_SUITE_INFO_NULL, +}; + +int drvdriver_devio_main(int argc, char *argv[]) +{ + int ret; + + /* parse common options: */ + if (odp_cunit_parse_options(argc, argv)) + return -1; + + /* prevent default ODP init: */ + odp_cunit_register_global_init(NULL); + odp_cunit_register_global_term(NULL); + + /* register the tests: */ + ret = odp_cunit_register(drvdriver_suites_devio); + + if (ret == 0) + ret = odp_cunit_run(); + + return ret; +} diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_devio.h b/test/common_plat/validation/drv/drvdriver/drvdriver_devio.h new file mode 100644 index 0000000..eea9623 --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_devio.h @@ -0,0 +1,24 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_DRVDRIVER_DEVIO_H_ +#define _ODP_TEST_DRVDRIVER_DEVIO_H_ + +#include + +/* test functions: */ +void drvdriver_test_devio_register(void); + +/* test arrays: */ +extern odp_testinfo_t drvdriver_suite_devio[]; + +/* test registry: */ +extern odp_suiteinfo_t drvdriver_suites_devio[]; + +/* main test program: */ +int drvdriver_devio_main(int argc, char *argv[]); + +#endif diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_devio_main.c b/test/common_plat/validation/drv/drvdriver/drvdriver_devio_main.c new file mode 100644 index 0000000..10733ad --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_devio_main.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "drvdriver_devio.h" + +int main(int argc, char *argv[]) +{ + return drvdriver_devio_main(argc, argv); +} diff --git a/test/linux-generic/Makefile.am b/test/linux-generic/Makefile.am index c95449a..55db05c 100644 --- a/test/linux-generic/Makefile.am +++ b/test/linux-generic/Makefile.am @@ -37,6 +37,7 @@ TESTS = validation/api/pktio/pktio_run.sh \ $(ALL_API_VALIDATION_DIR)/system/system_main$(EXEEXT) \ $(ALL_DRV_VALIDATION_DIR)/drvatomic/drvatomic_main$(EXEEXT) \ $(ALL_DRV_VALIDATION_DIR)/drvdriver/drvdriver_device_main$(EXEEXT)\ + $(ALL_DRV_VALIDATION_DIR)/drvdriver/drvdriver_devio_main$(EXEEXT)\ $(ALL_DRV_VALIDATION_DIR)/drvdriver/drvdriver_enumr_class_main$(EXEEXT)\ $(ALL_DRV_VALIDATION_DIR)/drvdriver/drvdriver_enumr_main$(EXEEXT)\ $(ALL_DRV_VALIDATION_DIR)/drvshmem/drvshmem_main$(EXEEXT) \ From patchwork Wed Mar 22 14:48:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95747 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp230942obz; Wed, 22 Mar 2017 07:05:45 -0700 (PDT) X-Received: by 10.237.53.113 with SMTP id b46mr37335501qte.119.1490191545751; Wed, 22 Mar 2017 07:05:45 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id i29si1166452qtf.101.2017.03.22.07.05.45; Wed, 22 Mar 2017 07:05:45 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id DBF0060A47; Wed, 22 Mar 2017 14:05:31 +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, URIBL_BLOCKED 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 C043D642D9; Wed, 22 Mar 2017 13:51:22 +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 2CF136430D; Wed, 22 Mar 2017 13:51:13 +0000 (UTC) Received: from mail-wm0-f53.google.com (mail-wm0-f53.google.com [74.125.82.53]) by lists.linaro.org (Postfix) with ESMTPS id 1530B642B5 for ; Wed, 22 Mar 2017 13:49:33 +0000 (UTC) Received: by mail-wm0-f53.google.com with SMTP id t189so38383024wmt.1 for ; Wed, 22 Mar 2017 06:49:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=m1G+n1kKPwCGBzdcSYe97aJTcR92hiGjd/LV1sHMe5E=; b=nsTV6uy09IvSrhHDrtC+TH+b8BFXd2ldR3ssDi5ltHv9IYRYI+V7E/YnEnu15h+aI0 0NC7bYQlXOiWvnyV7Laz4/6Z3HCA+jfsKj3ttT576s08m2+9YtE8aduXG2tCZpHnItL4 8B51oNgbKFIgEQ9oOfs/bFqSP3dh5tsccH6tTFtz/CIzVIyHwjk/+knAOBW/cijB6BLU gM3ifyr8jc1QOqOJ6nb/enGZo/GKI44w85WI7nH/Jy4YwoPlRmHZ1tMl99YN+oFZdncY cbq56PQWEPMUCoREplF9MWyvQShGpd1S7mTyvnoEH6VwjVXQD1Ufw0ytyPZlEoNHLb5a mIgA== X-Gm-Message-State: AFeK/H1WjV9RfNEIjmpmlUumm5rUpcaiy1s4eoU7DsgU+D83IlpboqO8BMjVsE98XyHaei0ETxo= X-Received: by 10.25.115.19 with SMTP id o19mr995300lfc.162.1490190571984; Wed, 22 Mar 2017 06:49:31 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:31 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:24 +0100 Message-Id: <1490194110-40168-18-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 17/23] drv: adding driver remove 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" The remove function, as for other driver items (such as enumerators...) is called before the driver is to be removed, i.e. after all devices have been been unbound from the driver. remove() should release any resource held by the driver. Signed-off-by: Christophe Milard --- include/odp/drv/spec/driver.h | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.7.4 diff --git a/include/odp/drv/spec/driver.h b/include/odp/drv/spec/driver.h index f89c282..394aa92 100644 --- a/include/odp/drv/spec/driver.h +++ b/include/odp/drv/spec/driver.h @@ -336,6 +336,14 @@ struct odpdrv_driver_param_t { int (*unbind)(odpdrv_device_t dev, void (*callback)(odpdrv_device_t dev), uint32_t flags); + + /** remove function: + * remove any resource taken by the driver. Called when the driver + * itself is to be removed, i.e. after all devices are unbound + * Can be set to NULL if the driver has nothing to release. + * + */ + int (*remove)(void); }; /** The callback function must be called mmediately by the current ODP thread */ From patchwork Wed Mar 22 14:48:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95748 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp231250obz; Wed, 22 Mar 2017 07:06:26 -0700 (PDT) X-Received: by 10.200.41.33 with SMTP id y30mr36426637qty.47.1490191585994; Wed, 22 Mar 2017 07:06:25 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 29si1174736qtn.48.2017.03.22.07.06.25; Wed, 22 Mar 2017 07:06:25 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 58387642D3; Wed, 22 Mar 2017 14:06: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=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED 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 0E8DB64317; Wed, 22 Mar 2017 13:51:27 +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 AAE3064310; Wed, 22 Mar 2017 13:51:16 +0000 (UTC) Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com [74.125.82.47]) by lists.linaro.org (Postfix) with ESMTPS id 36EDB642D9 for ; Wed, 22 Mar 2017 13:49:34 +0000 (UTC) Received: by mail-wm0-f47.google.com with SMTP id t189so38383466wmt.1 for ; Wed, 22 Mar 2017 06:49:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=S41fRErygZ0+W4h1TFLqYM5f+oEBqj2RqFYKXlArrwI=; b=qPn84MrJ6AYK+7AFlITzUdWUPpGUEBBJh3lrga3e/HIX8f1eBAJDHNas7PS2mYilwF AfA/TzWMaffwDbeARo6IEUlr2SOuTd/bP0zys49xtGRJyju0+JMSq/BVNlFA6/13o091 H89UcKciEVE+2rozk+OhpWjHKCdc7GgTEmF5G+MuZ5/ksvBCx36nWpFEQKhQfmv1B1R4 9CcYtWLA70W+kH73OaYFzJ9E5cNmhYNmeLS5fTlqgVZEQaDu6JnzXc4OkJRDNpA/xWhA 85VhaiF0XmcGHuEMAMfAhahAsO23cC++GIAwGfTewYhOj8u6WAFnAl+Oiimlo7UiuenZ 1tTQ== X-Gm-Message-State: AFeK/H3gjvmBE87BwK6t6KuU/dVFwocxIGl7dW4s+gf0cSgnwLO5QVaPSLRAv69TTxCuv9UMRjI= X-Received: by 10.25.41.209 with SMTP id p200mr11111581lfp.55.1490190573098; Wed, 22 Mar 2017 06:49:33 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:32 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:25 +0100 Message-Id: <1490194110-40168-19-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 18/23] drv: complement parameters to the driver probe() 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" Of course, when probing a driver, the latter should be given the devio handle to be used. This is what this patch adds. It also adds the index of the devio, hence telling the driver which of the possible ODPDRV_MAX_DEVIOS devios was selected, as this is going to be the first thing the driver needs to know. Signed-off-by: Christophe Milard --- include/odp/drv/spec/driver.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/include/odp/drv/spec/driver.h b/include/odp/drv/spec/driver.h index 394aa92..ad2b8db 100644 --- a/include/odp/drv/spec/driver.h +++ b/include/odp/drv/spec/driver.h @@ -314,9 +314,12 @@ struct odpdrv_driver_param_t { /** Probe function: * Called by ODP to see if the driver can drive a given device - * + * -dev the device to be probed + * -devio is the devio to be used. + * -devio_idx actually tells which devio was selected: it is the + * index in the devios array above. */ - int (*probe)(odpdrv_device_t *dev); + int (*probe)(odpdrv_device_t dev, odpdrv_devio_t devio, int devio_idx); /** unbind function: * Only called with devices whose probe() returned true From patchwork Wed Mar 22 14:48:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95749 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp231592obz; Wed, 22 Mar 2017 07:07:06 -0700 (PDT) X-Received: by 10.107.47.137 with SMTP id v9mr36245112iov.112.1490191626696; Wed, 22 Mar 2017 07:07:06 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 21si1876513ioe.135.2017.03.22.07.07.06; Wed, 22 Mar 2017 07:07:06 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 15F2E642D3; Wed, 22 Mar 2017 14:07: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, URIBL_BLOCKED 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 80B53642FB; Wed, 22 Mar 2017 13:51:31 +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 9789A64315; Wed, 22 Mar 2017 13:51:22 +0000 (UTC) Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by lists.linaro.org (Postfix) with ESMTPS id 98A56642D0 for ; Wed, 22 Mar 2017 13:49:35 +0000 (UTC) Received: by mail-wm0-f52.google.com with SMTP id t189so38384065wmt.1 for ; Wed, 22 Mar 2017 06:49:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hNj+1a6Kq6fn6/ZslSPjy+0Ix5QumCiwkesqVH1Vzlo=; b=Xnakg3gmh99BU71EcECZUv3tojCzfXryX2KO3Pl0WvkMGT0pR/8N/FWTMKwN0uEJ14 0AP1Ic7yzRpJjiQv3msuuSKYtRhc/t6vestPGVwjLGF82K5d5GHCUdnB8UN5ivjyXB5s kjoNPf8VrYIdW5IIyvJHrKF7usAHT0NjXcfzoIIOWpsyyP4jUCOSELvunpuSdqwCvQbL DG5b9bwHqf+l2x01ngHWo838mTGDHF70MMbiSJ9ZF8xxqYCnd6K0OTjM030M/YvbSo3U 4ZVif9sN6w7KXysmBJUWjbox33mTIOVIVw/AJgHCMoeKZwx7giEZELHiLd8Bw6/Y21rK gSxw== X-Gm-Message-State: AFeK/H0KE9xhBPzNTBBRgbIgs6v653ud31sX4RltHFctPZ4Z7e7HaHZ0p0lB5WblVxnInUYSj2U= X-Received: by 10.25.223.86 with SMTP id q22mr11407156lfj.73.1490190574273; Wed, 22 Mar 2017 06:49:34 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:33 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:26 +0100 Message-Id: <1490194110-40168-20-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 19/23] linux-gen: driver registration and probing 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" Driver registration and probing is implemented for linux-gen ODP. Signed-off-by: Christophe Milard --- platform/linux-generic/drv_driver.c | 349 ++++++++++++++++++++++++++++++++++-- 1 file changed, 336 insertions(+), 13 deletions(-) -- 2.7.4 diff --git a/platform/linux-generic/drv_driver.c b/platform/linux-generic/drv_driver.c index 873ec3c..ea92457 100644 --- a/platform/linux-generic/drv_driver.c +++ b/platform/linux-generic/drv_driver.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -29,6 +30,11 @@ typedef struct _odpdrv_enumr_class_s _odpdrv_enumr_class_t; typedef struct _odpdrv_enumr_s _odpdrv_enumr_t; typedef struct _odpdrv_device_s _odpdrv_device_t; typedef struct _odpdrv_devio_s _odpdrv_devio_t; +typedef struct _odpdrv_driver_s _odpdrv_driver_t; + +static int unbind_device_driver(_odpdrv_device_t *dev, + void (*callback)(odpdrv_device_t odpdrv_dev), + int immediate); /* an enumerator class (list element) */ struct _odpdrv_enumr_class_s { @@ -62,6 +68,8 @@ static struct _odpdrv_enumr_lst_t enumr_lst; /* a device (list element) */ struct _odpdrv_device_s { odpdrv_device_param_t param; + _odpdrv_driver_t *driver; /* driver for the device (if bound), or NULL*/ + _odpdrv_devio_t *devio; /* devio used for device (if bound), or NULL*/ void (*enumr_destroy_callback)(void *enum_dev);/*dev destroy callback */ struct _odpdrv_device_s *next; } _odpdrv_device_s; @@ -87,6 +95,21 @@ typedef struct _odpdrv_devio_lst_t { } _odpdrv_devio_lst_t; static struct _odpdrv_devio_lst_t devio_lst; +/* a driver (list element) */ +struct _odpdrv_driver_s { + odpdrv_driver_param_t param; + _odp_ishm_pool_t *pool; + odp_ticketlock_t probelock; /* to avoid concurrent probe on same drv*/ + struct _odpdrv_driver_s *next; +}; + +/* the driver list: */ +typedef struct _odpdrv_driver_lst_t { + odp_rwlock_recursive_t lock; + _odpdrv_driver_t *head; +} _odpdrv_driver_lst_t; +static struct _odpdrv_driver_lst_t driver_lst; + /* some driver elements (such as enumeraor classes, drivers, devio) may * register before init_global and init_local complete. Mutex will fail * in this cases but should be used later on. @@ -188,6 +211,30 @@ static void devio_list_write_unlock(void) odp_rwlock_recursive_write_unlock(&devio_lst.lock); } +static void driver_list_read_lock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_read_lock(&driver_lst.lock); +} + +static void driver_list_read_unlock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_read_unlock(&driver_lst.lock); +} + +static void driver_list_write_lock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_write_lock(&driver_lst.lock); +} + +static void driver_list_write_unlock(void) +{ + if (init_global_status == DONE) + odp_rwlock_recursive_write_unlock(&driver_lst.lock); +} + /* some functions to get internal pointers from handles... */ static inline _odpdrv_enumr_class_t *get_enumr_class(odpdrv_enumr_class_t class) { @@ -346,6 +393,8 @@ odpdrv_device_t odpdrv_device_create(odpdrv_device_param_t *param) /* save and set dev init parameters and insert new device in list */ dev->param = *param; dev->enumr_destroy_callback = NULL; + dev->driver = NULL; + dev->devio = NULL; dev_list_write_lock(); dev->next = device_lst.head; device_lst.head = dev; @@ -399,19 +448,17 @@ int odpdrv_device_destroy(odpdrv_device_t dev, */ target->enumr_destroy_callback = callback; - /* TODO: if a driver is bound to the device, unbind it! - * passing the flag andf device_destroy_terminate() as a callback */ - - /* no driver is handling this device, or no callback was - * provided: continue removing the device: */ - device_destroy_terminate(dev); + /* unbind the driver from the device (if bound). + * The callback is always called. */ + unbind_device_driver(target, + device_destroy_terminate, + (flags & ODPDRV_DEV_DESTROY_IMMEDIATE)); return 0; } /* This function is called as a callback from the driver, when unbindind - * a device, or directely from odpdrv_device_destroy() if no driver - * was bound to the device. + * a device drom odpdrv_device_destroy() * just call the enumerator callback to cleanup the enumerator part * and free device memory */ static void device_destroy_terminate(odpdrv_device_t drv_device) @@ -532,10 +579,239 @@ odpdrv_devio_t odpdrv_devio_register(odpdrv_devio_param_t *param) odpdrv_driver_t odpdrv_driver_register(odpdrv_driver_param_t *param) { - ODP_ERR("NOT Supported yet! Driver %s Registration!\n.", - param->name); + _odpdrv_driver_t *driver; + + /* check for a few compulsory things: */ + if ((param->probe == NULL) || + (param->unbind == NULL)) + return ODPDRV_DRIVER_INVALID; + + /* parse the list of already registered drivers to make + * sure no driver with same name already exists: + */ + driver_list_read_lock(); + driver = driver_lst.head; + while (driver) { + if ((strncmp(param->name, driver->param.name, + ODPDRV_NAME_SIZE) == 0)) { + ODP_ERR("driver %s already registered!\n", + param->name); + driver_list_read_unlock(); + return ODPDRV_DRIVER_INVALID; + } + driver = driver->next; + } + driver_list_read_unlock(); + + /* allocate memory for the new driver: + * If init_global has not been done yet, then, we cannot allocate + * from any _ishm pool (ishm has not even been initialised at this + * stage...this happens when statically linked drivers + * register: their __constructor__ function is run before main() + * is called). But any malloc performed here(before init_global) + * will be inherited by any odpthreads (process or pthreads) as we + * are still running in the ODP instantiation processes and all + * other processes are guaranteed to be descendent of this one... + * If init_global has been done, then we allocate from the _ishm pool + * to guarantee visibility from any ODP thread. + */ + + if (init_global_status == UNDONE) { + driver = malloc(sizeof(_odpdrv_driver_t)); + if (!driver) + return ODPDRV_DRIVER_INVALID; + driver->pool = NULL; + } else { + driver = _odp_ishm_pool_alloc(list_elt_pool, + sizeof(_odpdrv_driver_t)); + if (!driver) { + ODP_ERR("_odp_ishm_pool_alloc failed!\n"); + return ODPDRV_DRIVER_INVALID; + } + driver->pool = list_elt_pool; + } + + /* save init parameters and insert driver in list */ + driver->param = *param; + odp_ticketlock_init(&driver->probelock); + driver_list_write_lock(); + driver->next = driver_lst.head; + driver_lst.head = driver; + driver_list_write_unlock(); + + return (odpdrv_driver_t)driver; +} + +/* Probe, if possible, the given driver with the given device: + * The driver is probed if: + * There exist a devio D such as + * -The name and version of the API provided by D matches one of the requested + * devio {name,version} requested by the driver + * -The enumerator's API (name and version) requested by D is provided + * by the enumerator which enumerated the device. + * This function will return zero if the above condition where met by some + * devio D and the driver probe function returns 0 (success). + * The function will return -1 if some devio D were found, but the driver + * returned a non-zero value when probed (for all of them). + * The function will return -2 if no devio matching the above requirement was + * found. + * The function will return -3 if the device was already bound to a driver */ +static int probe_device_driver(_odpdrv_device_t *dev, _odpdrv_driver_t *drv) +{ + int i; + int ret = -2; + _odpdrv_devio_t *devio; + _odpdrv_enumr_t *enumr; + _odpdrv_enumr_class_t *enumr_c; + + /* the device already has a driver?: end of story... */ + if (dev->driver) + return -3; + + /* look at the different devio this driver can work with: */ + for (i = 0; i < ODPDRV_MAX_DEVIOS; i++) { + /* look at each registered devios: */ + devio_list_read_lock(); + for (devio = devio_lst.head; devio; devio = devio->next) { + /* if devio is no good for this driver, keep searching*/ + if ((strncmp(drv->param.devios[i].api_name, + devio->param.api_name, + ODPDRV_NAME_SIZE) != 0) || + (drv->param.devios[i].api_version != + devio->param.api_version)) + continue; + + /* give a chance to the devio to reject the device + * if it feels it should do so: */ + if (devio->param.probe && + devio->param.probe((odpdrv_device_t)dev)) + continue; + + /* grab the device enumerator and its class: */ + enumr = get_enumr(dev->param.enumerator); + enumr_c = get_enumr_class(enumr->param.enumr_class); + + /* if devio is no good for this dev, keep searching */ + if ((strncmp(devio->param.enumr_api_name, + enumr->param.api_name, + ODPDRV_NAME_SIZE) != 0) || + (devio->param.enumr_api_version != + enumr->param.api_version)) + continue; + + /* seems we are good to probe the driver: */ + odp_ticketlock_lock(&drv->probelock); + if (drv->param.probe((odpdrv_device_t)dev, + (odpdrv_devio_t)devio, i) == 0) { + /* the driver accepts this device */ + odp_ticketlock_unlock(&drv->probelock); + devio_list_read_unlock(); + ODP_DBG("driver %s will handle device %s(%s)\n", + drv->param.name, + dev->param.address, + enumr_c->param.name); + dev->driver = drv; + dev->devio = devio; + return 0; + } + odp_ticketlock_unlock(&drv->probelock); + + /* driver did not accept the device: keep searching */ + ret = -1; + } + devio_list_read_unlock(); + } + return ret; +} + +/* an empty callback is given to the driver on unprobe, if no real callback is + * needed */ +static void empty_unbind_callback(odpdrv_device_t odpdrv_dev ODP_UNUSED) +{ +} + +/* unbind the device driver from the device (i.e. "unprobe") + * if the immediate flag is set, the unbind is requested to be immediate, + * i.e. the driver is due to call the callback within its unbind function. + * (if the flag is not set, the callback can be called later on from + * another context. Immediate unbinding may be less graceful then + * non immediate binding) + * The callback function is called in all cases (even if the device was not + * bound) + */ +static int unbind_device_driver(_odpdrv_device_t *dev, + void (*callback)(odpdrv_device_t odpdrv_dev), + int immediate) +{ + _odpdrv_driver_t *drv; + odpdrv_device_t odpdrv_dev = (odpdrv_device_t)dev; + int flg = immediate ? ODPDRV_DRV_UNBIND_IMMEDIATE : 0; + + if (!callback) + callback = empty_unbind_callback; + + drv = dev->driver; + if (!drv) { /* nothing to do */ + callback(odpdrv_dev); + return 0; + } + + /* note that we assure that a given driver will not be bound/unbound + * concurrentely - but this does not cover the callback */ + odp_ticketlock_lock(&drv->probelock); + if (drv->param.unbind(odpdrv_dev, callback, flg)) { + ODP_DBG("driver %s could not release device %s\n", + drv->param.name, + dev->param.address); + odp_ticketlock_unlock(&drv->probelock); + return -1; + } + + /* unbind succeeded */ + dev->driver = NULL; + dev->devio = NULL; + odp_ticketlock_unlock(&drv->probelock); + return 0; +} + +/* try to find a driver for the given device, trying all possible registered + * drivers against it: + * returns 0 on success or -1 on error + */ +static int probe_device(_odpdrv_device_t *dev) +{ + _odpdrv_driver_t *driver; + int ret = -1; + + /* go through the list of registered drivers: */ + driver_list_read_lock(); + driver = driver_lst.head; + while (driver) { + if (probe_device_driver(dev, driver) == 0) { + ret = 0; + break; + } + driver = driver->next; + } + driver_list_read_unlock(); + + return ret; +} + +/* try to find a driver for all the registered devices, trying all possible + * drivers-devices combinaison + */ +static void probe_all(void) +{ + _odpdrv_device_t *dev; - return ODPDRV_DRIVER_INVALID; + dev_list_read_lock(); + dev = device_lst.head; + while (dev) { + (void)probe_device(dev); + dev = dev->next; + } + dev_list_read_unlock(); } /* the following function is called each time probing is needed, i.e. @@ -571,6 +847,9 @@ void _odpdrv_driver_probe_drv_items(void) enumr = enumr->next; } enumr_list_read_unlock(); + + /* probe drivers for all devices */ + probe_all(); } int odpdrv_print_all(void) @@ -579,6 +858,7 @@ int odpdrv_print_all(void) _odpdrv_enumr_t *enumr; _odpdrv_device_t *dev; _odpdrv_devio_t *devio; + _odpdrv_driver_t *driver; /* we cannot use ODP_DBG before ODP init... */ if (init_global_status == UNDONE) @@ -618,11 +898,16 @@ int odpdrv_print_all(void) enumr = get_enumr(dev->param.enumerator); enumr_c = get_enumr_class(enumr->param.enumr_class); ODP_DBG(" device: address: %s, from enumerator class: %s " - " API: %s, Version: %d\n", + " API: %s, Version: %d, " + " handled by driver %s, with devio API: %s " + " (version %d)\n", dev->param.address, enumr_c->param.name, enumr->param.api_name, - enumr->param.api_version); + enumr->param.api_version, + dev->driver ? dev->driver->param.name : "", + dev->devio ? dev->devio->param.api_name : "", + dev->devio ? dev->devio->param.api_version : 0); dev = dev->next; } dev_list_read_unlock(); @@ -642,6 +927,17 @@ int odpdrv_print_all(void) } devio_list_read_unlock(); + /* print the list of registered drivers: */ + driver_list_read_lock(); + driver = driver_lst.head; + ODP_DBG("The following dev drivers have been registered:\n"); + while (driver) { + ODP_DBG(" driver: '%s'\n", + driver->param.name); + driver = driver->next; + } + driver_list_read_unlock(); + return 0; } @@ -660,6 +956,7 @@ int _odpdrv_driver_init_global(void) odp_rwlock_recursive_init(&enumr_lst.lock); odp_rwlock_recursive_init(&device_lst.lock); odp_rwlock_recursive_init(&devio_lst.lock); + odp_rwlock_recursive_init(&driver_lst.lock); /* probe things... */ _odpdrv_driver_probe_drv_items(); @@ -680,10 +977,36 @@ int _odpdrv_driver_term_global(void) _odpdrv_devio_t *devio; _odpdrv_enumr_class_t *enumr_c; _odpdrv_enumr_t *enumr; + _odpdrv_device_t *dev; + _odpdrv_driver_t *driver; if (init_global_status == UNDONE) return 0; + /* unbind any driver from any device: */ + dev_list_read_lock(); + dev = device_lst.head; + while (dev) { + unbind_device_driver(dev, NULL, 1); + dev = dev->next; + } + dev_list_read_unlock(); + + /* and remove all registered drivers: */ + driver_list_read_lock(); + while (driver_lst.head) { + driver = driver_lst.head; + if (driver->param.remove) { + if (driver->param.remove()) + ODP_ERR("driver removal indicated failure!\n"); + } + driver_lst.head = driver->next; + if (driver->pool) + _odp_ishm_pool_free(list_elt_pool, driver); + else + free(driver); + } + /* remove all devios which are registered: */ devio_list_write_lock(); while (devio_lst.head) { From patchwork Wed Mar 22 14:48:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95750 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp232253obz; Wed, 22 Mar 2017 07:08:32 -0700 (PDT) X-Received: by 10.107.148.5 with SMTP id w5mr35349271iod.222.1490191712413; Wed, 22 Mar 2017 07:08:32 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id e69si1883929ioe.101.2017.03.22.07.08.32; Wed, 22 Mar 2017 07:08:32 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id E9F6E642D6; Wed, 22 Mar 2017 14:08:31 +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.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED,URI_NOVOWEL 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 288B16431F; Wed, 22 Mar 2017 13:51:37 +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 437226431B; Wed, 22 Mar 2017 13:51:27 +0000 (UTC) Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) by lists.linaro.org (Postfix) with ESMTPS id A2BBC642D2 for ; Wed, 22 Mar 2017 13:49:36 +0000 (UTC) Received: by mail-wm0-f46.google.com with SMTP id t189so38384450wmt.1 for ; Wed, 22 Mar 2017 06:49:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QEF0QndHzKfh6vxlwNHD0lVwShrLxKkepRIvhe8x/3s=; b=FdjT4LihSJGx1+MeYNHcRQN3JmDjtBwx5IKK8g1OM2k9Yg85PyBgq4rtrX2SnuRiyr GrHi0qVfIPOf4HjXMKAO39pTxBdlSXA8BPKGt7C3TppdaLRx7T+34oiAFT3r7QSz4wQG 20PTXa6hwR+jPlTYGDBVoVRoSUb5Uu0Lbw7Thz5sZxdxJrgiqSRvZhdDZKQgcXiV0xUk pZLh2Lm8Smsbh9WKMZ8z9My31QYrukDfGj1ntmcffBctLupAKYB8zhUH/lmceaxJsasZ c7H6dzN4/0qyHO8Gj44DkGV2NLiV6cIa/Ij4lm4xezpuic0CM73yHQGWBNltggEzSBet fHdA== X-Gm-Message-State: AFeK/H3bK+mx6/L1GYCgKd86jkHWgeHA/n41GNiHVtvJ6msP0qh6F+0HyWIXDzOTcxXw+enZVqo= X-Received: by 10.25.19.90 with SMTP id j87mr11464552lfi.182.1490190575439; Wed, 22 Mar 2017 06:49:35 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:34 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:27 +0100 Message-Id: <1490194110-40168-21-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 20/23] test: drv: driver registration and probing 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" Register driver, devios, enumerators, create devices, and check that probing occurs correctely. Signed-off-by: Christophe Milard --- .../validation/drv/drvdriver/.gitignore | 1 + .../validation/drv/drvdriver/Makefile.am | 11 + .../validation/drv/drvdriver/drvdriver_driver.c | 515 +++++++++++++++++++++ .../validation/drv/drvdriver/drvdriver_driver.h | 24 + .../drv/drvdriver/drvdriver_driver_main.c | 12 + test/linux-generic/Makefile.am | 1 + 6 files changed, 564 insertions(+) create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_driver.c create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_driver.h create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_driver_main.c -- 2.7.4 diff --git a/test/common_plat/validation/drv/drvdriver/.gitignore b/test/common_plat/validation/drv/drvdriver/.gitignore index 829c8b4..76bb6ba 100644 --- a/test/common_plat/validation/drv/drvdriver/.gitignore +++ b/test/common_plat/validation/drv/drvdriver/.gitignore @@ -2,3 +2,4 @@ drvdriver_enumr_class_main drvdriver_enumr_main drvdriver_device_main drvdriver_devio_main +drvdriver_driver_main diff --git a/test/common_plat/validation/drv/drvdriver/Makefile.am b/test/common_plat/validation/drv/drvdriver/Makefile.am index 8e695ba..88bd828 100644 --- a/test/common_plat/validation/drv/drvdriver/Makefile.am +++ b/test/common_plat/validation/drv/drvdriver/Makefile.am @@ -47,3 +47,14 @@ drvdriver_devio_main_LDADD = libtestdrvdriverdevio.la \ $(LIBCUNIT_COMMON) $(LIBODP) EXTRA_DIST += drvdriver_devio.h + +#tests for driver registration and probing: +noinst_LTLIBRARIES += libtestdrvdriverdriver.la +libtestdrvdriverdriver_la_SOURCES = drvdriver_driver.c + +test_PROGRAMS += drvdriver_driver_main$(EXEEXT) +dist_drvdriver_driver_main_SOURCES = drvdriver_driver_main.c +drvdriver_driver_main_LDADD = libtestdrvdriverdriver.la \ + $(LIBCUNIT_COMMON) $(LIBODP) + +EXTRA_DIST += drvdriver_driver.h diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_driver.c b/test/common_plat/validation/drv/drvdriver/drvdriver_driver.c new file mode 100644 index 0000000..d90aa56 --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_driver.c @@ -0,0 +1,515 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/* This file is a bit long as it tries to simulate the presence of 2 + * enumerator classes, 2 enumerators, and 3 drivers in one go to + * see how things are handled by the driver framework. + * The following is done: + * - create 2 enumerator classes, + * - each with its own enumerator providing interfaces: E1 and E2. + * - E1 and E2 create 4 devices each. + * - the following devio are created: + * devio1 enabling device handling from DRVIF-1 to E1 + * devio2 enabling device handling from DRVIF-2 to E2 + * devio3 enabling device handling from DRVIF-3 to E2 + * devio4 enabling device handling from DRVIF-3 to E3 (does not exist) + * devio5 enabling device handling from DRVIF-4 to E3 (does not exist) + * + * -then the following driver are created: + * driver1, requiring devio DRVIF-1 + * driver2, requiring devio DRVIF-2 (preferred) and DRVIF-3 + * driver3, requiring devio DRVIF-4 + * + * The test amkes sure that: + * driver 1 is probed (and accepts) the 4 devices of E1 with devio1 + * driver 2 is probed (and rejects) the 4 devices of E2 with devio2 and devio4 + * driver3 is never probed. + */ + +#include +#include +#include +#include "drvdriver_driver.h" +#include + +static odp_instance_t odp_instance; +static odpdrv_enumr_class_t enumr_class1; +static odpdrv_enumr_class_t enumr_class2; +static odpdrv_enumr_t enumr1; +static odpdrv_enumr_t enumr2; +#define NB_DEVICES 4 +static odpdrv_device_t E1_devs[NB_DEVICES]; +static odpdrv_device_t E2_devs[NB_DEVICES]; +static odpdrv_devio_t devio1; +static odpdrv_devio_t devio2; +static odpdrv_devio_t devio3; +static odpdrv_devio_t devio4; +static odpdrv_devio_t devio5; +static odpdrv_driver_t driver1; +static odpdrv_driver_t driver2; +static odpdrv_driver_t driver3; + +static int driver1_probed_index; +static int driver2_probed_index; + +/* forward declaration */ +static int enumr1_probe(void); +static int enumr2_probe(void); +static int enumr1_remove(void); +static int enumr2_remove(void); +static int enumr_class1_probe(void); +static int enumr_class2_probe(void); +static int driver1_probe(odpdrv_device_t dev, odpdrv_devio_t devio, int idx); +static int driver2_probe(odpdrv_device_t dev, odpdrv_devio_t devio, int idx); +static int driver3_probe(odpdrv_device_t dev, odpdrv_devio_t devio, int idx); +static int driver1_unbind(odpdrv_device_t dev, + void (*callback)(odpdrv_device_t dev), + uint32_t flags); +static int driver2_unbind(odpdrv_device_t dev, + void (*callback)(odpdrv_device_t dev), + uint32_t flags); +static int driver3_unbind(odpdrv_device_t dev, + void (*callback)(odpdrv_device_t dev), + uint32_t flags); + +/* because many things to be checked are performed during ODP initialisation, + * the initialisation functions have to be a part of the test + */ +static int tests_global_init(void) +{ + if (0 != odp_init_global(&odp_instance, NULL, NULL)) { + fprintf(stderr, "error: odp_init_global() failed.\n"); + return -1; + } + if (0 != odp_init_local(odp_instance, ODP_THREAD_CONTROL)) { + fprintf(stderr, "error: odp_init_local() failed.\n"); + return -1; + } + + return 0; +} + +static int tests_global_term(void) +{ + if (0 != odp_term_local()) { + fprintf(stderr, "error: odp_term_local() failed.\n"); + return -1; + } + + if (0 != odp_term_global(odp_instance)) { + fprintf(stderr, "error: odp_term_global() failed.\n"); + return -1; + } + + return 0; +} + +/*enumerator class register functions, all "statically linked" + *(i.e. directely run at start), due to the fact that platorm independent + * shared lib loading in autotools is a mess */ +static void ODPDRV_CONSTRUCTOR enumr_class1_register(void) +{ + odpdrv_enumr_class_param_t param = { + .name = "C1", + .probe = enumr_class1_probe, + .remove = NULL + }; + + enumr_class1 = odpdrv_enumr_class_register(¶m); +} + +static void ODPDRV_CONSTRUCTOR enumr_class2_register(void) +{ + odpdrv_enumr_class_param_t param = { + .name = "C2", + .probe = enumr_class2_probe, + .remove = NULL + }; + + enumr_class2 = odpdrv_enumr_class_register(¶m); +} + +/*enumerator class probe functions, registering enumerators E1 and E2: */ +static int enumr_class1_probe(void) +{ + odpdrv_enumr_param_t param = { + .enumr_class = enumr_class1, + .api_name = "E1", + .api_version = 1, + .probe = enumr1_probe, + .remove = enumr1_remove, + .register_notifier = NULL + }; + + enumr1 = odpdrv_enumr_register(¶m); + CU_ASSERT(enumr1 != ODPDRV_ENUMR_INVALID); + + return 0; +} + +static int enumr_class2_probe(void) +{ + odpdrv_enumr_param_t param = { + .enumr_class = enumr_class2, + .api_name = "E2", + .api_version = 1, + .probe = enumr2_probe, + .remove = enumr2_remove, + .register_notifier = NULL + }; + + enumr2 = odpdrv_enumr_register(¶m); + CU_ASSERT(enumr2 != ODPDRV_ENUMR_INVALID); + + return 0; +} + +/*enumerator probe functions, creating four devices each: */ +static int enumr1_probe(void) +{ + int dev; + + odpdrv_device_param_t param = { + .enumerator = enumr1, + .address = "E1:00:0X", + .enum_dev = NULL + }; + + /* create devices: */ + for (dev = 0; dev < NB_DEVICES; dev++) { + param.address[7] = '0' + dev; /* change X in the address */ + param.enum_dev = NULL; + E1_devs[dev] = odpdrv_device_create(¶m); + CU_ASSERT(E1_devs[dev] != ODPDRV_DEVICE_INVALID); + } + + return 0; +} + +static int enumr2_probe(void) +{ + int dev; + + odpdrv_device_param_t param = { + .enumerator = enumr2, + .address = "E2:00:0X", + .enum_dev = NULL + }; + + /* create devices: */ + for (dev = 0; dev < NB_DEVICES; dev++) { + param.address[7] = '0' + dev; /* change X in the address */ + param.enum_dev = NULL; + E2_devs[dev] = odpdrv_device_create(¶m); + CU_ASSERT(E1_devs[dev] != ODPDRV_DEVICE_INVALID); + } + + return 0; +} + +/*enumerator remove functions, to remove the enumerated devices: */ +static int enumr1_remove(void) +{ + odpdrv_device_t *my_devices; + odpdrv_device_t *dev; + int count = 0; + + /* destroy all devices created by enumerator 5: */ + my_devices = odpdrv_device_query(enumr1, NULL); + + for (dev = my_devices; *dev != ODPDRV_DEVICE_INVALID; dev++) { + odpdrv_device_destroy(*dev, NULL, 0); + count++; + } + + CU_ASSERT(count == NB_DEVICES); + + free(my_devices); + return 0; +} + +static int enumr2_remove(void) +{ + odpdrv_device_t *my_devices; + odpdrv_device_t *dev; + int count = 0; + + /* destroy all devices created by enumerator 5: */ + my_devices = odpdrv_device_query(enumr2, NULL); + + for (dev = my_devices; *dev != ODPDRV_DEVICE_INVALID; dev++) { + odpdrv_device_destroy(*dev, NULL, 0); + count++; + } + + CU_ASSERT(count == NB_DEVICES); + + free(my_devices); + return 0; +} + +/* devios: */ +static void ODPDRV_CONSTRUCTOR devio1_register(void) +{ + odpdrv_devio_param_t param = { + .api_name = "DRVIF-1", + .api_version = 1, + .enumr_api_name = "E1", + .enumr_api_version = 1, + .probe = NULL, + .remove = NULL, + .ops = NULL, + }; + + devio1 = odpdrv_devio_register(¶m); +} + +static void ODPDRV_CONSTRUCTOR devio2_register(void) +{ + odpdrv_devio_param_t param = { + .api_name = "DRVIF-2", + .api_version = 1, + .enumr_api_name = "E2", + .enumr_api_version = 1, + .probe = NULL, + .remove = NULL, + .ops = NULL, + }; + + devio2 = odpdrv_devio_register(¶m); +} + +static void ODPDRV_CONSTRUCTOR devio3_register(void) +{ + odpdrv_devio_param_t param = { + .api_name = "DRVIF-3", + .api_version = 1, + .enumr_api_name = "E2", + .enumr_api_version = 1, + .probe = NULL, + .remove = NULL, + .ops = NULL, + }; + + devio3 = odpdrv_devio_register(¶m); +} + +static void ODPDRV_CONSTRUCTOR devio4_register(void) +{ + odpdrv_devio_param_t param = { + .api_name = "DRVIF-3", + .api_version = 1, + .enumr_api_name = "E3", + .enumr_api_version = 1, + .probe = NULL, + .remove = NULL, + .ops = NULL, + }; + + devio4 = odpdrv_devio_register(¶m); +} + +static void ODPDRV_CONSTRUCTOR devio5_register(void) +{ + odpdrv_devio_param_t param = { + .api_name = "DRVIF-4", + .api_version = 1, + .enumr_api_name = "E3", + .enumr_api_version = 1, + .probe = NULL, + .remove = NULL, + .ops = NULL, + }; + + devio5 = odpdrv_devio_register(¶m); +} + +static void ODPDRV_CONSTRUCTOR driver1_register(void) +{ + odpdrv_driver_param_t param = { + .name = "driver1", + .devios = { {"DRVIF-1", 1}, {"", -1}, {"", -1} }, + .probe = driver1_probe, + .unbind = driver1_unbind, + .remove = NULL, + }; + + driver1 = odpdrv_driver_register(¶m); +} + +static void ODPDRV_CONSTRUCTOR driver2_register(void) +{ + odpdrv_driver_param_t param = { + .name = "driver2", + .devios = { {"DRVIF-2", 1}, {"DRVIF-3", 1}, {"", -1} }, + .probe = driver2_probe, + .unbind = driver2_unbind, + .remove = NULL, + }; + + driver2 = odpdrv_driver_register(¶m); +} + +static void ODPDRV_CONSTRUCTOR driver3_register(void) +{ + odpdrv_driver_param_t param = { + .name = "driver3", + .devios = { {"DRVIF-4", 1}, {"", -1}, {"", -1} }, + .probe = driver3_probe, + .unbind = driver3_unbind, + .remove = NULL, + }; + + driver3 = odpdrv_driver_register(¶m); +} + +static int driver1_probe(odpdrv_device_t dev, odpdrv_devio_t devio, int idx) +{ + int i; + int dev_found = 0; + + CU_ASSERT(dev != ODPDRV_DEVICE_INVALID); + CU_ASSERT(devio == devio1); + CU_ASSERT(idx < 1); + + /*makes sure the device is from E1 */ + for (i = 0; i < NB_DEVICES; i++) { + if (dev == E1_devs[i]) { + driver1_probed_index |= (1 << i); + dev_found = 1; + } + } + CU_ASSERT(dev_found); + return 0; /* accept the device */ +} + +static int driver2_probe(odpdrv_device_t dev, odpdrv_devio_t devio, int idx) +{ + int i; + int dev_found = 0; + + CU_ASSERT(dev != ODPDRV_DEVICE_INVALID); + + /* check that we are probed with one of the required deviios */ + CU_ASSERT(((devio == devio2) && (idx == 0)) || + ((devio == devio3) && (idx == 1))); + + /*make sure the device is from E2, and probed twice */ + for (i = 0; i < NB_DEVICES; i++) { + if (dev == E2_devs[i]) { + /* check that device was probed with idx=0 first */ + if (idx > 0) + CU_ASSERT(driver2_probed_index & (1 << i)); + /* marked as probed: */ + driver2_probed_index |= (1 << (i + idx * NB_DEVICES)); + dev_found = 1; + } + } + CU_ASSERT(dev_found); + if (idx == 0) + return -1; /* reject the device, when probed with idx = 0 */ + return 0; /* accept second probe*/ +} + +static int driver3_probe(odpdrv_device_t dev, odpdrv_devio_t devio, int idx) +{ + /* we can look for some strangeness here ... */ + CU_ASSERT(dev != ODPDRV_DEVICE_INVALID); + CU_ASSERT(devio != ODPDRV_DEVIO_INVALID); + CU_ASSERT(idx >= 0); + + /* but we should not be probing this driver anyway! */ + CU_FAIL("This driver should not be probed"); + return -1; /* reject the device */ +} + +static int driver1_unbind(odpdrv_device_t dev, + void (*callback)(odpdrv_device_t dev), + uint32_t flags) +{ + CU_ASSERT(dev != ODPDRV_DEVICE_INVALID); + CU_ASSERT(flags == ODPDRV_DRV_UNBIND_IMMEDIATE); + callback(dev); + + return 0; +} + +static int driver2_unbind(odpdrv_device_t dev, + void (*callback)(odpdrv_device_t dev), + uint32_t flags) +{ + CU_ASSERT(dev != ODPDRV_DEVICE_INVALID); + CU_ASSERT(flags == ODPDRV_DRV_UNBIND_IMMEDIATE); + callback(dev); + + return 0; +} + +static int driver3_unbind(odpdrv_device_t dev, + void (*callback)(odpdrv_device_t dev), + uint32_t flags) +{ + CU_ASSERT(dev != ODPDRV_DEVICE_INVALID); + CU_ASSERT(flags == ODPDRV_DRV_UNBIND_IMMEDIATE); + callback(dev); + + return 0; +} + +void drvdriver_test_driver_register(void) +{ + CU_ASSERT(enumr_class1 != ODPDRV_ENUMR_CLASS_INVALID); + CU_ASSERT(enumr_class2 != ODPDRV_ENUMR_CLASS_INVALID); + CU_ASSERT(devio1 != ODPDRV_DEVIO_INVALID); + CU_ASSERT(devio2 != ODPDRV_DEVIO_INVALID); + CU_ASSERT(devio3 != ODPDRV_DEVIO_INVALID); + CU_ASSERT(devio4 != ODPDRV_DEVIO_INVALID); + CU_ASSERT(devio5 != ODPDRV_DEVIO_INVALID); + CU_ASSERT(driver1 != ODPDRV_DRIVER_INVALID); + CU_ASSERT(driver2 != ODPDRV_DRIVER_INVALID); + CU_ASSERT(driver3 != ODPDRV_DRIVER_INVALID); + + CU_ASSERT(tests_global_init() == 0); + + CU_ASSERT(odpdrv_print_all() == 0); + + /* check that expected probing occurred: */ + CU_ASSERT(driver1_probed_index == (1 << NB_DEVICES) - 1); + CU_ASSERT(driver2_probed_index == (1 << (NB_DEVICES * 2)) - 1); + + CU_ASSERT(tests_global_term() == 0); +} + +odp_testinfo_t drvdriver_suite_driver[] = { + ODP_TEST_INFO(drvdriver_test_driver_register), + ODP_TEST_INFO_NULL, +}; + +odp_suiteinfo_t drvdriver_suites_driver[] = { + {"Enumerator registration", NULL, NULL, drvdriver_suite_driver}, + ODP_SUITE_INFO_NULL, +}; + +int drvdriver_driver_main(int argc, char *argv[]) +{ + int ret; + + /* parse common options: */ + if (odp_cunit_parse_options(argc, argv)) + return -1; + + /* prevent default ODP init: */ + odp_cunit_register_global_init(NULL); + odp_cunit_register_global_term(NULL); + + /* register the tests: */ + ret = odp_cunit_register(drvdriver_suites_driver); + + if (ret == 0) + ret = odp_cunit_run(); + + return ret; +} diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_driver.h b/test/common_plat/validation/drv/drvdriver/drvdriver_driver.h new file mode 100644 index 0000000..d80c689 --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_driver.h @@ -0,0 +1,24 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_DRVDRIVER_DRIVER_H_ +#define _ODP_TEST_DRVDRIVER_DRIVER_H_ + +#include + +/* test functions: */ +void drvdriver_test_driver_register(void); + +/* test arrays: */ +extern odp_testinfo_t drvdriver_suite_driver[]; + +/* test registry: */ +extern odp_suiteinfo_t drvdriver_suites_driver[]; + +/* main test program: */ +int drvdriver_driver_main(int argc, char *argv[]); + +#endif diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_driver_main.c b/test/common_plat/validation/drv/drvdriver/drvdriver_driver_main.c new file mode 100644 index 0000000..671689c --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_driver_main.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "drvdriver_driver.h" + +int main(int argc, char *argv[]) +{ + return drvdriver_driver_main(argc, argv); +} diff --git a/test/linux-generic/Makefile.am b/test/linux-generic/Makefile.am index 55db05c..03f9a8d 100644 --- a/test/linux-generic/Makefile.am +++ b/test/linux-generic/Makefile.am @@ -38,6 +38,7 @@ TESTS = validation/api/pktio/pktio_run.sh \ $(ALL_DRV_VALIDATION_DIR)/drvatomic/drvatomic_main$(EXEEXT) \ $(ALL_DRV_VALIDATION_DIR)/drvdriver/drvdriver_device_main$(EXEEXT)\ $(ALL_DRV_VALIDATION_DIR)/drvdriver/drvdriver_devio_main$(EXEEXT)\ + $(ALL_DRV_VALIDATION_DIR)/drvdriver/drvdriver_driver_main$(EXEEXT)\ $(ALL_DRV_VALIDATION_DIR)/drvdriver/drvdriver_enumr_class_main$(EXEEXT)\ $(ALL_DRV_VALIDATION_DIR)/drvdriver/drvdriver_enumr_main$(EXEEXT)\ $(ALL_DRV_VALIDATION_DIR)/drvshmem/drvshmem_main$(EXEEXT) \ From patchwork Wed Mar 22 14:48:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95751 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp232284obz; Wed, 22 Mar 2017 07:08:36 -0700 (PDT) X-Received: by 10.107.12.80 with SMTP id w77mr38171161ioi.124.1490191716207; Wed, 22 Mar 2017 07:08:36 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id b62si1869344ith.93.2017.03.22.07.08.35; Wed, 22 Mar 2017 07:08:36 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id B0AD5642C1; Wed, 22 Mar 2017 14:08:35 +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, URIBL_BLOCKED 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 EBC3A642DD; Wed, 22 Mar 2017 13:51:45 +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 1F373642DD; Wed, 22 Mar 2017 13:51:38 +0000 (UTC) Received: from mail-wm0-f51.google.com (mail-wm0-f51.google.com [74.125.82.51]) by lists.linaro.org (Postfix) with ESMTPS id 9935C642DD for ; Wed, 22 Mar 2017 13:49:37 +0000 (UTC) Received: by mail-wm0-f51.google.com with SMTP id n11so37225269wma.1 for ; Wed, 22 Mar 2017 06:49:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=g/LSpV0ad6TQ1iUkkTxwbKv+bFvGt8ZBJOT7LpNANKo=; b=LIOMOZxEqlgUnr3kA0MzhdGHreWBsTNZlmCBzRMAu8Kwe5py7mL5WdT5qBFKrNOw9D 3yO7/jYMAd2W5FZJsNk8H2RUHh514OaCryM1f68c+u9Md67sFhGIDSv9ALqmsEum5pIK DocM4MwTemxthD960fqEW1PjYXw0TggLT8Ww2R53dHuNg+Toq0LX9Ksy+OdjwQti8phZ ISe2V8MTEtQ/q4VUl7RkfoWPoQj/AqY0aBSSvamXgqOHMsRa09YdqOibzsw+yLxE9HmW +uv47DBYAdvK8k2vRQrzCQBSeLoNiz0eWGHyrJlu3CmOslgBphw59JKyPjSjvVE9Kibb W7OQ== X-Gm-Message-State: AFeK/H2/5Iix2URLtO4ILuZz2dLcbStsgAyc4Yg7I7ngANe6MpBK7GAWLZ354cEKGCYku7B/Kqk= X-Received: by 10.25.23.33 with SMTP id n33mr10298990lfi.48.1490190576404; Wed, 22 Mar 2017 06:49:36 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:35 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:28 +0100 Message-Id: <1490194110-40168-22-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 21/23] drv: driver: adding functions to attach driver's data to the device 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" Driver will need to attach their data to devices when bound. The patch introduce a data setter and a data getter function to do so. Signed-off-by: Christophe Milard --- include/odp/drv/spec/driver.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) -- 2.7.4 diff --git a/include/odp/drv/spec/driver.h b/include/odp/drv/spec/driver.h index ad2b8db..224baf4 100644 --- a/include/odp/drv/spec/driver.h +++ b/include/odp/drv/spec/driver.h @@ -450,6 +450,27 @@ odpdrv_devio_t odpdrv_devio_register(odpdrv_devio_param_t *param); odpdrv_driver_t odpdrv_driver_register(odpdrv_driver_param_t *param); /** +* Sets the device driver data, i.e. the driver data which should be attached to +* the device. +* After a driver is bound to a device, this driver will need to keep +* data attached to this device. This data is, of course, driver dependent. +* +* @param dev: the device to which data should be attached. +* @param data Pointer to whatever thre driver want to keep attached to the +* device +*/ +void odpdrv_device_set_data(odpdrv_device_t dev, void *data); + +/** +* Gets the device driver data, i.e. the driver data which should be attached to +* the device. +* Retrieve the pointer which was set with odpdrv_device_set_data() +* @param dev: the device from which the driver data should be retrieved. +* @return the driver data pointer (as set by odpdrv_device_set_data()) or NULL. +*/ +void *odpdrv_device_get_data(odpdrv_device_t dev); + +/** * Print (ODP_DBG) the driver interface status (debug). * * @return 0 on success, less than zero on error (inconsistency detected) From patchwork Wed Mar 22 14:48:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95756 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp233039obz; Wed, 22 Mar 2017 07:10:18 -0700 (PDT) X-Received: by 10.107.169.201 with SMTP id f70mr44138626ioj.161.1490191818301; Wed, 22 Mar 2017 07:10:18 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id q188si1866126itg.94.2017.03.22.07.10.17; Wed, 22 Mar 2017 07:10:18 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id BD522642E5; Wed, 22 Mar 2017 14:10:17 +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, URIBL_BLOCKED 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 45DB664328; Wed, 22 Mar 2017 13:51:55 +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 64F6864329; Wed, 22 Mar 2017 13:51:52 +0000 (UTC) Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by lists.linaro.org (Postfix) with ESMTPS id A5820642BB for ; Wed, 22 Mar 2017 13:49:38 +0000 (UTC) Received: by mail-wm0-f48.google.com with SMTP id n11so37225695wma.1 for ; Wed, 22 Mar 2017 06:49:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cx/j/kGStKI8qAMd3PYMgFmP7jHqPWZ1aK6MoSUI254=; b=VTc+HIOnAMifnzd5HumaCbaUkFKro0Uzo2uRh3C0Mj2W/rQR2nuesF0CvqAYE3qb66 /cKLmjB7hBLgeokMK3W9PkJZrra7+MAYF4BHtzCFX75hGt7F1LzblPCj7tAYJ2eMDvj5 Ob5US0O+NAkVMYbkf1BGz1npX2BYS0Zy1lH53lL27rZIV+388gZquJbdSTJ2zcVnnqxn yrdWEdy9yq6ExVa/RI8EbMBgy1VIANgqfJwFeLsGbLYFGKPqIZ1XtTihrkOVACcxgjGs ZHNFc2FWj469+FzPOPlHl2kQfQ2JvG8i4LF8NveCt9KsVIbXXbC4YsU9m36HDmGG2ooX fhsQ== X-Gm-Message-State: AFeK/H1M3d98PvCx12PGMQLNsmJ+T9jX4IDTPquhkIR/8EKMZ1QRHmTcpBbUzRIyA7Nfx7cNGDIaotNo X-Received: by 10.25.167.203 with SMTP id q194mr11285924lfe.138.1490190577481; Wed, 22 Mar 2017 06:49:37 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:36 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:29 +0100 Message-Id: <1490194110-40168-23-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 22/23] linux-gen: adding functions to attach driver's data to the device 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 functions to set/retrieve driver's data to/from a bound device. Signed-off-by: Christophe Milard --- platform/linux-generic/drv_driver.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) -- 2.7.4 diff --git a/platform/linux-generic/drv_driver.c b/platform/linux-generic/drv_driver.c index ea92457..70bf318 100644 --- a/platform/linux-generic/drv_driver.c +++ b/platform/linux-generic/drv_driver.c @@ -70,6 +70,7 @@ struct _odpdrv_device_s { odpdrv_device_param_t param; _odpdrv_driver_t *driver; /* driver for the device (if bound), or NULL*/ _odpdrv_devio_t *devio; /* devio used for device (if bound), or NULL*/ + void *driver_data; /* anything that the driver need to attach. */ void (*enumr_destroy_callback)(void *enum_dev);/*dev destroy callback */ struct _odpdrv_device_s *next; } _odpdrv_device_s; @@ -395,6 +396,7 @@ odpdrv_device_t odpdrv_device_create(odpdrv_device_param_t *param) dev->enumr_destroy_callback = NULL; dev->driver = NULL; dev->devio = NULL; + dev->driver_data = NULL; dev_list_write_lock(); dev->next = device_lst.head; device_lst.head = dev; @@ -852,6 +854,22 @@ void _odpdrv_driver_probe_drv_items(void) probe_all(); } +void odpdrv_device_set_data(odpdrv_device_t dev, void *data) +{ + _odpdrv_device_t *_dev; + + _dev = get_device(dev); + _dev->driver_data = data; +} + +void *odpdrv_device_get_data(odpdrv_device_t dev) +{ + _odpdrv_device_t *_dev; + + _dev = get_device(dev); + return _dev->driver_data; +} + int odpdrv_print_all(void) { _odpdrv_enumr_class_t *enumr_c; From patchwork Wed Mar 22 14:48:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95762 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp233577obz; Wed, 22 Mar 2017 07:11:26 -0700 (PDT) X-Received: by 10.36.228.13 with SMTP id o13mr8177765ith.56.1490191886637; Wed, 22 Mar 2017 07:11:26 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id h189si1872542ioe.162.2017.03.22.07.11.26; Wed, 22 Mar 2017 07:11:26 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 27D6E6402F; Wed, 22 Mar 2017 14:11:26 +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, URIBL_BLOCKED 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 887BE64329; Wed, 22 Mar 2017 13:51:57 +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 3309C6432B; Wed, 22 Mar 2017 13:51:54 +0000 (UTC) Received: from mail-wm0-f42.google.com (mail-wm0-f42.google.com [74.125.82.42]) by lists.linaro.org (Postfix) with ESMTPS id A2D3A642EA for ; Wed, 22 Mar 2017 13:49:39 +0000 (UTC) Received: by mail-wm0-f42.google.com with SMTP id u132so37328155wmg.0 for ; Wed, 22 Mar 2017 06:49:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PmTBLqNCMxssz7l/rxypa6bsYVKdW35AVxY98mBplM0=; b=VyGatihNhnRUOkSL4Y+9CCFSC1SfagXnG9FJvoe79FXAH0AU97nBvmKdWdWTl3CxIG WnBOXStC0Yt9mIEFo+Y0mjM8y3PvQpQoXj4O7Kdh4HabBDA3ATGGqvWIaFYiX5c1HUsV hHWZPf32jfeAmGTKfBr9HxxfgLpf3HtOl39jrRyRQ4eA7V5q7K1ZB+zMk2olVSyUI87/ 6M2Cs5kLj/XL2Y6x7gWIB61oVILshk3B5zLbJl1jOHFebOAqcKwClnPz3zx9rJFG+szt /E2B5hf7ecghSrqUqnzVbVcvFftwgHKvCeQvi1aX5ouCOmxVzWxd0TDou1EiC3tktYxP vdQg== X-Gm-Message-State: AFeK/H3CFWy10YGbjtn26tggJhoHF9fAgxWkqnXiCxbCc1qI0kRARRR/J8AtAYfxZYEhTx0FmfY= X-Received: by 10.25.160.1 with SMTP id j1mr12048693lfe.44.1490190578481; Wed, 22 Mar 2017 06:49:38 -0700 (PDT) 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 l23sm522305lfk.27.2017.03.22.06.49.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:37 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:30 +0100 Message-Id: <1490194110-40168-24-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 23/23] test: drv: test for setting and retrieving driver's data 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" trivial tests for function odpdrv_device_set_data() and odpdrv_device_get_data(). Signed-off-by: Christophe Milard --- test/common_plat/validation/drv/drvdriver/drvdriver_driver.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.7.4 diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_driver.c b/test/common_plat/validation/drv/drvdriver/drvdriver_driver.c index d90aa56..edcb0f4 100644 --- a/test/common_plat/validation/drv/drvdriver/drvdriver_driver.c +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_driver.c @@ -380,6 +380,8 @@ static int driver1_probe(odpdrv_device_t dev, odpdrv_devio_t devio, int idx) if (dev == E1_devs[i]) { driver1_probed_index |= (1 << i); dev_found = 1; + /* just set dev index as driver data */ + odpdrv_device_set_data(dev, (void *)(uintptr_t)i); } } CU_ASSERT(dev_found); @@ -430,6 +432,7 @@ static int driver1_unbind(odpdrv_device_t dev, void (*callback)(odpdrv_device_t dev), uint32_t flags) { + CU_ASSERT(E1_devs[(uintptr_t)odpdrv_device_get_data(dev)] == dev); CU_ASSERT(dev != ODPDRV_DEVICE_INVALID); CU_ASSERT(flags == ODPDRV_DRV_UNBIND_IMMEDIATE); callback(dev);