Received: by 10.223.185.116 with SMTP id b49csp3395044wrg; Tue, 13 Feb 2018 01:45:06 -0800 (PST) X-Google-Smtp-Source: AH8x227K8loTEbq6oXsEV1+tmrAkJnp8fLdocJwhbeNVRcRWYI+P3d1msJfX6b0Pf982FUl5wHU7 X-Received: by 10.98.204.132 with SMTP id j4mr637691pfk.161.1518515105955; Tue, 13 Feb 2018 01:45:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518515105; cv=none; d=google.com; s=arc-20160816; b=R4NcPj2ipYsnTkomdWW+w7u+9WNw17GX24P+v1bitPEx+1Uqgtp/uGW0vUPGILr+bi HRKORjva8d2SRP+aENSHjj5rYR3qVaPG43OPrB7CQk5z20irrF0zeG/zwsB2dv2jVUzS PQ0C+FgahzAsP4BOhi8dLBKkTwiDkVoYCaqgkuOAPMgCcz8z79ozq5QDie7ylSP0ZYYj Ft3pJwuhvewV5eWN/RTx195MaSzWLaa1y3yvFlItP4xbM4dQQgjqzB3HTGBBS71EzyOY IDNpRs7IkBh7SO9U0LmYLsiz4uJmY8WSySN9HwRosSg7IiecunMIhq4u0AL7pbfA7GCY HQWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=qAYrhk+j/LZHwtd2GIlP0CD2YN2f3hbLvk5tLOJV1gs=; b=SdRUz178kIlSPTVWPKFYNvdTFPkfniViPFlOQf4K86xq8sX+SPAMW+6b7xPUMJmIp0 81zbfdbiEKyZe35C/Qr4FvdZZAiJY17/gXG0B3A2X5Xti+vGsfJePOeRmGE5jVDB3E4L zjkLhLwx2lPyWDgJLv1EU2lRvkahq81ovRqm310+fL5hK3JcWCytIj4mG1CdeSzJ7/AE ctJncVE6TdhOndTz82qRXbtmvyt2pq+O+is08UvhdXZozPE5XWijJihwXCj9qtBg+e4w btTpkTvF781HZBG3nHHA0UORoE+HMcBK07Y/w7CpskXR7CdIDwtILfZ66/VG4yptQq2A 9zlg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q9-v6si539420plk.730.2018.02.13.01.44.51; Tue, 13 Feb 2018 01:45:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934638AbeBMJnL (ORCPT + 99 others); Tue, 13 Feb 2018 04:43:11 -0500 Received: from mga03.intel.com ([134.134.136.65]:27123 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934692AbeBMJf2 (ORCPT ); Tue, 13 Feb 2018 04:35:28 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Feb 2018 01:35:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,507,1511856000"; d="scan'208";a="26889516" Received: from hao-dev.bj.intel.com ([10.238.157.61]) by FMSMGA003.fm.intel.com with ESMTP; 13 Feb 2018 01:35:25 -0800 From: Wu Hao To: atull@kernel.org, mdf@kernel.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-api@vger.kernel.org, luwei.kang@intel.com, yi.z.zhang@intel.com, hao.wu@intel.com, Tim Whisonant , Enno Luebbers , Shiva Rao , Christopher Rauer , Xiao Guangrong Subject: [PATCH v4 06/24] fpga: dfl: adds fpga_cdev_find_port Date: Tue, 13 Feb 2018 17:24:35 +0800 Message-Id: <1518513893-4719-7-git-send-email-hao.wu@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518513893-4719-1-git-send-email-hao.wu@intel.com> References: <1518513893-4719-1-git-send-email-hao.wu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For feature devices, we need a method to find the port dedicated to the device. This patch adds a function fpga_cdev_find_port for this purpose. e.g FPGA Management Engine (FME) Partial Reconfiguration sub feature, it uses this function to find dedicated port on the device for PR function implementation. Signed-off-by: Tim Whisonant Signed-off-by: Enno Luebbers Signed-off-by: Shiva Rao Signed-off-by: Christopher Rauer Signed-off-by: Xiao Guangrong Signed-off-by: Wu Hao --- v3: s/fpga_for_each_port/fpga_cdev_find_port/ move fpga_cdev_find_port to fpga-dfl module. v4: improve description in commit message. add comments to remind user to put_device after use this function. --- drivers/fpga/dfl.c | 34 ++++++++++++++++++++++++++++++++++ drivers/fpga/dfl.h | 20 ++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c index dcfe5ab..38dc819 100644 --- a/drivers/fpga/dfl.c +++ b/drivers/fpga/dfl.c @@ -783,6 +783,40 @@ void fpga_remove_feature_devs(struct fpga_cdev *cdev) } EXPORT_SYMBOL_GPL(fpga_remove_feature_devs); +/** + * __fpga_cdev_find_port - find a port under given container device + * + * @cdev: container device + * @data: data passed to match function + * @match: match function used to find specific port from the port device list + * + * Find a port device under container device. This function needs to be + * invoked with lock held. + * + * This function returns NULL if the device doesn't match and non-zero if it + * does. If this function returns non-zero and a reference to the platform + * device of port can be obtained. + * + * NOTE: you will need to drop the device reference with put_device() after use. + */ +struct platform_device * +__fpga_cdev_find_port(struct fpga_cdev *cdev, void *data, + int (*match)(struct platform_device *, void *)) +{ + struct feature_platform_data *pdata; + struct platform_device *port_dev; + + list_for_each_entry(pdata, &cdev->port_dev_list, node) { + port_dev = pdata->dev; + + if (match(port_dev, data) && get_device(&port_dev->dev)) + return port_dev; + } + + return NULL; +} +EXPORT_SYMBOL_GPL(__fpga_cdev_find_port); + int fpga_port_id(struct platform_device *pdev) { void __iomem *base = get_feature_ioaddr_by_id(&pdev->dev, diff --git a/drivers/fpga/dfl.h b/drivers/fpga/dfl.h index 9b19399..d6ecda1 100644 --- a/drivers/fpga/dfl.h +++ b/drivers/fpga/dfl.h @@ -356,4 +356,24 @@ struct fpga_cdev { struct fpga_cdev *fpga_enumerate_feature_devs(struct fpga_enum_info *info); void fpga_remove_feature_devs(struct fpga_cdev *cdev); +/* + * need to drop the device reference with put_device() after use port platform + * device returned by __fpga_cdev_find_port and fpga_cdev_find_port functions. + */ +struct platform_device * +__fpga_cdev_find_port(struct fpga_cdev *cdev, void *data, + int (*match)(struct platform_device *, void *)); + +static inline struct platform_device * +fpga_cdev_find_port(struct fpga_cdev *cdev, void *data, + int (*match)(struct platform_device *, void *)) +{ + struct platform_device *pdev; + + mutex_lock(&cdev->lock); + pdev = __fpga_cdev_find_port(cdev, data, match); + mutex_unlock(&cdev->lock); + + return pdev; +} #endif /* __FPGA_DFL_H */ -- 2.7.4