From patchwork Tue Jan 8 10:24:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damian Hobson-Garcia X-Patchwork-Id: 1945011 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 54289DF23A for ; Tue, 8 Jan 2013 10:24:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755343Ab3AHKYX (ORCPT ); Tue, 8 Jan 2013 05:24:23 -0500 Received: from mail-da0-f50.google.com ([209.85.210.50]:48132 "EHLO mail-da0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755088Ab3AHKYV (ORCPT ); Tue, 8 Jan 2013 05:24:21 -0500 Received: by mail-da0-f50.google.com with SMTP id h15so129767dan.9 for ; Tue, 08 Jan 2013 02:24:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=t3W0MKiZMLoAEaivjHRxuZwsUKwC9e2j35ub/mQr2vQ=; b=LbDRh03mg8ctWkAlX10mErbdHVWbWYdyTdVwhQNKLJEDVSYW8/dYnQ+50KLzM/wyP2 IfRo99TaubjHZlsGPnB+vjh8KXMKdhB5rengYRYZf2HipbdtvZB49IrSCQOxZ6dZH6ZZ IZfEhb/tOLCObEM93Yuot3B3eXo7uqzSx21u52ebxr9rXWOWRXOk/mZU/Ay+EbgrsCVH RpaXTmTE/2v7dUfqMkA247zl1+HYX/RDSkFYsjpn3B6ezXJ4HK27HtJG1II9LV8zbxYV 9r9pmbq/CsSUf0dpdZDCY19UNYiQxgg6d0w5oP3Onw7+R1SMdIefYhrrQn6iLwOxap4v cjFw== X-Received: by 10.68.197.135 with SMTP id iu7mr196547553pbc.71.1357640661041; Tue, 08 Jan 2013 02:24:21 -0800 (PST) Received: from localhost.localdomain ([219.106.231.132]) by mx.google.com with ESMTPS id ol4sm39394745pbb.58.2013.01.08.02.24.18 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 08 Jan 2013 02:24:19 -0800 (PST) From: Damian Hobson-Garcia 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 Subject: [PATCH] drivers: uio_dmem_genirq: Add mmap support for dynamic regions Date: Tue, 8 Jan 2013 19:24:03 +0900 Message-Id: <1357640643-17713-1-git-send-email-dhobsong@igel.co.jp> X-Mailer: git-send-email 1.7.5.4 X-Gm-Message-State: ALoCoQn72HOS6s7HTS8ifF6UwqjfNLqGwz4jEhM4wTZ/ZxD5DNBRsqKmATUwhO4WOSPI6r2szz9X Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org 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 --- 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: