From patchwork Wed Feb 22 12:55:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 94308 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp876292qgi; Wed, 22 Feb 2017 03:58:12 -0800 (PST) X-Received: by 10.36.227.198 with SMTP id d189mr1449993ith.70.1487764692223; Wed, 22 Feb 2017 03:58:12 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id r192si1281442ith.83.2017.02.22.03.58.11; Wed, 22 Feb 2017 03:58:12 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id C363860DB8; Wed, 22 Feb 2017 11:58:11 +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 3B06F60DED; Wed, 22 Feb 2017 11:57: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 6279B60D7B; Wed, 22 Feb 2017 11:57:21 +0000 (UTC) Received: from mail-lf0-f47.google.com (mail-lf0-f47.google.com [209.85.215.47]) by lists.linaro.org (Postfix) with ESMTPS id 0969C60D7B for ; Wed, 22 Feb 2017 11:57:20 +0000 (UTC) Received: by mail-lf0-f47.google.com with SMTP id z127so131662lfa.2 for ; Wed, 22 Feb 2017 03:57:19 -0800 (PST) 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=JLHqMopNdxItYCSnP7wD16uRbGw03SUWYuYzlA4p9y8yAeA9+BFnJCb35gxqXLhtdf ALFFLOZzc63fXoz1lxmaPaapPQ14u84QYSavN1PQYurbSQHQyFH9IofMa38+w50PtePl 0Q+6v4vZcjva2+haZCTegT6QpSo61mFWUlrOvPTdodA9J9m0Z4kGPKpX/FegTHaMK6GD JHipi1xy83dNltWDtwQDDrR4KDPD+0J3hyoXJLhTHDkkcl/JvTIA+QeNuA0JUaoSzg1S easY6EId5x/Td2M6s1U5+45KMNviyqLSmn/GHCuMW2jRZ9vQPu9Q/dHhUPVpzVjHtKeR VLWA== X-Gm-Message-State: AMke39kcUMmD9dugS/ZeT9b5pNe7oSTSdYfqvstDVaiWrVmqtEscc1UAkJ43eqY9akRKj8qMhEA= X-Received: by 10.46.77.17 with SMTP id a17mr7471907ljb.2.1487764638848; Wed, 22 Feb 2017 03:57:18 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id v21sm7035187ljd.9.2017.02.22.03.57.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 03:57:18 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, sachin.saxena@linaro.com, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Feb 2017 13:55:44 +0100 Message-Id: <1487768164-43184-2-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> References: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCH 01/21] 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 Feb 22 12:55:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 94309 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp876484qgi; Wed, 22 Feb 2017 03:58:49 -0800 (PST) X-Received: by 10.55.3.7 with SMTP id 7mr17072561qkd.299.1487764729799; Wed, 22 Feb 2017 03:58:49 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id x14si693713qtf.266.2017.02.22.03.58.49; Wed, 22 Feb 2017 03:58:49 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 7999962DAB; Wed, 22 Feb 2017 11:58:49 +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 4FA2E60E48; Wed, 22 Feb 2017 11:57:36 +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 862F460C71; Wed, 22 Feb 2017 11:57:23 +0000 (UTC) Received: from mail-lf0-f53.google.com (mail-lf0-f53.google.com [209.85.215.53]) by lists.linaro.org (Postfix) with ESMTPS id 5E9EB60C71 for ; Wed, 22 Feb 2017 11:57:21 +0000 (UTC) Received: by mail-lf0-f53.google.com with SMTP id g134so160040lfe.1 for ; Wed, 22 Feb 2017 03:57:21 -0800 (PST) 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=MwGXZeYloXmfgqWEAmjUWNfirBMMDV3vElJiR/27vRs=; b=HIqj5ardrZ2uveaRKlmvujlsCzBq9yAthUjeVddcGyQH6sTKYw+CJUoT2qAOfStfZO xG+qe+oa4BIt0b24zVZLPkBS6V946gouUJ8mVYsV3XKs7ZXp9D64EnqVjyMd/azTfuen CY1m8U8KPXXeD5tAfskiYFvx3MZdk+Koh94yempGM9thFBydw4OF4D7/wHWWUf/jU8jQ a4eyqxdL2sHKJZcAcP39XNsmCEsT3i7KkphTNs11JNV18srDsgfvfhMPKEryLHsYB8A4 NvLvcucMTwHFyj4nvI30RzZwOYxN3lMPES+pD5bg7/cpFlm1sPnRbtrpaGfi6qilXYld ENFA== X-Gm-Message-State: AMke39n8fiZcu8Vx0Qsbl8BAZUurencfi8/6XrF1zNmorv8byrvPEWJGfj4R6KIMlhvL6HbcmqA= X-Received: by 10.46.21.89 with SMTP id 25mr9135213ljv.19.1487764639978; Wed, 22 Feb 2017 03:57:19 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id v21sm7035187ljd.9.2017.02.22.03.57.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 03:57:19 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, sachin.saxena@linaro.com, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Feb 2017 13:55:45 +0100 Message-Id: <1487768164-43184-3-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> References: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCH 02/21] 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 66ff53d..b7d1b1a 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 Feb 22 12:55:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 94310 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp876812qgi; Wed, 22 Feb 2017 03:59:57 -0800 (PST) X-Received: by 10.55.165.202 with SMTP id o193mr21021726qke.284.1487764797252; Wed, 22 Feb 2017 03:59:57 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id h41si692744qtc.301.2017.02.22.03.59.57; Wed, 22 Feb 2017 03:59:57 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id E4BCA63544; Wed, 22 Feb 2017 11:59:56 +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 A5B2162B88; Wed, 22 Feb 2017 11:57:41 +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 7813760E02; Wed, 22 Feb 2017 11:57:27 +0000 (UTC) Received: from mail-lf0-f44.google.com (mail-lf0-f44.google.com [209.85.215.44]) by lists.linaro.org (Postfix) with ESMTPS id 5666660D7B for ; Wed, 22 Feb 2017 11:57:22 +0000 (UTC) Received: by mail-lf0-f44.google.com with SMTP id l12so177390lfe.0 for ; Wed, 22 Feb 2017 03:57:22 -0800 (PST) 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=bqKrJbWwb/Ojyj9PL35fRKjdM0yDlUDaO89suBctuuE=; b=bnnDdFz1yEmMa5Z45UtSQTx+ePds9Mn1x4v+fIPeASj9sjIUUdvV8CG5QmIDTfhmes uVYSdZSDjyw2QaODqiCjCfljJMEEqajL1tr9XJ52QlKxo4kqwGriGFUxQnIXn1cR2iB9 NrpX5fbrPz0EFLjiRCKMVo3kHQ95PJyFhS2UOR6Kx8FfE+AADrXP4lEomyZKUcocM8HM lW+KDowxu5BrAXOugXORqYzimtQT1jE+T99zUnZpJdN8OPmSEtuqMv74q2eQrjER0jCG l+xI+5eoEF4lTQt+c2iK29C2eUHdBpESDFPuEE9a3359qkipO5DgQYRyiIop+Es6nZ1m siCQ== X-Gm-Message-State: AMke39neOgrc9UDODBQrfbUGnevmq0SzEvjdsT8KtX5ClNojmuIkDLwF/zNHzCCoDBqUJtcowZ8= X-Received: by 10.46.1.222 with SMTP id f91mr8873902lji.115.1487764641117; Wed, 22 Feb 2017 03:57:21 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id v21sm7035187ljd.9.2017.02.22.03.57.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 03:57:20 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, sachin.saxena@linaro.com, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Feb 2017 13:55:46 +0100 Message-Id: <1487768164-43184-4-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> References: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCH 03/21] 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..62b99ea --- /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 __attribute__ ((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 __attribute__ ((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 ran: */ +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 ran: */ +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 terminaison 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 Feb 22 12:55:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 94311 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp922801obz; Wed, 22 Feb 2017 04:01:11 -0800 (PST) X-Received: by 10.36.26.9 with SMTP id 9mr1674517iti.25.1487764871349; Wed, 22 Feb 2017 04:01:11 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id n186si1303337ith.39.2017.02.22.04.01.10; Wed, 22 Feb 2017 04:01:11 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id C9337608A7; Wed, 22 Feb 2017 12:01: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=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 0E7E162C62; Wed, 22 Feb 2017 11:57:46 +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 DD1FE60E18; Wed, 22 Feb 2017 11:57:28 +0000 (UTC) Received: from mail-lf0-f46.google.com (mail-lf0-f46.google.com [209.85.215.46]) by lists.linaro.org (Postfix) with ESMTPS id 7F5A260D92 for ; Wed, 22 Feb 2017 11:57:23 +0000 (UTC) Received: by mail-lf0-f46.google.com with SMTP id g134so160455lfe.1 for ; Wed, 22 Feb 2017 03:57:23 -0800 (PST) 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=K8o8wsNsU0IYMdGOl0P6Ja7Q9niUB9T0F7Nhnf7ZFXg=; b=Yj3rW0GUIFkKYeanLuwaI8q14KkxZ9tcTt73CfCWmYySBXStIuDlXMALhnPyyAgBeE Ao4gmHMzncFPxnHmAL4xU2RbykbtNSe1m8tLBucPJRXD19bANkJK9M5TKsmH0s9IVHRK 7WrpksqAprfJnbLoOKAhjmla3yJJ/O+tizDxZZVF690BcE1pj77EFAaDQDQYM7/2Vc9q dThcSGz2ZhSWpEolZRnJgzu9x/kq9od+W8qqCi4y6watTnOMJBUm+JWHSuG37EHQ6i1t zkLnWgUMrH0mSIOh0uFdpkPEJrGuu/Xuaplzaw3pGSDvhnCXWKt0SjnRYJLZCoi6v6eD doZQ== X-Gm-Message-State: AMke39nafvhXcXVj01c6jj0tu30MEV62yHiroxoJsThBnsrqOErgHrV7XFNI2ntuM8Lq9EQB2CQ= X-Received: by 10.25.166.131 with SMTP id p125mr7782467lfe.142.1487764642334; Wed, 22 Feb 2017 03:57:22 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id v21sm7035187ljd.9.2017.02.22.03.57.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 03:57:21 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, sachin.saxena@linaro.com, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Feb 2017 13:55:47 +0100 Message-Id: <1487768164-43184-5-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> References: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCH 04/21] 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 | 135 +++++++++++++++++++++++++++++++++++- 1 file changed, 132 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/platform/linux-generic/drv_driver.c b/platform/linux-generic/drv_driver.c index 50956a7..ee0a75c 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,29 @@ 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); +} odpdrv_enumr_class_t odpdrv_enumr_class_register(odpdrv_enumr_class_param_t *param) @@ -133,10 +171,53 @@ 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; + + /* 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 ((_odpdrv_enumr_class_t *)(void *)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 porbed 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_INVALID; + return (odpdrv_enumr_t)enumr; } odpdrv_device_t odpdrv_device_create(odpdrv_device_param_t *param) @@ -174,6 +255,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 +268,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 +304,22 @@ 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 = (_odpdrv_enumr_class_t *) + (void *)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 +335,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 +354,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 Feb 22 12:55:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 94314 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp924045obz; Wed, 22 Feb 2017 04:03:40 -0800 (PST) X-Received: by 10.202.173.195 with SMTP id w186mr2793779oie.18.1487765020384; Wed, 22 Feb 2017 04:03:40 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id o68si1622636itb.110.2017.02.22.04.03.40; Wed, 22 Feb 2017 04:03:40 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id DDB7260DBD; Wed, 22 Feb 2017 12:03:39 +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 4F9E262D1B; Wed, 22 Feb 2017 11:58:23 +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 296EC60DC9; Wed, 22 Feb 2017 11:58:10 +0000 (UTC) Received: from mail-lf0-f51.google.com (mail-lf0-f51.google.com [209.85.215.51]) by lists.linaro.org (Postfix) with ESMTPS id A86E760DBD for ; Wed, 22 Feb 2017 11:57:24 +0000 (UTC) Received: by mail-lf0-f51.google.com with SMTP id g134so160702lfe.1 for ; Wed, 22 Feb 2017 03:57:24 -0800 (PST) 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=mr/2wl6K+1soefW6WTvbHFYENIvPOmCOQDGdOXpZ8+I=; b=snPxS4hL6euVMrfVEtO2kDB9RA9u5uFU7HiL/hQr4hCGrjNfg5H6+4bxh8uIp9E2FC Gel3xQKF1+TIzr/2Hemb748whpvBKbjAP9sD1MBgVn+yzNaqduE4Xk/5P++yW+hG+9XS GA+RTpzoE4ucoz1vUoVuwmKCwieWTVVs5ID8D0/wcbrZTNOYfH/VfiQ0hNWcr2XzYt+F 2McBMnrjvCfYOvKS5TwlUpxwlS/LbAkDK0oPEJwbcWQWqNKT58z832Ixo/t5pYXbLzy1 pgfVu4DS31EWI8y1tWLfFfCnVGExglMKBZVib0tnLFD7oWCjW/P/8S4VABSl5+VKF1TH xS1w== X-Gm-Message-State: AMke39mGqObhGRG0B8Emj8uFf7TmpUABHVYuzraN2usSUXDzjSEm4VrLX8a03J9Hj241b3R3jXA= X-Received: by 10.46.74.26 with SMTP id x26mr8477103lja.96.1487764643452; Wed, 22 Feb 2017 03:57:23 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id v21sm7035187ljd.9.2017.02.22.03.57.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 03:57:22 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, sachin.saxena@linaro.com, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Feb 2017 13:55:48 +0100 Message-Id: <1487768164-43184-6-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> References: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCH 05/21] 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..cf844cf --- /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 ran: */ +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 ran: */ +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 __attribute__ ((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 __attribute__ ((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 ran: */ +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 terminaison 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 Feb 22 12:55:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 94312 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp923395obz; Wed, 22 Feb 2017 04:02:24 -0800 (PST) X-Received: by 10.36.36.142 with SMTP id f136mr1779679ita.0.1487764944085; Wed, 22 Feb 2017 04:02:24 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id g73si1288913ioi.199.2017.02.22.04.02.23; Wed, 22 Feb 2017 04:02:24 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 22E5562D87; Wed, 22 Feb 2017 12:02:23 +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 9565760DB8; Wed, 22 Feb 2017 11:58:13 +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 4E1E460DB8; Wed, 22 Feb 2017 11:58:08 +0000 (UTC) Received: from mail-lf0-f52.google.com (mail-lf0-f52.google.com [209.85.215.52]) by lists.linaro.org (Postfix) with ESMTPS id A513460DC1 for ; Wed, 22 Feb 2017 11:57:25 +0000 (UTC) Received: by mail-lf0-f52.google.com with SMTP id b80so116358lfe.3 for ; Wed, 22 Feb 2017 03:57:25 -0800 (PST) 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=xnXKr/o79ZittsYwAXg1WZx9rTgl/slb+jc9hYyDKkg=; b=GGreKPXp/SfMDehlcbTxPxA49hV/H1CpW6h/ComZyPpvhYbEE0Pv2FsMCl7BjRdTMx ko8DvTvJREtgmY8UC+GdWOFHhP+eXl3Mhf2qASuQwvKAZSFN5nTwjl3pj6dq5Hk8IoVn vSHj3rPnHibn1zRHhKPHcRRgc6qxFDrP67o9nePwB4+2PEz+sV9kaLvn2pW+5ZGlUrE7 ndmrYlKeR69QYBMIlzEB8xB6KefwieyOiJ0KkwqnbvWfpQJbv6dU89SIZXoQ7Aegy/9B 3cevnH1denYsuupOBROHLNnKoP/zQOaq71mAp2T1pLDVf8L2whwM3H45FU8cUZ2z0kqH nJDA== X-Gm-Message-State: AMke39kZPaxffsjzMZlHtjsrA24IB3ZdTMpwWuOV9E4Ccm1Ue7x6ATyxdEYVs8f6xTcl7zhBFlk= X-Received: by 10.25.227.79 with SMTP id c15mr8599481lfk.167.1487764644535; Wed, 22 Feb 2017 03:57:24 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id v21sm7035187ljd.9.2017.02.22.03.57.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 03:57:23 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, sachin.saxena@linaro.com, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Feb 2017 13:55:49 +0100 Message-Id: <1487768164-43184-7-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> References: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCH 06/21] 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..a978d12 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 gracefuly, 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 gracefuly). + * 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 Feb 22 12:55:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 94313 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp923702obz; Wed, 22 Feb 2017 04:02:59 -0800 (PST) X-Received: by 10.107.162.194 with SMTP id l185mr26878528ioe.184.1487764979508; Wed, 22 Feb 2017 04:02:59 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id k201si1291029itk.102.2017.02.22.04.02.59; Wed, 22 Feb 2017 04:02:59 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id E38A360DB8; Wed, 22 Feb 2017 12:02:58 +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 F2E0A60DD0; Wed, 22 Feb 2017 11:58:18 +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 86A4C62C40; Wed, 22 Feb 2017 11:58:09 +0000 (UTC) Received: from mail-lf0-f42.google.com (mail-lf0-f42.google.com [209.85.215.42]) by lists.linaro.org (Postfix) with ESMTPS id CF6E560DC9 for ; Wed, 22 Feb 2017 11:57:26 +0000 (UTC) Received: by mail-lf0-f42.google.com with SMTP id l12so178299lfe.0 for ; Wed, 22 Feb 2017 03:57:26 -0800 (PST) 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=RZQph+aq+oP/G2/ytBUD95R4LwgvjhaV2qKJz5A5M5k=; b=Co1GSjKtgeM+xb8ihXIdPduxB7qLXHijAU+BQ/j/hkxDzIIAgkMNeA7Z17EanOxgs/ 9Gg404Lk4CXGxX40vrcvw6EukVbXJngb1oGT960/839jaBKSxrfcUDB8+ROwzvHOCMqz 6+eYFSljqXn2IUDnzEp+0ZogeCydWBADM0H3JqyCHBKntpFDOhI61W+kGAYETgYxwzyx 8X2Zk/JdxEhUSRDOxD+3OQtOJXLbjiqWX6EkAmU+XBBi9G+LaspX4QEAEWkeBAxqdqGc 5HQRxjvkdLHfMYNjRO/HT5nBvefgZvU+JiKyoq1v5PKTQLM2RLE+AqmsVdhgckIWWPA9 F/LQ== X-Gm-Message-State: AMke39lFLsdyQxsFnt21iqM/LeOGLoDYgOKyTVvvwQcpds8VTVj5afFj6eyBucnqpulh9obza0s= X-Received: by 10.25.193.21 with SMTP id r21mr8956625lff.103.1487764645703; Wed, 22 Feb 2017 03:57:25 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id v21sm7035187ljd.9.2017.02.22.03.57.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 03:57:25 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, sachin.saxena@linaro.com, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Feb 2017 13:55:50 +0100 Message-Id: <1487768164-43184-8-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> References: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCH 07/21] 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 a978d12..21a5fe1 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 ee0a75c..f8844f5 100644 --- a/platform/linux-generic/drv_driver.c +++ b/platform/linux-generic/drv_driver.c @@ -227,10 +227,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 Feb 22 12:55:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 94316 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp925012obz; Wed, 22 Feb 2017 04:05:47 -0800 (PST) X-Received: by 10.36.89.17 with SMTP id p17mr1701238itb.43.1487765147216; Wed, 22 Feb 2017 04:05:47 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id x194si1638498itb.77.2017.02.22.04.05.46; Wed, 22 Feb 2017 04:05:47 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id C230860E02; Wed, 22 Feb 2017 12:05:46 +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 7788562D97; Wed, 22 Feb 2017 11:58: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 60FBB62D98; Wed, 22 Feb 2017 11:58:36 +0000 (UTC) Received: from mail-lf0-f47.google.com (mail-lf0-f47.google.com [209.85.215.47]) by lists.linaro.org (Postfix) with ESMTPS id 9960560D7B for ; Wed, 22 Feb 2017 11:57:28 +0000 (UTC) Received: by mail-lf0-f47.google.com with SMTP id z127so133250lfa.2 for ; Wed, 22 Feb 2017 03:57:28 -0800 (PST) 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=0lKkvD5hlsUPbBHnOH71ve9pcEMKoPqsV2nI99KL06k=; b=k5PwNVn80FL667kGKzlK/MnHE3bWz8uejCIiusHytybTGX3fSKAs6QlPbEVbkXnyOG VudFMlH2KDW7rPE2mEOE23/O5f1caJzJoPM6oqZN8xb4gKNIYP6Eijag0TkYXHfKX+6l PhkXwA+haOePxMSYaXwyDMjzTsiq3lu/F/DoRVCp35wvshO4y+poFc/JJvgXX2Mg1YNM SzcxU2krmGRSHUFBTWKxF9qA1hOWMO8XtPF9vlzDEZUwgSX/xvpbhPp+0qYthjQIj7cs 9VuSrN95jffaMQCvIQWLIrXn5MWyGbpFgzN6zhA4GqLXL4IaazYppG4L83XsDXEjdgnP eziA== X-Gm-Message-State: AMke39m15aMUFL46ZnaLIMK+q0p7b1p1bbXVA0khsBcGVhccoc4XRNCyh7CedghburKDe81t0TE= X-Received: by 10.46.71.71 with SMTP id u68mr7434301lja.99.1487764646770; Wed, 22 Feb 2017 03:57:26 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id v21sm7035187ljd.9.2017.02.22.03.57.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 03:57:26 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, sachin.saxena@linaro.com, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Feb 2017 13:55:51 +0100 Message-Id: <1487768164-43184-9-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> References: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCH 08/21] 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 | 172 ++++++++++++++++++++++++++++++++++-- 1 file changed, 164 insertions(+), 8 deletions(-) -- 2.7.4 diff --git a/platform/linux-generic/drv_driver.c b/platform/linux-generic/drv_driver.c index f8844f5..48a90a2 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,6 +125,30 @@ 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); +} + odpdrv_enumr_class_t odpdrv_enumr_class_register(odpdrv_enumr_class_param_t *param) { @@ -222,24 +263,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 = (_odpdrv_device_t *)(void *)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 = (_odpdrv_device_t *)(void *)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.", @@ -295,6 +431,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) @@ -327,6 +464,24 @@ 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 = (_odpdrv_enumr_t *)(void *)dev->param.enumerator; + enumr_c = (_odpdrv_enumr_class_t *) + (void *)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; } @@ -343,6 +498,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 Feb 22 12:55:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 94315 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp924743obz; Wed, 22 Feb 2017 04:05:12 -0800 (PST) X-Received: by 10.36.207.136 with SMTP id y130mr1743402itf.56.1487765112083; Wed, 22 Feb 2017 04:05:12 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id d75si1301904ioj.178.2017.02.22.04.05.11; Wed, 22 Feb 2017 04:05:12 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 9EAB362C40; Wed, 22 Feb 2017 12:05:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 22E3660D92; Wed, 22 Feb 2017 11:58:42 +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 BC5D862D9A; Wed, 22 Feb 2017 11:58:34 +0000 (UTC) Received: from mail-lf0-f54.google.com (mail-lf0-f54.google.com [209.85.215.54]) by lists.linaro.org (Postfix) with ESMTPS id 0438F60D92 for ; Wed, 22 Feb 2017 11:57:29 +0000 (UTC) Received: by mail-lf0-f54.google.com with SMTP id g134so161536lfe.1 for ; Wed, 22 Feb 2017 03:57:28 -0800 (PST) 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=zYiVPErxFgykoqvy9DZmcr9SZmR/9XPJvasY4pgm6K4=; b=c5jAOkZwvQnDsCx7i4qEISq8eFvE4Ug/QZzaCID1mVo6GWeqvOh8AT4csK4Y+Xbu8D lr0kXVS0mwoA3e8bsU7y/VQc5L69SVae+l5q6adNhv15IE2AUmZ6orYAxrVQb/OJlOKP t75UWFYf7REB/IG08Ty0O+j5nFFT6KevDa2AZOQmVCsHvjKpGVKNCHcmo85QlrUn2fc/ YwPBkuh8a/c5moOgv5qlDOPDqsMbYJT8MWUDUT/aZiMZlI4fEf22c8XIt33fMF1+LWQr WhhKPZULx256YWOGTqVixQXvKv3pNuLE/EYp7xzI4OOjCzg9JV/QBh6tsoFwPtZ7yW+G KHKQ== X-Gm-Message-State: AMke39l4PZHrTnxc2EHxXK6ES95wxjflifxKiG8Vcr8JmmeGfCGCjy7g4M7wuUgrma1o4J3H0xA= X-Received: by 10.25.21.214 with SMTP id 83mr1200950lfv.66.1487764647776; Wed, 22 Feb 2017 03:57:27 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id v21sm7035187ljd.9.2017.02.22.03.57.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 03:57:27 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, sachin.saxena@linaro.com, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Feb 2017 13:55:52 +0100 Message-Id: <1487768164-43184-10-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> References: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCH 09/21] 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 21a5fe1..abac138 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 Feb 22 12:55:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 94317 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp925410obz; Wed, 22 Feb 2017 04:06:35 -0800 (PST) X-Received: by 10.157.22.193 with SMTP id s1mr17137034ots.17.1487765195324; Wed, 22 Feb 2017 04:06:35 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id f13si1312710iod.99.2017.02.22.04.06.34; Wed, 22 Feb 2017 04:06:35 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id C569F60F22; Wed, 22 Feb 2017 12:06:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 CCDCE62D9F; Wed, 22 Feb 2017 11:58: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 718EA60D92; Wed, 22 Feb 2017 11:58:36 +0000 (UTC) Received: from mail-lf0-f49.google.com (mail-lf0-f49.google.com [209.85.215.49]) by lists.linaro.org (Postfix) with ESMTPS id 6F40660DFB for ; Wed, 22 Feb 2017 11:57:30 +0000 (UTC) Received: by mail-lf0-f49.google.com with SMTP id l12so178949lfe.0 for ; Wed, 22 Feb 2017 03:57:30 -0800 (PST) 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=cw46YJLijzTOeGkmlz2ZqsfY9k/IC6JETKZTgL8n/hs=; b=SPBj7KP1KwTeFxxQKb/ioKBz8WRPgg3so4MNvRp9PWI5cI8n1Cu6+Ii2RuQ4ZPbp9/ gOnmy68Ayb23Pll/eIKfEjESm7h3zQZ2SrX1NMZ7y8dRIfL7sYzlv/bHCjCA6HrBQBtz xdODs6qzpP0CGHZU3MH9A2uRiK/xiU95FEJ9OUilTezGdP01uwXppPinvcCKasQoHtXh IyIDSvtHV9U9jeyGgzSFuKL0d+VsYdYft4tNw9B73FsR85EhmcIg+32mj2bUsgVyQJts 1RiY7zx1EEJMqEHwqRdJo8ZqmrHHpiBT/V8lKGGD4AqHb1ZzSKZQKmROep+z3Lfivo/b asqg== X-Gm-Message-State: AMke39mkC3VdwWpeED6jJtCfmurN8IEkXM2P5z/ZuT5wMQkmsVi9OoaBJQrMmsYY6O/sfMYWy9c= X-Received: by 10.25.165.201 with SMTP id o192mr7212322lfe.84.1487764649057; Wed, 22 Feb 2017 03:57:29 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id v21sm7035187ljd.9.2017.02.22.03.57.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 03:57:28 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, sachin.saxena@linaro.com, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Feb 2017 13:55:53 +0100 Message-Id: <1487768164-43184-11-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> References: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCH 10/21] 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 48a90a2..517a3c6 100644 --- a/platform/linux-generic/drv_driver.c +++ b/platform/linux-generic/drv_driver.c @@ -376,6 +376,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 Feb 22 12:55:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 94318 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp925678obz; Wed, 22 Feb 2017 04:07:08 -0800 (PST) X-Received: by 10.36.207.212 with SMTP id y203mr1610105itf.63.1487765228121; Wed, 22 Feb 2017 04:07:08 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id c9si1652422itf.40.2017.02.22.04.07.07; Wed, 22 Feb 2017 04:07:08 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id AF0A560E48; Wed, 22 Feb 2017 12:07:07 +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 1688C60E3E; Wed, 22 Feb 2017 11:58:52 +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 BFD3C60D92; Wed, 22 Feb 2017 11:58:40 +0000 (UTC) Received: from mail-lf0-f43.google.com (mail-lf0-f43.google.com [209.85.215.43]) by lists.linaro.org (Postfix) with ESMTPS id 6139960E02 for ; Wed, 22 Feb 2017 11:57:31 +0000 (UTC) Received: by mail-lf0-f43.google.com with SMTP id l12so179190lfe.0 for ; Wed, 22 Feb 2017 03:57:31 -0800 (PST) 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=4Q6vhuFmeNxP9B970fLKWF754PwEcmTXkvFQgxNTKNs=; b=uFLu6+nbE849lxJmsZgzPIp7aTBeMFBdFeyBkehMIp8NS2DIyX+/EF4DxX4j+SDFfy 8tl/6zTC1iR77P/T6F5nkvAis2yofAJtg8K67aqhJxiJVlhutJuM2Rqy4gG4zH5YxzQX 6rBiSSXsp7rnkgb9hYnXQg0tGXoN0pyIfb0cgf0STBgqBVJVeX6iPENVasJkenK5Ku3d xpdMar6hVcMcyWTHrSYHMAVV1AF5+syqrKr3gM7KIw3DJPFMtDTX2osUDgHH/FXfbiQU I2WcWlUFg8iDpgQOORFT/9EEet9QtXn6ZW4O72TmtjyXGMD83KwWG2Aevon8Hm+TftUW ivTA== X-Gm-Message-State: AMke39lQ7eBGdhXVnVLAUDryXyvS7LJWLwey1FGaRyLLSOaAQQTsrsrZJLxKswjoCBwZZqDplhU= X-Received: by 10.25.87.196 with SMTP id l187mr9411668lfb.143.1487764650213; Wed, 22 Feb 2017 03:57:30 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id v21sm7035187ljd.9.2017.02.22.03.57.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 03:57:29 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, sachin.saxena@linaro.com, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Feb 2017 13:55:54 +0100 Message-Id: <1487768164-43184-12-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> References: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCH 11/21] 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..9254e17 --- /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 ran: */ +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 __attribute__ ((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 ran: */ +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 Feb 22 12:55:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 94319 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp926081obz; Wed, 22 Feb 2017 04:08:04 -0800 (PST) X-Received: by 10.200.35.225 with SMTP id r30mr14614807qtr.183.1487765283987; Wed, 22 Feb 2017 04:08:03 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id t190si627875qkf.315.2017.02.22.04.08.03; Wed, 22 Feb 2017 04:08:03 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 9803560F0D; Wed, 22 Feb 2017 12:08:03 +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 74FDA62DB3; Wed, 22 Feb 2017 11:58:56 +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 3420A60E23; Wed, 22 Feb 2017 11:58:44 +0000 (UTC) Received: from mail-lf0-f43.google.com (mail-lf0-f43.google.com [209.85.215.43]) by lists.linaro.org (Postfix) with ESMTPS id 4E2D460E23 for ; Wed, 22 Feb 2017 11:57:32 +0000 (UTC) Received: by mail-lf0-f43.google.com with SMTP id l12so179385lfe.0 for ; Wed, 22 Feb 2017 03:57:32 -0800 (PST) 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=kAmx38f64/5mgAlc9j+0zeLEhnJ+YUxs6mAnCNqO/oA=; b=eIoBzAw4RWF1tWvdTv3RkP1hnky46Bs9BJw4vSbQhAO0zmczxiTHNae0Q6PW/bq6LX rz9JGhY6fUTnJjdYGSX6EP5xnpff8Q8DItBItOI3r27E6Ior1h8IC3BBu+EBByi+IhS+ r3sWBgdls8YPQs2jMEaE7nmnYZzk3VuqMaG0YccqQiuJ1rgjNpNeTiqXd7zNeqJgz+ZM wP7VWYkfHLL9NeeY9+qh7dwE+y6SJk6iEszJb0aOJix83vBTbvTkLFv/UKykMlOfwh+H OKFATUW6BsV2pk5+Az5muBMf5hQ9IVqZMGxVenRBvE433JiMEdlLD5mWDy6lsVqwJ1nd H66g== X-Gm-Message-State: AMke39kzdTmlin7gdGRaATDHmaIHjOyjmSj3kYQiDCwjMIdPuiParJe/XBwNVolyLAAa6d9nNaI= X-Received: by 10.46.21.18 with SMTP id s18mr8315986ljd.73.1487764651215; Wed, 22 Feb 2017 03:57:31 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id v21sm7035187ljd.9.2017.02.22.03.57.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 03:57:30 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, sachin.saxena@linaro.com, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Feb 2017 13:55:55 +0100 Message-Id: <1487768164-43184-13-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> References: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCH 12/21] 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 abac138..0b62c1b 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 Feb 22 12:55:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 94320 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp926578obz; Wed, 22 Feb 2017 04:09:12 -0800 (PST) X-Received: by 10.55.71.210 with SMTP id u201mr8160842qka.90.1487765351956; Wed, 22 Feb 2017 04:09:11 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id b125si485280qke.226.2017.02.22.04.09.11; Wed, 22 Feb 2017 04:09:11 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 9C26962D18; Wed, 22 Feb 2017 12:09:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 0D57960E15; Wed, 22 Feb 2017 11:59:30 +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 2E52E62FDA; Wed, 22 Feb 2017 11:59:25 +0000 (UTC) Received: from mail-lf0-f41.google.com (mail-lf0-f41.google.com [209.85.215.41]) by lists.linaro.org (Postfix) with ESMTPS id 8E50F60E15 for ; Wed, 22 Feb 2017 11:57:33 +0000 (UTC) Received: by mail-lf0-f41.google.com with SMTP id g134so162438lfe.1 for ; Wed, 22 Feb 2017 03:57:33 -0800 (PST) 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=7d0KCN5tj5i3b5VJB5WwACQiexviaYvXvupJGf96iPw=; b=AAHpLd2n/Vdm1gk6qkhR/D6Yr9MIhXc42ULp5ejvH0QbRCZWahJ2x4jClDj5nAvTaF 1D/iKSIxcBZCpBMWFIS+vDgndCyPslGlXDxqXfyhrNSf0TjUQThjMjVDXJYxjiAEgXtQ /KFp1GCs8iWFkZ65xltHrA689jAfMtgQAHwsfelt3qO6WNYgvwVL3SDsqQeWabRk6U3D 4rYggnBc/oA91VpO6lEiL3828xUruGikUKT/2k6BeoqTygjez3FQPv+ApLhd2fv0sevu Kmt3BOGKXw6SlHhISC+ilySuXM7+lygUpU5yXH1ZAqdKOJ2eRHGLn6KRn+4pSR+xuVGY swAw== X-Gm-Message-State: AMke39kuW5w69PSc6sVHfAc0TO26HlmyZkW1QidjlSoDXDg0K+7nPHS87gb8u6zvjvSIi72QPJU= X-Received: by 10.46.7.82 with SMTP id i18mr6387633ljd.0.1487764652328; Wed, 22 Feb 2017 03:57:32 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id v21sm7035187ljd.9.2017.02.22.03.57.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 03:57:31 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, sachin.saxena@linaro.com, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Feb 2017 13:55:56 +0100 Message-Id: <1487768164-43184-14-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> References: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCH 13/21] 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 517a3c6..eb0dc48 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); +} + odpdrv_enumr_class_t odpdrv_enumr_class_register(odpdrv_enumr_class_param_t *param) { @@ -415,10 +454,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) @@ -469,6 +563,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) @@ -519,6 +614,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; } @@ -536,6 +646,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(); @@ -553,12 +664,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 Feb 22 12:55:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 94321 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp926852obz; Wed, 22 Feb 2017 04:09:51 -0800 (PST) X-Received: by 10.200.41.13 with SMTP id y13mr28046200qty.154.1487765391476; Wed, 22 Feb 2017 04:09:51 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id z201si713017qkz.244.2017.02.22.04.09.51; Wed, 22 Feb 2017 04:09:51 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 1A51060D92; Wed, 22 Feb 2017 12:09: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=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 57FB960F51; Wed, 22 Feb 2017 11:59: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 778F961063; Wed, 22 Feb 2017 11:59:25 +0000 (UTC) Received: from mail-lf0-f49.google.com (mail-lf0-f49.google.com [209.85.215.49]) by lists.linaro.org (Postfix) with ESMTPS id 778C260E18 for ; Wed, 22 Feb 2017 11:57:35 +0000 (UTC) Received: by mail-lf0-f49.google.com with SMTP id b80so118320lfe.3 for ; Wed, 22 Feb 2017 03:57:35 -0800 (PST) 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=oL8ZSbiudAmtxOqMrdU01XDgLHKv8kFe/JgcYbSr3sk=; b=BlrFopW4fVMP1iReFFjeAVUZ4OQ/MU/IU07105S8sSGMPoSfWjhKGbcJdND7Mcd5yg ocS6lytuZBXg9+AmFyHtTKUsRZ//ta+obmf3hcYyr6hTfR6wTRPh9TWCpu1nIRxh+U3e cDD5VFA1V01AtIKLwwqwky9us19xYgYkX0JvYvetZ2h/BME9niQXYCCCusaLOQJ0irJV MHFn6NTUacU6B8kAAhvTqPnNvJf5V8sg8u05FBirpsxXD3wJAffDTH1JHWSRmnxmHbX0 jEDYqw/GDzVUs7Z0er/sjtR2McGf3rZY7JoeNo0fWLpDNxdmeJT2TGiNadmuRIhUGSC4 P32w== X-Gm-Message-State: AMke39koAFRs3AcAdr48WLyKs9pgFvYO8lGO4Ozdf0Syuf1p5YTtDJuFFBmMXaTCxYZ2GdkiDT0= X-Received: by 10.46.84.84 with SMTP id y20mr7600574ljd.126.1487764654420; Wed, 22 Feb 2017 03:57:34 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id v21sm7035187ljd.9.2017.02.22.03.57.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 03:57:33 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, sachin.saxena@linaro.com, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Feb 2017 13:55:58 +0100 Message-Id: <1487768164-43184-16-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> References: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCH 15/21] 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 enumeratos...) is called before the driver is to be removed, i.e. after all devices have been been unboud 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 0b62c1b..221a6ce 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 Feb 22 12:56:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 94323 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp927111obz; Wed, 22 Feb 2017 04:10:25 -0800 (PST) X-Received: by 10.200.50.112 with SMTP id y45mr9596504qta.75.1487765425479; Wed, 22 Feb 2017 04:10:25 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id t75si706692qkt.325.2017.02.22.04.10.25; Wed, 22 Feb 2017 04:10:25 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 1728E60F4D; Wed, 22 Feb 2017 12:10: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 8B51962FDA; Wed, 22 Feb 2017 11:59:38 +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 3C48F61063; Wed, 22 Feb 2017 11:59:30 +0000 (UTC) Received: from mail-lf0-f51.google.com (mail-lf0-f51.google.com [209.85.215.51]) by lists.linaro.org (Postfix) with ESMTPS id 16A8C60F51 for ; Wed, 22 Feb 2017 11:57:38 +0000 (UTC) Received: by mail-lf0-f51.google.com with SMTP id l12so180552lfe.0 for ; Wed, 22 Feb 2017 03:57:38 -0800 (PST) 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=YVPoNfGF9XcoEGtA6tifIA3SriA46pN0j92rdHTUoTA=; b=GqwcX6KlBxUla5/y7kQ342HTVg+KSu8X920bQ1bUDsbSkkzR8/4og32YByARz5uKAq Ohw1WLQ4ZfBmRrDABvYYZJNSuBAQiuFX80Tv+O5cRJGBWqJxbW8+y7VkJ0knabnmMT4n x/EEBbCLtBTmxQnBKlKCFMyWu+aFSU9OGJQA4fI/MlkYHs43PyEQvHF2+vhSEEES20xs efDnTvcb6OIA6dkX2k7B9eYTA/WM/8dJj3DdUtsI7H1ZRJMXD5cBOUj1KoUyW4t/Lo76 LGOgVK5/EMD6PQX+k5lyRQakKVtwRRl1DBsf7JlymSOzeKBrTz1pytgqRQXg5B3mGn16 NKeg== X-Gm-Message-State: AMke39m7BPFiCDBSembFr0Xw0BVKmTy8Mt+gYOJiV5CjLkIPm/qvVWOxv09m4SzXvGL8OBZDjFQ= X-Received: by 10.46.33.75 with SMTP id h72mr8438789ljh.37.1487764656685; Wed, 22 Feb 2017 03:57:36 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id v21sm7035187ljd.9.2017.02.22.03.57.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 03:57:36 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, sachin.saxena@linaro.com, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Feb 2017 13:56:00 +0100 Message-Id: <1487768164-43184-18-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> References: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCH 17/21] 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 | 348 ++++++++++++++++++++++++++++++++++-- 1 file changed, 335 insertions(+), 13 deletions(-) -- 2.7.4 diff --git a/platform/linux-generic/drv_driver.c b/platform/linux-generic/drv_driver.c index eb0dc48..0148fc3 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_spinlock_t probelock; /* to avoid concurrent probe on the 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); +} + odpdrv_enumr_class_t odpdrv_enumr_class_register(odpdrv_enumr_class_param_t *param) { @@ -331,6 +378,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; @@ -384,19 +433,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) @@ -517,10 +564,238 @@ 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(); - return ODPDRV_DRIVER_INVALID; + /* 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_spinlock_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 = (_odpdrv_enumr_t *) + (void *)dev->param.enumerator; + enumr_c = (_odpdrv_enumr_class_t *) + (void *)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_spinlock_lock(&drv->probelock); + if (drv->param.probe((odpdrv_device_t)dev, + (odpdrv_devio_t)devio, i) == 0) { + /* the driver accepts this device */ + odp_spinlock_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_spinlock_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)(void *)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_spinlock_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_spinlock_unlock(&drv->probelock); + return -1; + } + + /* unbind succeeded */ + dev->driver = NULL; + dev->devio = NULL; + odp_spinlock_unlock(&drv->probelock); + return 0; +} + +/* try to find a driver for the given device, trying all possible registered + * drivers against it: + */ +static int probe_device(_odpdrv_device_t *dev) +{ + _odpdrv_driver_t *driver; + + /* print the list of registered drivers: */ + driver_list_read_lock(); + driver = driver_lst.head; + while (driver) { + probe_device_driver(dev, driver); + driver = driver->next; + } + driver_list_read_unlock(); + + return 0; +} + +/* try to find a driver for all the registered devices, trying all possible + * drivers-devices combinaison + */ +static int probe_all(void) +{ + _odpdrv_device_t *dev; + + dev_list_read_lock(); + dev = device_lst.head; + while (dev) { + probe_device(dev); + dev = dev->next; + } + dev_list_read_unlock(); + + return 0; } /* the following function is called each time probing is needed, i.e. @@ -556,6 +831,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) @@ -564,6 +842,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) @@ -605,11 +884,16 @@ int odpdrv_print_all(void) enumr_c = (_odpdrv_enumr_class_t *) (void *)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(); @@ -629,6 +913,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; } @@ -647,6 +942,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(); @@ -667,10 +963,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 Feb 22 12:56:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 94324 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp927663obz; Wed, 22 Feb 2017 04:11:44 -0800 (PST) X-Received: by 10.55.189.197 with SMTP id n188mr1442812qkf.252.1487765503987; Wed, 22 Feb 2017 04:11:43 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id u13si718672qki.218.2017.02.22.04.11.43; Wed, 22 Feb 2017 04:11:43 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id A007560E3E; Wed, 22 Feb 2017 12:11:43 +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 D77926352A; Wed, 22 Feb 2017 11:59: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 E5F1D60F22; Wed, 22 Feb 2017 11:59:32 +0000 (UTC) Received: from mail-lf0-f43.google.com (mail-lf0-f43.google.com [209.85.215.43]) by lists.linaro.org (Postfix) with ESMTPS id 5155D60F22 for ; Wed, 22 Feb 2017 11:57:39 +0000 (UTC) Received: by mail-lf0-f43.google.com with SMTP id l12so180877lfe.0 for ; Wed, 22 Feb 2017 03:57:39 -0800 (PST) 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=8MFxnA7nHDYByuwXD1+dIRvUcttaWwgP8BUD3dEugfc=; b=fR44Mvs9x4jXJOhT25g7NOMcWpyd2uOWqqKpa96o51oq5wuBHD8zGB1h8VD7fREUil fZyg33ZIM574zWSbXvHStccF5KV8oVTZuR1YJ0741f7Av0hUNkspym0Ty1hEYJUzQx78 BhOXeos+i3aWoGI7fQO8BYsQWy1kcFJfIMamOmjoxVGqOwS/FbMXT1jle0BZNeBSACcN rw1qIW2yrWJk14j43lLnKdpDr8uv7L0Iqz89oJpJEfURc+I23wrImhh1oPq4Gpc/byxd /xzow73XCHJF+8QGyPQ3oGTG4ChjakOhsez3JbjJxOtMqYEs05KoDc4tnZi7kbbKW5bT NoeQ== X-Gm-Message-State: AMke39mr9ovJNLALSNLGkjvaNmoV2ePHzt4xDIZwn2+SalPRNtRrYuGL8Sqj2YC//5Mg2rwEDV8= X-Received: by 10.25.207.81 with SMTP id f78mr8941852lfg.4.1487764658024; Wed, 22 Feb 2017 03:57:38 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id v21sm7035187ljd.9.2017.02.22.03.57.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 03:57:37 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, sachin.saxena@linaro.com, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Feb 2017 13:56:01 +0100 Message-Id: <1487768164-43184-19-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> References: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCH 18/21] 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..c293b06 --- /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 __attribute__ ((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 __attribute__ ((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 __attribute__ ((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 __attribute__ ((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 __attribute__ ((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 __attribute__ ((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 __attribute__ ((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 __attribute__ ((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 __attribute__ ((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 __attribute__ ((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 Feb 22 12:56:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 94325 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp929006obz; Wed, 22 Feb 2017 04:15:14 -0800 (PST) X-Received: by 10.107.11.92 with SMTP id v89mr23092750ioi.138.1487765714349; Wed, 22 Feb 2017 04:15:14 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 15si1316023iou.239.2017.02.22.04.15.14; Wed, 22 Feb 2017 04:15:14 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id D718B61063; Wed, 22 Feb 2017 12:15:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 00EC1634C6; Wed, 22 Feb 2017 12:00:21 +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 B7CCD634C6; Wed, 22 Feb 2017 12:00:13 +0000 (UTC) Received: from mail-lf0-f50.google.com (mail-lf0-f50.google.com [209.85.215.50]) by lists.linaro.org (Postfix) with ESMTPS id 3582860F2D for ; Wed, 22 Feb 2017 11:57:40 +0000 (UTC) Received: by mail-lf0-f50.google.com with SMTP id b80so119257lfe.3 for ; Wed, 22 Feb 2017 03:57:40 -0800 (PST) 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=pr7W00SiH2ALmVtst+2LCUpk2TP2yuZYDqMtSUOtEOo=; b=HUbkNcyNexz9KL5ReHG4+4AZEHyxQ+lEUb3pAsvV16IKbIR6h6rZT2GXS0ZT+Yn8Ps RJyisxEmIsGjgrxudguSWItTnE7k8cLFISpOxfLG15WE+T/S/XMr5It2xPjvwGxC1Ipv 8uHjW/jxD/boICMsGi+/z9xkN4Yrz5imIqExq387T6nbhs2KHxD7oYN0JFK9zYTgmXhu Kg5h1whS1FjeNqk/nOkmhVU5zD3K1VNF0iX/7rTJvRkYPRQXxjioeTk3AR79xmcyOy1U NytM4h0BdrfwJ61ht3674rTxblkRP8o5h7uXCXWATIWbkw3mqMDuTOCnX0MXlRSPdus+ LBxg== X-Gm-Message-State: AMke39nkK79a0pIhbIV6BjNuVE5bZ+KNUwehaCKaKUJzgSc/XTR0UCGW16PZxRHslmqt1so2tS0= X-Received: by 10.25.210.82 with SMTP id j79mr6443535lfg.96.1487764659048; Wed, 22 Feb 2017 03:57:39 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id v21sm7035187ljd.9.2017.02.22.03.57.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 03:57:38 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, sachin.saxena@linaro.com, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Feb 2017 13:56:02 +0100 Message-Id: <1487768164-43184-20-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> References: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCH 19/21] 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 b3c9b76..50ed3a0 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 Feb 22 12:56:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 94326 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp929033obz; Wed, 22 Feb 2017 04:15:18 -0800 (PST) X-Received: by 10.107.6.210 with SMTP id f79mr27165975ioi.140.1487765717933; Wed, 22 Feb 2017 04:15:17 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id n133si1349790ion.1.2017.02.22.04.15.17; Wed, 22 Feb 2017 04:15:17 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 6F86A62C92; Wed, 22 Feb 2017 12:15: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 3E86E6356F; Wed, 22 Feb 2017 12:00:23 +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 1C06E62CEF; Wed, 22 Feb 2017 12:00:16 +0000 (UTC) Received: from mail-lf0-f53.google.com (mail-lf0-f53.google.com [209.85.215.53]) by lists.linaro.org (Postfix) with ESMTPS id 3A7A962C3D for ; Wed, 22 Feb 2017 11:57:42 +0000 (UTC) Received: by mail-lf0-f53.google.com with SMTP id g134so164196lfe.1 for ; Wed, 22 Feb 2017 03:57:42 -0800 (PST) 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=R27JvWnk31V7essmqdZs49X6/7DMOersngUSdpyvrQY=; b=NLJqRa93hLkw/LHBen6dVq7Hq2QYYraHeYP57t8zpXU8U1GkZ+xXZSo4r+SM//oHAx bAqKDpjFUpZE4YI5CC3MUhvzaWGUPbZgzqAUk9kTzQHVocJ5pBh3REF01Q04nYCRBwzs WZbMCtdcqMZVaPCRmEGPYbZTOI1qU0aZC7MZ0t4M87YY7kv0gWRwuxTyjAD7j/3nfD6w hpsHzC+HU7G0LO5bFX3IPDl7MJqBain0KHJydLQXDoeS+B+74GNY6A9+nuwVPjHI010w ifOZDupHnhqsPTzOXGVh+l6n+agnkPBEIEuGcaWGi3wVUf9jpaL6yieoEwV72VAggVAE QdPw== X-Gm-Message-State: AMke39k6bHPFq3Hs+1XtBUOILK64Ht3FpcZDi0ClQUhHU72UfdQHGY3kuV9FOh+7wuI+cB+lcsE= X-Received: by 10.25.217.79 with SMTP id q76mr8420279lfg.178.1487764661147; Wed, 22 Feb 2017 03:57:41 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id v21sm7035187ljd.9.2017.02.22.03.57.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 03:57:40 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, sachin.saxena@linaro.com, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Feb 2017 13:56:04 +0100 Message-Id: <1487768164-43184-22-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> References: <1487768164-43184-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCH 21/21] 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 c293b06..4143acd 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);