Commit d7b461ca authored by Stefano Stabellini's avatar Stefano Stabellini Committed by Juergen Gross

xen/arm: call dma_to_phys on the dma_addr_t parameter of dma_cache_maint

dma_cache_maint is getting called passing a dma address which could be
different from a physical address.

Add a struct device* parameter to dma_cache_maint.

Translate the dma_addr_t parameter of dma_cache_maint by calling
dma_to_phys. Do it for the first page and all the following pages, in
case of multipage handling.
Signed-off-by: default avatarStefano Stabellini <stefano.stabellini@xilinx.com>
Reviewed-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
Tested-by: default avatarCorey Minyard <cminyard@mvista.com>
Tested-by: default avatarRoman Shaposhnik <roman@zededa.com>
Link: https://lore.kernel.org/r/20200710223427.6897-11-sstabellini@kernel.orgSigned-off-by: default avatarJuergen Gross <jgross@suse.com>
parent 63f0620c
...@@ -43,15 +43,18 @@ unsigned long xen_get_swiotlb_free_pages(unsigned int order) ...@@ -43,15 +43,18 @@ unsigned long xen_get_swiotlb_free_pages(unsigned int order)
static bool hypercall_cflush = false; static bool hypercall_cflush = false;
/* buffers in highmem or foreign pages cannot cross page boundaries */ /* buffers in highmem or foreign pages cannot cross page boundaries */
static void dma_cache_maint(dma_addr_t handle, size_t size, u32 op) static void dma_cache_maint(struct device *dev, dma_addr_t handle,
size_t size, u32 op)
{ {
struct gnttab_cache_flush cflush; struct gnttab_cache_flush cflush;
cflush.a.dev_bus_addr = handle & XEN_PAGE_MASK;
cflush.offset = xen_offset_in_page(handle); cflush.offset = xen_offset_in_page(handle);
cflush.op = op; cflush.op = op;
handle &= XEN_PAGE_MASK;
do { do {
cflush.a.dev_bus_addr = dma_to_phys(dev, handle);
if (size + cflush.offset > XEN_PAGE_SIZE) if (size + cflush.offset > XEN_PAGE_SIZE)
cflush.length = XEN_PAGE_SIZE - cflush.offset; cflush.length = XEN_PAGE_SIZE - cflush.offset;
else else
...@@ -60,7 +63,7 @@ static void dma_cache_maint(dma_addr_t handle, size_t size, u32 op) ...@@ -60,7 +63,7 @@ static void dma_cache_maint(dma_addr_t handle, size_t size, u32 op)
HYPERVISOR_grant_table_op(GNTTABOP_cache_flush, &cflush, 1); HYPERVISOR_grant_table_op(GNTTABOP_cache_flush, &cflush, 1);
cflush.offset = 0; cflush.offset = 0;
cflush.a.dev_bus_addr += cflush.length; handle += cflush.length;
size -= cflush.length; size -= cflush.length;
} while (size); } while (size);
} }
...@@ -76,16 +79,16 @@ void xen_dma_sync_for_cpu(struct device *dev, dma_addr_t handle, ...@@ -76,16 +79,16 @@ void xen_dma_sync_for_cpu(struct device *dev, dma_addr_t handle,
size_t size, enum dma_data_direction dir) size_t size, enum dma_data_direction dir)
{ {
if (dir != DMA_TO_DEVICE) if (dir != DMA_TO_DEVICE)
dma_cache_maint(handle, size, GNTTAB_CACHE_INVAL); dma_cache_maint(dev, handle, size, GNTTAB_CACHE_INVAL);
} }
void xen_dma_sync_for_device(struct device *dev, dma_addr_t handle, void xen_dma_sync_for_device(struct device *dev, dma_addr_t handle,
size_t size, enum dma_data_direction dir) size_t size, enum dma_data_direction dir)
{ {
if (dir == DMA_FROM_DEVICE) if (dir == DMA_FROM_DEVICE)
dma_cache_maint(handle, size, GNTTAB_CACHE_INVAL); dma_cache_maint(dev, handle, size, GNTTAB_CACHE_INVAL);
else else
dma_cache_maint(handle, size, GNTTAB_CACHE_CLEAN); dma_cache_maint(dev, handle, size, GNTTAB_CACHE_CLEAN);
} }
bool xen_arch_need_swiotlb(struct device *dev, bool xen_arch_need_swiotlb(struct device *dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment