All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] libnvdimm/of_pmem: handle memory-region in DT
@ 2020-02-22 18:30 ` Alistair Delva
  0 siblings, 0 replies; 12+ messages in thread
From: Alistair Delva @ 2020-02-22 18:30 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kenny Root, Rob Herring, devicetree, linux-nvdimm, kernel-team

From: Kenny Root <kroot@google.com>

Add support for parsing the 'memory-region' DT property in addition to
the 'reg' DT property. This enables use cases where the pmem region is
not in I/O address space or dedicated memory (e.g. a bootloader
carveout).

Signed-off-by: Kenny Root <kroot@google.com>
Signed-off-by: Alistair Delva <adelva@google.com>
Cc: "Oliver O'Halloran" <oohall@gmail.com>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: devicetree@vger.kernel.org
Cc: linux-nvdimm@lists.01.org
Cc: kernel-team@android.com
---
 drivers/nvdimm/of_pmem.c | 75 ++++++++++++++++++++++++++--------------
 1 file changed, 50 insertions(+), 25 deletions(-)

diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
index 8224d1431ea9..a68e44fb0041 100644
--- a/drivers/nvdimm/of_pmem.c
+++ b/drivers/nvdimm/of_pmem.c
@@ -14,13 +14,47 @@ struct of_pmem_private {
 	struct nvdimm_bus *bus;
 };
 
+static void of_pmem_register_region(struct platform_device *pdev,
+				    struct nvdimm_bus *bus,
+				    struct device_node *np,
+				    struct resource *res, bool is_volatile)
+{
+	struct nd_region_desc ndr_desc;
+	struct nd_region *region;
+
+	/*
+	 * NB: libnvdimm copies the data from ndr_desc into it's own
+	 * structures so passing a stack pointer is fine.
+	 */
+	memset(&ndr_desc, 0, sizeof(ndr_desc));
+	ndr_desc.numa_node = dev_to_node(&pdev->dev);
+	ndr_desc.target_node = ndr_desc.numa_node;
+	ndr_desc.res = res;
+	ndr_desc.of_node = np;
+	set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
+
+	if (is_volatile)
+		region = nvdimm_volatile_region_create(bus, &ndr_desc);
+	else
+		region = nvdimm_pmem_region_create(bus, &ndr_desc);
+
+	if (!region)
+		dev_warn(&pdev->dev,
+			 "Unable to register region %pR from %pOF\n",
+			 ndr_desc.res, np);
+	else
+		dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
+			ndr_desc.res, np);
+}
+
 static int of_pmem_region_probe(struct platform_device *pdev)
 {
 	struct of_pmem_private *priv;
-	struct device_node *np;
+	struct device_node *mrp, *np;
 	struct nvdimm_bus *bus;
+	struct resource res;
 	bool is_volatile;
-	int i;
+	int i, ret;
 
 	np = dev_of_node(&pdev->dev);
 	if (!np)
@@ -46,31 +80,22 @@ static int of_pmem_region_probe(struct platform_device *pdev)
 			is_volatile ? "volatile" : "non-volatile",  np);
 
 	for (i = 0; i < pdev->num_resources; i++) {
-		struct nd_region_desc ndr_desc;
-		struct nd_region *region;
-
-		/*
-		 * NB: libnvdimm copies the data from ndr_desc into it's own
-		 * structures so passing a stack pointer is fine.
-		 */
-		memset(&ndr_desc, 0, sizeof(ndr_desc));
-		ndr_desc.numa_node = dev_to_node(&pdev->dev);
-		ndr_desc.target_node = ndr_desc.numa_node;
-		ndr_desc.res = &pdev->resource[i];
-		ndr_desc.of_node = np;
-		set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
-
-		if (is_volatile)
-			region = nvdimm_volatile_region_create(bus, &ndr_desc);
-		else
-			region = nvdimm_pmem_region_create(bus, &ndr_desc);
+		of_pmem_register_region(pdev, bus, np, &pdev->resource[i],
+					is_volatile);
+	}
 
-		if (!region)
-			dev_warn(&pdev->dev, "Unable to register region %pR from %pOF\n",
-					ndr_desc.res, np);
+	i = 0;
+	while ((mr_np = of_parse_phandle(np, "memory-region", i++))) {
+		ret = of_address_to_resource(mr_np, 0, &res);
+		if (ret)
+			dev_warn(
+				&pdev->dev,
+				"Unable to acquire memory-region from %pOF: %d\n",
+				mr_np, ret);
 		else
-			dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
-					ndr_desc.res, np);
+			of_pmem_register_region(pdev, bus, np, &res,
+						is_volatile);
+		of_node_put(mr_np);
 	}
 
 	return 0;
-- 
2.25.0.265.gbab2e86ba0-goog
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

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

* [PATCH 1/2] libnvdimm/of_pmem: handle memory-region in DT
@ 2020-02-22 18:30 ` Alistair Delva
  0 siblings, 0 replies; 12+ messages in thread
From: Alistair Delva @ 2020-02-22 18:30 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kenny Root, Oliver O'Halloran, Rob Herring, Dan Williams,
	Vishal Verma, Dave Jiang, Ira Weiny, devicetree, linux-nvdimm,
	kernel-team

From: Kenny Root <kroot@google.com>

Add support for parsing the 'memory-region' DT property in addition to
the 'reg' DT property. This enables use cases where the pmem region is
not in I/O address space or dedicated memory (e.g. a bootloader
carveout).

Signed-off-by: Kenny Root <kroot@google.com>
Signed-off-by: Alistair Delva <adelva@google.com>
Cc: "Oliver O'Halloran" <oohall@gmail.com>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: devicetree@vger.kernel.org
Cc: linux-nvdimm@lists.01.org
Cc: kernel-team@android.com
---
 drivers/nvdimm/of_pmem.c | 75 ++++++++++++++++++++++++++--------------
 1 file changed, 50 insertions(+), 25 deletions(-)

diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
index 8224d1431ea9..a68e44fb0041 100644
--- a/drivers/nvdimm/of_pmem.c
+++ b/drivers/nvdimm/of_pmem.c
@@ -14,13 +14,47 @@ struct of_pmem_private {
 	struct nvdimm_bus *bus;
 };
 
