From patchwork Wed Jan 4 10:33:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Murzin X-Patchwork-Id: 9497909 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C68A160237 for ; Wed, 4 Jan 2017 21:45:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C455F2793B for ; Wed, 4 Jan 2017 21:45:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B751A27F17; Wed, 4 Jan 2017 21:45:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 493D72793B for ; Wed, 4 Jan 2017 21:45:08 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cOtLd-0002nU-WB; Wed, 04 Jan 2017 21:43:54 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cOsqx-0007IB-Qu for linux-arm-kernel@bombadil.infradead.org; Wed, 04 Jan 2017 21:12:12 +0000 Received: from foss.arm.com ([217.140.101.70]) by casper.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cOita-0006xp-Oz for linux-arm-kernel@lists.infradead.org; Wed, 04 Jan 2017 10:34:16 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9BE46154D; Wed, 4 Jan 2017 02:33:53 -0800 (PST) Received: from [10.1.79.26] (unknown [10.1.79.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 947EE3F318; Wed, 4 Jan 2017 02:33:52 -0800 (PST) Subject: Re: [RFC v2 PATCH 1/3] ARM: NOMMU: introduce dma operations for noMMU To: Benjamin Gaignard References: <1481636704-18948-1-git-send-email-vladimir.murzin@arm.com> <1481636704-18948-2-git-send-email-vladimir.murzin@arm.com> From: Vladimir Murzin Message-ID: <9c957673-64ba-67ca-46a0-2bde26c95d9c@arm.com> Date: Wed, 4 Jan 2017 10:33:51 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170104_103414_951920_3EBF37CF X-CRM114-Status: GOOD ( 23.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sza@esh.hu, robin.murphy@arm.com, linux@armlinux.org.uk, linux-arm-kernel@lists.infradead.org, Alexandre Torgue Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Hello Benjamin, On 02/01/17 15:26, Benjamin Gaignard wrote: > Hello Vladimir, > > I have tested your patch on my setup (stm32f4: no MMU, no MPU) where > I'm writing display driver. > This driver use dma_alloc_wc() and dma_mmap_wc() for frame buffer > allocation and mmapping. > > In dma-mapping-nommu.c you haven't implement dma_map_ops.mmap so > obviously my driver > doesn't work with your code. > In current implementation it is buggy too but I submit a patch to fix > that problem: > http://www.armlinux.org.uk/developer/patches/viewpatch.php?id=8633/1 > > Could it be possible for you to include mmap support in dma-mapping-nommu.c ? > IIRC, stm32f4 is Cortex-M4, so no cache support and it means that it uses dma_noop_ops. I offloaded mmap to common implementation, but completely forgot it has the same restriction as arm counterpart. Regardless, thanks for noticing that! It seems that I need to check that mapping is done from DMA coherent area (I'm moving to dma-coherent and here we have dma_mmap_from_coherent for that) and something like bellow for dma_noop_ops: I'd be glad to hear if it works for you. Cheers Vladimir > Regards, > Benjamin diff --git a/lib/dma-noop.c b/lib/dma-noop.c index 3d766e7..d838b88 100644 --- a/lib/dma-noop.c +++ b/lib/dma-noop.c @@ -64,6 +64,25 @@ static int dma_noop_supported(struct device *dev, u64 mask) return 1; } +static int dma_noop_mmap(struct device *dev, struct vm_area_struct *vma, + void *cpu_addr, dma_addr_t dma_addr, size_t size) +{ + unsigned long user_count = vma_pages(vma); + unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT; + unsigned long pfn = page_to_pfn(virt_to_page(cpu_addr)); + unsigned long off = vma->vm_pgoff; + int ret = -ENXIO; + + if (off < count && user_count <= (count - off)) { + ret = remap_pfn_range(vma, vma->vm_start, + pfn + off, + user_count << PAGE_SHIFT, + vma->vm_page_prot); + } + + return ret; +} + struct dma_map_ops dma_noop_ops = { .alloc = dma_noop_alloc, .free = dma_noop_free, @@ -71,6 +90,7 @@ struct dma_map_ops dma_noop_ops = { .map_sg = dma_noop_map_sg, .mapping_error = dma_noop_mapping_error, .dma_supported = dma_noop_supported, + .mmap = dma_noop_mmap, }; EXPORT_SYMBOL(dma_noop_ops);