Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
50dfd03
Documentation
LICENSES
arch
alpha
arc
arm
boot
common
configs
crypto
include
kernel
kvm
lib
mach-actions
mach-alpine
mach-artpec
mach-asm9260
mach-aspeed
mach-at91
mach-axxia
mach-bcm
mach-berlin
mach-clps711x
mach-cns3xxx
mach-davinci
mach-digicolor
mach-dove
mach-ebsa110
mach-efm32
mach-ep93xx
mach-exynos
mach-footbridge
mach-gemini
mach-highbank
mach-hisi
mach-imx
mach-integrator
mach-iop32x
mach-ixp4xx
mach-keystone
mach-lpc18xx
mach-lpc32xx
mach-mediatek
mach-meson
mach-milbeaut
mach-mmp
mach-moxart
mach-mv78xx0
mach-mvebu
mach-mxs
mach-nomadik
mach-npcm
mach-nspire
mach-omap1
mach-omap2
mach-orion5x
mach-oxnas
mach-picoxcell
mach-prima2
mach-pxa
mach-qcom
mach-rda
mach-realview
mach-rockchip
mach-rpc
mach-s3c24xx
mach-s3c64xx
mach-s5pv210
mach-sa1100
mach-shmobile
mach-socfpga
mach-spear
mach-sti
mach-stm32
mach-sunxi
mach-tango
mach-tegra
mach-u300
mach-uniphier
mach-ux500
mach-versatile
mach-vexpress
mach-vt8500
mach-zx
mach-zynq
mm
net
nwfpe
oprofile
plat-omap
plat-orion
plat-pxa
plat-samsung
plat-versatile
probes
tools
vdso
vfp
xen
Makefile
enlighten.c
grant-table.c
hypercall.S
mm.c
p2m.c
Kconfig
Kconfig-nommu
Kconfig.debug
Makefile
arm64
c6x
csky
h8300
hexagon
ia64
m68k
microblaze
mips
nds32
nios2
openrisc
parisc
powerpc
riscv
s390
sh
sparc
um
unicore32
x86
xtensa
.gitignore
Kconfig
block
certs
crypto
drivers
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
arch
/
arm
/
xen
/
mm.c
Copy path
Blame
Blame
Latest commit
History
History
151 lines (132 loc) · 4.19 KB
Breadcrumbs
linux
/
arch
/
arm
/
xen
/
mm.c
Top
File metadata and controls
Code
Blame
151 lines (132 loc) · 4.19 KB
Raw
// SPDX-License-Identifier: GPL-2.0-only #include <linux/cpu.h> #include <linux/dma-noncoherent.h> #include <linux/gfp.h> #include <linux/highmem.h> #include <linux/export.h> #include <linux/memblock.h> #include <linux/of_address.h> #include <linux/slab.h> #include <linux/types.h> #include <linux/vmalloc.h> #include <linux/swiotlb.h> #include <xen/xen.h> #include <xen/interface/grant_table.h> #include <xen/interface/memory.h> #include <xen/page.h> #include <xen/swiotlb-xen.h> #include <asm/cacheflush.h> #include <asm/xen/hypercall.h> #include <asm/xen/interface.h> unsigned long xen_get_swiotlb_free_pages(unsigned int order) { struct memblock_region *reg; gfp_t flags = __GFP_NOWARN|__GFP_KSWAPD_RECLAIM; for_each_memblock(memory, reg) { if (reg->base < (phys_addr_t)0xffffffff) { if (IS_ENABLED(CONFIG_ZONE_DMA32)) flags |= __GFP_DMA32; else flags |= __GFP_DMA; break; } } return __get_free_pages(flags, order); } static bool hypercall_cflush = false; /* buffers in highmem or foreign pages cannot cross page boundaries */ static void dma_cache_maint(dma_addr_t handle, size_t size, u32 op) { struct gnttab_cache_flush cflush; cflush.a.dev_bus_addr = handle & XEN_PAGE_MASK; cflush.offset = xen_offset_in_page(handle); cflush.op = op; do { if (size + cflush.offset > XEN_PAGE_SIZE) cflush.length = XEN_PAGE_SIZE - cflush.offset; else cflush.length = size; HYPERVISOR_grant_table_op(GNTTABOP_cache_flush, &cflush, 1); cflush.offset = 0; cflush.a.dev_bus_addr += cflush.length; size -= cflush.length; } while (size); } /* * Dom0 is mapped 1:1, and while the Linux page can span across multiple Xen * pages, it is not possible for it to contain a mix of local and foreign Xen * pages. Calling pfn_valid on a foreign mfn will always return false, so if * pfn_valid returns true the pages is local and we can use the native * dma-direct functions, otherwise we call the Xen specific version. */ void xen_dma_sync_for_cpu(struct device *dev, dma_addr_t handle, phys_addr_t paddr, size_t size, enum dma_data_direction dir) { if (pfn_valid(PFN_DOWN(handle))) arch_sync_dma_for_cpu(dev, paddr, size, dir); else if (dir != DMA_TO_DEVICE) dma_cache_maint(handle, size, GNTTAB_CACHE_INVAL); } void xen_dma_sync_for_device(struct device *dev, dma_addr_t handle, phys_addr_t paddr, size_t size, enum dma_data_direction dir) { if (pfn_valid(PFN_DOWN(handle))) arch_sync_dma_for_device(dev, paddr, size, dir); else if (dir == DMA_FROM_DEVICE) dma_cache_maint(handle, size, GNTTAB_CACHE_INVAL); else dma_cache_maint(handle, size, GNTTAB_CACHE_CLEAN); } bool xen_arch_need_swiotlb(struct device *dev, phys_addr_t phys, dma_addr_t dev_addr) { unsigned int xen_pfn = XEN_PFN_DOWN(phys); unsigned int bfn = XEN_PFN_DOWN(dev_addr); /* * The swiotlb buffer should be used if * - Xen doesn't have the cache flush hypercall * - The Linux page refers to foreign memory * - The device doesn't support coherent DMA request * * The Linux page may be spanned acrros multiple Xen page, although * it's not possible to have a mix of local and foreign Xen page. * Furthermore, range_straddles_page_boundary is already checking * if buffer is physically contiguous in the host RAM. * * Therefore we only need to check the first Xen page to know if we * require a bounce buffer because the device doesn't support coherent * memory and we are not able to flush the cache. */ return (!hypercall_cflush && (xen_pfn != bfn) && !dev_is_dma_coherent(dev)); } int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order, unsigned int address_bits, dma_addr_t *dma_handle) { if (!xen_initial_domain()) return -EINVAL; /* we assume that dom0 is mapped 1:1 for now */ *dma_handle = pstart; return 0; } void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order) { return; } int __init xen_mm_init(void) { struct gnttab_cache_flush cflush; if (!xen_initial_domain()) return 0; xen_swiotlb_init(1, false); cflush.op = 0; cflush.a.dev_bus_addr = 0; cflush.offset = 0; cflush.length = 0; if (HYPERVISOR_grant_table_op(GNTTABOP_cache_flush, &cflush, 1) != -ENOSYS) hypercall_cflush = true; return 0; } arch_initcall(xen_mm_init);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
You can’t perform that action at this time.