Patchwork [29/40] xenner: libxc emu: grant tables

login
register
mail settings
Submitter Alexander Graf
Date Nov. 1, 2010, 3:01 p.m.
Message ID <1288623713-28062-30-git-send-email-agraf@suse.de>
Download mbox | patch
Permalink /patch/69789/
State New
Headers show

Comments

Alexander Graf - Nov. 1, 2010, 3:01 p.m.
Xenner emulates parts of libxc, so we can not use the real xen infrastructure
when running xen pv guests without xen.

This patch adds support for grant tables.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 hw/xenner_libxc_gnttab.c |   91 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 91 insertions(+), 0 deletions(-)
 create mode 100644 hw/xenner_libxc_gnttab.c

Patch

diff --git a/hw/xenner_libxc_gnttab.c b/hw/xenner_libxc_gnttab.c
new file mode 100644
index 0000000..c9f4ce2
--- /dev/null
+++ b/hw/xenner_libxc_gnttab.c
@@ -0,0 +1,91 @@ 
+/*
+ *  Copyright (C) Red Hat 2007
+ *  Copyright (C) Novell Inc. 2010
+ *
+ *  Author(s): Gerd Hoffmann <kraxel@redhat.com>
+ *             Alexander Graf <agraf@suse.de>
+ *
+ *  Xenner Emulation -- grant tables
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; under version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <xenctrl.h>
+#include <xen/grant_table.h>
+
+#include "hw.h"
+#include "xen_interfaces.h"
+#include "xenner.h"
+
+/* ------------------------------------------------------------- */
+
+static grant_entry_v1_t *get_grant(uint32_t ref)
+{
+    grant_entry_v1_t *e;
+    int page, index;
+
+    page  = ref / (PAGE_SIZE / sizeof(grant_entry_v1_t));
+    index = ref % (PAGE_SIZE / sizeof(grant_entry_v1_t));
+
+    e = xenner_get_grant_table(page);
+    if (!e) {
+        return NULL;
+    }
+    return e + index;
+}
+
+/* ------------------------------------------------------------- */
+
+static int _qemu_open(void)
+{
+    return 42;
+}
+
+static int qemu_close(int xcg_handle)
+{
+    return 0;
+}
+
+static void *qemu_map_grant_ref(int xcg_handle, uint32_t domid,
+                                uint32_t ref, int prot)
+{
+    grant_entry_v1_t *e;
+
+    e = get_grant(ref);
+    if (!e) {
+        return NULL;
+    }
+
+    return xenner_mfn_to_ptr(e->frame);
+}
+
+static void *qemu_map_grant_refs(int xcg_handle, uint32_t count,
+                                 uint32_t *domids, uint32_t *refs, int prot)
+{
+    /* Hmm, not so easy ... */
+    return NULL;
+}
+
+static int qemu_munmap(int xcg_handle, void *start_address, uint32_t count)
+{
+    /* nothing as we didn't actually map anything ... */
+    return 0;
+}
+
+struct XenGnttabOps xc_gnttab_xenner = {
+    .open            = _qemu_open,
+    .close           = qemu_close,
+    .map_grant_ref   = qemu_map_grant_ref,
+    .map_grant_refs  = qemu_map_grant_refs,
+    .munmap          = qemu_munmap,
+};