svn commit: r185388 - user/dfr/xenhvm/6/sys/xen
Doug Rabson
dfr at FreeBSD.org
Fri Nov 28 08:25:44 PST 2008
Author: dfr
Date: Fri Nov 28 16:25:43 2008
New Revision: 185388
URL: http://svn.freebsd.org/changeset/base/185388
Log:
Add Xen HVM support.
Modified:
user/dfr/xenhvm/6/sys/xen/gnttab.c
user/dfr/xenhvm/6/sys/xen/gnttab.h
Modified: user/dfr/xenhvm/6/sys/xen/gnttab.c
==============================================================================
--- user/dfr/xenhvm/6/sys/xen/gnttab.c Fri Nov 28 15:50:35 2008 (r185387)
+++ user/dfr/xenhvm/6/sys/xen/gnttab.c Fri Nov 28 16:25:43 2008 (r185388)
@@ -452,6 +452,8 @@ unmap_pte_fn(pte_t *pte, struct page *pm
}
#endif
+#ifndef XENHVM
+
static int
gnttab_map(unsigned int start_idx, unsigned int end_idx)
{
@@ -484,6 +486,8 @@ gnttab_map(unsigned int start_idx, unsig
PANIC_IF(area == 0);
shared = (grant_entry_t *)area;
}
+
+
for (i = 0; i < nr_gframes; i++)
PT_SET_MA(((caddr_t)shared) + i*PAGE_SIZE,
((vm_paddr_t)frames[i]) << PAGE_SHIFT | PG_RW | PG_V);
@@ -514,6 +518,59 @@ gnttab_suspend(void)
return (0);
}
+#else /* XENHVM */
+
+#include <dev/xen/xenpci/xenpcivar.h>
+
+static unsigned long resume_frames;
+
+static int gnttab_map(unsigned int start_idx, unsigned int end_idx)
+{
+ struct xen_add_to_physmap xatp;
+ unsigned int i = end_idx;
+
+ /* Loop backwards, so that the first hypercall has the largest index,
+ * ensuring that the table will grow only once.
+ */
+ do {
+ xatp.domid = DOMID_SELF;
+ xatp.idx = i;
+ xatp.space = XENMAPSPACE_grant_table;
+ xatp.gpfn = (resume_frames >> PAGE_SHIFT) + i;
+ if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp))
+ panic("HYPERVISOR_memory_op failed to map gnttab");
+ } while (i-- > start_idx);
+
+ shared = pmap_mapdev(resume_frames, (end_idx + 1) * PAGE_SIZE);
+
+ return (0);
+}
+
+int
+gnttab_resume(void)
+{
+ int error;
+ unsigned int max_nr_gframes, nr_gframes;
+
+ nr_gframes = nr_grant_frames;
+ max_nr_gframes = max_nr_grant_frames();
+ if (max_nr_gframes < nr_gframes)
+ 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);
+ }
+ }
+
+ return (gnttab_map(0, nr_gframes - 1));
+}
+
+#endif
+
static int
gnttab_expand(unsigned int req_entries)
{
@@ -564,7 +621,7 @@ gnttab_init(void *unused)
goto ini_nomem;
}
- if (gnttab_resume() < 0)
+ if (gnttab_resume())
return -ENODEV;
nr_init_grefs = nr_grant_frames * GREFS_PER_GRANT_FRAME;
@@ -576,7 +633,8 @@ gnttab_init(void *unused)
gnttab_free_count = nr_init_grefs - NR_RESERVED_ENTRIES;
gnttab_free_head = NR_RESERVED_ENTRIES;
- printk("Grant table initialized\n");
+ if (bootverbose)
+ printf("Grant table initialized\n");
return 0;
ini_nomem:
Modified: user/dfr/xenhvm/6/sys/xen/gnttab.h
==============================================================================
--- user/dfr/xenhvm/6/sys/xen/gnttab.h Fri Nov 28 15:50:35 2008 (r185387)
+++ user/dfr/xenhvm/6/sys/xen/gnttab.h Fri Nov 28 16:25:43 2008 (r185388)
@@ -43,6 +43,7 @@
#include <machine/xen/hypervisor.h>
#include <xen/interface/grant_table.h>
+#include <xen/interface/memory.h>
#include <machine/xen/xen-os.h>
#include <machine/xen/hypervisor.h>
#include <machine/xen/features.h>
More information about the svn-src-user
mailing list