linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Don't fail device probing due to of_dma_set_restricted_buffer()
@ 2021-08-16 13:26 Will Deacon
  2021-08-16 13:26 ` [PATCH v2 1/2] of: Move of_dma_set_restricted_buffer() into device.c Will Deacon
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Will Deacon @ 2021-08-16 13:26 UTC (permalink / raw)
  To: linux-kernel
  Cc: iommu, Will Deacon, Claire Chang, Konrad Rzeszutek Wilk,
	Christoph Hellwig, Rob Herring, Robin Murphy

Hi all,

This is v2 of the patch I previously posted here:

  https://lore.kernel.org/r/20210805094736.902-1-will@kernel.org

Changes since v1 are:

  * Move of_dma_set_restricted_buffer() into of/device.c (Rob)
  * Use IS_ENABLED() instead of 'static inline' stub (Rob)

This applies on Konrad's devel/for-linus-5.15 branch in swiotlb.git

Cheers,

Will

Cc: Claire Chang <tientzu@chromium.org>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Robin Murphy <robin.murphy@arm.com>

--->8

Will Deacon (2):
  of: Move of_dma_set_restricted_buffer() into device.c
  of: restricted dma: Don't fail device probe on rmem init failure

 drivers/of/address.c    | 33 ---------------------------------
 drivers/of/device.c     | 39 ++++++++++++++++++++++++++++++++++++++-
 drivers/of/of_private.h |  7 -------
 3 files changed, 38 insertions(+), 41 deletions(-)

-- 
2.33.0.rc1.237.g0d66db33f3-goog


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/2] of: Move of_dma_set_restricted_buffer() into device.c
  2021-08-16 13:26 [PATCH v2 0/2] Don't fail device probing due to of_dma_set_restricted_buffer() Will Deacon
@ 2021-08-16 13:26 ` Will Deacon
  2021-08-16 13:26 ` [PATCH v2 2/2] of: restricted dma: Don't fail device probe on rmem init failure Will Deacon
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Will Deacon @ 2021-08-16 13:26 UTC (permalink / raw)
  To: linux-kernel
  Cc: iommu, Will Deacon, Claire Chang, Konrad Rzeszutek Wilk,
	Christoph Hellwig, Rob Herring, Robin Murphy

Rob observes that:

  | of_dma_set_restricted_buffer() [...] should also be moved to
  | of/device.c. There's no reason for it to be in of/address.c. It has
  | nothing to do with address parsing.

Move it to of/device.c, as he suggests.

Cc: Claire Chang <tientzu@chromium.org>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Robin Murphy <robin.murphy@arm.com>
Suggested-by: Rob Herring <robh+dt@kernel.org>
Link: https://lore.kernel.org/r/CAL_JsqJ7ROWWJX84x2kEex9NQ8G+2=ybRuNOobX+j8bjZzSemQ@mail.gmail.com
Signed-off-by: Will Deacon <will@kernel.org>
---
 drivers/of/address.c    | 33 ---------------------------------
 drivers/of/device.c     | 34 ++++++++++++++++++++++++++++++++++
 drivers/of/of_private.h |  7 -------
 3 files changed, 34 insertions(+), 40 deletions(-)

diff --git a/drivers/of/address.c b/drivers/of/address.c
index 973257434398..94f017d808c4 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -8,7 +8,6 @@
 #include <linux/logic_pio.h>
 #include <linux/module.h>
 #include <linux/of_address.h>
-#include <linux/of_reserved_mem.h>
 #include <linux/pci.h>
 #include <linux/pci_regs.h>
 #include <linux/sizes.h>
@@ -996,38 +995,6 @@ int of_dma_get_range(struct device_node *np, const struct bus_dma_region **map)
 	of_node_put(node);
 	return ret;
 }
-
-int of_dma_set_restricted_buffer(struct device *dev, struct device_node *np)
-{
-	struct device_node *node, *of_node = dev->of_node;
-	int count, i;
-
-	count = of_property_count_elems_of_size(of_node, "memory-region",
-						sizeof(u32));
-	/*
-	 * If dev->of_node doesn't exist or doesn't contain memory-region, try
-	 * the OF node having DMA configuration.
-	 */
-	if (count <= 0) {
-		of_node = np;
-		count = of_property_count_elems_of_size(
-			of_node, "memory-region", sizeof(u32));
-	}
-
-	for (i = 0; i < count; i++) {
-		node = of_parse_phandle(of_node, "memory-region", i);
-		/*
-		 * There might be multiple memory regions, but only one
-		 * restricted-dma-pool region is allowed.
-		 */
-		if (of_device_is_compatible(node, "restricted-dma-pool") &&
-		    of_device_is_available(node))
-			return of_reserved_mem_device_init_by_idx(dev, of_node,
-								  i);
-	}
-
-	return 0;
-}
 #endif /* CONFIG_HAS_DMA */
 
 /**
diff --git a/drivers/of/device.c b/drivers/of/device.c
index 2defdca418ec..089c5b4b97fb 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -5,6 +5,7 @@
 #include <linux/of_device.h>
 #include <linux/of_address.h>
 #include <linux/of_iommu.h>
+#include <linux/of_reserved_mem.h>
 #include <linux/dma-direct.h> /* for bus_dma_region */
 #include <linux/dma-map-ops.h>
 #include <linux/init.h>
@@ -52,6 +53,39 @@ int of_device_add(struct platform_device *ofdev)
 	return device_add(&ofdev->dev);
 }
 
+static int
+of_dma_set_restricted_buffer(struct device *dev, struct device_node *np)
+{
+	struct device_node *node, *of_node = dev->of_node;
+	int count, i;
+
+	count = of_property_count_elems_of_size(of_node, "memory-region",
+						sizeof(u32));
+	/*
+	 * If dev->of_node doesn't exist or doesn't contain memory-region, try
+	 * the OF node having DMA configuration.
+	 */
+	if (count <= 0) {
+		of_node = np;
+		count = of_property_count_elems_of_size(
+			of_node, "memory-region", sizeof(u32));
+	}
+
+	for (i = 0; i < count; i++) {
+		node = of_parse_phandle(of_node, "memory-region", i);
+		/*
+		 * There might be multiple memory regions, but only one
+		 * restricted-dma-pool region is allowed.
+		 */
+		if (of_device_is_compatible(node, "restricted-dma-pool") &&
+		    of_device_is_available(node))
+			return of_reserved_mem_device_init_by_idx(dev, of_node,
+								  i);
+	}
+
+	return 0;
+}
+
 /**
  * of_dma_configure_id - Setup DMA configuration
  * @dev:	Device to apply DMA configuration
diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h
index f557bd22b0cf..631489f7f8c0 100644
--- a/drivers/of/of_private.h
+++ b/drivers/of/of_private.h
@@ -163,19 +163,12 @@ struct bus_dma_region;
 #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_HAS_DMA)
 int of_dma_get_range(struct device_node *np,
 		const struct bus_dma_region **map);
-int of_dma_set_restricted_buffer(struct device *dev, struct device_node *np);
 #else
 static inline int of_dma_get_range(struct device_node *np,
 		const struct bus_dma_region **map)
 {
 	return -ENODEV;
 }
-static inline int of_dma_set_restricted_buffer(struct device *dev,
-					       struct device_node *np)
-{
-	/* Do nothing, successfully. */
-	return 0;
-}
 #endif
 
 void fdt_init_reserved_mem(void);
-- 
2.33.0.rc1.237.g0d66db33f3-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] of: restricted dma: Don't fail device probe on rmem init failure
  2021-08-16 13:26 [PATCH v2 0/2] Don't fail device probing due to of_dma_set_restricted_buffer() Will Deacon
  2021-08-16 13:26 ` [PATCH v2 1/2] of: Move of_dma_set_restricted_buffer() into device.c Will Deacon
