Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp887501ybv; Thu, 20 Feb 2020 09:02:25 -0800 (PST) X-Google-Smtp-Source: APXvYqzJz5DAPHWpH84wwcavcL6zMz9Av/zGGw6pL+0jK0XwF+WS2cCEF8IovC8535WcAVYpouFi X-Received: by 2002:aca:dc45:: with SMTP id t66mr2873930oig.39.1582218145726; Thu, 20 Feb 2020 09:02:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582218145; cv=none; d=google.com; s=arc-20160816; b=Fb5eSZG+gASb/7TRPBgA1pVyoBFbwrM51eBvMBCONhx2r/Lu6yNEuF/SpgTdaXEdts cnO6EyKWEBW6jTDvVkbb/GDa7mo6MjbAUyms/v63KxparZRBj/YgRC19vMWZTe0fAdyk SAYHG8d4NKJEAnXDLUezGmAgGqgnoDg2ayTqv1iuZjNVHt1wh900W+eo+p7XOOjboUOR /eOCf3Trx0GwGpC9gz+XXfRa2PqqxNHIFRgg9QPw5dXeHtRMwyBD5jB9gdOcF44gkzrv LvcSvlUl6RlCbMZBhe4AGB0asJ4j4jljGyPvNvyxJpzJx7mEy90uyQCSEKLOyRI8AfWZ qFIw== 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=HtENtGXMu5lv8v2BETZ/HEIobwIkiHxnVtk2a6XxHoE=; b=a10k4tASDBTOyaw0OofIUPNsHC9kPW8Y+DnEVe/XHoL+asOxvygmhPL/OOG+uC+ehy SLpGKWglqhSKgeqNFLMpPC4NCJ6GHI42sBOmDJqUxMYQslLH2SKUNSCs9mydK0II3jej HNpP+IhPHXQT5ycQUpdfo9rh4TvD9yKY7CY+3mE5nVjllA6go1QZPYXAjvBr8eXVX8+7 xQaIps2SPLOMnUFJXhCklycy4ldDhCqVzF2uiC6P1DuUpvrcgGbBXJSuG88wXGiN0ZQW eDJUfygQtX94ZSstOYsHrZHgGTeGxulqdgq4ZptUscOXiZtokwh2s40WXGiB+bnxgXsf 5B6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=T5FBHWOl; 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 t26si10475808oic.169.2020.02.20.09.02.08; Thu, 20 Feb 2020 09:02:25 -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=T5FBHWOl; 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 S1728678AbgBTRB6 (ORCPT + 99 others); Thu, 20 Feb 2020 12:01:58 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:33252 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726959AbgBTRB5 (ORCPT ); Thu, 20 Feb 2020 12:01:57 -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; bh=HtENtGXMu5lv8v2BETZ/HEIobwIkiHxnVtk2a6XxHoE=; b=T5FBHWOl/1ly9t3RQlAFneq+LH znE7SnHgY6zEKFQuQFZUtOazi674gzMFHGtiQRguRPHKUpUbCoRszbOyCSWhkt5V4wSetu00nWMIj SDgv5AxVFpQcpDs+txdludIlKBFYOQM5UH4DDKtuJx3uUFq3HQs9y6EFsF2ibt/ltHLfYK5TuFuGb RlMbOcbURkAR2slWv5WKCiEA3XimfqMSpfvhYQoM2LMwGno23dRlU80vcUm8bl1QsE3T7jCGJVyHF 7Xk61JwG6k321wmvBIC0Nvxxm0md3oLioj7VFTWt/fxqpt0GInQM4j4s/G4tm7ygXDCIQP8LoIgV9 ib0EF5Dg==; Received: from [38.126.112.138] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1j4pCl-0000Dq-Og; Thu, 20 Feb 2020 17:01:39 +0000 From: Christoph Hellwig To: Jonas Bonn , Stefan Kristiansson , Stafford Horne Cc: Marek Szyprowski , Robin Murphy , Will Deacon , Mark Rutland , openrisc@lists.librecores.org, iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] openrisc: use the generic in-place uncached DMA allocator Date: Thu, 20 Feb 2020 09:01:39 -0800 Message-Id: <20200220170139.387354-3-hch@lst.de> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200220170139.387354-1-hch@lst.de> References: <20200220170139.387354-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 Switch openrisc to use the dma-direct allocator and just provide the hooks for setting memory uncached or cached. Signed-off-by: Christoph Hellwig --- arch/openrisc/Kconfig | 1 + arch/openrisc/kernel/dma.c | 51 +++++--------------------------------- 2 files changed, 7 insertions(+), 45 deletions(-) diff --git a/arch/openrisc/Kconfig b/arch/openrisc/Kconfig index 1928e061ff96..041fff4326dc 100644 --- a/arch/openrisc/Kconfig +++ b/arch/openrisc/Kconfig @@ -7,6 +7,7 @@ config OPENRISC def_bool y select ARCH_32BIT_OFF_T + select ARCH_HAS_DMA_SET_UNCACHED select ARCH_HAS_SYNC_DMA_FOR_DEVICE select OF select OF_EARLY_FLATTREE diff --git a/arch/openrisc/kernel/dma.c b/arch/openrisc/kernel/dma.c index adec711ad39d..c73d2b3ae267 100644 --- a/arch/openrisc/kernel/dma.c +++ b/arch/openrisc/kernel/dma.c @@ -11,8 +11,6 @@ * Copyright (C) 2010-2011 Jonas Bonn * * DMA mapping callbacks... - * As alloc_coherent is the only DMA callback being used currently, that's - * the only thing implemented properly. The rest need looking into... */ #include @@ -67,62 +65,25 @@ static const struct mm_walk_ops clear_nocache_walk_ops = { .pte_entry = page_clear_nocache, }; -/* - * Alloc "coherent" memory, which for OpenRISC means simply uncached. - * - * This function effectively just calls __get_free_pages, sets the - * cache-inhibit bit on those pages, and makes sure that the pages are - * flushed out of the cache before they are used. - * - * If the NON_CONSISTENT attribute is set, then this function just - * returns "normal", cachable memory. - * - * There are additional flags WEAK_ORDERING and WRITE_COMBINE to take - * into consideration here, too. All current known implementations of - * the OR1K support only strongly ordered memory accesses, so that flag - * is being ignored for now; uncached but write-combined memory is a - * missing feature of the OR1K. - */ -void * -arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, - gfp_t gfp, unsigned long attrs) +int arch_dma_set_uncached(void *cpu_addr, size_t size) { - unsigned long va; - void *page; - - page = alloc_pages_exact(size, gfp | __GFP_ZERO); - if (!page) - return NULL; - - /* This gives us the real physical address of the first page. */ - *dma_handle = __pa(page); - - va = (unsigned long)page; + unsigned long va = (unsigned long)cpu_addr; /* * We need to iterate through the pages, clearing the dcache for * them and setting the cache-inhibit bit. */ - if (walk_page_range(&init_mm, va, va + size, &set_nocache_walk_ops, - NULL)) { - free_pages_exact(page, size); - return NULL; - } - - return (void *)va; + return walk_page_range(&init_mm, va, va + size, &set_nocache_walk_ops, + NULL); } -void -arch_dma_free(struct device *dev, size_t size, void *vaddr, - dma_addr_t dma_handle, unsigned long attrs) +void arch_dma_clear_uncached(void *cpu_addr, size_t size) { - unsigned long va = (unsigned long)vaddr; + unsigned long va = (unsigned long)cpu_addr; /* walk_page_range shouldn't be able to fail here */ WARN_ON(walk_page_range(&init_mm, va, va + size, &clear_nocache_walk_ops, NULL)); - - free_pages_exact(vaddr, size); } void arch_sync_dma_for_device(phys_addr_t addr, size_t size, -- 2.24.1