Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1509303imu; Mon, 5 Nov 2018 23:02:23 -0800 (PST) X-Google-Smtp-Source: AJdET5cJN0aAL0iyihPZpF4epwA5jSQQISmkD5p0jlq+Xl3Vb25FOGSuTpTcFW7i1tVsZH3U+iDD X-Received: by 2002:a17:902:598f:: with SMTP id p15-v6mr24992929pli.260.1541487743304; Mon, 05 Nov 2018 23:02:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541487743; cv=none; d=google.com; s=arc-20160816; b=QeXFb7nPTYbm7ppNmZZmkxXK4jy7MxR+y8k2wFwwedW2NOn7qYNHqRiQzQJkWnn27/ eZg7WYi8Ussd/u90o0ixrrSHPWeXXIrWQUTpZYyXjK6t4eS1o46IMfaifLIYLRbIWYCu +muDrD3DSp4/Osl3VkoPRaXfNK72U05FHZccULp8Oj24p+UGKsyg8VEm8P87DAKezjaq PuZtGI6uMplfDV4nLS+nCMa271alrERe0zQFlcD8d+IisyrP0pKKl2r/KOs5eWsin3I3 o6ohyVRJPqMPkWkoiqC3qqbYdObXicQuDj2TvSqaJzu8K3GLPM0Zt6kRFyTd1Ef+YyAX Tg4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=KPi20omL3q+0DevYt38oEYfEvChovPkB7GM/h4vpwaM=; b=TonKcTBbhwQ3rj0FuikQ7mlzwcXUrmvJ62Gr5OO6lU1rqHnvMJvlpm0Icvzkm8rMUx pJl7lmb32H8nnlnHIDC30eeBGK+el83aX5phG6izfR6vYn4TJJeSutE3NxPlc4fEd54p vDa0V8Rv0CYnYxgiyBp8Tt0oOxAlOJsKG4h/NShXgAmINP8bvNnIeqTP8eArQvl75g4q fpFhU8phxpb0Ys5LfuNneMdLfiVhef0W32M0+Fbdg/bLScgZG2vmA7LwOJPc2tK3uUwX ig7brYVJpUpPnwm94LHU+pX/Umz2eZNbCEVBHErjuSfT7hc7uGgEXQDjRWX7LmV0FbgI dzPQ== ARC-Authentication-Results: i=1; mx.google.com; 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 y73si32933375pgd.478.2018.11.05.23.02.07; Mon, 05 Nov 2018 23:02:23 -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; 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 S2387579AbeKFQZd (ORCPT + 99 others); Tue, 6 Nov 2018 11:25:33 -0500 Received: from smtp2200-217.mail.aliyun.com ([121.197.200.217]:49870 "EHLO smtp2200-217.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387469AbeKFQZd (ORCPT ); Tue, 6 Nov 2018 11:25:33 -0500 X-Alimail-AntiSpam: AC=CONTINUE;BC=0.07437118|-1;CH=green;FP=0|0|0|0|0|-1|-1|-1;HT=e01e01534;MF=ren_guo@c-sky.com;NM=1;PH=DS;RN=8;RT=8;SR=0;TI=SMTPD_---.DECBElK_1541487701; Received: from localhost(mailfrom:ren_guo@c-sky.com fp:SMTPD_---.DECBElK_1541487701) by smtp.aliyun-inc.com(10.147.41.120); Tue, 06 Nov 2018 15:01:41 +0800 Date: Tue, 6 Nov 2018 15:01:41 +0800 From: Guo Ren To: Christoph Hellwig Cc: iommu@lists.linux-foundation.org, Robin Murphy , Catalin Marinas , Will Deacon , Laura Abbott , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 9/9] csky: use the generic remapping dma alloc implementation Message-ID: <20181106070140.GA6232@guoren-Inspiron-7460> References: <20181105121931.13481-1-hch@lst.de> <20181105121931.13481-10-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181105121931.13481-10-hch@lst.de> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 05, 2018 at 01:19:31PM +0100, Christoph Hellwig wrote: > The csky code was largely copied from arm/arm64, so switch to the > generic arm64-based implementation instead. > > Signed-off-by: Christoph Hellwig > --- > arch/csky/Kconfig | 2 +- > arch/csky/mm/dma-mapping.c | 142 +------------------------------------ > 2 files changed, 3 insertions(+), 141 deletions(-) > > diff --git a/arch/csky/Kconfig b/arch/csky/Kconfig > index c0cf8e948821..ea74f3a9eeaf 100644 > --- a/arch/csky/Kconfig > +++ b/arch/csky/Kconfig > @@ -8,7 +8,7 @@ config CSKY > select CLKSRC_MMIO > select CLKSRC_OF > select DMA_DIRECT_OPS > - select DMA_REMAP > + select DMA_DIRECT_REMAP > select IRQ_DOMAIN > select HANDLE_DOMAIN_IRQ > select DW_APB_TIMER_OF > diff --git a/arch/csky/mm/dma-mapping.c b/arch/csky/mm/dma-mapping.c > index ad4046939713..80783bb71c5c 100644 > --- a/arch/csky/mm/dma-mapping.c > +++ b/arch/csky/mm/dma-mapping.c > @@ -14,73 +14,13 @@ > #include > #include > > -static struct gen_pool *atomic_pool; > -static size_t atomic_pool_size __initdata = SZ_256K; > - > -static int __init early_coherent_pool(char *p) > -{ > - atomic_pool_size = memparse(p, &p); > - return 0; > -} > -early_param("coherent_pool", early_coherent_pool); > - > static int __init atomic_pool_init(void) > { > - struct page *page; > - size_t size = atomic_pool_size; > - void *ptr; > - int ret; > - > - atomic_pool = gen_pool_create(PAGE_SHIFT, -1); > - if (!atomic_pool) > - BUG(); > - > - page = alloc_pages(GFP_KERNEL, get_order(size)); > - if (!page) > - BUG(); > - > - ptr = dma_common_contiguous_remap(page, size, VM_ALLOC, > - pgprot_noncached(PAGE_KERNEL), > - __builtin_return_address(0)); > - if (!ptr) > - BUG(); > - > - ret = gen_pool_add_virt(atomic_pool, (unsigned long)ptr, > - page_to_phys(page), atomic_pool_size, -1); > - if (ret) > - BUG(); > - > - gen_pool_set_algo(atomic_pool, gen_pool_first_fit_order_align, NULL); > - > - pr_info("DMA: preallocated %zu KiB pool for atomic coherent pool\n", > - atomic_pool_size / 1024); > - > - pr_info("DMA: vaddr: 0x%x phy: 0x%lx,\n", (unsigned int)ptr, > - page_to_phys(page)); > - > - return 0; > + return dma_atomic_pool_init(GFP_KERNEL, pgprot_noncached(PAGE_KERNEL)); > } > postcore_initcall(atomic_pool_init); Seems also could remove atomic_pool_init from csky, why not put them in common? > > -static void *csky_dma_alloc_atomic(struct device *dev, size_t size, > - dma_addr_t *dma_handle) > -{ > - unsigned long addr; > - > - addr = gen_pool_alloc(atomic_pool, size); > - if (addr) > - *dma_handle = gen_pool_virt_to_phys(atomic_pool, addr); > - > - return (void *)addr; > -} > - > -static void csky_dma_free_atomic(struct device *dev, size_t size, void *vaddr, > - dma_addr_t dma_handle, unsigned long attrs) > -{ > - gen_pool_free(atomic_pool, (unsigned long)vaddr, size); > -} > - > -static void __dma_clear_buffer(struct page *page, size_t size) > +void arch_dma_prep_coherent(struct page *page, size_t size) > { > if (PageHighMem(page)) { > unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT; > @@ -107,84 +47,6 @@ static void __dma_clear_buffer(struct page *page, size_t size) > } > } > > -static void *csky_dma_alloc_nonatomic(struct device *dev, size_t size, > - dma_addr_t *dma_handle, gfp_t gfp, > - unsigned long attrs) > -{ > - void *vaddr; > - struct page *page; > - unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT; > - > - if (DMA_ATTR_NON_CONSISTENT & attrs) { > - pr_err("csky %s can't support DMA_ATTR_NON_CONSISTENT.\n", __func__); > - return NULL; > - } > - > - if (IS_ENABLED(CONFIG_DMA_CMA)) > - page = dma_alloc_from_contiguous(dev, count, get_order(size), > - gfp); > - else > - page = alloc_pages(gfp, get_order(size)); > - > - if (!page) { > - pr_err("csky %s no more free pages.\n", __func__); > - return NULL; > - } > - > - *dma_handle = page_to_phys(page); > - > - __dma_clear_buffer(page, size); > - > - if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) > - return page; > - > - vaddr = dma_common_contiguous_remap(page, PAGE_ALIGN(size), VM_USERMAP, > - pgprot_noncached(PAGE_KERNEL), __builtin_return_address(0)); > - if (!vaddr) > - BUG(); > - > - return vaddr; > -} > - > -static void csky_dma_free_nonatomic( > - struct device *dev, > - size_t size, > - void *vaddr, > - dma_addr_t dma_handle, > - unsigned long attrs > - ) > -{ > - struct page *page = phys_to_page(dma_handle); > - unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT; > - > - if ((unsigned int)vaddr >= VMALLOC_START) > - dma_common_free_remap(vaddr, size, VM_USERMAP); > - > - if (IS_ENABLED(CONFIG_DMA_CMA)) > - dma_release_from_contiguous(dev, page, count); > - else > - __free_pages(page, get_order(size)); > -} > - > -void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, > - gfp_t gfp, unsigned long attrs) > -{ > - if (gfpflags_allow_blocking(gfp)) > - return csky_dma_alloc_nonatomic(dev, size, dma_handle, gfp, > - attrs); > - else > - return csky_dma_alloc_atomic(dev, size, dma_handle); > -} > - > -void arch_dma_free(struct device *dev, size_t size, void *vaddr, > - dma_addr_t dma_handle, unsigned long attrs) > -{ > - if (!addr_in_gen_pool(atomic_pool, (unsigned int) vaddr, size)) > - csky_dma_free_nonatomic(dev, size, vaddr, dma_handle, attrs); > - else > - csky_dma_free_atomic(dev, size, vaddr, dma_handle, attrs); > -} > - > static inline void cache_op(phys_addr_t paddr, size_t size, > void (*fn)(unsigned long start, unsigned long end)) > { > -- > 2.19.1 Reviewed-by: Guo Ren Compile is OK, qemu boot OK. Functions are the same and just move to common. Looks good for me. Guo Ren