From: Stanislav Meduna <stano@meduna.org>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: hjk@hansjkoch.de, gregkh@linuxfoundation.org
Subject: UIO and memory from dma_alloc_coherent - UIO_MEM_PHYS?
Date: Mon, 17 Feb 2014 19:06:37 +0100 [thread overview]
Message-ID: <53024FAD.2000709@meduna.org> (raw)
Hi,
what is the correct way for a UIO driver to pass a memory allocated
using dma_alloc_coherent to userspace? I have googled for examples
but I was not able to find a definitive answer.
My device needs two 128 kB chunks of DMA-able memory. First I tried
pdev->tx_vaddr = dma_zalloc_coherent(&dev->dev, pdev->dma_len,
&pdev->tx_paddr, GFP_KERNEL | GFP_DMA);
info->mem[2].name = "txdma";
info->mem[2].addr = (phys_addr_t) pdev->tx_vaddr;
info->mem[2].size = pdev->dma_len;
info->mem[2].memtype = UIO_MEM_LOGICAL;
This seemed to work at the first try, but tends to panic in various
ways when unmapping. It probably only maps the first page or something
like that and accessing past some limit overwrites something.
If I change this to
info->mem[2].addr = (phys_addr_t) pdev->tx_paddr;
info->mem[2].memtype = UIO_MEM_PHYS;
it seems to work at least on x86 with < 4GB memory. The uio_pruss.c
(or uio_dmem_genirq.c in newer kernels) do this as well.
I have a bad feeling here - if I am allocating something that
is a virtual memory in the kernel, I don't expect to pretend I am
accessing something else. The UIO howto explicitely states
that UIO_MEM_PHYS is meant for a "physical memory on your card".
Is this really a recommended way of doing this and is it portable
to other architectures?
I am using 3.4 kernel with realtime patches.
Please Cc: me when replying.
Thanks
--
Stano
next reply other threads:[~2014-02-17 18:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-17 18:06 Stanislav Meduna [this message]
2014-02-17 18:18 ` UIO and memory from dma_alloc_coherent - UIO_MEM_PHYS? Greg KH
2014-02-17 18:32 ` Stanislav Meduna
2014-02-17 19:18 ` Greg KH
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=53024FAD.2000709@meduna.org \
--to=stano@meduna.org \
--cc=gregkh@linuxfoundation.org \
--cc=hjk@hansjkoch.de \
--cc=linux-kernel@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