Skip to contentSkip to conversation

Xenstore communication support for Seabios

PATCH In review Daniel Castro 3 participants 15 messages Aug 18, 2011 – Aug 24, 2011 Kbuild

lore
Share & tools
lore
#0 lore raw

cover Xenstore communication support for Seabios

As part of Google Summer of Code we are in the process to add Block PV-drivers to Seabios, in order to this, first we have to be able to communicate with xenstore so we can exchange information before the front and back ends connect. To communicate with xenstore we need to make seabios Xen-friendly so support for hypercalls has been added to Seabios. In the next month, Seabios will become a front-end for the block devices, connecting to dom0 back-end block device when used with Xen.

There is an issue, if you issue a query and the ring did not prepare the answer fast enough, after the event signal hypercall, the ring will force a ring wait for an event that will never arrive. For now this is solved by doing a dprintf after the hypercall, this gives enough time to the ring.

This patch should be applied to Seabios and must be used with qemu-upstream with xen4.1, please follow this guide for this:
http://wiki.xensource.com/xenwiki/QEMUUpstream

Some more documentation on this can be found here:
http://wiki.xensource.com/xenwiki/SeaBIOS

Daniel Castro (10):
Xen: Guest Handlers and Copyrights
Move PAGE_SHIFT to memmap.h
Xen: Use PAGE_SHIFT as a constant
Xen: Support for interdomain event channel
Xen: Support for HVM_op Hypercall
Xen: Support for memory_op Hypercall
Xen: Support for sched_op hypercall
Xen: Shared info for CPU yield support and xenbus protocol
Xen: Xenstore communication via xenbus
Xen: Xenstore example -do not apply

 Makefile          |    2 +-
 src/bitops.h      |   14 ++
 src/memmap.h      |    2 +
 src/post.c        |    2 +
 src/virtio-ring.h |    2 +-
 src/xen-xs.c      |  251 +++++++++++++++++++++++++++++++++++++
 src/xen-xs.h      |    9 ++
 src/xen.c         |   20 +++-
 src/xen.h         |  357 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 9 files changed, 653 insertions(+), 6 deletions(-)
 create mode 100644 src/bitops.h
 create mode 100644 src/xen-xs.c
 create mode 100644 src/xen-xs.h
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 1/10 Xen: Guest Handlers and Copyrights

These are used as part of the Xen hypercall interfaces.

---
 src/xen.h |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 58 insertions(+), 3 deletions(-)
src/xen.h +58 -3
index 0ed1e9f..f65078a 100644
@@ -17,6 +17,8 @@ static inline int usingXen(void) {
 }
 
 unsigned long xen_hypercall_page;
