Skip to content

Commit d7b461c

Browse files
Stefano Stabellinijgross1
authored andcommitted
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: Stefano Stabellini <[email protected]> Reviewed-by: Boris Ostrovsky <[email protected]> Tested-by: Corey Minyard <[email protected]> Tested-by: Roman Shaposhnik <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Juergen Gross <[email protected]>
1 parent 63f0620 commit d7b461c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

arch/arm/xen/mm.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,18 @@ unsigned long xen_get_swiotlb_free_pages(unsigned int order)
4343
static bool hypercall_cflush = false;
4444

4545
/* buffers in highmem or foreign pages cannot cross page boundaries */
46-
static void dma_cache_maint(dma_addr_t handle, size_t size, u32 op)
46+
static void dma_cache_maint(struct device *dev, dma_addr_t handle,
47+
size_t size, u32 op)
4748
{
4849
struct gnttab_cache_flush cflush;
4950

50-
cflush.a.dev_bus_addr = handle & XEN_PAGE_MASK;
5151
cflush.offset = xen_offset_in_page(handle);
5252
cflush.op = op;
53+
handle &= XEN_PAGE_MASK;
5354

5455
do {
56+
cflush.a.dev_bus_addr = dma_to_phys(dev, handle);
57+
5558
if (size + cflush.offset > XEN_PAGE_SIZE)
5659
cflush.length = XEN_PAGE_SIZE - cflush.offset;
5760
else
@@ -60,7 +63,7 @@ static void dma_cache_maint(dma_addr_t handle, size_t size, u32 op)
6063
HYPERVISOR_grant_table_op(GNTTABOP_cache_flush, &cflush, 1);
6164

6265
cflush.offset = 0;
63-
cflush.a.dev_bus_addr += cflush.length;
66+
handle += cflush.length;
6467
size -= cflush.length;
6568
} while (size);
6669
}
@@ -76,16 +79,16 @@ void xen_dma_sync_for_cpu(struct device *dev, dma_addr_t handle,
7679
size_t size, enum dma_data_direction dir)
7780
{
7881
if (dir != DMA_TO_DEVICE)
79-
dma_cache_maint(handle, size, GNTTAB_CACHE_INVAL);
82+
dma_cache_maint(dev, handle, size, GNTTAB_CACHE_INVAL);
8083
}
8184

8285
void xen_dma_sync_for_device(struct device *dev, dma_addr_t handle,
8386
size_t size, enum dma_data_direction dir)
8487
{
8588
if (dir == DMA_FROM_DEVICE)
86-
dma_cache_maint(handle, size, GNTTAB_CACHE_INVAL);
89+
dma_cache_maint(dev, handle, size, GNTTAB_CACHE_INVAL);
8790
else
88-
dma_cache_maint(handle, size, GNTTAB_CACHE_CLEAN);
91+
dma_cache_maint(dev, handle, size, GNTTAB_CACHE_CLEAN);
8992
}
9093

9194
bool xen_arch_need_swiotlb(struct device *dev,

0 commit comments

Comments
 (0)