From patchwork Tue Apr 8 12:08:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Dmytryshyn X-Patchwork-Id: 27936 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qg0-f71.google.com (mail-qg0-f71.google.com [209.85.192.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CC29E20553 for ; Tue, 8 Apr 2014 12:10:30 +0000 (UTC) Received: by mail-qg0-f71.google.com with SMTP id j5sf1675162qga.6 for ; Tue, 08 Apr 2014 05:10:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:cc:subject :precedence:list-id:list-unsubscribe:list-post:list-help :list-subscribe:mime-version:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive :content-type:content-transfer-encoding; bh=UZTgEeX1BO4ZSSdbsxX7YlOwxlnXgZ5flKid0l1X+bM=; b=cYCcAt7ncYOjhP7+kdI8c4RQCQfM5750noYJd8IU/qEbY4Dir9zLvFpNU1Vq1uvo4v rkvI80fO7kDkmLsyfAztl0WqBXwge2tLPrRcbkFQLUOQtogvWvYv+z/FLXuIWmpeAZx9 6xGnSjY0jJFNAr61i8Mnc7qXHyxgGS0vTuxxCdElwZyglZWvAox11QsIXbeahFJ6o74i 0obs6xudS3wcgPwkoSuYvGytNxBMT117eenoloOyB+mzXzLxd2036nbExFxhhGNE/ncr zDj9DDU7+PjA3yDku1WD3p9Oel3vf6UneqoivQwob+0JnZOB36AIEIHUrUBHoFAcjBRd QLvA== X-Gm-Message-State: ALoCoQn3c1VpJCAJK1Hmo0uAS2OMT4ioFhO/rIN9MXvzMN4iFCGhkhBFb/FgjsrLCzaUsbJ1p/t2 X-Received: by 10.236.93.38 with SMTP id k26mr1440798yhf.20.1396959030574; Tue, 08 Apr 2014 05:10:30 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.27.138 with SMTP id 10ls182362qgx.52.gmail; Tue, 08 Apr 2014 05:10:30 -0700 (PDT) X-Received: by 10.52.173.165 with SMTP id bl5mr2442055vdc.13.1396959030437; Tue, 08 Apr 2014 05:10:30 -0700 (PDT) Received: from mail-ve0-x22e.google.com (mail-ve0-x22e.google.com [2607:f8b0:400c:c01::22e]) by mx.google.com with ESMTPS id kp12si351961veb.120.2014.04.08.05.10.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 08 Apr 2014 05:10:30 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::22e is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c01::22e; Received: by mail-ve0-f174.google.com with SMTP id oz11so640881veb.19 for ; Tue, 08 Apr 2014 05:10:30 -0700 (PDT) X-Received: by 10.52.72.48 with SMTP id a16mr2444132vdv.19.1396959030328; Tue, 08 Apr 2014 05:10:30 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.12.8 with SMTP id v8csp240020vcv; Tue, 8 Apr 2014 05:10:30 -0700 (PDT) X-Received: by 10.58.77.238 with SMTP id v14mr271475vew.27.1396959029895; Tue, 08 Apr 2014 05:10:29 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id jb7si350265vec.143.2014.04.08.05.10.29 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 08 Apr 2014 05:10:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xen.org designates 50.57.142.19 as permitted sender) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WXUpD-00056I-1C; Tue, 08 Apr 2014 12:08:23 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WXUpB-00056D-3v for xen-devel@lists.xenproject.org; Tue, 08 Apr 2014 12:08:21 +0000 Received: from [85.158.143.35:28734] by server-2.bemta-4.messagelabs.com id 73/07-06539-4B6E3435; Tue, 08 Apr 2014 12:08:20 +0000 X-Env-Sender: oleksandr.dmytryshyn@globallogic.com X-Msg-Ref: server-16.tower-21.messagelabs.com!1396958897!7662661!1 X-Originating-IP: [64.18.0.149] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9560 invoked from network); 8 Apr 2014 12:08:19 -0000 Received: from exprod5og117.obsmtp.com (HELO exprod5og117.obsmtp.com) (64.18.0.149) by server-16.tower-21.messagelabs.com with DHE-RSA-AES256-SHA encrypted SMTP; 8 Apr 2014 12:08:19 -0000 Received: from mail-lb0-f170.google.com ([209.85.217.170]) (using TLSv1) by exprod5ob117.postini.com ([64.18.4.12]) with SMTP ID DSNKU0PmsVfxwBF3jpN1REsX9N6qVxQpEY4R@postini.com; Tue, 08 Apr 2014 05:08:19 PDT Received: by mail-lb0-f170.google.com with SMTP id s7so785075lbd.15 for ; Tue, 08 Apr 2014 05:08:15 -0700 (PDT) X-Received: by 10.112.150.162 with SMTP id uj2mr1212749lbb.52.1396958895750; Tue, 08 Apr 2014 05:08:15 -0700 (PDT) X-Received: by 10.112.150.162 with SMTP id uj2mr1212733lbb.52.1396958895544; Tue, 08 Apr 2014 05:08:15 -0700 (PDT) Received: from localhost ([195.238.92.241]) by mx.google.com with ESMTPSA id zf7sm1830995lab.7.2014.04.08.05.08.13 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 08 Apr 2014 05:08:14 -0700 (PDT) From: Oleksandr Dmytryshyn To: Stefano Stabellini Date: Tue, 8 Apr 2014 15:08:12 +0300 Message-Id: <1396958892-32449-1-git-send-email-oleksandr.dmytryshyn@globallogic.com> X-Mailer: git-send-email 1.8.2.rc2 Cc: xen-devel@lists.xenproject.org Subject: [Xen-devel] [PATCH v1] swiotlb-xen: implement xen_swiotlb_dma_mmap callback X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Original-Sender: oleksandr.dmytryshyn@globallogic.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::22e is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@globallogic.com; dmarc=fail (p=NONE dis=NONE) header.from=globallogic.com Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: From: Stefano Stabellini This function creates userspace mapping for the DMA-coherent memory. Signed-off-by: Stefano Stabellini Signed-off-by: Oleksandr Dmytryshyn --- arch/arm/xen/mm.c | 1 + drivers/xen/swiotlb-xen.c | 36 ++++++++++++++++++++++++++++++++++++ include/xen/swiotlb-xen.h | 5 +++++ 3 files changed, 42 insertions(+) diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c index b0e77de..91408b1 100644 --- a/arch/arm/xen/mm.c +++ b/arch/arm/xen/mm.c @@ -48,6 +48,7 @@ static struct dma_map_ops xen_swiotlb_dma_ops = { .sync_sg_for_device = xen_swiotlb_sync_sg_for_device, .map_sg = xen_swiotlb_map_sg_attrs, .unmap_sg = xen_swiotlb_unmap_sg_attrs, + .mmap = xen_swiotlb_dma_mmap, .map_page = xen_swiotlb_map_page, .unmap_page = xen_swiotlb_unmap_page, .dma_supported = xen_swiotlb_dma_supported, diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 5403855..acf0c06 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -407,6 +407,42 @@ dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, EXPORT_SYMBOL_GPL(xen_swiotlb_map_page); /* + * Create userspace mapping for the DMA-coherent memory. + */ +int xen_swiotlb_dma_mmap(struct device *dev, struct vm_area_struct *vma, + void *cpu_addr, dma_addr_t dma_addr, size_t size, + struct dma_attrs *attrs) +{ + int ret = -ENXIO; + unsigned long nr_vma_pages = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT; + unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT; + unsigned long pfn = PFN_DOWN(xen_bus_to_phys(dma_addr)); + unsigned long off = vma->vm_pgoff; + pgprot_t prot = vma->vm_page_prot; + + prot = dma_get_attr(DMA_ATTR_WRITE_COMBINE, attrs) ? + pgprot_writecombine(prot) : + pgprot_dmacoherent(prot); + + vma->vm_page_prot = prot; + + if (dma_mmap_from_coherent(dev, vma, cpu_addr, size, &ret)) + return ret; + + if (off < nr_pages && nr_vma_pages <= (nr_pages - off)) { + ret = remap_pfn_range(vma, vma->vm_start, + pfn + off, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); + } + + return ret; +} +EXPORT_SYMBOL_GPL(xen_swiotlb_dma_mmap); + +/* * Unmap a single streaming mode DMA translation. The dma_addr and size must * match what was provided for in a previous xen_swiotlb_map_page call. All * other usages are undefined. diff --git a/include/xen/swiotlb-xen.h b/include/xen/swiotlb-xen.h index 7b64465..930fa94 100644 --- a/include/xen/swiotlb-xen.h +++ b/include/xen/swiotlb-xen.h @@ -15,6 +15,11 @@ xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle, struct dma_attrs *attrs); +extern int +xen_swiotlb_dma_mmap(struct device *dev, struct vm_area_struct *vma, + void *cpu_addr, dma_addr_t dma_addr, size_t size, + struct dma_attrs *attrs); + extern dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, enum dma_data_direction dir,