+typedef unsigned long xen_ulong_t;
+typedef unsigned long xen_pfn_t;
 
 #define _hypercall0(type, name)                                         \
 ({                                                                      \
@@ -121,15 +123,68 @@ unsigned long xen_hypercall_page;
  * DEALINGS IN THE SOFTWARE.
  */
 
-/* xen.h */
+/******************************************************************************
+ * arch-x86/xen.h
+ *
+ * Guest OS interface to x86 Xen.
+ *
+ * Copyright (c) 2004-2006, K A Fraser
+ */
 
-#define __HYPERVISOR_xen_version          17
 
-/* version.h */
+/* Structural guest handles introduced in 0x00030201. */
+#define ___DEFINE_XEN_GUEST_HANDLE(name, type) \
+    typedef struct { type *p; } __guest_handle_ ## name
+
+#define __DEFINE_XEN_GUEST_HANDLE(name, type) \
+    ___DEFINE_XEN_GUEST_HANDLE(name, type);   \
+    ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type)
+#define DEFINE_XEN_GUEST_HANDLE(name)   __DEFINE_XEN_GUEST_HANDLE(name, name)
+#define __XEN_GUEST_HANDLE(name)        __guest_handle_ ## name
+#define XEN_GUEST_HANDLE(name)          __XEN_GUEST_HANDLE(name)
+#define set_xen_guest_handle_raw(hnd, val)  do { (hnd).p = val; } while (0)
+#define set_xen_guest_handle(hnd, val) set_xen_guest_handle_raw(hnd, val)
+
+/******************************************************************************
+ * version.h
+ *
+ * Xen version, type, and compile information.
+ *
+ * Copyright (c) 2005, Nguyen Anh Quynh <[email protected]>
+ * Copyright (c) 2005, Keir Fraser <[email protected]>
+ */
 
 /* arg == xen_extraversion_t. */
 #define XENVER_extraversion 1
 typedef char xen_extraversion_t[16];
 #define XEN_EXTRAVERSION_LEN (sizeof(xen_extraversion_t))
 
+/******************************************************************************
+ * xen.h
+ *
+ * Guest OS interface to Xen.
+ *
+ * Copyright (c) 2004, K A Fraser
+ */
+
+#define DOMID_SELF  (0x7FF0U)
+
+/* Guest handles for primitive C types. */
+DEFINE_XEN_GUEST_HANDLE(char);
+__DEFINE_XEN_GUEST_HANDLE(uchar, unsigned char);
+DEFINE_XEN_GUEST_HANDLE(int);
+__DEFINE_XEN_GUEST_HANDLE(uint,  unsigned int);
+DEFINE_XEN_GUEST_HANDLE(long);
+__DEFINE_XEN_GUEST_HANDLE(ulong, unsigned long);
+DEFINE_XEN_GUEST_HANDLE(void);
+
+DEFINE_XEN_GUEST_HANDLE(u64);
+DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);
+
+__DEFINE_XEN_GUEST_HANDLE(u8,  u8);
+__DEFINE_XEN_GUEST_HANDLE(u16, u16);
+__DEFINE_XEN_GUEST_HANDLE(u32, u32);
+
+#define __HYPERVISOR_xen_version          17
+
 #endif
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH 2/10 Move PAGE_SHIFT to memmap.h

In reply to Daniel Castro

PAGE_SHIFT is used by both Virtio and Xen as a contant when moving addresses from guest space to machine space, in order to have a single definition PAGE_SHIFT has been moved to memmap.h. This has no impact on neither virtio or xen.

---
 src/memmap.h      |    2 ++
 src/virtio-ring.h |    2 +-
 2 files changed, 3 insertions(+), 1 deletions(-)
src/memmap.h +2 -0
index 01c7ddb..8674168 100644
@@ -21,6 +21,8 @@ void memmap_finalize(void);
 
 // A typical OS page size
 #define PAGE_SIZE 4096
+//Used by Virtio and Xen
+#define PAGE_SHIFT 12
 
 // e820 map storage (defined in system.c)
 extern struct e820entry e820_list[];
src/virtio-ring.h +1 -1
index b7a7aaf..fd30778 100644
@@ -4,7 +4,7 @@
 #include "types.h" // u64
 #include "memmap.h" // PAGE_SIZE
 
-#define PAGE_SHIFT 12
+
 #define PAGE_MASK  (PAGE_SIZE-1)
 
 #define virt_to_phys(v) (unsigned long)(v)
Signature · 1 line
1.7.4.1
#3 lore raw

Re: [PATCH 02/10] Move PAGE_SHIFT to memmap.h

Quoted 16 lines · Daniel Castro

PAGE_SHIFT is used by both Virtio and Xen as a contant when moving addresses from guest space to machine space, in order to have a single definition PAGE_SHIFT has been moved to memmap.h. This has no impact on neither virtio or xen.

---
 src/memmap.h      |    2 ++
 src/virtio-ring.h |    2 +-
 2 files changed, 3 insertions(+), 1 deletions(-)
src/memmap.h +0 -0
index 01c7ddb..8674168 100644

src/memmap.h void memmap_finalize(void); · line 25

Quoted 5 lines
src/memmap.h +2 -0
@@ -21,6 +21,8 @@ void memmap_finalize(void);
 
 // A typical OS page size
 #define PAGE_SIZE 4096
+//Used by Virtio and Xen
+#define PAGE_SHIFT 12

So aren't those two files also used on other architectures - say PPC64 which have a different page size - 64K. Isn't there some other defines for this? Or are the patches for that not present anywhere yet?

Quoted 24 lines
src/memmap.h +0 -0
 // e820 map storage (defined in system.c)
 extern struct e820entry e820_list[];
src/virtio-ring.h +1 -1
index b7a7aaf..fd30778 100644
@@ -4,7 +4,7 @@
 #include "types.h" // u64
 #include "memmap.h" // PAGE_SIZE
 
-#define PAGE_SHIFT 12
+
 #define PAGE_MASK  (PAGE_SIZE-1)
 
 #define virt_to_phys(v) (unsigned long)(v)
Signature · 7 lines
1.7.4.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
#4 lore raw

Re: [PATCH 02/10] Move PAGE_SHIFT to memmap.h

Quoted 18 lines · Konrad Rzeszutek Wilk
Quoted 17 lines · Daniel Castro

PAGE_SHIFT is used by both Virtio and Xen as a contant when moving addresses from guest space to machine space, in order to have a single definition PAGE_SHIFT has been moved to memmap.h. This has no impact on neither virtio or xen.

---
 src/memmap.h      |    2 ++
 src/virtio-ring.h |    2 +-
 2 files changed, 3 insertions(+), 1 deletions(-)
src/memmap.h +0 -0
index 01c7ddb..8674168 100644
@@ -21,6 +21,8 @@ void memmap_finalize(void);
 
Quoted 8 lines

src/memmap.h void memmap_finalize(void); · line 25

Quoted 4 lines
src/memmap.h +2 -0
 // A typical OS page size
 #define PAGE_SIZE 4096
+//Used by Virtio and Xen
+#define PAGE_SHIFT 12

So aren't those two files also used on other architectures - say PPC64 which have a different page size - 64K. Isn't there some other defines for this? Or are the patches for that not present anywhere yet?

This patch is against SeaBIOS, which is a reimplementation of the legacy PC BIOS -- I don't think you would want it on anything other than x86 and AFAICT SeaBIOS doesn't have any support for doing so.

Ian.

Quoted 30 lines
Quoted 25 lines
src/memmap.h +0 -0
 // e820 map storage (defined in system.c)
 extern struct e820entry e820_list[];
src/virtio-ring.h +1 -1
index b7a7aaf..fd30778 100644
@@ -4,7 +4,7 @@
 #include "types.h" // u64
 #include "memmap.h" // PAGE_SIZE
 
-#define PAGE_SHIFT 12
+
 #define PAGE_MASK  (PAGE_SIZE-1)
 
 #define virt_to_phys(v) (unsigned long)(v)
Signature · 7 lines
1.7.4.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#5 lore raw

PATCH 3/10 Xen: Use PAGE_SHIFT as a constant

In reply to Daniel Castro

PAGE_SHIFT can now be used as a contant instead of "<< 12".

---
 src/xen.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
src/xen.c +1 -1
index 4072793..5e93a41 100644
@@ -96,7 +96,7 @@ void xen_init_hypercalls(void)
 
     dprintf(1, "Allocated Xen hypercall page at %lx\n", xen_hypercall_page);
     for ( i = 0; i < eax; i++ )
-        wrmsr(ebx, xen_hypercall_page + (i << 12) + i);
+        wrmsr(ebx, xen_hypercall_page + (i << PAGE_SHIFT) + i);
 
     /* Print version information. */
     cpuid(xen_cpuid_base + 1, &eax, &ebx, &ecx, &edx);
Signature · 1 line
1.7.4.1
#6 lore raw

