Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1681327
| From | Tomasz Figa <tfiga@chromium.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [RFC PATCH 2/5] base: dma-mapping: Provide a function to look up remapped pages |
| Date | 2017-07-05 09:20 +0200 |
| Message-ID | <tZMLo-3av-21@gated-at.bofh.it> (permalink) |
| References | <tZMLn-3av-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[RFC PATCH 0/5] Fixes for loadable modules implementing DMA/IOMMU APIs Tomasz Figa <tfiga@chromium.org> - 2017-07-05 09:20 +0200
[RFC PATCH 5/5] iommu/dma: Add iommu_dma_cleanup() Tomasz Figa <tfiga@chromium.org> - 2017-07-05 09:20 +0200
[RFC PATCH 2/5] base: dma-mapping: Provide a function to look up remapped pages Tomasz Figa <tfiga@chromium.org> - 2017-07-05 09:20 +0200
[RFC PATCH 3/5] iommu: Export non-static functions to use in modules Tomasz Figa <tfiga@chromium.org> - 2017-07-05 09:20 +0200
[RFC PATCH 1/5] base: dma-mapping: Export commonly used symbols Tomasz Figa <tfiga@chromium.org> - 2017-07-05 09:20 +0200
Re: [RFC PATCH 1/5] base: dma-mapping: Export commonly used symbols Christoph Hellwig <hch@lst.de> - 2017-07-05 17:20 +0200
Re: [RFC PATCH 1/5] base: dma-mapping: Export commonly used symbols Tomasz Figa <tfiga@chromium.org> - 2017-07-05 17:30 +0200
Re: [RFC PATCH 1/5] base: dma-mapping: Export commonly used symbols Christoph Hellwig <hch@lst.de> - 2017-07-05 19:30 +0200
Re: [RFC PATCH 1/5] base: dma-mapping: Export commonly used symbols Tomasz Figa <tfiga@chromium.org> - 2017-07-06 03:50 +0200
Re: [RFC PATCH 1/5] base: dma-mapping: Export commonly used symbols Arnd Bergmann <arnd@arndb.de> - 2017-07-06 10:30 +0200
Re: [RFC PATCH 1/5] base: dma-mapping: Export commonly used symbols Tomasz Figa <tfiga@chromium.org> - 2017-07-06 10:40 +0200
Re: [RFC PATCH 1/5] base: dma-mapping: Export commonly used symbols Tomasz Figa <tfiga@chromium.org> - 2017-07-06 10:50 +0200
Re: [RFC PATCH 1/5] base: dma-mapping: Export commonly used symbols Arnd Bergmann <arnd@arndb.de> - 2017-07-06 14:30 +0200
Re: [RFC PATCH 1/5] base: dma-mapping: Export commonly used symbols Tomasz Figa <tfiga@chromium.org> - 2017-07-06 15:40 +0200
Re: [RFC PATCH 1/5] base: dma-mapping: Export commonly used symbols Tomasz Figa <tfiga@chromium.org> - 2017-07-06 15:50 +0200
Re: [RFC PATCH 1/5] base: dma-mapping: Export commonly used symbols Tomasz Figa <tfiga@chromium.org> - 2017-07-06 16:10 +0200
Re: [RFC PATCH 1/5] base: dma-mapping: Export commonly used symbols Arnd Bergmann <arnd@arndb.de> - 2017-07-06 16:30 +0200
Re: [RFC PATCH 1/5] base: dma-mapping: Export commonly used symbols Tomasz Figa <tfiga@chromium.org> - 2017-07-06 16:40 +0200
Re: [RFC PATCH 1/5] base: dma-mapping: Export commonly used symbols Arnd Bergmann <arnd@arndb.de> - 2017-07-06 16:10 +0200
Re: [RFC PATCH 1/5] base: dma-mapping: Export commonly used symbols Arnd Bergmann <arnd@arndb.de> - 2017-07-06 16:00 +0200
[RFC PATCH 4/5] iommu/dma: Export non-static functions to use in modules Tomasz Figa <tfiga@chromium.org> - 2017-07-05 09:20 +0200
Re: [RFC PATCH 4/5] iommu/dma: Export non-static functions to use in modules Robin Murphy <robin.murphy@arm.com> - 2017-07-05 18:30 +0200
Re: [RFC PATCH 4/5] iommu/dma: Export non-static functions to use in modules Tomasz Figa <tfiga@chromium.org> - 2017-07-06 04:30 +0200
Re: [RFC PATCH 4/5] iommu/dma: Export non-static functions to use in modules Robin Murphy <robin.murphy@arm.com> - 2017-07-06 13:20 +0200
Re: [RFC PATCH 4/5] iommu/dma: Export non-static functions to use in modules Christoph Hellwig <hch@lst.de> - 2017-07-06 16:20 +0200
Re: [RFC PATCH 4/5] iommu/dma: Export non-static functions to use in modules Tomasz Figa <tfiga@chromium.org> - 2017-07-06 16:20 +0200
Re: [RFC PATCH 4/5] iommu/dma: Export non-static functions to use in modules Tomasz Figa <tfiga@chromium.org> - 2017-07-06 16:30 +0200
Re: [RFC PATCH 4/5] iommu/dma: Export non-static functions to use in modules Arnd Bergmann <arnd@arndb.de> - 2017-07-06 16:40 +0200
Re: [RFC PATCH 4/5] iommu/dma: Export non-static functions to use in modules Tomasz Figa <tfiga@chromium.org> - 2017-07-06 16:50 +0200
csiph-web