]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
drivers/xengnttab: Move grant table to own library
authorSimon Kuenzer <simon@unikraft.io>
Wed, 11 Dec 2024 02:04:21 +0000 (18:04 -0800)
committerUnikraft Bot <monkey@unikraft.io>
Sat, 14 Dec 2024 10:47:47 +0000 (10:47 +0000)
This commit moves the code for the Xen grant table from the Xen platform
library to a separate driver library. This follows the goal of decomposing
`libxenplat`. All Xen drivers that require grant table support (`9pfront`,
`blkfront`, `netfront`) will specify their dependency to `libxengnttab`
with `select`. This simplifies the automatic configuration of dependencies.

For example, if an application requires networking and selects `uknetdev`,
`netfront` is automatically added to a build and will automatically resolve
its dependencies.

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Oleksii Moisieiev <oleksii_moisieiev@epam.com>
Reviewed-by: Oleksii Moisieiev <oleksii_moisieiev@epam.com>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1501

21 files changed:
drivers/xen/9pfront/9pfront.h
drivers/xen/9pfront/Config.uk
drivers/xen/Makefile.uk
drivers/xen/blkfront/Config.uk
drivers/xen/blkfront/blkfront.h
drivers/xen/netfront/Config.uk
drivers/xen/netfront/netfront.h
drivers/xen/xengnttab/Config.uk [new file with mode: 0644]
drivers/xen/xengnttab/Makefile.uk [new file with mode: 0644]
drivers/xen/xengnttab/arch/arm64/gnttab.c [new file with mode: 0644]
drivers/xen/xengnttab/arch/x86_64/gnttab.c [new file with mode: 0644]
drivers/xen/xengnttab/exportsyms.uk [new file with mode: 0644]
drivers/xen/xengnttab/gnttab.c [new file with mode: 0644]
drivers/xen/xengnttab/include/uk/xen/gnttab.h [new file with mode: 0644]
plat/xen/Config.uk
plat/xen/Makefile.uk
plat/xen/arm/gnttab.c [deleted file]
plat/xen/gnttab.c [deleted file]
plat/xen/include/common/gnttab.h [deleted file]
plat/xen/memory.c
plat/xen/x86/gnttab.c [deleted file]

index 77be134002cdd386196d714cbc033f1a105a8316..c3f6381d73da2cdfd1961c35ec7f596a701997aa 100644 (file)
@@ -43,7 +43,7 @@
 #endif
 #include <xen/io/9pfs.h>
 #include <common/events.h>
