Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2251444pxk; Mon, 14 Sep 2020 08:27:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPeO+K17M8Lt50wKUr0Xd943VoUq7GQ7mo2lm5bKxi1jJsq1zVBd99kWMpAo9LywglM4RM X-Received: by 2002:a17:906:cc99:: with SMTP id oq25mr3267215ejb.292.1600097248230; Mon, 14 Sep 2020 08:27:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600097248; cv=none; d=google.com; s=arc-20160816; b=NQyD6xd+/a+yH4FVwvCrKT6NxbmRKWJbj37x+dczIeseX96Ccd5p4zXOCmLO+74bEC hNoBRSaNIuJWULBhY2m2rAHXLzPyMESTceht9WY5Pf04YVFchBipGQz7kYVXOs+4ZuNZ rV7tecmkTxfNFldE4kADPuj59z5jtytyjIxwhqTyOVIdJR7PhH2tJH28Tztpli21seAY GujnQ0v5GlpqTM3L0M0FBT3FHQox/6+6NfuzVNoDnpRLCY1Af0i9eFqBN9021CoLxA/i DYdbb8AvfakYMkPT7NZMhTaYlnBMqqFq06HQhfgSvQAEFQZv9Ye6VBeo06D1K3d4ttVj 6yiA== 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=1/bEcy21h9dr4Lop81Jp+A+3tsDr/+YN8bI8sHR6ers=; b=ae6fBJt26YNk9yQbmtaX7Z3ThLGdlq1+rvC/ZyU6cXe47nh4pAg+AEnz7I3/KWpxZE P0hbbJJi+Pg7cGu+/Whe1bpWAATrjkLDgei8yxSpEAGyHD2GSbfiPor7S+fwtOWAgxD2 R9a8VZMiuWZpfah6b+cyUOcFu5Lun443hvrwf2yI4BIYYmreYltfV6Q54q8Vk5zLVRxn ZhwpZk1pdofvxFJsdqb7iSuebwliGyTF7mPLmll8Y5l/k96IfKuNy0Fdmzzl4hmKUoD5 esD6cueXpB5HKXTuSrguya+i4z5TIEz+HTops+z7RYyE5yrWOn5Kac7hbaMvMYqydB/K YAtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b="JY/8kYp/"; 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 t7si7246817ejx.194.2020.09.14.08.27.04; Mon, 14 Sep 2020 08:27:28 -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="JY/8kYp/"; 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 S1726402AbgINPUg (ORCPT + 99 others); Mon, 14 Sep 2020 11:20:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726356AbgINPUE (ORCPT ); Mon, 14 Sep 2020 11:20:04 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F0ABC06174A; Mon, 14 Sep 2020 08:20:03 -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=1/bEcy21h9dr4Lop81Jp+A+3tsDr/+YN8bI8sHR6ers=; b=JY/8kYp/POQkPS9/pbiO0kzzh+ mOyOphuwGiSxozJvdBmQbVXdpG38y4zvNPvDTEyqS70PZWHyQ+nUIMv9lzq4a5ypYPc9tvDK+CIM0 7lPCr4+YDj0yPFSArV9+fF62o2ujujYy0fqhRY7vll4u9LQmtZw2tTKPsUgNC0K4460oEdMJDxZH8 sQX9U2nH0JZQmQSYjbvSg5j0AR5nK0avIw2Pm4jETjZ3wR7Ck3smxO0QE/zAC0srKZ0vyTkUngfv0 wWOHZXVky9pTxXktOYz6Qkry3FEB9cbV2JlxroMdit4cUgD9HF00poCUnC+JhWxxk6qSXNvtOcUpC Re7j27kQ==; Received: from 089144214092.atnat0023.highway.a1.net ([89.144.214.92] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kHqGY-0003zk-8d; Mon, 14 Sep 2020 15:19:38 +0000 From: Christoph Hellwig To: Mauro Carvalho Chehab , Thomas Bogendoerfer , "James E.J. Bottomley" , Joonyoung Shim , Seung-Woo Kim , Ben Skeggs , Marek Szyprowski , Tomasz Figa , Matt Porter , iommu@lists.linux-foundation.org Cc: Stefan Richter , linux1394-devel@lists.sourceforge.net, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linux-samsung-soc@vger.kernel.org, nouveau@lists.freedesktop.org, netdev@vger.kernel.org, linux-scsi@vger.kernel.org, linux-mm@kvack.org, alsa-devel@alsa-project.org Subject: [PATCH 15/17] dma-mapping: add new {alloc,free}_noncoherent dma_map_ops methods Date: Mon, 14 Sep 2020 16:44:31 +0200 Message-Id: <20200914144433.1622958-16-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200914144433.1622958-1-hch@lst.de> References: <20200914144433.1622958-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 This will allow IOMMU drivers to allocate non-contigous memory and return a vmapped virtual address. Signed-off-by: Christoph Hellwig --- include/linux/dma-mapping.h | 5 +++++ kernel/dma/mapping.c | 33 +++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index bf592cf0db4acb..b4b5d75260d6dc 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -80,6 +80,11 @@ struct dma_map_ops { gfp_t gfp); void (*free_pages)(struct device *dev, size_t size, struct page *vaddr, dma_addr_t dma_handle, enum dma_data_direction dir); + void* (*alloc_noncoherent)(struct device *dev, size_t size, + dma_addr_t *dma_handle, enum dma_data_direction dir, + gfp_t gfp); + void (*free_noncoherent)(struct device *dev, size_t size, void *vaddr, + dma_addr_t dma_handle, enum dma_data_direction dir); int (*mmap)(struct device *, struct vm_area_struct *, void *, dma_addr_t, size_t, unsigned long attrs); diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index 6f86c925b8251d..8614d7d2ee59a9 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -502,19 +502,40 @@ EXPORT_SYMBOL_GPL(dma_free_pages); void *dma_alloc_noncoherent(struct device *dev, size_t size, dma_addr_t *dma_handle, enum dma_data_direction dir, gfp_t gfp) { - struct page *page; + const struct dma_map_ops *ops = get_dma_ops(dev); + void *vaddr; - page = dma_alloc_pages(dev, size, dma_handle, dir, gfp); - if (!page) - return NULL; - return page_address(page); + if (!ops || !ops->alloc_noncoherent) { + struct page *page; + + page = dma_alloc_pages(dev, size, dma_handle, dir, gfp); + if (!page) + return NULL; + return page_address(page); + } + + size = PAGE_ALIGN(size); + vaddr = ops->alloc_noncoherent(dev, size, dma_handle, dir, gfp); + if (vaddr) + debug_dma_map_page(dev, virt_to_page(vaddr), 0, size, dir, + *dma_handle); + return vaddr; } EXPORT_SYMBOL_GPL(dma_alloc_noncoherent); void dma_free_noncoherent(struct device *dev, size_t size, void *vaddr, dma_addr_t dma_handle, enum dma_data_direction dir) { - dma_free_pages(dev, size, virt_to_page(vaddr), dma_handle, dir); + const struct dma_map_ops *ops = get_dma_ops(dev); + + if (!ops || !ops->free_noncoherent) { + dma_free_pages(dev, size, virt_to_page(vaddr), dma_handle, dir); + return; + } + + size = PAGE_ALIGN(size); + debug_dma_unmap_page(dev, dma_handle, size, dir); + ops->free_noncoherent(dev, size, vaddr, dma_handle, dir); } EXPORT_SYMBOL_GPL(dma_free_noncoherent); -- 2.28.0