Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp591940imm; Wed, 25 Jul 2018 02:42:19 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeawuZAvex3f53AjSn7Th4aMcNfqF7vJvzS7Yok3IXQehza06cD6n5kVENMChJi1NEYWE42 X-Received: by 2002:a63:82c7:: with SMTP id w190-v6mr19775040pgd.253.1532511739827; Wed, 25 Jul 2018 02:42:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532511739; cv=none; d=google.com; s=arc-20160816; b=HU/GPwVAxPfsiJzNtRRrx1fUpmFa4WDPiiZUdpb6Rklqdy8Gd+ChSRVbctbKQr4KsD wpjDGb1JXnmteC/uPUahO1XeP3maHe3kDs3mZ95XUFTwsiGTtcmMIF2lJXnuItErnUyE d4o9Cida5XrEwto0UaWnGyCJtaMD4W7xLKBbI9KpwuPpd5wMdtRyJVoimfxHU5of0wSr h3DXseanLiF9fqXLWH9KdcGKK4K1qliIFtMXmm/kiWys6Y9RALxAbDnyyV3qf9m70bFd cYUTU/Qn+z8Iq5CtTMviAnEf6tzgsYMFVCRdXFtW47gIBGQr4fE5XPSYi5wwzIeduFFb sXug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=YwKminqdyYJqg4zlyStqJH0xOnOcrhypADGgJ9kmgGk=; b=i/5jxM2SQFVVQTtag3M6qtxP1vjQyQC96Ih0xuNrZtRneLXcDuqFFFEvUNemwLOSEv KCd+SuWo5cMKHc7Gk3UL8TTTuIziH51mTvnDKA2ASbyYZYZnLgBscykNTbF8X+/c1RCL 124mY6AL5h1oCPjMTfKY2p3w5on6V+xaLU6jbwAkE7Tht3MnjsjlJr1TXYgtQg5t6dz3 S+aaZ7P0hn1eOdMCud0nNg25wRwtNl50yNtIfhXo9sqVNSCPnprloEkuzkiJ3qoZMzer n8snKIvkfEMWjK7FMCd44JMRKYd9XTiQc3X3xxdlVn4vyHkff+dGcLDj23MTTwCg47+D Wwiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="Sf/hvBka"; 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 l6-v6si13590879pgl.567.2018.07.25.02.42.04; Wed, 25 Jul 2018 02:42:19 -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="Sf/hvBka"; 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 S1728817AbeGYKwB (ORCPT + 99 others); Wed, 25 Jul 2018 06:52:01 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:43538 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728694AbeGYKwB (ORCPT ); Wed, 25 Jul 2018 06:52:01 -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=YwKminqdyYJqg4zlyStqJH0xOnOcrhypADGgJ9kmgGk=; b=Sf/hvBkaJGIucNj3/jMLJrecn nem+461ve5hmktR3gfjNk14Ka26hCQzTJTk7UPX30swRpwlVsmKzjSdZB2ZiqxqZIpGo+7xSQ4RhQ Bn+X265CF8qT8aS5r7zeDhsO/+HoCUgsQeXkPa2T8i9S37hyLQQeSEmsXQulNCP14KJPlfWk75Vve jY952R8KlWVOFUCMta3OVM9Dn9vz3ZEJwWh7KjMOn1VNqDa2XBsiEikI2Qlm+qtNFRDpn9atIdBB6 V+b1h7DewSQEjTLDTM6TsSr2vUgtYb/Fs6s19VMvW58bbknSE2aOl9H9COeyn6sj21Hsx+dHb9Uz+ 2wZ9C02tw==; Received: from [91.112.108.175] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fiGHx-0007TM-S5; Wed, 25 Jul 2018 09:40:58 +0000 From: Christoph Hellwig To: Yoshinori Sato , Rich Felker Cc: Jacopo Mondi , Thomas Petazzoni , linux-sh@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] sh: split arch/sh/mm/consistent.c Date: Wed, 25 Jul 2018 11:40:42 +0200 Message-Id: <20180725094043.32443-5-hch@lst.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180725094043.32443-1-hch@lst.de> References: <20180725094043.32443-1-hch@lst.de> 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 Half of the file just contains platform device memory setup code which is required for all builds, and half contains helpers for dma coherent allocation, which is only needed if CONFIG_DMA_NONCOHERENT is enabled. Signed-off-by: Christoph Hellwig --- arch/sh/kernel/Makefile | 2 +- arch/sh/kernel/dma-coherent.c | 84 +++++++++++++++++++++++++++++++++++ arch/sh/mm/consistent.c | 80 --------------------------------- 3 files changed, 85 insertions(+), 81 deletions(-) create mode 100644 arch/sh/kernel/dma-coherent.c diff --git a/arch/sh/kernel/Makefile b/arch/sh/kernel/Makefile index cb5f1bfb52de..d5ddb64bfffe 100644 --- a/arch/sh/kernel/Makefile +++ b/arch/sh/kernel/Makefile @@ -45,7 +45,7 @@ obj-$(CONFIG_DUMP_CODE) += disassemble.o obj-$(CONFIG_HIBERNATION) += swsusp.o obj-$(CONFIG_DWARF_UNWINDER) += dwarf.o obj-$(CONFIG_PERF_EVENTS) += perf_event.o perf_callchain.o -obj-$(CONFIG_DMA_NONCOHERENT) += dma-nommu.o +obj-$(CONFIG_DMA_NONCOHERENT) += dma-nommu.o dma-coherent.o obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o ccflags-y := -Werror diff --git a/arch/sh/kernel/dma-coherent.c b/arch/sh/kernel/dma-coherent.c new file mode 100644 index 000000000000..2518065d5d27 --- /dev/null +++ b/arch/sh/kernel/dma-coherent.c @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2004 - 2007 Paul Mundt + * + * This file is subject to the terms and conditions of the GNU General Public + * License. See the file "COPYING" in the main directory of this archive + * for more details. + */ +#include +#include +#include +#include +#include +#include + +void *dma_generic_alloc_coherent(struct device *dev, size_t size, + dma_addr_t *dma_handle, gfp_t gfp, + unsigned long attrs) +{ + void *ret, *ret_nocache; + int order = get_order(size); + + gfp |= __GFP_ZERO; + + ret = (void *)__get_free_pages(gfp, order); + if (!ret) + return NULL; + + /* + * Pages from the page allocator may have data present in + * cache. So flush the cache before using uncached memory. + */ + sh_sync_dma_for_device(ret, size, DMA_BIDIRECTIONAL); + + ret_nocache = (void __force *)ioremap_nocache(virt_to_phys(ret), size); + if (!ret_nocache) { + free_pages((unsigned long)ret, order); + return NULL; + } + + split_page(pfn_to_page(virt_to_phys(ret) >> PAGE_SHIFT), order); + + *dma_handle = virt_to_phys(ret); + if (!WARN_ON(!dev)) + *dma_handle -= PFN_PHYS(dev->dma_pfn_offset); + + return ret_nocache; +} + +void dma_generic_free_coherent(struct device *dev, size_t size, + void *vaddr, dma_addr_t dma_handle, + unsigned long attrs) +{ + int order = get_order(size); + unsigned long pfn = (dma_handle >> PAGE_SHIFT); + int k; + + if (!WARN_ON(!dev)) + pfn += dev->dma_pfn_offset; + + for (k = 0; k < (1 << order); k++) + __free_pages(pfn_to_page(pfn + k), 0); + + iounmap(vaddr); +} + +void sh_sync_dma_for_device(void *vaddr, size_t size, + enum dma_data_direction direction) +{ + void *addr = sh_cacheop_vaddr(vaddr); + + switch (direction) { + case DMA_FROM_DEVICE: /* invalidate only */ + __flush_invalidate_region(addr, size); + break; + case DMA_TO_DEVICE: /* writeback only */ + __flush_wback_region(addr, size); + break; + case DMA_BIDIRECTIONAL: /* writeback and invalidate */ + __flush_purge_region(addr, size); + break; + default: + BUG(); + } +} diff --git a/arch/sh/mm/consistent.c b/arch/sh/mm/consistent.c index 1622ae6b9dbd..792f36129062 100644 --- a/arch/sh/mm/consistent.c +++ b/arch/sh/mm/consistent.c @@ -1,10 +1,6 @@ /* - * arch/sh/mm/consistent.c - * * Copyright (C) 2004 - 2007 Paul Mundt * - * Declared coherent memory functions based on arch/x86/kernel/pci-dma_32.c - * * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. @@ -13,83 +9,7 @@ #include #include #include -#include #include -#include -#include -#include -#include - -void *dma_generic_alloc_coherent(struct device *dev, size_t size, - dma_addr_t *dma_handle, gfp_t gfp, - unsigned long attrs) -{ - void *ret, *ret_nocache; - int order = get_order(size); - - gfp |= __GFP_ZERO; - - ret = (void *)__get_free_pages(gfp, order); - if (!ret) - return NULL; - - /* - * Pages from the page allocator may have data present in - * cache. So flush the cache before using uncached memory. - */ - sh_sync_dma_for_device(ret, size, DMA_BIDIRECTIONAL); - - ret_nocache = (void __force *)ioremap_nocache(virt_to_phys(ret), size); - if (!ret_nocache) { - free_pages((unsigned long)ret, order); - return NULL; - } - - split_page(pfn_to_page(virt_to_phys(ret) >> PAGE_SHIFT), order); - - *dma_handle = virt_to_phys(ret); - if (!WARN_ON(!dev)) - *dma_handle -= PFN_PHYS(dev->dma_pfn_offset); - - return ret_nocache; -} - -void dma_generic_free_coherent(struct device *dev, size_t size, - void *vaddr, dma_addr_t dma_handle, - unsigned long attrs) -{ - int order = get_order(size); - unsigned long pfn = dma_handle >> PAGE_SHIFT; - int k; - - if (!WARN_ON(!dev)) - pfn += dev->dma_pfn_offset; - - for (k = 0; k < (1 << order); k++) - __free_pages(pfn_to_page(pfn + k), 0); - - iounmap(vaddr); -} - -void sh_sync_dma_for_device(void *vaddr, size_t size, - enum dma_data_direction direction) -{ - void *addr = sh_cacheop_vaddr(vaddr); - - switch (direction) { - case DMA_FROM_DEVICE: /* invalidate only */ - __flush_invalidate_region(addr, size); - break; - case DMA_TO_DEVICE: /* writeback only */ - __flush_wback_region(addr, size); - break; - case DMA_BIDIRECTIONAL: /* writeback and invalidate */ - __flush_purge_region(addr, size); - break; - default: - BUG(); - } -} static int __init memchunk_setup(char *str) { -- 2.18.0