Skip to contentSkip to conversation

ARM: OMAP: hwmod/omapd_device: Fix for resource handling in DT boot

PATCH New Peter Ujfalusi 5 participants 11 messages Oct 30, 2012 – Nov 21, 2012

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover ARM: OMAP: hwmod/omapd_device: Fix for resource handling in DT boot

Hello,

Changes since v1:
- If the device does not have DMA resource do not try to recreate the resources

Intro mail from v1:

This series resolves the issue we currently have with the resource handling when booting with DT.
In short: at the moment the omap_device_alloc() decides if it needs to update the OF filled resources based on the number of resources on the device and in the hwmod database.
This prevents us from removing hwmod data for platforms (OMAP5) which does not support non DT boot anymore.

With this series we can make sure that the DT provided resources are used and we only append the DMA resources to the device from hwmod.
I have added extra check to prepare us when the DMA resource can be filled via OF. In this case we do not update the resources at all.

Tony, Benoit, Paul: Not sure if this qualify for 3.7 inclusion, but for sure going to help us to clean up the OMAP5 hwmod database.

Regards,
Peter
---
Peter Ujfalusi (2):
ARM: OMAP: hwmod: Add possibility to count hwmod resources based on
type
ARM: OMAP: omap_device: Correct resource handling for DT boot

 arch/arm/mach-omap2/omap_hwmod.c             | 27 +++++----
 arch/arm/plat-omap/include/plat/omap_hwmod.h |  2 +-
 arch/arm/plat-omap/omap_device.c             | 87 ++++++++++++++++++----------
 3 files changed, 72 insertions(+), 44 deletions(-)
Signature · 1 line
1.7.12.4
#1 lore raw

PATCH v2 1/2 ARM: OMAP: hwmod: Add possibility to count hwmod resources based on type

Add flags parameter for omap_hwmod_count_resources() so users can tell which type of resources they are interested when counting them in hwmod database.

---
 arch/arm/mach-omap2/omap_hwmod.c             | 27 ++++++++++++++++-----------
 arch/arm/plat-omap/include/plat/omap_hwmod.h |  2 +-
 arch/arm/plat-omap/omap_device.c             | 11 ++++++++---
 3 files changed, 25 insertions(+), 15 deletions(-)
arch/arm/mach-omap2/omap_hwmod.c +16 -11
index b969ab1..a79c941 100644
@@ -3337,7 +3337,7 @@ int omap_hwmod_reset(struct omap_hwmod *oh)
 /**
  * omap_hwmod_count_resources - count number of struct resources needed by hwmod
  * @oh: struct omap_hwmod *
- * @res: pointer to the first element of an array of struct resource to fill
+ * @flags: Type of resources to include when counting (IRQ/DMA/MEM)
  *
  * Count the number of struct resource array elements necessary to
  * contain omap_hwmod @oh resources.  Intended to be called by code
@@ -3350,20 +3350,25 @@ int omap_hwmod_reset(struct omap_hwmod *oh)
  * resource IDs.
  *
  */
