Skip to content

Commit bef4d20

Browse files
author
Christoph Hellwig
committed
xen/arm: consolidate page-coherent.h
Shared the duplicate arm/arm64 code in include/xen/arm/page-coherent.h. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
1 parent 8e23c82 commit bef4d20

3 files changed

Lines changed: 80 additions & 150 deletions

File tree

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,2 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
2-
#ifndef _ASM_ARM_XEN_PAGE_COHERENT_H
3-
#define _ASM_ARM_XEN_PAGE_COHERENT_H
4-
5-
#include <linux/dma-mapping.h>
6-
#include <asm/page.h>
72
#include <xen/arm/page-coherent.h>
8-
9-
static inline void *xen_alloc_coherent_pages(struct device *hwdev, size_t size,
10-
dma_addr_t *dma_handle, gfp_t flags, unsigned long attrs)
11-
{
12-
return dma_direct_alloc(hwdev, size, dma_handle, flags, attrs);
13-
}
14-
15-
static inline void xen_free_coherent_pages(struct device *hwdev, size_t size,
16-
void *cpu_addr, dma_addr_t dma_handle, unsigned long attrs)
17-
{
18-
dma_direct_free(hwdev, size, cpu_addr, dma_handle, attrs);
19-
}
20-
21-
static inline void xen_dma_sync_single_for_cpu(struct device *hwdev,
22-
dma_addr_t handle, size_t size, enum dma_data_direction dir)
23-
{
24-
unsigned long pfn = PFN_DOWN(handle);
25-
26-
if (pfn_valid(pfn))
27-
dma_direct_sync_single_for_cpu(hwdev, handle, size, dir);
28-
else
29-
__xen_dma_sync_single_for_cpu(hwdev, handle, size, dir);
30-
}
31-
32-
static inline void xen_dma_sync_single_for_device(struct device *hwdev,
33-
dma_addr_t handle, size_t size, enum dma_data_direction dir)
34-
{
35-
unsigned long pfn = PFN_DOWN(handle);
36-
if (pfn_valid(pfn))
37-
dma_direct_sync_single_for_device(hwdev, handle, size, dir);
38-
else
39-
__xen_dma_sync_single_for_device(hwdev, handle, size, dir);
40-
}
41-
42-
static inline void xen_dma_map_page(struct device *hwdev, struct page *page,
43-
dma_addr_t dev_addr, unsigned long offset, size_t size,
44-
enum dma_data_direction dir, unsigned long attrs)
45-
{
46-
unsigned long page_pfn = page_to_xen_pfn(page);
47-
unsigned long dev_pfn = XEN_PFN_DOWN(dev_addr);
48-
unsigned long compound_pages =
49-
(1<<compound_order(page)) * XEN_PFN_PER_PAGE;
50-
bool local = (page_pfn <= dev_pfn) &&
51-
(dev_pfn - page_pfn < compound_pages);
52-
53-
if (local)
54-
dma_direct_map_page(hwdev, page, offset, size, dir, attrs);
55-
else
56-
__xen_dma_map_page(hwdev, page, dev_addr, offset, size, dir, attrs);
57-
}
58-
59-
static inline void xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle,
60-
size_t size, enum dma_data_direction dir, unsigned long attrs)
61-
{
62-
unsigned long pfn = PFN_DOWN(handle);
63-
/*
64-
* Dom0 is mapped 1:1, while the Linux page can be spanned accross
65-
* multiple Xen page, it's not possible to have a mix of local and
66-
* foreign Xen page. Dom0 is mapped 1:1, so calling pfn_valid on a
67-
* foreign mfn will always return false. If the page is local we can
68-
* safely call the native dma_ops function, otherwise we call the xen
69-
* specific function.
70-
*/
71-
if (pfn_valid(pfn))
72-
dma_direct_unmap_page(hwdev, handle, size, dir, attrs);
73-
else
74-
__xen_dma_unmap_page(hwdev, handle, size, dir, attrs);
75-
}
76-
77-
#endif /* _ASM_ARM_XEN_PAGE_COHERENT_H */
Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,2 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
2-
#ifndef _ASM_ARM64_XEN_PAGE_COHERENT_H
3-
#define _ASM_ARM64_XEN_PAGE_COHERENT_H
4-
5-
#include <linux/dma-mapping.h>
6-
#include <asm/page.h>
72
#include <xen/arm/page-coherent.h>
8-
9-
static inline void *xen_alloc_coherent_pages(struct device *hwdev, size_t size,
10-
dma_addr_t *dma_handle, gfp_t flags, unsigned long attrs)
11-
{
12-
return dma_direct_alloc(hwdev, size, dma_handle, flags, attrs);
13-
}
14-
15-
static inline void xen_free_coherent_pages(struct device *hwdev, size_t size,
16-
void *cpu_addr, dma_addr_t dma_handle, unsigned long attrs)
17-
{
18-
dma_direct_free(hwdev, size, cpu_addr, dma_handle, attrs);
19-
}
20-
21-
static inline void xen_dma_sync_single_for_cpu(struct device *hwdev,
22-
dma_addr_t handle, size_t size, enum dma_data_direction dir)
23-
{
24-
unsigned long pfn = PFN_DOWN(handle);
25-
26-
if (pfn_valid(pfn))
27-
dma_direct_sync_single_for_cpu(hwdev, handle, size, dir);
28-
else
29-
__xen_dma_sync_single_for_cpu(hwdev, handle, size, dir);
30-
}
31-
32-
static inline void xen_dma_sync_single_for_device(struct device *hwdev,
33-
dma_addr_t handle, size_t size, enum dma_data_direction dir)
34-
{
35-
unsigned long pfn = PFN_DOWN(handle);
36-
if (pfn_valid(pfn))
37-
dma_direct_sync_single_for_device(hwdev, handle, size, dir);
38-
else
39-
__xen_dma_sync_single_for_device(hwdev, handle, size, dir);
40-
}
41-
42-
static inline void xen_dma_map_page(struct device *hwdev, struct page *page,
43-
dma_addr_t dev_addr, unsigned long offset, size_t size,
44-
enum dma_data_direction dir, unsigned long attrs)
45-
{
46-
unsigned long page_pfn = page_to_xen_pfn(page);
47-
unsigned long dev_pfn = XEN_PFN_DOWN(dev_addr);
48-
unsigned long compound_pages =
49-
(1<<compound_order(page)) * XEN_PFN_PER_PAGE;
50-
bool local = (page_pfn <= dev_pfn) &&
51-
(dev_pfn - page_pfn < compound_pages);
52-
53-
if (local)
54-
dma_direct_map_page(hwdev, page, offset, size, dir, attrs);
55-
else
56-
__xen_dma_map_page(hwdev, page, dev_addr, offset, size, dir, attrs);
57-
}
58-
59-
static inline void xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle,
60-
size_t size, enum dma_data_direction dir, unsigned long attrs)
61-
{
62-
unsigned long pfn = PFN_DOWN(handle);
63-
/*
64-
* Dom0 is mapped 1:1, while the Linux page can be spanned accross
65-
* multiple Xen page, it's not possible to have a mix of local and
66-
* foreign Xen page. Dom0 is mapped 1:1, so calling pfn_valid on a
67-
* foreign mfn will always return false. If the page is local we can
68-
* safely call the native dma_ops function, otherwise we call the xen
69-
* specific function.
70-
*/
71-
if (pfn_valid(pfn))
72-
dma_direct_unmap_page(hwdev, handle, size, dir, attrs);
73-
else
74-
__xen_dma_unmap_page(hwdev, handle, size, dir, attrs);
75-
}
76-
77-
#endif /* _ASM_ARM64_XEN_PAGE_COHERENT_H */

