Skip to contentSkip to conversation

ARM: EDMA: Fix clearing of unused list for DT DMA resources

PATCH Superseded Joel Fernandes 2 participants 10 messages Jul 22, 2013 – Jul 31, 2013

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ARM: EDMA: Fix clearing of unused list for DT DMA resources

HWMOD removal for MMC is breaking edma_start as the events are being manually triggered due to unused channel list not being clear, Thanks to Balaji TK for finding this issue.

This patch fixes the issue, by reading the "dmas" property from the DT node if it exists and clearing the bits in the unused channel list.

Cc Balaji T K <[email protected]>
Cc Pantel Antoniou <[email protected]>

---
v2 changes: Fixed compiler warning

 arch/arm/common/edma.c |   31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)
arch/arm/common/edma.c +23 -8
index a432e6c..765d578 100644
@@ -561,14 +561,29 @@ static int reserve_contiguous_slots(int ctlr, unsigned int id,
 static int prepare_unused_channel_list(struct device *dev, void *data)
 {
 	struct platform_device *pdev = to_platform_device(dev);
-	int i, ctlr;
-
-	for (i = 0; i < pdev->num_resources; i++) {
-		if ((pdev->resource[i].flags & IORESOURCE_DMA) &&
-				(int)pdev->resource[i].start >= 0) {
-			ctlr = EDMA_CTLR(pdev->resource[i].start);
-			clear_bit(EDMA_CHAN_SLOT(pdev->resource[i].start),
-					edma_cc[ctlr]->edma_unused);
+	int i = 0, ctlr;
+	u32 dma_chan;
+	const __be32 *dma_chan_p;
+	struct property *prop;
+
+	if (dev->of_node) {
+		of_property_for_each_u32(dev->of_node, "dmas", prop, \
+					 dma_chan_p, dma_chan) {
+			if (i++ & 1) {
+				ctlr = EDMA_CTLR(dma_chan);
+				clear_bit(EDMA_CHAN_SLOT(dma_chan),
+						edma_cc[ctlr]->edma_unused);
+			}
+		}
+	} else {
+		for (; i < pdev->num_resources; i++) {
+			if ((pdev->resource[i].flags & IORESOURCE_DMA) &&
+			    (int)pdev->resource[i].start >= 0) {
+				ctlr = EDMA_CTLR(pdev->resource[i].start);
+				clear_bit(EDMA_CHAN_SLOT(
+					  pdev->resource[i].start),
+					  edma_cc[ctlr]->edma_unused);
+			}
 		}
 	}
 
Signature · 1 line
1.7.9.5
#1 lore raw

Hi Tony or Sekhar,

If this patch looks ok, could you pick it up for -rc cycle?

It fixes DMA breakages after the merge window for devices for which DMA resources are being populated in device tree instead pdev.

Thanks,

-Joel

Quoted 59 lines · Joel Fernandes

HWMOD removal for MMC is breaking edma_start as the events are being manually triggered due to unused channel list not being clear, Thanks to Balaji TK for finding this issue.

This patch fixes the issue, by reading the "dmas" property from the DT node if it exists and clearing the bits in the unused channel list.

Cc Balaji T K <[email protected]>
Cc Pantel Antoniou <[email protected]>

---
v2 changes: Fixed compiler warning

 arch/arm/common/edma.c |   31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)
arch/arm/common/edma.c +23 -8
index a432e6c..765d578 100644
@@ -561,14 +561,29 @@ static int reserve_contiguous_slots(int ctlr, unsigned int id,
 static int prepare_unused_channel_list(struct device *dev, void *data)
 {
 	struct platform_device *pdev = to_platform_device(dev);
-	int i, ctlr;
-
-	for (i = 0; i < pdev->num_resources; i++) {
-		if ((pdev->resource[i].flags & IORESOURCE_DMA) &&
-				(int)pdev->resource[i].start >= 0) {
-			ctlr = EDMA_CTLR(pdev->resource[i].start);
-			clear_bit(EDMA_CHAN_SLOT(pdev->resource[i].start),
-					edma_cc[ctlr]->edma_unused);
+	int i = 0, ctlr;
+	u32 dma_chan;
+	const __be32 *dma_chan_p;
+	struct property *prop;
+
+	if (dev->of_node) {
+		of_property_for_each_u32(dev->of_node, "dmas", prop, \
+					 dma_chan_p, dma_chan) {
+			if (i++ & 1) {
+				ctlr = EDMA_CTLR(dma_chan);
+				clear_bit(EDMA_CHAN_SLOT(dma_chan),
+						edma_cc[ctlr]->edma_unused);
+			}
+		}
+	} else {
+		for (; i < pdev->num_resources; i++) {
+			if ((pdev->resource[i].flags & IORESOURCE_DMA) &&
+			    (int)pdev->resource[i].start >= 0) {
+				ctlr = EDMA_CTLR(pdev->resource[i].start);
+				clear_bit(EDMA_CHAN_SLOT(
+					  pdev->resource[i].start),
+					  edma_cc[ctlr]->edma_unused);
+			}
 		}
 	}
 
#2 lore raw
Quoted 6 lines · Joel Fernandes

Hi Tony or Sekhar,

If this patch looks ok, could you pick it up for -rc cycle?

It fixes DMA breakages after the merge window for devices for which DMA resources are being populated in device tree instead pdev.

But which DT-enabled platform in kernel is using EDMA? A grep for edma over arch/arm/boot/dts/* brings up nothing.

Does this really have to go into the -rc cycle or can it wait till v3.12?

Thanks,
Sekhar

#3 lore raw
Quoted 5 lines · Sekhar Nori
Quoted 4 lines · Joel Fernandes

Hi Tony or Sekhar,

If this patch looks ok, could you pick it up for -rc cycle?

Quoted 7 lines
Quoted 2 lines

It fixes DMA breakages after the merge window for devices for which DMA resources are being populated in device tree instead pdev.

But which DT-enabled platform in kernel is using EDMA? A grep for edma over arch/arm/boot/dts/* brings up nothing.
Does this really have to go into the -rc cycle or can it wait till v3.12?

But unused channel list is also populated for private EDMA callers like davinci-pcm no? IIRC, HWMOD data is also removed for McASP so EDMA for those may break.

Thanks,

-Joel

#4 lore raw
Quoted 15 lines · Joel Fernandes
Quoted 5 lines · Sekhar Nori
Quoted 4 lines · Joel Fernandes

Hi Tony or Sekhar,

If this patch looks ok, could you pick it up for -rc cycle?

Quoted 7 lines
Quoted 2 lines

It fixes DMA breakages after the merge window for devices for which DMA resources are being populated in device tree instead pdev.

But which DT-enabled platform in kernel is using EDMA? A grep for edma over arch/arm/boot/dts/* brings up nothing.
Does this really have to go into the -rc cycle or can it wait till v3.12?

Quoted 3 lines

But unused channel list is also populated for private EDMA callers like davinci-pcm no? IIRC, HWMOD data is also removed for McASP so EDMA for those may break.

Yes, but which DT-enabled platform has davinci-pcm working today? AFAICS, this bug affects DT-enabled platforms only.

Thanks,
Sekhar

#5 lore raw
Quoted 15 lines · Joel Fernandes
Quoted 15 lines · Sekhar Nori
Quoted 12 lines · Joel Fernandes
Quoted 6 lines

Hi Tony or Sekhar,

If this patch looks ok, could you pick it up for -rc cycle?

It fixes DMA breakages after the merge window for devices for which DMA resources are being populated in device tree instead pdev.

But which DT-enabled platform in kernel is using EDMA? A grep for edma over arch/arm/boot/dts/* brings up nothing.
Does this really have to go into the -rc cycle or can it wait till v3.12?

Quoted 6 lines
Quoted 3 lines

But unused channel list is also populated for private EDMA callers like davinci-pcm no? IIRC, HWMOD data is also removed for McASP so EDMA for those may break.

Yes, but which DT-enabled platform has davinci-pcm working today? AFAICS, this bug affects DT-enabled platforms only.

Yes, you're right. I didn't realize nothing else is working yet. I guess its fine then for next kernel release.

Thanks,

-Joel

#6 lore raw
In reply to Joel Fernandes
Quoted 3 lines · Joel Fernandes

HWMOD removal for MMC is breaking edma_start as the events are being manually triggered due to unused channel list not being clear, Thanks to Balaji TK for finding this issue.

So, Reported-by: Balaji T K <[email protected]>

?

Quoted 32 lines

This patch fixes the issue, by reading the "dmas" property from the DT node if it exists and clearing the bits in the unused channel list.

Cc Balaji T K <[email protected]>
Cc Pantel Antoniou <[email protected]>

---
v2 changes: Fixed compiler warning

 arch/arm/common/edma.c |   31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)
arch/arm/common/edma.c +3 -8
index a432e6c..765d578 100644
@@ -561,14 +561,29 @@ static int reserve_contiguous_slots(int ctlr, unsigned int id,
 static int prepare_unused_channel_list(struct device *dev, void *data)
 {
 	struct platform_device *pdev = to_platform_device(dev);
-	int i, ctlr;
-
-	for (i = 0; i < pdev->num_resources; i++) {
-		if ((pdev->resource[i].flags & IORESOURCE_DMA) &&
-				(int)pdev->resource[i].start >= 0) {
-			ctlr = EDMA_CTLR(pdev->resource[i].start);
-			clear_bit(EDMA_CHAN_SLOT(pdev->resource[i].start),
-					edma_cc[ctlr]->edma_unused);
+	int i = 0, ctlr;
+	u32 dma_chan;
+	const __be32 *dma_chan_p;

arch/arm/common/edma.c static int reserve_contiguous_slots(int ctlr, unsigned int id, · line 576

Quoted 10 lines
arch/arm/common/edma.c +10 -0
+	struct property *prop;
+
+	if (dev->of_node) {
+		of_property_for_each_u32(dev->of_node, "dmas", prop, \
+					 dma_chan_p, dma_chan) {
+			if (i++ & 1) {
+				ctlr = EDMA_CTLR(dma_chan);
+				clear_bit(EDMA_CHAN_SLOT(dma_chan),
+						edma_cc[ctlr]->edma_unused);
+			}

I think it will be cleaner if you use of_property_count_strings() on dma-names to get the count of DMA channels for this device and then use of_parse_phandle_with_args() to get access to the args. Honestly, I have not used these APIs myself, so if this doesn?t work the way I think it should then let me know and I will try to do some experiments myself.

The current way of skipping over even fields really depends on #dma-cells for EDMA to be 1. That in itself is not such a bad assumption, but if you have APIs which already take care of this for you, why not use them?

arch/arm/common/edma.c static int reserve_contiguous_slots(int ctlr, unsigned int id, · line 586

Quoted 10 lines
arch/arm/common/edma.c +10 -0
+		}
+	} else {
+		for (; i < pdev->num_resources; i++) {
+			if ((pdev->resource[i].flags & IORESOURCE_DMA) &&
+			    (int)pdev->resource[i].start >= 0) {
+				ctlr = EDMA_CTLR(pdev->resource[i].start);
+				clear_bit(EDMA_CHAN_SLOT(
+					  pdev->resource[i].start),
+					  edma_cc[ctlr]->edma_unused);
+			}

So there is very little in common between OF and non-OF versions of this function. Why not have two different versions of this function for the two cases? The OF version can reside under the CONFIG_OF conditional already in use in the file. This will also save you the ugly line breaks you had to resort to due to too deep indentation.

Thanks,
Sekhar

#7 lore raw
Quoted 1 line · Joel Fernandes
Quoted 1 line

HWMOD removal for MMC is breaking edma_start as the events are being

manually

Quoted 1 line
Quoted 1 line

triggered due to unused channel list not being clear, Thanks to

Balaji TK for

Quoted 5 lines
Quoted 1 line

finding this issue.

So, Reported-by: Balaji T K <[email protected]>

?

Sure, I'll add that as well.

Quoted 3 lines
Quoted 3 lines

This patch fixes the issue, by reading the "dmas" property from the

DT node if

Quoted 8 lines
Quoted 8 lines

it exists and clearing the bits in the unused channel list.

Cc Balaji T K <[email protected]>
Cc Pantel Antoniou <[email protected]>

---
v2 changes: Fixed compiler warning

Quoted 8 lines

arch/arm/common/edma.c static int reserve_contiguous_slots(int ctlr,

Quoted 8 lines
 arch/arm/common/edma.c |   31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)
arch/arm/common/edma.c +0 -0
index a432e6c..765d578 100644
@@ -561,14 +561,29 @@ static int reserve_contiguous_slots(int ctlr,

unsigned int id,

Quoted 31 lines
Quoted 14 lines
arch/arm/common/edma.c +3 -8
 static int prepare_unused_channel_list(struct device *dev, void *data)
 {
 	struct platform_device *pdev = to_platform_device(dev);
-	int i, ctlr;
-
-	for (i = 0; i < pdev->num_resources; i++) {
-		if ((pdev->resource[i].flags & IORESOURCE_DMA) &&
-				(int)pdev->resource[i].start >= 0) {
-			ctlr = EDMA_CTLR(pdev->resource[i].start);
-			clear_bit(EDMA_CHAN_SLOT(pdev->resource[i].start),
-					edma_cc[ctlr]->edma_unused);
+	int i = 0, ctlr;
+	u32 dma_chan;
+	const __be32 *dma_chan_p;

arch/arm/common/edma.c static int reserve_contiguous_slots(int ctlr, unsigned int id, · line 576

Quoted 10 lines
arch/arm/common/edma.c +10 -0
+	struct property *prop;
+
+	if (dev->of_node) {
+		of_property_for_each_u32(dev->of_node, "dmas", prop, \
+					 dma_chan_p, dma_chan) {
+			if (i++ & 1) {
+				ctlr = EDMA_CTLR(dma_chan);
+				clear_bit(EDMA_CHAN_SLOT(dma_chan),
+						edma_cc[ctlr]->edma_unused);
+			}

I think it will be cleaner if you use of_property_count_strings() on dma-names to get the count of DMA channels for this device and then use of_parse_phandle_with_args() to get access to the args. Honestly, I have not used these APIs myself, so if this doesn?t work the way I think it should then let me know and I will try to do some experiments myself.

Quoted 4 lines

The current way of skipping over even fields really depends on #dma-cells for EDMA to be 1. That in itself is not such a bad assumption, but if you have APIs which already take care of this for you, why not use them?

Sure, looks like of_dma_request_slave_channel does same thing in drive/dma/of-dma.c. Let me follow up with a patch that does it this way. I agree its cleaner.

Quoted 8 lines
Quoted 8 lines
arch/arm/common/edma.c +8 -0
+		}
+	} else {
+		for (; i < pdev->num_resources; i++) {
+			if ((pdev->resource[i].flags & IORESOURCE_DMA) &&
+			    (int)pdev->resource[i].start >= 0) {
+				ctlr = EDMA_CTLR(pdev->resource[i].start);
+				clear_bit(EDMA_CHAN_SLOT(
+					  pdev->resource[i].start),
Quoted 8 lines

arch/arm/common/edma.c static int reserve_contiguous_slots(int ctlr, · line 586

Quoted 2 lines
arch/arm/common/edma.c +2 -0
+					  edma_cc[ctlr]->edma_unused);
+			}

So there is very little in common between OF and non-OF versions of this function. Why not have two different versions of this function for the two cases? The OF version can reside under the CONFIG_OF conditional already in use in the file. This will also save you the ugly line breaks you had to resort to due to too deep indentation.

Actually those line breaks are not necessary and wouldn't result in compilation errors. I was planning to drop them. I'll go ahead and split it out anyway, now that also the OF version of the function is going to be bit longer if we use the of_parse functions.

Thanks for your review,

Regards,

-Joel

#8 lore raw
Quoted 21 lines · Joel Fernandes
Quoted 5 lines
Quoted 4 lines
arch/arm/common/edma.c +0 -0
index a432e6c..765d578 100644
Quoted 15 lines

arch/arm/common/edma.c static int reserve_contiguous_slots(int ctlr, unsigned int id, · line 586

Quoted 9 lines
arch/arm/common/edma.c +9 -0
+	} else {
+		for (; i < pdev->num_resources; i++) {
+			if ((pdev->resource[i].flags & IORESOURCE_DMA) &&
+			    (int)pdev->resource[i].start >= 0) {
+				ctlr = EDMA_CTLR(pdev->resource[i].start);
+				clear_bit(EDMA_CHAN_SLOT(
+					  pdev->resource[i].start),
+					  edma_cc[ctlr]->edma_unused);
+			}

So there is very little in common between OF and non-OF versions of this function. Why not have two different versions of this function for the two cases? The OF version can reside under the CONFIG_OF conditional already in use in the file. This will also save you the ugly line breaks you had to resort to due to too deep indentation.

Quoted 6 lines

Actually those line breaks are not necessary and wouldn't result in compilation errors. I was planning to drop them. I'll go ahead and split it out anyway, now that also the OF version of the function is going to be bit longer if we use the of_parse functions.

Thanks for your review,

It turns out, I gave a bad idea. What I suggested will break the case of non-DT boot with CONFIG_OF enabled. So what you had was fine. May be just return from "if (dev->of_node)" so you don't need to have an else block and can save on the indentation.

Thanks,
Sekhar

#9 lore raw
Quoted 28 lines · Sekhar Nori
Quoted 26 lines · Joel Fernandes
Quoted 5 lines
Quoted 4 lines
arch/arm/common/edma.c +0 -0
index a432e6c..765d578 100644
Quoted 15 lines

arch/arm/common/edma.c static int reserve_contiguous_slots(int ctlr, unsigned int id, · line 586

Quoted 9 lines
arch/arm/common/edma.c +9 -0
+	} else {
+		for (; i < pdev->num_resources; i++) {
+			if ((pdev->resource[i].flags & IORESOURCE_DMA) &&
+			    (int)pdev->resource[i].start >= 0) {
+				ctlr = EDMA_CTLR(pdev->resource[i].start);
+				clear_bit(EDMA_CHAN_SLOT(
+					  pdev->resource[i].start),
+					  edma_cc[ctlr]->edma_unused);
+			}

So there is very little in common between OF and non-OF versions of this function. Why not have two different versions of this function for the two cases? The OF version can reside under the CONFIG_OF conditional already in use in the file. This will also save you the ugly line breaks you had to resort to due to too deep indentation.

Actually those line breaks are not necessary and wouldn't result in compilation errors. I was planning to drop them. I'll go ahead and split it out anyway, now that also the OF version of the function is going to be bit longer if we use the of_parse functions.

Quoted 6 lines
Quoted 1 line

Thanks for your review,

It turns out, I gave a bad idea. What I suggested will break the case of non-DT boot with CONFIG_OF enabled. So what you had was fine. May be just return from "if (dev->of_node)" so you don't need to have an else block and can save on the indentation.>

Ok, sure. I will go ahead and return from the if block.

Thanks,

-Joel