From: Chris Leech <cleech@redhat.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Christoph Hellwig <hch@lst.de>, Rasesh Mody <rmody@marvell.com>,
Ariel Elior <aelior@marvell.com>,
Sudarsana Kalluru <skalluru@marvell.com>,
Manish Chopra <manishc@marvell.com>
Cc: Nilesh Javali <njavali@marvell.com>,
Manish Rangankar <mrangankar@marvell.com>,
Jerry Snitselaar <jsnitsel@redhat.com>,
John Meneghini <jmeneghi@redhat.com>,
Lee Duncan <lduncan@suse.com>,
Mike Christie <michael.christie@oracle.com>,
Hannes Reinecke <hare@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] uio: introduce UIO_DMA_COHERENT type
Date: Fri, 29 Sep 2023 10:00:21 -0700 [thread overview]
Message-ID: <20230929170023.1020032-2-cleech@redhat.com> (raw)
In-Reply-To: <20230929170023.1020032-1-cleech@redhat.com>
Add a UIO memtype specificially for sharing dma_alloc_coherent
memory with userspace, backed by dma_mmap_coherent.
Signed-off-by: Chris Leech <cleech@redhat.com>
---
drivers/uio/uio.c | 34 ++++++++++++++++++++++++++++++++++
include/linux/uio_driver.h | 12 ++++++++++--
2 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 62082d64ece0..f8f1f7ba6378 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -24,6 +24,7 @@
#include <linux/kobject.h>
#include <linux/cdev.h>
#include <linux/uio_driver.h>
+#include <linux/dma-mapping.h>
#define UIO_MAX_DEVICES (1U << MINORBITS)
@@ -759,6 +760,36 @@ static int uio_mmap_physical(struct vm_area_struct *vma)
vma->vm_page_prot);
}
+static int uio_mmap_dma_coherent(struct vm_area_struct *vma)
+{
+ struct uio_device *idev = vma->vm_private_data;
+ int mi = uio_find_mem_index(vma);
+ struct uio_mem *mem;
+ int rc;
+
+ if (mi < 0)
+ return -EINVAL;
+ mem = idev->info->mem + mi;
+
+ if (mem->dma_addr & ~PAGE_MASK)
+ return -ENODEV;
+ if (vma->vm_end - vma->vm_start > mem->size)
+ return -EINVAL;
+
+ /*
+ * UIO uses offset to index into the maps for a device.
+ * We need to clear vm_pgoff for dma_mmap_coherent.
+ */
+ vma->vm_pgoff = 0;
+ rc = dma_mmap_coherent(mem->dma_device,
+ vma,
+ mem->virtual_addr,
+ mem->dma_addr,
+ vma->vm_end - vma->vm_start);
+ vma->vm_pgoff = mi;
+ return rc;
+}
+
static int uio_mmap(struct file *filep, struct vm_area_struct *vma)
{
struct uio_listener *listener = filep->private_data;
@@ -806,6 +837,9 @@ static int uio_mmap(struct file *filep, struct vm_area_struct *vma)
case UIO_MEM_VIRTUAL:
ret = uio_mmap_logical(vma);
break;
+ case UIO_MEM_DMA_COHERENT:
+ ret = uio_mmap_dma_coherent(vma);
+ break;
default:
ret = -EINVAL;
}
diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
index 47c5962b876b..ede58e984658 100644
--- a/include/linux/uio_driver.h
+++ b/include/linux/uio_driver.h
@@ -36,11 +36,18 @@ struct uio_map;
*/
struct uio_mem {
const char *name;
- phys_addr_t addr;
+ union {
+ phys_addr_t addr;
+ dma_addr_t dma_addr;
+ };
unsigned long offs;
resource_size_t size;
int memtype;
- void __iomem *internal_addr;
+ union {
+ void __iomem *internal_addr;
+ void *virtual_addr;
+ };
+ struct device *dma_device;
struct uio_map *map;
};
@@ -158,6 +165,7 @@ extern int __must_check
#define UIO_MEM_LOGICAL 2
#define UIO_MEM_VIRTUAL 3
#define UIO_MEM_IOVA 4
+#define UIO_MEM_DMA_COHERENT 5
/* defines for uio_port->porttype */
#define UIO_PORT_NONE 0
--
2.41.0
next prev parent reply other threads:[~2023-09-29 17:00 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-29 17:00 [PATCH 0/3] UIO_MEM_DMA_COHERENT for cnic/bnx2/bnx2x Chris Leech
2023-09-29 17:00 ` Chris Leech [this message]
2023-09-30 7:10 ` [PATCH 1/3] uio: introduce UIO_DMA_COHERENT type Greg Kroah-Hartman
2023-09-30 18:08 ` Chris Leech
2023-10-02 6:09 ` Christoph Hellwig
2023-09-29 17:00 ` [PATCH 2/3] cnic,bnx2,bnx2x: page align uio mmap allocations Chris Leech
2023-09-29 17:18 ` Jacob Keller
2023-10-02 6:11 ` Christoph Hellwig
2023-09-29 17:00 ` [PATCH 3/3] cnic,bnx2,bnx2x: use UIO_MEM_DMA_COHERENT Chris Leech
2023-09-29 17:19 ` Jacob Keller
2023-09-30 7:06 ` Greg Kroah-Hartman
2023-09-30 9:10 ` Jerry Snitselaar
2023-09-30 18:29 ` Greg Kroah-Hartman
2023-09-30 18:19 ` Chris Leech
2023-09-30 18:28 ` Greg Kroah-Hartman
2023-10-01 10:44 ` Hannes Reinecke
2023-10-01 11:57 ` Greg Kroah-Hartman
2023-10-01 14:22 ` Jerry Snitselaar
2023-10-02 6:04 ` Christoph Hellwig
2023-10-02 7:50 ` Jerry Snitselaar
2023-10-02 8:46 ` Greg Kroah-Hartman
2023-10-02 8:59 ` Hannes Reinecke
2023-10-05 10:39 ` Paolo Abeni
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=20230929170023.1020032-2-cleech@redhat.com \
--to=cleech@redhat.com \
--cc=aelior@marvell.com \
--cc=gregkh@linuxfoundation.org \
--cc=hare@kernel.org \
--cc=hch@lst.de \
--cc=jmeneghi@redhat.com \
--cc=jsnitsel@redhat.com \
--cc=lduncan@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=manishc@marvell.com \
--cc=michael.christie@oracle.com \
--cc=mrangankar@marvell.com \
--cc=netdev@vger.kernel.org \
--cc=njavali@marvell.com \
--cc=rmody@marvell.com \
--cc=skalluru@marvell.com \
/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).