linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Damian Hobson-Garcia <dhobsong@igel.co.jp>
To: hjk@hansjkoch.de, gregkh@linuxfoundation.org, horms@verge.net.au
Cc: linux-kernel@vger.kernel.org, linux-sh@vger.kernel.org,
	Damian Hobson-Garcia <dhobsong@igel.co.jp>
Subject: [PATCH] drivers: uio_dmem_genirq: Add mmap support for dynamic regions
Date: Tue, 08 Jan 2013 10:24:03 +0000	[thread overview]
Message-ID: <1357640643-17713-1-git-send-email-dhobsong@igel.co.jp> (raw)

Dynamic regions allocated with dma_alloc_coherent() should use
dma_mmap_coherent() to perform memory mapping. Other regions
are simply ioremapped, the same way as in the uio subsystem base
implementation.

Signed-off-by: Damian Hobson-Garcia <dhobsong@igel.co.jp>
---
 drivers/uio/uio_dmem_genirq.c |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/drivers/uio/uio_dmem_genirq.c b/drivers/uio/uio_dmem_genirq.c
index 252434c..7a047ad 100644
--- a/drivers/uio/uio_dmem_genirq.c
+++ b/drivers/uio/uio_dmem_genirq.c
@@ -144,6 +144,38 @@ static int uio_dmem_genirq_irqcontrol(struct uio_info *dev_info, s32 irq_on)
 	return 0;
 }
 
+static int uio_dmem_genirq_mmap(struct uio_info *info,
+				struct vm_area_struct *vma) {
+	struct uio_dmem_genirq_platdata *priv = info->priv;
+	struct uio_mem *uiomem;
+	int dmem_region = priv->dmem_region_start;
+	int mi = vma->vm_pgoff;
+
+	if (priv->uioinfo->mem[mi].memtype != UIO_MEM_PHYS)
+		return -EINVAL;
+
+	if (mi < MAX_UIO_MAPS) {
+		uiomem = &priv->uioinfo->mem[mi];
+		if (!uiomem->size)
+			return -EINVAL;
+
+		if (mi < dmem_region) {	/* phyiscal address */
+			vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+			return remap_pfn_range(vma,
+				       vma->vm_start,
+				       uiomem->addr >> PAGE_SHIFT,
+				       vma->vm_end - vma->vm_start,
+				       vma->vm_page_prot);
+		} else {		/* DMA address */
+			vma->vm_pgoff = 0;
+			return dma_mmap_coherent(&priv->pdev->dev, vma,
+				priv->dmem_region_vaddr[mi],
+				uiomem->addr, uiomem->size);
+		}
+	}
+	return -EINVAL;
+}
+
 static int uio_dmem_genirq_probe(struct platform_device *pdev)
 {
 	struct uio_dmem_genirq_pdata *pdata = pdev->dev.platform_data;
@@ -263,6 +295,7 @@ static int uio_dmem_genirq_probe(struct platform_device *pdev)
 	uioinfo->irqcontrol = uio_dmem_genirq_irqcontrol;
 	uioinfo->open = uio_dmem_genirq_open;
 	uioinfo->release = uio_dmem_genirq_release;
+	uioinfo->mmap = uio_dmem_genirq_mmap;
 	uioinfo->priv = priv;
 
 	/* Enable Runtime PM for this device:
-- 
1.7.5.4


                 reply	other threads:[~2013-01-08 10:24 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=1357640643-17713-1-git-send-email-dhobsong@igel.co.jp \
    --to=dhobsong@igel.co.jp \
    --cc=gregkh@linuxfoundation.org \
    --cc=hjk@hansjkoch.de \
    --cc=horms@verge.net.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sh@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;
as well as URLs for NNTP newsgroup(s).