PATCH 4/10 Xen: Support for interdomain event channel

In reply to Daniel Castro

Added support for interdomain event_channels headers

---
 src/xen.h |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
src/xen.h +27 -0
index f65078a..b6b72b9 100644
@@ -99,6 +99,7 @@ typedef unsigned long xen_pfn_t;
     (type)__res;                                                        \
 })
 
+
 /******************************************************************************
  *
  * The following interface definitions are taken from Xen and have the
@@ -186,5 +187,31 @@ __DEFINE_XEN_GUEST_HANDLE(u16, u16);
 __DEFINE_XEN_GUEST_HANDLE(u32, u32);
 
 #define __HYPERVISOR_xen_version          17
+#define __HYPERVISOR_event_channel_op     32
+
+/******************************************************************************
+ * event_channel.h
+ *
+ * Event channels between domains.
+ *
+ * Copyright (c) 2003-2004, K A Fraser.
+ */
+
+typedef u32 evtchn_port_t;
+DEFINE_XEN_GUEST_HANDLE(evtchn_port_t);
+
+#define EVTCHNOP_send             4
+struct evtchn_send {
+    /* IN parameters. */
+    evtchn_port_t port;
+};
+typedef struct evtchn_send evtchn_send_t;
 
+/*
+ * Wrappers for hypercalls
+ */
+static inline int hypercall_event_channel_op(int cmd, void *arg)
+{
+	return _hypercall2(int, event_channel_op, cmd, arg);
+}
 #endif
Signature · 1 line
1.7.4.1
#7 lore raw

PATCH 5/10 Xen: Support for HVM_op Hypercall

In reply to Daniel Castro

Added support for hvm_op and hvm_params hypercalls.

---
 src/xen.h |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)
src/xen.h +31 -0
index b6b72b9..9e218fc 100644
@@ -188,6 +188,33 @@ __DEFINE_XEN_GUEST_HANDLE(u32, u32);
 
 #define __HYPERVISOR_xen_version          17
 #define __HYPERVISOR_event_channel_op     32
+#define __HYPERVISOR_hvm_op               34
+
+/*
+ *  from: xen/include/public/hvm/hvm_op.h
+ */
+
+/*
+ *  in an HVM guest you find your xenstore ring and evtchn via hvmparams,
+ *  HVM_PARAM_STORE_PFN and HVM_PARAM_STORE_EVTCHN.
+ *  it's a hypercall (type) hvmop, subcommand HVMOP_get_param (this is the hypercall actually) with this:
+ *  Get/set subcommands: extra argument == pointer to xen_hvm_param struct.
+*/
+#define HVMOP_set_param  0
+#define HVMOP_get_param  1
+
+/*
+ * from: include/public/hvm/params.h
+ */
+
+#define HVM_PARAM_STORE_PFN    1 //pass as index
+#define HVM_PARAM_STORE_EVTCHN 2 //pass as index
+
+struct xen_hvm_param {
+    u32 domid;    //IN
+    u32 index;    //IN
+    u64 value;    //IN/OUT
+};
 
 /******************************************************************************
  * event_channel.h
@@ -210,6 +237,10 @@ typedef struct evtchn_send evtchn_send_t;
 /*
  * Wrappers for hypercalls
  */
+static inline int hypercall_hvm_op(int cmd, void *arg)
+{
+	return _hypercall2(int, hvm_op, cmd, arg);
+}
 static inline int hypercall_event_channel_op(int cmd, void *arg)
 {
 	return _hypercall2(int, event_channel_op, cmd, arg);
Signature · 1 line
1.7.4.1
#8 lore raw

PATCH 6/10 Xen: Support for memory_op Hypercall

In reply to Daniel Castro

Adds support via hypercalls to change memory mapping, get shared_info and get the grant table from the hypervisor.

---
 src/xen.h |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)
