From patchwork Mon Sep 20 11:31:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 1530051 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=GfoUICJz; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=sparclinux-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4HCj8T6m5Nz9sRN for ; Mon, 20 Sep 2021 21:32:25 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236976AbhITLdv (ORCPT ); Mon, 20 Sep 2021 07:33:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231279AbhITLdv (ORCPT ); Mon, 20 Sep 2021 07:33:51 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 773A4C061574 for ; Mon, 20 Sep 2021 04:32:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=G0bIwG0s0R5HmnXRdo1m5ugvyiGKA8hcIxeIKAgekwA=; b=GfoUICJzwxaukBUu4IpQiKkz6o YDaBi9Qn13PsvrPiKjpIZ+CTf6eLIm2PtvkZ4D6IkDXQDmESOstTIhb8RHHFcI28Q8YSvjhUnnXLJ dN+FQ6dBewZjAh2ecOicpnDsBZAA5mSDo/D7Xfz0FF3QaiCfZ4u9HKJCA7YvytwfJkgs6dkInn1Gf tpNLn+ft02eItDyPccUZdkb1dTu0XfNp9NXhdj6ZcFcvIYBONwDT3dCWucacikAf6BS+GqhtGx+s9 iRGmwSuN7zFISl/cD+u9+xZX5jJP5o3/C+2j3s3zssEVGqwCFlVcxFESPvpEQvMyUTAijM6lDXW/l IRqhf3Dw==; Received: from 213-225-6-64.nat.highway.a1.net ([213.225.6.64] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mSHWW-002cHB-Ov; Mon, 20 Sep 2021 11:31:59 +0000 From: Christoph Hellwig To: "David S. Miller" Cc: Andreas Larsson , sparclinux@vger.kernel.org Subject: [PATCH 1/2] sparc32: remove dma_make_coherent Date: Mon, 20 Sep 2021 13:31:07 +0200 Message-Id: <20210920113108.1299996-2-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210920113108.1299996-1-hch@lst.de> References: <20210920113108.1299996-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: sparclinux@vger.kernel.org LEON only needs snooping when DMA accesses are not seen on the processor bus. Given that coherent allocations are mapped uncached this can't happen for those, so open code the d-cache flushing logic in the only remaing place that needs it, arch_sync_dma_for_cpu. Signed-off-by: Christoph Hellwig Tested-by: Andreas Larsson --- arch/sparc/kernel/ioport.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/arch/sparc/kernel/ioport.c b/arch/sparc/kernel/ioport.c index 7ceae24b0ca99..3eb748e862220 100644 --- a/arch/sparc/kernel/ioport.c +++ b/arch/sparc/kernel/ioport.c @@ -52,17 +52,6 @@ #include #include -/* This function must make sure that caches and memory are coherent after DMA - * On LEON systems without cache snooping it flushes the entire D-CACHE. - */ -static inline void dma_make_coherent(unsigned long pa, unsigned long len) -{ - if (sparc_cpu_model == sparc_leon) { - if (!sparc_leon3_snooping_enabled()) - leon_flush_dcache_all(); - } -} - static void __iomem *_sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz); static void __iomem *_sparc_alloc_io(unsigned int busno, unsigned long phys, unsigned long size, char *name); @@ -361,18 +350,23 @@ void arch_dma_free(struct device *dev, size_t size, void *cpu_addr, if (!sparc_dma_free_resource(cpu_addr, size)) return; - dma_make_coherent(dma_addr, size); srmmu_unmapiorange((unsigned long)cpu_addr, size); free_pages((unsigned long)phys_to_virt(dma_addr), get_order(size)); } -/* IIep is write-through, not flushing on cpu to device transfer. */ - +/* + * IIep is write-through, not flushing on cpu to device transfer. + * + * On LEON systems without cache snooping, the entire D-CACHE must be flushed to + * make DMA to cacheable memory coherent. + */ void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size, enum dma_data_direction dir) { - if (dir != PCI_DMA_TODEVICE) - dma_make_coherent(paddr, PAGE_ALIGN(size)); + if (dir != PCI_DMA_TODEVICE && + sparc_cpu_model == sparc_leon && + !sparc_leon3_snooping_enabled()) + leon_flush_dcache_all(); } #ifdef CONFIG_PROC_FS From patchwork Mon Sep 20 11:31:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 1530052 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=jPlJ5mhQ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=sparclinux-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4HCj8w3qhxz9sW5 for ; Mon, 20 Sep 2021 21:32:48 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232681AbhITLeO (ORCPT ); Mon, 20 Sep 2021 07:34:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236963AbhITLeL (ORCPT ); Mon, 20 Sep 2021 07:34:11 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FAE1C061574 for ; Mon, 20 Sep 2021 04:32:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=u45r6MitWyCxusudU5ASyBKzzauZHQs57vTEQo+c/tw=; b=jPlJ5mhQdREw0t7856DvhhFHTW 99ZUfwR4EpyLsikwG5wE6xPp6qZFtFiH2NWJcfyLOR9jsZSxpHqY0YfMhflM1Pa+cfXViar7DoltA OLswKyCkSwaj2nF8x+TQATE9nxDxEl2IVLmtfnI70Z8eomFRc09gcXF0WVdZNzW2s+S9Wf0O2uDOV 8OWblDZ+AC3s7NZCCU3chDA+a5yJKFg260tuv7Qpni9vDta7aweGHqcxyvk2waZugRRbhI+b3ooHC E4JCu7gpoFGD8mWvEvhr2sDSjlHJHBDCPpMDP59knrYk0BwXEYrDbCd+BJ5kYqqifMxdnrvMJXO4Q i8rNiWjg==; Received: from 213-225-6-64.nat.highway.a1.net ([213.225.6.64] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mSHX0-002cHb-14; Mon, 20 Sep 2021 11:32:23 +0000 From: Christoph Hellwig To: "David S. Miller" Cc: Andreas Larsson , sparclinux@vger.kernel.org Subject: [PATCH 2/2] sparc32: use DMA_DIRECT_REMAP Date: Mon, 20 Sep 2021 13:31:08 +0200 Message-Id: <20210920113108.1299996-3-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210920113108.1299996-1-hch@lst.de> References: <20210920113108.1299996-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: sparclinux@vger.kernel.org Use the generic dma remapping allocator instead of open coding it. This also avoids setting up page tables from irq context which is generally dangerous and uses the atomic pool instead. Note that this changes the kernel virtual address at which the dma coherent memory is mapped from the DVMA_VADDR region to the general vmalloc pool. I could not find any indication that this matters for the hardware. Signed-off-by: Christoph Hellwig --- arch/sparc/Kconfig | 3 ++- arch/sparc/kernel/ioport.c | 54 -------------------------------------- 2 files changed, 2 insertions(+), 55 deletions(-) diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig index b120ed947f50b..66fc08646be5e 100644 --- a/arch/sparc/Kconfig +++ b/arch/sparc/Kconfig @@ -53,8 +53,9 @@ config SPARC32 def_bool !64BIT select ARCH_32BIT_OFF_T select ARCH_HAS_SYNC_DMA_FOR_CPU - select GENERIC_ATOMIC64 select CLZ_TAB + select DMA_DIRECT_REMAP + select GENERIC_ATOMIC64 select HAVE_UID16 select OLD_SIGACTION select ZONE_DMA diff --git a/arch/sparc/kernel/ioport.c b/arch/sparc/kernel/ioport.c index 3eb748e862220..57a72c46eddb0 100644 --- a/arch/sparc/kernel/ioport.c +++ b/arch/sparc/kernel/ioport.c @@ -300,60 +300,6 @@ arch_initcall(sparc_register_ioport); #endif /* CONFIG_SBUS */ - -/* Allocate and map kernel buffer using consistent mode DMA for a device. - * hwdev should be valid struct pci_dev pointer for PCI devices. - */ -void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, - gfp_t gfp, unsigned long attrs) -{ - unsigned long addr; - void *va; - - if (!size || size > 256 * 1024) /* __get_free_pages() limit */ - return NULL; - - size = PAGE_ALIGN(size); - va = (void *) __get_free_pages(gfp | __GFP_ZERO, get_order(size)); - if (!va) { - printk("%s: no %zd pages\n", __func__, size >> PAGE_SHIFT); - return NULL; - } - - addr = sparc_dma_alloc_resource(dev, size); - if (!addr) - goto err_nomem; - - srmmu_mapiorange(0, virt_to_phys(va), addr, size); - - *dma_handle = virt_to_phys(va); - return (void *)addr; - -err_nomem: - free_pages((unsigned long)va, get_order(size)); - return NULL; -} - -/* Free and unmap a consistent DMA buffer. - * cpu_addr is what was returned arch_dma_alloc, size must be the same as what - * was passed into arch_dma_alloc, and likewise dma_addr must be the same as - * what *dma_ndler was set to. - * - * References to the memory and mappings associated with cpu_addr/dma_addr - * past this call are illegal. - */ -void arch_dma_free(struct device *dev, size_t size, void *cpu_addr, - dma_addr_t dma_addr, unsigned long attrs) -{ - size = PAGE_ALIGN(size); - - if (!sparc_dma_free_resource(cpu_addr, size)) - return; - - srmmu_unmapiorange((unsigned long)cpu_addr, size); - free_pages((unsigned long)phys_to_virt(dma_addr), get_order(size)); -} - /* * IIep is write-through, not flushing on cpu to device transfer. *