Received: by 10.223.176.46 with SMTP id f43csp4071505wra; Tue, 23 Jan 2018 03:54:21 -0800 (PST) X-Google-Smtp-Source: AH8x2266F54cLGguE6DHAZxhHejLhORHUQveGUVG18OPmjureZRBxwBzB+s6DxGBetf0lrPlDJAE X-Received: by 10.98.129.194 with SMTP id t185mr10198485pfd.228.1516708461772; Tue, 23 Jan 2018 03:54:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516708461; cv=none; d=google.com; s=arc-20160816; b=dJ3nGPOWIqsvI+q4MFD98r6tm5hFit3d6Xl5qiCvVIYrzZBXUxaVkuubPv4FrClhZ/ gw3545p04VKaTOUw9H15lwlwp1PR/liE9p1FxHJLKlew9jJaOZ+PA++1NkhT0QrhMpXk kTQUAhzBjbj3SXJM/QK0GsdFk/Vzxt+BPeVtVQ9JzaZxZiQXY0VvChefH2mauL2w7G5Q 2+HE1i87iFP4zyb3G0L2m5mf6VpvMZM3lVlsL0d4zi6CRYc7dzF9qcivzAkaSwBxK3yR 4CkLh7i7zNdceZc+P8CxvW9E6aPSY4umAKNPTe8SCqBZzVohHRhbyQePezVxZr3DdRBH b2Nw== 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=a3jVnTY7a+bBoPHIVIPSNeVCBeJE6ta4E6vz1ZRmddo=; b=Xez7GZlzlNP0FpeXqIyVqb5X3bx3pGtALVCMoLlkgAznmT2pEfcTMW3d12UyVaByYh R3YODBNNwlS/KizkyBYH2uEX5Elu5I8HxqOVBbKKVx01wDP8X9dVVKemukS0VQEFwhjF 6TVmvOsff2a+ub/QNR0QyjdYtbgO6E8qPSYIJeXtteuk2/uAD1ZfUcq+lbzTOESWe7A6 1OJ4xm56fgylIssMxnaxmIUS1PW/xJMD47pcgO/r4juNsH758fQh6Tc4h+jnZQ4yJmEl Rt7FcIUMZNyqxhQuzG7BKE/Pszmc+BYF571M3PxjxSYn9TAlA+Kp0I7lrs7z0B8S1EYu cERw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=e6dthoSC; 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 f89-v6si1913693plb.344.2018.01.23.03.54.06; Tue, 23 Jan 2018 03:54:21 -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=e6dthoSC; 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 S1751360AbeAWLxk (ORCPT + 99 others); Tue, 23 Jan 2018 06:53:40 -0500 Received: from mail-ua0-f195.google.com ([209.85.217.195]:46073 "EHLO mail-ua0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751173AbeAWLxh (ORCPT ); Tue, 23 Jan 2018 06:53:37 -0500 Received: by mail-ua0-f195.google.com with SMTP id z3so123742uae.12; Tue, 23 Jan 2018 03:53:36 -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=a3jVnTY7a+bBoPHIVIPSNeVCBeJE6ta4E6vz1ZRmddo=; b=e6dthoSCrtofa0NsaGQ/EB5Yu3iQneYtCvgOIH2eFb+PnqXTeuAMmnSc1SbFpeAu6f jyZr5myX32px2JkdBpD+9Bu4OOPt/Mclrp7OuOm89/4EVtBzglX7ET2rk1J6Vkqn4uxY ogOg6ycy3WBe0VcZLy38PWSHyVsRKg1tgG4tBB3yqx/SN9pR1cdkHQDYdOMdFWsTs81j t0c53izj9E8WiQcubG3eDvcTiV5Fr+kB3zqCLNKstBpy1hbEIyEw87z8ZK1dVBJVhQT+ HnGtersYts1mdIkvZ4j3r9F60YRTAfvhFvDFhccDb8w8ae/pqhYhh+nvQ9OqSMDDX97T nzEg== 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=a3jVnTY7a+bBoPHIVIPSNeVCBeJE6ta4E6vz1ZRmddo=; b=FH4+4Xxy4PO/ZCYXkwN6DPUO1DeN2ZNhXIi5Gf3p849WDCFOexraDgjwwUY5U+TAQ2 Fntr9b1BFoEx7iOeA0e1+K8w0A+bVH18RRVUHnhLVa90zYIlz4woeiZbHmChtsk/hODE aMzjb9L/QAfY3vZRd7tEtixI8uypG4MBtnMlQ2J9xu86pFTZfqqYfmTGLSH0cxb/2dtQ fax8AO8SJZrM0YrDYisTbyB5kO2zNL8+csZpUzMkr2U1EtoV+FREs6f1OAbn/Cm22ZqX pnBN0KISIql9V7zvf/iCO1mQ/DTENBoaYZWR6hmfybpJK+maJxD154NxFChgrSVFIdip Yagw== X-Gm-Message-State: AKwxytcEoK5YuN0wSywARitZZi9FFzZ5bjSIByj0W6oPp2JlJeHqr9Gj NUMtLDNwChURYMnELNhjacJDfiArmkL7On5dye0= X-Received: by 10.176.87.194 with SMTP id u2mr486103uac.91.1516708415909; Tue, 23 Jan 2018 03:53:35 -0800 (PST) MIME-Version: 1.0 Received: by 10.159.42.194 with HTTP; Tue, 23 Jan 2018 03:52:55 -0800 (PST) In-Reply-To: References: From: Greentime Hu Date: Tue, 23 Jan 2018 19:52:55 +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-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? > > static void > nds32_dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle, > size_t size, enum dma_data_direction dir) > { > switch (direction) { > case DMA_TO_DEVICE: /* writeback only */ > break; > case DMA_FROM_DEVICE: /* invalidate only */ > case DMA_BIDIRECTIONAL: /* writeback and invalidate */ > cpu_dma_inval_range(start, end); > break; > default: > BUG(); > } > } > > static void > nds32_dma_sync_single_for_device(struct device *dev, dma_addr_t handle, > size_t size, enum dma_data_direction dir) > { > switch (direction) { > case DMA_FROM_DEVICE: /* invalidate only */ > break; > case DMA_TO_DEVICE: /* writeback only */ > case DMA_BIDIRECTIONAL: /* writeback and invalidate */ > cpu_dma_wb_range(start, end); > break; > default: > BUG(); > } > } 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(); } } } static void nds32_dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle, size_t size, enum dma_data_direction dir) { consistent_sync((void *)phys_to_virt(handle), size, dir, FOR_CPU); } static void nds32_dma_sync_single_for_device(struct device *dev, dma_addr_t handle, size_t size, enum dma_data_direction dir) { consistent_sync((void *)phys_to_virt(handle), size, dir, FOR_DEVICE); } static dma_addr_t nds32_dma_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, enum dma_data_direction dir, unsigned long attrs) { if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) consistent_sync((void *)(page_address(page) + offset), size, dir, FOR_DEVICE); return page_to_phys(page) + offset; } static void nds32_dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size, enum dma_data_direction dir, unsigned long attrs) { if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) consistent_sync(phys_to_virt(handle), size, dir, FOR_CPU); }