From a8f2f559f3f266431ce7a60ba8ed9721fb9fd83c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Mon, 16 Jun 2014 08:48:42 +0000 Subject: 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. --- sys/xen/gnttab.c | 40 +++++++++++++++++++++++++++------------- sys/xen/gnttab.h | 4 ++-- 2 files changed, 29 insertions(+), 15 deletions(-) (limited to 'sys/xen') diff --git a/sys/xen/gnttab.c b/sys/xen/gnttab.c index 03c32b724fd6..ca6fa3b8863c 100644 --- a/sys/xen/gnttab.c +++ b/sys/xen/gnttab.c @@ -25,6 +25,9 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include +#include +#include #include #include @@ -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 - 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; diff --git a/sys/xen/gnttab.h b/sys/xen/gnttab.h index d81e965fc43a..afbe600607a0 100644 --- a/sys/xen/gnttab.h +++ b/sys/xen/gnttab.h @@ -51,7 +51,7 @@ struct gnttab_free_callback { uint16_t count; }; -int gnttab_init(void); +int gnttab_init(device_t); /* * Allocate a grant table reference and return it in *result. Returns @@ -116,7 +116,7 @@ void gnttab_grant_foreign_transfer_ref(grant_ref_t, domid_t domid, unsigned long pfn); int gnttab_suspend(void); -int gnttab_resume(void); +int gnttab_resume(device_t); #if 0 -- cgit v1.2.3