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) {