Received: by 10.192.165.148 with SMTP id m20csp633983imm; Wed, 25 Apr 2018 05:28:16 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+I0RrF+rD7bjvmWjUGP0/6DbqfD7om4xRYK8hgvnZZjelhRexEJ3Zv1ncFxclQ9Ucshyur X-Received: by 2002:a17:902:207:: with SMTP id 7-v6mr29022263plc.261.1524659296571; Wed, 25 Apr 2018 05:28:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524659296; cv=none; d=google.com; s=arc-20160816; b=h/j0drg4Q83MMzoMEmiKpXggeFXFP8gktQVguudEVMfM/tbCIpAnosIrZDAO+l6vBu gifBs1daNlnMUT8mH3iQmbX0y2k8FcRLoThc8r1rRdn3H18LRaR4BDPkak8/HfGiwl7V fSwkY5T1i1XOdEINo1h44Q6wjDqUSgaLXjOjdBuaG5RvoS4DrzurqaDjkkhDUbnFy8y3 aJK5VgfyU851jyqDWbu1/HdVTvTNRhazDPS2YWS8hyCAcViKGSB8jGKSFZelTs53fDyx CP31lJ9Dx2l474LHtLaacpuRj6euw6TkGLoa4rfEcuju9kcxeWcS5GaQhVfgpT15zJvs ebOw== 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=w/Wmv3PocXIv+SCTwr0sWS75lM/EgokOzpi2r8Yun2Q=; b=qP3Ov3JdnHUFuQ7r9ewZGQ+QR6ig+ILI63Ua+DmQqO4wQmXtz4h8IHEId0Qi/BYzyE ZoYaQOBYAht97hZ0TqZNH4epJCDFi4MMTHmWbXfOOvQC2eiXkeGmwwU9lwOAUAbI+56u gIqoCnePz7GbXaFa1XyCx84hPKqrx4/acRvzyBR5s36C9AhjP8qV0WYFaUk0FOWZApTH +1/bmF7lhBAydp9bPSw75CYdzqHoxGBJ+zawOp64Fy5cDsdoJTB4p3leb/tfMLkpW0Bq o6QRoYb5THx+XEolpXS0YKjFlQL512jlxU7Rk3H0fgXc0fIl6vfU5BcDdUukRUER1bsC 1zig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MxmQtCZ+; 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=QUARANTINE 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 d2-v6si13613878plh.387.2018.04.25.05.28.02; Wed, 25 Apr 2018 05:28:16 -0700 (PDT) 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=MxmQtCZ+; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753547AbeDYM0u (ORCPT + 99 others); Wed, 25 Apr 2018 08:26:50 -0400 Received: from mail-vk0-f65.google.com ([209.85.213.65]:44610 "EHLO mail-vk0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752924AbeDYM0i (ORCPT ); Wed, 25 Apr 2018 08:26:38 -0400 Received: by mail-vk0-f65.google.com with SMTP id r184so13681356vke.11; Wed, 25 Apr 2018 05:26:37 -0700 (PDT) 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=w/Wmv3PocXIv+SCTwr0sWS75lM/EgokOzpi2r8Yun2Q=; b=MxmQtCZ+6c3nh77+/e/abztbjjK+NJwWc2TeSQ8N0aTHGTR9pjKsjgon+ghNxF+osR KH64+jpzq/sXR8/YpfLWuyKp89yj9j0IuzyWynpWHIbOQgXOpuj75X3j9NN1gaMOJ9RK id2sseqwZYfbp8Wmjkd0uND4klUHGO8RYFtO40dMwLgzQ5q/GHiKmY0JQOe7JY7vWwaA nPSeLYbE3aDq8uxJkef6+sgGrpXrACtAOxBJqBumwCOQvd2hhK7dkBCNUc7Y2qtdUwKT tla0loqJxJCSRSNPGGUw7yXWYapJlYpZyVmHm31PXArpCK6QvtJoNo8z6Kn1uC3Fit9I MoAQ== 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=w/Wmv3PocXIv+SCTwr0sWS75lM/EgokOzpi2r8Yun2Q=; b=aR+7SjWilYm33fcXZysImGqtcgBJK4YRfh+0NDnaCXuWMcuMQxQmG/F6yDGMfeC0Qd 34YmgxT0C+j41xkOPhwGvziC8DcT+x8/BNULHIYO9/b9Bx20pW/qWbxPEA9A9WYaLGSJ u4D83mvoK+2wnwNULYaXLIElvixgUNP7zFlEPmSa9OGewcaYUkJMMtq5RL4WyIVbM0Hz CKDMU8p8sFywnT3EhtkhtgGxVwXhoy4WEVp17pY/PNxVgJAJ9eukf+SY7BwChLPoEcGR dBqgNdz9aPcsp7vl/5BMP9n2MOjLgRJgZuRQlKe3BCl0RZRBZe2CbWfUOXjWxkLKSufE Z9Ng== X-Gm-Message-State: ALQs6tBKFKwP8EyznM2FLGmC3HgSpHOcUIkeGXGVqoITH0EdI05iDKuo aj/yDtBwfOE6sii2TTga8KCdFoIwqaqQ/mLTe8I= X-Received: by 10.31.169.145 with SMTP id s139mr13398360vke.54.1524659196366; Wed, 25 Apr 2018 05:26:36 -0700 (PDT) MIME-Version: 1.0 Received: by 10.176.92.86 with HTTP; Wed, 25 Apr 2018 05:25:55 -0700 (PDT) In-Reply-To: <20180425064055.GA11460@lst.de> References: <20180420080313.18796-1-hch@lst.de> <20180420080313.18796-14-hch@lst.de> <20180424191640.GA32495@lst.de> <20180425064055.GA11460@lst.de> From: Greentime Hu Date: Wed, 25 Apr 2018 20:25:55 +0800 Message-ID: Subject: Re: [PATCH 13/22] nds32: use generic dma_noncoherent_ops To: Christoph Hellwig Cc: linux-arch , Michal Simek , Vincent Chen , linux-alpha@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-c6x-dev@linux-c6x.org, linux-hexagon@vger.kernel.org, linux-m68k@lists.linux-m68k.org, nios2-dev@lists.rocketboards.org, openrisc@lists.librecores.org, linux-parisc@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux , linux-xtensa@linux-xtensa.org, Linux Kernel Mailing List 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 2018-04-25 14:40 GMT+08:00 Christoph Hellwig : > On Wed, Apr 25, 2018 at 09:43:43AM +0800, Greentime Hu wrote: >> Hi Crhistoph, >> >> The ftmac100 works if I revert this commit. > > Thanks. ftmac100 only use dma_map_page, which in the old nds32 code > is just doing a plain page_address and never kmaps. Can you apply > the patch below on the tree with the origin "nds32: use generic > dma_noncoherent_ops" reverted? This always just uses page_address, > although that, just like the original code is broken if you actually > have highmem that needs to be mapped: > Hi, Christoph, It still failed. > --- > From 1dc5d1cae4cd7b9ce03d0e2943364ed4cca938d7 Mon Sep 17 00:00:00 2001 > From: Christoph Hellwig > Date: Mon, 16 Apr 2018 19:20:30 +0200 > Subject: nds32: use generic dma_noncoherent_ops > > Switch to the generic noncoherent direct mapping implementation. > > This makes sure the cache_sync routines is called in the unmap_sg > case, to match the unmap_single and sync_{single,sg}_to_cpu cases. > > Signed-off-by: Christoph Hellwig > --- > arch/nds32/Kconfig | 3 + > arch/nds32/include/asm/Kbuild | 1 + > arch/nds32/include/asm/dma-mapping.h | 14 --- > arch/nds32/kernel/dma.c | 182 +++++---------------------- > 4 files changed, 37 insertions(+), 163 deletions(-) > delete mode 100644 arch/nds32/include/asm/dma-mapping.h > > diff --git a/arch/nds32/Kconfig b/arch/nds32/Kconfig > index 249f38d3388f..67d0ac0a989c 100644 > --- a/arch/nds32/Kconfig > +++ b/arch/nds32/Kconfig > @@ -5,10 +5,13 @@ > > config NDS32 > def_bool y > + select ARCH_HAS_SYNC_DMA_FOR_CPU > + select ARCH_HAS_SYNC_DMA_FOR_DEVICE > select ARCH_WANT_FRAME_POINTERS if FTRACE > select CLKSRC_MMIO > select CLONE_BACKWARDS > select COMMON_CLK > + select DMA_NONCOHERENT_OPS > select GENERIC_ATOMIC64 > select GENERIC_CPU_DEVICES > select GENERIC_CLOCKEVENTS > diff --git a/arch/nds32/include/asm/Kbuild b/arch/nds32/include/asm/Kbuild > index 06bdf8167f5a..b3e951f805f8 100644 > --- a/arch/nds32/include/asm/Kbuild > +++ b/arch/nds32/include/asm/Kbuild > @@ -13,6 +13,7 @@ generic-y += cputime.h > generic-y += device.h > generic-y += div64.h > generic-y += dma.h > +generic-y += dma-mapping.h > generic-y += emergency-restart.h > generic-y += errno.h > generic-y += exec.h > diff --git a/arch/nds32/include/asm/dma-mapping.h b/arch/nds32/include/asm/dma-mapping.h > deleted file mode 100644 > index 2dd47d245c25..000000000000 > --- a/arch/nds32/include/asm/dma-mapping.h > +++ /dev/null > @@ -1,14 +0,0 @@ > -// SPDX-License-Identifier: GPL-2.0 > -// Copyright (C) 2005-2017 Andes Technology Corporation > - > -#ifndef ASMNDS32_DMA_MAPPING_H > -#define ASMNDS32_DMA_MAPPING_H > - > -extern struct dma_map_ops nds32_dma_ops; > - > -static inline struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus) > -{ > - return &nds32_dma_ops; > -} > - > -#endif > diff --git a/arch/nds32/kernel/dma.c b/arch/nds32/kernel/dma.c > index d291800fc621..78311a1e6fd1 100644 > --- a/arch/nds32/kernel/dma.c > +++ b/arch/nds32/kernel/dma.c > @@ -3,17 +3,14 @@ > > #include > #include > -#include > #include > -#include > -#include > +#include > #include > #include > #include > #include > #include > #include > -#include > #include > > /* > @@ -22,11 +19,6 @@ > static pte_t *consistent_pte; > static DEFINE_RAW_SPINLOCK(consistent_lock); > > -enum master_type { > - FOR_CPU = 0, > - FOR_DEVICE = 1, > -}; > - > /* > * VM region handling support. > * > @@ -124,10 +116,8 @@ static struct arch_vm_region *vm_region_find(struct arch_vm_region *head, > return c; > } > > -/* FIXME: attrs is not used. */ > -static void *nds32_dma_alloc_coherent(struct device *dev, size_t size, > - dma_addr_t * handle, gfp_t gfp, > - unsigned long attrs) > +void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, > + gfp_t gfp, unsigned long attrs) > { > struct page *page; > struct arch_vm_region *c; > @@ -232,8 +222,8 @@ static void *nds32_dma_alloc_coherent(struct device *dev, size_t size, > return NULL; > } > > -static void nds32_dma_free(struct device *dev, size_t size, void *cpu_addr, > - dma_addr_t handle, unsigned long attrs) > +void arch_dma_free(struct device *dev, size_t size, void *cpu_addr, > + dma_addr_t handle, unsigned long attrs) > { > struct arch_vm_region *c; > unsigned long flags, addr; > @@ -333,145 +323,39 @@ static int __init consistent_init(void) > } > > core_initcall(consistent_init); > -static void consistent_sync(void *vaddr, size_t size, int direction, int master_type); > -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) > +void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr, > + size_t size, enum dma_data_direction dir) > { > - if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) > - consistent_sync(phys_to_virt(handle), size, dir, FOR_CPU); > -} > - > -/* > - * Make an area consistent for devices. > - */ > -static void consistent_sync(void *vaddr, size_t size, int direction, int master_type) > -{ > - unsigned long start = (unsigned long)vaddr; > - unsigned long end = start + size; > - > - if (master_type == 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(); > - } > + void *addr = phys_to_virt(paddr); > + unsigned long start = (unsigned long)addr; > + > + switch (dir) { > + case DMA_FROM_DEVICE: > + break; > + case DMA_TO_DEVICE: > + case DMA_BIDIRECTIONAL: > + cpu_dma_wb_range(start, start + size); > + break; > + default: > + BUG(); > } > } > > -static int nds32_dma_map_sg(struct device *dev, struct scatterlist *sg, > - int nents, enum dma_data_direction dir, > - unsigned long attrs) > +void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr, > + size_t size, enum dma_data_direction dir) > { > - int i; > - > - for (i = 0; i < nents; i++, sg++) { > - void *virt; > - unsigned long pfn; > - struct page *page = sg_page(sg); > - > - sg->dma_address = sg_phys(sg); > - pfn = page_to_pfn(page) + sg->offset / PAGE_SIZE; > - page = pfn_to_page(pfn); > - if (PageHighMem(page)) { > - virt = kmap_atomic(page); > - consistent_sync(virt, sg->length, dir, FOR_CPU); > - kunmap_atomic(virt); > - } else { > - if (sg->offset > PAGE_SIZE) > - panic("sg->offset:%08x > PAGE_SIZE\n", > - sg->offset); > - virt = page_address(page) + sg->offset; > - consistent_sync(virt, sg->length, dir, FOR_CPU); > - } > + void *addr = phys_to_virt(paddr); > + unsigned long start = (unsigned long)addr; > + > + switch (dir) { > + case DMA_TO_DEVICE: > + break; > + case DMA_FROM_DEVICE: > + case DMA_BIDIRECTIONAL: > + cpu_dma_inval_range(start, start + size); > + break; > + default: > + BUG(); > } > - return nents; > } > - > -static void nds32_dma_unmap_sg(struct device *dev, struct scatterlist *sg, > - int nhwentries, enum dma_data_direction dir, > - unsigned long attrs) > -{ > -} > - > -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 void > -nds32_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nents, > - enum dma_data_direction dir) > -{ > - int i; > - > - for (i = 0; i < nents; i++, sg++) { > - char *virt = > - page_address((struct page *)sg->page_link) + sg->offset; > - consistent_sync(virt, sg->length, dir, FOR_CPU); > - } > -} > - > -static void > -nds32_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, > - int nents, enum dma_data_direction dir) > -{ > - int i; > - > - for (i = 0; i < nents; i++, sg++) { > - char *virt = > - page_address((struct page *)sg->page_link) + sg->offset; > - consistent_sync(virt, sg->length, dir, FOR_DEVICE); > - } > -} > - > -struct dma_map_ops nds32_dma_ops = { > - .alloc = nds32_dma_alloc_coherent, > - .free = nds32_dma_free, > - .map_page = nds32_dma_map_page, > - .unmap_page = nds32_dma_unmap_page, > - .map_sg = nds32_dma_map_sg, > - .unmap_sg = nds32_dma_unmap_sg, > - .sync_single_for_device = nds32_dma_sync_single_for_device, > - .sync_single_for_cpu = nds32_dma_sync_single_for_cpu, > - .sync_sg_for_cpu = nds32_dma_sync_sg_for_cpu, > - .sync_sg_for_device = nds32_dma_sync_sg_for_device, > -}; > - > -EXPORT_SYMBOL(nds32_dma_ops); > -- > 2.17.0 >