The dma-mapping core and the implementations do not change the DMA attributes passed by pointer. Thus the pointer can point to const data. However the attributes do not have to be a bitfield. Instead unsigned long will do fine: 1. This is just simpler. Both in terms of reading the code and setting attributes. Instead of initializing local attributes on the stack and passing pointer to it to dma_set_attr(), just set the bits. 2. It brings safeness and checking for const correctness because the attributes are passed by value. Semantic patches for this change (at least most of them): virtual patch virtual context @r@ identifier f, attrs; @@ f(..., - struct dma_attrs *attrs + unsigned long attrs , ...) { ... } @@ identifier r.f; @@ f(..., - NULL + 0 ) and // Options: --all-includes virtual patch virtual context @r@ identifier f, attrs; type t; @@ t f(..., struct dma_attrs *attrs); @@ identifier r.f; @@ f(..., - NULL + 0 ) Link: http://lkml.kernel.org/r/1468399300-5399-2-git-send-email-k.kozlowski@samsung.com Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> Acked-by: Vineet Gupta <vgupta@synopsys.com> Acked-by: Robin Murphy <robin.murphy@arm.com> Acked-by: Hans-Christian Noren Egtvedt <egtvedt@samfundet.no> Acked-by: Mark Salter <msalter@redhat.com> [c6x] Acked-by: Jesper Nilsson <jesper.nilsson@axis.com> [cris] Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch> [drm] Reviewed-by: Bart Van Assche <bart.vanassche@sandisk.com> Acked-by: Joerg Roedel <jroedel@suse.de> [iommu] Acked-by: Fabien Dessenne <fabien.dessenne@st.com> [bdisp] Reviewed-by: Marek Szyprowski <m.szyprowski@samsung.com> [vb2-core] Acked-by: David Vrabel <david.vrabel@citrix.com> [xen] Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> [xen swiotlb] Acked-by: Joerg Roedel <jroedel@suse.de> [iommu] Acked-by: Richard Kuo <rkuo@codeaurora.org> [hexagon] Acked-by: Geert Uytterhoeven <geert@linux-m68k.org> [m68k] Acked-by: Gerald Schaefer <gerald.schaefer@de.ibm.com> [s390] Acked-by: Bjorn Andersson <bjorn.andersson@linaro.org> Acked-by: Hans-Christian Noren Egtvedt <egtvedt@samfundet.no> [avr32] Acked-by: Vineet Gupta <vgupta@synopsys.com> [arc] Acked-by: Robin Murphy <robin.murphy@arm.com> [arm64 and dma-iommu] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
99 lines
3.7 KiB
C
99 lines
3.7 KiB
C
#ifndef _ASM_ARM_XEN_PAGE_COHERENT_H
|
|
#define _ASM_ARM_XEN_PAGE_COHERENT_H
|
|
|
|
#include <asm/page.h>
|
|
#include <linux/dma-mapping.h>
|
|
|
|
void __xen_dma_map_page(struct device *hwdev, struct page *page,
|
|
dma_addr_t dev_addr, unsigned long offset, size_t size,
|
|
enum dma_data_direction dir, unsigned long attrs);
|
|
void __xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle,
|
|
size_t size, enum dma_data_direction dir,
|
|
unsigned long attrs);
|
|
void __xen_dma_sync_single_for_cpu(struct device *hwdev,
|
|
dma_addr_t handle, size_t size, enum dma_data_direction dir);
|
|
|
|
void __xen_dma_sync_single_for_device(struct device *hwdev,
|
|
dma_addr_t handle, size_t size, enum dma_data_direction dir);
|
|
|
|
static inline void *xen_alloc_coherent_pages(struct device *hwdev, size_t size,
|
|
dma_addr_t *dma_handle, gfp_t flags, unsigned long attrs)
|
|
{
|
|
return __generic_dma_ops(hwdev)->alloc(hwdev, size, dma_handle, flags, attrs);
|
|
}
|
|
|
|
static inline void xen_free_coherent_pages(struct device *hwdev, size_t size,
|
|
void *cpu_addr, dma_addr_t dma_handle, unsigned long attrs)
|
|
{
|
|
__generic_dma_ops(hwdev)->free(hwdev, size, cpu_addr, dma_handle, attrs);
|
|
}
|
|
|
|
static inline void xen_dma_map_page(struct device *hwdev, struct page *page,
|
|
dma_addr_t dev_addr, unsigned long offset, size_t size,
|
|
enum dma_data_direction dir, unsigned long attrs)
|
|
{
|
|
unsigned long page_pfn = page_to_xen_pfn(page);
|
|
unsigned long dev_pfn = XEN_PFN_DOWN(dev_addr);
|
|
unsigned long compound_pages =
|
|
(1<<compound_order(page)) * XEN_PFN_PER_PAGE;
|
|
bool local = (page_pfn <= dev_pfn) &&
|
|
(dev_pfn - page_pfn < compound_pages);
|
|
|
|
/*
|
|
* Dom0 is mapped 1:1, while the Linux page can span across
|
|
* multiple Xen pages, it's not possible for it to contain a
|
|
* mix of local and foreign Xen pages. So if the first xen_pfn
|
|
* == mfn the page is local otherwise it's a foreign page
|
|
* grant-mapped in dom0. If the page is local we can safely
|
|
* call the native dma_ops function, otherwise we call the xen
|
|
* specific function.
|
|
*/
|
|
if (local)
|
|
__generic_dma_ops(hwdev)->map_page(hwdev, page, offset, size, dir, attrs);
|
|
else
|
|
__xen_dma_map_page(hwdev, page, dev_addr, offset, size, dir, attrs);
|
|
}
|
|
|
|
static inline void xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle,
|
|
size_t size, enum dma_data_direction dir, unsigned long attrs)
|
|
{
|
|
unsigned long pfn = PFN_DOWN(handle);
|
|
/*
|
|
* Dom0 is mapped 1:1, while the Linux page can be spanned accross
|
|
* multiple Xen page, it's not possible to have a mix of local and
|
|
* foreign Xen page. Dom0 is mapped 1:1, so calling pfn_valid on a
|
|
* foreign mfn will always return false. If the page is local we can
|
|
* safely call the native dma_ops function, otherwise we call the xen
|
|
* specific function.
|
|
*/
|
|
if (pfn_valid(pfn)) {
|
|
if (__generic_dma_ops(hwdev)->unmap_page)
|
|
__generic_dma_ops(hwdev)->unmap_page(hwdev, handle, size, dir, attrs);
|
|
} else
|
|
__xen_dma_unmap_page(hwdev, handle, size, dir, attrs);
|
|
}
|
|
|
|
static inline void xen_dma_sync_single_for_cpu(struct device *hwdev,
|
|
dma_addr_t handle, size_t size, enum dma_data_direction dir)
|
|
{
|
|
unsigned long pfn = PFN_DOWN(handle);
|
|
if (pfn_valid(pfn)) {
|
|
if (__generic_dma_ops(hwdev)->sync_single_for_cpu)
|
|
__generic_dma_ops(hwdev)->sync_single_for_cpu(hwdev, handle, size, dir);
|
|
} else
|
|
__xen_dma_sync_single_for_cpu(hwdev, handle, size, dir);
|
|
}
|
|
|
|
static inline void xen_dma_sync_single_for_device(struct device *hwdev,
|
|
dma_addr_t handle, size_t size, enum dma_data_direction dir)
|
|
{
|
|
unsigned long pfn = PFN_DOWN(handle);
|
|
if (pfn_valid(pfn)) {
|
|
if (__generic_dma_ops(hwdev)->sync_single_for_device)
|
|
__generic_dma_ops(hwdev)->sync_single_for_device(hwdev, handle, size, dir);
|
|
} else
|
|
__xen_dma_sync_single_for_device(hwdev, handle, size, dir);
|
|
}
|
|
|
|
#endif /* _ASM_ARM_XEN_PAGE_COHERENT_H */
|