Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp490036imu; Mon, 5 Nov 2018 04:20:56 -0800 (PST) X-Google-Smtp-Source: AJdET5ecZQtVisIwzJba7EcWKsrSkAdMGMp26Miimm65eSRifSdK4QCC/ttNoceCRpsyan9x7lgV X-Received: by 2002:a17:902:4481:: with SMTP id l1-v6mr21551851pld.123.1541420456191; Mon, 05 Nov 2018 04:20:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541420456; cv=none; d=google.com; s=arc-20160816; b=TReevTuKr9QHF00vBCq4RoxyUhgiKfy2p+pwj+sSxnQnqXnkv3bb3jgxVfYXhaZQfx anOIZ4Fc0xr34Q320/xdmTyLlEHq1IL11i72FRSARJl7Vj5BMxCb8jooSIPP9CjpH61j G1VtJULjH+vGQRcxot1c1+NWfkY+7OFOb1TogAifrXF23F9ovyyyqb6dR6NxpuYnCSCS n4Q9gEHrAfDG8SXyFOaOY2nWz1AqrRcVUd+wmipco8Ph3ITMsrn6Fz0zHv5J5B3syyMW THCgmLslqKwSYrEroXEUVfh4Uay+LDICnviWBm/hE2ynnARmZYfny4fjukx/DP0CJ1lK 7nCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WtOoQACujRoeqRVMfwffW62gslMl1Yjj0c8jJ+sQtQU=; b=q0nwv/M7B7pSEAddeCDicCtak/lIhzjS7Bbs24vb35/sZcQTOXE9LFs8+StQo6758O Esn41kc07SghtYK2vN9r5TX836hcOr+fqHsylDfd7clGczLChwb1e8C7UFHr9OGlZLdH 0PH6BlhBVBvM+6PIFIacOn2A0WmOcKHYN2SgPFwq5yWdsopVMaZLw47GcOwcJIQdkqRc fPLrlIGHBb6j3opQdpc5ViA5UnP7wR/yIhfGo5R+FQd7OgEdRCNW22X1L1/n0FbnD3NB y3t4sJhpQYlVWpALTwHsS1O/jpJxglvojKccuHZC40lwrxjhS7AvL5NRMEk4+mW8jWl8 sPEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=RlVLDzmi; 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 u189-v6si46593496pfu.263.2018.11.05.04.20.41; Mon, 05 Nov 2018 04:20: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=@infradead.org header.s=bombadil.20170209 header.b=RlVLDzmi; 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 S1729794AbeKEVji (ORCPT + 99 others); Mon, 5 Nov 2018 16:39:38 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:44116 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726358AbeKEVjh (ORCPT ); Mon, 5 Nov 2018 16:39:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=WtOoQACujRoeqRVMfwffW62gslMl1Yjj0c8jJ+sQtQU=; b=RlVLDzmierUCy/UJanBS270nwr 4mjFpOJxGAyBq1OCuXopBx+uSTEh+NLN0MugWESEDwNbq0iEqJ+qBiv4WrApasB/1F1tRJLCxNrUd lEwPLIyJguOBVGTP/RN7wVDoAJy1c5MrWg4jpEzSEq7PBXu9Fz2L0kxGo9Zu7o+5SfvfbBr+mTY+o huGHrq9q4nmQHcmcJrWM2lJ9rU/4Xsam6bPHTKW4bdBAVMBm5kChnbNDqf73LK03M6kgC5XzoyqVH OtqSbds39zu67mwweOOWJ8PIwD3K7hKMBoN0yr3H9Rd7JO1HAunXgn8pbvdliFA8P5nsNtdZWogfG j8frPT+A==; Received: from 213-225-37-95.nat.highway.a1.net ([213.225.37.95] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gJdrM-0003u3-TO; Mon, 05 Nov 2018 12:20:01 +0000 From: Christoph Hellwig To: iommu@lists.linux-foundation.org Cc: Robin Murphy , Catalin Marinas , Will Deacon , Guo Ren , Laura Abbott , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 9/9] csky: use the generic remapping dma alloc implementation Date: Mon, 5 Nov 2018 13:19:31 +0100 Message-Id: <20181105121931.13481-10-hch@lst.de> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181105121931.13481-1-hch@lst.de> References: <20181105121931.13481-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -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