Skip to content

Commit

Permalink
xen/grant-table: Add an helper to iterate over a specific number of g…
Browse files Browse the repository at this point in the history
…rants

With the 64KB page granularity support on ARM64, a Linux page may be
split accross multiple grant.

Currently we have the helper gnttab_foreach_grant_in_grant to break a
Linux page based on an offset and a len, but it doesn't fit when we only
have a number of grants in hand.

Introduce a new helper which take an array of Linux page and a number of
grant and will figure out the address of each grant.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Signed-off-by: David Vrabel <david.vrabel@citrix.com>
  • Loading branch information
Julien Grall authored and David Vrabel committed Oct 23, 2015
1 parent 9cce291 commit f73314b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
22 changes: 22 additions & 0 deletions drivers/xen/grant-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,28 @@ void gnttab_foreach_grant_in_range(struct page *page,
}
EXPORT_SYMBOL_GPL(gnttab_foreach_grant_in_range);

void gnttab_foreach_grant(struct page **pages,
unsigned int nr_grefs,
xen_grant_fn_t fn,
void *data)
{
unsigned int goffset = 0;
unsigned long xen_pfn = 0;
unsigned int i;

for (i = 0; i < nr_grefs; i++) {
if ((i % XEN_PFN_PER_PAGE) == 0) {
xen_pfn = page_to_xen_pfn(pages[i / XEN_PFN_PER_PAGE]);
goffset = 0;
}

fn(pfn_to_gfn(xen_pfn), goffset, XEN_PAGE_SIZE, data);

goffset += XEN_PAGE_SIZE;
xen_pfn++;
}
}

int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
struct gnttab_map_grant_ref *kmap_ops,
struct page **pages, unsigned int count)
Expand Down
6 changes: 6 additions & 0 deletions include/xen/grant_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ static inline void gnttab_for_one_grant(struct page *page, unsigned int offset,
gnttab_foreach_grant_in_range(page, offset, len, fn, data);
}

/* Get @nr_grefs grants from an array of page and call fn for each grant */
void gnttab_foreach_grant(struct page **pages,
unsigned int nr_grefs,
xen_grant_fn_t fn,
void *data);

/* Get the number of grant in a specified region
*
* start: Offset from the beginning of the first page
Expand Down

0 comments on commit f73314b

Please sign in to comment.