From: Tomasz Figa <tfiga@chromium.org>
To: iommu@lists.linux-foundation.org
Cc: linux-kernel@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Robin Murphy <robin.murphy@arm.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Joerg Roedel <joro@8bytes.org>, Will Deacon <will.deacon@arm.com>,
Vineet Gupta <vgupta@synopsys.com>,
Hans-Christian Noren Egtvedt <egtvedt@samfundet.no>,
Mitchel Humpherys <mitchelh@codeaurora.org>,
Krzysztof Kozlowski <krzk@kernel.org>,
Arnd Bergmann <arnd@arndb.de>, Tomasz Figa <tfiga@chromium.org>
Subject: [RFC PATCH 2/5] base: dma-mapping: Provide a function to look up remapped pages
Date: Wed, 5 Jul 2017 16:12:12 +0900 [thread overview]
Message-ID: <20170705071215.17603-3-tfiga@chromium.org> (raw)
In-Reply-To: <20170705071215.17603-1-tfiga@chromium.org>
DMA API implementations, which use the dma_common_*() helpers, typically
use them in pair with other helpers, such as iommu_dma_*(). For example,
a typical .free() callback needs to retrieve the pages remapped earlier
by dma_common_remap() and call iommu_dma_unmap() on them. Currently it
is done by calling find_vm_area() manually, however it relies on
implementation details of dma_common_remap() and is also difficult to
expose to loadable modules, due to find_vm_area() being quite a low
level function without its symbol exported.
Improve this by providing a function to look-up the pages previously
remapped. It hides implementation details, can do more sanity checks
than find_vm_area() and can be exported for use in loadable modules.
Signed-off-by: Tomasz Figa <tfiga@chromium.org>
---
drivers/base/dma-mapping.c | 15 +++++++++++++++
include/linux/dma-mapping.h | 2 ++
2 files changed, 17 insertions(+)
diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c
index 1fda8df3d849..9add50dd7a08 100644
--- a/drivers/base/dma-mapping.c
+++ b/drivers/base/dma-mapping.c
@@ -335,6 +335,21 @@ void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags)
vunmap(cpu_addr);
}
EXPORT_SYMBOL(dma_common_free_remap);
+
+struct page **dma_common_get_mapped_pages(void *cpu_addr,
+ unsigned long vm_flags)
+{
+ struct vm_struct *area = find_vm_area(cpu_addr);
+
+ if (!area || (area->flags & vm_flags) != vm_flags) {
+ WARN(1, "trying to get pages for invalid coherent area: %p\n",
+ cpu_addr);
+ return NULL;
+ }
+
+ return area->pages;
+}
+EXPORT_SYMBOL(dma_common_get_mapped_pages);
#endif
/*
diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index 843ab866e0f4..bd20435dac16 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -422,6 +422,8 @@ void *dma_common_pages_remap(struct page **pages, size_t size,
unsigned long vm_flags, pgprot_t prot,
const void *caller);
void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags);
+struct page **dma_common_get_mapped_pages(void *cpu_addr,
+ unsigned long vm_flags);
/**
* dma_mmap_attrs - map a coherent DMA allocation into user space
--
2.13.2.725.g09c95d1e9-goog
next prev parent reply other threads:[~2017-07-05 7:12 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-05 7:12 [RFC PATCH 0/5] Fixes for loadable modules implementing DMA/IOMMU APIs Tomasz Figa
2017-07-05 7:12 ` [RFC PATCH 1/5] base: dma-mapping: Export commonly used symbols Tomasz Figa
2017-07-05 15:17 ` Christoph Hellwig
2017-07-05 15:22 ` Tomasz Figa
2017-07-05 17:20 ` Christoph Hellwig
2017-07-06 1:44 ` Tomasz Figa
2017-07-06 8:26 ` Arnd Bergmann
2017-07-06 8:34 ` Tomasz Figa
2017-07-06 8:36 ` Tomasz Figa
2017-07-06 12:23 ` Arnd Bergmann
2017-07-06 13:31 ` Tomasz Figa
2017-07-06 13:49 ` Tomasz Figa
2017-07-06 14:02 ` Arnd Bergmann
2017-07-06 14:06 ` Tomasz Figa
2017-07-06 14:27 ` Arnd Bergmann
2017-07-06 14:35 ` Tomasz Figa
2017-07-06 13:56 ` Arnd Bergmann
2017-07-05 7:12 ` Tomasz Figa [this message]
2017-07-05 7:12 ` [RFC PATCH 3/5] iommu: Export non-static functions to use in modules Tomasz Figa
2017-07-05 7:12 ` [RFC PATCH 4/5] iommu/dma: " Tomasz Figa
2017-07-05 16:22 ` Robin Murphy
2017-07-06 2:25 ` Tomasz Figa
2017-07-06 11:09 ` Robin Murphy
2017-07-06 14:10 ` Christoph Hellwig
2017-07-06 14:17 ` Tomasz Figa
2017-07-06 14:24 ` Tomasz Figa
2017-07-06 14:35 ` Arnd Bergmann
2017-07-06 14:41 ` Tomasz Figa
2017-07-05 7:12 ` [RFC PATCH 5/5] iommu/dma: Add iommu_dma_cleanup() Tomasz Figa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170705071215.17603-3-tfiga@chromium.org \
--to=tfiga@chromium.org \
--cc=arnd@arndb.de \
--cc=egtvedt@samfundet.no \
--cc=gregkh@linuxfoundation.org \
--cc=hch@lst.de \
--cc=iommu@lists.linux-foundation.org \
--cc=joro@8bytes.org \
--cc=krzk@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mitchelh@codeaurora.org \
--cc=robin.murphy@arm.com \
--cc=vgupta@synopsys.com \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®