+static void of_pmem_register_region(struct platform_device *pdev,
+				    struct nvdimm_bus *bus,
+				    struct device_node *np,
+				    struct resource *res, bool is_volatile)
+{
+	struct nd_region_desc ndr_desc;
+	struct nd_region *region;
+
+	/*
+	 * NB: libnvdimm copies the data from ndr_desc into it's own
+	 * structures so passing a stack pointer is fine.
+	 */
+	memset(&ndr_desc, 0, sizeof(ndr_desc));
+	ndr_desc.numa_node = dev_to_node(&pdev->dev);
+	ndr_desc.target_node = ndr_desc.numa_node;
+	ndr_desc.res = res;
+	ndr_desc.of_node = np;
+	set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
+
+	if (is_volatile)
+		region = nvdimm_volatile_region_create(bus, &ndr_desc);
+	else
+		region = nvdimm_pmem_region_create(bus, &ndr_desc);
+
+	if (!region)
+		dev_warn(&pdev->dev,
+			 "Unable to register region %pR from %pOF\n",
+			 ndr_desc.res, np);
+	else
+		dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
+			ndr_desc.res, np);
+}
+
 static int of_pmem_region_probe(struct platform_device *pdev)
 {
 	struct of_pmem_private *priv;
-	struct device_node *np;
+	struct device_node *mrp, *np;
 	struct nvdimm_bus *bus;
+	struct resource res;
 	bool is_volatile;
-	int i;
+	int i, ret;
 
 	np = dev_of_node(&pdev->dev);
 	if (!np)
@@ -46,31 +80,22 @@ static int of_pmem_region_probe(struct platform_device *pdev)
 			is_volatile ? "volatile" : "non-volatile",  np);
 
 	for (i = 0; i < pdev->num_resources; i++) {
-		struct nd_region_desc ndr_desc;
-		struct nd_region *region;
-
-		/*
-		 * NB: libnvdimm copies the data from ndr_desc into it's own
-		 * structures so passing a stack pointer is fine.
-		 */
-		memset(&ndr_desc, 0, sizeof(ndr_desc));
-		ndr_desc.numa_node = dev_to_node(&pdev->dev);
-		ndr_desc.target_node = ndr_desc.numa_node;
-		ndr_desc.res = &pdev->resource[i];
-		ndr_desc.of_node = np;
-		set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
-
-		if (is_volatile)
-			region = nvdimm_volatile_region_create(bus, &ndr_desc);
-		else
-			region = nvdimm_pmem_region_create(bus, &ndr_desc);
+		of_pmem_register_region(pdev, bus, np, &pdev->resource[i],
+					is_volatile);
+	}
 
-		if (!region)
-			dev_warn(&pdev->dev, "Unable to register region %pR from %pOF\n",
-					ndr_desc.res, np);
+	i = 0;
+	while ((mr_np = of_parse_phandle(np, "memory-region", i++))) {
+		ret = of_address_to_resource(mr_np, 0, &res);
+		if (ret)
+			dev_warn(
+				&pdev->dev,
+				"Unable to acquire memory-region from %pOF: %d\n",
+				mr_np, ret);
 		else
-			dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
-					ndr_desc.res, np);
+			of_pmem_register_region(pdev, bus, np, &res,
+						is_volatile);
+		of_node_put(mr_np);
 	}
 
 	return 0;
-- 
2.25.0.265.gbab2e86ba0-goog


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

* [PATCH 2/2] dt-bindings: pmem-region: Document memory-region
  2020-02-22 18:30 ` Alistair Delva
@ 2020-02-22 18:30   ` Alistair Delva
  -1 siblings, 0 replies; 12+ messages in thread
From: Alistair Delva @ 2020-02-22 18:30 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kenny Root, Rob Herring, devicetree, linux-nvdimm, kernel-team

From: Kenny Root <kroot@google.com>

Add documentation and example for memory-region in pmem.

Signed-off-by: Kenny Root <kroot@google.com>
Signed-off-by: Alistair Delva <adelva@google.com>
Cc: "Oliver O'Halloran" <oohall@gmail.com>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: devicetree@vger.kernel.org
Cc: linux-nvdimm@lists.01.org
Cc: kernel-team@android.com
---
 .../devicetree/bindings/pmem/pmem-region.txt  | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/Documentation/devicetree/bindings/pmem/pmem-region.txt b/Documentation/devicetree/bindings/pmem/pmem-region.txt
index 5cfa4f016a00..851ffa71967e 100644
--- a/Documentation/devicetree/bindings/pmem/pmem-region.txt
+++ b/Documentation/devicetree/bindings/pmem/pmem-region.txt
@@ -29,6 +29,18 @@ Required properties:
 		in a separate device node. Having multiple address ranges in a
 		node implies no special relationship between the two ranges.
 
+		This property may be replaced or supplemented with a
+		memory-region property. Only one of reg or memory-region
+		properties is required.
+
+	- memory-region:
+		Reference to the reserved memory node. The reserved memory
+		node should be defined as per the bindings in
+		reserved-memory.txt
+
+		This property may be replaced or supplemented with a reg
+		property. Only one of reg or memory-region is required.
+
 Optional properties:
 	- Any relevant NUMA assocativity properties for the target platform.
 
@@ -63,3 +75,21 @@ Examples:
 		volatile;
 	};
 
+
+	/*
+	 * This example uses a reserved-memory entry instead of
+	 * specifying the memory region directly in the node.
+	 */
+
+	reserved-memory {
+		pmem_1: pmem@5000 {
+			no-map;
+			reg = <0x00005000 0x00001000>;
+		};
+	};
+
+	pmem@1 {
+		compatible = "pmem-region";
+		memory-region = <&pmem_1>;
+	};
+
-- 
2.25.0.265.gbab2e86ba0-goog
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

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

* [PATCH 2/2] dt-bindings: pmem-region: Document memory-region
@ 2020-02-22 18:30   ` Alistair Delva
  0 siblings, 0 replies; 12+ messages in thread
From: Alistair Delva @ 2020-02-22 18:30 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kenny Root, Oliver O'Halloran, Rob Herring, Dan Williams,
	Vishal Verma, Dave Jiang, Ira Weiny, devicetree, linux-nvdimm,
	kernel-team

From: Kenny Root <kroot@google.com>

Add documentation and example for memory-region in pmem.

Signed-off-by: Kenny Root <kroot@google.com>
Signed-off-by: Alistair Delva <adelva@google.com>
Cc: "Oliver O'Halloran" <oohall@gmail.com>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: devicetree@vger.kernel.org
Cc: linux-nvdimm@lists.01.org
Cc: kernel-team@android.com
---
 .../devicetree/bindings/pmem/pmem-region.txt  | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/Documentation/devicetree/bindings/pmem/pmem-region.txt b/Documentation/devicetree/bindings/pmem/pmem-region.txt
index 5cfa4f016a00..851ffa71967e 100644
--- a/Documentation/devicetree/bindings/pmem/pmem-region.txt
+++ b/Documentation/devicetree/bindings/pmem/pmem-region.txt
@@ -29,6 +29,18 @@ Required properties:
 		in a separate device node. Having multiple address ranges in a
 		node implies no special relationship between the two ranges.
 
+		This property may be replaced or supplemented with a
+		memory-region property. Only one of reg or memory-region
+		properties is required.
+
+	- memory-region:
+		Reference to the reserved memory node. The reserved memory
+		node should be defined as per the bindings in
+		reserved-memory.txt
+
+		This property may be replaced or supplemented with a reg
+		property. Only one of reg or memory-region is required.
+
 Optional properties:
 	- Any relevant NUMA assocativity properties for the target platform.
 
@@ -63,3 +75,21 @@ Examples:
 		volatile;
 	};
 
+
+	/*
+	 * This example uses a reserved-memory entry instead of
+	 * specifying the memory region directly in the node.
+	 */
+
+	reserved-memory {
+		pmem_1: pmem@5000 {
+			no-map;
+			reg = <0x00005000 0x00001000>;
+		};
+	};
+
+	pmem@1 {
+		compatible = "pmem-region";
+		memory-region = <&pmem_1>;
+	};
+
-- 
2.25.0.265.gbab2e86ba0-goog


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

* Re: [PATCH 1/2] libnvdimm/of_pmem: handle memory-region in DT
  2020-02-22 18:30 ` Alistair Delva