src/xen.h +41 -0
index 9e218fc..de2b1ef 100644
@@ -186,6 +186,7 @@ __DEFINE_XEN_GUEST_HANDLE(u8,  u8);
 __DEFINE_XEN_GUEST_HANDLE(u16, u16);
 __DEFINE_XEN_GUEST_HANDLE(u32, u32);
 
+#define __HYPERVISOR_memory_op            12
 #define __HYPERVISOR_xen_version          17
 #define __HYPERVISOR_event_channel_op     32
 #define __HYPERVISOR_hvm_op               34
@@ -234,6 +235,41 @@ struct evtchn_send {
 };
 typedef struct evtchn_send evtchn_send_t;
 
+/******************************************************************************
+ * memory.h
+ *
+ * Memory reservation and information.
+ *
+ * Copyright (c) 2005, Keir Fraser <[email protected]>
+ */
+/*
+ * Sets the GPFN at which a particular page appears in the specified guest's
+ * pseudophysical address space.
+ * arg == addr of xen_add_to_physmap_t.
+ */
+#define XENMEM_add_to_physmap      7
+struct xen_add_to_physmap {
+    /* Which domain to change the mapping for. */
+    u64 domid;
+
+    /* Source mapping space. */
+#define XENMAPSPACE_shared_info 0 /* shared info page */
+#define XENMAPSPACE_grant_table 1 /* grant table page */
+#define XENMAPSPACE_gmfn        2 /* GMFN */
+    unsigned int space;
+
+#define XENMAPIDX_grant_table_status 0x80000000
+
+    /* Index into source mapping space. */
+    xen_ulong_t idx;
+
+    /* GPFN where the source mapping page should appear. */
+    xen_pfn_t     gpfn;
+};
+typedef struct xen_add_to_physmap xen_add_to_physmap_t;
+DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t);
+
+
 /*
  * Wrappers for hypercalls
  */
@@ -245,4 +281,9 @@ static inline int hypercall_event_channel_op(int cmd, void *arg)
 {
 	return _hypercall2(int, event_channel_op, cmd, arg);
 }
+static inline int hypercall_memory_op(int cmd ,void *arg)
+{
+	return _hypercall2(int, memory_op, cmd ,arg);
+}
+
 #endif
Signature · 1 line
1.7.4.1
#9 lore raw

PATCH 7/10 Xen: Support for sched_op hypercall

In reply to Daniel Castro

Adds support for CPU yield operation until event arrives.

---
 src/xen.h |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)
src/xen.h +41 -0
index de2b1ef..b70593a 100644
@@ -188,6 +188,7 @@ __DEFINE_XEN_GUEST_HANDLE(u32, u32);
 
 #define __HYPERVISOR_memory_op            12
 #define __HYPERVISOR_xen_version          17
+#define __HYPERVISOR_sched_op             29
 #define __HYPERVISOR_event_channel_op     32
 #define __HYPERVISOR_hvm_op               34
 
