Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4070674pxk; Tue, 8 Sep 2020 09:55:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzV0pROYQbbcZjHJc0ETaD0q7vqces0w9E3p3ekAh8rI1qUi7XxRhLHKOveno+JZwAaVgnR X-Received: by 2002:aa7:dbd9:: with SMTP id v25mr29133094edt.78.1599584135971; Tue, 08 Sep 2020 09:55:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599584135; cv=none; d=google.com; s=arc-20160816; b=g0CjE74JBo7onMHb6xwJpQyj1UYTRz/pHgGmv8Axk/tzrxeVWptcVus8PhoCqP9UPd Fb8SX4qEGE1u3I6bxY5V5euY5/g5q1A6RNi13YZJDEw3gZHPAOv75mJtq8yprrgkhDQH GJALIxgADjWmn9ncDcy7q5pFjeGIWELMfWpG3826VxKUXyLRrYHPe0nm5Ts6D3+ETbvq vX/bzphTl0d+IxyUJjyKMz1ekDv8GgqjyrEhAmBaInyT/QU2YbwEl32cEnLY2DQ4/cw7 w64KyU8LZ7SXCuB6YruxDXYUuPpmB8N74zY4A6fqveUPhgcu5b3+5HYjUFS3pVMDiJ7h 6BWw== 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=soQt1Tw9+1Fdq6LKNOQ8tGb15t1mDxMbN44xbNYSfjs=; b=So7t/GCPeCywxdl5FBtV0X3fXYebgZxiznZa1W94TsyUzzcwiqGqRBtGtC9OfpGf3m BN0G9KIPy6i/id8DyRlyn1/zjpvr94XafrzIaDh7XXy/kjZZn+OniR5ZXKp1CNZPcTOa /dmHHBDWPImEEuop7utJwefJDtcPJsW3Fs2GYTXiPVDG9gdW10kwCrRorD5pW8q7FAuX i9fSXeblw2dDq81M5mCBmVlF6cptL8EcWeGsWaDC27igUF298SMhFQ7yyPbbotutgRh7 zhg8oHgsNiF662/XHUn78opLOyHztaG70SfAmk/tSmen3w7oj/0g81BZqfUJLzeGcg5O HhBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=hV05IY82; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a16si12714200ejk.665.2020.09.08.09.55.12; Tue, 08 Sep 2020 09:55:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=hV05IY82; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732028AbgIHQya (ORCPT + 99 others); Tue, 8 Sep 2020 12:54:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732001AbgIHQsR (ORCPT ); Tue, 8 Sep 2020 12:48:17 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 224F0C061755; Tue, 8 Sep 2020 09:48:15 -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=soQt1Tw9+1Fdq6LKNOQ8tGb15t1mDxMbN44xbNYSfjs=; b=hV05IY82BWGuy3E6hUTd9qlkH0 3oipOFrp2gTwvrCawc0gW9yoF7cBZZxwQdGaLBWY4XlC/ONtKbMMUkySMuwkGsoEF/gQx/GYNw+I8 MfWTbHnPuhNsegLXX1h6kM/OQQK9laVWV8EIDOZz4Rlys4taZ4LWYBm+3jyq+tEJWKoAw95AWCEu0 rDwcjhcSDoy+g3JL9SzEmYQuMd+fpVE97CcNwzufa3BRDqhSMz7dmErGFEND2MHibfQSfHa2JaYaF sbXzb+HWnTBz6NEgLaLQpBVOsky9rwpoW+2qZZGt01gs74COue8pbul31rJWukjAEk8PbbkVi6HLy plooEkQg==; Received: from [2001:4bb8:184:af1:3dc3:9c83:fc6c:e0f] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kFgmo-0001Rd-Mm; Tue, 08 Sep 2020 16:48:03 +0000 From: Christoph Hellwig To: Tony Luck , Fenghua Yu , Thomas Bogendoerfer , iommu@lists.linux-foundation.org Cc: Tomasz Figa , Joerg Roedel , Robin Murphy , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ia64@vger.kernel.org, linux-mips@vger.kernel.org Subject: [PATCH 03/12] MIPS/jazzdma: decouple from dma-direct Date: Tue, 8 Sep 2020 18:47:49 +0200 Message-Id: <20200908164758.3177341-4-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200908164758.3177341-1-hch@lst.de> References: <20200908164758.3177341-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.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 jazzdma ops implement support for a very basic IOMMU. Thus we really should not use the dma-direct code that takes physical address limits into account. This survived through the great MIPS DMA ops cleanup mostly because I was lazy, but now it is time to fully split the implementations. Signed-off-by: Christoph Hellwig Acked-by: Thomas Bogendoerfer --- arch/mips/jazz/jazzdma.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/arch/mips/jazz/jazzdma.c b/arch/mips/jazz/jazzdma.c index fe40dbed04c1d6..d0b5a2ba2b1a8a 100644 --- a/arch/mips/jazz/jazzdma.c +++ b/arch/mips/jazz/jazzdma.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -492,26 +491,38 @@ int vdma_get_enable(int channel) static void *jazz_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) { + struct page *page; void *ret; - ret = dma_direct_alloc_pages(dev, size, dma_handle, gfp, attrs); - if (!ret) - return NULL; + if (attrs & DMA_ATTR_NO_WARN) + gfp |= __GFP_NOWARN; - *dma_handle = vdma_alloc(virt_to_phys(ret), size); - if (*dma_handle == DMA_MAPPING_ERROR) { - dma_direct_free_pages(dev, size, ret, *dma_handle, attrs); + size = PAGE_ALIGN(size); + page = alloc_pages(gfp, get_order(size)); + if (!page) return NULL; - } + ret = page_address(page); + *dma_handle = vdma_alloc(virt_to_phys(ret), size); + if (*dma_handle == DMA_MAPPING_ERROR) + goto out_free_pages; + + if (attrs & DMA_ATTR_NON_CONSISTENT) + return ret; + arch_dma_prep_coherent(page, size); + return (void *)(UNCAC_BASE + __pa(ret)); - return ret; +out_free_pages: + __free_pages(page, get_order(size)); + return NULL; } static void jazz_dma_free(struct device *dev, size_t size, void *vaddr, dma_addr_t dma_handle, unsigned long attrs) { vdma_free(dma_handle); - dma_direct_free_pages(dev, size, vaddr, dma_handle, attrs); + if (!(attrs & DMA_ATTR_NON_CONSISTENT)) + vaddr = __va(vaddr - UNCAC_BASE); + __free_pages(virt_to_page(vaddr), get_order(size)); } static dma_addr_t jazz_dma_map_page(struct device *dev, struct page *page, @@ -608,7 +619,6 @@ const struct dma_map_ops jazz_dma_ops = { .sync_single_for_device = jazz_dma_sync_single_for_device, .sync_sg_for_cpu = jazz_dma_sync_sg_for_cpu, .sync_sg_for_device = jazz_dma_sync_sg_for_device, - .dma_supported = dma_direct_supported, .cache_sync = arch_dma_cache_sync, .mmap = dma_common_mmap, .get_sgtable = dma_common_get_sgtable, -- 2.28.0