Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1397439ybk; Thu, 14 May 2020 08:02:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSf7PoHHmgbNnLP0/IQeCVL/zUrZR6esrFp+fyWL8Q4qwhHiLNv8/zPvOeqi56eUvMcnfV X-Received: by 2002:a50:e444:: with SMTP id e4mr2672031edm.191.1589468578699; Thu, 14 May 2020 08:02:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589468578; cv=none; d=google.com; s=arc-20160816; b=fIEgMV57yinY7YN56rcJpflFOoWw4xNYjYkCnSJkU7vVH3QYW2t5IDD5X9cAIYpdCE Hr9bQbjPvmhTX9rmYQvV9zjgNxu7m4ohaBChVxekuxY4yapqbkp/pJflaCW5Owg+3X/p eSfvmp/EyCYaJKn+fVMLJxdkd2GRvrfEo1qoD0+jPUNj6VIxMOac2Gkc6o/B904x0hiG zBFS8/HPctZwXZUuoajgQAYAroSkhhUKz6Ge84MPF4TNxOF4bgo+ejN087TAzcvLuhEj F4vlsKOviKhQlnTMZ3M+A+ouPOk+Xn1jd/LnYAhqp0byZ2VQJqcVOJrQ37y17PqiqSZf gQRA== 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=oPxuXqtF223OER+bcyGCz8Cb674T5LZwKws+2r6ddns=; b=L6yoqLJY/Ad37ILwRS/kyWfr0v6ApqBKvw/ZTu8Rfj0HHcgmjEk90g62vUbAxXSJCJ 2kfD/M/BuxJ4hm3JKDW817mSP5bhA1VmOOWCLlgVpOZ3m/kZCfwzEVEo8/hnQ92Pg7Ji AsanJLrOYRPctieUuVaO9PWiwQRvFitwvXV5UUixbLv7H/nAmpWbB7O0GIMoADyrS4Nu IvNiB7Znn+onemHseb08e6UYhKKErQVVoaHuKC5x+/ghlPw3YVXw3LkRheUi+VloRR1F o0l5rfM2AW0ZBYXM5K33VyaE3zL2LXThRIQgvvbiYax2bNRcIPyJC2z9adSLl7wit/3/ 1Tug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=MkKcHfOX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id t11si2082566eju.257.2020.05.14.08.02.34; Thu, 14 May 2020 08:02:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=MkKcHfOX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728017AbgENPAX (ORCPT + 99 others); Thu, 14 May 2020 11:00:23 -0400 Received: from fllv0015.ext.ti.com ([198.47.19.141]:42116 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726146AbgENPAV (ORCPT ); Thu, 14 May 2020 11:00:21 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 04EF06Rd029135; Thu, 14 May 2020 10:00:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1589468406; bh=oPxuXqtF223OER+bcyGCz8Cb674T5LZwKws+2r6ddns=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=MkKcHfOX0rkPf/0CruxXMcU/KDNgv7PfzNXoxweAGS0wa6ecFAEvPpP/K37TmmSmb Muc1KvKYi7OBEN/wPFkhaFxwWdgNqM3rPHdKkYoVv365sZNi2HVPqPogyD5qLel9IP TIt80aFUFEPdMTPyhdw1PlkTnDLp9CTxsgTYgFoM= Received: from DFLE103.ent.ti.com (dfle103.ent.ti.com [10.64.6.24]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 04EF05qA117768 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 14 May 2020 10:00:06 -0500 Received: from DFLE101.ent.ti.com (10.64.6.22) by DFLE103.ent.ti.com (10.64.6.24) 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:06 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE101.ent.ti.com (10.64.6.22) 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:05 -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 04EExgAm019279; Thu, 14 May 2020 10:00:01 -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 04/19] PCI: endpoint: Add API to create EPF device from device tree Date: Thu, 14 May 2020 20:29:12 +0530 Message-ID: <20200514145927.17555-5-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add API to create EPF device from device tree and the device managed interface corresponding to it. This is added in order to define an endpoint function completely from device tree. Signed-off-by: Kishon Vijay Abraham I --- drivers/pci/endpoint/pci-epf-core.c | 68 +++++++++++++++++++++++++++++ include/linux/pci-epf.h | 6 +++ 2 files changed, 74 insertions(+) diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index 244e00f48c5c..cb6c7b886325 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -280,6 +280,73 @@ struct pci_epf *pci_epf_create(const char *name) } EXPORT_SYMBOL_GPL(pci_epf_create); +/** + * pci_epf_of_create() - create a new PCI EPF device from device tree node + * @node: the device node of the PCI EPF device. + * + * Invoke to create a new PCI EPF device by providing a device tree node + * with compatible property. + */ +struct pci_epf *pci_epf_of_create(struct device_node *node) +{ + struct pci_epf *epf; + const char *compat; + int ret; + + of_node_get(node); + + ret = of_property_read_string(node, "compatible", &compat); + if (ret) { + of_node_put(node); + return ERR_PTR(ret); + } + + epf = pci_epf_create(compat); + if (!IS_ERR(epf)) + epf->node = node; + + return epf; +} +EXPORT_SYMBOL_GPL(pci_epf_of_create); + +static void devm_epf_release(struct device *dev, void *res) +{ + struct pci_epf *epf = *(struct pci_epf **)res; + + pci_epf_destroy(epf); +} + +/** + * devm_pci_epf_of_create() - create a new PCI EPF device from device tree node + * @dev: device that is creating the new EPF + * @node: the device node of the PCI EPF device. + * + * Invoke to create a new PCI EPF device by providing a device tree node with + * compatible property. While at that, it also associates the device with the + * EPF using devres. On driver detach, release function is invoked on the devres + * data, where devres data is freed. + */ +struct pci_epf *devm_pci_epf_of_create(struct device *dev, + struct device_node *node) +{ + struct pci_epf **ptr, *epf; + + ptr = devres_alloc(devm_epf_release, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + epf = pci_epf_of_create(node); + if (!IS_ERR(epf)) { + *ptr = epf; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return epf; +} +EXPORT_SYMBOL_GPL(devm_pci_epf_of_create); + const struct pci_epf_device_id * pci_epf_match_device(const struct pci_epf_device_id *id, struct pci_epf *epf) { @@ -300,6 +367,7 @@ static void pci_epf_dev_release(struct device *dev) { struct pci_epf *epf = to_pci_epf(dev); + of_node_put(epf->node); kfree(epf->name); kfree(epf); } diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index 6644ff3b0702..8fb77ab1968f 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -11,6 +11,7 @@ #include #include +#include #include struct pci_epf; @@ -108,6 +109,7 @@ struct pci_epf_bar { /** * struct pci_epf - represents the PCI EPF device * @dev: the PCI EPF device + * @node: the device tree node of the PCI EPF device * @name: the name of the PCI EPF device * @header: represents standard configuration header * @bar: represents the BAR of EPF device @@ -121,6 +123,7 @@ struct pci_epf_bar { */ struct pci_epf { struct device dev; + struct device_node *node; const char *name; struct pci_epf_header *header; struct pci_epf_bar bar[6]; @@ -167,6 +170,9 @@ static inline void *epf_get_drvdata(struct pci_epf *epf) const struct pci_epf_device_id * pci_epf_match_device(const struct pci_epf_device_id *id, struct pci_epf *epf); struct pci_epf *pci_epf_create(const char *name); +struct pci_epf *pci_epf_of_create(struct device_node *node); +struct pci_epf *devm_pci_epf_of_create(struct device *dev, + struct device_node *node); void pci_epf_destroy(struct pci_epf *epf); int __pci_epf_register_driver(struct pci_epf_driver *driver, struct module *owner); -- 2.17.1