Skip to contentSkip to conversation

dmaengine: ste_dma40, imx-dma: Cleanup scatterlist layering violations

PATCH Superseded Logan Gunthorpe 3 participants 3 messages May 24, 2017 – May 30, 2017

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmaengine: ste_dma40, imx-dma: Cleanup scatterlist layering violations

Two dma engine drivers directly accesses page_link assuming knowledge that should be contained only in scatterlist.h.

We replace these with calls to sg_chain and sg_assign_page.

---
 drivers/dma/imx-dma.c   | 7 ++-----
 drivers/dma/ste_dma40.c | 5 +----
 2 files changed, 3 insertions(+), 9 deletions(-)
drivers/dma/imx-dma.c +2 -5
index ab0fb80..f681df8 100644
@@ -888,7 +888,7 @@ static struct dma_async_tx_descriptor *imxdma_prep_dma_cyclic(
 	sg_init_table(imxdmac->sg_list, periods);
 
 	for (i = 0; i < periods; i++) {
-		imxdmac->sg_list[i].page_link = 0;
+		sg_assign_page(&imxdmac->sg_list[i], NULL);
 		imxdmac->sg_list[i].offset = 0;
 		imxdmac->sg_list[i].dma_address = dma_addr;
 		sg_dma_len(&imxdmac->sg_list[i]) = period_len;
@@ -896,10 +896,7 @@ static struct dma_async_tx_descriptor *imxdma_prep_dma_cyclic(
 	}
 
 	/* close the loop */
-	imxdmac->sg_list[periods].offset = 0;
-	sg_dma_len(&imxdmac->sg_list[periods]) = 0;
-	imxdmac->sg_list[periods].page_link =
-		((unsigned long)imxdmac->sg_list | 0x01) & ~0x02;
+	sg_chain(imxdmac->sg_list, periods + 1, imxdmac->sg_list);
 
 	desc->type = IMXDMA_DESC_CYCLIC;
 	desc->sg = imxdmac->sg_list;
drivers/dma/ste_dma40.c +1 -4
index a6620b6..c3052fb 100644
@@ -2528,10 +2528,7 @@ dma40_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t dma_addr,
 		dma_addr += period_len;
 	}
 
-	sg[periods].offset = 0;
-	sg_dma_len(&sg[periods]) = 0;
-	sg[periods].page_link =
-		((unsigned long)sg | 0x01) & ~0x02;
+	sg_chain(sg, periods + 1, sg);
 
 	txd = d40_prep_sg(chan, sg, sg, periods, direction,
 			  DMA_PREP_INTERRUPT);
Signature · 1 line
2.1.4
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Logan Gunthorpe

Two dma engine drivers directly accesses page_link assuming knowledge that should be contained only in scatterlist.h.

We replace these with calls to sg_chain and sg_assign_page.

OMG I guess you know what you're doing, so:

I will shout if Ux500 breaks.

CC Per Förlin who wrote the code.

Quoted 48 lines
 drivers/dma/imx-dma.c   | 7 ++-----
 drivers/dma/ste_dma40.c | 5 +----
 2 files changed, 3 insertions(+), 9 deletions(-)
drivers/dma/imx-dma.c +2 -5
index ab0fb80..f681df8 100644
@@ -888,7 +888,7 @@ static struct dma_async_tx_descriptor *imxdma_prep_dma_cyclic(
        sg_init_table(imxdmac->sg_list, periods);
 
        for (i = 0; i < periods; i++) {
-               imxdmac->sg_list[i].page_link = 0;
+               sg_assign_page(&imxdmac->sg_list[i], NULL);
                imxdmac->sg_list[i].offset = 0;
                imxdmac->sg_list[i].dma_address = dma_addr;
                sg_dma_len(&imxdmac->sg_list[i]) = period_len;
@@ -896,10 +896,7 @@ static struct dma_async_tx_descriptor *imxdma_prep_dma_cyclic(
        }
 
        /* close the loop */
-       imxdmac->sg_list[periods].offset = 0;
-       sg_dma_len(&imxdmac->sg_list[periods]) = 0;
-       imxdmac->sg_list[periods].page_link =
-               ((unsigned long)imxdmac->sg_list | 0x01) & ~0x02;
+       sg_chain(imxdmac->sg_list, periods + 1, imxdmac->sg_list);
 
        desc->type = IMXDMA_DESC_CYCLIC;
        desc->sg = imxdmac->sg_list;
drivers/dma/ste_dma40.c +1 -5
index a6620b6..c3052fb 100644
@@ -2528,10 +2528,7 @@ dma40_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t dma_addr,
                dma_addr += period_len;
        }
 
-       sg[periods].offset = 0;
-       sg_dma_len(&sg[periods]) = 0;
-       sg[periods].page_link =
-               ((unsigned long)sg | 0x01) & ~0x02;
+       sg_chain(sg, periods + 1, sg);
 
        txd = d40_prep_sg(chan, sg, sg, periods, direction,
                          DMA_PREP_INTERRUPT);
--

2.1.4

#2 lore raw
In reply to Logan Gunthorpe
Quoted 4 lines · Logan Gunthorpe

Two dma engine drivers directly accesses page_link assuming knowledge that should be contained only in scatterlist.h.

We replace these with calls to sg_chain and sg_assign_page.

good catch, but can you please split these to per driver

Quoted 55 lines
---
 drivers/dma/imx-dma.c   | 7 ++-----
 drivers/dma/ste_dma40.c | 5 +----
 2 files changed, 3 insertions(+), 9 deletions(-)
drivers/dma/imx-dma.c +2 -5
index ab0fb80..f681df8 100644
@@ -888,7 +888,7 @@ static struct dma_async_tx_descriptor *imxdma_prep_dma_cyclic(
 	sg_init_table(imxdmac->sg_list, periods);
 
 	for (i = 0; i < periods; i++) {
-		imxdmac->sg_list[i].page_link = 0;
+		sg_assign_page(&imxdmac->sg_list[i], NULL);
 		imxdmac->sg_list[i].offset = 0;
 		imxdmac->sg_list[i].dma_address = dma_addr;
 		sg_dma_len(&imxdmac->sg_list[i]) = period_len;
@@ -896,10 +896,7 @@ static struct dma_async_tx_descriptor *imxdma_prep_dma_cyclic(
 	}
 
 	/* close the loop */
-	imxdmac->sg_list[periods].offset = 0;
-	sg_dma_len(&imxdmac->sg_list[periods]) = 0;
-	imxdmac->sg_list[periods].page_link =
-		((unsigned long)imxdmac->sg_list | 0x01) & ~0x02;
+	sg_chain(imxdmac->sg_list, periods + 1, imxdmac->sg_list);
 
 	desc->type = IMXDMA_DESC_CYCLIC;
 	desc->sg = imxdmac->sg_list;
drivers/dma/ste_dma40.c +1 -4
index a6620b6..c3052fb 100644
@@ -2528,10 +2528,7 @@ dma40_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t dma_addr,
 		dma_addr += period_len;
 	}
 
-	sg[periods].offset = 0;
-	sg_dma_len(&sg[periods]) = 0;
-	sg[periods].page_link =
-		((unsigned long)sg | 0x01) & ~0x02;
+	sg_chain(sg, periods + 1, sg);
 
 	txd = d40_prep_sg(chan, sg, sg, periods, direction,
 			  DMA_PREP_INTERRUPT);
Signature · 1 line
2.1.4
Signature · 1 line
~Vinod