Received: by 10.223.176.46 with SMTP id f43csp2179701wra; Sun, 21 Jan 2018 13:16:54 -0800 (PST) X-Google-Smtp-Source: AH8x224ypiutijIJCnKXz0eBPrztZC9gpf6uWNMpVxH0hhk/sbOGuVZa5CE3/TzA0NXoL879eiDG X-Received: by 10.98.20.20 with SMTP id 20mr6061994pfu.152.1516569414397; Sun, 21 Jan 2018 13:16:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516569414; cv=none; d=google.com; s=arc-20160816; b=bn21nQiH06E++qwtfMXhP7fm8t/zMMQvdJx829lc7s6okdZzfFYX2nzpqCon9WvwTI 3Frg224Aw7hGen4mv7HYAHv+xXsgsJm8l4bJ2Gpi6l2VMjlwUPWHKzFgfiBez1yy07y/ PKRhh2GqB/MhyFTOH0AAwgJ9y6BNHzo/ikwY3LzIjc/izl6w1k9f07LTszoZ951TlF0R ORSPJcYKjpc3d7FcmTZ+DQBFEgPkDJr44iBYuCtJgTUUxzsLQQZsShbeybb9NWFK8++p 4FLE+C/OUULtZb/4Y6sjpMwKklYHfoVYXKP0Vg8E73L+dg+52XlTd2oLaBVvr7l644O/ g9Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=C+bqdGo+DvhuW39TJVVJbsuhh3rqWx1MzaAxGoLGjpI=; b=J67xTlpCG+27H9uUivX5svkQxdW8RiwKUGrK0shAbSLLEQgzVdFdnqmChnx1qJLDes sEtc22Kr8GC9QE/+2c+Y0CgFhcsfTOiO2gospf9ZIALqiT5S89UYPeey5IH9xRk2Ska6 x0INw662C2maTiQScyiMluKg2Nnu6jr06fMAWNIRbPEJnPGV7DQLZT8lVpqYoXQc1X9T WaZiGYqCJMTdTYYMf+6lTNL8WmEsEbWUgU3wClbXIxaKDEaGxIUOCLaRiqKEsv7YX1Yt nWM9smMbmzSANA+o3Cf245KcHa/0iAk5GFsoAIjnFJzf3C2DSBLvUsf6TeT9i3y2MNrz ekGw== 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 f61-v6si1527660plb.179.2018.01.21.13.16.40; Sun, 21 Jan 2018 13:16:54 -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 S1751335AbeAUVPo (ORCPT + 99 others); Sun, 21 Jan 2018 16:15:44 -0500 Received: from eddie.linux-mips.org ([148.251.95.138]:39738 "EHLO cvs.linux-mips.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751047AbeAUVPm (ORCPT ); Sun, 21 Jan 2018 16:15:42 -0500 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23992521AbeAUVPlsh6xG (ORCPT + 1 other); Sun, 21 Jan 2018 22:15:41 +0100 Date: Sun, 21 Jan 2018 22:15:39 +0100 From: Ladislav Michl To: Bjorn Helgaas , Wei Yongjun Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Dmitry Torokhov Subject: [PATCH 2/5] PCI: Move managed resource alloc to devres Message-ID: <20180121211538.GC15151@lenoch> References: <20180121211432.GA15151@lenoch> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180121211432.GA15151@lenoch> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org devm_pci_remap_cfgspace() is using devm_ioremap_release() devres release function. Move it to devres along with similar PCI functions to allow hiding devm_ioremap_release() from public. Signed-off-by: Ladislav Michl --- drivers/pci/pci.c | 82 ------------------------------------------------------- lib/devres.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 82 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 764ca7b8840d..fcf5cc2c91de 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3533,88 +3533,6 @@ void pci_unmap_iospace(struct resource *res) } EXPORT_SYMBOL(pci_unmap_iospace); -/** - * devm_pci_remap_cfgspace - Managed pci_remap_cfgspace() - * @dev: Generic device to remap IO address for - * @offset: Resource address to map - * @size: Size of map - * - * Managed pci_remap_cfgspace(). Map is automatically unmapped on driver - * detach. - */ -void __iomem *devm_pci_remap_cfgspace(struct device *dev, - resource_size_t offset, - resource_size_t size) -{ - void __iomem **ptr, *addr; - - ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL); - if (!ptr) - return NULL; - - addr = pci_remap_cfgspace(offset, size); - if (addr) { - *ptr = addr; - devres_add(dev, ptr); - } else - devres_free(ptr); - - return addr; -} -EXPORT_SYMBOL(devm_pci_remap_cfgspace); - -/** - * devm_pci_remap_cfg_resource - check, request region and ioremap cfg resource - * @dev: generic device to handle the resource for - * @res: configuration space resource to be handled - * - * Checks that a resource is a valid memory region, requests the memory - * region and ioremaps with pci_remap_cfgspace() API that ensures the - * proper PCI configuration space memory attributes are guaranteed. - * - * All operations are managed and will be undone on driver detach. - * - * Returns a pointer to the remapped memory or an ERR_PTR() encoded error code - * on failure. Usage example:: - * - * res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - * base = devm_pci_remap_cfg_resource(&pdev->dev, res); - * if (IS_ERR(base)) - * return PTR_ERR(base); - */ -void __iomem *devm_pci_remap_cfg_resource(struct device *dev, - struct resource *res) -{ - resource_size_t size; - const char *name; - void __iomem *dest_ptr; - - BUG_ON(!dev); - - if (!res || resource_type(res) != IORESOURCE_MEM) { - dev_err(dev, "invalid resource\n"); - return IOMEM_ERR_PTR(-EINVAL); - } - - size = resource_size(res); - name = res->name ?: dev_name(dev); - - if (!devm_request_mem_region(dev, res->start, size, name)) { - dev_err(dev, "can't request region for resource %pR\n", res); - return IOMEM_ERR_PTR(-EBUSY); - } - - dest_ptr = devm_pci_remap_cfgspace(dev, res->start, size); - if (!dest_ptr) { - dev_err(dev, "ioremap failed for resource %pR\n", res); - devm_release_mem_region(dev, res->start, size); - dest_ptr = IOMEM_ERR_PTR(-ENOMEM); - } - - return dest_ptr; -} -EXPORT_SYMBOL(devm_pci_remap_cfg_resource); - static void __pci_set_master(struct pci_dev *dev, bool enable) { u16 old_cmd, cmd; diff --git a/lib/devres.c b/lib/devres.c index 5f2aedd58bc5..f2f80c233aa4 100644 --- a/lib/devres.c +++ b/lib/devres.c @@ -428,4 +428,86 @@ void pcim_iounmap_regions(struct pci_dev *pdev, int mask) } } EXPORT_SYMBOL(pcim_iounmap_regions); + +/** + * devm_pci_remap_cfgspace - Managed pci_remap_cfgspace() + * @dev: Generic device to remap IO address for + * @offset: Resource address to map + * @size: Size of map + * + * Managed pci_remap_cfgspace(). Map is automatically unmapped on driver + * detach. + */ +void __iomem *devm_pci_remap_cfgspace(struct device *dev, + resource_size_t offset, + resource_size_t size) +{ + void __iomem **ptr, *addr; + + ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return NULL; + + addr = pci_remap_cfgspace(offset, size); + if (addr) { + *ptr = addr; + devres_add(dev, ptr); + } else + devres_free(ptr); + + return addr; +} +EXPORT_SYMBOL(devm_pci_remap_cfgspace); + +/** + * devm_pci_remap_cfg_resource - check, request region and ioremap cfg resource + * @dev: generic device to handle the resource for + * @res: configuration space resource to be handled + * + * Checks that a resource is a valid memory region, requests the memory + * region and ioremaps with pci_remap_cfgspace() API that ensures the + * proper PCI configuration space memory attributes are guaranteed. + * + * All operations are managed and will be undone on driver detach. + * + * Returns a pointer to the remapped memory or an ERR_PTR() encoded error code + * on failure. Usage example:: + * + * res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + * base = devm_pci_remap_cfg_resource(&pdev->dev, res); + * if (IS_ERR(base)) + * return PTR_ERR(base); + */ +void __iomem *devm_pci_remap_cfg_resource(struct device *dev, + struct resource *res) +{ + resource_size_t size; + const char *name; + void __iomem *dest_ptr; + + BUG_ON(!dev); + + if (!res || resource_type(res) != IORESOURCE_MEM) { + dev_err(dev, "invalid resource\n"); + return IOMEM_ERR_PTR(-EINVAL); + } + + size = resource_size(res); + name = res->name ?: dev_name(dev); + + if (!devm_request_mem_region(dev, res->start, size, name)) { + dev_err(dev, "can't request region for resource %pR\n", res); + return IOMEM_ERR_PTR(-EBUSY); + } + + dest_ptr = devm_pci_remap_cfgspace(dev, res->start, size); + if (!dest_ptr) { + dev_err(dev, "ioremap failed for resource %pR\n", res); + devm_release_mem_region(dev, res->start, size); + dest_ptr = IOMEM_ERR_PTR(-ENOMEM); + } + + return dest_ptr; +} +EXPORT_SYMBOL(devm_pci_remap_cfg_resource); #endif /* CONFIG_PCI */ -- 2.15.1