@ 2020-02-23 14:56   ` Ira Weiny
  -1 siblings, 0 replies; 12+ messages in thread
From: Ira Weiny @ 2020-02-23 14:56 UTC (permalink / raw)
  To: Alistair Delva
  Cc: linux-kernel, Kenny Root, Rob Herring, devicetree, linux-nvdimm,
	kernel-team

On Sat, Feb 22, 2020 at 10:30:09AM -0800, Alistair Delva wrote:
> From: Kenny Root <kroot@google.com>
> 
> Add support for parsing the 'memory-region' DT property in addition to
> the 'reg' DT property. This enables use cases where the pmem region is
> not in I/O address space or dedicated memory (e.g. a bootloader
> carveout).
> 
> Signed-off-by: Kenny Root <kroot@google.com>
> Signed-off-by: Alistair Delva <adelva@google.com>
> Cc: "Oliver O'Halloran" <oohall@gmail.com>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: Vishal Verma <vishal.l.verma@intel.com>
> Cc: Dave Jiang <dave.jiang@intel.com>
> Cc: Ira Weiny <ira.weiny@intel.com>
> Cc: devicetree@vger.kernel.org
> Cc: linux-nvdimm@lists.01.org
> Cc: kernel-team@android.com
> ---
>  drivers/nvdimm/of_pmem.c | 75 ++++++++++++++++++++++++++--------------
>  1 file changed, 50 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
> index 8224d1431ea9..a68e44fb0041 100644
> --- a/drivers/nvdimm/of_pmem.c
> +++ b/drivers/nvdimm/of_pmem.c
> @@ -14,13 +14,47 @@ struct of_pmem_private {
>  	struct nvdimm_bus *bus;
>  };
>  
> +static void of_pmem_register_region(struct platform_device *pdev,
> +				    struct nvdimm_bus *bus,
> +				    struct device_node *np,
> +				    struct resource *res, bool is_volatile)

FWIW it would be easier to review if this was splut into a patch which created
the helper of_pmem_register_region() without the new logic.  Then added the new
logic here.

> +{
> +	struct nd_region_desc ndr_desc;
> +	struct nd_region *region;
> +
> +	/*
> +	 * NB: libnvdimm copies the data from ndr_desc into it's own
> +	 * structures so passing a stack pointer is fine.
> +	 */
> +	memset(&ndr_desc, 0, sizeof(ndr_desc));
> +	ndr_desc.numa_node = dev_to_node(&pdev->dev);
> +	ndr_desc.target_node = ndr_desc.numa_node;
> +	ndr_desc.res = res;
> +	ndr_desc.of_node = np;
> +	set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
> +
> +	if (is_volatile)
> +		region = nvdimm_volatile_region_create(bus, &ndr_desc);
> +	else
> +		region = nvdimm_pmem_region_create(bus, &ndr_desc);
> +
> +	if (!region)
> +		dev_warn(&pdev->dev,
> +			 "Unable to register region %pR from %pOF\n",
> +			 ndr_desc.res, np);
> +	else
> +		dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
> +			ndr_desc.res, np);
> +}
> +
>  static int of_pmem_region_probe(struct platform_device *pdev)
>  {
>  	struct of_pmem_private *priv;
> -	struct device_node *np;
> +	struct device_node *mrp, *np;
>  	struct nvdimm_bus *bus;
> +	struct resource res;
>  	bool is_volatile;
> -	int i;
> +	int i, ret;
>  
>  	np = dev_of_node(&pdev->dev);
>  	if (!np)
> @@ -46,31 +80,22 @@ static int of_pmem_region_probe(struct platform_device *pdev)
>  			is_volatile ? "volatile" : "non-volatile",  np);
>  
>  	for (i = 0; i < pdev->num_resources; i++) {
> -		struct nd_region_desc ndr_desc;
> -		struct nd_region *region;
> -
> -		/*
> -		 * NB: libnvdimm copies the data from ndr_desc into it's own
> -		 * structures so passing a stack pointer is fine.
> -		 */
> -		memset(&ndr_desc, 0, sizeof(ndr_desc));
> -		ndr_desc.numa_node = dev_to_node(&pdev->dev);
> -		ndr_desc.target_node = ndr_desc.numa_node;
> -		ndr_desc.res = &pdev->resource[i];
> -		ndr_desc.of_node = np;
> -		set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
> -
> -		if (is_volatile)
> -			region = nvdimm_volatile_region_create(bus, &ndr_desc);
> -		else
> -			region = nvdimm_pmem_region_create(bus, &ndr_desc);
> +		of_pmem_register_region(pdev, bus, np, &pdev->resource[i],
> +					is_volatile);
> +	}
>  
> -		if (!region)
> -			dev_warn(&pdev->dev, "Unable to register region %pR from %pOF\n",
> -					ndr_desc.res, np);
> +	i = 0;
> +	while ((mr_np = of_parse_phandle(np, "memory-region", i++))) {
> +		ret = of_address_to_resource(mr_np, 0, &res);
> +		if (ret)
> +			dev_warn(
> +				&pdev->dev,
> +				"Unable to acquire memory-region from %pOF: %d\n",
> +				mr_np, ret);
>  		else
> -			dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
> -					ndr_desc.res, np);
> +			of_pmem_register_region(pdev, bus, np, &res,
> +						is_volatile);
> +		of_node_put(mr_np);

Why of_node_put()?

Ira
>  	}
>  
>  	return 0;
> -- 
> 2.25.0.265.gbab2e86ba0-goog
> 
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

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

* Re: [PATCH 1/2] libnvdimm/of_pmem: handle memory-region in DT
@ 2020-02-23 14:56   ` Ira Weiny
  0 siblings, 0 replies; 12+ messages in thread
