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
1
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
564eb71
Documentation
arch
block
crypto
drivers
accessibility
acpi
amba
ata
atm
auxdisplay
base
bcma
block
bluetooth
bus
cdrom
char
clk
clocksource
connector
cpufreq
cpuidle
crypto
dca
devfreq
dio
dma
edac
eisa
extcon
firewire
firmware
fmc
gpio
gpu
hid
hsi
hv
hwmon
hwspinlock
i2c
ide
idle
iio
infiniband
input
iommu
ipack
irqchip
isdn
leds
lguest
macintosh
mailbox
md
media
memory
memstick
message
mfd
misc
mmc
mtd
net
nfc
ntb
nubus
of
oprofile
parisc
parport
pci
pcmcia
phy
pinctrl
platform
pnp
power
powercap
pps
ps3
ptp
pwm
rapidio
regulator
remoteproc
reset
rpmsg
rtc
s390
sbus
scsi
sfi
sh
sn
spi
ssb
staging
target
tc
thermal
tty
uio
usb
uwb
vfio
vhost
video
virt
virtio
vlynq
vme
w1
watchdog
xen
events
xen-pciback
xenbus
xenfs
Kconfig
Makefile
acpi.c
balloon.c
biomerge.c
cpu_hotplug.c
dbgp.c
evtchn.c
fallback.c
features.c
gntalloc.c
gntdev.c
grant-table.c
manage.c
mcelog.c
pci.c
pcpu.c
platform-pci.c
privcmd.c
privcmd.h
swiotlb-xen.c
sys-hypervisor.c
tmem.c
xen-acpi-cpuhotplug.c
xen-acpi-memhotplug.c
xen-acpi-pad.c
xen-acpi-processor.c
xen-balloon.c
xen-selfballoon.c
xen-stub.c
xencomm.c
zorro
Kconfig
Makefile
firmware
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
REPORTING-BUGS
Breadcrumbs
linux
/
drivers
/
xen
/
xencomm.c
Copy path
Blame
Blame
Latest commit
History
History
219 lines (178 loc) · 5.47 KB
Breadcrumbs
linux
/
drivers
/
xen
/
xencomm.c
Top
File metadata and controls
Code
Blame
219 lines (178 loc) · 5.47 KB
Raw
/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Copyright (C) IBM Corp. 2006 * * Authors: Hollis Blanchard <hollisb@us.ibm.com> */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/mm.h> #include <linux/slab.h> #include <asm/page.h> #include <xen/xencomm.h> #include <xen/interface/xen.h> #include <asm/xen/xencomm.h> /* for xencomm_is_phys_contiguous() */ static int xencomm_init(struct xencomm_desc *desc, void *buffer, unsigned long bytes) { unsigned long recorded = 0; int i = 0; while ((recorded < bytes) && (i < desc->nr_addrs)) { unsigned long vaddr = (unsigned long)buffer + recorded; unsigned long paddr; int offset; int chunksz; offset = vaddr % PAGE_SIZE; /* handle partial pages */ chunksz = min(PAGE_SIZE - offset, bytes - recorded); paddr = xencomm_vtop(vaddr); if (paddr == ~0UL) { printk(KERN_DEBUG "%s: couldn't translate vaddr %lx\n", __func__, vaddr); return -EINVAL; } desc->address[i++] = paddr; recorded += chunksz; } if (recorded < bytes) { printk(KERN_DEBUG "%s: could only translate %ld of %ld bytes\n", __func__, recorded, bytes); return -ENOSPC; } /* mark remaining addresses invalid (just for safety) */ while (i < desc->nr_addrs) desc->address[i++] = XENCOMM_INVALID; desc->magic = XENCOMM_MAGIC; return 0; } static struct xencomm_desc *xencomm_alloc(gfp_t gfp_mask, void *buffer, unsigned long bytes) { struct xencomm_desc *desc; unsigned long buffer_ulong = (unsigned long)buffer; unsigned long start = buffer_ulong & PAGE_MASK; unsigned long end = (buffer_ulong + bytes) | ~PAGE_MASK; unsigned long nr_addrs = (end - start + 1) >> PAGE_SHIFT; unsigned long size = sizeof(*desc) + sizeof(desc->address[0]) * nr_addrs; /* * slab allocator returns at least sizeof(void*) aligned pointer. * When sizeof(*desc) > sizeof(void*), struct xencomm_desc might * cross page boundary. */ if (sizeof(*desc) > sizeof(void *)) { unsigned long order = get_order(size); desc = (struct xencomm_desc *)__get_free_pages(gfp_mask, order); if (desc == NULL) return NULL; desc->nr_addrs = ((PAGE_SIZE << order) - sizeof(struct xencomm_desc)) / sizeof(*desc->address); } else { desc = kmalloc(size, gfp_mask); if (desc == NULL) return NULL; desc->nr_addrs = nr_addrs; } return desc; } void xencomm_free(struct xencomm_handle *desc) { if (desc && !((ulong)desc & XENCOMM_INLINE_FLAG)) { struct xencomm_desc *desc__ = (struct xencomm_desc *)desc; if (sizeof(*desc__) > sizeof(void *)) { unsigned long size = sizeof(*desc__) + sizeof(desc__->address[0]) * desc__->nr_addrs; unsigned long order = get_order(size); free_pages((unsigned long)__va(desc), order); } else kfree(__va(desc)); } } static int xencomm_create(void *buffer, unsigned long bytes, struct xencomm_desc **ret, gfp_t gfp_mask) { struct xencomm_desc *desc; int rc; pr_debug("%s: %p[%ld]\n", __func__, buffer, bytes); if (bytes == 0) { /* don't create a descriptor; Xen recognizes NULL. */ BUG_ON(buffer != NULL); *ret = NULL; return 0; } BUG_ON(buffer == NULL); /* 'bytes' is non-zero */ desc = xencomm_alloc(gfp_mask, buffer, bytes); if (!desc) { printk(KERN_DEBUG "%s failure\n", "xencomm_alloc"); return -ENOMEM; } rc = xencomm_init(desc, buffer, bytes); if (rc) { printk(KERN_DEBUG "%s failure: %d\n", "xencomm_init", rc); xencomm_free((struct xencomm_handle *)__pa(desc)); return rc; } *ret = desc; return 0; } static struct xencomm_handle *xencomm_create_inline(void *ptr) { unsigned long paddr; BUG_ON(!xencomm_is_phys_contiguous((unsigned long)ptr)); paddr = (unsigned long)xencomm_pa(ptr); BUG_ON(paddr & XENCOMM_INLINE_FLAG); return (struct xencomm_handle *)(paddr | XENCOMM_INLINE_FLAG); } /* "mini" routine, for stack-based communications: */ static int xencomm_create_mini(void *buffer, unsigned long bytes, struct xencomm_mini *xc_desc, struct xencomm_desc **ret) { int rc = 0; struct xencomm_desc *desc; BUG_ON(((unsigned long)xc_desc) % sizeof(*xc_desc) != 0); desc = (void *)xc_desc; desc->nr_addrs = XENCOMM_MINI_ADDRS; rc = xencomm_init(desc, buffer, bytes); if (!rc) *ret = desc; return rc; } struct xencomm_handle *xencomm_map(void *ptr, unsigned long bytes) { int rc; struct xencomm_desc *desc; if (xencomm_is_phys_contiguous((unsigned long)ptr)) return xencomm_create_inline(ptr); rc = xencomm_create(ptr, bytes, &desc, GFP_KERNEL); if (rc || desc == NULL) return NULL; return xencomm_pa(desc); } struct xencomm_handle *__xencomm_map_no_alloc(void *ptr, unsigned long bytes, struct xencomm_mini *xc_desc) { int rc; struct xencomm_desc *desc = NULL; if (xencomm_is_phys_contiguous((unsigned long)ptr)) return xencomm_create_inline(ptr); rc = xencomm_create_mini(ptr, bytes, xc_desc, &desc); if (rc) return NULL; return xencomm_pa(desc); }
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
You can’t perform that action at this time.