Received: by 10.192.165.148 with SMTP id m20csp414995imm; Fri, 20 Apr 2018 01:10:51 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/PIC4ZhXH5gm/acb83nkyck3AHmixEDFS9K2YPDlHbZXWbFxpMkV+r4ArQa2WMgmy7vHll X-Received: by 10.98.52.193 with SMTP id b184mr4803239pfa.178.1524211851891; Fri, 20 Apr 2018 01:10:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524211851; cv=none; d=google.com; s=arc-20160816; b=W+cBsx2/28OAHDs7aad4GW4w049j3Nwg911gmJyXkB0BqHyPovOB/+6CQ10vZ2q8lV Ba+ukBAGQBXveLc4Hdxa4hakljThrOKY5dYc8OVQt/WHj9cu+FVs72cJukjXC0G+unWq EsRBUoXI1mTwey1Dbcqyi+M4oYHVCtarqHOSQErar77woKuqcF8I6wl0VvgBH+AuM1x8 bigAI6DswJPm05rtSiK0gaDAdJXDXhUKfPs8MmeT7Pi++fGjqs4OWqeA25lsD2aAJ6Lf knxi84rQbkvo1/nRuL6NIti+lKnPv413G9N+61YsPOa7Nbudmaj1EReDKYlM2U7QcjN8 qVZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:in-reply-to:message-id:date :subject:cc:from:dkim-signature:arc-authentication-results; bh=ArzbOtkYTANRsiGaXx5Yvjmfb5lT2+rt7trPCUU+OVk=; b=qW/K8n+8hxC1a0Abj5T49ekd+PYJ6OFu1vU9VkV19dMCDaEWxYy/kFu9uH/iI2IORA DbHgDxu6xbSYrlrucNI8kwDg7k6EndGQIg9c1dlXLEyIzxYNzgiUjr3zk55lOM6QLt8j 2wVbOAJUTrqjJzXInaDHxL/d9q89894zqEHLtUOb1J/GsRW+rG9GzAOViDYPcSw5Puih zRj1i+AFqW/75fT9XokOy1ir9z8WnklEcPnKMyyon9iQgMeTKa8KrC18sL3FaU3wuR2S QVlBRqH4p+9+1zvo5Mseai1chJPmNQOZKRdShzU1Ed4Dwp7obINTN8tCc2S/Y8TxEddi suJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=PVTNWesq; 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 b3-v6si5077334pla.505.2018.04.20.01.10.37; Fri, 20 Apr 2018 01:10:51 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=PVTNWesq; 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 S1754384AbeDTIJ3 (ORCPT + 99 others); Fri, 20 Apr 2018 04:09:29 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:40538 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754283AbeDTIEn (ORCPT ); Fri, 20 Apr 2018 04:04:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding: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=ArzbOtkYTANRsiGaXx5Yvjmfb5lT2+rt7trPCUU+OVk=; b=PVTNWesqfDHaJySZWAR7CMyMh Vohr4tvd0CYt32KJyEsBe96IpJZR4MlrPpnHIgTxcIz24S4u4ipoJSW+EhR7QJ4nddKiTAsS7nURn 1lsX7YwoIGz5FHE2E0L+Ih9Nv69fTLcsfJmdYkDpQFL9oDUsxJpBq/QxTj+CakA2Rsage0jsO6iAN B8/bwm48kc519NDu03AWZu0CJtvQKhYylep77NjRo4cYP0K8kGVeai1DH/Ipdep17L8hsnckDdEs/ 1t4N14OZcNv9oQhqExs3SIEHZE6Rtd4FCRlD21QWqXQTZCH5u8az8O7t3rDo/9kGI6N5HropS+iOe lP6wSlmLA==; Received: from static-242-42-24-46.ipcom.comunitel.net ([46.24.42.242] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1f9R1c-0007cw-IG; Fri, 20 Apr 2018 08:04:09 +0000 From: Christoph Hellwig Cc: linux-arch@vger.kernel.org, Michal Simek , Greentime Hu , 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@vger.kernel.org, linux-xtensa@linux-xtensa.org, linux-kernel@vger.kernel.org Subject: [PATCH 15/22] openrisc: use generic dma_noncoherent_ops Date: Fri, 20 Apr 2018 10:03:06 +0200 Message-Id: <20180420080313.18796-16-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180420080313.18796-1-hch@lst.de> References: <20180420080313.18796-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Switch to the generic noncoherent direct mapping implementation. Fix sync_single_for_device to do the same cache coherency operations as the more tested map_single path, as both should transfer ownership to the device. Remove the sync_single_for_cpu implementation as no cache coherency operations are used in the more commonly used unmap_single case, both of which transfer ownership to the CPU. Implement the missing sync_sg_for_device operation, matching the cache coherency operations in sync_single_for_device and map_{single,sg}. Signed-off-by: Christoph Hellwig --- arch/openrisc/Kconfig | 2 + arch/openrisc/include/asm/Kbuild | 1 + arch/openrisc/include/asm/dma-mapping.h | 35 -------- arch/openrisc/kernel/dma.c | 109 +++--------------------- 4 files changed, 13 insertions(+), 134 deletions(-) delete mode 100644 arch/openrisc/include/asm/dma-mapping.h diff --git a/arch/openrisc/Kconfig b/arch/openrisc/Kconfig index 9ecad05bfc73..65e3c574c9d3 100644 --- a/arch/openrisc/Kconfig +++ b/arch/openrisc/Kconfig @@ -6,6 +6,8 @@ config OPENRISC def_bool y + select ARCH_HAS_SYNC_DMA_FOR_DEVICE + select DMA_NONCOHERENT_OPS select OF select OF_EARLY_FLATTREE select IRQ_DOMAIN diff --git a/arch/openrisc/include/asm/Kbuild b/arch/openrisc/include/asm/Kbuild index f05c722a21f8..e663a996b612 100644 --- a/arch/openrisc/include/asm/Kbuild +++ b/arch/openrisc/include/asm/Kbuild @@ -6,6 +6,7 @@ generic-y += current.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 += exec.h generic-y += extable.h diff --git a/arch/openrisc/include/asm/dma-mapping.h b/arch/openrisc/include/asm/dma-mapping.h deleted file mode 100644 index e212a1f0b6d2..000000000000 --- a/arch/openrisc/include/asm/dma-mapping.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * OpenRISC Linux - * - * Linux architectural port borrowing liberally from similar works of - * others. All original copyrights apply as per the original source - * declaration. - * - * OpenRISC implementation: - * Copyright (C) 2010-2011 Jonas Bonn - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - */ - -#ifndef __ASM_OPENRISC_DMA_MAPPING_H -#define __ASM_OPENRISC_DMA_MAPPING_H - -/* - * See Documentation/DMA-API-HOWTO.txt and - * Documentation/DMA-API.txt for documentation. - */ - -#include -#include - -extern const struct dma_map_ops or1k_dma_map_ops; - -static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus) -{ - return &or1k_dma_map_ops; -} - -#endif /* __ASM_OPENRISC_DMA_MAPPING_H */ diff --git a/arch/openrisc/kernel/dma.c b/arch/openrisc/kernel/dma.c index ec7fd45704d2..cce99405edf4 100644 --- a/arch/openrisc/kernel/dma.c +++ b/arch/openrisc/kernel/dma.c @@ -19,9 +19,7 @@ * the only thing implemented properly. The rest need looking into... */ -#include -#include -#include +#include #include #include @@ -80,10 +78,9 @@ page_clear_nocache(pte_t *pte, unsigned long addr, * is being ignored for now; uncached but write-combined memory is a * missing feature of the OR1K. */ -static void * -or1k_dma_alloc(struct device *dev, size_t size, - dma_addr_t *dma_handle, gfp_t gfp, - unsigned long attrs) +void * +arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, + gfp_t gfp, unsigned long attrs) { unsigned long va; void *page; @@ -115,9 +112,9 @@ or1k_dma_alloc(struct device *dev, size_t size, return (void *)va; } -static void -or1k_dma_free(struct device *dev, size_t size, void *vaddr, - dma_addr_t dma_handle, unsigned long attrs) +void +arch_dma_free(struct device *dev, size_t size, void *vaddr, + dma_addr_t dma_handle, unsigned long attrs) { unsigned long va = (unsigned long)vaddr; struct mm_walk walk = { @@ -133,18 +130,11 @@ or1k_dma_free(struct device *dev, size_t size, void *vaddr, free_pages_exact(vaddr, size); } -static dma_addr_t -or1k_map_page(struct device *dev, struct page *page, - unsigned long offset, size_t size, - enum dma_data_direction dir, - unsigned long attrs) +void arch_sync_dma_for_device(struct device *dev, phys_addr_t addr, size_t size, + enum dma_data_direction dir) { - unsigned long cl; - dma_addr_t addr = page_to_phys(page) + offset; struct cpuinfo_or1k *cpuinfo = &cpuinfo_or1k[smp_processor_id()]; - - if (attrs & DMA_ATTR_SKIP_CPU_SYNC) - return addr; + unsigned long cl; switch (dir) { case DMA_TO_DEVICE: @@ -167,83 +157,4 @@ or1k_map_page(struct device *dev, struct page *page, */ break; } - - return addr; } - -static void -or1k_unmap_page(struct device *dev, dma_addr_t dma_handle, - size_t size, enum dma_data_direction dir, - unsigned long attrs) -{ - /* Nothing special to do here... */ -} - -static int -or1k_map_sg(struct device *dev, struct scatterlist *sg, - int nents, enum dma_data_direction dir, - unsigned long attrs) -{ - struct scatterlist *s; - int i; - - for_each_sg(sg, s, nents, i) { - s->dma_address = or1k_map_page(dev, sg_page(s), s->offset, - s->length, dir, 0); - } - - return nents; -} - -static void -or1k_unmap_sg(struct device *dev, struct scatterlist *sg, - int nents, enum dma_data_direction dir, - unsigned long attrs) -{ - struct scatterlist *s; - int i; - - for_each_sg(sg, s, nents, i) { - or1k_unmap_page(dev, sg_dma_address(s), sg_dma_len(s), dir, 0); - } -} - -static void -or1k_sync_single_for_cpu(struct device *dev, - dma_addr_t dma_handle, size_t size, - enum dma_data_direction dir) -{ - unsigned long cl; - dma_addr_t addr = dma_handle; - struct cpuinfo_or1k *cpuinfo = &cpuinfo_or1k[smp_processor_id()]; - - /* Invalidate the dcache for the requested range */ - for (cl = addr; cl < addr + size; cl += cpuinfo->dcache_block_size) - mtspr(SPR_DCBIR, cl); -} - -static void -or1k_sync_single_for_device(struct device *dev, - dma_addr_t dma_handle, size_t size, - enum dma_data_direction dir) -{ - unsigned long cl; - dma_addr_t addr = dma_handle; - struct cpuinfo_or1k *cpuinfo = &cpuinfo_or1k[smp_processor_id()]; - - /* Flush the dcache for the requested range */ - for (cl = addr; cl < addr + size; cl += cpuinfo->dcache_block_size) - mtspr(SPR_DCBFR, cl); -} - -const struct dma_map_ops or1k_dma_map_ops = { - .alloc = or1k_dma_alloc, - .free = or1k_dma_free, - .map_page = or1k_map_page, - .unmap_page = or1k_unmap_page, - .map_sg = or1k_map_sg, - .unmap_sg = or1k_unmap_sg, - .sync_single_for_cpu = or1k_sync_single_for_cpu, - .sync_single_for_device = or1k_sync_single_for_device, -}; -EXPORT_SYMBOL(or1k_dma_map_ops); -- 2.17.0