All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Li Chen <me@linux.beauty>
Cc: Arnd Bergmann <arnd@arndb.de>,
	linux-arm-kernel <linux-arm-kernel@lists.infradead.org>
Subject: Re: Why dma_alloc_coherent don't return direct mapped vaddr?
Date: Fri, 22 Jul 2022 08:50:17 +0200	[thread overview]
Message-ID: <CAK8P3a2Nzky44cj4GN910c0DK=gAhR5keFSOsmwHaBkELPCStQ@mail.gmail.com> (raw)
In-Reply-To: <18223d6f513.b214956e3076389.5726369280729584331@linux.beauty>

On Fri, Jul 22, 2022 at 4:57 AM Li Chen <me@linux.beauty> wrote:
>  ---- On Thu, 21 Jul 2022 15:06:57 +0800  Arnd Bergmann <arnd@arndb.de> wrote ---
>  > in between.
>
> Thanks for your answer! My device is a misc character device, just like
> https://lwn.net/ml/linux-kernel/20220711122459.13773-5-me@linux.beauty/
> IIUC, its dma_addr is always the same with phy addr. If I want to alloc from
> reserved memory and then mmap to userspace with vm_insert_pages, are
> cma_alloc/dma_alloc_contigous/dma_alloc_from_contigous better choices?

In the driver, you should only ever use dma_alloc_coherent() for getting
a coherent DMA buffer, the other functions are just the implementation
details behind that.

To map this buffer to user space, your mmap() function should call
dma_mmap_coherent(), which in turn does the correct translation
from device specific dma_addr_t values into pages and uses the
correct caching attributes.

       Arnd

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2022-07-22  6:52 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-21  3:28 Why dma_alloc_coherent don't return direct mapped vaddr? Li Chen
2022-07-21  7:06 ` Arnd Bergmann
2022-07-22  2:57   ` Li Chen
2022-07-22  6:50     ` Arnd Bergmann [this message]
2022-07-22  8:19       ` Li Chen
2022-07-22  9:06         ` Arnd Bergmann
2022-07-22 10:31           ` Li Chen
2022-07-22 11:06             ` Arnd Bergmann
2022-07-25  2:50               ` Li Chen
2022-07-25  7:03                 ` Arnd Bergmann
2022-07-25 11:06                   ` Li Chen
2022-07-25 11:45                     ` Arnd Bergmann
2022-07-26  6:50                       ` Li Chen
2022-07-27  3:02                         ` Li Chen
2022-07-27  6:40                           ` Arnd Bergmann

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='CAK8P3a2Nzky44cj4GN910c0DK=gAhR5keFSOsmwHaBkELPCStQ@mail.gmail.com' \
    --to=arnd@arndb.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=me@linux.beauty \
    /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.