From patchwork Thu Sep 26 11:29:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kishon Vijay Abraham I X-Patchwork-Id: 174463 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1920022ill; Thu, 26 Sep 2019 04:31:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqwkNWTiIDyKD67BUT5ZXMqgy6r9hE7RkH2cow6nwswSS/amwLEPyrUkPUkuIS2OmVHKbTYI X-Received: by 2002:a50:93a4:: with SMTP id o33mr3123787eda.0.1569497466290; Thu, 26 Sep 2019 04:31:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569497466; cv=none; d=google.com; s=arc-20160816; b=AWYT113G8Ck5e4UpPRaNndjSrudrJMBRPIqu0tV5SSpEnQcmEFi26+tLIhiNmd/IeV nWDxMg2gxq4h9prAfe4xOJVQJrbVp5tqUdRbUIVQbqn7TBQiSjKYs744HNpibGYE0d3Y Sr7X6dYu8D3EI8IC6VpWs7AdFt1ACRYmkOv0Lrp/jECFNtBhc70bklLUYeXbOrV6g2m8 RkMiT1tfnEOv/+E0IiwxLP11dQ17Ti/fbjlDaUuWw8nn5KM/6AiUllkvKIn5MbNdLBbg sXvmmPVjN4QVAPVJNaDs55eWo9fWX9tVtiVEvbq/+ODbymAg23zy2IBHo44kVCo2dfZT wzcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=4zHnlcPjrtmbIQZ9Yub799bUIN/qndEfK5n4s1oKXSI=; b=rbuWMcXxx1rxxf2typrMIcLMMM7ChjPvzW7E0w720y5O/f2/fcERWWsL5Iw388eEjB 1Nf97B565397f7NBoAcp+hvdYFAyY4Ov2PF+Cis4GA/3LMOoyISb4o/MZx8S1zMi9BUJ n8oRFSn1WmEl5QdLk8Rrt+DDFUEP6Bws9/OsxiC6TMcVCq3jpAc5euvS9UEc6Eektd95 vpCuiC7hNVuzKg0kC7DkyQyGt/EzsQjG459pI7YsiPe8AYkHxU76hKjkhkbXb8eowRn1 QLXIckLKpE/f/jDPzulsv7dVA3KhpfDCjGQ/Nuzwkmnk3LwfI58i+dFz7VaC9206tVIk MUoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=OXXAw2TF; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z19si1053114edr.403.2019.09.26.04.31.06; Thu, 26 Sep 2019 04:31:06 -0700 (PDT) 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; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=OXXAw2TF; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726402AbfIZLbF (ORCPT + 26 others); Thu, 26 Sep 2019 07:31:05 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:52866 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726330AbfIZLbD (ORCPT ); Thu, 26 Sep 2019 07:31:03 -0400 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id x8QBUtqC016119; Thu, 26 Sep 2019 06:30:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1569497455; bh=4zHnlcPjrtmbIQZ9Yub799bUIN/qndEfK5n4s1oKXSI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=OXXAw2TFU4DSgE1N4jo04YQO4YG5zvgFHh+qqrW7hdrV+biWQ8dH3MgfMmNc8Sy4d a5l49OEt1+qsAx1AirKy6mLmtoZ35nV5X6+0wR+nssdV/NQC8THLpKJsOya90wEBBg sD0cmrZXN/BFL+qJ87zvgXL0xlonrjROSogStJLY= Received: from DLEE104.ent.ti.com (dlee104.ent.ti.com [157.170.170.34]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x8QBUt7o030976 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 26 Sep 2019 06:30:55 -0500 Received: from DLEE106.ent.ti.com (157.170.170.36) by DLEE104.ent.ti.com (157.170.170.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Thu, 26 Sep 2019 06:30:47 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DLEE106.ent.ti.com (157.170.170.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Thu, 26 Sep 2019 06:30:54 -0500 Received: from a0393678ub.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id x8QBUTjw069017; Thu, 26 Sep 2019 06:30:51 -0500 From: Kishon Vijay Abraham I To: Bjorn Helgaas , Jonathan Corbet , Rob Herring , Jon Mason , Dave Jiang , Allen Hubbe , Lorenzo Pieralisi CC: Mark Rutland , , , , , , Subject: [RFC PATCH 05/21] PCI: endpoint: Add API to get reference to EPC from device-tree Date: Thu, 26 Sep 2019 16:59:17 +0530 Message-ID: <20190926112933.8922-6-kishon@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190926112933.8922-1-kishon@ti.com> References: <20190926112933.8922-1-kishon@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add of_pci_epc_get() and of_pci_epc_get_by_name() to get reference to EPC from device-tree. This is added in preparation to define an endpoint function from device tree. Signed-off-by: Kishon Vijay Abraham I --- drivers/pci/endpoint/pci-epc-core.c | 61 +++++++++++++++++++++++++++++ include/linux/pci-epc.h | 4 +- 2 files changed, 64 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index 5bc094093a47..0c2fdd39090c 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -83,6 +83,66 @@ struct pci_epc *pci_epc_get(const char *epc_name) } EXPORT_SYMBOL_GPL(pci_epc_get); +/** + * of_pci_epc_get() - get PCI endpoint controller from device node and index + * @node: device node which contains the phandle to endpoint controller + * @index: index of the endpoint controller in "epcs" property + * + * Returns the EPC corresponding to the _index_ entry in "epcs" property + * present in device node, after getting a refcount to it or -ENODEV if + * there is no such EPC or -EPROBE_DEFER if there is a phandle to the phy, + * but the device is not yet loaded. + */ +struct pci_epc *of_pci_epc_get(struct device_node *node, int index) +{ + struct device_node *epc_node; + struct class_dev_iter iter; + struct pci_epc *epc; + struct device *dev; + + epc_node = of_parse_phandle(node, "epcs", index); + if (!epc_node) + return ERR_PTR(-ENODEV); + + class_dev_iter_init(&iter, pci_epc_class, NULL, NULL); + while ((dev = class_dev_iter_next(&iter))) { + epc = to_pci_epc(dev); + if (epc_node != epc->dev.of_node) + continue; + + of_node_put(epc_node); + class_dev_iter_exit(&iter); + get_device(&epc->dev); + return epc; + } + + of_node_put(node); + class_dev_iter_exit(&iter); + return ERR_PTR(-EPROBE_DEFER); +} +EXPORT_SYMBOL_GPL(of_pci_epc_get); + +/** + * of_pci_epc_get_by_name() - get PCI endpoint controller from device node + * and string + * @node: device node which contains the phandle to endpoint controller + * @epc_name: name of endpoint controller as present in "epc-names" property + * + * Returns the EPC corresponding to the epc_name in "epc-names" property + * present in device node. + */ +struct pci_epc *of_pci_epc_get_by_name(struct device_node *node, + const char *epc_name) +{ + int index = 0; + + if (epc_name) + index = of_property_match_string(node, "epc-names", epc_name); + + return of_pci_epc_get(node, index); +} +EXPORT_SYMBOL_GPL(of_pci_epc_get_by_name); + /** * pci_epc_get_first_free_bar() - helper to get first unreserved BAR * @epc_features: pci_epc_features structure that holds the reserved bar bitmap @@ -661,6 +721,7 @@ __pci_epc_create(struct device *dev, const struct pci_epc_ops *ops, device_initialize(&epc->dev); epc->dev.class = pci_epc_class; epc->dev.parent = dev; + epc->dev.of_node = dev->of_node; epc->ops = ops; ret = dev_set_name(&epc->dev, "%s", dev_name(dev)); diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index 0fff52675a6b..ef6531af6ed2 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -202,7 +202,9 @@ unsigned int pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features); struct pci_epc *pci_epc_get(const char *epc_name); void pci_epc_put(struct pci_epc *epc); - +struct pci_epc *of_pci_epc_get(struct device_node *node, int index); +struct pci_epc *of_pci_epc_get_by_name(struct device_node *node, + const char *epc_name); int __pci_epc_mem_init(struct pci_epc *epc, phys_addr_t phys_addr, size_t size, size_t page_size); void pci_epc_mem_exit(struct pci_epc *epc);