From: Ira Weiny @ 2020-02-23 14:56 UTC (permalink / raw)
  To: Alistair Delva
  Cc: linux-kernel, Kenny Root, Oliver O'Halloran, Rob Herring,
	Dan Williams, Vishal Verma, Dave Jiang, devicetree, linux-nvdimm,
	kernel-team

On Sat, Feb 22, 2020 at 10:30:09AM -0800, Alistair Delva wrote:
> From: Kenny Root <kroot@google.com>
> 
> Add support for parsing the 'memory-region' DT property in addition to
> the 'reg' DT property. This enables use cases where the pmem region is
> not in I/O address space or dedicated memory (e.g. a bootloader
> carveout).
> 
> Signed-off-by: Kenny Root <kroot@google.com>
> Signed-off-by: Alistair Delva <adelva@google.com>
> Cc: "Oliver O'Halloran" <oohall@gmail.com>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: Vishal Verma <vishal.l.verma@intel.com>
> Cc: Dave Jiang <dave.jiang@intel.com>
> Cc: Ira Weiny <ira.weiny@intel.com>
> Cc: devicetree@vger.kernel.org
> Cc: linux-nvdimm@lists.01.org
> Cc: kernel-team@android.com
> ---
>  drivers/nvdimm/of_pmem.c | 75 ++++++++++++++++++++++++++--------------
>  1 file changed, 50 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
> index 8224d1431ea9..a68e44fb0041 100644
> --- a/drivers/nvdimm/of_pmem.c
> +++ b/drivers/nvdimm/of_pmem.c
> @@ -14,13 +14,47 @@ struct of_pmem_private {
>  	struct nvdimm_bus *bus;
>  };
>  
> +static void of_pmem_register_region(struct platform_device *pdev,
> +				    struct nvdimm_bus *bus,
> +				    struct device_node *np,
> +				    struct resource *res, bool is_volatile)

FWIW it would be easier to review if this was splut into a patch which created
the helper of_pmem_register_region() without the new logic.  Then added the new
logic here.

> +{
> +	struct nd_region_desc ndr_desc;
> +	struct nd_region *region;
> +
> +	/*
> +	 * NB: libnvdimm copies the data from ndr_desc into it's own
> +	 * structures so passing a stack pointer is fine.
> +	 */
> +	memset(&ndr_desc, 0, sizeof(ndr_desc));
> +	ndr_desc.numa_node = dev_to_node(&pdev->dev);
> +	ndr_desc.target_node = ndr_desc.numa_node;
> +	ndr_desc.res = res;
> +	ndr_desc.of_node = np;
> +	set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
> +
> +	if (is_volatile)
> +		region = nvdimm_volatile_region_create(bus, &ndr_desc);
> +	else
> +		region = nvdimm_pmem_region_create(bus, &ndr_desc);
> +
> +	if (!region)
> +		dev_warn(&pdev->dev,
> +			 "Unable to register region %pR from %pOF\n",
> +			 ndr_desc.res, np);
> +	else
> +		dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
> +			ndr_desc.res, np);
> +}
> +
>  static int of_pmem_region_probe(struct platform_device *pdev)
>  {
>  	struct of_pmem_private *priv;
> -	struct device_node *np;
> +	struct device_node *mrp, *np;
>  	struct nvdimm_bus *bus;
> +	struct resource res;
>  	bool is_volatile;
> -	int i;
> +	int i, ret;
>  
>  	np = dev_of_node(&pdev->dev);
>  	if (!np)
> @@ -46,31 +80,22 @@ static int of_pmem_region_probe(struct platform_device *pdev)
>  			is_volatile ? "volatile" : "non-volatile",  np);
>  
>  	for (i = 0; i < pdev->num_resources; i++) {
> -		struct nd_region_desc ndr_desc;
> -		struct nd_region *region;
> -
> -		/*
> -		 * NB: libnvdimm copies the data from ndr_desc into it's own
> -		 * structures so passing a stack pointer is fine.
> -		 */
> -		memset(&ndr_desc, 0, sizeof(ndr_desc));
> -		ndr_desc.numa_node = dev_to_node(&pdev->dev);
> -		ndr_desc.target_node = ndr_desc.numa_node;
> -		ndr_desc.res = &pdev->resource[i];
> -		ndr_desc.of_node = np;
> -		set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
> -
> -		if (is_volatile)
> -			region = nvdimm_volatile_region_create(bus, &ndr_desc);
> -		else
> -			region = nvdimm_pmem_region_create(bus, &ndr_desc);
> +		of_pmem_register_region(pdev, bus, np, &pdev->resource[i],
> +					is_volatile);
> +	}
>  
> -		if (!region)
> -			dev_warn(&pdev->dev, "Unable to register region %pR from %pOF\n",
> -					ndr_desc.res, np);
> +	i = 0;
> +	while ((mr_np = of_parse_phandle(np, "memory-region", i++))) {
> +		ret = of_address_to_resource(mr_np, 0, &res);
> +		if (ret)
> +			dev_warn(
> +				&pdev->dev,
> +				"Unable to acquire memory-region from %pOF: %d\n",
> +				mr_np, ret);
>  		else
> -			dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
> -					ndr_desc.res, np);
> +			of_pmem_register_region(pdev, bus, np, &res,
> +						is_volatile);
> +		of_node_put(mr_np);

Why of_node_put()?

Ira
>  	}
>  
>  	return 0;
> -- 
> 2.25.0.265.gbab2e86ba0-goog
> 

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

* Re: [PATCH 1/2] libnvdimm/of_pmem: handle memory-region in DT
  2020-02-22 18:30 ` Alistair Delva
@ 2020-02-24  1:30   ` Oliver O'Halloran
  -1 siblings, 0 replies; 12+ messages in thread
From: Oliver O'Halloran @ 2020-02-24  1:30 UTC (permalink / raw)
  To: Alistair Delva
  Cc: Linux Kernel Mailing List, Kenny Root, Rob Herring, Device Tree,
	linux-nvdimm, kernel-team

