From patchwork Wed Nov 15 15:00:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 118977 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp4420259qgn; Wed, 15 Nov 2017 07:01:33 -0800 (PST) X-Google-Smtp-Source: AGs4zMaI+IIibYhw2TzN9ziUQy34b7WyEqQrnoQgBq+BCxE+adcTA6I6OsdjDhaYqqYQCZwmB10I X-Received: by 10.233.232.213 with SMTP id a204mr25559485qkg.264.1510758092910; Wed, 15 Nov 2017 07:01:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510758092; cv=none; d=google.com; s=arc-20160816; b=xYC1hZOQKE9hsTnjA1nOY2PQfuGKOT4LcjST2c+HaESyka9c/wZw045oUkezVlRShw lNXr2xCS+BPR3Z7uSB5yXXB8FVYGANN1E+8RXel7abnHGd/KZJknw4Yo3TNxPR30iS3r GzWviKhPOiaXxubq/kYQ8iuV25gaJftXSlQIJDQjGnSsrkpfU0vr+PkaolO1pXGazNak iFQIOQmM1RQffVCYiq14Lnvjm84Ki2vMt2liCY15bqGnABUyLMdeO+lJLQ1vgfEVMAPP JGsAMXwLDU01KIjEXaakhKyPGJpVakwAhh6amPxJwvGDFNy+EzFaET8KvZUxws2JVz/1 Ok5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=R1ETIOslRmCK2/NUXn7EYSf8iu/VVt7DQfGhnkegoi0=; b=eqbbo6+9kxXN/drx0Je/ZaqvzowcF+i3NnjnqIlZgomtFMcYmwlZXDJ+kzMlpZqQLw a/V6XTjNLYCMSf8W08qyllGka1J04YVcW73UpN/Qrz5icGB/gYNBxJLknl3He0N/Emv8 NCgeZVUJIiS2aQXL0ZTYcVOEFFha3ihvBQmmjpdKJpezzoClaqMKLSdM618u2/wGVI7z kBtRs2rwVFEi70aqcN5z8AIR55wADknuZh3y44HHO+tiXuzlyAkMROS7+pohLzc5Rrm2 uSaD2gY73KSl2sdYhoKeVPWdvcZoBLi0eerjdSxk03etN0JmcqlE6JWSw/d6GX98gT2J xnQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id v20si12060737qta.458.2017.11.15.07.01.32; Wed, 15 Nov 2017 07:01:32 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 57D3E606A4; Wed, 15 Nov 2017 15:01:32 +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,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 3ECDE60723; Wed, 15 Nov 2017 15:00:40 +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 D7614606A1; Wed, 15 Nov 2017 15:00:19 +0000 (UTC) Received: from forward15o.cmail.yandex.net (forward15o.cmail.yandex.net [37.9.109.212]) by lists.linaro.org (Postfix) with ESMTPS id BFF55606A4 for ; Wed, 15 Nov 2017 15:00:12 +0000 (UTC) Received: from mxback18j.mail.yandex.net (mxback18j.mail.yandex.net [IPv6:2a02:6b8:0:1619::94]) by forward15o.cmail.yandex.net (Yandex) with ESMTP id BD5A42A100 for ; Wed, 15 Nov 2017 18:00:10 +0300 (MSK) Received: from smtp1p.mail.yandex.net (smtp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:6]) by mxback18j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id Lkkmk3Hc0Z-0AS82brp; Wed, 15 Nov 2017 18:00:10 +0300 Received: by smtp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id IdPkqKtE1s-09r46rpE; Wed, 15 Nov 2017 18:00:09 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Wed, 15 Nov 2017 18:00:08 +0300 Message-Id: <1510758008-29501-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510758008-29501-1-git-send-email-odpbot@yandex.ru> References: <1510758008-29501-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 295 Subject: [lng-odp] [PATCH 2.0 v2 1/1] driver.h: add parameter when registering enumerators 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" From: Josep Puigdemont If a class registers more than once the same enumerator, as it could happen for different PCI platforms, we need to provide information for the enumerator probe function to know where to act. This information shall be provided in the odpdrv_enumr_param_t structure as a void pointer, which will be passed to the probe() function of the enumerator. Signed-off-by: Josep Puigdemont --- /** Email created from pull request 295 (joseppc:add-enumr-param) ** https://github.com/Linaro/odp/pull/295 ** Patch: https://github.com/Linaro/odp/pull/295.patch ** Base sha: 6cd43041e55bd73a02ca202f835e590b3ad5c354 ** Merge commit sha: e195f03663fc92c61a9a989ccab693720393dccc **/ example/ddf_ifs/ddf_ifs_enumr_dpdk.c | 4 +- example/ddf_ifs/ddf_ifs_enumr_generic.c | 4 +- include/odp/drv/spec/driver.h | 10 ++++- platform/linux-generic/drv_driver.c | 4 +- test/validation/drv/drvdriver/drvdriver_device.c | 11 ++--- test/validation/drv/drvdriver/drvdriver_driver.c | 18 ++++---- test/validation/drv/drvdriver/drvdriver_enumr.c | 52 ++++++++++++++---------- 7 files changed, 61 insertions(+), 42 deletions(-) diff --git a/example/ddf_ifs/ddf_ifs_enumr_dpdk.c b/example/ddf_ifs/ddf_ifs_enumr_dpdk.c index 782f7b745..258865dfc 100644 --- a/example/ddf_ifs/ddf_ifs_enumr_dpdk.c +++ b/example/ddf_ifs/ddf_ifs_enumr_dpdk.c @@ -17,7 +17,7 @@ static odpdrv_enumr_t dpdk_enumr; static odpdrv_device_t dpdk_dev[DDF_DPDK_DEV_MAX]; static int dpdk_dev_cnt; -static int dpdk_enumr_probe(void) +static int dpdk_enumr_probe(void *data __attribute__((__unused__))) { int dpdk_dev_cnt_detected = TEST_DPDK_DEV_CNT; /* detected with dpdk APIs*/ @@ -46,7 +46,7 @@ static int dpdk_enumr_probe(void) return 0; } -static int dpdk_enumr_remove(void) +static int dpdk_enumr_remove(void *data __attribute__((__unused__))) { printf("%s()\n", __func__); return 0; diff --git a/example/ddf_ifs/ddf_ifs_enumr_generic.c b/example/ddf_ifs/ddf_ifs_enumr_generic.c index f5e1a2cbb..5cfa1d9ae 100644 --- a/example/ddf_ifs/ddf_ifs_enumr_generic.c +++ b/example/ddf_ifs/ddf_ifs_enumr_generic.c @@ -11,13 +11,13 @@ static odpdrv_enumr_t gen_enumr; -static int gen_enumr_probe(void) +static int gen_enumr_probe(void *data __attribute__((__unused__))) { printf("%s() - no devices found\n", __func__); return 0; } -static int gen_enumr_remove(void) +static int gen_enumr_remove(void *data __attribute__((__unused__))) { printf("%s()\n", __func__); return 0; diff --git a/include/odp/drv/spec/driver.h b/include/odp/drv/spec/driver.h index 224baf4fe..51baedb5a 100644 --- a/include/odp/drv/spec/driver.h +++ b/include/odp/drv/spec/driver.h @@ -205,12 +205,12 @@ struct odpdrv_enumr_param_t { * Called by ODP when it is ready for device creation/deletion * returns an negative value on error or 0 on success. */ - int (*probe)(void); + int (*probe)(void *enumr_data); /** Remove function: * destroy all enumerated devices and release all resources */ - int (*remove)(void); + int (*remove)(void *enumr_data); /** Register event notifier function for hotplug events: * register_notifier(fcnt,event_mask) registers fcnt as a callback when @@ -218,6 +218,12 @@ struct odpdrv_enumr_param_t { */ int (*register_notifier)(void (*event_handler) (uint64_t event), int64_t event_mask); + + /** Class dependent part + * This part is allocated by the enumerator class for use by the + * enumerator, it is passed as a parameter to the probe function. + */ + void *enumr_data; }; /* The following events are supported by enumerators */ diff --git a/platform/linux-generic/drv_driver.c b/platform/linux-generic/drv_driver.c index ecf75ab9d..cfb42f119 100644 --- a/platform/linux-generic/drv_driver.c +++ b/platform/linux-generic/drv_driver.c @@ -851,7 +851,7 @@ void _odpdrv_driver_probe_drv_items(void) enumr = enumr_lst.head; while (enumr) { if (!enumr->probed) { - enumr->param.probe(); + enumr->param.probe(enumr->param.enumr_data); enumr->probed = 1; } enumr = enumr->next; @@ -1055,7 +1055,7 @@ int _odpdrv_driver_term_global(void) while (enumr_lst.head) { enumr = enumr_lst.head; if (enumr->param.remove) { /* run remove callback, if any */ - if (enumr->param.remove()) + if (enumr->param.remove(enumr->param.enumr_data)) ODP_ERR("Enumerator (API %s) removal failed.\n", enumr->param.api_name); } diff --git a/test/validation/drv/drvdriver/drvdriver_device.c b/test/validation/drv/drvdriver/drvdriver_device.c index d010026ff..eaf7dcfa5 100644 --- a/test/validation/drv/drvdriver/drvdriver_device.c +++ b/test/validation/drv/drvdriver/drvdriver_device.c @@ -22,8 +22,8 @@ typedef struct dev_enumr_data_t { /* enumerator data for registered devices */ #define NB_DEVICES 5 /* forward declaration */ -static int enumr1_probe(void); -static int enumr1_remove(void); +static int enumr1_probe(void *); +static int enumr1_remove(void *); static int enumr_class1_probe(void); static int enumr_class1_remove(void); @@ -68,7 +68,8 @@ static odpdrv_enumr_t enumr1_register(void) .api_version = 1, .probe = enumr1_probe, .remove = enumr1_remove, - .register_notifier = NULL + .register_notifier = NULL, + .enumr_data = NULL }; enumr1 = odpdrv_enumr_register(¶m); @@ -76,7 +77,7 @@ static odpdrv_enumr_t enumr1_register(void) } /*enumerator probe functions, just making sure they have been run: */ -static int enumr1_probe(void) +static int enumr1_probe(void *enumr_data __attribute__((__unused__))) { int dev; odpdrv_shm_t shm; @@ -128,7 +129,7 @@ static void enumr5_device_destroy_terminate(void *priv_data) } /*enumerator remove functions, to remove the enumerated devices: */ -static int enumr1_remove(void) +static int enumr1_remove(void *data __attribute__((__unused__))) { odpdrv_device_t *my_devices; odpdrv_device_t *dev; diff --git a/test/validation/drv/drvdriver/drvdriver_driver.c b/test/validation/drv/drvdriver/drvdriver_driver.c index edcb0f43f..eeb424cc7 100644 --- a/test/validation/drv/drvdriver/drvdriver_driver.c +++ b/test/validation/drv/drvdriver/drvdriver_driver.c @@ -56,10 +56,10 @@ 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 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); @@ -167,8 +167,10 @@ static int enumr_class2_probe(void) return 0; } +#define UNUSED __attribute__((__unused__)) + /*enumerator probe functions, creating four devices each: */ -static int enumr1_probe(void) +static int enumr1_probe(void *enumr_data UNUSED) { int dev; @@ -189,7 +191,7 @@ static int enumr1_probe(void) return 0; } -static int enumr2_probe(void) +static int enumr2_probe(void *enumr_data UNUSED) { int dev; @@ -211,7 +213,7 @@ static int enumr2_probe(void) } /*enumerator remove functions, to remove the enumerated devices: */ -static int enumr1_remove(void) +static int enumr1_remove(void *data UNUSED) { odpdrv_device_t *my_devices; odpdrv_device_t *dev; @@ -231,7 +233,7 @@ static int enumr1_remove(void) return 0; } -static int enumr2_remove(void) +static int enumr2_remove(void *data UNUSED) { odpdrv_device_t *my_devices; odpdrv_device_t *dev; diff --git a/test/validation/drv/drvdriver/drvdriver_enumr.c b/test/validation/drv/drvdriver/drvdriver_enumr.c index 38aac3d03..04b6dcdbb 100644 --- a/test/validation/drv/drvdriver/drvdriver_enumr.c +++ b/test/validation/drv/drvdriver/drvdriver_enumr.c @@ -20,15 +20,15 @@ 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_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 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); @@ -68,6 +68,8 @@ static int tests_global_term(void) return 0; } +#define ENUMR1_PROBE_DATA ((void *)0x1000) + /*enumerator register functions */ static odpdrv_enumr_t enumr1_register(void) { @@ -77,7 +79,8 @@ static odpdrv_enumr_t enumr1_register(void) .api_version = 1, .probe = enumr1_probe, .remove = enumr1_remove, - .register_notifier = NULL + .register_notifier = NULL, + .enumr_data = ENUMR1_PROBE_DATA }; return odpdrv_enumr_register(¶m); @@ -91,7 +94,8 @@ static odpdrv_enumr_t enumr2_register(void) .api_version = 1, .probe = enumr2_probe, .remove = enumr2_remove, - .register_notifier = NULL + .register_notifier = NULL, + .enumr_data = NULL }; return odpdrv_enumr_register(¶m); @@ -105,7 +109,8 @@ static odpdrv_enumr_t enumr3_register(void) .api_version = 1, .probe = enumr3_probe, .remove = enumr3_remove, - .register_notifier = NULL + .register_notifier = NULL, + .enumr_data = NULL }; return odpdrv_enumr_register(¶m); @@ -119,7 +124,8 @@ static odpdrv_enumr_t enumr4_register(void) .api_version = 1, .probe = enumr4_probe, .remove = enumr4_remove, - .register_notifier = NULL + .register_notifier = NULL, + .enumr_data = NULL }; return odpdrv_enumr_register(¶m); @@ -133,57 +139,61 @@ static odpdrv_enumr_t enumr_invalid_register(void) .api_version = 1, .probe = enumr4_probe, .remove = enumr4_remove, - .register_notifier = NULL + .register_notifier = NULL, + .enumr_data = NULL }; return odpdrv_enumr_register(¶m); } /*enumerator probe functions, just making sure they have been run: */ -static int enumr1_probe(void) +static int enumr1_probe(void *data) { + CU_ASSERT(data == ENUMR1_PROBE_DATA); enumr1_probed = 1; return 0; } -static int enumr2_probe(void) +#define UNUSED __attribute__((__unused__)) + +static int enumr2_probe(void *data UNUSED) { enumr2_probed = 1; return 0; } -static int enumr3_probe(void) +static int enumr3_probe(void *data UNUSED) { enumr3_probed = 1; return 0; } -static int enumr4_probe(void) +static int enumr4_probe(void *data UNUSED) { enumr4_probed = 1; return 0; } /*enumerator remove functions, just making sure they have been run: */ -static int enumr1_remove(void) +static int enumr1_remove(void *data UNUSED) { enumr1_probed = -1; return 0; } -static int enumr2_remove(void) +static int enumr2_remove(void *data UNUSED) { enumr2_probed = -1; return 0; } -static int enumr3_remove(void) +static int enumr3_remove(void *data UNUSED) { enumr3_probed = -1; return 0; } -static int enumr4_remove(void) +static int enumr4_remove(void *data UNUSED) { enumr4_probed = -1; return 0;