aboutsummaryrefslogtreecommitdiffstats
path: root/include/xen
diff options
context:
space:
mode:
authorJulien Grall <julien.grall@citrix.com>2015-06-19 12:49:03 -0400
committerDavid Vrabel <david.vrabel@citrix.com>2015-10-23 09:20:33 -0400
commit008c320a96d218712043f8db0111d5472697785c (patch)
treead1140a3a51567e5bb14b71fe002ba40db3bf681 /include/xen
parent1084b1988d22dc165c9dbbc2b0e057f9248ac4db (diff)
xen/grant: Introduce helpers to split a page into grant
Currently, a grant is always based on the Xen page granularity (i.e 4KB). When Linux is using a different page granularity, a single page will be split between multiple grants. The new helpers will be in charge of splitting the Linux page into grants and call a function given by the caller on each grant. Also provide an helper to count the number of grants within a given contiguous region. Note that the x86/include/asm/xen/page.h is now including xen/interface/grant_table.h rather than xen/grant_table.h. It's necessary because xen/grant_table.h depends on asm/xen/page.h and will break the compilation. Furthermore, only definition in interface/grant_table.h is required. Signed-off-by: Julien Grall <julien.grall@citrix.com> Reviewed-by: David Vrabel <david.vrabel@citrix.com> Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Signed-off-by: David Vrabel <david.vrabel@citrix.com>
Diffstat (limited to 'include/xen')
-rw-r--r--include/xen/grant_table.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h
index 4478f4b4aae2..05b5b08c2afc 100644
--- a/include/xen/grant_table.h
+++ b/include/xen/grant_table.h
@@ -45,8 +45,10 @@
45#include <asm/xen/hypervisor.h> 45#include <asm/xen/hypervisor.h>
46 46
47#include <xen/features.h> 47#include <xen/features.h>
48#include <xen/page.h>
48#include <linux/mm_types.h> 49#include <linux/mm_types.h>
49#include <linux/page-flags.h> 50#include <linux/page-flags.h>
51#include <linux/kernel.h>
50 52
51#define GNTTAB_RESERVED_XENSTORE 1 53#define GNTTAB_RESERVED_XENSTORE 1
52 54
@@ -224,4 +226,44 @@ static inline struct xen_page_foreign *xen_page_foreign(struct page *page)
224#endif 226#endif
225} 227}
226 228
229/* Split Linux page in chunk of the size of the grant and call fn
230 *
231 * Parameters of fn:
232 * gfn: guest frame number
233 * offset: offset in the grant
234 * len: length of the data in the grant.
235 * data: internal information
236 */
237typedef void (*xen_grant_fn_t)(unsigned long gfn, unsigned int offset,
238 unsigned int len, void *data);
239
240void gnttab_foreach_grant_in_range(struct page *page,
241 unsigned int offset,
242 unsigned int len,
243 xen_grant_fn_t fn,
244 void *data);
245
246/* Helper to get to call fn only on the first "grant chunk" */
247static inline void gnttab_for_one_grant(struct page *page, unsigned int offset,
248 unsigned len, xen_grant_fn_t fn,
249 void *data)
250{
251 /* The first request is limited to the size of one grant */
252 len = min_t(unsigned int, XEN_PAGE_SIZE - (offset & ~XEN_PAGE_MASK),
253 len);
254
255 gnttab_foreach_grant_in_range(page, offset, len, fn, data);
256}
257
258/* Get the number of grant in a specified region
259 *
260 * start: Offset from the beginning of the first page
261 * len: total length of data (can cross multiple page)
262 */
263static inline unsigned int gnttab_count_grant(unsigned int start,
264 unsigned int len)
265{
266 return XEN_PFN_UP(xen_offset_in_page(start) + len);
267}
268
227#endif /* __ASM_GNTTAB_H__ */ 269#endif /* __ASM_GNTTAB_H__ */