On Sun, Feb 23, 2020 at 5:30 AM Alistair Delva <adelva@google.com> wrote:
>
> From: Kenny Root <kroot@google.com>
>
> Add support for parsing the 'memory-region' DT property in addition to
> the 'reg' DT property. This enables use cases where the pmem region is
> not in I/O address space or dedicated memory (e.g. a bootloader
> carveout).
>
> Signed-off-by: Kenny Root <kroot@google.com>
> Signed-off-by: Alistair Delva <adelva@google.com>
> Cc: "Oliver O'Halloran" <oohall@gmail.com>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: Vishal Verma <vishal.l.verma@intel.com>
> Cc: Dave Jiang <dave.jiang@intel.com>
> Cc: Ira Weiny <ira.weiny@intel.com>
> Cc: devicetree@vger.kernel.org
> Cc: linux-nvdimm@lists.01.org
> Cc: kernel-team@android.com
> ---
>  drivers/nvdimm/of_pmem.c | 75 ++++++++++++++++++++++++++--------------
>  1 file changed, 50 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
> index 8224d1431ea9..a68e44fb0041 100644
> --- a/drivers/nvdimm/of_pmem.c
> +++ b/drivers/nvdimm/of_pmem.c
> @@ -14,13 +14,47 @@ struct of_pmem_private {
>         struct nvdimm_bus *bus;
>  };
>
> +static void of_pmem_register_region(struct platform_device *pdev,
> +                                   struct nvdimm_bus *bus,
> +                                   struct device_node *np,
> +                                   struct resource *res, bool is_volatile)
> +{
> +       struct nd_region_desc ndr_desc;
> +       struct nd_region *region;
> +
> +       /*
> +        * NB: libnvdimm copies the data from ndr_desc into it's own
> +        * structures so passing a stack pointer is fine.
> +        */
> +       memset(&ndr_desc, 0, sizeof(ndr_desc));
> +       ndr_desc.numa_node = dev_to_node(&pdev->dev);
> +       ndr_desc.target_node = ndr_desc.numa_node;
> +       ndr_desc.res = res;
> +       ndr_desc.of_node = np;
> +       set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
> +
> +       if (is_volatile)
> +               region = nvdimm_volatile_region_create(bus, &ndr_desc);
> +       else
> +               region = nvdimm_pmem_region_create(bus, &ndr_desc);
> +
> +       if (!region)
> +               dev_warn(&pdev->dev,
> +                        "Unable to register region %pR from %pOF\n",
> +                        ndr_desc.res, np);
> +       else
> +               dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
> +                       ndr_desc.res, np);
> +}
> +
>  static int of_pmem_region_probe(struct platform_device *pdev)
>  {
>         struct of_pmem_private *priv;
> -       struct device_node *np;
> +       struct device_node *mrp, *np;
>         struct nvdimm_bus *bus;
> +       struct resource res;
>         bool is_volatile;
> -       int i;
> +       int i, ret;
>
>         np = dev_of_node(&pdev->dev);
>         if (!np)
> @@ -46,31 +80,22 @@ static int of_pmem_region_probe(struct platform_device *pdev)
>                         is_volatile ? "volatile" : "non-volatile",  np);
>
>         for (i = 0; i < pdev->num_resources; i++) {
> -               struct nd_region_desc ndr_desc;
> -               struct nd_region *region;
> -
> -               /*
> -                * NB: libnvdimm copies the data from ndr_desc into it's own
> -                * structures so passing a stack pointer is fine.
> -                */
> -               memset(&ndr_desc, 0, sizeof(ndr_desc));
> -               ndr_desc.numa_node = dev_to_node(&pdev->dev);
> -               ndr_desc.target_node = ndr_desc.numa_node;
> -               ndr_desc.res = &pdev->resource[i];
> -               ndr_desc.of_node = np;
> -               set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
> -
> -               if (is_volatile)
> -                       region = nvdimm_volatile_region_create(bus, &ndr_desc);
> -               else
> -                       region = nvdimm_pmem_region_create(bus, &ndr_desc);
> +               of_pmem_register_region(pdev, bus, np, &pdev->resource[i],
> +                                       is_volatile);
> +       }
>
> -               if (!region)
> -                       dev_warn(&pdev->dev, "Unable to register region %pR from %pOF\n",
> -                                       ndr_desc.res, np);
> +       i = 0;
> +       while ((mr_np = of_parse_phandle(np, "memory-region", i++))) {

Doesn't compile since the the iteration variable is declared above as
"mrp" rather than "mr_np". The patch looks fine otherwise and seems to
work ok, so:

Reviewed-by: Oliver O'Halloran <oohall@gmail.com>

> +               ret = of_address_to_resource(mr_np, 0, &res);
> +               if (ret)
> +                       dev_warn(
> +                               &pdev->dev,
> +                               "Unable to acquire memory-region from %pOF: %d\n",
> +                               mr_np, ret);
>                 else
> -                       dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
> -                                       ndr_desc.res, np);
> +                       of_pmem_register_region(pdev, bus, np, &res,
> +                                               is_volatile)

Now days I think it's cleaner to use braces around multi-line blocks
even if it's a single statement, up to you though.

> +               of_node_put(mr_np);
>         }
>
>         return 0;
> --
> 2.25.0.265.gbab2e86ba0-goog
>
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

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

