diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-01-13 21:46:48 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-01-13 21:46:48 -0500 |
commit | 9c4bc1c2befbbdce4b9fd526e67a7a2ea143ffa2 (patch) | |
tree | 1b08c1bb00ce477ca947461777cd7e24de72c148 /include | |
parent | 2c0076d8c7eb1dafa03d0a792444862080b34106 (diff) | |
parent | e1b478e4ec4477520767d1a920433626263a2a6b (diff) |
Merge branch 'stable/gntdev' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen
* 'stable/gntdev' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen:
xen/p2m: Fix module linking error.
xen p2m: clear the old pte when adding a page to m2p_override
xen gntdev: use gnttab_map_refs and gnttab_unmap_refs
xen: introduce gnttab_map_refs and gnttab_unmap_refs
xen p2m: transparently change the p2m mappings in the m2p override
xen/gntdev: Fix circular locking dependency
xen/gntdev: stop using "token" argument
xen: gntdev: move use of GNTMAP_contains_pte next to the map_op
xen: add m2p override mechanism
xen: move p2m handling to separate file
xen/gntdev: add VM_PFNMAP to vma
xen/gntdev: allow usermode to map granted pages
xen: define gnttab_set_map_op/unmap_op
Fix up trivial conflict in drivers/xen/Kconfig
Diffstat (limited to 'include')
-rw-r--r-- | include/xen/gntdev.h | 119 | ||||
-rw-r--r-- | include/xen/grant_table.h | 44 |
2 files changed, 162 insertions, 1 deletions
diff --git a/include/xen/gntdev.h b/include/xen/gntdev.h new file mode 100644 index 000000000000..eb23f4188f5a --- /dev/null +++ b/include/xen/gntdev.h | |||
@@ -0,0 +1,119 @@ | |||
1 | /****************************************************************************** | ||
2 | * gntdev.h | ||
3 | * | ||
4 | * Interface to /dev/xen/gntdev. | ||
5 | * | ||
6 | * Copyright (c) 2007, D G Murray | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License version 2 | ||
10 | * as published by the Free Software Foundation; or, when distributed | ||
11 | * separately from the Linux kernel or incorporated into other | ||
12 | * software packages, subject to the following license: | ||
13 | * | ||
14 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
15 | * of this source file (the "Software"), to deal in the Software without | ||
16 | * restriction, including without limitation the rights to use, copy, modify, | ||
17 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, | ||
18 | * and to permit persons to whom the Software is furnished to do so, subject to | ||
19 | * the following conditions: | ||
20 | * | ||
21 | * The above copyright notice and this permission notice shall be included in | ||
22 | * all copies or substantial portions of the Software. | ||
23 | * | ||
24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
29 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
30 | * IN THE SOFTWARE. | ||
31 | */ | ||
32 | |||
33 | #ifndef __LINUX_PUBLIC_GNTDEV_H__ | ||
34 | #define __LINUX_PUBLIC_GNTDEV_H__ | ||
35 | |||
36 | struct ioctl_gntdev_grant_ref { | ||
37 | /* The domain ID of the grant to be mapped. */ | ||
38 | uint32_t domid; | ||
39 | /* The grant reference of the grant to be mapped. */ | ||
40 | uint32_t ref; | ||
41 | }; | ||
42 | |||
43 | /* | ||
44 | * Inserts the grant references into the mapping table of an instance | ||
45 | * of gntdev. N.B. This does not perform the mapping, which is deferred | ||
46 | * until mmap() is called with @index as the offset. | ||
47 | */ | ||
48 | #define IOCTL_GNTDEV_MAP_GRANT_REF \ | ||
49 | _IOC(_IOC_NONE, 'G', 0, sizeof(struct ioctl_gntdev_map_grant_ref)) | ||
50 | struct ioctl_gntdev_map_grant_ref { | ||
51 | /* IN parameters */ | ||
52 | /* The number of grants to be mapped. */ | ||
53 | uint32_t count; | ||
54 | uint32_t pad; | ||
55 | /* OUT parameters */ | ||
56 | /* The offset to be used on a subsequent call to mmap(). */ | ||
57 | uint64_t index; | ||
58 | /* Variable IN parameter. */ | ||
59 | /* Array of grant references, of size @count. */ | ||
60 | struct ioctl_gntdev_grant_ref refs[1]; | ||
61 | }; | ||
62 | |||
63 | /* | ||
64 | * Removes the grant references from the mapping table of an instance of | ||
65 | * of gntdev. N.B. munmap() must be called on the relevant virtual address(es) | ||
66 | * before this ioctl is called, or an error will result. | ||
67 | */ | ||
68 | #define IOCTL_GNTDEV_UNMAP_GRANT_REF \ | ||
69 | _IOC(_IOC_NONE, 'G', 1, sizeof(struct ioctl_gntdev_unmap_grant_ref)) | ||
70 | struct ioctl_gntdev_unmap_grant_ref { | ||
71 | /* IN parameters */ | ||
72 | /* The offset was returned by the corresponding map operation. */ | ||
73 | uint64_t index; | ||
74 | /* The number of pages to be unmapped. */ | ||
75 | uint32_t count; | ||
76 | uint32_t pad; | ||
77 | }; | ||
78 | |||
79 | /* | ||
80 | * Returns the offset in the driver's address space that corresponds | ||
81 | * to @vaddr. This can be used to perform a munmap(), followed by an | ||
82 | * UNMAP_GRANT_REF ioctl, where no state about the offset is retained by | ||
83 | * the caller. The number of pages that were allocated at the same time as | ||
84 | * @vaddr is returned in @count. | ||
85 | * | ||
86 | * N.B. Where more than one page has been mapped into a contiguous range, the | ||
87 | * supplied @vaddr must correspond to the start of the range; otherwise | ||
88 | * an error will result. It is only possible to munmap() the entire | ||
89 | * contiguously-allocated range at once, and not any subrange thereof. | ||
90 | */ | ||
91 | #define IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR \ | ||
92 | _IOC(_IOC_NONE, 'G', 2, sizeof(struct ioctl_gntdev_get_offset_for_vaddr)) | ||
93 | struct ioctl_gntdev_get_offset_for_vaddr { | ||
94 | /* IN parameters */ | ||
95 | /* The virtual address of the first mapped page in a range. */ | ||
96 | uint64_t vaddr; | ||
97 | /* OUT parameters */ | ||
98 | /* The offset that was used in the initial mmap() operation. */ | ||
99 | uint64_t offset; | ||
100 | /* The number of pages mapped in the VM area that begins at @vaddr. */ | ||
101 | uint32_t count; | ||
102 | uint32_t pad; | ||
103 | }; | ||
104 | |||
105 | /* | ||
106 | * Sets the maximum number of grants that may mapped at once by this gntdev | ||
107 | * instance. | ||
108 | * | ||
109 | * N.B. This must be called before any other ioctl is performed on the device. | ||
110 | */ | ||
111 | #define IOCTL_GNTDEV_SET_MAX_GRANTS \ | ||
112 | _IOC(_IOC_NONE, 'G', 3, sizeof(struct ioctl_gntdev_set_max_grants)) | ||
113 | struct ioctl_gntdev_set_max_grants { | ||
114 | /* IN parameter */ | ||
115 | /* The maximum number of grants that may be mapped at once. */ | ||
116 | uint32_t count; | ||
117 | }; | ||
118 | |||
119 | #endif /* __LINUX_PUBLIC_GNTDEV_H__ */ | ||
diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h index 9a731706a016..b1fab6b5b3ef 100644 --- a/include/xen/grant_table.h +++ b/include/xen/grant_table.h | |||
@@ -37,10 +37,16 @@ | |||
37 | #ifndef __ASM_GNTTAB_H__ | 37 | #ifndef __ASM_GNTTAB_H__ |
38 | #define __ASM_GNTTAB_H__ | 38 | #define __ASM_GNTTAB_H__ |
39 | 39 | ||
40 | #include <asm/xen/hypervisor.h> | 40 | #include <asm/page.h> |
41 | |||
42 | #include <xen/interface/xen.h> | ||
41 | #include <xen/interface/grant_table.h> | 43 | #include <xen/interface/grant_table.h> |
44 | |||
45 | #include <asm/xen/hypervisor.h> | ||
42 | #include <asm/xen/grant_table.h> | 46 | #include <asm/xen/grant_table.h> |
43 | 47 | ||
48 | #include <xen/features.h> | ||
49 | |||
44 | /* NR_GRANT_FRAMES must be less than or equal to that configured in Xen */ | 50 | /* NR_GRANT_FRAMES must be less than or equal to that configured in Xen */ |
45 | #define NR_GRANT_FRAMES 4 | 51 | #define NR_GRANT_FRAMES 4 |
46 | 52 | ||
@@ -107,6 +113,37 @@ void gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid, | |||
107 | void gnttab_grant_foreign_transfer_ref(grant_ref_t, domid_t domid, | 113 | void gnttab_grant_foreign_transfer_ref(grant_ref_t, domid_t domid, |
108 | unsigned long pfn); | 114 | unsigned long pfn); |
109 | 115 | ||
116 | static inline void | ||
117 | gnttab_set_map_op(struct gnttab_map_grant_ref *map, phys_addr_t addr, | ||
118 | uint32_t flags, grant_ref_t ref, domid_t domid) | ||
119 | { | ||
120 | if (flags & GNTMAP_contains_pte) | ||
121 | map->host_addr = addr; | ||
122 | else if (xen_feature(XENFEAT_auto_translated_physmap)) | ||
123 | map->host_addr = __pa(addr); | ||
124 | else | ||
125 | map->host_addr = addr; | ||
126 | |||
127 | map->flags = flags; | ||
128 | map->ref = ref; | ||
129 | map->dom = domid; | ||
130 | } | ||
131 | |||
132 | static inline void | ||
133 | gnttab_set_unmap_op(struct gnttab_unmap_grant_ref *unmap, phys_addr_t addr, | ||
134 | uint32_t flags, grant_handle_t handle) | ||
135 | { | ||
136 | if (flags & GNTMAP_contains_pte) | ||
137 | unmap->host_addr = addr; | ||
138 | else if (xen_feature(XENFEAT_auto_translated_physmap)) | ||
139 | unmap->host_addr = __pa(addr); | ||
140 | else | ||
141 | unmap->host_addr = addr; | ||
142 | |||
143 | unmap->handle = handle; | ||
144 | unmap->dev_bus_addr = 0; | ||
145 | } | ||
146 | |||
110 | int arch_gnttab_map_shared(unsigned long *frames, unsigned long nr_gframes, | 147 | int arch_gnttab_map_shared(unsigned long *frames, unsigned long nr_gframes, |
111 | unsigned long max_nr_gframes, | 148 | unsigned long max_nr_gframes, |
112 | struct grant_entry **__shared); | 149 | struct grant_entry **__shared); |
@@ -118,4 +155,9 @@ unsigned int gnttab_max_grant_frames(void); | |||
118 | 155 | ||
119 | #define gnttab_map_vaddr(map) ((void *)(map.host_virt_addr)) | 156 | #define gnttab_map_vaddr(map) ((void *)(map.host_virt_addr)) |
120 | 157 | ||
158 | int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops, | ||
159 | struct page **pages, unsigned int count); | ||
160 | int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops, | ||
161 | struct page **pages, unsigned int count); | ||
162 | |||
121 | #endif /* __ASM_GNTTAB_H__ */ | 163 | #endif /* __ASM_GNTTAB_H__ */ |