From: Andrew Cooper Date: Wed, 30 Mar 2016 17:50:03 +0000 (+0100) Subject: Infrastructure for connecting the xenbus ring X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=f8ea3d8cab5c52744e5035157e4f1f6eb5fc6711;p=people%2Fandrewcoop%2Fxen-test-framework.git Infrastructure for connecting the xenbus ring Extra ABI and setup to obtain the xenstore ring location. Signed-off-by: Andrew Cooper --- diff --git a/arch/x86/setup.c b/arch/x86/setup.c index ab1d060..526361d 100644 --- a/arch/x86/setup.c +++ b/arch/x86/setup.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -172,6 +173,36 @@ static void setup_pv_console(void) init_pv_console(cons_ring, cons_evtchn); } +static void setup_xenbus(void) +{ + xenbus_interface_t *xb_ring; + evtchn_port_t xb_port; + + if ( IS_DEFINED(CONFIG_PV) ) + { + xb_ring = mfn_to_virt(start_info->store_mfn); + xb_port = start_info->store_evtchn; + } + else /* HVM */ + { + uint64_t raw_pfn, raw_evtchn; + int rc; + + rc = hvm_get_param(HVM_PARAM_STORE_PFN, &raw_pfn); + if ( rc ) + panic("Failed to get XenStore PFN: %d\n", rc); + + rc = hvm_get_param(HVM_PARAM_STORE_EVTCHN, &raw_evtchn); + if ( rc ) + panic("Failed to get XenStore evtchn: %d\n", rc); + + xb_ring = pfn_to_virt(raw_pfn); + xb_port = raw_evtchn; + } + + init_xenbus(xb_ring, xb_port); +} + static void map_shared_info(void) { int rc; @@ -226,6 +257,7 @@ void arch_setup(void) setup_pv_console(); map_shared_info(); + setup_xenbus(); } /* diff --git a/build/files.mk b/build/files.mk index 8c50dd4..6001a92 100644 --- a/build/files.mk +++ b/build/files.mk @@ -14,6 +14,7 @@ obj-perarch += $(ROOT)/common/libc/string.o obj-perarch += $(ROOT)/common/libc/vsnprintf.o obj-perarch += $(ROOT)/common/report.o obj-perarch += $(ROOT)/common/setup.o +obj-perarch += $(ROOT)/common/xenbus.o obj-perenv += $(ROOT)/arch/x86/decode.o obj-perenv += $(ROOT)/arch/x86/desc.o diff --git a/common/xenbus.c b/common/xenbus.c new file mode 100644 index 0000000..4a640ad --- /dev/null +++ b/common/xenbus.c @@ -0,0 +1,25 @@ +#include +#include +#include + +static xenbus_interface_t *xb_ring; +static evtchn_port_t xb_port; + +void init_xenbus(xenbus_interface_t *ring, evtchn_port_t port) +{ + if ( port >= (sizeof(shared_info.evtchn_pending) * CHAR_BIT) ) + panic("evtchn %u out of evtchn_pending[] range\n", port); + + xb_ring = ring; + xb_port = port; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/include/xen/hvm/params.h b/include/xen/hvm/params.h index 101a5c5..886b986 100644 --- a/include/xen/hvm/params.h +++ b/include/xen/hvm/params.h @@ -5,6 +5,9 @@ #ifndef XEN_PUBLIC_HVM_PARAMS_H #define XEN_PUBLIC_HVM_PARAMS_H +#define HVM_PARAM_STORE_PFN 1 +#define HVM_PARAM_STORE_EVTCHN 2 + #define HVM_PARAM_CONSOLE_PFN 17 #define HVM_PARAM_CONSOLE_EVTCHN 18 diff --git a/include/xen/io/xs_wire.h b/include/xen/io/xs_wire.h new file mode 100644 index 0000000..a963c7d --- /dev/null +++ b/include/xen/io/xs_wire.h @@ -0,0 +1,37 @@ +#ifndef XEN_PUBLIC_IO_XS_WIRE_H +#define XEN_PUBLIC_IO_XS_WIRE_H + +/* API/ABI relevent to the XenBus shared memory interface. */ + +#define XENBUS_RING_SIZE 1024 +static inline uint32_t mask_xenbus_idx(uint32_t idx) +{ + return idx & (XENBUS_RING_SIZE - 1); +} + +struct xenbus_interface { + char req[XENBUS_RING_SIZE]; /* Requests to the xenstore daemon. */ + char rsp[XENBUS_RING_SIZE]; /* Replies and async watch events. */ + uint32_t req_cons, req_prod; + uint32_t rsp_cons, rsp_prod; + uint32_t server_features; + uint32_t connection; +}; +typedef struct xenbus_interface xenbus_interface_t; + +#define XENBUS_SERVER_FEATURE_RECONNECTION 1 + +#define XENBUS_CONNECTED 0 +#define XENBUS_RECONNECT 1 + +#endif /* XEN_PUBLIC_IO_XS_WIRE_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/include/xtf.h b/include/xtf.h index 134819a..f1cebfa 100644 --- a/include/xtf.h +++ b/include/xtf.h @@ -23,6 +23,7 @@ #include #include #include +#include /* Arch specific headers. */ #include diff --git a/include/xtf/xenbus.h b/include/xtf/xenbus.h new file mode 100644 index 0000000..3ed77d5 --- /dev/null +++ b/include/xtf/xenbus.h @@ -0,0 +1,20 @@ +#ifndef XTF_XENBUS_H +#define XTF_XENBUS_H + +#include +#include +#include + +void init_xenbus(xenbus_interface_t *ring, evtchn_port_t port); + +#endif /* XTF_XENBUS_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */