linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] ARM: OMAP: hwmod/omapd_device: Fix for resource handling in DT boot
@ 2012-10-30 10:33 Peter Ujfalusi
  2012-10-30 10:33 ` [PATCH 1/2] ARM: OMAP: hwmod: Add possibility to count hwmod resources based on type Peter Ujfalusi
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Peter Ujfalusi @ 2012-10-30 10:33 UTC (permalink / raw)
  To: linux-arm-kernel

Hello,

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             | 83 +++++++++++++++++-----------
 3 files changed, 68 insertions(+), 44 deletions(-)

-- 
1.7.12.4

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

* [PATCH 1/2] ARM: OMAP: hwmod: Add possibility to count hwmod resources based on type
  2012-10-30 10:33 [PATCH 0/2] ARM: OMAP: hwmod/omapd_device: Fix for resource handling in DT boot Peter Ujfalusi
@ 2012-10-30 10:33 ` Peter Ujfalusi
  2012-10-30 10:33 ` [PATCH 2/2] ARM: OMAP: omap_device: Correct resource handling for DT boot Peter Ujfalusi
  2012-10-30 11:25 ` [PATCH 0/2] ARM: OMAP: hwmod/omapd_device: Fix for resource handling in " Paul Walmsley
  2 siblings, 0 replies; 6+ messages in thread
From: Peter Ujfalusi @ 2012-10-30 10:33 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 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(-)

diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
index b969ab1..a79c941 100644
--- a/arch/arm/mach-omap2/omap_hwmod.c
+++ b/arch/arm/mach-omap2/omap_hwmod.c
@@ -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;
diff --git a/arch/arm/plat-omap/include/plat/omap_hwmod.h b/arch/arm/plat-omap/include/plat/omap_hwmod.h
index b3349f7..48a6f5d 100644
--- a/arch/arm/plat-omap/include/plat/omap_hwmod.h
+++ b/arch/arm/plat-omap/include/plat/omap_hwmod.h
@@ -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,
diff --git a/arch/arm/plat-omap/omap_device.c b/arch/arm/plat-omap/omap_device.c
index 7a7d1f2..915cf68 100644
--- a/arch/arm/plat-omap/omap_device.c
+++ b/arch/arm/plat-omap/omap_device.c
@@ -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
-- 
1.7.12.4

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

* [PATCH 2/2] ARM: OMAP: omap_device: Correct resource handling for DT boot
  2012-10-30 10:33 [PATCH 0/2] ARM: OMAP: hwmod/omapd_device: Fix for resource handling in DT boot Peter Ujfalusi
  2012-10-30 10:33 ` [PATCH 1/2] ARM: OMAP: hwmod: Add possibility to count hwmod resources based on type Peter Ujfalusi
@ 2012-10-30 10:33 ` Peter Ujfalusi
  2012-10-30 11:21   ` Péter Ujfalusi
  2012-10-30 11:25 ` [PATCH 0/2] ARM: OMAP: hwmod/omapd_device: Fix for resource handling in " Paul Walmsley
  2 siblings, 1 reply; 6+ messages in thread
From: Peter Ujfalusi @ 2012-10-30 10:33 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 arch/arm/plat-omap/omap_device.c | 80 +++++++++++++++++++++++-----------------
 1 file changed, 47 insertions(+), 33 deletions(-)

diff --git a/arch/arm/plat-omap/omap_device.c b/arch/arm/plat-omap/omap_device.c
index 915cf68..a8a9d08 100644
--- a/arch/arm/plat-omap/omap_device.c
+++ b/arch/arm/plat-omap/omap_device.c
@@ -560,55 +560,69 @@ 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);
+		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);
-- 
1.7.12.4

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

* [PATCH 2/2] ARM: OMAP: omap_device: Correct resource handling for DT boot
  2012-10-30 10:33 ` [PATCH 2/2] ARM: OMAP: omap_device: Correct resource handling for DT boot Peter Ujfalusi
@ 2012-10-30 11:21   ` Péter Ujfalusi
  0 siblings, 0 replies; 6+ messages in thread
From: Péter Ujfalusi @ 2012-10-30 11:21 UTC (permalink / raw)
  To: linux-arm-kernel

On 10/30/2012 11:33 AM, Peter Ujfalusi wrote:
> 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.
> 
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
> ---
>  arch/arm/plat-omap/omap_device.c | 80 +++++++++++++++++++++++-----------------
>  1 file changed, 47 insertions(+), 33 deletions(-)
> 
> diff --git a/arch/arm/plat-omap/omap_device.c b/arch/arm/plat-omap/omap_device.c
> index 915cf68..a8a9d08 100644
> --- a/arch/arm/plat-omap/omap_device.c
> +++ b/arch/arm/plat-omap/omap_device.c
> @@ -560,55 +560,69 @@ 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);

We have devices without DMA channel so we can skip the resource recreation for
them.
I'll resend the series with this update.

> +		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);
> 


-- 
P?ter

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

* [PATCH 0/2] ARM: OMAP: hwmod/omapd_device: Fix for resource handling in DT boot
  2012-10-30 10:33 [PATCH 0/2] ARM: OMAP: hwmod/omapd_device: Fix for resource handling in DT boot Peter Ujfalusi
  2012-10-30 10:33 ` [PATCH 1/2] ARM: OMAP: hwmod: Add possibility to count hwmod resources based on type Peter Ujfalusi
  2012-10-30 10:33 ` [PATCH 2/2] ARM: OMAP: omap_device: Correct resource handling for DT boot Peter Ujfalusi
@ 2012-10-30 11:25 ` Paul Walmsley
  2012-10-30 11:33   ` Péter Ujfalusi
  2 siblings, 1 reply; 6+ messages in thread
From: Paul Walmsley @ 2012-10-30 11:25 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, 30 Oct 2012, Peter Ujfalusi wrote:

> 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.

It's definitely not 3.7 material, but will look at it for 3.8 merge 
window.  The OMAP5 hwmod data isn't in mainline yet.


- Paul

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

* [PATCH 0/2] ARM: OMAP: hwmod/omapd_device: Fix for resource handling in DT boot
  2012-10-30 11:25 ` [PATCH 0/2] ARM: OMAP: hwmod/omapd_device: Fix for resource handling in " Paul Walmsley
@ 2012-10-30 11:33   ` Péter Ujfalusi
  0 siblings, 0 replies; 6+ messages in thread
From: Péter Ujfalusi @ 2012-10-30 11:33 UTC (permalink / raw)
  To: linux-arm-kernel

On 10/30/2012 12:25 PM, Paul Walmsley wrote:
> On Tue, 30 Oct 2012, Peter Ujfalusi wrote:
> 
>> 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.
> 
> It's definitely not 3.7 material, but will look at it for 3.8 merge 
> window.  The OMAP5 hwmod data isn't in mainline yet.

True, it can wait till 3.8.

-- 
P?ter

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

end of thread, other threads:[~2012-10-30 11:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-30 10:33 [PATCH 0/2] ARM: OMAP: hwmod/omapd_device: Fix for resource handling in DT boot Peter Ujfalusi
2012-10-30 10:33 ` [PATCH 1/2] ARM: OMAP: hwmod: Add possibility to count hwmod resources based on type Peter Ujfalusi
2012-10-30 10:33 ` [PATCH 2/2] ARM: OMAP: omap_device: Correct resource handling for DT boot Peter Ujfalusi
2012-10-30 11:21   ` Péter Ujfalusi
2012-10-30 11:25 ` [PATCH 0/2] ARM: OMAP: hwmod/omapd_device: Fix for resource handling in " Paul Walmsley
2012-10-30 11:33   ` Péter Ujfalusi

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).