diff options
author | royger <royger@FreeBSD.org> | 2014-06-16 08:48:42 +0000 |
---|---|---|
committer | royger <royger@FreeBSD.org> | 2014-06-16 08:48:42 +0000 |
commit | f013e4ff53da712d502ee27018f0a631f47b442c (patch) | |
tree | 4477500f87829c29d6037ef7592fe4503fb7878b /sys/xen/gnttab.c | |
parent | 8cb3293c2284670ddeecbac6a6a274b5cc9ad995 (diff) | |
download | FreeBSD-src-f013e4ff53da712d502ee27018f0a631f47b442c.zip FreeBSD-src-f013e4ff53da712d502ee27018f0a631f47b442c.tar.gz |
xen: unify gnttab initialization for PVHVM and PVH
Switch the initialization of gnttab to use an unused physical memory
range for both PVHVM and PVH.
In the past PVHVM was using the xenpci BAR, but there's no reason to
do that, and in fact FreeBSD was probably doing it because it was the
way it was done in Windows, were drivers cannot probably request for
unused physical memory ranges, but it was never enforced in the
hypervisor.
Sponsored by: Citrix Systems R&D
Approved by: gibbs
xen/gnttab.c:
- Allocate contiguous physical memory for grant table frames for both
PVHVM and PVH.
- Since gnttab is not a device, use the xenpv device in order to
request for this allocation.
dev/xen/xenpci/xenpcivar.h:
dev/xen/xenpci/xenpci.c:
- Remove the now unused xenpci_alloc_space and xenpci_alloc_space_int
functions.
xen/gnttab.h:
- Change the prototype of gnttab_init and gnttab_resume, that now
takes a device_t parameter.
dev/xen/control/control.c:
x86/xen/xenpv.c:
- Changes to accomodate the new prototype of gnttab_init and
gnttab_resume.
Diffstat (limited to 'sys/xen/gnttab.c')
-rw-r--r-- | sys/xen/gnttab.c | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/sys/xen/gnttab.c b/sys/xen/gnttab.c index 03c32b7..ca6fa3b 100644 --- a/sys/xen/gnttab.c +++ b/sys/xen/gnttab.c @@ -25,6 +25,9 @@ __FBSDID("$FreeBSD$"); #include <sys/lock.h> #include <sys/malloc.h> #include <sys/mman.h> +#include <sys/limits.h> +#include <sys/rman.h> +#include <machine/resource.h> #include <xen/xen-os.h> #include <xen/hypervisor.h> @@ -51,6 +54,17 @@ static int gnttab_free_count; static grant_ref_t gnttab_free_head; static struct mtx gnttab_list_lock; +#ifdef XENHVM +/* + * Resource representing allocated physical address space + * for the grant table metainfo + */ +static struct resource *gnttab_pseudo_phys_res; + +/* Resource id for allocated physical address space. */ +static int gnttab_pseudo_phys_res_id; +#endif + static grant_entry_t *shared; static struct gnttab_free_callback *gnttab_free_callback_list = NULL; @@ -542,7 +556,7 @@ gnttab_map(unsigned int start_idx, unsigned int end_idx) } int -gnttab_resume(void) +gnttab_resume(device_t dev) { if (max_nr_grant_frames() < nr_grant_frames) @@ -563,8 +577,6 @@ gnttab_suspend(void) #else /* XENHVM */ -#include <dev/xen/xenpci/xenpcivar.h> - static vm_paddr_t resume_frames; static int @@ -603,9 +615,8 @@ gnttab_map(unsigned int start_idx, unsigned int end_idx) } int -gnttab_resume(void) +gnttab_resume(device_t dev) { - int error; unsigned int max_nr_gframes, nr_gframes; nr_gframes = nr_grant_frames; @@ -614,12 +625,15 @@ gnttab_resume(void) return (ENOSYS); if (!resume_frames) { - error = xenpci_alloc_space(PAGE_SIZE * max_nr_gframes, - &resume_frames); - if (error) { - printf("error mapping gnttab share frames\n"); - return (error); - } + KASSERT(dev != NULL, + ("No resume frames and no device provided")); + + gnttab_pseudo_phys_res = bus_alloc_resource(dev, + SYS_RES_MEMORY, &gnttab_pseudo_phys_res_id, 0, ~0, + PAGE_SIZE * max_nr_gframes, RF_ACTIVE); + if (gnttab_pseudo_phys_res == NULL) + panic("Unable to reserve physical memory for gnttab"); + resume_frames = rman_get_start(gnttab_pseudo_phys_res); } return (gnttab_map(0, nr_gframes - 1)); @@ -647,7 +661,7 @@ gnttab_expand(unsigned int req_entries) } int -gnttab_init() +gnttab_init(device_t dev) { int i; unsigned int max_nr_glist_frames; @@ -679,7 +693,7 @@ gnttab_init() goto ini_nomem; } - if (gnttab_resume()) + if (gnttab_resume(dev)) return (ENODEV); nr_init_grefs = nr_grant_frames * GREFS_PER_GRANT_FRAME; |