From: Roland Dreier <roland@topspin.com>
To: Bret Indrelee <Bret.Indrelee@qlogic.com>
Cc: Matt Porter <mporter@kernel.crashing.org>,
Linux PPC Embedded mailing list
<linuxppc-embedded@lists.linuxppc.org>
Subject: Re: Any restrictions on DMA address boundry?
Date: 25 Sep 2003 11:26:12 -0700 [thread overview]
Message-ID: <52k77wk9mj.fsf@topspin.com> (raw)
In-Reply-To: <Pine.LNX.4.44.0309251306450.12966-100000@spider.ancor.com>
Bret> What exactly is the issue?
Bret> As I understand it, if there is a DMA to the same cache line
Bret> as something that the CPU is referencing, you've got a cache
Bret> problem.
The problem is the following. Suppose for concreteness that we're
working on a system with 32-byte cache lines, and there is no
coherency between PCI and the CPU cache. (This describes the IBM
PowerPC 440GP)
Now suppose you have a 16-byte DMA buffer, and some other unrelated
data in the same cache line. Let's say you want to start a DMA from
an external PCI device into that buffer. The first thing you do is
invalidate the cache line containing the DMA buffer, so that you get
the data the device is about to write and not any data that might
already be in the CPU cache.
You have to do this invalidate before you initiate the DMA, because
otherwise there is the risk of the CPU evicting that cache line and
writing it back to memory after the DMA has occurred, and stomping on
the data the device has written.
Then you tell the device to do the DMA, and go off and do other stuff
while waiting for the DMA to complete. If that other stuff touches
the other 16 bytes of unrelated data that shares the cache line with
the DMA buffer, the CPU will bring it back into the cache. But if you
do this before the DMA happens, you won't see the data the device
writes.
People often come up with complicated schemes like flushing and
invalidating the cache before and after the DMA transfer, but there's
always a scenario where the DMA buffer and/or the unrelated data get
corrupted. The only solution is to make sure that you don't put
unrelated data in the same cache line as a DMA buffer.
Bret> Does it matter what type of transfer the PCI device is
Bret> doing? If it always does 32-bit burst memory write transfers
Bret> instead of memory write & invalidate does that make a
Bret> difference?
No.
- Roland
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
next prev parent reply other threads:[~2003-09-25 18:26 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-22 15:13 Any restrictions on DMA address boundry? Bret Indrelee
2003-09-22 16:59 ` Matt Porter
2003-09-25 17:56 ` Roland Dreier
2003-09-25 18:15 ` Bret Indrelee
2003-09-25 18:26 ` Roland Dreier [this message]
2003-09-25 20:54 ` Eugene Surovegin
2003-09-25 19:56 ` Matt Porter
2003-09-25 20:20 ` Bret Indrelee
2003-09-25 20:55 ` Matt Porter
2003-09-25 21:27 ` Bret Indrelee
2003-09-25 20:25 ` Eugene Surovegin
2003-09-25 20:32 ` Bret Indrelee
2003-09-25 20:57 ` Matt Porter
2003-09-25 20:41 ` Matt Porter
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=52k77wk9mj.fsf@topspin.com \
--to=roland@topspin.com \
--cc=Bret.Indrelee@qlogic.com \
--cc=linuxppc-embedded@lists.linuxppc.org \
--cc=mporter@kernel.crashing.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).