From patchwork Sun Jan 21 21:16:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 10177127 X-Patchwork-Delegate: bhelgaas@google.com 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 62221601E7 for ; Sun, 21 Jan 2018 21:17:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55D9926E5D for ; Sun, 21 Jan 2018 21:17:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4889F26E74; Sun, 21 Jan 2018 21:17:02 +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=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B597F26E5D for ; Sun, 21 Jan 2018 21:17:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751216AbeAUVQc (ORCPT ); Sun, 21 Jan 2018 16:16:32 -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 S1751047AbeAUVQc (ORCPT ); Sun, 21 Jan 2018 16:16:32 -0500 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23992604AbeAUVQbD8pcG (ORCPT + 1 other); Sun, 21 Jan 2018 22:16:31 +0100 Date: Sun, 21 Jan 2018 22:16:29 +0100 From: Ladislav Michl To: Bjorn Helgaas , Wei Yongjun Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Dmitry Torokhov Subject: [PATCH 4/5] devres: Add devm_ioremap_shared_resource() Message-ID: <20180121211629.GE15151@lenoch> References: <20180121211432.GA15151@lenoch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180121211432.GA15151@lenoch> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Implement managed ioremap function for shared resources. Signed-off-by: Ladislav Michl --- include/linux/device.h | 9 ++++++++- lib/devres.c | 22 ++++++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/include/linux/device.h b/include/linux/device.h index e99d41a6190b..a35247a5f578 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -731,7 +731,14 @@ void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset, resource_size_t size); void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset, resource_size_t size); -void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res); + +#define devm_ioremap_resource(dev, res) \ + __devm_ioremap_resource(dev, res, false) +#define devm_ioremap_shared_resource(dev, res) \ + __devm_ioremap_resource(dev, res, true) + +void __iomem *__devm_ioremap_resource(struct device *dev, struct resource *res, + bool shared); void devm_iounmap(struct device *dev, void __iomem *addr); diff --git a/lib/devres.c b/lib/devres.c index e9aad136f667..9fa15816cb83 100644 --- a/lib/devres.c +++ b/lib/devres.c @@ -22,6 +22,9 @@ static int devm_ioremap_match(struct device *dev, void *res, void *match_data) * @size: Size of map * * Managed ioremap(). Map is automatically unmapped on driver detach. + * + * When possible, use devm_ioremap_resource() or + * devm_ioremap_shared_resource() instead. */ void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, resource_size_t size) @@ -116,13 +119,14 @@ void devm_iounmap(struct device *dev, void __iomem *addr) EXPORT_SYMBOL(devm_iounmap); /** - * devm_ioremap_resource() - check, request region, and ioremap resource + * __devm_ioremap_resource() - check, request region, and ioremap resource * @dev: generic device to handle the resource for * @res: resource to be handled + * @shared: region is not requested when true * - * Checks that a resource is a valid memory region, requests the memory - * region and ioremaps it. All operations are managed and will be undone - * on driver detach. + * Checks that a resource is a valid memory region, eventually requests the + * memory region and ioremaps it. 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: @@ -132,7 +136,8 @@ EXPORT_SYMBOL(devm_iounmap); * if (IS_ERR(base)) * return PTR_ERR(base); */ -void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res) +void __iomem *__devm_ioremap_resource(struct device *dev, struct resource *res, + bool shared) { resource_size_t size; const char *name; @@ -148,7 +153,7 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res) size = resource_size(res); name = res->name ?: dev_name(dev); - if (!devm_request_mem_region(dev, res->start, size, name)) { + if (!shared && !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); } @@ -156,13 +161,14 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res) dest_ptr = devm_ioremap(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); + if (!shared) + devm_release_mem_region(dev, res->start, size); dest_ptr = IOMEM_ERR_PTR(-ENOMEM); } return dest_ptr; } -EXPORT_SYMBOL(devm_ioremap_resource); +EXPORT_SYMBOL(__devm_ioremap_resource); #ifdef CONFIG_HAS_IOPORT_MAP /*