[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200224021029.142701-1-adelva@google.com>
Date: Sun, 23 Feb 2020 18:10:27 -0800
From: Alistair Delva <adelva@...gle.com>
To: linux-kernel@...r.kernel.org
Cc: Kenny Root <kroot@...gle.com>,
"Oliver O'Halloran" <oohall@...il.com>,
Rob Herring <robh+dt@...nel.org>,
Dan Williams <dan.j.williams@...el.com>,
Vishal Verma <vishal.l.verma@...el.com>,
Dave Jiang <dave.jiang@...el.com>,
Ira Weiny <ira.weiny@...el.com>, devicetree@...r.kernel.org,
linux-nvdimm@...ts.01.org, kernel-team@...roid.com
Subject: [PATCH v3 1/3] libnvdimm/of_pmem: factor out region registration
From: Kenny Root <kroot@...gle.com>
Factor out region registration for 'reg' node. A follow-up change will
use of_pmem_register_region() to handle memory-region nodes too.
Signed-off-by: Kenny Root <kroot@...gle.com>
Signed-off-by: Alistair Delva <adelva@...gle.com>
Reviewed-by: "Oliver O'Halloran" <oohall@...il.com>
Cc: Rob Herring <robh+dt@...nel.org>
Cc: Dan Williams <dan.j.williams@...el.com>
Cc: Vishal Verma <vishal.l.verma@...el.com>
Cc: Dave Jiang <dave.jiang@...el.com>
Cc: Ira Weiny <ira.weiny@...el.com>
Cc: devicetree@...r.kernel.org
Cc: linux-nvdimm@...ts.01.org
Cc: kernel-team@...roid.com
---
[v3: adelva: remove duplicate "From:"]
drivers/nvdimm/of_pmem.c | 60 +++++++++++++++++++++++-----------------
1 file changed, 35 insertions(+), 25 deletions(-)
diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
index 8224d1431ea9..fdf54494e8c9 100644
--- a/drivers/nvdimm/of_pmem.c
+++ b/drivers/nvdimm/of_pmem.c
@@ -14,6 +14,39 @@ 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;
@@ -46,31 +79,8 @@ 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);
-
- 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);
+ of_pmem_register_region(pdev, bus, np, &pdev->resource[i],
+ is_volatile);
}
return 0;
--
2.25.0.265.gbab2e86ba0-goog
Powered by blists - more mailing lists