linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Oliver O'Halloran <oohall@gmail.com>
To: linux-nvdimm@lists.01.org
Cc: devicetree@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	Oliver O'Halloran <oohall@gmail.com>
Subject: [PATCH 4/6] libnvdimm/of: Symlink platform and region devices
Date: Fri, 23 Mar 2018 19:12:07 +1100	[thread overview]
Message-ID: <20180323081209.31387-4-oohall@gmail.com> (raw)
In-Reply-To: <20180323081209.31387-1-oohall@gmail.com>

Add a way direct link between the region and the platform device that
creates the region.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 drivers/nvdimm/of_nvdimm.c   | 11 +++++++++++
 drivers/nvdimm/region_devs.c | 13 +++++++++++++
 include/linux/libnvdimm.h    |  1 +
 3 files changed, 25 insertions(+)

diff --git a/drivers/nvdimm/of_nvdimm.c b/drivers/nvdimm/of_nvdimm.c
index 79c28291f420..28f4ca23a690 100644
--- a/drivers/nvdimm/of_nvdimm.c
+++ b/drivers/nvdimm/of_nvdimm.c
@@ -37,6 +37,7 @@ static int of_nd_region_probe(struct platform_device *pdev)
 	struct resource temp_res;
 	struct nd_region *region;
 	struct device_node *np;
+	int rc;
 
 	np = dev_of_node(&pdev->dev);
 	if (!np)
@@ -71,6 +72,15 @@ static int of_nd_region_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, region);
 
+	/*
+	 * Add a symlink to the ndbus region object. Without this there's no
+	 * simple way to go from the platform device to the region it spawned.
+	 */
+	rc = sysfs_create_link(&pdev->dev.kobj,
+				nd_region_kobj(region), "region");
+	if (rc)
+		pr_warn("Failed to create symlink to region (rc = %d)!\n", rc);
+
 	return 0;
 }
 
@@ -78,6 +88,7 @@ static int of_nd_region_remove(struct platform_device *pdev)
 {
 	struct nd_region *r = platform_get_drvdata(pdev);
 
+	sysfs_delete_link(&pdev->dev.kobj, nd_region_kobj(r), "region");
 	nd_region_destroy(r);
 
 	return 0;
diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c
index 76f46fd1fae0..af09acc1d93b 100644
--- a/drivers/nvdimm/region_devs.c
+++ b/drivers/nvdimm/region_devs.c
@@ -1054,6 +1054,19 @@ struct nd_region *nvdimm_volatile_region_create(struct nvdimm_bus *nvdimm_bus,
 }
 EXPORT_SYMBOL_GPL(nvdimm_volatile_region_create);
 
+struct kobject *nd_region_kobj(struct nd_region *region)
+{
+	/*
+	 * region init is async so we need to explicitly synchronise
+	 * to prevent handing out a kobj reference before device_add()
+	 * has been run
+	 */
+	nd_synchronize();
+
+	return &region->dev.kobj;
+}
+EXPORT_SYMBOL_GPL(nd_region_kobj);
+
 /**
  * nvdimm_flush - flush any posted write queues between the cpu and pmem media
  * @nd_region: blk or interleaved pmem region
diff --git a/include/linux/libnvdimm.h b/include/linux/libnvdimm.h
index df21ca176e98..a4b3663bac38 100644
--- a/include/linux/libnvdimm.h
+++ b/include/linux/libnvdimm.h
@@ -172,6 +172,7 @@ struct nvdimm_bus_descriptor *to_nd_desc(struct nvdimm_bus *nvdimm_bus);
 struct device *to_nvdimm_bus_dev(struct nvdimm_bus *nvdimm_bus);
 const char *nvdimm_name(struct nvdimm *nvdimm);
 struct kobject *nvdimm_kobj(struct nvdimm *nvdimm);
+struct kobject *nd_region_kobj(struct nd_region *region);
 unsigned long nvdimm_cmd_mask(struct nvdimm *nvdimm);
 void *nvdimm_provider_data(struct nvdimm *nvdimm);
 struct nvdimm *nvdimm_create(struct nvdimm_bus *nvdimm_bus, void *provider_data,
-- 
2.9.5

  parent reply	other threads:[~2018-03-23  8:12 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-23  8:12 [PATCH 1/6] libnvdimm: Add of_node to region and bus descriptors Oliver O'Halloran
2018-03-23  8:12 ` [PATCH 2/6] libnvdimm: Add nd_region_destroy() Oliver O'Halloran
2018-03-23 16:59   ` Dan Williams
2018-03-25 23:24   ` Balbir Singh
2018-03-23  8:12 ` [PATCH 3/6] libnvdimm: Add device-tree based driver Oliver O'Halloran
2018-03-23 17:07   ` Dan Williams
2018-03-26  1:07     ` Oliver
2018-03-25  2:51   ` kbuild test robot
2018-03-25  4:27   ` kbuild test robot
2018-03-25  4:28   ` [RFC PATCH] libnvdimm: bus_desc can be static kbuild test robot
2018-03-26  4:05   ` [PATCH 3/6] libnvdimm: Add device-tree based driver Balbir Singh
2018-03-23  8:12 ` Oliver O'Halloran [this message]
2018-03-23 17:08   ` [PATCH 4/6] libnvdimm/of: Symlink platform and region devices Dan Williams
2018-03-23  8:12 ` [PATCH 5/6] powerpc/powernv: Create platform devs for nvdimm buses Oliver O'Halloran
2018-03-23  8:12 ` [PATCH 6/6] doc/devicetree: NVDIMM region documentation Oliver O'Halloran
2018-03-26 22:24   ` Rob Herring
2018-03-27 14:53     ` Oliver
2018-03-28 17:06       ` Rob Herring
2018-03-28 17:25         ` Dan Williams
2018-03-29  3:10         ` Oliver
2018-03-25 23:16 ` [PATCH 1/6] libnvdimm: Add of_node to region and bus descriptors Balbir Singh

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=20180323081209.31387-4-oohall@gmail.com \
    --to=oohall@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-nvdimm@lists.01.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    /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 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).