‎include/xen/arm/page-coherent.h‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#ifndef _XEN_ARM_PAGE_COHERENT_H
33
#define _XEN_ARM_PAGE_COHERENT_H
44

5+
#include <linux/dma-mapping.h>
6+
#include <asm/page.h>
7+
58
void __xen_dma_map_page(struct device *hwdev, struct page *page,
69
dma_addr_t dev_addr, unsigned long offset, size_t size,
710
enum dma_data_direction dir, unsigned long attrs);
@@ -13,4 +16,81 @@ void __xen_dma_sync_single_for_cpu(struct device *hwdev,
1316
void __xen_dma_sync_single_for_device(struct device *hwdev,
1417
dma_addr_t handle, size_t size, enum dma_data_direction dir);
1518

19+
static inline void *xen_alloc_coherent_pages(struct device *hwdev, size_t size,
20+
dma_addr_t *dma_handle, gfp_t flags, unsigned long attrs)
21+
{
22+
return dma_direct_alloc(hwdev, size, dma_handle, flags, attrs);
23+
}
24+
25+
static inline void xen_free_coherent_pages(struct device *hwdev, size_t size,
26+
void *cpu_addr, dma_addr_t dma_handle, unsigned long attrs)
27+
{
28+
dma_direct_free(hwdev, size, cpu_addr, dma_handle, attrs);
29+
}
30+
31+
static inline void xen_dma_sync_single_for_cpu(struct device *hwdev,
32+
dma_addr_t handle, size_t size, enum dma_data_direction dir)
33+
{
34+
unsigned long pfn = PFN_DOWN(handle);
35+
36+
if (pfn_valid(pfn))
37+
dma_direct_sync_single_for_cpu(hwdev, handle, size, dir);
38+
else
39+
__xen_dma_sync_single_for_cpu(hwdev, handle, size, dir);
40+
}
41+
42+
static inline void xen_dma_sync_single_for_device(struct device *hwdev,
43+
dma_addr_t handle, size_t size, enum dma_data_direction dir)
44+
{
45+
unsigned long pfn = PFN_DOWN(handle);
46+
if (pfn_valid(pfn))
47+
dma_direct_sync_single_for_device(hwdev, handle, size, dir);
48+
else
49+
__xen_dma_sync_single_for_device(hwdev, handle, size, dir);
50+
}
51+
52+
static inline void xen_dma_map_page(struct device *hwdev, struct page *page,
53+
dma_addr_t dev_addr, unsigned long offset, size_t size,
54+
enum dma_data_direction dir, unsigned long attrs)
55+
{
56+
unsigned long page_pfn = page_to_xen_pfn(page);
57+
unsigned long dev_pfn = XEN_PFN_DOWN(dev_addr);
58+
unsigned long compound_pages =
59+
(1<<compound_order(page)) * XEN_PFN_PER_PAGE;
60+
bool local = (page_pfn <= dev_pfn) &&
61+
(dev_pfn - page_pfn < compound_pages);
62+
63+
/*
64+
* Dom0 is mapped 1:1, while the Linux page can span across
65+
* multiple Xen pages, it's not possible for it to contain a
66+
* mix of local and foreign Xen pages. So if the first xen_pfn
67+
* == mfn the page is local otherwise it's a foreign page
68+
* grant-mapped in dom0. If the page is local we can safely
69+
* call the native dma_ops function, otherwise we call the xen
70+
* specific function.
71+
*/
72+
if (local)
73+
dma_direct_map_page(hwdev, page, offset, size, dir, attrs);
74+
else
75+
__xen_dma_map_page(hwdev, page, dev_addr, offset, size, dir, attrs);
76+
}
77+
78+
static inline void xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle,
79+
size_t size, enum dma_data_direction dir, unsigned long attrs)
80+
{
81+
unsigned long pfn = PFN_DOWN(handle);
82+
/*
83+
* Dom0 is mapped 1:1, while the Linux page can be spanned accross
84+
* multiple Xen page, it's not possible to have a mix of local and
85+
* foreign Xen page. Dom0 is mapped 1:1, so calling pfn_valid on a
86+
* foreign mfn will always return false. If the page is local we can
87+
* safely call the native dma_ops function, otherwise we call the xen
88+
* specific function.
89+
*/
90+
if (pfn_valid(pfn))
91+
dma_direct_unmap_page(hwdev, handle, size, dir, attrs);
92+
else
93+
__xen_dma_unmap_page(hwdev, handle, size, dir, attrs);
94+
}
95+
1696
#endif /* _XEN_ARM_PAGE_COHERENT_H */

0 commit comments

Comments
 (0)