* Re: [PATCH 1/2] libnvdimm/of_pmem: handle memory-region in DT
@ 2020-02-24  1:30   ` Oliver O'Halloran
  0 siblings, 0 replies; 12+ messages in thread
From: Oliver O'Halloran @ 2020-02-24  1:30 UTC (permalink / raw)
  To: Alistair Delva
  Cc: Linux Kernel Mailing List, Kenny Root, Rob Herring, Dan Williams,
	Vishal Verma, Dave Jiang, Ira Weiny, Device Tree, linux-nvdimm,
	kernel-team

On Sun, Feb 23, 2020 at 5:30 AM Alistair Delva <adelva@google.com> wrote:
>
> From: Kenny Root <kroot@google.com>
>
> Add support for parsing the 'memory-region' DT property in addition to
> the 'reg' DT property. This enables use cases where the pmem region is
> not in I/O address space or dedicated memory (e.g. a bootloader
> carveout).
>
> Signed-off-by: Kenny Root <kroot@google.com>
> Signed-off-by: Alistair Delva <adelva@google.com>
> Cc: "Oliver O'Halloran" <oohall@gmail.com>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: Vishal Verma <vishal.l.verma@intel.com>
> Cc: Dave Jiang <dave.jiang@intel.com>
> Cc: Ira Weiny <ira.weiny@intel.com>
> Cc: devicetree@vger.kernel.org
> Cc: linux-nvdimm@lists.01.org
> Cc: kernel-team@android.com
> ---
>  drivers/nvdimm/of_pmem.c | 75 ++++++++++++++++++++++++++--------------
>  1 file changed, 50 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
> index 8224d1431ea9..a68e44fb0041 100644
> --- a/drivers/nvdimm/of_pmem.c
> +++ b/drivers/nvdimm/of_pmem.c
> @@ -14,13 +14,47 @@ struct of_pmem_private {
>         struct nvdimm_bus *bus;
>  };
>
> +static void of_pmem_register_region(struct platform_device *pdev,
> +                                   struct nvdimm_bus *bus,
> +                                   struct device_node *np,
> +                                   struct resource *res, bool is_volatile)
> +{
> +       struct nd_region_desc ndr_desc;
> +       struct nd_region *region;
> +
> +       /*
> +        * NB: libnvdimm copies the data from ndr_desc into it's own
> +        * structures so passing a stack pointer is fine.
> +        */
> +       memset(&ndr_desc, 0, sizeof(ndr_desc));
> +       ndr_desc.numa_node = dev_to_node(&pdev->dev);
> +       ndr_desc.target_node = ndr_desc.numa_node;
> +       ndr_desc.res = res;
> +       ndr_desc.of_node = np;
> +       set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
> +
> +       if (is_volatile)
> +               region = nvdimm_volatile_region_create(bus, &ndr_desc);
> +       else
> +               region = nvdimm_pmem_region_create(bus, &ndr_desc);
> +
> +       if (!region)
> +               dev_warn(&pdev->dev,
> +                        "Unable to register region %pR from %pOF\n",
> +                        ndr_desc.res, np);
> +       else
> +               dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
> +                       ndr_desc.res, np);
> +}
> +
>  static int of_pmem_region_probe(struct platform_device *pdev)
>  {
>         struct of_pmem_private *priv;
> -       struct device_node *np;
> +       struct device_node *mrp, *np;
>         struct nvdimm_bus *bus;
> +       struct resource res;
>         bool is_volatile;
> -       int i;
> +       int i, ret;
>
>         np = dev_of_node(&pdev->dev);
>         if (!np)
> @@ -46,31 +80,22 @@ static int of_pmem_region_probe(struct platform_device *pdev)
>                         is_volatile ? "volatile" : "non-volatile",  np);
>
>         for (i = 0; i < pdev->num_resources; i++) {
> -               struct nd_region_desc ndr_desc;
> -               struct nd_region *region;
> -
> -               /*
> -                * NB: libnvdimm copies the data from ndr_desc into it's own
> -                * structures so passing a stack pointer is fine.
> -                */
> -               memset(&ndr_desc, 0, sizeof(ndr_desc));
> -               ndr_desc.numa_node = dev_to_node(&pdev->dev);
> -               ndr_desc.target_node = ndr_desc.numa_node;
> -               ndr_desc.res = &pdev->resource[i];
> -               ndr_desc.of_node = np;
> -               set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
> -
> -               if (is_volatile)
> -                       region = nvdimm_volatile_region_create(bus, &ndr_desc);
> -               else
> -                       region = nvdimm_pmem_region_create(bus, &ndr_desc);
> +               of_pmem_register_region(pdev, bus, np, &pdev->resource[i],
> +                                       is_volatile);
> +       }
>
> -               if (!region)
> -                       dev_warn(&pdev->dev, "Unable to register region %pR from %pOF\n",
> -                                       ndr_desc.res, np);
> +       i = 0;
> +       while ((mr_np = of_parse_phandle(np, "memory-region", i++))) {

Doesn't compile since the the iteration variable is declared above as
"mrp" rather than "mr_np". The patch looks fine otherwise and seems to
work ok, so:

Reviewed-by: Oliver O'Halloran <oohall@gmail.com>

> +               ret = of_address_to_resource(mr_np, 0, &res);
> +               if (ret)
> +                       dev_warn(
> +                               &pdev->dev,
> +                               "Unable to acquire memory-region from %pOF: %d\n",
> +                               mr_np, ret);
>                 else
> -                       dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
> -                                       ndr_desc.res, np);
> +                       of_pmem_register_region(pdev, bus, np, &res,
> +                                               is_volatile)

Now days I think it's cleaner to use braces around multi-line blocks
even if it's a single statement, up to you though.

> +               of_node_put(mr_np);
>         }
>
>         return 0;
> --
> 2.25.0.265.gbab2e86ba0-goog
>

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

* Re: [PATCH 1/2] libnvdimm/of_pmem: handle memory-region in DT
  2020-02-23 14:56   ` Ira Weiny
@ 2020-02-24  1:41     ` Oliver O'Halloran
  -1 siblings, 0 replies; 12+ messages in thread
From: Oliver O'Halloran @ 2020-02-24  1:41 UTC (permalink / raw)
  To: Ira Weiny
  Cc: Alistair Delva, Linux Kernel Mailing List, Kenny Root,
	Rob Herring, Device Tree, linux-nvdimm, kernel-team

On Mon, Feb 24, 2020 at 1:56 AM Ira Weiny <ira.weiny@intel.com> wrote:
>
> On Sat, Feb 22, 2020 at 10:30:09AM -0800, Alistair Delva wrote:
> > From: Kenny Root <kroot@google.com>
> >
> > Add support for parsing the 'memory-region' DT property in addition to
> > the 'reg' DT property. This enables use cases where the pmem region is
> > not in I/O address space or dedicated memory (e.g. a bootloader
> > carveout).
> >
> > Signed-off-by: Kenny Root <kroot@google.com>
> > Signed-off-by: Alistair Delva <adelva@google.com>
> > Cc: "Oliver O'Halloran" <oohall@gmail.com>
> > Cc: Rob Herring <robh+dt@kernel.org>
> > Cc: Dan Williams <dan.j.williams@intel.com>
> > Cc: Vishal Verma <vishal.l.verma@intel.com>
> > Cc: Dave Jiang <dave.jiang@intel.com>
> > Cc: Ira Weiny <ira.weiny@intel.com>
> > Cc: devicetree@vger.kernel.org
> > Cc: linux-nvdimm@lists.01.org
> > Cc: kernel-team@android.com
> > ---
> >  drivers/nvdimm/of_pmem.c | 75 ++++++++++++++++++++++++++--------------
> >  1 file changed, 50 insertions(+), 25 deletions(-)
> >
> > diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
> > index 8224d1431ea9..a68e44fb0041 100644
> > --- a/drivers/nvdimm/of_pmem.c
> > +++ b/drivers/nvdimm/of_pmem.c
> > @@ -14,13 +14,47 @@ struct of_pmem_private {
> >       struct nvdimm_bus *bus;
> >  };
> >
> > +static void of_pmem_register_region(struct platform_device *pdev,
> > +                                 struct nvdimm_bus *bus,
> > +                                 struct device_node *np,
> > +                                 struct resource *res, bool is_volatile)
>
> FWIW it would be easier to review if this was splut into a patch which created
> the helper of_pmem_register_region() without the new logic.  Then added the new
> logic here.

Yeah, that wouldn't hurt.

*snip*

> > +     i = 0;
> > +     while ((mr_np = of_parse_phandle(np, "memory-region", i++))) {
> > +             ret = of_address_to_resource(mr_np, 0, &res);
> > +             if (ret)
> > +                     dev_warn(
> > +                             &pdev->dev,
> > +                             "Unable to acquire memory-region from %pOF: %d\n",
> > +                             mr_np, ret);
> >               else
> > -                     dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
> > -                                     ndr_desc.res, np);
> > +                     of_pmem_register_region(pdev, bus, np, &res,
> > +                                             is_volatile);
> > +             of_node_put(mr_np);
>
> Why of_node_put()?

"memory-region" is an array of pointers to nodes in /reserved-memory/
which describe the actual memory region. of_parse_phandle() elevates
the refcount of the returned node and we need to balance that.

>
> Ira
> >       }
> >
> >       return 0;
> > --
> > 2.25.0.265.gbab2e86ba0-goog
> >
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

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

* Re: [PATCH 1/2] libnvdimm/of_pmem: handle memory-region in DT
@ 2020-02-24  1:41     ` Oliver O'Halloran
  0 siblings, 0 replies; 12+ messages in thread
