Skip to content

Commit 6084fc2

Browse files
stroeseVinod Koul
authored andcommitted
dmaengine: altera: Use macros instead of structs to describe the registers
This patch moves from a struct declaration for the DMA controller registers to macros with offests to the base address. This is mainly done to remove the sparse warnings, since the function parameter of ioread32/iowrite32 is "void __iomem *" instead of a pointer to struct members. With this patch applied, no sparse warning is seen anymore. Please note that the struct for the descriptors is still kept in place, as the code largely accesses the struct members as internal variables before the complete struct is copied into the descriptor FIFO of the DMA controller. Additionally this patch also removes two warnings "variable xxx set but not used" seen when compiling with "W=1". The registers need to be read to flush the response FIFO, but nothing needs to be done with them. So the code is correct here and the warning is a false one. Signed-off-by: Stefan Roese <[email protected]> Signed-off-by: Vinod Koul <[email protected]>
1 parent 491bea0 commit 6084fc2

File tree

1 file changed

+35
-45
lines changed

1 file changed

+35
-45
lines changed

drivers/dma/altera-msgdma.c

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,14 @@ struct msgdma_extended_desc {
104104
#define MSGDMA_DESC_STRIDE_WR 0x00010000
105105
#define MSGDMA_DESC_STRIDE_RW 0x00010001
106106

107-
/**
108-
* struct msgdma_csr - mSGDMA dispatcher control and status register map
109-
* @status: Read/Clear
110-
* @control: Read/Write
111-
* @rw_fill_level: bit 31:16 - write fill level
112-
* bit 15:00 - read fill level
113-
* @resp_fill_level: bit 15:00 - response FIFO fill level
114-
* @rw_seq_num: bit 31:16 - write sequence number
115-
* bit 15:00 - read sequence number
116-
* @pad: reserved
117-
*/
118-
struct msgdma_csr {
119-
u32 status;
120-
u32 control;
121-
u32 rw_fill_level;
122-
u32 resp_fill_level;
123-
u32 rw_seq_num;
124-
u32 pad[3];
125-
};
107+
/* mSGDMA dispatcher control and status register map */
108+
#define MSGDMA_CSR_STATUS 0x00 /* Read / Clear */
109+
#define MSGDMA_CSR_CONTROL 0x04 /* Read / Write */
110+
#define MSGDMA_CSR_RW_FILL_LEVEL 0x08 /* 31:16 - write fill level */
111+
/* 15:00 - read fill level */
112+
#define MSGDMA_CSR_RESP_FILL_LEVEL 0x0c /* response FIFO fill level */
113+
#define MSGDMA_CSR_RW_SEQ_NUM 0x10 /* 31:16 - write seq number */
114+
/* 15:00 - read seq number */
126115

127116
/* mSGDMA CSR status register bit definitions */
128117
#define MSGDMA_CSR_STAT_BUSY BIT(0)
@@ -157,10 +146,8 @@ struct msgdma_csr {
157146
#define MSGDMA_CSR_SEQ_NUM_GET(v) (((v) & 0xffff0000) >> 16)
158147

159148
/* mSGDMA response register map */
160-
struct msgdma_response {
161-
u32 bytes_transferred;
162-
u32 status;
163-
};
149+
#define MSGDMA_RESP_BYTES_TRANSFERRED 0x00
150+
#define MSGDMA_RESP_STATUS 0x04
164151

165152
/* mSGDMA response register bit definitions */
166153
#define MSGDMA_RESP_EARLY_TERM BIT(8)
@@ -204,13 +191,13 @@ struct msgdma_device {
204191
int irq;
205192

206193
/* mSGDMA controller */
207-
struct msgdma_csr *csr;
194+
void __iomem *csr;
208195

209196
/* mSGDMA descriptors */
210-
struct msgdma_extended_desc *desc;
197+
void __iomem *desc;
211198

212199
/* mSGDMA response */
213-
struct msgdma_response *resp;
200+
void __iomem *resp;
214201
};
215202

216203
#define to_mdev(chan) container_of(chan, struct msgdma_device, dmachan)
@@ -484,35 +471,36 @@ static void msgdma_reset(struct msgdma_device *mdev)
484471
int ret;
485472

486473
/* Reset mSGDMA */
487-
iowrite32(MSGDMA_CSR_STAT_MASK, &mdev->csr->status);
488-
iowrite32(MSGDMA_CSR_CTL_RESET, &mdev->csr->control);
474+
iowrite32(MSGDMA_CSR_STAT_MASK, mdev->csr + MSGDMA_CSR_STATUS);
475+
iowrite32(MSGDMA_CSR_CTL_RESET, mdev->csr + MSGDMA_CSR_CONTROL);
489476

490-
ret = readl_poll_timeout(&mdev->csr->status, val,
477+
ret = readl_poll_timeout(mdev->csr + MSGDMA_CSR_STATUS, val,
491478
(val & MSGDMA_CSR_STAT_RESETTING) == 0,
492479
1, 10000);
493480
if (ret)
494481
dev_err(mdev->dev, "DMA channel did not reset\n");
495482

496483
/* Clear all status bits */
497-
iowrite32(MSGDMA_CSR_STAT_MASK, &mdev->csr->status);
484+
iowrite32(MSGDMA_CSR_STAT_MASK, mdev->csr + MSGDMA_CSR_STATUS);
498485

499486
/* Enable the DMA controller including interrupts */
500487
iowrite32(MSGDMA_CSR_CTL_STOP_ON_ERR | MSGDMA_CSR_CTL_STOP_ON_EARLY |
501-
MSGDMA_CSR_CTL_GLOBAL_INTR, &mdev->csr->control);
488+
MSGDMA_CSR_CTL_GLOBAL_INTR, mdev->csr + MSGDMA_CSR_CONTROL);
502489

503490
mdev->idle = true;
504491
};
505492

506493
static void msgdma_copy_one(struct msgdma_device *mdev,
507494
struct msgdma_sw_desc *desc)
508495
{
509-
struct msgdma_extended_desc *hw_desc = mdev->desc;
496+
void __iomem *hw_desc = mdev->desc;
510497

511498
/*
512499
* Check if the DESC FIFO it not full. If its full, we need to wait
513500
* for at least one entry to become free again
514501
*/
515-
while (ioread32(&mdev->csr->status) & MSGDMA_CSR_STAT_DESC_BUF_FULL)
502+
while (ioread32(mdev->csr + MSGDMA_CSR_STATUS) &
503+
MSGDMA_CSR_STAT_DESC_BUF_FULL)
516504
mdelay(1);
517505

518506
/*
@@ -524,12 +512,14 @@ static void msgdma_copy_one(struct msgdma_device *mdev,
524512
* sure this control word is written last by single coding it and
525513
* adding some write-barriers here.
526514
*/
527-
memcpy(hw_desc, &desc->hw_desc, sizeof(desc->hw_desc) - sizeof(u32));
515+
memcpy((void __force *)hw_desc, &desc->hw_desc,
516+
sizeof(desc->hw_desc) - sizeof(u32));
528517

529518
/* Write control word last to flush this descriptor into the FIFO */
530519
mdev->idle = false;
531520
wmb();
532-
iowrite32(desc->hw_desc.control, &hw_desc->control);
521+
iowrite32(desc->hw_desc.control, hw_desc +
522+
offsetof(struct msgdma_extended_desc, control));
533523
wmb();
534524
}
535525

@@ -690,13 +680,13 @@ static void msgdma_tasklet(unsigned long data)
690680
{
691681
struct msgdma_device *mdev = (struct msgdma_device *)data;
692682
u32 count;
693-
u32 size;
694-
u32 status;
683+
u32 __maybe_unused size;
684+
u32 __maybe_unused status;
695685

696686
spin_lock(&mdev->lock);
697687

698688
/* Read number of responses that are available */
699-
count = ioread32(&mdev->csr->resp_fill_level);
689+
count = ioread32(mdev->csr + MSGDMA_CSR_RESP_FILL_LEVEL);
700690
dev_dbg(mdev->dev, "%s (%d): response count=%d\n",
701691
__func__, __LINE__, count);
702692

@@ -707,8 +697,8 @@ static void msgdma_tasklet(unsigned long data)
707697
* have any real values, like transferred bytes or error
708698
* bits. So we need to just drop these values.
709699
*/
710-
size = ioread32(&mdev->resp->bytes_transferred);
711-
status = ioread32(&mdev->resp->status);
700+
size = ioread32(mdev->resp + MSGDMA_RESP_BYTES_TRANSFERRED);
701+
status = ioread32(mdev->resp - MSGDMA_RESP_STATUS);
712702

713703
msgdma_complete_descriptor(mdev);
714704
msgdma_chan_desc_cleanup(mdev);
@@ -729,7 +719,7 @@ static irqreturn_t msgdma_irq_handler(int irq, void *data)
729719
struct msgdma_device *mdev = data;
730720
u32 status;
731721

732-
status = ioread32(&mdev->csr->status);
722+
status = ioread32(mdev->csr + MSGDMA_CSR_STATUS);
733723
if ((status & MSGDMA_CSR_STAT_BUSY) == 0) {
734724
/* Start next transfer if the DMA controller is idle */
735725
spin_lock(&mdev->lock);
@@ -741,7 +731,7 @@ static irqreturn_t msgdma_irq_handler(int irq, void *data)
741731
tasklet_schedule(&mdev->irq_tasklet);
742732

743733
/* Clear interrupt in mSGDMA controller */
744-
iowrite32(MSGDMA_CSR_STAT_IRQ, &mdev->csr->status);
734+
iowrite32(MSGDMA_CSR_STAT_IRQ, mdev->csr + MSGDMA_CSR_STATUS);
745735

746736
return IRQ_HANDLED;
747737
}
@@ -809,17 +799,17 @@ static int msgdma_probe(struct platform_device *pdev)
809799
mdev->dev = &pdev->dev;
810800

811801
/* Map CSR space */
812-
ret = request_and_map(pdev, "csr", &dma_res, (void **)&mdev->csr);
802+
ret = request_and_map(pdev, "csr", &dma_res, &mdev->csr);
813803
if (ret)
814804
return ret;
815805

816806
/* Map (extended) descriptor space */
817-
ret = request_and_map(pdev, "desc", &dma_res, (void **)&mdev->desc);
807+
ret = request_and_map(pdev, "desc", &dma_res, &mdev->desc);
818808
if (ret)
819809
return ret;
820810

821811
/* Map response space */
822-
ret = request_and_map(pdev, "resp", &dma_res, (void **)&mdev->resp);
812+
ret = request_and_map(pdev, "resp", &dma_res, &mdev->resp);
823813
if (ret)
824814
return ret;
825815

0 commit comments

Comments
 (0)