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)