All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Jonathan Corbet <corbet@lwn.net>,
	Bjorn Helgaas <bhelgaas@google.com>, Tejun Heo <tj@kernel.org>,
	Arnd Bergmann <arnd@arndb.de>, Will Deacon <will.deacon@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Russell King <linux@armlinux.org.uk>,
	Pratyush Anand <pratyush.anand@gmail.com>,
	Jingoo Han <jingoohan1@gmail.com>,
	Mingkai Hu <mingkai.hu@freescale.com>,
	John Garry <john.garry@huawei.com>,
	Tanmay Inamdar <tinamdar@apm.com>,
	Murali Karicheri <m-karicheri2@ti.com>,
	Bharat Kumar Gogada <bharat.kumar.gogada@xilinx.com>,
	Ray Jui <rjui@broadcom.com>, Wenrui Li <wenrui.li@rock-chips.com>,
	Shawn Lin <shawn.lin@rock-chips.com>,
	Minghuan Lian <minghuan.Lian@freescale.com>,
	Jon Mason <jonmason@broadcom.com>,
	Gabriele Paoloni <gabriele.paoloni@huawei.com>,
	Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
	Joao Pinto <Joao.Pinto@synopsys.com>,
	Thierry Reding <thierry.reding@gmail.com>,
	Michal Simek <michal.simek@xilinx.com>,
	Stanimir Varbanov <svarbanov@mm-sol.com>,
	Zhou Wang <wangzhou1@hisilicon.com>,
	Roy Zang <tie-fei.zang@freescale.com>,
	"Luis R. Rodriguez" <mcgrof@kernel.org>
Subject: Re: [PATCH v2 08/22] lib: implement Devres ioremap_nopost() interface
Date: Mon, 27 Mar 2017 20:41:29 -0500	[thread overview]
Message-ID: <20170328014129.GJ25380@bhelgaas-glaptop.roam.corp.google.com> (raw)
In-Reply-To: <20170327094954.7162-9-lorenzo.pieralisi@arm.com>

