From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: Linus Walleij <linus.walleij@stericsson.com>
Cc: Dan Williams <dan.j.williams@intel.com>,
linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 5/7] ARM: add PrimeCell generic DMA to PL011 v6
Date: Fri, 7 May 2010 10:23:57 +0100 [thread overview]
Message-ID: <20100507092357.GA19936@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <1272848113-29359-1-git-send-email-linus.walleij@stericsson.com>
On Mon, May 03, 2010 at 02:55:13AM +0200, Linus Walleij wrote:
> + /* Map DMA buffers */
> + sglen = dma_map_sg(uap->port.dev, &dmarx->scatter_a,
> + 1, DMA_FROM_DEVICE);
> + if (sglen != 1)
> + goto err_rx_sgmap_a;
> +
> + sglen = dma_map_sg(uap->port.dev, &dmarx->scatter_b,
> + 1, DMA_FROM_DEVICE);
> + if (sglen != 1)
> + goto err_rx_sgmap_b;
> +
> + sglen = dma_map_sg(uap->port.dev, &dmatx->scatter,
> + 1, DMA_TO_DEVICE);
> + if (sglen != 1)
> + goto err_tx_sgmap;
So as soon as we allocate these, we hand them over to DMA device ownership...
> + /* Else proceed to copy the TX chars to the DMA buffer and fire DMA */
> + count = uart_circ_chars_pending(xmit);
> + if (count > PL011_DMA_BUFFER_SIZE)
> + count = PL011_DMA_BUFFER_SIZE;
> +
> + if (xmit->tail < xmit->head)
> + memcpy(&dmatx->tx_dma_buf[0], &xmit->buf[xmit->tail], count);
> + else {
> + size_t first = UART_XMIT_SIZE - xmit->tail;
> + size_t second = xmit->head;
> +
> + memcpy(&dmatx->tx_dma_buf[0], &xmit->buf[xmit->tail], first);
> + memcpy(&dmatx->tx_dma_buf[first], &xmit->buf[0], second);
> + }
But here we write to the buffers without switching them to CPU ownership.
Only one device of {CPU, DMA} actively owns the DMA buffer at any one time,
and only the active owner is permited under DMA API rules to access that
buffer.
Consider the situation where you've written to the first half of a cache
line, but the DMA device has yet to read from the second half of that
cache line - the result is a corrupted transfer.
prev parent reply other threads:[~2010-05-07 9:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-03 0:55 [PATCH 5/7] ARM: add PrimeCell generic DMA to PL011 v6 Linus Walleij
2010-05-07 9:23 ` Russell King - ARM Linux [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100507092357.GA19936@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=dan.j.williams@intel.com \
--cc=linus.walleij@stericsson.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).