Skip to content

Commit efcd572

Browse files
author
Christoph Hellwig
committed
xen/arm: simplify dma_cache_maint
Calculate the required operation in the caller, and pass it directly instead of recalculating it for each page, and use simple arithmetics to get from the physical address to Xen page size aligned chunks. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
1 parent a8e6d95 commit efcd572

1 file changed

Lines changed: 21 additions & 40 deletions

File tree

‎arch/arm/xen/mm.c‎

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -35,64 +35,45 @@ unsigned long xen_get_swiotlb_free_pages(unsigned int order)
3535
return __get_free_pages(flags, order);
3636
}
3737

38-
enum dma_cache_op {
39-
DMA_UNMAP,
40-
DMA_MAP,
41-
};
4238
static bool hypercall_cflush = false;
4339

44-
/* functions called by SWIOTLB */
45-
46-
static void dma_cache_maint(dma_addr_t handle, unsigned long offset,
47-
size_t size, enum dma_data_direction dir, enum dma_cache_op op)
40+
/* buffers in highmem or foreign pages cannot cross page boundaries */
41+
static void dma_cache_maint(dma_addr_t handle, size_t size, u32 op)
4842
{
4943
struct gnttab_cache_flush cflush;
50-
unsigned long xen_pfn;
51-
size_t left = size;
5244

53-
xen_pfn = (handle >> XEN_PAGE_SHIFT) + offset / XEN_PAGE_SIZE;
54-
offset %= XEN_PAGE_SIZE;
45+
cflush.a.dev_bus_addr = handle & XEN_PAGE_MASK;
46+
cflush.offset = xen_offset_in_page(handle);
47+
cflush.op = op;
5548

5649
do {
57-
size_t len = left;
58-
59-
/* buffers in highmem or foreign pages cannot cross page
60-
* boundaries */
61-
if (len + offset > XEN_PAGE_SIZE)
62-
len = XEN_PAGE_SIZE - offset;
63-
64-
cflush.op = 0;
65-
cflush.a.dev_bus_addr = xen_pfn << XEN_PAGE_SHIFT;
66-
cflush.offset = offset;
67-
cflush.length = len;
68-
69-
if (op == DMA_UNMAP && dir != DMA_TO_DEVICE)
70-
cflush.op = GNTTAB_CACHE_INVAL;
71-
if (op == DMA_MAP) {
72-
if (dir == DMA_FROM_DEVICE)
73-
cflush.op = GNTTAB_CACHE_INVAL;
74-
else
75-
cflush.op = GNTTAB_CACHE_CLEAN;
76-
}
77-
if (cflush.op)
78-
HYPERVISOR_grant_table_op(GNTTABOP_cache_flush, &cflush, 1);
50+
if (size + cflush.offset > XEN_PAGE_SIZE)
51+
cflush.length = XEN_PAGE_SIZE - cflush.offset;
52+
else
53+
cflush.length = size;
54+
55+
HYPERVISOR_grant_table_op(GNTTABOP_cache_flush, &cflush, 1);
7956

80-
offset = 0;
81-
xen_pfn++;
82-
left -= len;
83-
} while (left);
57+
cflush.offset = 0;
58+
cflush.a.dev_bus_addr += cflush.length;
59+
size -= cflush.length;
60+
} while (size);
8461
}
8562

8663
static void __xen_dma_page_dev_to_cpu(struct device *hwdev, dma_addr_t handle,
8764
size_t size, enum dma_data_direction dir)
8865
{
89-
dma_cache_maint(handle & PAGE_MASK, handle & ~PAGE_MASK, size, dir, DMA_UNMAP);
66+
if (dir != DMA_TO_DEVICE)
67+
dma_cache_maint(handle, size, GNTTAB_CACHE_INVAL);
9068
}
9169

9270
static void __xen_dma_page_cpu_to_dev(struct device *hwdev, dma_addr_t handle,
9371
size_t size, enum dma_data_direction dir)
9472
{
95-
dma_cache_maint(handle & PAGE_MASK, handle & ~PAGE_MASK, size, dir, DMA_MAP);
73+
if (dir == DMA_FROM_DEVICE)
74+
dma_cache_maint(handle, size, GNTTAB_CACHE_INVAL);
75+
else
76+
dma_cache_maint(handle, size, GNTTAB_CACHE_CLEAN);
9677
}
9778

9879
void __xen_dma_map_page(struct device *hwdev, struct page *page,

0 commit comments

Comments
 (0)