@@ -236,6 +237,42 @@ struct evtchn_send {
 typedef struct evtchn_send evtchn_send_t;
 
 /******************************************************************************
+ * sched.h
+ *
+ * Scheduler state interactions
+ *
+ * Copyright (c) 2005, Keir Fraser <[email protected]>
+ */
+
+
+
+/*
+ * Poll a set of event-channel ports. Return when one or more are pending. An
+ * optional timeout may be specified.
+ * @arg == pointer to sched_poll structure.
+ */
+#define SCHEDOP_poll        3
+struct sched_poll {
+    XEN_GUEST_HANDLE(evtchn_port_t) ports;
+    unsigned int nr_ports;
+    u64 timeout;
+};
+typedef struct sched_poll sched_poll_t;
+DEFINE_XEN_GUEST_HANDLE(sched_poll_t);
+
+/*
+ * Error base
+ */
+#define	EPERM		 1	/* Operation not permitted */
+#define	ENOENT		 2	/* No such file or directory */
+#define	EIO		 5	/* I/O error */
+#define	EACCES		13	/* Permission denied */
+#define	EINVAL		22	/* Invalid argument */
+#define	ENOSYS		38	/* Function not implemented */
+#define	EISCONN		106	/* Transport endpoint is already connected */
+
+
+/******************************************************************************
  * memory.h
  *
  * Memory reservation and information.
@@ -285,5 +322,9 @@ static inline int hypercall_memory_op(int cmd ,void *arg)
 {
 	return _hypercall2(int, memory_op, cmd ,arg);
 }
+static inline int hypercall_sched_op(int cmd, void *arg)
+{
+	return _hypercall2(int, sched_op, cmd, arg);
+}
 
 #endif
Signature · 1 line
1.7.4.1
#10 lore raw

PATCH 8/10 Xen: Shared info for CPU yield support and xenbus protocol

In reply to Daniel Castro

Shared info page added to complete the functionality to yield the CPU while waiting for event arrival this is used in xenbus.

Xenbus protocol are the structs needed for a xenbus implementation, they are defined in this patch but will be used later on.

---
 src/bitops.h |   14 +++++
 src/xen.c    |   18 +++++++
 src/xen.h    |  156 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 188 insertions(+), 0 deletions(-)
 create mode 100644 src/bitops.h
src/bitops.h new file +14 -0
new file mode 100644
index 0000000..550edbb
@@ -0,0 +1,14 @@
+#ifndef _BIT_OPS_H
+#define _BIT_OPS_H
+
+static inline int test_and_clear_bit(int nr, volatile void *addr)
+{
+    int oldbit;
+    asm volatile (
+        "lock ; btrl %2,%1 ; sbbl %0,%0"
+        : "=r" (oldbit), "=m" (*(volatile long *)addr)
+        : "Ir" (nr), "m" (*(volatile long *)addr) : "memory");
+    return oldbit;
+}
+
+#endif
src/xen.c +18 -0
index 5e93a41..9e6c669 100644
@@ -147,3 +147,21 @@ void xen_setup(void)
     RamSize = maxram;
     RamSizeOver4G = maxram_over4G;
 }
+
+struct shared_info *get_shared_info(void)
+{
+    static struct shared_info *shared_info = NULL;
+    struct xen_add_to_physmap xatp;
+
+    if (shared_info != NULL)
+        return shared_info;
+
+    xatp.domid = DOMID_SELF;
+    xatp.space = XENMAPSPACE_shared_info;
+    xatp.idx   = 0;
+    xatp.gpfn  = 0xfffffu;
+    shared_info = (struct shared_info *)(xatp.gpfn << PAGE_SHIFT);
+    if (hypercall_memory_op(XENMEM_add_to_physmap, &xatp) != 0)
+        panic("MAP info page fail");
+    return shared_info;
+}
src/xen.h +156 -0

180 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#11 lore raw

PATCH 9/10 Xen: Xenstore communication via xenbus

In reply to Daniel Castro

Communication with Xenstore is now possible via xenbus. Initially only xenstore_read and xenstore_directory are provided, but more operations will be added. Xenbus rings are initialized on post.c hardware init.

---
 Makefile     |    2 +-
 src/post.c   |    2 +
 src/xen-xs.c |  243 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/xen-xs.h |    8 ++
 4 files changed, 254 insertions(+), 1 deletions(-)
 create mode 100644 src/xen-xs.c
 create mode 100644 src/xen-xs.h
Makefile +1 -1
index 109091b..e4dd814 100644
@@ -20,7 +20,7 @@ SRC16=$(SRCBOTH) system.c disk.c font.c
 SRC32FLAT=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \
       acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \
       lzmadecode.c bootsplash.c jpeg.c usb-hub.c paravirt.c \
-      biostables.c xen.c bmp.c
+      biostables.c xen.c bmp.c xen-xs.c
 SRC32SEG=util.c output.c pci.c pcibios.c apm.c stacks.c
 
 cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
src/post.c +2 -0
index e195e89..be8f5ed 100644
@@ -26,6 +26,7 @@
 #include "xen.h" // xen_probe_hvm_info
 #include "ps2port.h" // ps2port_setup
 #include "virtio-blk.h" // virtio_blk_setup
+#include "xen-xs.h"
 
 
 /****************************************************************
@@ -190,6 +191,7 @@ init_hw(void)
     cbfs_payload_setup();
     ramdisk_setup();
     virtio_blk_setup();
+    xenbus_setup();
 }
 
 // Begin the boot process by invoking an int0x19 in 16bit mode.
src/xen-xs.c new file +243 -0

243 lines not on this page · raw message

src/xen-xs.h new file +8 -0
new file mode 100644
index 0000000..91e8da0
@@ -0,0 +1,8 @@
+#ifndef _XEN_XS_H
+#define _XEN_XS_H
+
+void xenbus_setup(void);
+char * xenstore_read(char *path);
+char * xenstore_directory(char *path, u32 *ans_len);
+
+#endif
Signature · 1 line
1.7.4.1
#12 lore raw

PATCH 10/10 Xen: Xenstore example -do not apply

In reply to Daniel Castro

Here is a simple example of xenstore query functionality. Please do not apply this patch.

After the xenbus ring initialization we issue a directory query for the list of virtual block devices attached to the current guest. The answer is displayed in the console. For simplicity we only print the first vbd but we leave a clue that there may be more.

---
 src/xen-xs.c |   10 +++++++++-
 src/xen-xs.h |    1 +
 2 files changed, 10 insertions(+), 1 deletions(-)
src/xen-xs.c +9 -1
index d4b6b26..1173ce2 100644
@@ -36,7 +36,7 @@ static struct xenstore_domain_interface *rings; /* Shared ring with dom0 */
 static evtchn_port_t event;                     /* Event-channel to dom0 */
 static char payload[XENSTORE_PAYLOAD_MAX + 1];  /* Unmarshalling area */
 
-
+void test_xenstore(void);
 /*
  * Connect our xenbus client to the backend.
  * Call once, before any other xenbus actions.
@@ -62,6 +62,7 @@ void xenbus_setup(void)
 	event = param.value;
 	dprintf(1,"Xenbus rings @0x%lx, event channel %lu\n",
 			(unsigned long) rings, (unsigned long) event);
+	test_xenstore();
 }
 
 /*
@@ -241,3 +242,10 @@ char * xenstore_directory(char *path, u32 *ans_len){
 	/* We know xenbus_send() nul-terminates its answer, so just pass it on. */
 	return answer;
 }
