From patchwork Thu Jun 8 14:13:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Pieralisi X-Patchwork-Id: 9775679 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2483E601C3 for ; Thu, 8 Jun 2017 14:34:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 144BE20265 for ; Thu, 8 Jun 2017 14:34:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08A10205AF; Thu, 8 Jun 2017 14:34:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9090E20265 for ; Thu, 8 Jun 2017 14:34:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=kUiUrVnlqnZnd1oQhFBUOAmU6hgBRtp3XZ1xLr+eM70=; b=Oxv7rTIaSD76KVp2BZkHd+HSPx XE2c2UV23M315tgADEwt1UOvSOWw5syzaXfin8eCyvJXJ6t935GbrNQBzR4PXjQzfj73DlTc8MZpI xCZEQpfY4DD8NTxE9MRQZQ31ZBa3npBaUZGepDrxredb+dFNe/Ked2szP7twm5rYlbGBrfI8hoIKL 4linoOeB2L3heIDwpYxJ7f/ivOud8XoU/aHZG092qUvdkI5qQS50QwEvCEbxULn3cNrUbj0V9CBP3 T4h2/Fqr7eFtLCaQrC7Rbh/WKrjg1CcZS7QubeDCryAdToDsOP4F1Ip0Y4Jfti6b8K17msV7QwL4N 6JnHB17Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dIyWT-0001eX-76; Thu, 08 Jun 2017 14:34:53 +0000 Received: from merlin.infradead.org ([205.233.59.134]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dIyRs-0002r8-H6 for linux-arm-kernel@bombadil.infradead.org; Thu, 08 Jun 2017 14:30:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=RGVeagLe2lFj2+Ym0GCKilCBsegEUwEYVBgdLXJL63o=; b=oRLUiRjZE0BuY+MgEr23A4dIV aueHxnxyOfwCv+NdLx+DD2cooUomn6AUUgjV8zPKcUwlHFswWYwe65wbtxcVdPs1fJMzJpI3yGTeZ luUtCzrWbaa55P8neC3UR3Hs/+B3HYigvovox1SggyNPLoTzX3MRWZK/1hXGhhURs+0CD0dQjZv7j x+ldba+Sx2VaHZ7I8IOQPMN1pUlymiyoY6DptAef4c6hLviyfG1nx4903ojJYiNpRQRFSu+0WPLok FWk2pP/mTJ6jfrCSQkbPI84E/265joJMpHHlAhxTLD4WQDTGp1z6nReWvpkS5L0wNxGsnhBH7cv8I BpCrPkC0g==; Received: from foss.arm.com ([217.140.101.70]) by merlin.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dIyBd-00086n-Gx for linux-arm-kernel@lists.infradead.org; Thu, 08 Jun 2017 14:13:22 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 68CAA15BF; Thu, 8 Jun 2017 07:13:00 -0700 (PDT) Received: from red-moon.cambridge.arm.com (red-moon.cambridge.arm.com [10.1.206.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0AD3D3F3E1; Thu, 8 Jun 2017 07:12:55 -0700 (PDT) From: Lorenzo Pieralisi To: linux-pci@vger.kernel.org Subject: [RFT PATCH v2 06/42] PCI: Add devm_pci_alloc_host_bridge() interface Date: Thu, 8 Jun 2017 15:13:06 +0100 Message-Id: <20170608141342.2018-7-lorenzo.pieralisi@arm.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20170608141342.2018-1-lorenzo.pieralisi@arm.com> References: <20170608141342.2018-1-lorenzo.pieralisi@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170608_101321_880497_F30A49EB X-CRM114-Status: GOOD ( 13.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wenrui Li , Gabriele Paoloni , Shawn Lin , Will Deacon , Michal Simek , Thierry Reding , Tanmay Inamdar , Matthew Minter , Rob Herring , Lorenzo Pieralisi , Pratyush Anand , Russell King , Murali Karicheri , Linus Walleij , Arnd Bergmann , Bharat Kumar Gogada , Joao Pinto , Bjorn Helgaas , Mingkai Hu , linux-arm-kernel@lists.infradead.org, Thomas Petazzoni , Jingoo Han , Stanimir Varbanov , Minghuan Lian , Zhou Wang , Simon Horman , Roy Zang MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP struct pci_host_bridge can be allocated by PCI host bridge drivers which usually allocate and map memory through devm managed interfaces. Add a devm version for the pci_alloc_host_bridge() interface to simplify PCI host controller drivers porting and simplify the drivers failures paths. Signed-off-by: Lorenzo Pieralisi Cc: Arnd Bergmann Cc: Bjorn Helgaas --- Documentation/driver-model/devres.txt | 1 + drivers/pci/probe.c | 24 ++++++++++++++++++++++-- include/linux/pci.h | 2 ++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index e72587f..ffbc891 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt @@ -342,6 +342,7 @@ PER-CPU MEM devm_free_percpu() PCI + devm_pci_alloc_host_bridge() : managed PCI host bridge allocation devm_pci_remap_cfgspace() : ioremap PCI configuration space devm_pci_remap_cfg_resource() : ioremap PCI configuration space resource pcim_enable_device() : after success, all PCI ops become managed diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index cbf0d0c..e3f6965 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -510,14 +510,18 @@ static struct pci_bus *pci_alloc_bus(struct pci_bus *parent) return b; } -static void pci_release_host_bridge_dev(struct device *dev) +static void devm_pci_release_host_bridge_dev(struct device *dev) { struct pci_host_bridge *bridge = to_pci_host_bridge(dev); if (bridge->release_fn) bridge->release_fn(bridge); +} - pci_free_host_bridge(bridge); +static void pci_release_host_bridge_dev(struct device *dev) +{ + devm_pci_release_host_bridge_dev(dev); + pci_free_host_bridge(to_pci_host_bridge(dev)); } struct pci_host_bridge *pci_alloc_host_bridge(size_t priv) @@ -535,6 +539,22 @@ struct pci_host_bridge *pci_alloc_host_bridge(size_t priv) } EXPORT_SYMBOL(pci_alloc_host_bridge); +struct pci_host_bridge *devm_pci_alloc_host_bridge(struct device *dev, + size_t priv) +{ + struct pci_host_bridge *bridge; + + bridge = devm_kzalloc(dev, sizeof(*bridge) + priv, GFP_KERNEL); + if (!bridge) + return NULL; + + INIT_LIST_HEAD(&bridge->windows); + bridge->dev.release = devm_pci_release_host_bridge_dev; + + return bridge; +} +EXPORT_SYMBOL(devm_pci_alloc_host_bridge); + void pci_free_host_bridge(struct pci_host_bridge *bridge) { pci_free_resource_list(&bridge->windows); diff --git a/include/linux/pci.h b/include/linux/pci.h index 5720635..b21308e 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -463,6 +463,8 @@ static inline struct pci_host_bridge *pci_host_bridge_from_priv(void *priv) } struct pci_host_bridge *pci_alloc_host_bridge(size_t priv); +struct pci_host_bridge *devm_pci_alloc_host_bridge(struct device *dev, + size_t priv); void pci_free_host_bridge(struct pci_host_bridge *bridge); int pci_register_host_bridge(struct pci_host_bridge *bridge); struct pci_host_bridge *pci_find_host_bridge(struct pci_bus *bus);