@ 2021-08-16 13:26 ` Will Deacon
  2021-08-16 19:40 ` [PATCH v2 0/2] Don't fail device probing due to of_dma_set_restricted_buffer() Rob Herring
  2021-08-23 10:47 ` Konrad Rzeszutek Wilk
  3 siblings, 0 replies; 6+ messages in thread
From: Will Deacon @ 2021-08-16 13:26 UTC (permalink / raw)
  To: linux-kernel
  Cc: iommu, Will Deacon, Claire Chang, Konrad Rzeszutek Wilk,
	Christoph Hellwig, Rob Herring, Robin Murphy

If CONFIG_DMA_RESTRICTED_POOL=n then probing a device with a reference
to a "restricted-dma-pool" will fail with a reasonably cryptic error:

  | pci-host-generic: probe of 10000.pci failed with error -22

Rework of_dma_set_restricted_buffer() so that it does not cause probing
failure and instead either returns early if CONFIG_DMA_RESTRICTED_POOL=n
or emits a diagnostic if the reserved DMA pool fails to initialise.

Cc: Claire Chang <tientzu@chromium.org>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Will Deacon <will@kernel.org>
---
 drivers/of/device.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/of/device.c b/drivers/of/device.c
index 089c5b4b97fb..5b043ee30824 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -53,12 +53,15 @@ int of_device_add(struct platform_device *ofdev)
 	return device_add(&ofdev->dev);
 }
 
-static int
+static void
 of_dma_set_restricted_buffer(struct device *dev, struct device_node *np)
 {
 	struct device_node *node, *of_node = dev->of_node;
 	int count, i;
 
+	if (!IS_ENABLED(CONFIG_DMA_RESTRICTED_POOL))
+		return;
+
 	count = of_property_count_elems_of_size(of_node, "memory-region",
 						sizeof(u32));
 	/*
@@ -79,11 +82,11 @@ of_dma_set_restricted_buffer(struct device *dev, struct device_node *np)
 		 */
 		if (of_device_is_compatible(node, "restricted-dma-pool") &&
 		    of_device_is_available(node))
-			return of_reserved_mem_device_init_by_idx(dev, of_node,
-								  i);
+			break;
 	}
 
-	return 0;
+	if (i != count && of_reserved_mem_device_init_by_idx(dev, of_node, i))
+		dev_warn(dev, "failed to initialise \"restricted-dma-pool\" memory node\n");
 }
 
 /**
@@ -200,7 +203,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 	arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
 
 	if (!iommu)
-		return of_dma_set_restricted_buffer(dev, np);
+		of_dma_set_restricted_buffer(dev, np);
 
 	return 0;
 }
-- 
2.33.0.rc1.237.g0d66db33f3-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/2] Don't fail device probing due to of_dma_set_restricted_buffer()
  2021-08-16 13:26 [PATCH v2 0/2] Don't fail device probing due to of_dma_set_restricted_buffer() Will Deacon
  2021-08-16 13:26 ` [PATCH v2 1/2] of: Move of_dma_set_restricted_buffer() into device.c Will Deacon
  2021-08-16 13:26 ` [PATCH v2 2/2] of: restricted dma: Don't fail device probe on rmem init failure Will Deacon
@ 2021-08-16 19:40 ` Rob Herring
  2021-08-23 10:47 ` Konrad Rzeszutek Wilk
  3 siblings, 0 replies; 6+ messages in thread
From: Rob Herring @ 2021-08-16 19:40 UTC (permalink / raw)
  To: Will Deacon
  Cc: linux-kernel, Linux IOMMU, Claire Chang, Konrad Rzeszutek Wilk,
	Christoph Hellwig, Robin Murphy

On Mon, Aug 16, 2021 at 8:26 AM Will Deacon <will@kernel.org> wrote:
>
> Hi all,
>
> This is v2 of the patch I previously posted here:
>
>   https://lore.kernel.org/r/20210805094736.902-1-will@kernel.org
>
> Changes since v1 are:
>
>   * Move of_dma_set_restricted_buffer() into of/device.c (Rob)
>   * Use IS_ENABLED() instead of 'static inline' stub (Rob)
>
> This applies on Konrad's devel/for-linus-5.15 branch in swiotlb.git
>
> Cheers,
>
> Will
>
> Cc: Claire Chang <tientzu@chromium.org>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Robin Murphy <robin.murphy@arm.com>
>
> --->8
>
> Will Deacon (2):
>   of: Move of_dma_set_restricted_buffer() into device.c
>   of: restricted dma: Don't fail device probe on rmem init failure
>
>  drivers/of/address.c    | 33 ---------------------------------
>  drivers/of/device.c     | 39 ++++++++++++++++++++++++++++++++++++++-
>  drivers/of/of_private.h |  7 -------
>  3 files changed, 38 insertions(+), 41 deletions(-)

Reviewed-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/2] Don't fail device probing due to of_dma_set_restricted_buffer()
  2021-08-16 13:26 [PATCH v2 0/2] Don't fail device probing due to of_dma_set_restricted_buffer() Will Deacon
                   ` (2 preceding siblings ...)
  2021-08-16 19:40 ` [PATCH v2 0/2] Don't fail device probing due to of_dma_set_restricted_buffer() Rob Herring
@ 2021-08-23 10:47 ` Konrad Rzeszutek Wilk
  2021-08-23 12:40   ` Will Deacon
  3 siblings, 1 reply; 6+ messages in thread
From: Konrad Rzeszutek Wilk @ 2021-08-23 10:47 UTC (permalink / raw)
  To: Will Deacon
  Cc: linux-kernel, iommu, Claire Chang, Christoph Hellwig,
	Rob Herring, Robin Murphy

On Mon, Aug 16, 2021 at 02:26:15PM +0100, Will Deacon wrote:
> Hi all,
> 
> This is v2 of the patch I previously posted here:
> 
>   https://lore.kernel.org/r/20210805094736.902-1-will@kernel.org
> 
> Changes since v1 are:
> 
>   * Move of_dma_set_restricted_buffer() into of/device.c (Rob)
>   * Use IS_ENABLED() instead of 'static inline' stub (Rob)
> 
> This applies on Konrad's devel/for-linus-5.15 branch in swiotlb.git

It should show up later today.

Thanks!
> 
> Cheers,
> 
> Will
> 
> Cc: Claire Chang <tientzu@chromium.org>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Robin Murphy <robin.murphy@arm.com>
> 
> --->8
> 
> Will Deacon (2):
>   of: Move of_dma_set_restricted_buffer() into device.c
>   of: restricted dma: Don't fail device probe on rmem init failure
> 
>  drivers/of/address.c    | 33 ---------------------------------
>  drivers/of/device.c     | 39 ++++++++++++++++++++++++++++++++++++++-
>  drivers/of/of_private.h |  7 -------
>  3 files changed, 38 insertions(+), 41 deletions(-)
> 
> -- 
> 2.33.0.rc1.237.g0d66db33f3-goog
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/2] Don't fail device probing due to of_dma_set_restricted_buffer()
  2021-08-23 10:47 ` Konrad Rzeszutek Wilk
