Received: by 10.223.176.46 with SMTP id f43csp1576283wra; Wed, 24 Jan 2018 19:46:48 -0800 (PST) X-Google-Smtp-Source: AH8x224v/4lDjWPBUg+/iQ9E+ABRfiKZE78xCNPL2h17MwhKFE4owJSkXGHJTU1Uohw0lNXxyhlL X-Received: by 10.101.64.139 with SMTP id t11mr11923460pgp.162.1516852008713; Wed, 24 Jan 2018 19:46:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516852008; cv=none; d=google.com; s=arc-20160816; b=X+MWwb5iTfoHSg+Mvc7TM/cj83zt7slcn6Wy8piRnyUc8Qh4cIpd/hMabNVSSXXhEG o+XnhnZjS6KCXQgQUehzVREIIdVXjPI/EjS/2hsSSYiNlMuopDQmenpcdCWOMaLoq3mE cCAxIg3JOYAPo+wlnm34kcrB6ADg3ofyDeo5ZdW9t7it/dSjlTf2RyujmV879G75w2G8 H/h6dvEK85EQVzbV1BdiP9VJyK5fxqqvp3uV+Xuc0Hchyaml48Ybu+RUkXJ1SEnwdAMh oDevbClNknP4nx90Vhs1U0ri6dfWebFGpOE4dTSScLWXgQx8W3yI7i2RqHAxoDCl4yPn QF0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=j49dvjrtvOqIsWCZv6Ih5/4qVS6vRhrTJiyoXxSJqq8=; b=tsHFmQe8q9RNHvQ3kpmOXWOr6nwTSi7rcf5sdNN6fH6aBguVlLr76kJYfNnw1vmMFg +2xubiccC06qISg28LTh9X7qWb41Hk6FWyv6MsQDpneO4/MZoU4akXiVIRt1PyabqMZX KSe303z6ZmXRwmQ/xPT5AZ0itvq8dfdxGee3Oe1oLCcjEMthJA9a0tOUp7XysjlGuHFt 1pRwRWTlA8K9SK4rdg/WWN8JRXLLEhDNokCRYtwqHcIBOeXHJw4R0hM1MYxMNkPYzYBK ZPQvbFF3/jIjWaktU4SnQRB2K+7RuTgGf+5y7GqqfYgxjBLXH2jksy1gxp5NkzyKaCtM +i0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pJRSNa+0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e27si2558845pfk.172.2018.01.24.19.46.34; Wed, 24 Jan 2018 19:46:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pJRSNa+0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933472AbeAYDqC (ORCPT + 99 others); Wed, 24 Jan 2018 22:46:02 -0500 Received: from mail-vk0-f65.google.com ([209.85.213.65]:44465 "EHLO mail-vk0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933198AbeAYDp7 (ORCPT ); Wed, 24 Jan 2018 22:45:59 -0500 Received: by mail-vk0-f65.google.com with SMTP id q62so3988389vkb.11; Wed, 24 Jan 2018 19:45:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=j49dvjrtvOqIsWCZv6Ih5/4qVS6vRhrTJiyoXxSJqq8=; b=pJRSNa+0xa3yt/vhI+Qxr9YqvZOnY3iYXJumekICKR8uLKdVhDbgaP6KwKfhOvpCIZ BgntogEZ6ceXuY/tSMUxA8mpcuvvqSpJsvtc4ejzuiKidt0CgpxVKQhZSdYwChUEwp3c gM/popBb5UEMb3kyoVUYkKE4+7jCom5gVlc5o7PD+fmcDdl/LPP5VZ4Db8fnn/t5D7H3 rhcMqlOozNX6I0dN7alLCFihdXvzaVAyKYSnHpCUYAN6I2ZCYFBOfR7qVBnvFFGjEl/X +b5nHR1yxPBZVz9oXjzrSZM15gyz0etYFU5rfQ/Ao3QfJA1wvU8M6i5TK/cbPZA3v2Cb UNEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=j49dvjrtvOqIsWCZv6Ih5/4qVS6vRhrTJiyoXxSJqq8=; b=I5hTADO0aLLxj3Ciy+uYWcq4LIfJjs8e3bdd9EGuLw/Mz9AsLngbUEoiMWyO4hOiln 4KcdBnQ8xqd+In9veDesCSjzdTuwgbTgoV04IHGgxgWOzGqeFB+rGGn6lbolYx7SFzrc q2S+GSkjgbEJdtXzdW+82s/joJUqVoqyYpMtIrtaViC721QQtKq45G/IoFDhXjQpN8Ex dmgwNF1384OLb3t616iE2m3x7Cc0yfWm1zSQQDBI51Ah1IIjMJSqN3Pai3Hs32nIoSoi mAoXbGEtVufK33SLVNyDc95rgcUhhn6HTflM654XhFIYAVNS08xH7fSaDuL7VjFQevrE K4bw== X-Gm-Message-State: AKwxyteLG2V6olJpC2juBfG+hme+SoNTQK/2EngQsOSYjB8fjE6lb2U0 /FHDmOIODYtwdwpRu0ny+nMohGndpccsmbta4zE= X-Received: by 10.31.108.66 with SMTP id h63mr6467116vkc.198.1516851958710; Wed, 24 Jan 2018 19:45:58 -0800 (PST) MIME-Version: 1.0 Received: by 10.159.42.194 with HTTP; Wed, 24 Jan 2018 19:45:18 -0800 (PST) In-Reply-To: References: From: Greentime Hu Date: Thu, 25 Jan 2018 11:45:18 +0800 Message-ID: Subject: Re: [PATCH v6 16/36] nds32: DMA mapping API To: Arnd Bergmann Cc: Greentime , Linux Kernel Mailing List , linux-arch , Thomas Gleixner , Jason Cooper , Marc Zyngier , Rob Herring , Networking , Vincent Chen , DTML , Al Viro , David Howells , Will Deacon , Daniel Lezcano , linux-serial@vger.kernel.org, Geert Uytterhoeven , Linus Walleij , Mark Rutland , Greg KH , Guo Ren , Randy Dunlap , David Miller , Jonas Bonn , Stefan Kristiansson , Stafford Horne , Vincent Chen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Arnd: 2018-01-24 19:36 GMT+08:00 Arnd Bergmann : > On Tue, Jan 23, 2018 at 12:52 PM, Greentime Hu wrote: >> Hi, Arnd: >> >> 2018-01-23 16:23 GMT+08:00 Greentime Hu : >>> Hi, Arnd: >>> >>> 2018-01-18 18:26 GMT+08:00 Arnd Bergmann : >>>> On Mon, Jan 15, 2018 at 6:53 AM, Greentime Hu wrote: >>>>> From: Greentime Hu >>>>> >>>>> This patch adds support for the DMA mapping API. It uses dma_map_ops for >>>>> flexibility. >>>>> >>>>> Signed-off-by: Vincent Chen >>>>> Signed-off-by: Greentime Hu >>>> >>>> I'm still unhappy about the way the cache flushes are done here as discussed >>>> before. It's not a show-stopped, but no Ack from me. >>> >>> How about this implementation? > >> I am not sure if I understand it correctly. >> I list all the combinations. >> >> RAM to DEVICE >> before DMA => writeback cache >> after DMA => nop >> >> DEVICE to RAM >> before DMA => nop >> after DMA => invalidate cache >> >> static void consistent_sync(void *vaddr, size_t size, int direction, int master) >> { >> unsigned long start = (unsigned long)vaddr; >> unsigned long end = start + size; >> >> if (master == FOR_CPU) { >> switch (direction) { >> case DMA_TO_DEVICE: >> break; >> case DMA_FROM_DEVICE: >> case DMA_BIDIRECTIONAL: >> cpu_dma_inval_range(start, end); >> break; >> default: >> BUG(); >> } >> } else { >> /* FOR_DEVICE */ >> switch (direction) { >> case DMA_FROM_DEVICE: >> break; >> case DMA_TO_DEVICE: >> case DMA_BIDIRECTIONAL: >> cpu_dma_wb_range(start, end); >> break; >> default: >> BUG(); >> } >> } >> } > > That looks reasonable enough, but it does depend on a number of factors, > and the dma-mapping.h implementation is not just about cache flushes. > > As I don't know the microarchitecture, can you answer these questions: > > - are caches always write-back, or could they be write-through? Yes, we can config it to write-back or write-through. > - can the cache be shared with another CPU or a device? No, we don't support it. > - if the cache is shared, is it always coherent, never coherent, or > either of them? We don't support SMP and the device will access memory through bus. I think the cache is not shared. > - could the same memory be visible at different physical addresses > and have conflicting caches? We currently don't have such kind of SoC memory map. > - is the CPU physical address always the same as the address visible to the > device? Yes, it is always the same unless the CPU uses local memory. The physical address of local memory will overlap the original bus address. I think the local memory case can be ignored because we don't use it for now. > - are there devices that can only see a subset of the physical memory? All devices are able to see the whole physical memory in our current SoC, but I think other SoC may support such kind of HW behavior. > - can there be an IOMMU? No. > - are there write-buffers in the CPU that might need to get flushed before > flushing the cache? Yes, there are write-buffers in front of CPU caches but it should be transparent to SW. We don't need to flush it. > - could cache lines be loaded speculatively or with read-ahead while > a buffer is owned by a device? No.