On Mon, Mar 27, 2017 at 10:49:36AM +0100, Lorenzo Pieralisi wrote:
> The introduction of the ioremap_nopost() interface allows
> kernel drivers to map memory through a dedicated kernel
> interface providing non-posted writes semantics.
> 
> Introduce two new functions in the Devres kernel layer and Devres
> documentation:
> 
> - devm_ioremap_nopost()
> - devm_ioremap_nopost_resource()
> 
> so that drivers can make use of devm_* interface to map memory
> regions requiring non-posted writes memory attributes.
> 
> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Jonathan Corbet <corbet@lwn.net>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Tejun Heo <tj@kernel.org>
> ---
>  Documentation/driver-model/devres.txt |  3 ++
>  include/linux/device.h                |  2 +
>  include/linux/io.h                    |  2 +
>  lib/devres.c                          | 78 +++++++++++++++++++++++++++++++++++
>  4 files changed, 85 insertions(+)
> 
> diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
> index bf34d5b..9991a66 100644
> --- a/Documentation/driver-model/devres.txt
> +++ b/Documentation/driver-model/devres.txt
> @@ -294,7 +294,10 @@ IOMAP
>    devm_ioremap()
>    devm_ioremap_nocache()
>    devm_ioremap_wc()
> +  devm_ioremap_nopost()
>    devm_ioremap_resource() : checks resource, requests memory region, ioremaps
> +  devm_ioremap_nopost_resource() : do devm_ioremap_resource() with nopost
> +				   memory attributes
>    devm_iounmap()
>    pcim_iomap()
>    pcim_iomap_regions()	: do request_region() and iomap() on multiple BARs
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 9ef518a..1dce865 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -689,6 +689,8 @@ extern unsigned long devm_get_free_pages(struct device *dev,
>  extern void devm_free_pages(struct device *dev, unsigned long addr);
>  
>  void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res);
> +void __iomem *devm_ioremap_nopost_resource(struct device *dev,
> +					   struct resource *res);
>  
>  /* allows to add/remove a custom action to devres stack */
>  int devm_add_action(struct device *dev, void (*action)(void *), void *data);
> diff --git a/include/linux/io.h b/include/linux/io.h
> index 82ef36e..e34d799 100644
> --- a/include/linux/io.h
> +++ b/include/linux/io.h
> @@ -79,6 +79,8 @@ 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_nopost(struct device *dev, resource_size_t offset,
> +				   resource_size_t size);
>  void devm_iounmap(struct device *dev, void __iomem *addr);
>  int check_signature(const volatile void __iomem *io_addr,
>  			const unsigned char *signature, int length);
> diff --git a/lib/devres.c b/lib/devres.c
> index cb1464c..4e05660 100644
> --- a/lib/devres.c
> +++ b/lib/devres.c
> @@ -100,6 +100,34 @@ void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset,
>  EXPORT_SYMBOL(devm_ioremap_wc);
>  
>  /**
> + * devm_ioremap_nopost - Managed ioremap_nopost()
> + * @dev: Generic device to remap IO address for
> + * @offset: BUS offset to map

I know this comment was just copied from other devm_ioremap*()
interfaces, but I think it's slightly misleading to call this the "BUS
offset".  That suggests this is a bus address, but it is not.  Maybe
it should be "resource address" or similar?

I propose a separate patch to update the existing comments, followed
by this patch to add this new one.

> + * @size: Size of map
> + *
> + * Managed ioremap_nopost().  Map is automatically unmapped on driver detach.
> + */
> +void __iomem *devm_ioremap_nopost(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 = ioremap_nopost(offset, size);
> +	if (addr) {
> +		*ptr = addr;
> +		devres_add(dev, ptr);
> +	} else
> +		devres_free(ptr);
> +
> +	return addr;
> +}
> +EXPORT_SYMBOL(devm_ioremap_nopost);
> +
> +/**
>   * devm_iounmap - Managed iounmap()
>   * @dev: Generic device to unmap for
>   * @addr: Address to unmap
> @@ -163,6 +191,56 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res)
>  }
>  EXPORT_SYMBOL(devm_ioremap_resource);
>  
> +/**
> + * devm_ioremap_nopost_resource() - devm_ioremap_resource() nopost version
> + * @dev: generic device to handle the resource for
> + * @res: resource to be handled
> + *
> + * Checks that a resource is a valid memory region, requests the memory
> + * region and ioremaps it with ioremap_nopost() interface.
> + * 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_ioremap_nopost_resource(&pdev->dev, res);
> + *	if (IS_ERR(base))
> + *		return PTR_ERR(base);
> + */
> +void __iomem *devm_ioremap_nopost_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_ioremap_nopost(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_ioremap_nopost_resource);
> +
>  #ifdef CONFIG_HAS_IOPORT_MAP
>  /*
>   * Generic iomap devres
> -- 
> 2.10.0
> 

WARNING: multiple messages have this Message-ID (diff)
From: Bjorn Helgaas <helgaas@kernel.org>
To: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Wenrui Li <wenrui.li@rock-chips.com>,
	Gabriele Paoloni <gabriele.paoloni@huawei.com>,
	linux-pci@vger.kernel.org, Shawn Lin <shawn.lin@rock-chips.com>,
	Will Deacon <will.deacon@arm.com>,
	Michal Simek <michal.simek@xilinx.com>,
	Thierry Reding <thierry.reding@gmail.com>,
	Tanmay Inamdar <tinamdar@apm.com>,
	Joao Pinto <Joao.Pinto@synopsys.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Pratyush Anand <pratyush.anand@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	Bharat Kumar Gogada <bharat.kumar.gogada@xilinx.com>,
	Murali Karicheri <m-karicheri2@ti.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Arnd Bergmann <arnd@arndb.de>, Jon Mason <jonmason@broadcom.com>,
	Ray Jui <rjui@broadcom.com>, John Garry <john.garry@huawei.com>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Mingkai Hu <mingkai.hu@freescale.com>,
	linux-arm-kernel@lists.infradead.org,
	"Luis R. Rodriguez" <mcgrof@kernel.org>,
	Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
	Jingoo Han <jingoohan1@gmail.com>,
	linux-kernel@vger.kernel.org,
	Stanimir Varbanov <svarbanov@mm-sol.com>,
	Minghuan Lian <minghuan.Lian@freescale.com>,
	Zhou Wang <wangzhou1@hisilicon.com>, Tejun Heo <tj@kernel.org>,
	Roy Zang <tie-fei.zang@freescale.com>
Subject: Re: [PATCH v2 08/22] lib: implement Devres ioremap_nopost() interface
Date: Mon, 27 Mar 2017 20:41:29 -0500	[thread overview]
Message-ID: <20170328014129.GJ25380@bhelgaas-glaptop.roam.corp.google.com> (raw)
In-Reply-To: <20170327094954.7162-9-lorenzo.pieralisi@arm.com>

On Mon, Mar 27, 2017 at 10:49:36AM +0100, Lorenzo Pieralisi wrote:
> The introduction of the ioremap_nopost() interface allows
> kernel drivers to map memory through a dedicated kernel
> interface providing non-posted writes semantics.
> 
> Introduce two new functions in the Devres kernel layer and Devres
> documentation:
> 
> - devm_ioremap_nopost()
> - devm_ioremap_nopost_resource()
> 
> so that drivers can make use of devm_* interface to map memory
> regions requiring non-posted writes memory attributes.
> 
> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Jonathan Corbet <corbet@lwn.net>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Tejun Heo <tj@kernel.org>
> ---
>  Documentation/driver-model/devres.txt |  3 ++
>  include/linux/device.h                |  2 +
>  include/linux/io.h                    |  2 +
>  lib/devres.c                          | 78 +++++++++++++++++++++++++++++++++++
>  4 files changed, 85 insertions(+)
> 
> diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
> index bf34d5b..9991a66 100644
> --- a/Documentation/driver-model/devres.txt
> +++ b/Documentation/driver-model/devres.txt
> @@ -294,7 +294,10 @@ IOMAP
>    devm_ioremap()
>    devm_ioremap_nocache()
>    devm_ioremap_wc()
> +  devm_ioremap_nopost()
>    devm_ioremap_resource() : checks resource, requests memory region, ioremaps
> +  devm_ioremap_nopost_resource() : do devm_ioremap_resource() with nopost
> +				   memory attributes
>    devm_iounmap()
>    pcim_iomap()
>    pcim_iomap_regions()	: do request_region() and iomap() on multiple BARs
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 9ef518a..1dce865 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -689,6 +689,8 @@ extern unsigned long devm_get_free_pages(struct device *dev,
>  extern void devm_free_pages(struct device *dev, unsigned long addr);
>  
>  void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res);
> +void __iomem *devm_ioremap_nopost_resource(struct device *dev,
> +					   struct resource *res);
>  
>  /* allows to add/remove a custom action to devres stack */
>  int devm_add_action(struct device *dev, void (*action)(void *), void *data);
> diff --git a/include/linux/io.h b/include/linux/io.h
> index 82ef36e..e34d799 100644
> --- a/include/linux/io.h
> +++ b/include/linux/io.h
> @@ -79,6 +79,8 @@ 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_nopost(struct device *dev, resource_size_t offset,
> +				   resource_size_t size);
>  void devm_iounmap(struct device *dev, void __iomem *addr);
>  int check_signature(const volatile void __iomem *io_addr,
>  			const unsigned char *signature, int length);
> diff --git a/lib/devres.c b/lib/devres.c
> index cb1464c..4e05660 100644
> --- a/lib/devres.c
> +++ b/lib/devres.c
> @@ -100,6 +100,34 @@ void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset,
>  EXPORT_SYMBOL(devm_ioremap_wc);
>  
>  /**
> + * devm_ioremap_nopost - Managed ioremap_nopost()
> + * @dev: Generic device to remap IO address for
> + * @offset: BUS offset to map

I know this comment was just copied from other devm_ioremap*()
interfaces, but I think it's slightly misleading to call this the "BUS
offset".  That suggests this is a bus address, but it is not.  Maybe
it should be "resource address" or similar?

I propose a separate patch to update the existing comments, followed
by this patch to add this new one.

> + * @size: Size of map
> + *
> + * Managed ioremap_nopost().  Map is automatically unmapped on driver detach.
> + */
> +void __iomem *devm_ioremap_nopost(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 = ioremap_nopost(offset, size);
> +	if (addr) {
> +		*ptr = addr;
> +		devres_add(dev, ptr);
> +	} else
> +		devres_free(ptr);
> +
> +	return addr;
> +}
> +EXPORT_SYMBOL(devm_ioremap_nopost);
> +
> +/**
>   * devm_iounmap - Managed iounmap()
>   * @dev: Generic device to unmap for
>   * @addr: Address to unmap
> @@ -163,6 +191,56 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res)
>  }
>  EXPORT_SYMBOL(devm_ioremap_resource);
>  
> +/**
> + * devm_ioremap_nopost_resource() - devm_ioremap_resource() nopost version
> + * @dev: generic device to handle the resource for
> + * @res: resource to be handled
> + *
> + * Checks that a resource is a valid memory region, requests the memory
> + * region and ioremaps it with ioremap_nopost() interface.
> + * 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_ioremap_nopost_resource(&pdev->dev, res);
> + *	if (IS_ERR(base))
> + *		return PTR_ERR(base);
> + */
> +void __iomem *devm_ioremap_nopost_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_ioremap_nopost(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_ioremap_nopost_resource);
> +
>  #ifdef CONFIG_HAS_IOPORT_MAP
>  /*
>   * Generic iomap devres
> -- 
> 2.10.0
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: helgaas@kernel.org (Bjorn Helgaas)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 08/22] lib: implement Devres ioremap_nopost() interface
Date: Mon, 27 Mar 2017 20:41:29 -0500	[thread overview]
Message-ID: <20170328014129.GJ25380@bhelgaas-glaptop.roam.corp.google.com> (raw)
In-Reply-To: <20170327094954.7162-9-lorenzo.pieralisi@arm.com>

On Mon, Mar 27, 2017 at 10:49:36AM +0100, Lorenzo Pieralisi wrote:
> The introduction of the ioremap_nopost() interface allows
> kernel drivers to map memory through a dedicated kernel
> interface providing non-posted writes semantics.
> 
> Introduce two new functions in the Devres kernel layer and Devres
> documentation:
> 
> - devm_ioremap_nopost()
> - devm_ioremap_nopost_resource()
> 
> so that drivers can make use of devm_* interface to map memory
> regions requiring non-posted writes memory attributes.
> 
> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Jonathan Corbet <corbet@lwn.net>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Tejun Heo <tj@kernel.org>
> ---
>  Documentation/driver-model/devres.txt |  3 ++
>  include/linux/device.h                |  2 +
>  include/linux/io.h                    |  2 +
>  lib/devres.c                          | 78 +++++++++++++++++++++++++++++++++++
>  4 files changed, 85 insertions(+)
> 
> diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
> index bf34d5b..9991a66 100644
> --- a/Documentation/driver-model/devres.txt
> +++ b/Documentation/driver-model/devres.txt
> @@ -294,7 +294,10 @@ IOMAP
>    devm_ioremap()
>    devm_ioremap_nocache()
>    devm_ioremap_wc()
> +  devm_ioremap_nopost()
>    devm_ioremap_resource() : checks resource, requests memory region, ioremaps
> +  devm_ioremap_nopost_resource() : do devm_ioremap_resource() with nopost
> +				   memory attributes
>    devm_iounmap()
>    pcim_iomap()
>    pcim_iomap_regions()	: do request_region() and iomap() on multiple BARs
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 9ef518a..1dce865 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -689,6 +689,8 @@ extern unsigned long devm_get_free_pages(struct device *dev,
>  extern void devm_free_pages(struct device *dev, unsigned long addr);
>  
>  void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res);
> +void __iomem *devm_ioremap_nopost_resource(struct device *dev,
> +					   struct resource *res);
>  
>  /* allows to add/remove a custom action to devres stack */
>  int devm_add_action(struct device *dev, void (*action)(void *), void *data);
> diff --git a/include/linux/io.h b/include/linux/io.h
> index 82ef36e..e34d799 100644
> --- a/include/linux/io.h
> +++ b/include/linux/io.h
> @@ -79,6 +79,8 @@ 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_nopost(struct device *dev, resource_size_t offset,
> +				   resource_size_t size);
>  void devm_iounmap(struct device *dev, void __iomem *addr);
>  int check_signature(const volatile void __iomem *io_addr,
>  			const unsigned char *signature, int length);
> diff --git a/lib/devres.c b/lib/devres.c
> index cb1464c..4e05660 100644
> --- a/lib/devres.c
> +++ b/lib/devres.c
> @@ -100,6 +100,34 @@ void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset,
>  EXPORT_SYMBOL(devm_ioremap_wc);
>  
>  /**
> + * devm_ioremap_nopost - Managed ioremap_nopost()
> + * @dev: Generic device to remap IO address for
> + * @offset: BUS offset to map

I know this comment was just copied from other devm_ioremap*()
interfaces, but I think it's slightly misleading to call this the "BUS
offset".  That suggests this is a bus address, but it is not.  Maybe
it should be "resource address" or similar?

I propose a separate patch to update the existing comments, followed
by this patch to add this new one.

> + * @size: Size of map
> + *
> + * Managed ioremap_nopost().  Map is automatically unmapped on driver detach.
> + */
> +void __iomem *devm_ioremap_nopost(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 = ioremap_nopost(offset, size);
> +	if (addr) {
> +		*ptr = addr;
> +		devres_add(dev, ptr);
> +	} else
> +		devres_free(ptr);
> +
> +	return addr;
> +}
> +EXPORT_SYMBOL(devm_ioremap_nopost);
> +
> +/**
>   * devm_iounmap - Managed iounmap()
>   * @dev: Generic device to unmap for
>   * @addr: Address to unmap
> @@ -163,6 +191,56 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res)
>  }
>  EXPORT_SYMBOL(devm_ioremap_resource);
>  
> +/**
> + * devm_ioremap_nopost_resource() - devm_ioremap_resource() nopost version
> + * @dev: generic device to handle the resource for
> + * @res: resource to be handled
> + *
> + * Checks that a resource is a valid memory region, requests the memory
> + * region and ioremaps it with ioremap_nopost() interface.
> + * 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_ioremap_nopost_resource(&pdev->dev, res);
> + *	if (IS_ERR(base))
> + *		return PTR_ERR(base);
> + */
> +void __iomem *devm_ioremap_nopost_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_ioremap_nopost(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_ioremap_nopost_resource);
> +
>  #ifdef CONFIG_HAS_IOPORT_MAP
>  /*
>   * Generic iomap devres
> -- 
> 2.10.0
> 

  reply	other threads:[~2017-03-28  1:42 UTC|newest]

Thread overview: 115+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-27  9:49 [PATCH v2 00/22] PCI: fix config and I/O Address space memory mappings Lorenzo Pieralisi
2017-03-27  9:49 ` Lorenzo Pieralisi
2017-03-27  9:49 ` [PATCH v2 01/22] PCI: remove __weak tag from pci_remap_iospace() Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49 ` [PATCH v2 02/22] asm-generic/io.h: add ioremap_nopost remap interface Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-28  1:41   ` Bjorn Helgaas
2017-03-28  1:41     ` Bjorn Helgaas
2017-03-28  1:41     ` Bjorn Helgaas
2017-03-28 14:45     ` Lorenzo Pieralisi
2017-03-28 14:45       ` Lorenzo Pieralisi
2017-03-30 16:47       ` Bjorn Helgaas
2017-03-30 16:47         ` Bjorn Helgaas
2017-03-30 16:47         ` Bjorn Helgaas
2017-04-05 10:58       ` Russell King - ARM Linux
2017-04-05 10:58         ` Russell King - ARM Linux
2017-04-05 12:38         ` Lorenzo Pieralisi
2017-04-05 12:38           ` Lorenzo Pieralisi
2017-04-06 10:26           ` Lorenzo Pieralisi
2017-04-06 10:26             ` Lorenzo Pieralisi
2017-04-06 10:47             ` Russell King - ARM Linux
2017-04-06 10:47               ` Russell King - ARM Linux
2017-04-10 14:30               ` Lorenzo Pieralisi
2017-04-10 14:30                 ` Lorenzo Pieralisi
2017-04-06 10:53             ` Luis R. Rodriguez
2017-04-06 10:53               ` Luis R. Rodriguez
2017-04-06 11:38               ` Lorenzo Pieralisi
2017-04-06 11:38                 ` Lorenzo Pieralisi
2017-04-06 11:59                 ` Luis R. Rodriguez
2017-04-06 11:59                   ` Luis R. Rodriguez
2017-04-06 13:07                   ` Russell King - ARM Linux
2017-04-06 13:07                     ` Russell King - ARM Linux
2017-04-06 16:21                     ` Lorenzo Pieralisi
2017-04-06 16:21                       ` Lorenzo Pieralisi
2017-04-06 16:40                       ` Russell King - ARM Linux
2017-04-06 16:40                         ` Russell King - ARM Linux
2017-04-06 17:09                         ` Lorenzo Pieralisi
2017-04-06 17:09                           ` Lorenzo Pieralisi
2017-04-06 17:19                           ` Russell King - ARM Linux
2017-04-06 17:19                             ` Russell King - ARM Linux
2017-04-06 12:11               ` Russell King - ARM Linux
2017-04-06 12:11                 ` Russell King - ARM Linux
2017-04-06 12:25                 ` Luis R. Rodriguez
2017-04-06 12:25                   ` Luis R. Rodriguez
2017-03-27  9:49 ` [PATCH v2 03/22] asm-generic/pgtable.h: introduce pgprot_nonposted remap attribute Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49 ` [PATCH v2 04/22] PCI: fix pci_remap_iospace() " Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49 ` [PATCH v2 05/22] ARM64: implement ioremap_nopost() interface Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-30 16:19   ` Will Deacon
2017-03-30 16:19     ` Will Deacon
2017-03-30 16:19     ` Will Deacon
2017-03-27  9:49 ` [PATCH v2 06/22] ARM: " Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-31 11:08   ` Lorenzo Pieralisi
2017-03-31 11:08     ` Lorenzo Pieralisi
2017-03-31 11:08     ` Lorenzo Pieralisi
2017-04-05 10:21     ` Lorenzo Pieralisi
2017-04-05 10:21       ` Lorenzo Pieralisi
2017-04-05 10:21       ` Lorenzo Pieralisi
2017-03-27  9:49 ` [PATCH v2 07/22] PCI: ECAM: use ioremap_nopost() to map config region Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-30 16:20   ` Will Deacon
2017-03-30 16:20     ` Will Deacon
2017-03-30 16:20     ` Will Deacon
2017-03-27  9:49 ` [PATCH v2 08/22] lib: implement Devres ioremap_nopost() interface Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-28  1:41   ` Bjorn Helgaas [this message]
2017-03-28  1:41     ` Bjorn Helgaas
2017-03-28  1:41     ` Bjorn Helgaas
2017-03-28 14:50     ` Lorenzo Pieralisi
2017-03-28 14:50       ` Lorenzo Pieralisi
2017-03-28 15:55       ` Tejun Heo
2017-03-28 15:55         ` Tejun Heo
2017-03-27  9:49 ` [PATCH v2 09/22] PCI: xilinx: update PCI config space remap function Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49 ` [PATCH v2 10/22] PCI: xilinx-nwl: " Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49 ` [PATCH v2 11/22] PCI: spear13xx: " Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49 ` [PATCH v2 12/22] PCI: rockchip: " Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49 ` [PATCH v2 13/22] PCI: qcom: " Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49 ` [PATCH v2 14/22] PCI: iproc-platform: " Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49 ` [PATCH v2 15/22] PCI: hisi: " Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49 ` [PATCH v2 16/22] PCI: designware: " Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49 ` [PATCH v2 17/22] PCI: armada8k: " Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49 ` [PATCH v2 18/22] PCI: xgene: " Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49 ` [PATCH v2 19/22] PCI: tegra: " Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49 ` [PATCH v2 20/22] PCI: layerscape: " Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49 ` [PATCH v2 21/22] PCI: keystone-dw: " Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49 ` [PATCH v2 22/22] PCI: versatile: " Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi
2017-03-27  9:49   ` Lorenzo Pieralisi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170328014129.GJ25380@bhelgaas-glaptop.roam.corp.google.com \
    --to=helgaas@kernel.org \
    --cc=Joao.Pinto@synopsys.com \
    --cc=arnd@arndb.de \
    --cc=bharat.kumar.gogada@xilinx.com \
    --cc=bhelgaas@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=corbet@lwn.net \
    --cc=gabriele.paoloni@huawei.com \
    --cc=jingoohan1@gmail.com \
    --cc=john.garry@huawei.com \
    --cc=jonmason@broadcom.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=m-karicheri2@ti.com \
    --cc=mcgrof@kernel.org \
    --cc=michal.simek@xilinx.com \
    --cc=minghuan.Lian@freescale.com \
    --cc=mingkai.hu@freescale.com \
    --cc=pratyush.anand@gmail.com \
    --cc=rjui@broadcom.com \
    --cc=shawn.lin@rock-chips.com \
    --cc=svarbanov@mm-sol.com \
    --cc=thierry.reding@gmail.com \
    --cc=thomas.petazzoni@free-electrons.com \
    --cc=tie-fei.zang@freescale.com \
    --cc=tinamdar@apm.com \
    --cc=tj@kernel.org \
    --cc=wangzhou1@hisilicon.com \
    --cc=wenrui.li@rock-chips.com \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.