Received: by 10.192.165.148 with SMTP id m20csp3092417imm; Sun, 22 Apr 2018 23:51:56 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+pBjIGvex+o5apZrXX6VJhEGydstidUmPkLNzloTMib/rSL6em8X5TKDFf4uJKJ+kkkQub X-Received: by 10.101.90.194 with SMTP id d2mr16267458pgt.352.1524466315980; Sun, 22 Apr 2018 23:51:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524466315; cv=none; d=google.com; s=arc-20160816; b=KAAHX8BzBZYfoJdZlI5s3acQNLQmZ4V7QM/iDQ3lxlySFNHNCtpC5zVvH7v8vGB6lS PufiZfeiFsN4GtKm5l+49UDp8Z6cMoN2gKmLAGsHkDqDHu6IDqpttCReusUsR1cbnZOk aUCG7lhYAdSokMi1KTv/0RIQ2GFwy550KU9PymmR4+o5FHYH0pRUcYSkvLgV5V8NJFBb ENRqavk9sijP3Rpo1wwfyAF1dzxnUyA2XTMOGi1QUZKAghwC5LHiHLJVbXsZ5wDWrCFD 5eRPG1p5M0MeVLwzjwbuW2GPsGAoV9m/GIaFIt+C2Cd4jrvmtrOVRGz9x+xYZAwiTiaY kOgQ== 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=PMWeELwN2wO6NhCjsBKzQYjfQvJVOGB+Cb+lkqyEBh8=; b=Lp019GJnAXnU+gklGdudBIxV0edyQYXqQnTa7TIqMXs4EQ2MrJGBdzNlAVi1J4fL9L ATc/88ZuDm8SrmHs0T5rGpfnqiDYjrCvDUN8qNCTDP/MervOORZym4H4mkSvfA8AyuZX hfHGa58lAX4YOEitWzSFBhedE6eWlqTFYXdhyUHF80M952LQ13gFK/w7ukPK8T+FFaQ/ TBVZniAvia7oGCmFb9raKnifY2tx+effkXZU+gwsuHmnAaa+Cg1to+v5vEjNZqoqjdY8 1w5/6sP5YO/cvj/QXyzCpNjp2Sii5+oz0LFAeDJxS6mGyGLSK4MuYganv/MKwixHvJmX j1ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lnNbTGtc; 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 g85si10903850pfg.192.2018.04.22.23.51.41; Sun, 22 Apr 2018 23:51:55 -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=lnNbTGtc; 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 S1752991AbeDWGua (ORCPT + 99 others); Mon, 23 Apr 2018 02:50:30 -0400 Received: from mail-ua0-f196.google.com ([209.85.217.196]:36292 "EHLO mail-ua0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751216AbeDWGuY (ORCPT ); Mon, 23 Apr 2018 02:50:24 -0400 Received: by mail-ua0-f196.google.com with SMTP id v4so9486740uaj.3; Sun, 22 Apr 2018 23:50:23 -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=PMWeELwN2wO6NhCjsBKzQYjfQvJVOGB+Cb+lkqyEBh8=; b=lnNbTGtcmRIDy/nNk6nAA7yeAM7kdmgIDbjgOC8gZXl7xQTj6OrwEPTbhv4OXjJhkC fvnaVyEktJWJ2lPhhSK823fU0RIvzZlW8k5NaVd0KqiAiYZnWhIsT4+r1jsyCLygtjP1 sbFBlEgg0DSSnQnIsYLiXHU2Sn/fdcb4ms/stWO1nAISiE3zcCxTmC5fINv4pqNWKdRo jxMe1eJvGK772AF6qy1Uapp2lNOIwxywpdIC4g8ySL/t5o/EBZA8ORTruK22JwpMnnP/ JsoSuaYIVFHVs+iYd+96FjMM0iLr5wJ/Gdv1F9CtwJ598U5E+AVJoOw8LpuHd4xdRcW1 TPKQ== 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=PMWeELwN2wO6NhCjsBKzQYjfQvJVOGB+Cb+lkqyEBh8=; b=GHrpxgMaX2akNmL1aVkMUU4F+9XTCI9N5xlFrYeq2R7QiAKjMtczA7zy5WHzhY3jp8 pzxYPWpl0wxFY4WKMTJPJo3UY5N2C7i3DEf4PhbmK3GBTuNgcvXnc8Jnef9XziHeFVuy 55zpsK4M5jig89VnqgTVexEOimAWRZWCqLy06OkGvdbnL9gIjodsyLZP7LoBs8qWbE3N YjGHhrmwMu4g9mRQcgw2WVEOuV27eFcrC+kmRqXvFuWMEJ9YLel/LjkbkX977dNuclJr DznqpAdq2+hwDhVAlE09HplYyyx+G7Zl+m6IiYihJeXAGo+l6hPqqJW6PTvUGRSPg67V eMkQ== X-Gm-Message-State: ALQs6tB+UWkKZ6I1W15nFdUNVJ9zVcCESUHLtOYvI/Jg/0XBp125aYk9 7Sen9hHbKvCHVg/X5oi/X1MT8AsXabRWjIziP/g= X-Received: by 10.176.19.3 with SMTP id g3mr14694689uae.140.1524466222850; Sun, 22 Apr 2018 23:50:22 -0700 (PDT) MIME-Version: 1.0 Received: by 10.176.92.86 with HTTP; Sun, 22 Apr 2018 23:49:42 -0700 (PDT) In-Reply-To: <20180420080313.18796-14-hch@lst.de> References: <20180420080313.18796-1-hch@lst.de> <20180420080313.18796-14-hch@lst.de> From: Greentime Hu Date: Mon, 23 Apr 2018 14:49:42 +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-20 16:03 GMT+08:00 Christoph Hellwig : > Switch to the generic noncoherent direct mapping implementation. > > This makes sure kmap_atomic_pfn is consistently used for access to > virtual addresses instead of either using the slower plain kmap > or blindly expecting page_address() to work. > > 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, 39 insertions(+), 161 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..688f1a03dee6 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,43 @@ 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) > -{ > - 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) > +void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr, > + size_t size, enum dma_data_direction dir) > { > - 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 = kmap_atomic_pfn(PHYS_PFN(paddr)); > + unsigned long start = (unsigned long)addr; > + > + switch (direction) { > + 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) > -{ > - 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); > - } > - } > - return nents; > -} > - > -static void nds32_dma_unmap_sg(struct device *dev, struct scatterlist *sg, > - int nhwentries, enum dma_data_direction dir, > - unsigned long attrs) > -{ > + kunmap_atomic(addr); > } > > -static void > -nds32_dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle, > - size_t size, enum dma_data_direction dir) > +void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr, > + 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); > + void *addr = kmap_atomic_pfn(PHYS_PFN(paddr)); > + unsigned long start = (unsigned long)addr; > + > + switch (direction) { > + case DMA_TO_DEVICE: > + break; > + case DMA_FROM_DEVICE: > + case DMA_BIDIRECTIONAL: > + cpu_dma_inval_range(start, end); > + break; > + default: > + BUG(); > } CC arch/nds32/kernel/dma.o arch/nds32/kernel/dma.c: In function 'arch_sync_dma_for_device': arch/nds32/kernel/dma.c:333:10: error: 'direction' undeclared (first use in this function) switch (direction) { ^~~~~~~~~ arch/nds32/kernel/dma.c:333:10: note: each undeclared identifier is reported only once for each function it appears in arch/nds32/kernel/dma.c: In function 'arch_sync_dma_for_cpu': arch/nds32/kernel/dma.c:353:10: error: 'direction' undeclared (first use in this function) switch (direction) { ^~~~~~~~~ arch/nds32/kernel/dma.c:358:30: error: 'end' undeclared (first use in this function) cpu_dma_inval_range(start, end); ^~~ make[1]: *** [arch/nds32/kernel/dma.o] Error 1 make: *** [arch/nds32/kernel] Error 2 After this building error, the ftmac100.c driver is broken. Not sure what happened.