+
+void test_xenstore(void){
+	char path[11] = {'d','e','v','i','c','e','/','v','b','d','\0'};
+	u32 ans_len;
+	char * res = xenstore_directory(path,&ans_len);
+	dprintf(1,"length: %d strlen: %d vdb-id: %s .\n",ans_len,strlen(res),res);
+}
src/xen-xs.h +1 -0
index 91e8da0..6957031 100644
@@ -4,5 +4,6 @@
 void xenbus_setup(void);
 char * xenstore_read(char *path);
 char * xenstore_directory(char *path, u32 *ans_len);
+void test_xenstore(void);
 
 #endif
Signature · 1 line
1.7.4.1
#13 lore raw

PATCH 10/10 Xen: Xenstore example

In reply to Daniel Castro

After the xenbus ring initialization we issue a directory query for the list of virtual block devices attached to the current guest. The answer is displayed in the console.

---
 src/xen-xs.c |   10 +++++++++-
 src/xen-xs.h |    1 +
 2 files changed, 10 insertions(+), 1 deletions(-)
src/xen-xs.c +9 -1
index d4b6b26..1173ce2 100644
@@ -36,7 +36,7 @@ static struct xenstore_domain_interface *rings; /* Shared ring with dom0 */
 static evtchn_port_t event;                     /* Event-channel to dom0 */
 static char payload[XENSTORE_PAYLOAD_MAX + 1];  /* Unmarshalling area */
 
