mmc: at91_mci: use DMA buffer for read
Convert the read to use the DMA buffer as well. The old code was doing double-buffering DMA with the PDC; no way to make it work. Replace it with a single-PDC approach. It also simplify things removing the need for a pre_dma_read() function. [nicolas.ferre@atmel.com coding style modifications] Signed-off-by: Wolfgang Muees <wolfgang.mues@auerswald.de> Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com> Cc: Andrew Victor <avictor.za@gmail.com> Cc: <linux-mmc@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
committed by
Linus Torvalds
parent
3780d90602
commit
86ee26f5b0
@@ -250,74 +250,6 @@ static inline void at91_mci_sg_to_dma(struct at91mci_host *host, struct mmc_data
|
|||||||
BUG_ON(size != 0);
|
BUG_ON(size != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Prepare a dma read
|
|
||||||
*/
|
|
||||||
static void at91_mci_pre_dma_read(struct at91mci_host *host)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
struct scatterlist *sg;
|
|
||||||
struct mmc_command *cmd;
|
|
||||||
struct mmc_data *data;
|
|
||||||
|
|
||||||
pr_debug("pre dma read\n");
|
|
||||||
|
|
||||||
cmd = host->cmd;
|
|
||||||
if (!cmd) {
|
|
||||||
pr_debug("no command\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
data = cmd->data;
|
|
||||||
if (!data) {
|
|
||||||
pr_debug("no data\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < 2; i++) {
|
|
||||||
/* nothing left to transfer */
|
|
||||||
if (host->transfer_index >= data->sg_len) {
|
|
||||||
pr_debug("Nothing left to transfer (index = %d)\n", host->transfer_index);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check to see if this needs filling */
|
|
||||||
if (i == 0) {
|
|
||||||
if (at91_mci_read(host, ATMEL_PDC_RCR) != 0) {
|
|
||||||
pr_debug("Transfer active in current\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (at91_mci_read(host, ATMEL_PDC_RNCR) != 0) {
|
|
||||||
pr_debug("Transfer active in next\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Setup the next transfer */
|
|
||||||
pr_debug("Using transfer index %d\n", host->transfer_index);
|
|
||||||
|
|
||||||
sg = &data->sg[host->transfer_index++];
|
|
||||||
pr_debug("sg = %p\n", sg);
|
|
||||||
|
|
||||||
sg->dma_address = dma_map_page(NULL, sg_page(sg), sg->offset, sg->length, DMA_FROM_DEVICE);
|
|
||||||
|
|
||||||
pr_debug("dma address = %08X, length = %d\n", sg->dma_address, sg->length);
|
|
||||||
|
|
||||||
if (i == 0) {
|
|
||||||
at91_mci_write(host, ATMEL_PDC_RPR, sg->dma_address);
|
|
||||||
at91_mci_write(host, ATMEL_PDC_RCR, (data->blksz & 0x3) ? sg->length : sg->length / 4);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
at91_mci_write(host, ATMEL_PDC_RNPR, sg->dma_address);
|
|
||||||
at91_mci_write(host, ATMEL_PDC_RNCR, (data->blksz & 0x3) ? sg->length : sg->length / 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pr_debug("pre dma read done\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handle after a dma read
|
* Handle after a dma read
|
||||||
*/
|
*/
|
||||||
@@ -325,6 +257,8 @@ static void at91_mci_post_dma_read(struct at91mci_host *host)
|
|||||||
{
|
{
|
||||||
struct mmc_command *cmd;
|
struct mmc_command *cmd;
|
||||||
struct mmc_data *data;
|
struct mmc_data *data;
|
||||||
|
unsigned int len, i, size;
|
||||||
|
unsigned *dmabuf = host->buffer;
|
||||||
|
|
||||||
pr_debug("post dma read\n");
|
pr_debug("post dma read\n");
|
||||||
|
|
||||||
@@ -340,42 +274,39 @@ static void at91_mci_post_dma_read(struct at91mci_host *host)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (host->in_use_index < host->transfer_index) {
|
size = data->blksz * data->blocks;
|
||||||
|
len = data->sg_len;
|
||||||
|
|
||||||
|
at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_ENDRX);
|
||||||
|
at91_mci_write(host, AT91_MCI_IER, AT91_MCI_RXBUFF);
|
||||||
|
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
struct scatterlist *sg;
|
struct scatterlist *sg;
|
||||||
|
int amount;
|
||||||
|
unsigned int *sgbuffer;
|
||||||
|
|
||||||
pr_debug("finishing index %d\n", host->in_use_index);
|
sg = &data->sg[i];
|
||||||
|
|
||||||
sg = &data->sg[host->in_use_index++];
|
sgbuffer = kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
|
||||||
|
amount = min(size, sg->length);
|
||||||
pr_debug("Unmapping page %08X\n", sg->dma_address);
|
size -= amount;
|
||||||
|
|
||||||
dma_unmap_page(NULL, sg->dma_address, sg->length, DMA_FROM_DEVICE);
|
|
||||||
|
|
||||||
if (cpu_is_at91rm9200()) { /* AT91RM9200 errata */
|
if (cpu_is_at91rm9200()) { /* AT91RM9200 errata */
|
||||||
unsigned int *buffer;
|
|
||||||
int index;
|
int index;
|
||||||
|
for (index = 0; index < (amount / 4); index++)
|
||||||
/* Swap the contents of the buffer */
|
sgbuffer[index] = swab32(*dmabuf++);
|
||||||
buffer = kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
|
} else {
|
||||||
pr_debug("buffer = %p, length = %d\n", buffer, sg->length);
|
char *tmpv = (char *)dmabuf;
|
||||||
|
memcpy(sgbuffer, tmpv, amount);
|
||||||
for (index = 0; index < (sg->length / 4); index++)
|
tmpv += amount;
|
||||||
buffer[index] = swab32(buffer[index]);
|
dmabuf = (unsigned *)tmpv;
|
||||||
|
|
||||||
kunmap_atomic(buffer, KM_BIO_SRC_IRQ);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
flush_dcache_page(sg_page(sg));
|
kunmap_atomic(((void *)sgbuffer)-sg->offset, KM_BIO_SRC_IRQ);
|
||||||
|
dmac_flush_range((void *)sgbuffer, ((void *)sgbuffer) + amount);
|
||||||
data->bytes_xfered += sg->length;
|
data->bytes_xfered += amount;
|
||||||
}
|
if (size == 0)
|
||||||
|
break;
|
||||||
/* Is there another transfer to trigger? */
|
|
||||||
if (host->transfer_index < data->sg_len)
|
|
||||||
at91_mci_pre_dma_read(host);
|
|
||||||
else {
|
|
||||||
at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_ENDRX);
|
|
||||||
at91_mci_write(host, AT91_MCI_IER, AT91_MCI_RXBUFF);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pr_debug("post dma read done\n");
|
pr_debug("post dma read done\n");
|
||||||
@@ -610,7 +541,12 @@ static void at91_mci_send_command(struct at91mci_host *host, struct mmc_command
|
|||||||
*/
|
*/
|
||||||
host->total_length = 0;
|
host->total_length = 0;
|
||||||
|
|
||||||
at91_mci_pre_dma_read(host);
|
at91_mci_write(host, ATMEL_PDC_RPR, host->physical_address);
|
||||||
|
at91_mci_write(host, ATMEL_PDC_RCR, (data->blksz & 0x3) ?
|
||||||
|
(blocks * block_length) : (blocks * block_length) / 4);
|
||||||
|
at91_mci_write(host, ATMEL_PDC_RNPR, 0);
|
||||||
|
at91_mci_write(host, ATMEL_PDC_RNCR, 0);
|
||||||
|
|
||||||
ier = AT91_MCI_ENDRX /* | AT91_MCI_RXBUFF */;
|
ier = AT91_MCI_ENDRX /* | AT91_MCI_RXBUFF */;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Reference in New Issue
Block a user