Received: by 10.223.176.46 with SMTP id f43csp627377wra; Wed, 24 Jan 2018 03:36:56 -0800 (PST) X-Google-Smtp-Source: AH8x226AcCEu/zbWq9oEGaj78tXScxc579g92pD7y5ONkSDEm0fPc0J0T55ESJxum+yLeGYUei3n X-Received: by 10.98.242.2 with SMTP id m2mr13021096pfh.102.1516793816582; Wed, 24 Jan 2018 03:36:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516793816; cv=none; d=google.com; s=arc-20160816; b=QTrwnnIwFaRpLemhmnh+zcVoE487HtzyqkkDPDrVg0IdcVFtd3/b9QChFACNBCHeCn PqfvrVtZc1z5eMnZr0WT4axHXGRd+nJNkkrmNzmFJmOcauo0QdMjFQvNafnUGcirIvzh ik/zBEMLTAHSjBPuwKieUNfDNqlWqaMQFKTQ+e90W1P83g7lhMvtbiYXSpoaUgCGAl9+ KiSEWM1hMWPkHowmAVAJqdOCAfVKaP54QEFM/1QIzjUlsFMme+K3kN/sWMINQTYRsNTh xCmfUTjbZ87b1uSuHSCercEp+sT/xnmJ3AN9/cjJFnrILFmtOIlWC1a9BvvkMp+Uvwld eApA== 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=MNDxSp2yYMddOgbA1w5vMItNm6hH+Vr0yrgfmqPuwoI=; b=nXAQcEMpRTU4fvqrrrXU7hpQoDBW+MSGN9/mNcI74zT8lFaVKhtGuBx9fiad9RPLYq kiMKMvm77xiTXf2mptry6NqIJWaGuICuSsMN4RdmNC0g7y17EPGD0HX11p0Onb5XcJCE A0Y7Gm2s4kwxjOmsBpk5LbsXaHN6uuaBObH3NvA/ySgMNXq99mbpQ2Gl9xAlVuA1Sj8Z T1VQx4V8t3WIjI8ZFnpRo+99nPGfz+7iG3mW8IAAN48KNrTe5zL2k/NympFSqT62xAf+ c0A0m925yFH6g+3sopFbEuLYKAgXrDYniZFAuLYDKmnKbhzPdyCCdme/Ed7lUMX95MJ/ FzmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Epo6CCXk; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r17si28736pge.478.2018.01.24.03.36.42; Wed, 24 Jan 2018 03:36:56 -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=fail header.i=@gmail.com header.s=20161025 header.b=Epo6CCXk; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933381AbeAXLgW (ORCPT + 99 others); Wed, 24 Jan 2018 06:36:22 -0500 Received: from mail-ot0-f196.google.com ([74.125.82.196]:41466 "EHLO mail-ot0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933060AbeAXLgT (ORCPT ); Wed, 24 Jan 2018 06:36:19 -0500 Received: by mail-ot0-f196.google.com with SMTP id 44so3286021otk.8; Wed, 24 Jan 2018 03:36:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=MNDxSp2yYMddOgbA1w5vMItNm6hH+Vr0yrgfmqPuwoI=; b=Epo6CCXkto0iDI3qf08yhMvxYhWKITRflOjA8pR6WxDOmIskNjR1BZW++pN8hYKBug SGmV4S6KpouBKOgYA7m1eJBcp+0/8zu/m55yxaABP4vgSnQnCnh9vM269B96OSKOcdJH tOOtJYLxwaugAz1nkWeJJbeezhVULzlaTybim4mjCR90LNMwvZrVQNrk+01uxpIHFJDN 0+m+n6BMXlRt2/DRM48umcCAr/zNmcKavKqYsEo6+LgiCaEAYqhW1LRNZKdFNFX9W1V3 AIQwnIVfwyTgxthyt1FNHoTQEii2jzwJ7TUu4n3gOoVB6AYdBEXSoguyBt0Ftsz2vsWo 0InA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=MNDxSp2yYMddOgbA1w5vMItNm6hH+Vr0yrgfmqPuwoI=; b=ZKTw2Hj4aH4OjHSXu9Yoi5mkZppQCOTptjO74sQqzUu90YmgssUcWB74ln8MoZ7iwL M6f1Bcsm/tndJBIE2UP1U2nVblGvTXMCt8qhFTIgiaT2/ux6eA+z6z63yKHyRr+agoxp xc68tuJpkjf1sDxmqRmJxwNZpnCvsK9IILh0Iz2TtNDyqlbXe/5Pdqznr7IEfrPoHeP/ 5Prhsaq02wb+xD9rfvq99ygAf+KF9iA4DZdB89lD4C2vsRoR9t3fYIU9dmouMRF0nKYC 3qIiispeYaLIaqBTUJgP1+RqW43NACyP0iRuGFFay6qgof8+hC3lQJodABo9oslvoRLZ XkYQ== X-Gm-Message-State: AKwxyteRK1V98JZgEpBBApdgyoq/5H/30WtMUk+XLc2LyydOm1M2lFZy oqqLTIc60B8ANKRAbxVzhb59oZQriFiViXlQ6ML7gg== X-Received: by 10.157.114.221 with SMTP id d29mr8883646otk.104.1516793778111; Wed, 24 Jan 2018 03:36:18 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.68.119 with HTTP; Wed, 24 Jan 2018 03:36:17 -0800 (PST) In-Reply-To: References: From: Arnd Bergmann Date: Wed, 24 Jan 2018 12:36:17 +0100 X-Google-Sender-Auth: BavH22m_mZ-6-mO7dE6wZFJ-YQw Message-ID: Subject: Re: [PATCH v6 16/36] nds32: DMA mapping API To: Greentime Hu 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 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? - can the cache be shared with another CPU or a device? - if the cache is shared, is it always coherent, never coherent, or either of them? - could the same memory be visible at different physical addresses and have conflicting caches? - is the CPU physical address always the same as the address visible to the device? - are there devices that can only see a subset of the physical memory? - can there be an IOMMU? - are there write-buffers in the CPU that might need to get flushed before flushing the cache? - could cache lines be loaded speculatively or with read-ahead while a buffer is owned by a device? Arnd