-#include <common/gnttab.h>
+#include <uk/xen/gnttab.h>
 
 struct p9front_dev_ring {
        /* Backpointer to the p9front device. */
index 0ffa3bbc6f3520a4e14f1d7b6a4b07dd02ae1d0e..ed971c2c64d37953bc58c51ee73e6437aa9af2d3 100644 (file)
@@ -2,6 +2,7 @@ menuconfig LIB9PFRONT
        bool "9pfront: Xen 9pfs volumes"
        select LIBXENBUS
        select LIBXENHEADERS
+       select LIBXENGNTTAB
        depends on HAVE_XENBUS
        depends on LIBUK9P
        help
index c017a7cdcb1e058320754e9ebb82c9c9d2c474b7..bf59397a97836fda4c36c9a4367b6f231a288697 100644 (file)
@@ -7,6 +7,7 @@
 UK_DRIV_XEN_BASE := $(UK_DRIV_BASE)/xen
 
 $(eval $(call import_lib,$(UK_DRIV_XEN_BASE)/xenheaders))
+$(eval $(call import_lib,$(UK_DRIV_XEN_BASE)/xengnttab))
 $(eval $(call import_lib,$(UK_DRIV_XEN_BASE)/9pfront))
 $(eval $(call import_lib,$(UK_DRIV_XEN_BASE)/blkfront))
 $(eval $(call import_lib,$(UK_DRIV_XEN_BASE)/netfront))
index 2b2f6ba69b5fb8024295c1302d3a9d66ed28018a..fb8347154f66d7c49b8dd3e53abe6430f35354f8 100644 (file)
@@ -2,6 +2,7 @@ menuconfig LIBBLKFRONT
        bool "blkfront: Xen block devices"
        select LIBXENHEADERS
        select LIBXENBUS
+       select LIBXENGNTTAB
        depends on HAVE_XENBUS
        depends on LIBUKBLKDEV
        help
index 97e858371d7ef1e9df3f2b9e4394afb338eb80aa..440f4c3f791bb5df11156fa1853c7bff46a118c7 100644 (file)
@@ -47,7 +47,7 @@
 #endif
 
 #include <xen/io/blkif.h>
-#include <common/gnttab.h>
+#include <uk/xen/gnttab.h>
 #include <common/events.h>
 
 #define BLK_RING_PAGES_NUM 1
index 2323bfb458242bd9cfab370f0acde794f446b463..70c6d1838f3746b895061993fa755f10efde13d4 100644 (file)
@@ -2,7 +2,7 @@ config LIBNETFRONT
        bool "netfront: Xen network interfaces"
        select LIBXENHEADERS
        select LIBXENBUS
-       depends on XEN_GNTTAB
+       select LIBXENGNTTAB
        depends on HAVE_XENBUS
        depends on LIBUKNETDEV
        help
index f3870fdb6bf54c5a5b4ee41bbbb6773351a01d70..0cb3314d768f3b25b21b99695116eafc71b1a4e4 100644 (file)
@@ -38,7 +38,7 @@
 #include <uk/netbuf.h>
 #include <uk/semaphore.h>
 #include <xen/io/netif.h>
-#include <common/gnttab.h>
+#include <uk/xen/gnttab.h>
 #include <common/events.h>
 #if defined(__aarch64__)
 #include <xen-arm/mm.h>
diff --git a/drivers/xen/xengnttab/Config.uk b/drivers/xen/xengnttab/Config.uk
new file mode 100644 (file)
index 0000000..7ca677a
--- /dev/null
@@ -0,0 +1,11 @@
+config LIBXENGNTTAB
+       bool "xengnttab: Xen Grant Table"
+       select LIBXENHEADERS
+       select LIBXENBUS
+       select LIBUKALLOC
+       select LIBUKLOCK
+       select LIBUKLOCK_SEMAPHORE
+       depends on (ARCH_X86_64 || ARCH_ARM_64)
+       depends on HAVE_XENBUS
+       help
+               Support grant table operations
diff --git a/drivers/xen/xengnttab/Makefile.uk b/drivers/xen/xengnttab/Makefile.uk
new file mode 100644 (file)
index 0000000..29283fb
--- /dev/null
@@ -0,0 +1,7 @@
+$(eval $(call addlib_s,libxengnttab,$(CONFIG_LIBXENGNTTAB)))
+
+CINCLUDES-$(CONFIG_LIBXENGNTTAB)        += -I$(LIBXENGNTTAB_BASE)/include
+
+LIBXENGNTTAB_SRCS-y                     += $(LIBXENGNTTAB_BASE)/gnttab.c
+LIBXENGNTTAB_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBXENGNTTAB_BASE)/arch/x86_64/gnttab.c|x86_64
+LIBXENGNTTAB_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBXENGNTTAB_BASE)/arch/arm64/gnttab.c|arm64
diff --git a/drivers/xen/xengnttab/arch/arm64/gnttab.c b/drivers/xen/xengnttab/arch/arm64/gnttab.c
new file mode 100644 (file)
index 0000000..7453b38
--- /dev/null
@@ -0,0 +1,96 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+/*
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/* Taken from Mini-OS */
+
+#include <stdint.h>
+#include <stddef.h>
+#include <uk/print.h>
+#include <xen/memory.h>
+#include <xen/xen.h>
+#include <libfdt.h>
+#include <xen/grant_table.h>
+#include <common/hypervisor.h>
+#include <xen-arm/os.h>
+#include <xen-arm/mm.h>
+
+extern lpae_t fixmap_pgtable[512];
+
+/* Get Xen's suggested physical page assignments for the grant table. */
+static paddr_t get_gnttab_base(void)
+{
+       int hypervisor;
+       int len = 0;
+       const uint64_t *regs;
+       paddr_t gnttab_base;
+
+       hypervisor =
+               fdt_node_offset_by_compatible(HYPERVISOR_dtb, -1, "xen,xen");
+       if (hypervisor < 0)
+               BUG();
+
+       regs = fdt_getprop(HYPERVISOR_dtb, hypervisor, "reg", &len);
+       /* The property contains the address and size, 8-bytes each. */
+       if (regs == NULL || len < 16) {
+               uk_pr_debug("Bad 'reg' property: %p %d\n", regs, len);
+               BUG();
+       }
+
+       gnttab_base = fdt64_ld(regs);
+
+       uk_pr_debug("FDT suggests grant table base %llx\n",
+                               (unsigned long long) gnttab_base);
+
+       return gnttab_base;
+}
+
+static paddr_t map_gnttab(paddr_t phys)
+{
+       uk_pr_debug("%s, phys = 0x%lx\n", __func__, phys);
+
+       set_pgt_entry(&fixmap_pgtable[l2_pgt_idx(FIX_GNT_START)],
+                     ((phys & L2_MASK) | BLOCK_DEF_ATTR | L2_BLOCK));
+
+       return (paddr_t)(FIX_GNT_START + (phys & L2_OFFSET));
+}
+
+grant_entry_v1_t *gnttab_arch_init(int nr_grant_frames)
+{
+       struct xen_add_to_physmap xatp;
+       paddr_t gnttab_table;
+       int i;
+
+       gnttab_table = get_gnttab_base();
+
+       for (i = 0; i < nr_grant_frames; i++) {
+               xatp.domid = DOMID_SELF;
+               xatp.size = 0;     // Seems to be unused
+               xatp.space = XENMAPSPACE_grant_table;
+               xatp.idx = i;
+               xatp.gpfn = (gnttab_table >> PAGE_SHIFT) + i;
+               if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp) != 0)
+                       BUG();
+       }
+
+       return (grant_entry_v1_t *)map_gnttab(gnttab_table);
+}
diff --git a/drivers/xen/xengnttab/arch/x86_64/gnttab.c b/drivers/xen/xengnttab/arch/x86_64/gnttab.c
new file mode 100644 (file)
index 0000000..7a64748
--- /dev/null
@@ -0,0 +1,60 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+/*
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/* Taken from Mini-OS */
+
+#include <stdint.h>
+#include <stddef.h>
+#include <uk/print.h>
+#include <xen/xen.h>
+#include <xen/grant_table.h>
+#include <common/hypervisor.h>
+#include <xen-x86/mm.h>
+
+
+grant_entry_v1_t *gnttab_arch_init(int grant_frames_num)
+{
+       grant_entry_v1_t *gnte = NULL;
+       struct gnttab_setup_table setup;
+       unsigned long frames[grant_frames_num];
+       int rc;
+
+       setup.dom = DOMID_SELF;
+       setup.nr_frames = grant_frames_num;
+       set_xen_guest_handle(setup.frame_list, frames);
+
+       rc = HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1);
+       if (rc) {
+               uk_pr_err("Hypercall error: %d\n", rc);
+               goto out;
+       }
+       if (setup.status != GNTST_okay) {
+               uk_pr_err("Hypercall status: %d\n", setup.status);
+               goto out;
+       }
+
+       gnte = map_frames(frames, grant_frames_num, ukplat_memallocator_get());
+
+out:
+       return gnte;
+}
diff --git a/drivers/xen/xengnttab/exportsyms.uk b/drivers/xen/xengnttab/exportsyms.uk
new file mode 100644 (file)
index 0000000..22338f5
--- /dev/null
@@ -0,0 +1,10 @@
+gnttab_init
+gnttab_fini
+gnttab_alloc_and_grant
+gnttab_grant_access
+gnttab_grant_transfer
+gnttab_update_grant
+gnttab_end_transfer
+gnttab_end_access
+gnttabop_error
+gnttab_arch_init
diff --git a/drivers/xen/xengnttab/gnttab.c b/drivers/xen/xengnttab/gnttab.c
new file mode 100644 (file)
index 0000000..bd379e8
--- /dev/null
@@ -0,0 +1,292 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ ****************************************************************************
+ * (C) 2006 - Cambridge University
+ ****************************************************************************
+ *
+ *        File: gnttab.c
+ *      Author: Steven Smith (sos22@cam.ac.uk)
+ *     Changes: Grzegorz Milos (gm281@cam.ac.uk)
+ *
+ *        Date: July 2006
+ *
+ * Environment: Xen Minimal OS
+ * Description: Simple grant tables implementation. About as stupid as it's
+ *  possible to be and still work.
+ *
+ ****************************************************************************
+ */
+#include <stdint.h>
+#include <stddef.h>
+#ifdef DBGGNT
+#include <string.h>
+#endif
+#include <uk/arch/limits.h>
+#include <uk/atomic.h>
+#include <uk/plat/lcpu.h>
+#include <uk/semaphore.h>
+#include <uk/xen/gnttab.h>
+#if defined(__i386__) || defined(__x86_64__)
+#include <xen-x86/mm.h>
+
+#include <xen-x86/hypercall.h>
+#elif defined(__aarch64__)
+#include <xen-arm/mm.h>
+
+#include <xen-arm/hypercall.h>
+#else
+#error "Unsupported architecture"
+#endif
+
+/* NR_GRANT_FRAMES must be less than or equal to that configured in Xen */
+#define NR_GRANT_FRAMES         4
+#define NR_GRANT_ENTRIES \
+       (NR_GRANT_FRAMES * PAGE_SIZE / sizeof(grant_entry_v1_t))
+
+static struct gnttab {
+       int initialized;
+       struct uk_semaphore sem;
+       grant_entry_v1_t *table;
+       grant_ref_t gref_list[NR_GRANT_ENTRIES];
+#ifdef DBGGNT
+       char inuse[NR_GRANT_ENTRIES];
+#endif
+} gnttab;
+
+
+static grant_ref_t get_free_entry(void)
+{
+       grant_ref_t gref;
+       unsigned long flags;
+
+       uk_semaphore_down(&gnttab.sem);
+
+       flags = ukplat_lcpu_save_irqf();
+
+       gref = gnttab.gref_list[0];
+       UK_ASSERT(gref >= GNTTAB_NR_RESERVED_ENTRIES &&
+               gref < NR_GRANT_ENTRIES);
+       gnttab.gref_list[0] = gnttab.gref_list[gref];
+#ifdef DBGGNT
+       UK_ASSERT(!gnttab.inuse[gref]);
+       gnttab.inuse[gref] = 1;
+#endif
+
+       ukplat_lcpu_restore_irqf(flags);
+
+       return gref;
+}
+
+static void put_free_entry(grant_ref_t gref)
+{
+       unsigned long flags;
+
+       flags = ukplat_lcpu_save_irqf();
+
+#ifdef DBGGNT
+       UK_ASSERT(gnttab.inuse[gref]);
+       gnttab.inuse[gref] = 0;
+#endif
+       gnttab.gref_list[gref] = gnttab.gref_list[0];
+       gnttab.gref_list[0] = gref;
+
+       ukplat_lcpu_restore_irqf(flags);
+
+       uk_semaphore_up(&gnttab.sem);
+}
+
+static void gnttab_grant_init(grant_ref_t gref, domid_t domid,
+               unsigned long mfn)
+{
+       gnttab.table[gref].frame = mfn;
+       gnttab.table[gref].domid = domid;
+
+       /* Memory barrier */
+       wmb();
+}
+
+static void gnttab_grant_permit_access(grant_ref_t gref, domid_t domid,
+               unsigned long mfn, int readonly)
+{
+       gnttab_grant_init(gref, domid, mfn);
+       readonly *= GTF_readonly;
+       gnttab.table[gref].flags = GTF_permit_access | readonly;
+}
+
+grant_ref_t gnttab_grant_access(domid_t domid, unsigned long mfn,
+               int readonly)
+{
+       grant_ref_t gref = get_free_entry();
+
+       gnttab_grant_permit_access(gref, domid, mfn, readonly);
+
+       return gref;
+}
+
+grant_ref_t gnttab_grant_transfer(domid_t domid, unsigned long mfn)
+{
+       grant_ref_t gref = get_free_entry();
+
+       gnttab_grant_init(gref, domid, mfn);
+       gnttab.table[gref].flags = GTF_accept_transfer;
+
+       return gref;
+}
+
+/* Reset flags to zero in order to stop using the grant */
+static int gnttab_reset_flags(grant_ref_t gref)
+{
+       __u16 flags, nflags;
+       __u16 *pflags;
+
+       pflags = &gnttab.table[gref].flags;
+       nflags = *pflags;
+
+       do {
+               if ((flags = nflags) & (GTF_reading | GTF_writing)) {
+                       uk_pr_warn("gref=%u still in use! (0x%x)\n",
+                                  gref, flags);
+                       return 0;
+               }
+       } while ((nflags = uk_compare_exchange_sync(pflags, flags, 0))
+                       != flags);
+
+       return 1;
+}
+
+int gnttab_update_grant(grant_ref_t gref,
+               domid_t domid, unsigned long mfn,
+               int readonly)
+{
+       int rc;
+
+       UK_ASSERT(gref >= GNTTAB_NR_RESERVED_ENTRIES &&
+               gref < NR_GRANT_ENTRIES);
+
+       rc = gnttab_reset_flags(gref);
+       if (!rc)
+               return rc;
+
+       gnttab_grant_permit_access(gref, domid, mfn, readonly);
+
+       return 1;
+}
+
+int gnttab_end_access(grant_ref_t gref)
+{
+       int rc;
+
+       UK_ASSERT(gref >= GNTTAB_NR_RESERVED_ENTRIES &&
+               gref < NR_GRANT_ENTRIES);
+
+       rc = gnttab_reset_flags(gref);
+       if (!rc)
+               return rc;
+
+       put_free_entry(gref);
+
+       return 1;
+}
+
+unsigned long gnttab_end_transfer(grant_ref_t gref)
+{
+       unsigned long frame;
+       __u16 flags;
+       __u16 *pflags;
+
+       UK_ASSERT(gref >= GNTTAB_NR_RESERVED_ENTRIES &&
+               gref < NR_GRANT_ENTRIES);
+
+       pflags = &gnttab.table[gref].flags;
+       while (!((flags = *pflags) & GTF_transfer_committed)) {
+               if (uk_compare_exchange_sync(pflags, flags, 0) == flags) {
+                       uk_pr_info("Release unused transfer grant.\n");
+                       put_free_entry(gref);
+                       return 0;
+               }
+       }
+
+       /* If a transfer is in progress then wait until it is completed. */
+       while (!(flags & GTF_transfer_completed))
+               flags = *pflags;
+
+       /* Read the frame number /after/ reading completion status. */
+       rmb();
+       frame = gnttab.table[gref].frame;
+
+       put_free_entry(gref);
+
+       return frame;
+}
+
+grant_ref_t gnttab_alloc_and_grant(void **map, struct uk_alloc *a)
+{
+       void *page;
+       unsigned long mfn;
+       grant_ref_t gref;
+
+       UK_ASSERT(map != NULL);
+       UK_ASSERT(a != NULL);
+
+       page = uk_palloc(a, 1);
+       if (page == NULL)
+               return GRANT_INVALID_REF;
+
+       mfn = virt_to_mfn(page);
+       gref = gnttab_grant_access(0, mfn, 0);
+
+       *map = page;
+
+       return gref;
+}
+
+static const char * const gnttabop_error_msgs[] = GNTTABOP_error_msgs;
+
+const char *gnttabop_error(__s16 status)
+{
+       status = -status;
+       if (status < 0 || (__u16) status >= ARRAY_SIZE(gnttabop_error_msgs))
+               return "bad status";
+       else
+               return gnttabop_error_msgs[status];
+}
+
+void gnttab_init(void)
+{
+       grant_ref_t gref;
+
+       UK_ASSERT(gnttab.initialized == 0);
+
+       uk_semaphore_init(&gnttab.sem, 0);
+
+#ifdef DBGGNT
+       memset(gnttab.inuse, 1, sizeof(gnttab.inuse));
+#endif
+       for (gref = GNTTAB_NR_RESERVED_ENTRIES; gref < NR_GRANT_ENTRIES; gref++)
+               put_free_entry(gref);
+
+       gnttab.table = gnttab_arch_init(NR_GRANT_FRAMES);
+       if (gnttab.table == NULL)
+               UK_CRASH("Failed to initialize grant table\n");
+
+       uk_pr_info("Grant table mapped at %p.\n", gnttab.table);
+
+       gnttab.initialized = 1;
+}
+
+void gnttab_fini(void)
+{
+       struct gnttab_setup_table setup;
+       int rc;
+
+       setup.dom = DOMID_SELF;
+       setup.nr_frames = 0;
+
+       rc = HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1);
+       if (rc) {
+               uk_pr_err("Hypercall error: %d\n", rc);
+               return;
+       }
+
+       gnttab.initialized = 0;
+}
diff --git a/drivers/xen/xengnttab/include/uk/xen/gnttab.h b/drivers/xen/xengnttab/include/uk/xen/gnttab.h
new file mode 100644 (file)
index 0000000..991d5b1
--- /dev/null
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+/*
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/* Taken from Mini-OS */
+
+#ifndef __UK_XEN_GNTTAB_H__
+#define __UK_XEN_GNTTAB_H__
+
+#include <uk/config.h>
+#include <uk/alloc.h>
+#include <xen/grant_table.h>
+
+#define GRANT_INVALID_REF 0
+
+void gnttab_init(void);
+void gnttab_fini(void);
+
+grant_ref_t gnttab_alloc_and_grant(void **map, struct uk_alloc *a);
+grant_ref_t gnttab_grant_access(domid_t domid, unsigned long pfn,
+                               int readonly);
+grant_ref_t gnttab_grant_transfer(domid_t domid, unsigned long pfn);
+int gnttab_update_grant(grant_ref_t gref,
+               domid_t domid, unsigned long pfn,
+               int readonly);
+unsigned long gnttab_end_transfer(grant_ref_t gref);
+int gnttab_end_access(grant_ref_t gref);
+
+const char *gnttabop_error(__s16 status);
+
+grant_entry_v1_t *gnttab_arch_init(int nr_grant_frames);
+
+#endif /* !__UK_XEN_GNTTAB_H__ */
index 84aa30a6fd8e8972334ab7ee21a058d08d6a1c47..4f49d50d3db2e6b4f494088255cb3984265d3c4f 100644 (file)
@@ -44,16 +44,4 @@ config XEN_PV_BUILD_P2M
                Create and initialize physical to machine (p2m) table on a PV
                xen host
 