-
+void test_xenstore(void);
 /*
  * Connect our xenbus client to the backend.
  * Call once, before any other xenbus actions.
@@ -62,6 +62,7 @@ void xenbus_setup(void)
 	event = param.value;
 	dprintf(1,"Xenbus rings @0x%lx, event channel %lu\n",
 			(unsigned long) rings, (unsigned long) event);
+	test_xenstore();
 }
 
 /*
@@ -241,3 +242,10 @@ char * xenstore_directory(char *path, u32 *ans_len){
 	/* We know xenbus_send() nul-terminates its answer, so just pass it on. */
 	return answer;
 }
+
+void test_xenstore(void){
+	char path[11] = {'d','e','v','i','c','e','/','v','b','d','\0'};
+	u32 ans_len;
+	char * res = xenstore_directory(path,&ans_len);
+	dprintf(1,"length: %d strlen: %d vdb-id: %s .\n",ans_len,strlen(res),res);
+}
src/xen-xs.h +1 -0
index 91e8da0..6957031 100644
@@ -4,5 +4,6 @@
 void xenbus_setup(void);
 char * xenstore_read(char *path);
 char * xenstore_directory(char *path, u32 *ans_len);
+void test_xenstore(void);
 
 #endif
Signature · 1 line
1.7.4.1
#14 lore raw
In reply to Daniel Castro
Quoted 7 lines · Daniel Castro

As part of Google Summer of Code we are in the process to add Block PV-drivers to Seabios, in order to this, first we have to be able to communicate with xenstore so we can exchange information before the front and back ends connect. To communicate with xenstore we need to make seabios Xen-friendly so support for hypercalls has been added to Seabios. In the next month, Seabios will become a front-end for the block devices, connecting to dom0 back-end block device when used with Xen.

Quoted 8 lines

There is an issue, if you issue a query and the ring did not prepare the answer fast enough, after the event signal hypercall, the ring will force a ring wait for an event that will never arrive. For now this is solved by doing a dprintf after the hypercall, this gives enough time to the ring.

This patch should be applied to Seabios and must be used with qemu-upstream with xen4.1, please follow this guide for this:
http://wiki.xensource.com/xenwiki/QEMUUpstream

Cool. From me glancing at it looks pretty clean (well, the addition of the different hypercalls could be squashed in one). You should probably CC the SeaBIOS folks and QEMU devel mailing list on the next re-post.

Quoted 38 lines

Some more documentation on this can be found here:
http://wiki.xensource.com/xenwiki/SeaBIOS

Daniel Castro (10):
Xen: Guest Handlers and Copyrights
Move PAGE_SHIFT to memmap.h
Xen: Use PAGE_SHIFT as a constant
Xen: Support for interdomain event channel
Xen: Support for HVM_op Hypercall
Xen: Support for memory_op Hypercall
Xen: Support for sched_op hypercall
Xen: Shared info for CPU yield support and xenbus protocol
Xen: Xenstore communication via xenbus
Xen: Xenstore example -do not apply

 Makefile          |    2 +-
 src/bitops.h      |   14 ++
 src/memmap.h      |    2 +
 src/post.c        |    2 +
 src/virtio-ring.h |    2 +-
 src/xen-xs.c      |  251 +++++++++++++++++++++++++++++++++++++
 src/xen-xs.h      |    9 ++
 src/xen.c         |   20 +++-
 src/xen.h         |  357 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 9 files changed, 653 insertions(+), 6 deletions(-)
 create mode 100644 src/bitops.h
 create mode 100644 src/xen-xs.c
 create mode 100644 src/xen-xs.h
Signature · 7 lines
1.7.4.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel