From patchwork Mon Apr 7 06:32:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Dmytryshyn X-Patchwork-Id: 27888 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f197.google.com (mail-qc0-f197.google.com [209.85.216.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CD7A52055D for ; Mon, 7 Apr 2014 06:34:32 +0000 (UTC) Received: by mail-qc0-f197.google.com with SMTP id i8sf18904977qcq.8 for ; Sun, 06 Apr 2014 23:34:32 -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=Fd/6HnqhHm9oa9h6m4fjIjK3hz3IrRWOE34svlWU/Xg=; b=cfKcbYdNWRM4GE3V3MRP3BMS1BiQqo/uitu+LsA8xx2iBjV0jJg5YNYwu6q9sY9ubx It8WQwGwUvdThnGWSzond40SEHz37xrfcQsrt/lIl9rbQ/itfBwDEyqM8id5N0dn93E+ xWlSN5GzTbo941ySU2ixbRzAT0DIDzYwNLzqQNsMjVMsJZlpcB0n8yXFjoJpC/Ql9r40 LlrtXd6tuHwqkxB6ZqnIBZTuppqNF/5MPHUvoEANMDHotySF++T2+3/3PmkQUy80fjaI E6wrCrCIfnbbBV8Y2xKRicWkvHcFqclLObkNJZkWYRJ574nIhTfJdabJo8fLwDY18Tm0 XKkg== X-Gm-Message-State: ALoCoQkAy91mYr6r1W4ffCrnWTA4nSt7spI3cRgnRVOIA3YePc647dJB5LnRxcE2/YFuLJoMUouu X-Received: by 10.52.28.116 with SMTP id a20mr13448528vdh.2.1396852472585; Sun, 06 Apr 2014 23:34:32 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.102.203 with SMTP id w69ls1616038qge.3.gmail; Sun, 06 Apr 2014 23:34:32 -0700 (PDT) X-Received: by 10.52.173.165 with SMTP id bl5mr23297554vdc.13.1396852472486; Sun, 06 Apr 2014 23:34:32 -0700 (PDT) Received: from mail-vc0-x22d.google.com (mail-vc0-x22d.google.com [2607:f8b0:400c:c03::22d]) by mx.google.com with ESMTPS id tz5si2959738vdc.151.2014.04.06.23.34.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 06 Apr 2014 23:34:32 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c03::22d 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:c03::22d; Received: by mail-vc0-f173.google.com with SMTP id il7so4871090vcb.4 for ; Sun, 06 Apr 2014 23:34:32 -0700 (PDT) X-Received: by 10.220.161.8 with SMTP id p8mr22726056vcx.4.1396852472353; Sun, 06 Apr 2014 23:34:32 -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 v8csp137440vcv; Sun, 6 Apr 2014 23:34:32 -0700 (PDT) X-Received: by 10.52.104.7 with SMTP id ga7mr110751vdb.29.1396852471940; Sun, 06 Apr 2014 23:34:31 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id j5si1956341veb.75.2014.04.06.23.34.31 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 06 Apr 2014 23:34:31 -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 1WX36L-0004Vs-HI; Mon, 07 Apr 2014 06:32:13 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WX36J-0004Vn-F7 for xen-devel@lists.xenproject.org; Mon, 07 Apr 2014 06:32:11 +0000 Received: from [85.158.139.211:50957] by server-12.bemta-5.messagelabs.com id 9D/CB-03824-A6642435; Mon, 07 Apr 2014 06:32:10 +0000 X-Env-Sender: oleksandr.dmytryshyn@globallogic.com X-Msg-Ref: server-8.tower-206.messagelabs.com!1396852327!5613024!1 X-Originating-IP: [64.18.0.246] 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 6063 invoked from network); 7 Apr 2014 06:32:09 -0000 Received: from exprod5og115.obsmtp.com (HELO exprod5og115.obsmtp.com) (64.18.0.246) by server-8.tower-206.messagelabs.com with DHE-RSA-AES256-SHA encrypted SMTP; 7 Apr 2014 06:32:09 -0000 Received: from mail-ee0-f54.google.com ([74.125.83.54]) (using TLSv1) by exprod5ob115.postini.com ([64.18.4.12]) with SMTP ID DSNKU0JGZ5DbelPla7CwYOCwQNS4dFLNh67A@postini.com; Sun, 06 Apr 2014 23:32:09 PDT Received: by mail-ee0-f54.google.com with SMTP id d49so246349eek.41 for ; Sun, 06 Apr 2014 23:32:06 -0700 (PDT) X-Received: by 10.15.45.130 with SMTP id b2mr375551eew.28.1396852326224; Sun, 06 Apr 2014 23:32:06 -0700 (PDT) X-Received: by 10.15.45.130 with SMTP id b2mr375529eew.28.1396852326087; Sun, 06 Apr 2014 23:32:06 -0700 (PDT) Received: from localhost ([195.238.92.241]) by mx.google.com with ESMTPSA id a42sm39715903ees.10.2014.04.06.23.32.04 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 06 Apr 2014 23:32:05 -0700 (PDT) From: Oleksandr Dmytryshyn To: Stefano Stabellini Date: Mon, 7 Apr 2014 09:32:03 +0300 Message-Id: <1396852323-11814-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] 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:c03::22d 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. Change-Id: If22f75996278063394f628f57869ccd3ca09de7c 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; +#ifdef CONFIG_MMU + 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); + } +#endif /* CONFIG_MMU */ + + 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,