From: Oliver O'Halloran @ 2020-02-24  1:41 UTC (permalink / raw)
  To: Ira Weiny
  Cc: Alistair Delva, Linux Kernel Mailing List, Kenny Root,
	Rob Herring, Dan Williams, Vishal Verma, Dave Jiang, Device Tree,
	linux-nvdimm, kernel-team

On Mon, Feb 24, 2020 at 1:56 AM Ira Weiny <ira.weiny@intel.com> wrote:
>
> On Sat, Feb 22, 2020 at 10:30:09AM -0800, Alistair Delva wrote:
> > From: Kenny Root <kroot@google.com>
> >
> > Add support for parsing the 'memory-region' DT property in addition to
> > the 'reg' DT property. This enables use cases where the pmem region is
> > not in I/O address space or dedicated memory (e.g. a bootloader
> > carveout).
> >
> > Signed-off-by: Kenny Root <kroot@google.com>
> > Signed-off-by: Alistair Delva <adelva@google.com>
> > Cc: "Oliver O'Halloran" <oohall@gmail.com>
> > Cc: Rob Herring <robh+dt@kernel.org>
> > Cc: Dan Williams <dan.j.williams@intel.com>
> > Cc: Vishal Verma <vishal.l.verma@intel.com>
> > Cc: Dave Jiang <dave.jiang@intel.com>
> > Cc: Ira Weiny <ira.weiny@intel.com>
> > Cc: devicetree@vger.kernel.org
> > Cc: linux-nvdimm@lists.01.org
> > Cc: kernel-team@android.com
> > ---
> >  drivers/nvdimm/of_pmem.c | 75 ++++++++++++++++++++++++++--------------
> >  1 file changed, 50 insertions(+), 25 deletions(-)
> >
> > diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
> > index 8224d1431ea9..a68e44fb0041 100644
> > --- a/drivers/nvdimm/of_pmem.c
> > +++ b/drivers/nvdimm/of_pmem.c
> > @@ -14,13 +14,47 @@ struct of_pmem_private {
> >       struct nvdimm_bus *bus;
> >  };
> >
> > +static void of_pmem_register_region(struct platform_device *pdev,
> > +                                 struct nvdimm_bus *bus,
> > +                                 struct device_node *np,
> > +                                 struct resource *res, bool is_volatile)
>
> FWIW it would be easier to review if this was splut into a patch which created
> the helper of_pmem_register_region() without the new logic.  Then added the new
> logic here.

Yeah, that wouldn't hurt.

*snip*

> > +     i = 0;
> > +     while ((mr_np = of_parse_phandle(np, "memory-region", i++))) {
> > +             ret = of_address_to_resource(mr_np, 0, &res);
> > +             if (ret)
> > +                     dev_warn(
> > +                             &pdev->dev,
> > +                             "Unable to acquire memory-region from %pOF: %d\n",
> > +                             mr_np, ret);
> >               else
> > -                     dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
> > -                                     ndr_desc.res, np);
> > +                     of_pmem_register_region(pdev, bus, np, &res,
> > +                                             is_volatile);
> > +             of_node_put(mr_np);
>
> Why of_node_put()?

"memory-region" is an array of pointers to nodes in /reserved-memory/
which describe the actual memory region. of_parse_phandle() elevates
the refcount of the returned node and we need to balance that.

>
> Ira
> >       }
> >
> >       return 0;
> > --
> > 2.25.0.265.gbab2e86ba0-goog
> >

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

* Re: [PATCH 1/2] libnvdimm/of_pmem: handle memory-region in DT
  2020-02-24  1:41     ` Oliver O'Halloran
@ 2020-02-24  1:43       ` Alistair Delva
  -1 siblings, 0 replies; 12+ messages in thread
From: Alistair Delva @ 2020-02-24  1:43 UTC (permalink / raw)
  To: Oliver O'Halloran
  Cc: Linux Kernel Mailing List, Kenny Root, Rob Herring, Device Tree,
	linux-nvdimm, kernel-team

On Sun, Feb 23, 2020 at 5:42 PM Oliver O'Halloran <oohall@gmail.com> wrote:
>
> On Mon, Feb 24, 2020 at 1:56 AM Ira Weiny <ira.weiny@intel.com> wrote:
> >
> > On Sat, Feb 22, 2020 at 10:30:09AM -0800, Alistair Delva wrote:
> > > From: Kenny Root <kroot@google.com>
> > >
> > > Add support for parsing the 'memory-region' DT property in addition to
> > > the 'reg' DT property. This enables use cases where the pmem region is
> > > not in I/O address space or dedicated memory (e.g. a bootloader
> > > carveout).
> > >
> > > Signed-off-by: Kenny Root <kroot@google.com>
> > > Signed-off-by: Alistair Delva <adelva@google.com>
> > > Cc: "Oliver O'Halloran" <oohall@gmail.com>
> > > Cc: Rob Herring <robh+dt@kernel.org>
> > > Cc: Dan Williams <dan.j.williams@intel.com>
> > > Cc: Vishal Verma <vishal.l.verma@intel.com>
> > > Cc: Dave Jiang <dave.jiang@intel.com>
> > > Cc: Ira Weiny <ira.weiny@intel.com>
> > > Cc: devicetree@vger.kernel.org
> > > Cc: linux-nvdimm@lists.01.org
> > > Cc: kernel-team@android.com
> > > ---
> > >  drivers/nvdimm/of_pmem.c | 75 ++++++++++++++++++++++++++--------------
> > >  1 file changed, 50 insertions(+), 25 deletions(-)
> > >
> > > diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
> > > index 8224d1431ea9..a68e44fb0041 100644
> > > --- a/drivers/nvdimm/of_pmem.c
> > > +++ b/drivers/nvdimm/of_pmem.c
> > > @@ -14,13 +14,47 @@ struct of_pmem_private {
> > >       struct nvdimm_bus *bus;
> > >  };
> > >
> > > +static void of_pmem_register_region(struct platform_device *pdev,
> > > +                                 struct nvdimm_bus *bus,
> > > +                                 struct device_node *np,
> > > +                                 struct resource *res, bool is_volatile)
> >
> > FWIW it would be easier to review if this was splut into a patch which created
> > the helper of_pmem_register_region() without the new logic.  Then added the new
> > logic here.
>
> Yeah, that wouldn't hurt.
>
> *snip*
>
> > > +     i = 0;
> > > +     while ((mr_np = of_parse_phandle(np, "memory-region", i++))) {
> > > +             ret = of_address_to_resource(mr_np, 0, &res);
> > > +             if (ret)
> > > +                     dev_warn(
> > > +                             &pdev->dev,
> > > +                             "Unable to acquire memory-region from %pOF: %d\n",
> > > +                             mr_np, ret);
> > >               else
> > > -                     dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
> > > -                                     ndr_desc.res, np);
> > > +                     of_pmem_register_region(pdev, bus, np, &res,
> > > +                                             is_volatile);
> > > +             of_node_put(mr_np);
> >
> > Why of_node_put()?
>
> "memory-region" is an array of pointers to nodes in /reserved-memory/
> which describe the actual memory region. of_parse_phandle() elevates
> the refcount of the returned node and we need to balance that.

