From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46EA9C433E2 for ; Thu, 14 May 2020 15:00:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 287AD20643 for ; Thu, 14 May 2020 15:00:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="XILpPMuJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728004AbgENPAX (ORCPT ); Thu, 14 May 2020 11:00:23 -0400 Received: from lelv0142.ext.ti.com ([198.47.23.249]:50410 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727991AbgENPAW (ORCPT ); Thu, 14 May 2020 11:00:22 -0400 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 04EF04GF032483; Thu, 14 May 2020 10:00:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1589468404; bh=bDHfeg2mPHd8gN2CoYU7iU5rAUI8DfJtiyLth9bqm8Q=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=XILpPMuJnHCkbsdfHqkWOg9NpMw2zFY8iYdg5WcRu8E48J//kLV6GRNQCHRS2LgKw 5VBvswXO0u+Q66POCghVoQmZmgDky622apKVGwJzAHjiQsTB8lAvhMhevkqM9Dmybu SCBw6b7HCWvshLaqcyIJGMfqwBzrdbljV5O2x7Fs= Received: from DLEE102.ent.ti.com (dlee102.ent.ti.com [157.170.170.32]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id 04EF03Ti127742; Thu, 14 May 2020 10:00:04 -0500 Received: from DLEE108.ent.ti.com (157.170.170.38) by DLEE102.ent.ti.com (157.170.170.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Thu, 14 May 2020 10:00:01 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Thu, 14 May 2020 10:00:01 -0500 Received: from a0393678ub.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 04EExgAl019279; Thu, 14 May 2020 09:59:57 -0500 From: Kishon Vijay Abraham I To: Lorenzo Pieralisi , Arnd Bergmann , Jon Mason , Dave Jiang , Allen Hubbe , Tom Joseph , Bjorn Helgaas , Rob Herring CC: Greg Kroah-Hartman , Jonathan Corbet , , , , , , Kishon Vijay Abraham I Subject: [PATCH 03/19] PCI: endpoint: Add API to get reference to EPC from device-tree Date: Thu, 14 May 2020 20:29:11 +0530 Message-ID: <20200514145927.17555-4-kishon@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200514145927.17555-1-kishon@ti.com> References: <20200514145927.17555-1-kishon@ti.com> MIME-Version: 1.0 Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@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 device in device tree. Signed-off-by: Kishon Vijay Abraham I --- drivers/pci/endpoint/pci-epc-core.c | 61 +++++++++++++++++++++++++++++ include/linux/pci-epc.h | 3 ++ 2 files changed, 64 insertions(+) diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index 82ba0dc7f2f5..177a3fc1a0dd 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(epc_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 @@ -629,6 +689,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 cc66bec8be90..dd3c2d566c3d 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -211,6 +211,9 @@ int pci_epc_mem_init(struct pci_epc *epc, phys_addr_t base, int pci_epc_multi_mem_init(struct pci_epc *epc, struct pci_epc_mem_window *window, unsigned int num_windows); +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); void pci_epc_mem_exit(struct pci_epc *epc); void __iomem *pci_epc_mem_alloc_addr(struct pci_epc *epc, phys_addr_t *phys_addr, size_t size); -- 2.17.1