All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Varney <bvarney@gmail.com>
To: dmaengine@vger.kernel.org
Subject: dma_alloc_coherent / dma_map_single question
Date: Mon, 26 Jul 2021 14:17:19 -0600	[thread overview]
Message-ID: <CA+WACTdfQfDXm6H7MrkJda2t51Fn-z8sM6-RDd0Kc92cW8OjQA@mail.gmail.com> (raw)

Hello,

I have the following situation:
1. I'm using dma_alloc_coherent to allocate memory for DeviceA
2. I use DeviceA to fill the memory buffer.

Everything is fine so far but at this point I would like to DMA the
memory to DeviceB and I'm not sure the proper way of doing it.

Is it allowed/ok/proper to call dma_map_single for DeviceB using the
address returned from dma_alloc_coherent called on DeviceA?  This
seems to work fine in x86_64 but it feels like I'm breaking the rules
because:
 1. dma_map_single is supposed to be called with kmalloc addresses.
 2. Since the address is from both dma_alloc_coherent and
dma_map_single, I don't know if the dma_sync_* functions are necessary
or not.

I'm worried that I'm just getting lucky having this work and a future
kernel update will break me since I'm not really following the rules.
My code may eventually have to run on ARM too, and I'm not sure it
would work.

I have also considered:
1. Call dma_alloc_coherent for DeviceB and memcpy the data from
DeviceA into it.  This would work but I don't want the performance hit
of double buffering.
2. Get rid of the the dma_alloc_coherent for deviceA use
kmalloc/dma_map_single instead.   This would work and maybe is the
right thing to do.  This requires the extra hassle of dma_sync_*
functions which I was trying to avoid.

Is there a better way of doing this that I'm missing?

Thanks,
Brian V.

                 reply	other threads:[~2021-07-26 20:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=CA+WACTdfQfDXm6H7MrkJda2t51Fn-z8sM6-RDd0Kc92cW8OjQA@mail.gmail.com \
    --to=bvarney@gmail.com \
    --cc=dmaengine@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 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.