-config XEN_GNTTAB
-       bool "Grant table support"
-       default y if (XEN_PV || ARCH_ARM_64)
-       depends on (ARCH_X86_64 || ARCH_ARM_64)
-       select LIBXENBUS
-       select LIBUKALLOC
-       select LIBUKLOCK
-       select LIBUKLOCK_SEMAPHORE
-       select LIBUKSCHED
-       help
-               Support grant table operations
-
 endif
index 72c8575281e39105487cebfb2cc728d7373f1998..9ff67449b078bbb74293f6c5ae0cc74a5b9175ed 100644 (file)
@@ -122,9 +122,3 @@ endif
 LIBXENPLAT_SRCS-y              += $(LIBXENPLAT_BASE)/lcpu.c
 LIBXENPLAT_SRCS-y              += $(LIBXENPLAT_BASE)/shutdown.c
 LIBXENPLAT_SRCS-y              += $(LIBXENPLAT_BASE)/events.c
-
-ifeq ($(CONFIG_XEN_GNTTAB),y)
-LIBXENPLAT_SRCS-y              += $(LIBXENPLAT_BASE)/gnttab.c
-LIBXENPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBXENPLAT_BASE)/x86/gnttab.c|x86
-LIBXENPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBXENPLAT_BASE)/arm/gnttab.c|arm64
-endif
diff --git a/plat/xen/arm/gnttab.c b/plat/xen/arm/gnttab.c
deleted file mode 100644 (file)
index 7453b38..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/* SPDX-License-Identifier: BSD-2-Clause */
-/*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-/* Taken from Mini-OS */
-
-#include <stdint.h>
-#include <stddef.h>
-#include <uk/print.h>
-#include <xen/memory.h>
-#include <xen/xen.h>
-#include <libfdt.h>
-#include <xen/grant_table.h>
-#include <common/hypervisor.h>
-#include <xen-arm/os.h>
-#include <xen-arm/mm.h>
-
-extern lpae_t fixmap_pgtable[512];
-
-/* Get Xen's suggested physical page assignments for the grant table. */
-static paddr_t get_gnttab_base(void)
-{
-       int hypervisor;
-       int len = 0;
-       const uint64_t *regs;
-       paddr_t gnttab_base;
-
-       hypervisor =
-               fdt_node_offset_by_compatible(HYPERVISOR_dtb, -1, "xen,xen");
-       if (hypervisor < 0)
-               BUG();
-
-       regs = fdt_getprop(HYPERVISOR_dtb, hypervisor, "reg", &len);
-       /* The property contains the address and size, 8-bytes each. */
-       if (regs == NULL || len < 16) {
-               uk_pr_debug("Bad 'reg' property: %p %d\n", regs, len);
-               BUG();
-       }
-
-       gnttab_base = fdt64_ld(regs);
-
-       uk_pr_debug("FDT suggests grant table base %llx\n",
-                               (unsigned long long) gnttab_base);
-
-       return gnttab_base;
-}
-
-static paddr_t map_gnttab(paddr_t phys)
-{
-       uk_pr_debug("%s, phys = 0x%lx\n", __func__, phys);
-
-       set_pgt_entry(&fixmap_pgtable[l2_pgt_idx(FIX_GNT_START)],
-                     ((phys & L2_MASK) | BLOCK_DEF_ATTR | L2_BLOCK));
-
-       return (paddr_t)(FIX_GNT_START + (phys & L2_OFFSET));
-}
-
-grant_entry_v1_t *gnttab_arch_init(int nr_grant_frames)
-{
-       struct xen_add_to_physmap xatp;
-       paddr_t gnttab_table;
-       int i;
-
-       gnttab_table = get_gnttab_base();
-
-       for (i = 0; i < nr_grant_frames; i++) {
-               xatp.domid = DOMID_SELF;
-               xatp.size = 0;     // Seems to be unused
-               xatp.space = XENMAPSPACE_grant_table;
-               xatp.idx = i;
-               xatp.gpfn = (gnttab_table >> PAGE_SHIFT) + i;
-               if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp) != 0)
-                       BUG();
-       }
-
-       return (grant_entry_v1_t *)map_gnttab(gnttab_table);
-}
diff --git a/plat/xen/gnttab.c b/plat/xen/gnttab.c
deleted file mode 100644 (file)
index 388b392..0000000
+++ /dev/null
@@ -1,292 +0,0 @@
-/* SPDX-License-Identifier: MIT */
-/*
- ****************************************************************************
- * (C) 2006 - Cambridge University
- ****************************************************************************
- *
- *        File: gnttab.c
- *      Author: Steven Smith (sos22@cam.ac.uk)
- *     Changes: Grzegorz Milos (gm281@cam.ac.uk)
- *
- *        Date: July 2006
- *
- * Environment: Xen Minimal OS
- * Description: Simple grant tables implementation. About as stupid as it's
- *  possible to be and still work.
- *
- ****************************************************************************
- */
-#include <stdint.h>
-#include <stddef.h>
-#ifdef DBGGNT
-#include <string.h>
-#endif
-#include <uk/arch/limits.h>
-#include <uk/atomic.h>
-#include <uk/plat/lcpu.h>
-#include <uk/semaphore.h>
-#include <common/gnttab.h>
-#if defined(__i386__) || defined(__x86_64__)
-#include <xen-x86/mm.h>
-
-#include <xen-x86/hypercall.h>
-#elif defined(__aarch64__)
-#include <xen-arm/mm.h>
-
-#include <xen-arm/hypercall.h>
-#else
-#error "Unsupported architecture"
-#endif
-
-/* NR_GRANT_FRAMES must be less than or equal to that configured in Xen */
-#define NR_GRANT_FRAMES         4
-#define NR_GRANT_ENTRIES \
-       (NR_GRANT_FRAMES * PAGE_SIZE / sizeof(grant_entry_v1_t))
-
-static struct gnttab {
-       int initialized;
-       struct uk_semaphore sem;
-       grant_entry_v1_t *table;
-       grant_ref_t gref_list[NR_GRANT_ENTRIES];
-#ifdef DBGGNT
-       char inuse[NR_GRANT_ENTRIES];
-#endif
-} gnttab;
-
-
-static grant_ref_t get_free_entry(void)
-{
-       grant_ref_t gref;
-       unsigned long flags;
-
-       uk_semaphore_down(&gnttab.sem);
-
-       flags = ukplat_lcpu_save_irqf();
-
-       gref = gnttab.gref_list[0];
-       UK_ASSERT(gref >= GNTTAB_NR_RESERVED_ENTRIES &&
-               gref < NR_GRANT_ENTRIES);
-       gnttab.gref_list[0] = gnttab.gref_list[gref];
-#ifdef DBGGNT
-       UK_ASSERT(!gnttab.inuse[gref]);
-       gnttab.inuse[gref] = 1;
-#endif
-
-       ukplat_lcpu_restore_irqf(flags);
-
-       return gref;
-}
-
-static void put_free_entry(grant_ref_t gref)
-{
-       unsigned long flags;
-
-       flags = ukplat_lcpu_save_irqf();
-
-#ifdef DBGGNT
-       UK_ASSERT(gnttab.inuse[gref]);
-       gnttab.inuse[gref] = 0;
-#endif
-       gnttab.gref_list[gref] = gnttab.gref_list[0];
-       gnttab.gref_list[0] = gref;
-
-       ukplat_lcpu_restore_irqf(flags);
-
-       uk_semaphore_up(&gnttab.sem);
-}
-
-static void gnttab_grant_init(grant_ref_t gref, domid_t domid,
-               unsigned long mfn)
-{
-       gnttab.table[gref].frame = mfn;
-       gnttab.table[gref].domid = domid;
-
-       /* Memory barrier */
-       wmb();
-}
-
-static void gnttab_grant_permit_access(grant_ref_t gref, domid_t domid,
-               unsigned long mfn, int readonly)
-{
-       gnttab_grant_init(gref, domid, mfn);
-       readonly *= GTF_readonly;
-       gnttab.table[gref].flags = GTF_permit_access | readonly;
-}
-
-grant_ref_t gnttab_grant_access(domid_t domid, unsigned long mfn,
-               int readonly)
-{
-       grant_ref_t gref = get_free_entry();
-
-       gnttab_grant_permit_access(gref, domid, mfn, readonly);
-
-       return gref;
-}
-
-grant_ref_t gnttab_grant_transfer(domid_t domid, unsigned long mfn)
-{
-       grant_ref_t gref = get_free_entry();
-
-       gnttab_grant_init(gref, domid, mfn);
-       gnttab.table[gref].flags = GTF_accept_transfer;
-
-       return gref;
-}
-
-/* Reset flags to zero in order to stop using the grant */
-static int gnttab_reset_flags(grant_ref_t gref)
-{
-       __u16 flags, nflags;
-       __u16 *pflags;
-
-       pflags = &gnttab.table[gref].flags;
-       nflags = *pflags;
-
-       do {
-               if ((flags = nflags) & (GTF_reading | GTF_writing)) {
-                       uk_pr_warn("gref=%u still in use! (0x%x)\n",
-                                  gref, flags);
-                       return 0;
-               }
-       } while ((nflags = uk_compare_exchange_sync(pflags, flags, 0))
-                       != flags);
-
-       return 1;
-}
-
-int gnttab_update_grant(grant_ref_t gref,
-               domid_t domid, unsigned long mfn,
-               int readonly)
-{
-       int rc;
-
-       UK_ASSERT(gref >= GNTTAB_NR_RESERVED_ENTRIES &&
-               gref < NR_GRANT_ENTRIES);
-
-       rc = gnttab_reset_flags(gref);
-       if (!rc)
-               return rc;
-
-       gnttab_grant_permit_access(gref, domid, mfn, readonly);
-
-       return 1;
-}
-
-int gnttab_end_access(grant_ref_t gref)
-{
-       int rc;
-
-       UK_ASSERT(gref >= GNTTAB_NR_RESERVED_ENTRIES &&
-               gref < NR_GRANT_ENTRIES);
-
-       rc = gnttab_reset_flags(gref);
-       if (!rc)
-               return rc;
-
-       put_free_entry(gref);
-
-       return 1;
-}
-
-unsigned long gnttab_end_transfer(grant_ref_t gref)
-{
-       unsigned long frame;
-       __u16 flags;
-       __u16 *pflags;
-
-       UK_ASSERT(gref >= GNTTAB_NR_RESERVED_ENTRIES &&
-               gref < NR_GRANT_ENTRIES);
-
-       pflags = &gnttab.table[gref].flags;
-       while (!((flags = *pflags) & GTF_transfer_committed)) {
-               if (uk_compare_exchange_sync(pflags, flags, 0) == flags) {
-                       uk_pr_info("Release unused transfer grant.\n");
-                       put_free_entry(gref);
-                       return 0;
-               }
-       }
-
-       /* If a transfer is in progress then wait until it is completed. */
-       while (!(flags & GTF_transfer_completed))
-               flags = *pflags;
-
-       /* Read the frame number /after/ reading completion status. */
-       rmb();
-       frame = gnttab.table[gref].frame;
-
-       put_free_entry(gref);
-
-       return frame;
-}
-
-grant_ref_t gnttab_alloc_and_grant(void **map, struct uk_alloc *a)
-{
-       void *page;
-       unsigned long mfn;
-       grant_ref_t gref;
-
-       UK_ASSERT(map != NULL);
-       UK_ASSERT(a != NULL);
-
-       page = uk_palloc(a, 1);
-       if (page == NULL)
-               return GRANT_INVALID_REF;
-
-       mfn = virt_to_mfn(page);
-       gref = gnttab_grant_access(0, mfn, 0);
-
-       *map = page;
-
-       return gref;
-}
-
-static const char * const gnttabop_error_msgs[] = GNTTABOP_error_msgs;
-
-const char *gnttabop_error(__s16 status)
-{
-       status = -status;
-       if (status < 0 || (__u16) status >= ARRAY_SIZE(gnttabop_error_msgs))
-               return "bad status";
-       else
-               return gnttabop_error_msgs[status];
-}
-
-void gnttab_init(void)
-{
-       grant_ref_t gref;
-
-       UK_ASSERT(gnttab.initialized == 0);
-
-       uk_semaphore_init(&gnttab.sem, 0);
-
-#ifdef DBGGNT
-       memset(gnttab.inuse, 1, sizeof(gnttab.inuse));
-#endif
-       for (gref = GNTTAB_NR_RESERVED_ENTRIES; gref < NR_GRANT_ENTRIES; gref++)
-               put_free_entry(gref);
-
-       gnttab.table = gnttab_arch_init(NR_GRANT_FRAMES);
-       if (gnttab.table == NULL)
-               UK_CRASH("Failed to initialize grant table\n");
-
-       uk_pr_info("Grant table mapped at %p.\n", gnttab.table);
-
-       gnttab.initialized = 1;
-}
-
-void gnttab_fini(void)
-{
-       struct gnttab_setup_table setup;
-       int rc;
-
-       setup.dom = DOMID_SELF;
-       setup.nr_frames = 0;
-
-       rc = HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1);
-       if (rc) {
-               uk_pr_err("Hypercall error: %d\n", rc);
-               return;
-       }
-
-       gnttab.initialized = 0;
-}
diff --git a/plat/xen/include/common/gnttab.h b/plat/xen/include/common/gnttab.h
deleted file mode 100644 (file)
index 5a830ed..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/* SPDX-License-Identifier: BSD-2-Clause */
-/*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-/* Taken from Mini-OS */
-
-#ifndef __GNTTAB_H__
-#define __GNTTAB_H__
-
-#include <uk/config.h>
-
-#ifdef CONFIG_XEN_GNTTAB
-
-#include <uk/alloc.h>
-#include <xen/grant_table.h>
-
-#define GRANT_INVALID_REF 0
-
-void gnttab_init(void);
-void gnttab_fini(void);
-
-grant_ref_t gnttab_alloc_and_grant(void **map, struct uk_alloc *a);
-grant_ref_t gnttab_grant_access(domid_t domid, unsigned long pfn,
-                               int readonly);
-grant_ref_t gnttab_grant_transfer(domid_t domid, unsigned long pfn);
-int gnttab_update_grant(grant_ref_t gref,
-               domid_t domid, unsigned long pfn,
-               int readonly);
-unsigned long gnttab_end_transfer(grant_ref_t gref);
-int gnttab_end_access(grant_ref_t gref);
-
-const char *gnttabop_error(__s16 status);
-
-grant_entry_v1_t *gnttab_arch_init(int nr_grant_frames);
-
-#endif /* CONFIG_XEN_GNTTAB */
-
-#endif /* !__GNTTAB_H__ */
index fa1af9e04cc58e2501ad32a10850bec11224d3a2..fdf5baa890503a9c020493f604cbc2b7807515b9 100644 (file)
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <uk/config.h>
 #include <stdint.h>
 
