All of lore.kernel.org
 help / color / mirror / Atom feed
From: linux@arm.linux.org.uk (Russell King - ARM Linux)
To: linux-arm-kernel@lists.infradead.org
Subject: RPmsg, DMA and ARM64
Date: Thu, 26 Mar 2015 16:15:05 +0000	[thread overview]
Message-ID: <20150326161505.GR8656@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <20150326160136.GC30197@toto>

On Fri, Mar 27, 2015 at 02:01:36AM +1000, Edgar E. Iglesias wrote:
> On Thu, Mar 26, 2015 at 03:26:07PM +0000, Russell King - ARM Linux wrote:
> > The only way to pass such memory using scatterlists is by doing:
> > 
> > 	sg_init_table(sg, 1);
> > 	sg_dma_address(sg) = addr;
> > 	sg_dma_length(sg) = length;
> > 
> > Such a scatterlist must _never_ have the dma_(map|unmap|sync)_sg*()
> > functions called on it - the only operations which would be permissible
> > is to walk the scatterlist, and access it using the standard DMA
> > accessors sg_dma_address() and sg_dma_length().
> 
> I'll have a closer look and see if I can change rpmsg to deal with
> this.

Thanks - I should point out too that when accessing the scatterlist for
DMA purposes, using the accessors I mentioned above is a must - especially
as we're now getting IOMMUs on ARM.

This is because of a subtlety of the DMA streaming API.

The reason is that sg_dma_length(sg) may not be equal to sg->length -
IOMMUs (as part of dma_map_sg()) are permitted to coalesce entries
together by using their remapping abilities, which can result in fewer
scatterlist entries being needed.

It's also important to realise that dma_map_sg() returns the number of
scatterlist entries to be walked for DMA purposes, rather than the nents
passed into dma_map_sg() should _not_ be used.  It's the same reason -
if coalescing has occurred, the return value will be smaller, telling
you how many scatterlist entries are to be walked.

Finally, it's important to realise that when such coalescing occurs,
the values you have in sg_dma_address() and sg_dma_length() may _not_
correspond with the struct page in the entry.  In other words, you
can't expect to be able to switch between DMA and PIO and use the
same scatterlist entry, and expect to hit the same memory.

I suspect a lot of ARM driver authors are not aware of these finer
points.

-- 
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.

      reply	other threads:[~2015-03-26 16:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-24  4:37 RPmsg, DMA and ARM64 Edgar E. Iglesias
2015-03-25 15:36 ` Catalin Marinas
2015-03-26  1:30   ` Edgar E. Iglesias
2015-03-26 15:26 ` Russell King - ARM Linux
2015-03-26 16:01   ` Edgar E. Iglesias
2015-03-26 16:15     ` 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=20150326161505.GR8656@n2100.arm.linux.org.uk \
    --to=linux@arm.linux.org.uk \
    --cc=linux-arm-kernel@lists.infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.