-int omap_hwmod_count_resources(struct omap_hwmod *oh)
+int omap_hwmod_count_resources(struct omap_hwmod *oh, unsigned long flags)
 {
-	struct omap_hwmod_ocp_if *os;
-	struct list_head *p;
-	int ret;
-	int i = 0;
+	int ret = 0;
 
-	ret = _count_mpu_irqs(oh) + _count_sdma_reqs(oh);
+	if (flags & IORESOURCE_IRQ)
+		ret += _count_mpu_irqs(oh);
 
-	p = oh->slave_ports.next;
+	if (flags & IORESOURCE_DMA)
+		ret += _count_sdma_reqs(oh);
 
-	while (i < oh->slaves_cnt) {
-		os = _fetch_next_ocp_if(&p, &i);
-		ret += _count_ocp_if_addr_spaces(os);
+	if (flags & IORESOURCE_MEM) {
+		int i = 0;
+		struct omap_hwmod_ocp_if *os;
+		struct list_head *p = oh->slave_ports.next;
+
+		while (i < oh->slaves_cnt) {
+			os = _fetch_next_ocp_if(&p, &i);
+			ret += _count_ocp_if_addr_spaces(os);
+		}
 	}
 
 	return ret;
arch/arm/plat-omap/include/plat/omap_hwmod.h +1 -1
index b3349f7..48a6f5d 100644
@@ -628,7 +628,7 @@ void omap_hwmod_write(u32 v, struct omap_hwmod *oh, u16 reg_offs);
 u32 omap_hwmod_read(struct omap_hwmod *oh, u16 reg_offs);
 int omap_hwmod_softreset(struct omap_hwmod *oh);
 
-int omap_hwmod_count_resources(struct omap_hwmod *oh);
+int omap_hwmod_count_resources(struct omap_hwmod *oh, unsigned long flags);
 int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res);
 int omap_hwmod_fill_dma_resources(struct omap_hwmod *oh, struct resource *res);
 int omap_hwmod_get_resource_byname(struct omap_hwmod *oh, unsigned int type,
arch/arm/plat-omap/omap_device.c +8 -3
index 7a7d1f2..915cf68 100644
@@ -442,19 +442,21 @@ int omap_device_get_context_loss_count(struct platform_device *pdev)
 /**
  * omap_device_count_resources - count number of struct resource entries needed
  * @od: struct omap_device *
+ * @flags: Type of resources to include when counting (IRQ/DMA/MEM)
  *
  * Count the number of struct resource entries needed for this
  * omap_device @od.  Used by omap_device_build_ss() to determine how
  * much memory to allocate before calling
  * omap_device_fill_resources().  Returns the count.
  */
-static int omap_device_count_resources(struct omap_device *od)
+static int omap_device_count_resources(struct omap_device *od,
+				       unsigned long flags)
 {
 	int c = 0;
 	int i;
 
 	for (i = 0; i < od->hwmods_cnt; i++)
-		c += omap_hwmod_count_resources(od->hwmods[i]);
+		c += omap_hwmod_count_resources(od->hwmods[i], flags);
 
 	pr_debug("omap_device: %s: counted %d total resources across %d hwmods\n",
 		 od->pdev->name, c, od->hwmods_cnt);
@@ -558,7 +560,10 @@ struct omap_device *omap_device_alloc(struct platform_device *pdev,
 	od->hwmods = hwmods;
 	od->pdev = pdev;
 
-	res_count = omap_device_count_resources(od);
+	/* Count all resources for the device */
+	res_count = omap_device_count_resources(od, IORESOURCE_IRQ |
+						    IORESOURCE_DMA |
+						    IORESOURCE_MEM);
 	/*
 	 * DT Boot:
 	 *   OF framework will construct the resource structure (currently
Signature · 1 line
1.7.12.4
#2 lore raw

PATCH v2 1/2 ARM: OMAP: hwmod: Add possibility to count hwmod resources based on type

Hi Peter,

That's great you've have done that fix.

Quoted 2 lines · Peter Ujfalusi

Add flags parameter for omap_hwmod_count_resources() so users can tell which type of resources they are interested when counting them in hwmod database.

Mmm, does it worth doing that for every resources considering that this is a temporary situation and than only the DMA resources are an issue so far?

Otherwise that looks fine to me and will allow a much smoother transition to full DT.

Thanks,
Benoit

Quoted 110 lines
---
  arch/arm/mach-omap2/omap_hwmod.c             | 27 ++++++++++++++++-----------
  arch/arm/plat-omap/include/plat/omap_hwmod.h |  2 +-
  arch/arm/plat-omap/omap_device.c             | 11 ++++++++---
  3 files changed, 25 insertions(+), 15 deletions(-)
arch/arm/mach-omap2/omap_hwmod.c +16 -11
index b969ab1..a79c941 100644
@@ -3337,7 +3337,7 @@ int omap_hwmod_reset(struct omap_hwmod *oh)
  /**
   * omap_hwmod_count_resources - count number of struct resources needed by hwmod
   * @oh: struct omap_hwmod *
- * @res: pointer to the first element of an array of struct resource to fill
+ * @flags: Type of resources to include when counting (IRQ/DMA/MEM)
   *
   * Count the number of struct resource array elements necessary to
   * contain omap_hwmod @oh resources.  Intended to be called by code
@@ -3350,20 +3350,25 @@ int omap_hwmod_reset(struct omap_hwmod *oh)
   * resource IDs.
   *
   */
-int omap_hwmod_count_resources(struct omap_hwmod *oh)
+int omap_hwmod_count_resources(struct omap_hwmod *oh, unsigned long flags)
  {
-	struct omap_hwmod_ocp_if *os;
-	struct list_head *p;
-	int ret;
-	int i = 0;
+	int ret = 0;
 
-	ret = _count_mpu_irqs(oh) + _count_sdma_reqs(oh);
+	if (flags & IORESOURCE_IRQ)
+		ret += _count_mpu_irqs(oh);
 
-	p = oh->slave_ports.next;
+	if (flags & IORESOURCE_DMA)
+		ret += _count_sdma_reqs(oh);
 
-	while (i < oh->slaves_cnt) {
-		os = _fetch_next_ocp_if(&p, &i);
-		ret += _count_ocp_if_addr_spaces(os);
+	if (flags & IORESOURCE_MEM) {
+		int i = 0;
+		struct omap_hwmod_ocp_if *os;
+		struct list_head *p = oh->slave_ports.next;
+
+		while (i < oh->slaves_cnt) {
+			os = _fetch_next_ocp_if(&p, &i);
+			ret += _count_ocp_if_addr_spaces(os);
+		}
  	}
 
  	return ret;
arch/arm/plat-omap/include/plat/omap_hwmod.h +1 -1
index b3349f7..48a6f5d 100644
@@ -628,7 +628,7 @@ void omap_hwmod_write(u32 v, struct omap_hwmod *oh, u16 reg_offs);
  u32 omap_hwmod_read(struct omap_hwmod *oh, u16 reg_offs);
  int omap_hwmod_softreset(struct omap_hwmod *oh);
 
-int omap_hwmod_count_resources(struct omap_hwmod *oh);
+int omap_hwmod_count_resources(struct omap_hwmod *oh, unsigned long flags);
  int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res);
  int omap_hwmod_fill_dma_resources(struct omap_hwmod *oh, struct resource *res);
  int omap_hwmod_get_resource_byname(struct omap_hwmod *oh, unsigned int type,
arch/arm/plat-omap/omap_device.c +8 -3
index 7a7d1f2..915cf68 100644
@@ -442,19 +442,21 @@ int omap_device_get_context_loss_count(struct platform_device *pdev)
  /**
   * omap_device_count_resources - count number of struct resource entries needed
   * @od: struct omap_device *
+ * @flags: Type of resources to include when counting (IRQ/DMA/MEM)
   *
   * Count the number of struct resource entries needed for this
   * omap_device @od.  Used by omap_device_build_ss() to determine how
   * much memory to allocate before calling
   * omap_device_fill_resources().  Returns the count.
   */
-static int omap_device_count_resources(struct omap_device *od)
+static int omap_device_count_resources(struct omap_device *od,
+				       unsigned long flags)
  {
  	int c = 0;
  	int i;
 
  	for (i = 0; i < od->hwmods_cnt; i++)
-		c += omap_hwmod_count_resources(od->hwmods[i]);
+		c += omap_hwmod_count_resources(od->hwmods[i], flags);
 
  	pr_debug("omap_device: %s: counted %d total resources across %d hwmods\n",
  		 od->pdev->name, c, od->hwmods_cnt);
@@ -558,7 +560,10 @@ struct omap_device *omap_device_alloc(struct platform_device *pdev,
  	od->hwmods = hwmods;
  	od->pdev = pdev;
 
-	res_count = omap_device_count_resources(od);
+	/* Count all resources for the device */
+	res_count = omap_device_count_resources(od, IORESOURCE_IRQ |
+						    IORESOURCE_DMA |
+						    IORESOURCE_MEM);
  	/*
  	 * DT Boot:
  	 *   OF framework will construct the resource structure (currently
#3 lore raw

PATCH v2 1/2 ARM: OMAP: hwmod: Add possibility to count hwmod resources based on type

Hi Benoit,

Quoted 10 lines · Benoit

Hi Peter,

That's great you've have done that fix.

Quoted 2 lines · Peter Ujfalusi

Add flags parameter for omap_hwmod_count_resources() so users can tell which type of resources they are interested when counting them in hwmod database.

Mmm, does it worth doing that for every resources considering that this is a temporary situation and than only the DMA resources are an issue so far?

I think it is better to have nice API - even for a short term - than introduce a new wrapper just to count the DMA resources.
Yes we only use this to either count all resources or to count the DMA resources only, but the other options does not look better either:
1. omap_hwmod_count_dma_resources(struct omap_hwmod *oh)
2. omap_hwmod_count_resources(struct omap_hwmod *oh, bool dma_only)

Signature · 1 line
P?ter
Quoted 128 lines

Otherwise that looks fine to me and will allow a much smoother transition to full DT.

Thanks,
Benoit

Quoted 120 lines
---
  arch/arm/mach-omap2/omap_hwmod.c             | 27 ++++++++++++++++-----------
  arch/arm/plat-omap/include/plat/omap_hwmod.h |  2 +-
  arch/arm/plat-omap/omap_device.c             | 11 ++++++++---
  3 files changed, 25 insertions(+), 15 deletions(-)
arch/arm/mach-omap2/omap_hwmod.c +0 -0
index b969ab1..a79c941 100644
@@ -3337,7 +3337,7 @@ int omap_hwmod_reset(struct omap_hwmod *oh)
  /**
   * omap_hwmod_count_resources - count number of struct resources needed by

hwmod
* @oh: struct omap_hwmod *
- * @res: pointer to the first element of an array of struct resource to fill
+ * @flags: Type of resources to include when counting (IRQ/DMA/MEM) *
* Count the number of struct resource array elements necessary to
* contain omap_hwmod @oh resources. Intended to be called by code

arch/arm/mach-omap2/omap_hwmod.c +15 -10
@@ -3350,20 +3350,25 @@ int omap_hwmod_reset(struct omap_hwmod *oh)
   * resource IDs.
   *
   */
-int omap_hwmod_count_resources(struct omap_hwmod *oh)
+int omap_hwmod_count_resources(struct omap_hwmod *oh, unsigned long flags)
  {
-    struct omap_hwmod_ocp_if *os;
-    struct list_head *p;
-    int ret;
-    int i = 0;
+    int ret = 0;
 
-    ret = _count_mpu_irqs(oh) + _count_sdma_reqs(oh);
+    if (flags & IORESOURCE_IRQ)
+        ret += _count_mpu_irqs(oh);
 
-    p = oh->slave_ports.next;
+    if (flags & IORESOURCE_DMA)
+        ret += _count_sdma_reqs(oh);
 
-    while (i < oh->slaves_cnt) {
-        os = _fetch_next_ocp_if(&p, &i);
-        ret += _count_ocp_if_addr_spaces(os);
+    if (flags & IORESOURCE_MEM) {
+        int i = 0;
+        struct omap_hwmod_ocp_if *os;
+        struct list_head *p = oh->slave_ports.next;
+
+        while (i < oh->slaves_cnt) {
+            os = _fetch_next_ocp_if(&p, &i);
+            ret += _count_ocp_if_addr_spaces(os);
+        }
      }
 
      return ret;
arch/arm/plat-omap/include/plat/omap_hwmod.h +1 -1
index b3349f7..48a6f5d 100644
@@ -628,7 +628,7 @@ void omap_hwmod_write(u32 v, struct omap_hwmod *oh, u16
 reg_offs);
  u32 omap_hwmod_read(struct omap_hwmod *oh, u16 reg_offs);
  int omap_hwmod_softreset(struct omap_hwmod *oh);
 
-int omap_hwmod_count_resources(struct omap_hwmod *oh);
+int omap_hwmod_count_resources(struct omap_hwmod *oh, unsigned long flags);
  int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res);
  int omap_hwmod_fill_dma_resources(struct omap_hwmod *oh, struct resource

*res);
int omap_hwmod_get_resource_byname(struct omap_hwmod *oh, unsigned int type,

arch/arm/plat-omap/omap_device.c +0 -0
index 7a7d1f2..915cf68 100644
@@ -442,19 +442,21 @@ int omap_device_get_context_loss_count(struct
 platform_device *pdev)
  /**
   * omap_device_count_resources - count number of struct resource entries

needed
* @od: struct omap_device *
+ * @flags: Type of resources to include when counting (IRQ/DMA/MEM) *
* Count the number of struct resource entries needed for this
* omap_device @od. Used by omap_device_build_ss() to determine how
* much memory to allocate before calling
* omap_device_fill_resources(). Returns the count.
*/

arch/arm/plat-omap/omap_device.c +3 -2
-static int omap_device_count_resources(struct omap_device *od)
+static int omap_device_count_resources(struct omap_device *od,
+                       unsigned long flags)
  {
      int c = 0;
      int i;
 
      for (i = 0; i < od->hwmods_cnt; i++)
-        c += omap_hwmod_count_resources(od->hwmods[i]);
+        c += omap_hwmod_count_resources(od->hwmods[i], flags);
 
      pr_debug("omap_device: %s: counted %d total resources across %d

hwmods\n",

           od->pdev->name, c, od->hwmods_cnt);
arch/arm/plat-omap/omap_device.c +4 -1
@@ -558,7 +560,10 @@ struct omap_device *omap_device_alloc(struct
 platform_device *pdev,
      od->hwmods = hwmods;
      od->pdev = pdev;
 
-    res_count = omap_device_count_resources(od);
+    /* Count all resources for the device */
+    res_count = omap_device_count_resources(od, IORESOURCE_IRQ |
+                            IORESOURCE_DMA |
+                            IORESOURCE_MEM);
      /*
       * DT Boot:

* OF framework will construct the resource structure (currently

#4 lore raw

PATCH v2 1/2 ARM: OMAP: hwmod: Add possibility to count hwmod resources based on type

Salut P?ter,

Quoted 14 lines · P?ter Ujfalusi

Hi Benoit,

Quoted 10 lines · Benoit

Hi Peter,

That's great you've have done that fix.

Quoted 2 lines · Peter Ujfalusi

Add flags parameter for omap_hwmod_count_resources() so users can tell which type of resources they are interested when counting them in hwmod database.

Mmm, does it worth doing that for every resources considering that this is a temporary situation and than only the DMA resources are an issue so far?

Quoted 6 lines

I think it is better to have nice API - even for a short term - than introduce a new wrapper just to count the DMA resources.
Yes we only use this to either count all resources or to count the DMA resources only, but the other options does not look better either:
1. omap_hwmod_count_dma_resources(struct omap_hwmod *oh)
2. omap_hwmod_count_resources(struct omap_hwmod *oh, bool dma_only)

Fair enough. I'm OK with that. I'll take theses patches, except if Paul already have a 3.8 branch for hwmod.

Regards,
Benoit

maintainer
#5 lore raw

PATCH v2 1/2 ARM: OMAP: hwmod: Add possibility to count hwmod resources based on type

In reply to Peter Ujfalusi
Quoted 4 lines · Peter Ujfalusi

Add flags parameter for omap_hwmod_count_resources() so users can tell which type of resources they are interested when counting them in hwmod database.

Here's this one, updated to apply after the various cleanups.

- Paul

From: Peter Ujfalusi <[email protected]>
Date: Wed, 21 Nov 2012 11:50:12 -0700
Subject: [PATCH 1/2] ARM: OMAP2+: hwmod: Add possibility to count hwmod
resources based on type
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add flags parameter for omap_hwmod_count_resources() so users can tell which type of resources they are interested when counting them in hwmod database.

[paul at pwsan.com: updated to apply]
---
 arch/arm/mach-omap2/omap_device.c |   11 ++++++++---
 arch/arm/mach-omap2/omap_hwmod.c  |   27 ++++++++++++++++-----------
 arch/arm/mach-omap2/omap_hwmod.h  |    2 +-
 3 files changed, 25 insertions(+), 15 deletions(-)
arch/arm/mach-omap2/omap_device.c +8 -3
index 0ef934f..8917a08 100644
@@ -441,19 +441,21 @@ int omap_device_get_context_loss_count(struct platform_device *pdev)
 /**
  * omap_device_count_resources - count number of struct resource entries needed
  * @od: struct omap_device *
+ * @flags: Type of resources to include when counting (IRQ/DMA/MEM)
  *
  * Count the number of struct resource entries needed for this
  * omap_device @od.  Used by omap_device_build_ss() to determine how
  * much memory to allocate before calling
  * omap_device_fill_resources().  Returns the count.
  */
-static int omap_device_count_resources(struct omap_device *od)
+static int omap_device_count_resources(struct omap_device *od,
+				       unsigned long flags)
 {
 	int c = 0;
 	int i;
 
 	for (i = 0; i < od->hwmods_cnt; i++)
-		c += omap_hwmod_count_resources(od->hwmods[i]);
+		c += omap_hwmod_count_resources(od->hwmods[i], flags);
 
 	pr_debug("omap_device: %s: counted %d total resources across %d hwmods\n",
 		 od->pdev->name, c, od->hwmods_cnt);
@@ -557,7 +559,10 @@ struct omap_device *omap_device_alloc(struct platform_device *pdev,
 	od->hwmods = hwmods;
 	od->pdev = pdev;
 
-	res_count = omap_device_count_resources(od);
+	/* Count all resources for the device */
+	res_count = omap_device_count_resources(od, IORESOURCE_IRQ |
+						    IORESOURCE_DMA |
+						    IORESOURCE_MEM);
 	/*
 	 * DT Boot:
 	 *   OF framework will construct the resource structure (currently
arch/arm/mach-omap2/omap_hwmod.c +16 -11
index 083adbe..a809090 100644
@@ -3427,7 +3427,7 @@ int omap_hwmod_reset(struct omap_hwmod *oh)
 /**
  * omap_hwmod_count_resources - count number of struct resources needed by hwmod
  * @oh: struct omap_hwmod *
- * @res: pointer to the first element of an array of struct resource to fill
+ * @flags: Type of resources to include when counting (IRQ/DMA/MEM)
  *
  * Count the number of struct resource array elements necessary to
  * contain omap_hwmod @oh resources.  Intended to be called by code
@@ -3440,20 +3440,25 @@ int omap_hwmod_reset(struct omap_hwmod *oh)
  * resource IDs.
  *
  */
-int omap_hwmod_count_resources(struct omap_hwmod *oh)
+int omap_hwmod_count_resources(struct omap_hwmod *oh, unsigned long flags)
 {
-	struct omap_hwmod_ocp_if *os;
-	struct list_head *p;
-	int ret;
-	int i = 0;
+	int ret = 0;
 
-	ret = _count_mpu_irqs(oh) + _count_sdma_reqs(oh);
+	if (flags & IORESOURCE_IRQ)
+		ret += _count_mpu_irqs(oh);
 
-	p = oh->slave_ports.next;
+	if (flags & IORESOURCE_DMA)
+		ret += _count_sdma_reqs(oh);
 
-	while (i < oh->slaves_cnt) {
-		os = _fetch_next_ocp_if(&p, &i);
-		ret += _count_ocp_if_addr_spaces(os);
+	if (flags & IORESOURCE_MEM) {
+		int i = 0;
+		struct omap_hwmod_ocp_if *os;
+		struct list_head *p = oh->slave_ports.next;
+
+		while (i < oh->slaves_cnt) {
+			os = _fetch_next_ocp_if(&p, &i);
+			ret += _count_ocp_if_addr_spaces(os);
+		}
 	}
 
 	return ret;
arch/arm/mach-omap2/omap_hwmod.h +1 -1
index 421ff65..86b7414 100644
@@ -631,7 +631,7 @@ void omap_hwmod_write(u32 v, struct omap_hwmod *oh, u16 reg_offs);
 u32 omap_hwmod_read(struct omap_hwmod *oh, u16 reg_offs);
 int omap_hwmod_softreset(struct omap_hwmod *oh);
 
-int omap_hwmod_count_resources(struct omap_hwmod *oh);
+int omap_hwmod_count_resources(struct omap_hwmod *oh, unsigned long flags);
 int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res);
 int omap_hwmod_fill_dma_resources(struct omap_hwmod *oh, struct resource *res);
 int omap_hwmod_get_resource_byname(struct omap_hwmod *oh, unsigned int type,
Signature · 1 line
1.7.10.4
#6 lore raw

PATCH v2 2/2 ARM: OMAP: omap_device: Correct resource handling for DT boot

In reply to Peter Ujfalusi

When booting with DT the OF core can fill up the resources provided within the DT blob.
The current way of handling the DT boot prevents us from removing hwmod data for platforms only suppose to boot with DT (OMAP5 for example) since we need to keep the whole hwmod database intact in order to have more resources in hwmod than in DT (to be able to append the DMA resource from hwmod).

To fix this issue we just examine the OF provided resources:
If we do not have resources we use hwmod to fill them.
If we have resources we check if we already able to recive DMA resource, if no we only append the DMA resurce from hwmod to the OF provided ones.

In this way we can start removing hwmod data for devices which have their resources correctly configured in DT without regressions.

---
 arch/arm/plat-omap/omap_device.c | 84 ++++++++++++++++++++++++----------------
 1 file changed, 51 insertions(+), 33 deletions(-)
arch/arm/plat-omap/omap_device.c +51 -33
index 915cf68..d35b468 100644
@@ -560,55 +560,73 @@ struct omap_device *omap_device_alloc(struct platform_device *pdev,
 	od->hwmods = hwmods;
 	od->pdev = pdev;
 
-	/* Count all resources for the device */
-	res_count = omap_device_count_resources(od, IORESOURCE_IRQ |
-						    IORESOURCE_DMA |
-						    IORESOURCE_MEM);
 	/*
+	 * Non-DT Boot:
+	 *   Here, pdev->num_resources = 0, and we should get all the
+	 *   resources from hwmod.
+	 *
 	 * DT Boot:
 	 *   OF framework will construct the resource structure (currently
 	 *   does for MEM & IRQ resource) and we should respect/use these
 	 *   resources, killing hwmod dependency.
 	 *   If pdev->num_resources > 0, we assume that MEM & IRQ resources
 	 *   have been allocated by OF layer already (through DTB).
-	 *
-	 * Non-DT Boot:
-	 *   Here, pdev->num_resources = 0, and we should get all the
-	 *   resources from hwmod.
+	 *   As preparation for the future we examine the OF provided resources
+	 *   to see if we have DMA resources provided already. In this case
+	 *   there is no need to update the resources for the device, we use the
+	 *   OF provided ones.
 	 *
 	 * TODO: Once DMA resource is available from OF layer, we should
 	 *   kill filling any resources from hwmod.
 	 */
-	if (res_count > pdev->num_resources) {
-		/* Allocate resources memory to account for new resources */
-		res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL);
-		if (!res)
-			goto oda_exit3;
-
-		/*
-		 * If pdev->num_resources > 0, then assume that,
-		 * MEM and IRQ resources will only come from DT and only
-		 * fill DMA resource from hwmod layer.
-		 */
-		if (pdev->num_resources && pdev->resource) {
-			dev_dbg(&pdev->dev, "%s(): resources already allocated %d\n",
-				__func__, res_count);
-			memcpy(res, pdev->resource,
-			       sizeof(struct resource) * pdev->num_resources);
-			_od_fill_dma_resources(od, &res[pdev->num_resources]);
-		} else {
-			dev_dbg(&pdev->dev, "%s(): using resources from hwmod %d\n",
-				__func__, res_count);
-			omap_device_fill_resources(od, res);
+	if (!pdev->num_resources) {
+		/* Count all resources for the device */
+		res_count = omap_device_count_resources(od, IORESOURCE_IRQ |
+							    IORESOURCE_DMA |
+							    IORESOURCE_MEM);
+	} else {
+		/* Take a look if we already have DMA resource via DT */
+		for (i = 0; i < pdev->num_resources; i++) {
+			struct resource *r = &pdev->resource[i];
+
+			/* We have it, no need to touch the resources */
+			if (r->flags == IORESOURCE_DMA)
+				goto have_everything;
 		}
+		/* Count only DMA resources for the device */
+		res_count = omap_device_count_resources(od, IORESOURCE_DMA);
+		/* The device has no DMA resource, no need for update */
+		if (!res_count)
+			goto have_everything;
+	
+		res_count += pdev->num_resources;
+	}
 
-		ret = platform_device_add_resources(pdev, res, res_count);
-		kfree(res);
+	/* Allocate resources memory to account for new resources */
+	res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL);
+	if (!res)
+		goto oda_exit3;
 
-		if (ret)
-			goto oda_exit3;
+	if (!pdev->num_resources) {
+		dev_dbg(&pdev->dev, "%s: using %d resources from hwmod\n",
+			__func__, res_count);
+		omap_device_fill_resources(od, res);
+	} else {
+		dev_dbg(&pdev->dev,
+			"%s: appending %d DMA resources from hwmod\n",
+			__func__, res_count - pdev->num_resources);
+		memcpy(res, pdev->resource,
+		       sizeof(struct resource) * pdev->num_resources);
+		_od_fill_dma_resources(od, &res[pdev->num_resources]);
 	}
 
+	ret = platform_device_add_resources(pdev, res, res_count);
+	kfree(res);
+
+	if (ret)
+		goto oda_exit3;
+
+have_everything:
 	if (!pm_lats) {
 		pm_lats = omap_default_latency;
 		pm_lats_cnt = ARRAY_SIZE(omap_default_latency);
Signature · 1 line
1.7.12.4
#7 lore raw

PATCH v2 2/2 ARM: OMAP: omap_device: Correct resource handling for DT boot

Quoted 12 lines · Peter Ujfalusi

When booting with DT the OF core can fill up the resources provided within the DT blob.
The current way of handling the DT boot prevents us from removing hwmod data for platforms only suppose to boot with DT (OMAP5 for example) since we need to keep the whole hwmod database intact in order to have more resources in hwmod than in DT (to be able to append the DMA resource from hwmod).

To fix this issue we just examine the OF provided resources:
If we do not have resources we use hwmod to fill them.
If we have resources we check if we already able to recive DMA resource, if no we only append the DMA resurce from hwmod to the OF provided ones.

Quoted 4 lines

In this way we can start removing hwmod data for devices which have their resources correctly configured in DT without regressions.

Benoit, feel free to take this one as well.

Kevin

#8 lore raw

PATCH v2 2/2 ARM: OMAP: omap_device: Correct resource handling for DT boot

Hi Kevin,

Quoted 18 lines · Kevin Hilman
Quoted 17 lines · Peter Ujfalusi

When booting with DT the OF core can fill up the resources provided within
the DT blob.
The current way of handling the DT boot prevents us from removing hwmod data
for platforms only suppose to boot with DT (OMAP5 for example) since we need
to keep the whole hwmod database intact in order to have more resources in
hwmod than in DT (to be able to append the DMA resource from hwmod).

To fix this issue we just examine the OF provided resources:
If we do not have resources we use hwmod to fill them.
If we have resources we check if we already able to recive DMA resource, if
no we only append the DMA resurce from hwmod to the OF provided ones.

Quoted 8 lines
Quoted 4 lines

In this way we can start removing hwmod data for devices which have their resources correctly configured in DT without regressions.

Benoit, feel free to take this one as well.

Thanks, I'll do.

Regards,
Benoit

maintainer
#9 lore raw

PATCH v2 2/2 ARM: OMAP: omap_device: Correct resource handling for DT boot

In reply to Peter Ujfalusi
Quoted 12 lines · Peter Ujfalusi

When booting with DT the OF core can fill up the resources provided within the DT blob.
The current way of handling the DT boot prevents us from removing hwmod data for platforms only suppose to boot with DT (OMAP5 for example) since we need to keep the whole hwmod database intact in order to have more resources in hwmod than in DT (to be able to append the DMA resource from hwmod).

To fix this issue we just examine the OF provided resources:
If we do not have resources we use hwmod to fill them.
If we have resources we check if we already able to recive DMA resource, if no we only append the DMA resurce from hwmod to the OF provided ones.

Quoted 4 lines

In this way we can start removing hwmod data for devices which have their resources correctly configured in DT without regressions.

Here's this one, updated to apply after the v3.8 cleanups.

- Paul

Quoted 1 line

From 65e57fff87781b60e9406888e0ae803cb0df41cc Mon Sep 17 00:00:00 2001

From: Peter Ujfalusi <[email protected]>
Date: Wed, 21 Nov 2012 11:50:46 -0700
Subject: [PATCH 2/2] ARM: OMAP2+: omap_device: Correct resource handling for
DT boot
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When booting with DT the OF core can fill up the resources provided within the DT blob.
The current way of handling the DT boot prevents us from removing hwmod data for platforms only suppose to boot with DT (OMAP5 for example) since we need to keep the whole hwmod database intact in order to have more resources in hwmod than in DT (to be able to append the DMA resource from hwmod).

To fix this issue we just examine the OF provided resources:
If we do not have resources we use hwmod to fill them.
If we have resources we check if we already able to recive DMA resource, if no we only append the DMA resurce from hwmod to the OF provided ones.

In this way we can start removing hwmod data for devices which have their resources correctly configured in DT without regressions.

[paul at pwsan.com: fixed checkpatch problem; updated to apply]
---
 arch/arm/mach-omap2/omap_device.c |   84 ++++++++++++++++++++++---------------
 1 file changed, 51 insertions(+), 33 deletions(-)
arch/arm/mach-omap2/omap_device.c +51 -33
index 8917a08..e065daa 100644
@@ -559,55 +559,73 @@ struct omap_device *omap_device_alloc(struct platform_device *pdev,
 	od->hwmods = hwmods;
 	od->pdev = pdev;
 
-	/* Count all resources for the device */
-	res_count = omap_device_count_resources(od, IORESOURCE_IRQ |
-						    IORESOURCE_DMA |
-						    IORESOURCE_MEM);
 	/*
+	 * Non-DT Boot:
+	 *   Here, pdev->num_resources = 0, and we should get all the
+	 *   resources from hwmod.
+	 *
 	 * DT Boot:
 	 *   OF framework will construct the resource structure (currently
 	 *   does for MEM & IRQ resource) and we should respect/use these
 	 *   resources, killing hwmod dependency.
 	 *   If pdev->num_resources > 0, we assume that MEM & IRQ resources
 	 *   have been allocated by OF layer already (through DTB).
-	 *
-	 * Non-DT Boot:
-	 *   Here, pdev->num_resources = 0, and we should get all the
-	 *   resources from hwmod.
+	 *   As preparation for the future we examine the OF provided resources
+	 *   to see if we have DMA resources provided already. In this case
+	 *   there is no need to update the resources for the device, we use the
+	 *   OF provided ones.
 	 *
 	 * TODO: Once DMA resource is available from OF layer, we should
 	 *   kill filling any resources from hwmod.
 	 */
-	if (res_count > pdev->num_resources) {
-		/* Allocate resources memory to account for new resources */
-		res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL);
-		if (!res)
-			goto oda_exit3;
-
-		/*
-		 * If pdev->num_resources > 0, then assume that,
-		 * MEM and IRQ resources will only come from DT and only
-		 * fill DMA resource from hwmod layer.
-		 */
-		if (pdev->num_resources && pdev->resource) {
-			dev_dbg(&pdev->dev, "%s(): resources already allocated %d\n",
-				__func__, res_count);
-			memcpy(res, pdev->resource,
-			       sizeof(struct resource) * pdev->num_resources);
-			_od_fill_dma_resources(od, &res[pdev->num_resources]);
-		} else {
-			dev_dbg(&pdev->dev, "%s(): using resources from hwmod %d\n",
-				__func__, res_count);
-			omap_device_fill_resources(od, res);
+	if (!pdev->num_resources) {
+		/* Count all resources for the device */
+		res_count = omap_device_count_resources(od, IORESOURCE_IRQ |
+							    IORESOURCE_DMA |
+							    IORESOURCE_MEM);
+	} else {
+		/* Take a look if we already have DMA resource via DT */
+		for (i = 0; i < pdev->num_resources; i++) {
+			struct resource *r = &pdev->resource[i];
+
+			/* We have it, no need to touch the resources */
+			if (r->flags == IORESOURCE_DMA)
+				goto have_everything;
 		}
+		/* Count only DMA resources for the device */
+		res_count = omap_device_count_resources(od, IORESOURCE_DMA);
+		/* The device has no DMA resource, no need for update */
+		if (!res_count)
+			goto have_everything;
 
-		ret = platform_device_add_resources(pdev, res, res_count);
-		kfree(res);
+		res_count += pdev->num_resources;
+	}
 
-		if (ret)
-			goto oda_exit3;
+	/* Allocate resources memory to account for new resources */
+	res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL);
+	if (!res)
+		goto oda_exit3;
+
+	if (!pdev->num_resources) {
+		dev_dbg(&pdev->dev, "%s: using %d resources from hwmod\n",
+			__func__, res_count);
+		omap_device_fill_resources(od, res);
+	} else {
+		dev_dbg(&pdev->dev,
+			"%s: appending %d DMA resources from hwmod\n",
+			__func__, res_count - pdev->num_resources);
+		memcpy(res, pdev->resource,
+		       sizeof(struct resource) * pdev->num_resources);
+		_od_fill_dma_resources(od, &res[pdev->num_resources]);
 	}
 
+	ret = platform_device_add_resources(pdev, res, res_count);
+	kfree(res);
+
+	if (ret)
+		goto oda_exit3;
+
+have_everything:
 	if (!pm_lats) {
 		pm_lats = omap_default_latency;
 		pm_lats_cnt = ARRAY_SIZE(omap_default_latency);
Signature · 1 line
1.7.10.4
#10 lore raw

v2 cover ARM: OMAP: hwmod/omapd_device: Fix for resource handling in DT boot

In reply to Peter Ujfalusi

Hi Peter,

Quoted 7 lines · Peter Ujfalusi

Hello,

Changes since v1:
- If the device does not have DMA resource do not try to recreate the resources

Intro mail from v1:

Quoted 7 lines

This series resolves the issue we currently have with the resource handling when booting with DT.
In short: at the moment the omap_device_alloc() decides if it needs to update the OF filled resources based on the number of resources on the device and in the hwmod database.
This prevents us from removing hwmod data for platforms (OMAP5) which does not support non DT boot anymore.

At list removing 160 lines for out of tree data for OMAP5 audio part. So going in the good direction. But should much more after cleaning up all IP. Now we need to add DMA binding to remove the data.

Quoted 17 lines

With this series we can make sure that the DT provided resources are used and we only append the DMA resources to the device from hwmod.
I have added extra check to prepare us when the DMA resource can be filled via OF. In this case we do not update the resources at all.

Tony, Benoit, Paul: Not sure if this qualify for 3.7 inclusion, but for sure going to help us to clean up the OMAP5 hwmod database.

Regards,
Peter
---
Peter Ujfalusi (2):
ARM: OMAP: hwmod: Add possibility to count hwmod resources based on
type
ARM: OMAP: omap_device: Correct resource handling for DT boot

Quoted 5 lines
  arch/arm/mach-omap2/omap_hwmod.c             | 27 +++++----
  arch/arm/plat-omap/include/plat/omap_hwmod.h |  2 +-
  arch/arm/plat-omap/omap_device.c             | 87 ++++++++++++++++++----------
  3 files changed, 72 insertions(+), 44 deletions(-)