-#include <common/gnttab.h>
+#if CONFIG_LIBXENGNTTAB
+#include <uk/xen/gnttab.h>
+#endif /* CONFIG_LIBXENGNTTAB */
 #if (defined __X86_32__) || (defined __X86_64__)
 #include <xen-x86/setup.h>
 #include <xen-x86/mm_pv.h>
@@ -50,7 +53,8 @@ void mm_init(void)
 int _ukplat_mem_mappings_init(void)
 {
        mm_init();
-#ifdef CONFIG_XEN_GNTTAB
+#ifdef CONFIG_LIBXENGNTTAB
+       /* TODO: Move `gnttab_init()` to (early) ctortab */
        gnttab_init();
 #endif
        return 0;
diff --git a/plat/xen/x86/gnttab.c b/plat/xen/x86/gnttab.c
deleted file mode 100644 (file)
index 7a64748..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/* SPDX-License-Identifier: BSD-2-Clause */
-/*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-/* Taken from Mini-OS */
-
-#include <stdint.h>
-#include <stddef.h>
-#include <uk/print.h>
-#include <xen/xen.h>
-#include <xen/grant_table.h>
-#include <common/hypervisor.h>
-#include <xen-x86/mm.h>
-
-
-grant_entry_v1_t *gnttab_arch_init(int grant_frames_num)
-{
-       grant_entry_v1_t *gnte = NULL;
-       struct gnttab_setup_table setup;
-       unsigned long frames[grant_frames_num];
-       int rc;
-
-       setup.dom = DOMID_SELF;
-       setup.nr_frames = grant_frames_num;
-       set_xen_guest_handle(setup.frame_list, frames);
-
-       rc = HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1);
-       if (rc) {
-               uk_pr_err("Hypercall error: %d\n", rc);
-               goto out;
-       }
-       if (setup.status != GNTST_okay) {
-               uk_pr_err("Hypercall status: %d\n", setup.status);
-               goto out;
-       }
-
-       gnte = map_frames(frames, grant_frames_num, ukplat_memallocator_get());
-
-out:
-       return gnte;
-}