mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marc Zyngier <marc.zyngier@arm.com>
To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org
Cc: Grant Likely <grant.likely@secretlab.ca>
Subject: [RFC PATCH v2 1/4] dt: expose device resource allocator
Date: Fri,  8 Jul 2011 09:54:07 +0100	[thread overview]
Message-ID: <1310115250-3859-2-git-send-email-marc.zyngier@arm.com> (raw)
In-Reply-To: <1310115250-3859-1-git-send-email-marc.zyngier@arm.com>

of_device_alloc() takes care of allocating both a platform
device and its associated resource, as part of the runtime
device-tree to platform_device conversion.

The resource allocation itself is useful on its own, and
would be used by the core driver subsystem.  Create the
of_device_alloc_resources() function, and let of_device_alloc()
use it.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
 drivers/of/platform.c       |   60 +++++++++++++++++++++++++++++-------------
 include/linux/of_platform.h |    2 +
 2 files changed, 43 insertions(+), 19 deletions(-)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index e75af39..f839f79 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -122,22 +122,16 @@ void of_device_make_bus_id(struct device *dev)
 }
 
 /**
- * of_device_alloc - Allocate and initialize an of_device
- * @np: device node to assign to device
- * @bus_id: Name to assign to the device.  May be null to use default name.
- * @parent: Parent device.
+ * of_device_alloc_resources - Allocate and initialize resources for an
+ *			       of_device
+ * @np: device node to fetch resources from
+ * @num_res: number of allocated resources
  */
-struct platform_device *of_device_alloc(struct device_node *np,
-				  const char *bus_id,
-				  struct device *parent)
+struct resource *of_device_alloc_resources(struct device_node *np,
+					   int *num_res)
 {
-	struct platform_device *dev;
 	int rc, i, num_reg = 0, num_irq;
-	struct resource *res, temp_res;
-
-	dev = platform_device_alloc("", -1);
-	if (!dev)
-		return NULL;
+	struct resource *res = NULL, temp_res;
 
 	/* count the io and irq resources */
 	while (of_address_to_resource(np, num_reg, &temp_res) == 0)
@@ -148,19 +142,47 @@ struct platform_device *of_device_alloc(struct device_node *np,
 	if (num_irq || num_reg) {
 		res = kzalloc(sizeof(*res) * (num_irq + num_reg), GFP_KERNEL);
 		if (!res) {
-			platform_device_put(dev);
+			*num_res = -1;
 			return NULL;
 		}
 
-		dev->num_resources = num_reg + num_irq;
-		dev->resource = res;
-		for (i = 0; i < num_reg; i++, res++) {
-			rc = of_address_to_resource(np, i, res);
+		for (i = 0; i < num_reg; i++) {
+			rc = of_address_to_resource(np, i, &res[i]);
 			WARN_ON(rc);
 		}
-		WARN_ON(of_irq_to_resource_table(np, res, num_irq) != num_irq);
+		WARN_ON(of_irq_to_resource_table(np, &res[i], num_irq) != num_irq);
+	}
+
+	*num_res = num_irq + num_reg;
+	return res;
+}
+
+/**
+ * of_device_alloc - Allocate and initialize an of_device
+ * @np: device node to assign to device
+ * @bus_id: Name to assign to the device.  May be null to use default name.
+ * @parent: Parent device.
+ */
+struct platform_device *of_device_alloc(struct device_node *np,
+				  const char *bus_id,
+				  struct device *parent)
+{
+	struct platform_device *dev;
+	int num_res;
+	struct resource *res;
+
+	dev = platform_device_alloc("", -1);
+	if (!dev)
+		return NULL;
+
+	res = of_device_alloc_resources(np, &num_res);
+	if (num_res == -1) {
+		platform_device_put(dev);
+		return NULL;
 	}
 
+	dev->num_resources = num_res;
+	dev->resource = res;
 	dev->dev.of_node = of_node_get(np);
 #if defined(CONFIG_PPC) || defined(CONFIG_MICROBLAZE)
 	dev->dev.dma_mask = &dev->archdata.dma_mask;
diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
index 5a6f458..773a880 100644
--- a/include/linux/of_platform.h
+++ b/include/linux/of_platform.h
@@ -77,6 +77,8 @@ struct of_platform_driver
 extern const struct of_device_id of_default_bus_match_table[];
 
 /* Platform drivers register/unregister */
+extern struct resource *of_device_alloc_resources(struct device_node *np,
+						  int *num_res);
 extern struct platform_device *of_device_alloc(struct device_node *np,
 					 const char *bus_id,
 					 struct device *parent);
-- 
1.7.0.4



  reply	other threads:[~2011-07-08  8:54 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-08  8:54 [RFC PATCH v2 0/4] Core device subsystem Marc Zyngier
2011-07-08  8:54 ` Marc Zyngier [this message]
2011-07-09 17:13   ` [RFC PATCH v2 1/4] dt: expose device resource allocator Grant Likely
2011-07-08  8:54 ` [RFC PATCH v2 2/4] Core device subsystem implementation Marc Zyngier
2011-07-08 10:18   ` Michał Mirosław
2011-07-08 10:33     ` Marc Zyngier
2011-07-09  5:38   ` Greg KH
2011-07-09 18:08   ` Grant Likely
2011-07-08  8:54 ` [RFC PATCH v2 3/4] Core devices: add OF interrupt controller sorting method Marc Zyngier
2011-07-09 21:14   ` Grant Likely
2011-07-08  8:54 ` [RFC PATCH v2 4/4] Core devices: documentation Marc Zyngier
2011-07-08 18:16   ` Randy Dunlap
2011-07-09 21:29   ` Grant Likely
2011-07-08 11:37 ` [RFC PATCH v2 0/4] Core device subsystem Michał Mirosław
2011-07-08 13:08   ` Marc Zyngier
2011-07-08 15:13     ` Marc Zyngier
2011-07-08 18:13       ` Michał Mirosław
2011-07-08 18:37         ` Michał Mirosław
2011-07-09  5:43 ` Greg KH

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=1310115250-3859-2-git-send-email-marc.zyngier@arm.com \
    --to=marc.zyngier@arm.com \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®