@ 2021-08-23 12:40   ` Will Deacon
  0 siblings, 0 replies; 6+ messages in thread
From: Will Deacon @ 2021-08-23 12:40 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: linux-kernel, iommu, Claire Chang, Christoph Hellwig,
	Rob Herring, Robin Murphy

On Mon, Aug 23, 2021 at 06:47:19AM -0400, Konrad Rzeszutek Wilk wrote:
> On Mon, Aug 16, 2021 at 02:26:15PM +0100, Will Deacon wrote:
> > Hi all,
> > 
> > This is v2 of the patch I previously posted here:
> > 
> >   https://lore.kernel.org/r/20210805094736.902-1-will@kernel.org
> > 
> > Changes since v1 are:
> > 
> >   * Move of_dma_set_restricted_buffer() into of/device.c (Rob)
> >   * Use IS_ENABLED() instead of 'static inline' stub (Rob)
> > 
> > This applies on Konrad's devel/for-linus-5.15 branch in swiotlb.git
> 
> It should show up later today.

Brill, thanks Konrad!

Will

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-08-23 12:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-16 13:26 [PATCH v2 0/2] Don't fail device probing due to of_dma_set_restricted_buffer() Will Deacon
2021-08-16 13:26 ` [PATCH v2 1/2] of: Move of_dma_set_restricted_buffer() into device.c Will Deacon
2021-08-16 13:26 ` [PATCH v2 2/2] of: restricted dma: Don't fail device probe on rmem init failure Will Deacon
2021-08-16 19:40 ` [PATCH v2 0/2] Don't fail device probing due to of_dma_set_restricted_buffer() Rob Herring
2021-08-23 10:47 ` Konrad Rzeszutek Wilk
2021-08-23 12:40   ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).