Received: by 10.213.65.68 with SMTP id h4csp1447576imn; Mon, 19 Mar 2018 04:34:32 -0700 (PDT) X-Google-Smtp-Source: AG47ELtvWZaawQKUHCgNb+l33YNTJWG5prwvmiQvtTPOTcYC0V7A/loayxK1Qzzd2h5W2v3t0rNs X-Received: by 2002:a17:902:7b85:: with SMTP id w5-v6mr12192244pll.131.1521459272926; Mon, 19 Mar 2018 04:34:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521459272; cv=none; d=google.com; s=arc-20160816; b=wGDm0w0YgVSqZIBrIbkCeILu7GtXpDYLjRAM9TmkCXQGhNADDrWO8JxtuqaXWAMEDj /rnrkrHaAZ9mf8my18qMmF5+Wqz5sre1MrHTE32jf8zIhszW2iz3xz+aPZcngUmiPZe3 LzUI39QAzo9R3ijU6pRJln/sR9r/9pBkYUcujH7+ZOg7BM1j1oUWfSlnYHRegnB4Ynn6 hTZXNbNa0jkv9kAm0IeuyzCm+IsAO0Ln567qWMnBXuJqtdGzhmfCnuusdOqaU0NSLT7c E7xk4tIvDW85ToOT15A+bQlYdfDfbap9Ioe6cOs/1Y33M7P9wpmVS2nsTOwOrxd961yS crWA== 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=frM5LW3HlTQT1xjEeg60meoidMKDkQvSgNe/NslqtQI=; b=B3j1JsK/gXJQ6eweFZ8O7x+6TRwUuwrevq49heJ0Oy6Mob45XmFi/eDRqiZECN+1Gp 3eKsjVWoviKo642ALngoLRGl9KUxh70SAEihUPYTiWvG/6qkJ+F5eWRs4yilnwLtJXyz X4hdliC40PzqWGYTzGDBedovxgRa6aXYSr9Nwnpge9S9DCE/ggnS/iQWmGWuPk3omRxp UXxmtQzSnSe6gBgsNWDBG267POQvQIBrPc09nHZ7Q8bCebPlpVrXBGZTAV0ibc+T1eUV 3C1L91EmepsVBEOR6mJlXIm+yNxGumTwZoymj0RYtr76XIL/GiYQBb9W/VnL9jRvA+FS 2LUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=OMc/AhtR; 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 a19-v6si9232373plm.121.2018.03.19.04.34.18; Mon, 19 Mar 2018 04:34:32 -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=OMc/AhtR; 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 S932912AbeCSKjI (ORCPT + 99 others); Mon, 19 Mar 2018 06:39:08 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:55074 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932841AbeCSKi5 (ORCPT ); Mon, 19 Mar 2018 06:38:57 -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=frM5LW3HlTQT1xjEeg60meoidMKDkQvSgNe/NslqtQI=; b=OMc/AhtRSVFI1QM1GWHWsN2ef cpc2vNlvv/OSqvAFLWOy26BnFwLXZFe6U/3ZJcAPOV+DUBQ59H29kye1j/P7VWFuatuks19YCmhpE Lv7UXjPZsewj/wk0HsJleVt+SGUc6ntoAuZjdluH1fkHe7U2kG3zyroQjg9u3hW0pGbThTAz1SKob bQpYVDgHUpXRpbaGHTvL4ifJ/cmM4b3O+NDam0xcxIQ7INGlxmmgniM7/OHkmwcjYmOD+DSyARxRH CgwWQM19/251T4ZqR9PZQbND2+oMlUhQq5kiWUUrDb7lOmsEl/rNP9+AIHjS/wKwqhy5oOu8X3hmj o5+AAIC2Q==; Received: from 178.114.187.156.wireless.dyn.drei.com ([178.114.187.156] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1exsBn-0005o3-FF; Mon, 19 Mar 2018 10:38:52 +0000 From: Christoph Hellwig To: x86@kernel.org Cc: Konrad Rzeszutek Wilk , Tom Lendacky , David Woodhouse , Muli Ben-Yehuda , Jon Mason , Joerg Roedel , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/14] x86/amd_gart: use dma_direct_{alloc,free} Date: Mon, 19 Mar 2018 11:38:18 +0100 Message-Id: <20180319103826.12853-7-hch@lst.de> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180319103826.12853-1-hch@lst.de> References: <20180319103826.12853-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 This gains support for CMA allocations for the force_iommu case, and cleans up the code a bit. Signed-off-by: Christoph Hellwig --- arch/x86/kernel/amd_gart_64.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c index 79ac6caaaabb..f299d8a479bb 100644 --- a/arch/x86/kernel/amd_gart_64.c +++ b/arch/x86/kernel/amd_gart_64.c @@ -480,29 +480,21 @@ static void * gart_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_addr, gfp_t flag, unsigned long attrs) { - dma_addr_t paddr; - unsigned long align_mask; - struct page *page; - - if (force_iommu && dev->coherent_dma_mask > DMA_BIT_MASK(24)) { - flag &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32); - page = alloc_pages(flag | __GFP_ZERO, get_order(size)); - if (!page) - return NULL; - - align_mask = (1UL << get_order(size)) - 1; - paddr = dma_map_area(dev, page_to_phys(page), size, - DMA_BIDIRECTIONAL, align_mask); - - flush_gart(); - if (paddr != bad_dma_addr) { - *dma_addr = paddr; - return page_address(page); - } - __free_pages(page, get_order(size)); - } else - return dma_direct_alloc(dev, size, dma_addr, flag, attrs); + void *vaddr; + + vaddr = dma_direct_alloc(dev, size, dma_addr, flag, attrs); + if (!vaddr || + !force_iommu || dev->coherent_dma_mask <= DMA_BIT_MASK(24)) + return vaddr; + *dma_addr = dma_map_area(dev, virt_to_phys(vaddr), size, + DMA_BIDIRECTIONAL, (1UL << get_order(size)) - 1); + flush_gart(); + if (unlikely(*dma_addr == bad_dma_addr)) + goto out_free; + return vaddr; +out_free: + dma_direct_free(dev, size, vaddr, *dma_addr, attrs); return NULL; } -- 2.14.2