That was my understanding too.

Thanks both for the review and sorry for the last minute untested
variable rename! I'll fix both and split the refactoring out in v2.

> >
> > Ira
> > >       }
> > >
> > >       return 0;
> > > --
> > > 2.25.0.265.gbab2e86ba0-goog
> > >
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

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

* Re: [PATCH 1/2] libnvdimm/of_pmem: handle memory-region in DT
@ 2020-02-24  1:43       ` Alistair Delva
  0 siblings, 0 replies; 12+ messages in thread
From: Alistair Delva @ 2020-02-24  1:43 UTC (permalink / raw)
  To: Oliver O'Halloran
  Cc: Ira Weiny, Linux Kernel Mailing List, Kenny Root, Rob Herring,
	Dan Williams, Vishal Verma, Dave Jiang, Device Tree,
	linux-nvdimm, kernel-team

On Sun, Feb 23, 2020 at 5:42 PM Oliver O'Halloran <oohall@gmail.com> wrote:
>
> On Mon, Feb 24, 2020 at 1:56 AM Ira Weiny <ira.weiny@intel.com> wrote:
> >
> > On Sat, Feb 22, 2020 at 10:30:09AM -0800, Alistair Delva wrote:
> > > From: Kenny Root <kroot@google.com>
> > >
> > > Add support for parsing the 'memory-region' DT property in addition to
> > > the 'reg' DT property. This enables use cases where the pmem region is
> > > not in I/O address space or dedicated memory (e.g. a bootloader
> > > carveout).
> > >
> > > Signed-off-by: Kenny Root <kroot@google.com>
> > > Signed-off-by: Alistair Delva <adelva@google.com>
> > > Cc: "Oliver O'Halloran" <oohall@gmail.com>
> > > Cc: Rob Herring <robh+dt@kernel.org>
> > > Cc: Dan Williams <dan.j.williams@intel.com>
> > > Cc: Vishal Verma <vishal.l.verma@intel.com>
> > > Cc: Dave Jiang <dave.jiang@intel.com>
> > > Cc: Ira Weiny <ira.weiny@intel.com>
> > > Cc: devicetree@vger.kernel.org
> > > Cc: linux-nvdimm@lists.01.org
> > > Cc: kernel-team@android.com
> > > ---
> > >  drivers/nvdimm/of_pmem.c | 75 ++++++++++++++++++++++++++--------------
> > >  1 file changed, 50 insertions(+), 25 deletions(-)
> > >
> > > diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
> > > index 8224d1431ea9..a68e44fb0041 100644
> > > --- a/drivers/nvdimm/of_pmem.c
> > > +++ b/drivers/nvdimm/of_pmem.c
> > > @@ -14,13 +14,47 @@ struct of_pmem_private {
> > >       struct nvdimm_bus *bus;
> > >  };
> > >
> > > +static void of_pmem_register_region(struct platform_device *pdev,
> > > +                                 struct nvdimm_bus *bus,
> > > +                                 struct device_node *np,
> > > +                                 struct resource *res, bool is_volatile)
> >
> > FWIW it would be easier to review if this was splut into a patch which created
> > the helper of_pmem_register_region() without the new logic.  Then added the new
> > logic here.
>
> Yeah, that wouldn't hurt.
>
> *snip*
>
> > > +     i = 0;
> > > +     while ((mr_np = of_parse_phandle(np, "memory-region", i++))) {
> > > +             ret = of_address_to_resource(mr_np, 0, &res);
> > > +             if (ret)
> > > +                     dev_warn(
> > > +                             &pdev->dev,
> > > +                             "Unable to acquire memory-region from %pOF: %d\n",
> > > +                             mr_np, ret);
> > >               else
> > > -                     dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
> > > -                                     ndr_desc.res, np);
> > > +                     of_pmem_register_region(pdev, bus, np, &res,
> > > +                                             is_volatile);
> > > +             of_node_put(mr_np);
> >
> > Why of_node_put()?
>
> "memory-region" is an array of pointers to nodes in /reserved-memory/
> which describe the actual memory region. of_parse_phandle() elevates
> the refcount of the returned node and we need to balance that.

That was my understanding too.

Thanks both for the review and sorry for the last minute untested
variable rename! I'll fix both and split the refactoring out in v2.

> >
> > Ira
> > >       }
> > >
> > >       return 0;
> > > --
> > > 2.25.0.265.gbab2e86ba0-goog
> > >

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

end of thread, other threads:[~2020-02-24  1:43 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-22 18:30 [PATCH 1/2] libnvdimm/of_pmem: handle memory-region in DT Alistair Delva
2020-02-22 18:30 ` Alistair Delva
2020-02-22 18:30 ` [PATCH 2/2] dt-bindings: pmem-region: Document memory-region Alistair Delva
2020-02-22 18:30   ` Alistair Delva
2020-02-23 14:56 ` [PATCH 1/2] libnvdimm/of_pmem: handle memory-region in DT Ira Weiny
2020-02-23 14:56   ` Ira Weiny
2020-02-24  1:41   ` Oliver O'Halloran
2020-02-24  1:41     ` Oliver O'Halloran
2020-02-24  1:43     ` Alistair Delva
2020-02-24  1:43       ` Alistair Delva
2020-02-24  1:30 ` Oliver O'Halloran
2020-02-24  1:30   ` Oliver O'Halloran

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.