Xen device model support
v14 cover Xen device model support
From: Anthony PERARD <[email protected]>
Hi all,
Update of the patch series that address comment from Jan Kiszka.
The change v13->v14:
- Remove of ram_size parameter from pc_memory_init
- set both below/above_4g_mem_size at the same place in the code.
Change v12->v13:
- There are few changes in the xen init code. A xen_hvm_init function is new
in this patch set and is call from xenfv:machine->init.
-> So "-xen-create -M xenpv" will continue to work as before this patch
series.
- There is a new reset handler to set env->halted = 0 on the first vcpu.
- One change have been made to pc_memory_init, the calculation of below/above_4g_mem_size have been moved to pc_init1. This is to remove a "random" "if (xen()) return;" in pc_memory_init.
- xen_map_block is a new function to map RAMBlock that belong to a ROM/RAM of a device.
- fix cpu_physical_memory_unmap with mapcache, Because qemu_get_ram_ptr can be called more than one time in cpu_physical_memory_map, qemu_put_ram_ptr need to be called the same amount of time.
- Add some trace_* call.
This series depends on the series "Introduce "machine" QemuOpts".
You can find a git tree here:
git://xenbits.xen.org/people/aperard/qemu-dm.git qemu-dm-v14
Anthony PERARD (13):
xen: Replace some tab-indents with spaces (clean-up).
xen: Make Xen build once.
xen: Support new libxc calls from xen unstable.
xen: Add initialisation of Xen
pc_memory_init: Move memory calculation to the caller.
xen: Add xenfv machine
piix_pci: Introduces Xen specific call for irq.
xen: Introduce Xen Interrupt Controller
Introduce qemu_put_ram_ptr
configure: Always use 64bits target physical addresses with xen
enabled.
vl.c: Introduce getter for shutdown_requested and reset_requested.
xen: Set running state in xenstore.
xen: Add Xen hypercall for sleep state in the cmos_s3 callback.
Arun Sharma (1):
xen: Initialize event channels and io rings
John Baboval (2):
xen: Adds a cap to the number of map cache entries.
pci: Use of qemu_put_ram_ptr in pci_add_option_rom.
Jun Nakajima (1):
xen: Introduce the Xen mapcache
Makefile.target | 14 +- configure | 71 ++++++- cpu-common.h | 1 + exec.c | 86 +++++++- hw/pc.c | 17 +-- hw/pc.h | 8 +- hw/pc_piix.c | 69 ++++++- hw/pci.c | 2 + hw/piix_pci.c | 47 ++++- hw/xen.h | 41 ++++ hw/xen_backend.c | 421 +++++++++++++++++++---------------- hw/xen_backend.h | 6 +- hw/xen_common.h | 106 ++++++++-- hw/xen_disk.c | 496 ++++++++++++++++++++++------------------- hw/xen_domainbuild.c | 3 +- hw/xen_machine_pv.c | 1 + hw/xen_nic.c | 265 ++++++++++++---------- sysemu.h | 2 + trace-events | 13 + vl.c | 12 + xen-all.c | 605 ++++++++++++++++++++++++++++++++++++++++++++++++++ xen-mapcache-stub.c | 44 ++++ xen-mapcache.c | 375 +++++++++++++++++++++++++++++++ xen-mapcache.h | 37 +++ xen-stub.c | 41 ++++ 25 files changed, 2187 insertions(+), 596 deletions(-) create mode 100644 xen-all.c create mode 100644 xen-mapcache-stub.c create mode 100644 xen-mapcache.c create mode 100644 xen-mapcache.h create mode 100644 xen-stub.c
Signature · 1 line
1.7.2.5
PATCH v14 1/17 xen: Replace some tab-indents with spaces (clean-up).
From: Anthony PERARD <[email protected]>
And put braces for blocks with a single statement.
--- hw/xen_backend.c | 411 +++++++++++++++++++++++++-------------------- hw/xen_disk.c | 492 +++++++++++++++++++++++++++++------------------------- hw/xen_nic.c | 265 ++++++++++++++++-------------- 3 files changed, 634 insertions(+), 534 deletions(-)
hw/xen_backend.c +227 -184
@@ -58,8 +58,9 @@ int xenstore_write_str(const char *base, const char *node, const char *val)char abspath[XEN_BUFSIZE ];snprintf (abspath,sizeof (abspath),"%s/%s" , base, node); -if (!xs_write (xenstore,0 , abspath, val,strlen (val))) -return -1 ; +if (!xs_write (xenstore,0 , abspath, val,strlen (val))) { +return -1 ; + }return 0 ; }
@@ -94,8 +95,9 @@ int xenstore_read_int(const char *base, const char *node, int *ival)int rc =-1 ; val =xenstore_read_str (base, node); -if (val &&1 ==sscanf (val,"%d" , ival)) - rc =0 ; +if (val &&1 ==sscanf (val,"%d" , ival)) { + rc =0 ; + }qemu_free (val);return rc; }
@@ -134,16 +136,16 @@ int xenstore_read_fe_int(struct XenDevice *xendev, const char *node, int *ival)const char *xenbus_strstate (enum xenbus_state state) { -static const char *const name[] = { - [ XenbusStateUnknown ] ="Unknown" , - [ XenbusStateInitialising ] ="Initialising" , - [ XenbusStateInitWait ] ="InitWait" , - [ XenbusStateInitialised ] ="Initialised" , - [ XenbusStateConnected ] ="Connected" , - [ XenbusStateClosing ] ="Closing" , - [ XenbusStateClosed ] ="Closed" , - }; -return (state <ARRAY_SIZE (name)) ? name[state] :"INVALID" ; +static const char *const name[] = { + [ XenbusStateUnknown ] ="Unknown" , + [ XenbusStateInitialising ] ="Initialising" , + [ XenbusStateInitWait ] ="InitWait" , + [ XenbusStateInitialised ] ="Initialised" , + [ XenbusStateConnected ] ="Connected" , + [ XenbusStateClosing ] ="Closing" , + [ XenbusStateClosed ] ="Closed" , + }; +return (state <ARRAY_SIZE (name)) ? name[state] :"INVALID" ; }int xen_be_set_state (struct XenDevice *xendev,enum xenbus_state state)
@@ -151,10 +153,11 @@ int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state)int rc; rc =xenstore_write_be_int (xendev,"state" , state); -if (rc <0 ) -return rc; +if (rc <0 ) { +return rc; + }xen_be_printf (xendev,1 ,"backend state: %s -> %s\n" , -xenbus_strstate (xendev->be_state),xenbus_strstate (state)); +xenbus_strstate (xendev->be_state),xenbus_strstate (state)); xendev->be_state = state;return 0 ; }
@@ -166,13 +169,16 @@ struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev)struct XenDevice *xendev; QTAILQ_FOREACH(xendev, &xendevs, next) { -if (xendev->dom != dom) -continue ; -if (xendev->dev != dev) -continue ; -if (strcmp (xendev->type, type) !=0 ) -continue ; -return xendev; +if (xendev->dom != dom) { +continue ; + } +if (xendev->dev != dev) { +continue ; + } +if (strcmp (xendev->type, type) !=0 ) { +continue ; + } +return xendev; }return NULL ; }
@@ -187,8 +193,9 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,char *dom0; xendev =xen_be_find_xendev (type, dom, dev); -if (xendev) -return xendev; +if (xendev) { +return xendev; + }/* init new xendev */ xendev =qemu_mallocz (ops->size);
@@ -199,9 +206,9 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, dom0 =xs_get_domain_path (xenstore,0 );snprintf (xendev->be,sizeof (xendev->be),"%s/backend/%s/%d/%d" , - dom0, xendev->type, xendev->dom, xendev->dev); + dom0, xendev->type, xendev->dom, xendev->dev);snprintf (xendev->name,sizeof (xendev->name),"%s-%d" , - xendev->type, xendev->dev); + xendev->type, xendev->dev);free (dom0); xendev->debug = debug;
@@ -209,28 +216,29 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, xendev->evtchndev =xc_evtchn_open ();if (xendev->evtchndev <0 ) { -xen_be_printf (NULL ,0 ,"can't open evtchn device\n" ); -qemu_free (xendev); -return NULL ; +xen_be_printf (NULL ,0 ,"can't open evtchn device\n" ); +qemu_free (xendev); +return NULL ; }fcntl (xc_evtchn_fd (xendev->evtchndev),F_SETFD ,FD_CLOEXEC );if (ops->flags &DEVOPS_FLAG_NEED_GNTDEV ) { - xendev->gnttabdev =xc_gnttab_open (); -if (xendev->gnttabdev <0 ) { -xen_be_printf (NULL ,0 ,"can't open gnttab device\n" ); -xc_evtchn_close (xendev->evtchndev); -qemu_free (xendev); -return NULL ; - } + xendev->gnttabdev =xc_gnttab_open (); +if (xendev->gnttabdev <0 ) { +xen_be_printf (NULL ,0 ,"can't open gnttab device\n" ); +xc_evtchn_close (xendev->evtchndev); +qemu_free (xendev); +return NULL ; + } }else { - xendev->gnttabdev =-1 ; + xendev->gnttabdev =-1 ; }QTAILQ_INSERT_TAIL (&xendevs, xendev, next); -if (xendev->ops->alloc) - xendev->ops->alloc (xendev); +if (xendev->ops->alloc) { + xendev->ops->alloc (xendev); + }return xendev; }
@@ -251,28 +259,33 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev) xendev = xnext; xnext = xendev->next.tqe_next; -if (xendev->dom != dom) -continue ; -if (xendev->dev != dev && dev !=-1 ) -continue ; - -if (xendev->ops->free) - xendev->ops->free (xendev); - -if (xendev->fe) { -char token[XEN_BUFSIZE ]; -snprintf (token,sizeof (token),"fe:%p" , xendev); -xs_unwatch (xenstore, xendev->fe, token); -qemu_free (xendev->fe); - } - -if (xendev->evtchndev >=0 ) -xc_evtchn_close (xendev->evtchndev); -if (xendev->gnttabdev >=0 ) -xc_gnttab_close (xendev->gnttabdev); - -QTAILQ_REMOVE (&xendevs, xendev, next); -qemu_free (xendev); +if (xendev->dom != dom) { +continue ; + } +if (xendev->dev != dev && dev !=-1 ) { +continue ; + } + +if (xendev->ops->free) { + xendev->ops->free (xendev); + } + +if (xendev->fe) { +char token[XEN_BUFSIZE ]; +snprintf (token,sizeof (token),"fe:%p" , xendev); +xs_unwatch (xenstore, xendev->fe, token); +qemu_free (xendev->fe); + } + +if (xendev->evtchndev >=0 ) { +xc_evtchn_close (xendev->evtchndev); + } +if (xendev->gnttabdev >=0 ) { +xc_gnttab_close (xendev->gnttabdev); + } + +QTAILQ_REMOVE (&xendevs, xendev, next); +qemu_free (xendev); }return NULL ; }
@@ -285,14 +298,16 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev)static void xen_be_backend_changed (struct XenDevice *xendev,const char *node) {if (node ==NULL ||strcmp (node,"online" ) ==0 ) { -if (xenstore_read_be_int (xendev,"online" , &xendev->online) ==-1 ) - xendev->online =0 ; +if (xenstore_read_be_int (xendev,"online" , &xendev->online) ==-1 ) { + xendev->online =0 ; + } }if (node) { -xen_be_printf (xendev,2 ,"backend update: %s\n" , node); -if (xendev->ops->backend_changed) - xendev->ops->backend_changed (xendev, node); +xen_be_printf (xendev,2 ,"backend update: %s\n" , node); +if (xendev->ops->backend_changed) { + xendev->ops->backend_changed (xendev, node); + } } }
@@ -301,25 +316,29 @@ static void xen_be_frontend_changed(struct XenDevice *xendev, const char *node)int fe_state;if (node ==NULL ||strcmp (node,"state" ) ==0 ) { -if (xenstore_read_fe_int (xendev,"state" , &fe_state) ==-1 ) - fe_state = XenbusStateUnknown; -if (xendev->fe_state != fe_state) -xen_be_printf (xendev,1 ,"frontend state: %s -> %s\n" , -xenbus_strstate (xendev->fe_state), -xenbus_strstate (fe_state)); - xendev->fe_state = fe_state; +if (xenstore_read_fe_int (xendev,"state" , &fe_state) ==-1 ) { + fe_state = XenbusStateUnknown; + } +if (xendev->fe_state != fe_state) { +xen_be_printf (xendev,1 ,"frontend state: %s -> %s\n" , +xenbus_strstate (xendev->fe_state), +xenbus_strstate (fe_state)); + } + xendev->fe_state = fe_state; }if (node ==NULL ||strcmp (node,"protocol" ) ==0 ) { -qemu_free (xendev->protocol); - xendev->protocol =xenstore_read_fe_str (xendev,"protocol" ); -if (xendev->protocol) -xen_be_printf (xendev,1 ,"frontend protocol: %s\n" , xendev->protocol); +qemu_free (xendev->protocol); + xendev->protocol =xenstore_read_fe_str (xendev,"protocol" ); +if (xendev->protocol) { +xen_be_printf (xendev,1 ,"frontend protocol: %s\n" , xendev->protocol); + } }if (node) { -xen_be_printf (xendev,2 ,"frontend update: %s\n" , node); -if (xendev->ops->frontend_changed) - xendev->ops->frontend_changed (xendev, node); +xen_be_printf (xendev,2 ,"frontend update: %s\n" , node); +if (xendev->ops->frontend_changed) { + xendev->ops->frontend_changed (xendev, node); + } } }
@@ -340,28 +359,28 @@ static int xen_be_try_setup(struct XenDevice *xendev)int be_state;if (xenstore_read_be_int (xendev,"state" , &be_state) ==-1 ) { -xen_be_printf (xendev,0 ,"reading backend state failed\n" ); -return -1 ; +xen_be_printf (xendev,0 ,"reading backend state failed\n" ); +return -1 ; }if (be_state != XenbusStateInitialising) { -xen_be_printf (xendev,0 ,"initial backend state is wrong (%s)\n" , -xenbus_strstate (be_state)); -return -1 ; +xen_be_printf (xendev,0 ,"initial backend state is wrong (%s)\n" , +xenbus_strstate (be_state)); +return -1 ; } xendev->fe =xenstore_read_be_str (xendev,"frontend" );if (xendev->fe ==NULL ) { -xen_be_printf (xendev,0 ,"reading frontend path failed\n" ); -return -1 ; +xen_be_printf (xendev,0 ,"reading frontend path failed\n" ); +return -1 ; }/* setup frontend watch */ snprintf (token,sizeof (token),"fe:%p" , xendev);if (!xs_watch (xenstore, xendev->fe, token)) { -xen_be_printf (xendev,0 ,"watching frontend path (%s) failed\n" , - xendev->fe); -return -1 ; +xen_be_printf (xendev,0 ,"watching frontend path (%s) failed\n" , + xendev->fe); +return -1 ; }xen_be_set_state (xendev, XenbusStateInitialising);
@@ -383,15 +402,16 @@ static int xen_be_try_init(struct XenDevice *xendev)int rc =0 ;if (!xendev->online) { -xen_be_printf (xendev,1 ,"not online\n" ); -return -1 ; +xen_be_printf (xendev,1 ,"not online\n" ); +return -1 ; } -if (xendev->ops->init) - rc = xendev->ops->init (xendev); +if (xendev->ops->init) { + rc = xendev->ops->init (xendev); + }if (rc !=0 ) { -xen_be_printf (xendev,1 ,"init() failed\n" ); -return rc; +xen_be_printf (xendev,1 ,"init() failed\n" ); +return rc; }xenstore_write_be_str (xendev,"hotplug-status" ,"connected" );
@@ -411,20 +431,21 @@ static int xen_be_try_connect(struct XenDevice *xendev)int rc =0 ;if (xendev->fe_state != XenbusStateInitialised && - xendev->fe_state != XenbusStateConnected) { -if (xendev->ops->flags &DEVOPS_FLAG_IGNORE_STATE ) { -xen_be_printf (xendev,2 ,"frontend not ready, ignoring\n" ); - }else { -xen_be_printf (xendev,2 ,"frontend not ready (yet)\n" ); -return -1 ; - } + xendev->fe_state != XenbusStateConnected) { +if (xendev->ops->flags &DEVOPS_FLAG_IGNORE_STATE ) { +xen_be_printf (xendev,2 ,"frontend not ready, ignoring\n" ); + }else { +xen_be_printf (xendev,2 ,"frontend not ready (yet)\n" ); +return -1 ; + } } -if (xendev->ops->connect) - rc = xendev->ops->connect (xendev); +if (xendev->ops->connect) { + rc = xendev->ops->connect (xendev); + }if (rc !=0 ) { -xen_be_printf (xendev,0 ,"connect() failed\n" ); -return rc; +xen_be_printf (xendev,0 ,"connect() failed\n" ); +return rc; }xen_be_set_state (xendev, XenbusStateConnected);
@@ -440,10 +461,12 @@ static void xen_be_disconnect(struct XenDevice *xendev, enum xenbus_state state) {if (xendev->be_state != XenbusStateClosing && xendev->be_state != XenbusStateClosed && - xendev->ops->disconnect) - xendev->ops->disconnect (xendev); -if (xendev->be_state != state) + xendev->ops->disconnect) { + xendev->ops->disconnect (xendev); + } +if (xendev->be_state != state) {xen_be_set_state (xendev, state); + } }/*
@@ -451,8 +474,9 @@ static void xen_be_disconnect(struct XenDevice *xendev, enum xenbus_state state)*/ static int xen_be_try_reset (struct XenDevice *xendev) { -if (xendev->fe_state != XenbusStateInitialising) +if (xendev->fe_state != XenbusStateInitialising) {return -1 ; + }xen_be_printf (xendev,1 ,"device reset (for re-connect)\n" );xen_be_set_state (xendev, XenbusStateInitialising);
@@ -468,31 +492,32 @@ void xen_be_check_state(struct XenDevice *xendev)/* frontend may request shutdown from almost anywhere */ if (xendev->fe_state == XenbusStateClosing || - xendev->fe_state == XenbusStateClosed) { -xen_be_disconnect (xendev, xendev->fe_state); -return ; + xendev->fe_state == XenbusStateClosed) { +xen_be_disconnect (xendev, xendev->fe_state); +return ; }/* check for possible backend state transitions */ for (;;) { -switch (xendev->be_state) { -case XenbusStateUnknown: - rc =xen_be_try_setup (xendev); -break ; -case XenbusStateInitialising: - rc =xen_be_try_init (xendev); -break ; -case XenbusStateInitWait: - rc =xen_be_try_connect (xendev); -break ; +switch (xendev->be_state) { +case XenbusStateUnknown: + rc =xen_be_try_setup (xendev); +break ; +case XenbusStateInitialising: + rc =xen_be_try_init (xendev); +break ; +case XenbusStateInitWait: + rc =xen_be_try_connect (xendev); +break ;case XenbusStateClosed: rc =xen_be_try_reset (xendev);break ; -default : - rc =-1 ; - } -if (rc !=0 ) -break ; +default : + rc =-1 ; + } +if (rc !=0 ) { +break ; + } } }
@@ -511,26 +536,28 @@ static int xenstore_scan(const char *type, int dom, struct XenDevOps *ops)snprintf (path,sizeof (path),"%s/backend/%s/%d" , dom0, type, dom);free (dom0);if (!xs_watch (xenstore, path, token)) { -xen_be_printf (NULL ,0 ,"xen be: watching backend path (%s) failed\n" , path); -return -1 ; +xen_be_printf (NULL ,0 ,"xen be: watching backend path (%s) failed\n" , path); +return -1 ; }/* look for backends */ dev =xs_directory (xenstore,0 , path, &cdev); -if (!dev) -return 0 ; +if (!dev) { +return 0 ; + }for (j =0 ; j < cdev; j++) { - xendev =xen_be_get_xendev (type, dom,atoi (dev[j]), ops); -if (xendev ==NULL ) -continue ; -xen_be_check_state (xendev); + xendev =xen_be_get_xendev (type, dom,atoi (dev[j]), ops); +if (xendev ==NULL ) { +continue ; + } +xen_be_check_state (xendev); }free (dev);return 0 ; }static void xenstore_update_be (char *watch,char *type,int dom, -struct XenDevOps *ops) +struct XenDevOps *ops) {struct XenDevice *xendev;char path[XEN_BUFSIZE ], *dom0;
@@ -539,25 +566,28 @@ static void xenstore_update_be(char *watch, char *type, int dom, dom0 =xs_get_domain_path (xenstore,0 ); len =snprintf (path,sizeof (path),"%s/backend/%s/%d" , dom0, type, dom);free (dom0); -if (strncmp (path, watch, len) !=0 ) -return ; +if (strncmp (path, watch, len) !=0 ) { +return ; + }if (sscanf (watch+len,"/%u/%255s" , &dev, path) !=2 ) { -strcpy (path,"" ); -if (sscanf (watch+len,"/%u" , &dev) !=1 ) - dev =-1 ; +strcpy (path,"" ); +if (sscanf (watch+len,"/%u" , &dev) !=1 ) { + dev =-1 ; + } + } +if (dev ==-1 ) { +return ; } -if (dev ==-1 ) -return ;if (0 ) { -/* FIXME: detect devices being deleted from xenstore ... */ -xen_be_del_xendev (dom, dev); +/* FIXME: detect devices being deleted from xenstore ... */ +xen_be_del_xendev (dom, dev); } xendev =xen_be_get_xendev (type, dom, dev, ops);if (xendev !=NULL ) { -xen_be_backend_changed (xendev, path); -xen_be_check_state (xendev); +xen_be_backend_changed (xendev, path); +xen_be_check_state (xendev); } }
@@ -567,10 +597,12 @@ static void xenstore_update_fe(char *watch, struct XenDevice *xendev)unsigned int len; len =strlen (xendev->fe); -if (strncmp (xendev->fe, watch, len) !=0 ) -return ; -if (watch[len] !='/' ) -return ; +if (strncmp (xendev->fe, watch, len) !=0 ) { +return ; + } +if (watch[len] !='/' ) { +return ; + } node = watch + len +1 ;xen_be_frontend_changed (xendev, node);
@@ -584,14 +616,17 @@ static void xenstore_update(void *unused)unsigned int dom, count; vec =xs_read_watch (xenstore, &count); -if (vec ==NULL ) - goto cleanup; +if (vec ==NULL ) { + goto cleanup; + }if (sscanf (vec[XS_WATCH_TOKEN ],"be:%" PRIxPTR":%d:%" PRIxPTR, - &type, &dom, &ops) ==3 ) -xenstore_update_be (vec[XS_WATCH_PATH ], (void *)type, dom, (void *)ops); -if (sscanf (vec[XS_WATCH_TOKEN ],"fe:%" PRIxPTR, &ptr) ==1 ) -xenstore_update_fe (vec[XS_WATCH_PATH ], (void *)ptr); + &type, &dom, &ops) ==3 ) { +xenstore_update_be (vec[XS_WATCH_PATH ], (void *)type, dom, (void *)ops); + } +if (sscanf (vec[XS_WATCH_TOKEN ],"fe:%" PRIxPTR, &ptr) ==1 ) { +xenstore_update_fe (vec[XS_WATCH_PATH ], (void *)ptr); + } cleanup:free (vec);
@@ -604,14 +639,15 @@ static void xen_be_evtchn_event(void *opaque) port =xc_evtchn_pending (xendev->evtchndev);if (port != xendev->local_port) { -xen_be_printf (xendev,0 ,"xc_evtchn_pending returned %d (expected %d)\n" , - port, xendev->local_port); -return ; +xen_be_printf (xendev,0 ,"xc_evtchn_pending returned %d (expected %d)\n" , + port, xendev->local_port); +return ; }xc_evtchn_unmask (xendev->evtchndev, port); -if (xendev->ops->event) - xendev->ops->event (xendev); +if (xendev->ops->event) { + xendev->ops->event (xendev); + } }/* -------------------------------------------------------------------- */
@@ -620,17 +656,18 @@ int xen_be_init(void) { xenstore =xs_daemon_open ();if (!xenstore) { -xen_be_printf (NULL ,0 ,"can't connect to xenstored\n" ); -return -1 ; +xen_be_printf (NULL ,0 ,"can't connect to xenstored\n" ); +return -1 ; } -if (qemu_set_fd_handler (xs_fileno (xenstore), xenstore_update,NULL ,NULL ) <0 ) - goto err; +if (qemu_set_fd_handler (xs_fileno (xenstore), xenstore_update,NULL ,NULL ) <0 ) { + goto err; + } xen_xc =xc_interface_open ();if (xen_xc ==-1 ) { -xen_be_printf (NULL ,0 ,"can't open xen interface\n" ); - goto err; +xen_be_printf (NULL ,0 ,"can't open xen interface\n" ); + goto err; }return 0 ;
@@ -649,24 +686,26 @@ int xen_be_register(const char *type, struct XenDevOps *ops)int xen_be_bind_evtchn (struct XenDevice *xendev) { -if (xendev->local_port !=-1 ) -return 0 ; +if (xendev->local_port !=-1 ) { +return 0 ; + } xendev->local_port =xc_evtchn_bind_interdomain - (xendev->evtchndev, xendev->dom, xendev->remote_port); + (xendev->evtchndev, xendev->dom, xendev->remote_port);if (xendev->local_port ==-1 ) { -xen_be_printf (xendev,0 ,"xc_evtchn_bind_interdomain failed\n" ); -return -1 ; +xen_be_printf (xendev,0 ,"xc_evtchn_bind_interdomain failed\n" ); +return -1 ; }xen_be_printf (xendev,2 ,"bind evtchn port %d\n" , xendev->local_port);qemu_set_fd_handler (xc_evtchn_fd (xendev->evtchndev), - xen_be_evtchn_event,NULL , xendev); + xen_be_evtchn_event,NULL , xendev);return 0 ; }void xen_be_unbind_evtchn (struct XenDevice *xendev) { -if (xendev->local_port ==-1 ) -return ; +if (xendev->local_port ==-1 ) { +return ; + }qemu_set_fd_handler (xc_evtchn_fd (xendev->evtchndev),NULL ,NULL ,NULL );xc_evtchn_unbind (xendev->evtchndev, xendev->local_port);xen_be_printf (xendev,2 ,"unbind evtchn port %d\n" , xendev->local_port);
@@ -690,17 +729,21 @@ void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, ...va_list args;if (xendev) { -if (msg_level > xendev->debug) +if (msg_level > xendev->debug) {return ; + }qemu_log ("xen be: %s: " , xendev->name); -if (msg_level ==0 ) +if (msg_level ==0 ) {fprintf (stderr,"xen be: %s: " , xendev->name); + } }else { -if (msg_level > debug) +if (msg_level > debug) {return ; + }qemu_log ("xen be core: " ); -if (msg_level ==0 ) +if (msg_level ==0 ) {fprintf (stderr,"xen be core: " ); + } }va_start (args, fmt);qemu_log_vprintf (fmt, args);
hw/xen_disk.c +265 -227
755 lines not on this page · raw message
hw/xen_nic.c +142 -123
391 lines not on this page · raw message
Signature · 1 line
1.7.2.5
PATCH v14 2/17 xen: Make Xen build once.
In reply to [email protected]From: Anthony PERARD <[email protected]>
xen_domainbuild and xen_machine_pv are built only for i386 targets.
--- Makefile.target | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile.target +1 -1
@@ -206,7 +206,7 @@ QEMU_CFLAGS += $(VNC_JPEG_CFLAGS) QEMU_CFLAGS += $(VNC_PNG_CFLAGS) # xen backend driver support -obj-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o +obj-i386-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o # Inter-VM PCI shared memory CONFIG_IVSHMEM =
Signature · 1 line
1.7.2.5
PATCH v14 3/17 xen: Support new libxc calls from xen unstable.
In reply to [email protected]From: Anthony PERARD <[email protected]>
This patch updates the libxenctrl calls in Qemu to use the new interface, otherwise Qemu wouldn't be able to build against new versions of the library.
We check libxenctrl version in configure, from Xen 3.3.0 to Xen unstable.
--- configure | 67 ++++++++++++++++++++++++++++++++++- hw/xen_backend.c | 21 ++++++----- hw/xen_backend.h | 6 ++-- hw/xen_common.h | 95 ++++++++++++++++++++++++++++++++++++++++++------- hw/xen_disk.c | 4 +- hw/xen_domainbuild.c | 3 +- 6 files changed, 164 insertions(+), 32 deletions(-)
configure +65 -2
@@ -127,6 +127,7 @@ vnc_jpeg="" vnc_png="" vnc_thread="no" xen="" +xen_ctrl_version="" linux_aio="" attr="" vhost_net=""
@@ -1180,20 +1181,81 @@ fi if test "$xen" != "no" ; then xen_libs="-lxenstore -lxenctrl -lxenguest" + + # Xen unstable cat > $TMPC <<EOF #include <xenctrl.h> #include <xs.h> -int main(void) { xs_daemon_open(); xc_interface_open(); return 0; } +#include <stdint.h> +#include <xen/hvm/hvm_info_table.h> +#if !defined(HVM_MAX_VCPUS) +# error HVM_MAX_VCPUS not defined +#endif +int main(void) { + xc_interface *xc; + xs_daemon_open(); + xc = xc_interface_open(0, 0, 0); + xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); + xc_gnttab_open(NULL, 0); + return 0; +} EOF if compile_prog "" "$xen_libs" ; then + xen_ctrl_version=410 xen=yes - libs_softmmu="$xen_libs $libs_softmmu" + + # Xen 4.0.0 + elif ( + cat > $TMPC <<EOF +#include <xenctrl.h> +#include <xs.h> +#include <stdint.h> +#include <xen/hvm/hvm_info_table.h> +#if !defined(HVM_MAX_VCPUS) +# error HVM_MAX_VCPUS not defined +#endif +int main(void) { + xs_daemon_open(); + xc_interface_open(); + xc_gnttab_open(); + xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); + return 0; +} +EOF + compile_prog "" "$xen_libs" + ) ; then + xen_ctrl_version=400 + xen=yes + + # Xen 3.3.0, 3.4.0 + elif ( + cat > $TMPC <<EOF +#include <xenctrl.h> +#include <xs.h> +int main(void) { + xs_daemon_open(); + xc_interface_open(); + xc_gnttab_open(); + xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); + return 0; +} +EOF + compile_prog "" "$xen_libs" + ) ; then + xen_ctrl_version=330 + xen=yes + + # Xen not found or unsupported else if test "$xen" = "yes" ; then feature_not_found "xen" fi xen=no fi + + if test "$xen" = yes; then + libs_softmmu="$xen_libs $libs_softmmu" + fi fi ##########################################
@@ -2847,6 +2909,7 @@ if test "$bluez" = "yes" ; then fi if test "$xen" = "yes" ; then echo "CONFIG_XEN=y" >> $config_host_mak + echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=$xen_ctrl_version" >> $config_host_mak fi if test "$io_thread" = "yes" ; then echo "CONFIG_IOTHREAD=y" >> $config_host_mak
hw/xen_backend.c +11 -10
@@ -43,7 +43,8 @@/* ------------------------------------------------------------- */ /* public */ -int xen_xc; +XenXC xen_xc =XC_HANDLER_INITIAL_VALUE ; +XenGnttab xen_xcg =XC_HANDLER_INITIAL_VALUE ;struct xs_handle *xenstore =NULL ;const char *xen_protocol;
@@ -214,8 +215,8 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, xendev->debug = debug; xendev->local_port =-1 ; - xendev->evtchndev =xc_evtchn_open (); -if (xendev->evtchndev <0 ) { + xendev->evtchndev =xen_xc_evtchn_open (NULL ,0 ); +if (xendev->evtchndev ==XC_HANDLER_INITIAL_VALUE ) {xen_be_printf (NULL ,0 ,"can't open evtchn device\n" );qemu_free (xendev);return NULL ;
@@ -223,15 +224,15 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,fcntl (xc_evtchn_fd (xendev->evtchndev),F_SETFD ,FD_CLOEXEC );if (ops->flags &DEVOPS_FLAG_NEED_GNTDEV ) { - xendev->gnttabdev =xc_gnttab_open (); -if (xendev->gnttabdev <0 ) { + xendev->gnttabdev =xen_xc_gnttab_open (NULL ,0 ); +if (xendev->gnttabdev ==XC_HANDLER_INITIAL_VALUE ) {xen_be_printf (NULL ,0 ,"can't open gnttab device\n" );xc_evtchn_close (xendev->evtchndev);qemu_free (xendev);return NULL ; } }else { - xendev->gnttabdev =-1 ; + xendev->gnttabdev =XC_HANDLER_INITIAL_VALUE ; }QTAILQ_INSERT_TAIL (&xendevs, xendev, next);
@@ -277,10 +278,10 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev)qemu_free (xendev->fe); } -if (xendev->evtchndev >=0 ) { +if (xendev->evtchndev !=XC_HANDLER_INITIAL_VALUE ) {xc_evtchn_close (xendev->evtchndev); } -if (xendev->gnttabdev >=0 ) { +if (xendev->gnttabdev !=XC_HANDLER_INITIAL_VALUE ) {xc_gnttab_close (xendev->gnttabdev); }
@@ -664,8 +665,8 @@ int xen_be_init(void) goto err; } - xen_xc =xc_interface_open (); -if (xen_xc ==-1 ) { + xen_xc =xen_xc_interface_open (0 ,0 ,0 ); +if (xen_xc ==XC_HANDLER_INITIAL_VALUE ) {xen_be_printf (NULL ,0 ,"can't open xen interface\n" ); goto err; }
hw/xen_backend.h +3 -3
@@ -45,8 +45,8 @@ struct XenDevice {int remote_port;int local_port; -int evtchndev; -int gnttabdev; +XenEvtchn evtchndev; +XenGnttab gnttabdev;struct XenDevOps *ops;QTAILQ_ENTRY (XenDevice) next;
@@ -55,7 +55,7 @@ struct XenDevice {/* ------------------------------------------------------------- */ /* variables */ -extern int xen_xc; +extern XenXC xen_xc;extern struct xs_handle *xenstore;extern const char *xen_protocol;
hw/xen_common.h +81 -14
109 lines not on this page · raw message
hw/xen_disk.c +2 -2
@@ -242,7 +242,7 @@ err:static void ioreq_unmap (struct ioreq *ioreq) { -int gnt = ioreq->blkdev->xendev.gnttabdev; +XenGnttab gnt = ioreq->blkdev->xendev.gnttabdev;int i;if (ioreq->v.niov ==0 ) {
@@ -275,7 +275,7 @@ static void ioreq_unmap(struct ioreq *ioreq)static int ioreq_map (struct ioreq *ioreq) { -int gnt = ioreq->blkdev->xendev.gnttabdev; +XenGnttab gnt = ioreq->blkdev->xendev.gnttabdev;int i;if (ioreq->v.niov ==0 ) {
hw/xen_domainbuild.c +2 -1
@@ -176,8 +176,9 @@ static int xen_domain_watcher(void)for (i =3 ; i < n; i++) {if (i == fd[0 ])continue ; -if (i == xen_xc) +if (i ==xc_fd (xen_xc)) {continue ; + }close (i); }
Signature · 1 line
1.7.2.5
PATCH v14 4/17 xen: Add initialisation of Xen
In reply to [email protected]From: Anthony PERARD <[email protected]>
The xenpv machine use the common init function.
--- Makefile.target | 9 +++++++++ hw/xen.h | 13 +++++++++++++ hw/xen_backend.c | 3 +-- hw/xen_machine_pv.c | 1 + vl.c | 2 ++ xen-all.c | 23 +++++++++++++++++++++++ xen-stub.c | 15 +++++++++++++++ 7 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 xen-all.c create mode 100644 xen-stub.c
Makefile.target +9 -0
@@ -208,6 +208,15 @@ QEMU_CFLAGS += $(VNC_PNG_CFLAGS) # xen backend driver support obj-i386-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o +ifeq ($(TARGET_BASE_ARCH), i386) + CONFIG_NO_XEN = $(if $(subst n,,$(CONFIG_XEN)),n,y) +else + CONFIG_NO_XEN = y +endif +# xen support +obj-i386-$(CONFIG_XEN) += xen-all.o +obj-$(CONFIG_NO_XEN) += xen-stub.o + # Inter-VM PCI shared memory CONFIG_IVSHMEM = ifeq ($(CONFIG_KVM), y)
hw/xen.h +13 -0
@@ -18,4 +18,17 @@ enum xen_mode {extern uint32_t xen_domid;extern enum xen_mode xen_mode; +extern int xen_allowed; + +static inline int xen_enabled (void ) +{ +#ifdef CONFIG_XEN +return xen_allowed; +#else +return 0 ; +#endif +} + +int xen_init (void ); +#endif /* QEMU_HW_XEN_H */
hw/xen_backend.c +1 -2
@@ -665,9 +665,8 @@ int xen_be_init(void) goto err; } - xen_xc =xen_xc_interface_open (0 ,0 ,0 );if (xen_xc ==XC_HANDLER_INITIAL_VALUE ) { -xen_be_printf (NULL ,0 ,"can't open xen interface\n" ); +/* Check if xen_init() have been called */ goto err; }return 0 ;
hw/xen_machine_pv.c +1 -0
@@ -114,6 +114,7 @@ static QEMUMachine xenpv_machine = { .desc = "Xen Para-virtualized PC", .init = xen_init_pv, .max_cpus = 1, + .default_machine_opts = "accel=xen", };static void xenpv_machine_init (void )
vl.c +2 -0
@@ -259,6 +259,7 @@ static NotifierList machine_init_done_notifiers =static int tcg_allowed =1 ;int kvm_allowed =0 ; +int xen_allowed =0 ;uint32_t xen_domid;enum xen_mode xen_mode =XEN_EMULATE ;
@@ -1890,6 +1891,7 @@ static struct {int *allowed; } accel_list[] = { { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed }, + { "xen", "Xen", xen_available, xen_init, &xen_allowed }, { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed }, };
xen-all.c new file +23 -0
@@ -0,0 +1,23 @@ +/* +* Copyright (C) 2010 Citrix Ltd. +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +*/ + +#include "hw/xen_common.h" +#include "hw/xen_backend.h" + +/* Initialise Xen */ + +int xen_init (void ) +{ + xen_xc =xen_xc_interface_open (0 ,0 ,0 ); +if (xen_xc ==XC_HANDLER_INITIAL_VALUE ) { +xen_be_printf (NULL ,0 ,"can't open xen interface\n" ); +return -1 ; + } + +return 0 ; +}
xen-stub.c new file +15 -0
@@ -0,0 +1,15 @@ +/* +* Copyright (C) 2010 Citrix Ltd. +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +*/ + +#include "qemu-common.h" +#include "hw/xen.h" + +int xen_init (void ) +{ +return -ENOSYS ; +}
Signature · 1 line
1.7.2.5
PATCH v14 5/17 pc_memory_init: Move memory calculation to the caller.
In reply to [email protected]From: Anthony PERARD <[email protected]>
This patch moves above_4g_mem_size and below_4g_mem_size calculation in the caller of pc_memory_init (pc_init1). And the prototype of pc_memory_init is changed because there is no need anymore to have variable pointer and the ram_size parameter.
--- hw/pc.c | 17 +++-------------- hw/pc.h | 7 +++---- hw/pc_piix.c | 12 ++++++++++-- 3 files changed, 16 insertions(+), 20 deletions(-)
hw/pc.c +3 -14
@@ -957,29 +957,18 @@ void pc_cpus_init(const char *cpu_model) } } -void pc_memory_init (ram_addr_t ram_size, -const char *kernel_filename, +void pc_memory_init (const char *kernel_filename,const char *kernel_cmdline,const char *initrd_filename, -ram_addr_t *below_4g_mem_size_p, -ram_addr_t *above_4g_mem_size_p) +ram_addr_t below_4g_mem_size, +ram_addr_t above_4g_mem_size) {char *filename;int ret, linux_boot, i;ram_addr_t ram_addr, bios_offset, option_rom_offset; -ram_addr_t below_4g_mem_size, above_4g_mem_size =0 ;int bios_size, isa_bios_size;void *fw_cfg; -if (ram_size >=0xe0000000 ) { - above_4g_mem_size = ram_size -0xe0000000 ; - below_4g_mem_size =0xe0000000 ; - }else { - below_4g_mem_size = ram_size; - } - *above_4g_mem_size_p = above_4g_mem_size; - *below_4g_mem_size_p = below_4g_mem_size; - linux_boot = (kernel_filename !=NULL );/* allocate RAM */
hw/pc.h +3 -4
@@ -129,12 +129,11 @@ void pc_cmos_set_s3_resume(void *opaque, int irq, int level);void pc_acpi_smi_interrupt (void *opaque,int irq,int level);void pc_cpus_init (const char *cpu_model); -void pc_memory_init (ram_addr_t ram_size, -const char *kernel_filename, +void pc_memory_init (const char *kernel_filename,const char *kernel_cmdline,const char *initrd_filename, -ram_addr_t *below_4g_mem_size_p, -ram_addr_t *above_4g_mem_size_p); +ram_addr_t below_4g_mem_size, +ram_addr_t above_4g_mem_size);qemu_irq *pc_allocate_cpu_irq (void );void pc_vga_init (PCIBus *pci_bus); void pc_basic_device_init(qemu_irq *isa_irq,
hw/pc_piix.c +10 -2
@@ -92,9 +92,17 @@ static void pc_init1(ram_addr_t ram_size,kvmclock_create (); } +if (ram_size >=0xe0000000 ) { + above_4g_mem_size = ram_size -0xe0000000 ; + below_4g_mem_size =0xe0000000 ; + }else { + above_4g_mem_size =0 ; + below_4g_mem_size = ram_size; + } +/* allocate ram and load rom/bios */ -pc_memory_init (ram_size, kernel_filename, kernel_cmdline, initrd_filename, - &below_4g_mem_size, &above_4g_mem_size); +pc_memory_init (kernel_filename, kernel_cmdline, initrd_filename, + below_4g_mem_size, above_4g_mem_size); cpu_irq =pc_allocate_cpu_irq (); i8259 =i8259_init (cpu_irq[0 ]);
Signature · 1 line
1.7.2.5
PATCH v14 6/17 xen: Add xenfv machine
In reply to [email protected]From: Anthony PERARD <[email protected]>
Introduce the Xen FV (Fully Virtualized) machine to Qemu, some more Xen specific call will be added in further patches.
--- hw/pc_piix.c | 41 +++++++++++++++++++++++++++++++++++++++-- hw/xen.h | 6 ++++++ xen-all.c | 24 ++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-)
hw/pc_piix.c +39 -2
@@ -38,6 +38,10 @@#include "arch_init.h" #include "blockdev.h" #include "smbus.h" +#include "xen.h" +#ifdef CONFIG_XEN +# include <xen/hvm/hvm_info_table.h> +#endif #define MAX_IDE_BUS 2
@@ -101,8 +105,10 @@ static void pc_init1(ram_addr_t ram_size, }/* allocate ram and load rom/bios */ -pc_memory_init (kernel_filename, kernel_cmdline, initrd_filename, - below_4g_mem_size, above_4g_mem_size); +if (!xen_enabled ()) { +pc_memory_init (kernel_filename, kernel_cmdline, initrd_filename, + below_4g_mem_size, above_4g_mem_size); + } cpu_irq =pc_allocate_cpu_irq (); i8259 =i8259_init (cpu_irq[0 ]);
@@ -221,6 +227,24 @@ static void pc_init_isa(ram_addr_t ram_size, initrd_filename, cpu_model, 0, 1); } +#ifdef CONFIG_XEN +static void pc_xen_hvm_init (ram_addr_t ram_size, +const char *boot_device, +const char *kernel_filename, +const char *kernel_cmdline, +const char *initrd_filename, +const char *cpu_model) +{ +if (xen_hvm_init () !=0 ) { +hw_error ("xen hardware virtual machine initialisation failed" ); + } +pc_init_pci_no_kvmclock (ram_size, boot_device, + kernel_filename, kernel_cmdline, + initrd_filename, cpu_model); +xen_vcpu_init (); +} +#endif +static QEMUMachine pc_machine = { .name ="pc-0.14" , .alias ="pc" ,
@@ -385,6 +409,16 @@ static QEMUMachine isapc_machine = { .max_cpus = 1, }; +#ifdef CONFIG_XEN +static QEMUMachine xenfv_machine = { + .name ="xenfv" , + .desc ="Xen Fully-virtualized PC" , + .init = pc_xen_hvm_init, + .max_cpus =HVM_MAX_VCPUS , + .default_machine_opts ="accel=xen" , +}; +#endif +static void pc_machine_init (void ) {qemu_register_machine (&pc_machine);
@@ -393,6 +427,9 @@ static void pc_machine_init(void)qemu_register_machine (&pc_machine_v0_11);qemu_register_machine (&pc_machine_v0_10);qemu_register_machine (&isapc_machine); +#ifdef CONFIG_XEN +qemu_register_machine (&xenfv_machine); +#endif }machine_init (pc_machine_init);
hw/xen.h +6 -0
@@ -30,5 +30,11 @@ static inline int xen_enabled(void) }int xen_init (void ); +int xen_hvm_init (void ); +void xen_vcpu_init (void ); + +#if defined(CONFIG_XEN ) &&CONFIG_XEN_CTRL_INTERFACE_VERSION <400 +# define HVM_MAX_VCPUS 32 +#endif #endif /* QEMU_HW_XEN_H */
xen-all.c +24 -0
@@ -9,6 +9,25 @@#include "hw/xen_common.h" #include "hw/xen_backend.h" +/* VCPU Operations, MMIO, IO ring ... */ + +static void xen_reset_vcpu (void *opaque) +{ +CPUState *env = opaque; + + env->halted =1 ; +} + +void xen_vcpu_init (void ) +{ +CPUState *first_cpu; + +if ((first_cpu =qemu_get_cpu (0 ))) { +qemu_register_reset (xen_reset_vcpu, first_cpu); +xen_reset_vcpu (first_cpu); + } +} +/* Initialise Xen */ int xen_init (void )
@@ -21,3 +40,8 @@ int xen_init(void)return 0 ; } + +int xen_hvm_init (void ) +{ +return 0 ; +}
Signature · 1 line
1.7.2.5
PATCH v14 7/17 piix_pci: Introduces Xen specific call for irq.
In reply to [email protected]From: Anthony PERARD <[email protected]>
This patch introduces Xen specific call in piix_pci.
The specific part for Xen is in write_config, set_irq and get_pirq.
--- hw/pc.h | 1 + hw/pc_piix.c | 6 +++++- hw/piix_pci.c | 47 ++++++++++++++++++++++++++++++++++++++++++++--- hw/xen.h | 6 ++++++ xen-all.c | 31 +++++++++++++++++++++++++++++++ xen-stub.c | 13 +++++++++++++ 6 files changed, 100 insertions(+), 4 deletions(-)
hw/pc.h +1 -0
@@ -175,6 +175,7 @@ struct PCII440FXState;typedef struct PCII440FXState PCII440FXState ;PCIBus *i440fx_init (PCII440FXState **pi440fx_state,int *piix_devfn,qemu_irq *pic,ram_addr_t ram_size); +PCIBus *i440fx_xen_init (PCII440FXState **pi440fx_state,int *piix3_devfn,qemu_irq *pic,ram_addr_t ram_size);void i440fx_init_memory_mappings (PCII440FXState *d);/* piix4.c */
hw/pc_piix.c +5 -1
@@ -120,7 +120,11 @@ static void pc_init1(ram_addr_t ram_size, isa_irq =qemu_allocate_irqs (isa_irq_handler, isa_irq_state,24 );if (pci_enabled) { - pci_bus =i440fx_init (&i440fx_state, &piix3_devfn, isa_irq, ram_size); +if (!xen_enabled ()) { + pci_bus =i440fx_init (&i440fx_state, &piix3_devfn, isa_irq, ram_size); + }else { + pci_bus =i440fx_xen_init (&i440fx_state, &piix3_devfn, isa_irq, ram_size); + } }else { pci_bus =NULL ; i440fx_state =NULL ;
hw/piix_pci.c +44 -3
88 lines not on this page · raw message
hw/xen.h +6 -0
@@ -8,6 +8,8 @@*/ #include <inttypes.h> +#include "qemu-common.h" +/* xen-machine.c */ enum xen_mode {XEN_EMULATE =0 ,// xen emulation, using xenner (default)
@@ -29,6 +31,10 @@ static inline int xen_enabled(void)#endif } +int xen_pci_slot_get_pirq (PCIDevice *pci_dev,int irq_num); +void xen_piix3_set_irq (void *opaque,int irq_num,int level); +void xen_piix_pci_write_config_client (uint32_t address,uint32_t val,int len); +int xen_init (void );int xen_hvm_init (void );void xen_vcpu_init (void );
xen-all.c +31 -0
@@ -6,9 +6,40 @@* */ +#include "hw/pci.h" #include "hw/xen_common.h" #include "hw/xen_backend.h" +/* Xen specific function for piix pci */ + +int xen_pci_slot_get_pirq (PCIDevice *pci_dev,int irq_num) +{ +return irq_num + ((pci_dev->devfn >>3 ) <<2 ); +} + +void xen_piix3_set_irq (void *opaque,int irq_num,int level) +{ +xc_hvm_set_pci_intx_level (xen_xc, xen_domid,0 ,0 , irq_num >>2 , + irq_num &3 , level); +} + +void xen_piix_pci_write_config_client (uint32_t address,uint32_t val,int len) +{ +int i; + +/* Scan for updates to PCI link routes (0x60-0x63). */ +for (i =0 ; i < len; i++) { +uint8_t v = (val >> (8 * i)) &0xff ; +if (v &0x80 ) { + v =0 ; + } + v &=0xf ; +if (((address + i) >=0x60 ) && ((address + i) <=0x63 )) { +xc_hvm_set_pci_link_route (xen_xc, xen_domid, address + i -0x60 , v); + } + } +} +/* VCPU Operations, MMIO, IO ring ... */ static void xen_reset_vcpu (void *opaque)
xen-stub.c +13 -0
@@ -9,6 +9,19 @@#include "qemu-common.h" #include "hw/xen.h" +int xen_pci_slot_get_pirq (PCIDevice *pci_dev,int irq_num) +{ +return -1 ; +} + +void xen_piix3_set_irq (void *opaque,int irq_num,int level) +{ +} + +void xen_piix_pci_write_config_client (uint32_t address,uint32_t val,int len) +{ +} +int xen_init (void ) {return -ENOSYS ;
Signature · 1 line
1.7.2.5
PATCH v14 8/17 xen: Introduce Xen Interrupt Controller
In reply to [email protected]From: Anthony PERARD <[email protected]>
Every set_irq call makes a Xen hypercall.
--- hw/pc_piix.c | 8 ++++++-- hw/xen.h | 2 ++ xen-all.c | 12 ++++++++++++ xen-stub.c | 5 +++++ 4 files changed, 25 insertions(+), 2 deletions(-)
hw/pc_piix.c +6 -2
@@ -110,8 +110,12 @@ static void pc_init1(ram_addr_t ram_size, below_4g_mem_size, above_4g_mem_size); } - cpu_irq =pc_allocate_cpu_irq (); - i8259 =i8259_init (cpu_irq[0 ]); +if (!xen_enabled ()) { + cpu_irq =pc_allocate_cpu_irq (); + i8259 =i8259_init (cpu_irq[0 ]); + }else { + i8259 =xen_interrupt_controller_init (); + } isa_irq_state =qemu_mallocz (sizeof (*isa_irq_state)); isa_irq_state->i8259 = i8259;if (pci_enabled) {
hw/xen.h +2 -0
@@ -35,6 +35,8 @@ int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num);void xen_piix3_set_irq (void *opaque,int irq_num,int level);void xen_piix_pci_write_config_client (uint32_t address,uint32_t val,int len); +qemu_irq *xen_interrupt_controller_init (void ); +int xen_init (void );int xen_hvm_init (void );void xen_vcpu_init (void );
xen-all.c +12 -0
@@ -40,6 +40,18 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len) } } +/* Xen Interrupt Controller */ + +static void xen_set_irq (void *opaque,int irq,int level) +{ +xc_hvm_set_isa_irq_level (xen_xc, xen_domid, irq, level); +} + +qemu_irq *xen_interrupt_controller_init (void ) +{ +return qemu_allocate_irqs (xen_set_irq,NULL ,16 ); +} +/* VCPU Operations, MMIO, IO ring ... */ static void xen_reset_vcpu (void *opaque)
xen-stub.c +5 -0
@@ -22,6 +22,11 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len) { } +qemu_irq *xen_interrupt_controller_init (void ) +{ +return NULL ; +} +int xen_init (void ) {return -ENOSYS ;
Signature · 1 line
1.7.2.5
PATCH v14 9/17 xen: Introduce the Xen mapcache
In reply to [email protected]From: Jun Nakajima <[email protected]>
On IA32 host or IA32 PAE host, at present, generally, we can't create an HVM guest with more than 2G memory, because generally it's almost impossible for Qemu to find a large enough and consecutive virtual address space to map an HVM guest's whole physical address space. The attached patch fixes this issue using dynamic mapping based on little blocks of memory.
Each call to qemu_get_ram_ptr makes a call to qemu_map_cache with the lock option, so mapcache will not unmap these ram_ptr.
Blocks that do not belong to the RAM, but usually to a device ROM or to a framebuffer, are handled in a separate function. So the whole RAMBlock can be map.
--- Makefile.target | 3 + configure | 3 + exec.c | 48 +++++++- hw/xen.h | 13 ++ hw/xen_common.h | 9 ++ trace-events | 10 ++ xen-all.c | 66 ++++++++++ xen-mapcache-stub.c | 44 +++++++ xen-mapcache.c | 349 +++++++++++++++++++++++++++++++++++++++++++++++++++ xen-mapcache.h | 37 ++++++ xen-stub.c | 4 + 11 files changed, 582 insertions(+), 4 deletions(-) create mode 100644 xen-mapcache-stub.c create mode 100644 xen-mapcache.c create mode 100644 xen-mapcache.h
Makefile.target +3 -0
@@ -214,8 +214,11 @@ else CONFIG_NO_XEN = y endif # xen support +CONFIG_NO_XEN_MAPCACHE = $(if $(subst n,,$(CONFIG_XEN_MAPCACHE)),n,y) obj-i386-$(CONFIG_XEN) += xen-all.o obj-$(CONFIG_NO_XEN) += xen-stub.o +obj-i386-$(CONFIG_XEN_MAPCACHE) += xen-mapcache.o +obj-$(CONFIG_NO_XEN_MAPCACHE) += xen-mapcache-stub.o # Inter-VM PCI shared memory CONFIG_IVSHMEM =
configure +3 -0
@@ -3283,6 +3283,9 @@ case "$target_arch2" in i386|x86_64) if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then echo "CONFIG_XEN=y" >> $config_target_mak + if test "$cpu" = "i386" -o "$cpu" = "x86_64"; then + echo "CONFIG_XEN_MAPCACHE=y" >> $config_target_mak + fi fi esac case "$target_arch2" in
exec.c +44 -4
105 lines not on this page · raw message
hw/xen.h +13 -0
@@ -31,6 +31,15 @@ static inline int xen_enabled(void)#endif } +static inline int xen_mapcache_enabled (void ) +{ +#ifdef CONFIG_XEN_MAPCACHE +return xen_enabled (); +#else +return 0 ; +#endif +} +int xen_pci_slot_get_pirq (PCIDevice *pci_dev,int irq_num);void xen_piix3_set_irq (void *opaque,int irq_num,int level);void xen_piix_pci_write_config_client (uint32_t address,uint32_t val,int len);
@@ -41,6 +50,10 @@ int xen_init(void);int xen_hvm_init (void );void xen_vcpu_init (void ); +#if defined(NEED_CPU_H ) && !defined(CONFIG_USER_ONLY ) +void xen_ram_alloc (ram_addr_t ram_addr,ram_addr_t size); +#endif +#if defined(CONFIG_XEN ) &&CONFIG_XEN_CTRL_INTERFACE_VERSION <400 # define HVM_MAX_VCPUS 32#endif
hw/xen_common.h +9 -0
@@ -63,6 +63,15 @@ static inline int xc_fd(int xen_xc) } +static inline int xc_domain_populate_physmap_exact + (XenXC xc_handle,uint32_t domid,unsigned long nr_extents, +unsigned int extent_order,unsigned int mem_flags,xen_pfn_t *extent_start) +{ +return xc_domain_memory_populate_physmap + (xc_handle, domid, nr_extents, extent_order, mem_flags, extent_start); +} + +/* Xen 4.1 */ #else
trace-events +10 -0
@@ -360,3 +360,13 @@ disable milkymist_uart_pulse_irq_tx(void) "Pulse IRQ TX" # hw/milkymist-vgafb.c disable milkymist_vgafb_memory_read(uint32_t addr, uint32_t value) "addr %08x value %08x" disable milkymist_vgafb_memory_write(uint32_t addr, uint32_t value) "addr %08x value %08x" + +# xen-all.c +disable xen_ram_alloc(unsigned long ram_addr, unsigned long size) "requested: %#lx, size %#lx" + +# xen-mapcache.c +disable qemu_map_cache(uint64_t phys_addr) "want %#"PRIx64"" +disable qemu_remap_bucket(uint64_t index) "index %#"PRIx64"" +disable qemu_map_cache_return(void* ptr) "%p" +disable xen_map_block(uint64_t phys_addr, uint64_t size) "%#"PRIx64", size %#"PRIx64"" +disable xen_unmap_block(void* addr, unsigned long size) "%p, size %#lx"
xen-all.c +66 -0
83 lines not on this page · raw message
xen-mapcache-stub.c new file +44 -0
44 lines not on this page · raw message
xen-mapcache.c new file +349 -0
349 lines not on this page · raw message
xen-mapcache.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Copyright (C) 2011 Citrix Ltd. +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +*/ + +#ifndef XEN_MAPCACHE_H +#define XEN_MAPCACHE_H + +#include <sys/mman.h> +#include "trace.h" + +void qemu_map_cache_init (void ); +uint8_t *qemu_map_cache (target_phys_addr_t phys_addr,target_phys_addr_t size,uint8_t lock); +void qemu_map_cache_unlock (void *phys_addr); +ram_addr_t qemu_ram_addr_from_mapcache (void *ptr); +void qemu_invalidate_entry (uint8_t *buffer); +void qemu_invalidate_map_cache (void ); + +uint8_t *xen_map_block (target_phys_addr_t phys_addr,target_phys_addr_t size); + +static inline void xen_unmap_block (void *addr,ram_addr_t size) +{ +trace_xen_unmap_block (addr, size); + +if (munmap (addr, size) !=0 ) { +hw_error ("xen_unmap_block: %s" ,strerror (errno)); + } +} + + +#define mapcache_lock () ((void)0) +#define mapcache_unlock () ((void)0) + +#endif /* !XEN_MAPCACHE_H */
xen-stub.c +4 -0
@@ -22,6 +22,10 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len) { } +void xen_ram_alloc (ram_addr_t ram_addr,ram_addr_t size) +{ +} +qemu_irq *xen_interrupt_controller_init (void ) {return NULL ;
Signature · 1 line
1.7.2.5
PATCH v14 10/17 xen: Adds a cap to the number of map cache entries.
In reply to [email protected]From: John Baboval <[email protected]>
Adds a cap to the number of map cache entries. This prevents the map cache from overwhelming system memory.
I also removed the bitmap macros and #included bitmap.h instead.
--- xen-mapcache.c | 37 +++++++++++++++---------------------- 1 files changed, 15 insertions(+), 22 deletions(-)
xen-mapcache.c +15 -22
@@ -12,6 +12,7 @@#include "hw/xen_backend.h" #include "blockdev.h" +#include "bitmap.h" #include <xen/hvm/params.h> #include <sys/mman.h>
@@ -32,15 +33,13 @@#if defined(__i386__)# define MCACHE_BUCKET_SHIFT 16 +# define MCACHE_MAX_SIZE (1UL<<31)/* 2GB Cap */ #elif defined(__x86_64__)# define MCACHE_BUCKET_SHIFT 20 +# define MCACHE_MAX_SIZE (1UL<<35)/* 32GB Cap */ #endif #define MCACHE_BUCKET_SIZE (1UL << MCACHE_BUCKET_SHIFT) -#define BITS_PER_LONG (sizeof(long) * 8) -#define BITS_TO_LONGS (bits) (((bits) + BITS_PER_LONG - 1) / BITS_PER_LONG) -#define DECLARE_BITMAP (name, bits) unsigned long name[BITS_TO_LONGS(bits)] - typedef struct MapCacheEntry { target_phys_addr_t paddr_index; uint8_t *vaddr_base;
@@ -69,11 +68,6 @@ typedef struct MapCache {static MapCache *mapcache; -static inline int test_bit (unsigned int bit,const unsigned long *map) -{ -return !!((map)[(bit) /BITS_PER_LONG ] & (1UL << ((bit) %BITS_PER_LONG ))); -} -void qemu_map_cache_init (void ) {unsigned long size;
@@ -85,9 +79,14 @@ void qemu_map_cache_init(void) mapcache->last_address_index =-1 ;getrlimit (RLIMIT_AS , &rlimit_as); - rlimit_as.rlim_cur = rlimit_as.rlim_max; +if (rlimit_as.rlim_max <MCACHE_MAX_SIZE ) { + rlimit_as.rlim_cur = rlimit_as.rlim_max; + }else { + rlimit_as.rlim_cur =MCACHE_MAX_SIZE ; + } +setrlimit (RLIMIT_AS , &rlimit_as); - mapcache->max_mcache_size = rlimit_as.rlim_max; + mapcache->max_mcache_size = rlimit_as.rlim_cur; mapcache->nr_buckets = (((mapcache->max_mcache_size >> XC_PAGE_SHIFT) +
@@ -107,7 +106,7 @@ static void qemu_remap_bucket(MapCacheEntry *entry,uint8_t *vaddr_base;xen_pfn_t *pfns;int *err; -unsigned int i, j; +unsigned int i;target_phys_addr_t nb_pfn = size >>XC_PAGE_SHIFT ;trace_qemu_remap_bucket (address_index);
@@ -136,17 +135,11 @@ static void qemu_remap_bucket(MapCacheEntry *entry, entry->vaddr_base = vaddr_base; entry->paddr_index = address_index; -for (i =0 ; i < nb_pfn; i +=BITS_PER_LONG ) { -unsigned long word =0 ; -if ((i +BITS_PER_LONG ) > nb_pfn) { - j = nb_pfn %BITS_PER_LONG ; - }else { - j =BITS_PER_LONG ; - } -while (j >0 ) { - word = (word <<1 ) | !err[i + --j]; +bitmap_zero (entry->valid_mapping, nb_pfn); +for (i =0 ; i < nb_pfn; i++) { +if (!err[i]) { +bitmap_set (entry->valid_mapping, i,1 ); } - entry->valid_mapping[i /BITS_PER_LONG ] = word; }qemu_free (pfns);
Signature · 1 line
1.7.2.5
PATCH v14 11/17 Introduce qemu_put_ram_ptr
In reply to [email protected]From: Anthony PERARD <[email protected]>
This function allows to unlock a ram_ptr give by qemu_get_ram_ptr. After a call to qemu_put_ram_ptr, the pointer may be unmap from QEMU when used with Xen.
--- cpu-common.h | 1 + exec.c | 38 +++++++++++++++++++++++++++++++++++--- trace-events | 3 +++ xen-mapcache.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 3 deletions(-)
cpu-common.h +1 -0
@@ -56,6 +56,7 @@ void *qemu_get_ram_ptr(ram_addr_t addr);/* Same but slower, to use for migration, where the order of * RAMBlocks must not change. */ void *qemu_safe_ram_ptr (ram_addr_t addr); +void qemu_put_ram_ptr (void *addr);/* This should not be used by devices. */ int qemu_ram_addr_from_host (void *ptr,ram_addr_t *ram_addr);ram_addr_t qemu_ram_addr_from_host_nofail (void *ptr);
exec.c +35 -3
@@ -3093,6 +3093,27 @@ void *qemu_safe_ram_ptr(ram_addr_t addr)return NULL ; } +void qemu_put_ram_ptr (void *addr) +{ +trace_qemu_put_ram_ptr (addr); + +if (xen_mapcache_enabled ()) { +RAMBlock *block; + + QLIST_FOREACH(block, &ram_list.blocks, next) { +if (addr == block->host) { +break ; + } + } +if (block && block->host) { +xen_unmap_block (block->host, block->length); + block->host =NULL ; + }else { +qemu_map_cache_unlock (addr); + } + } +} +int qemu_ram_addr_from_host (void *ptr,ram_addr_t *ram_addr) {RAMBlock *block;
@@ -3808,6 +3829,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,cpu_physical_memory_set_dirty_flags ( addr1, (0xff & ~CODE_DIRTY_FLAG )); } +qemu_put_ram_ptr (ptr); } }else { if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM &&
@@ -3835,9 +3857,9 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, } }else {/* RAM case */ - ptr =qemu_get_ram_ptr (pd &TARGET_PAGE_MASK ) + - (addr & ~TARGET_PAGE_MASK ); -memcpy (buf, ptr, l); + ptr =qemu_get_ram_ptr (pd &TARGET_PAGE_MASK ); +memcpy (buf, ptr + (addr & ~TARGET_PAGE_MASK ), l); +qemu_put_ram_ptr (ptr); } } len -= l;
@@ -3878,6 +3900,7 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr,/* ROM/RAM case */ ptr =qemu_get_ram_ptr (addr1);memcpy (ptr, buf, l); +qemu_put_ram_ptr (ptr); } len -= l; buf += l;
@@ -4019,6 +4042,15 @@ void cpu_physical_memory_unmap(void *buffer, target_phys_addr_t len, access_len -= l; } } +if (xen_mapcache_enabled ()) { +uint8_t *buffer1 = buffer; +uint8_t *end_buffer = buffer + len; + +while (buffer1 < end_buffer) { +qemu_put_ram_ptr (buffer1); + buffer1 +=TARGET_PAGE_SIZE ; + } + }return ; }if (is_write) {
trace-events +3 -0
@@ -370,3 +370,6 @@ disable qemu_remap_bucket(uint64_t index) "index %#"PRIx64"" disable qemu_map_cache_return(void* ptr) "%p" disable xen_map_block(uint64_t phys_addr, uint64_t size) "%#"PRIx64", size %#"PRIx64"" disable xen_unmap_block(void* addr, unsigned long size) "%p, size %#lx" + +# exec.c +disable qemu_put_ram_ptr(void* addr) "%p"
xen-mapcache.c +33 -0
@@ -196,6 +196,39 @@ uint8_t *qemu_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, ureturn mapcache->last_address_vaddr + address_offset; } +void qemu_map_cache_unlock (void *buffer) +{ +MapCacheEntry *entry =NULL , *pentry =NULL ; +MapCacheRev *reventry; +target_phys_addr_t paddr_index; +int found =0 ; + + QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) { +if (reventry->vaddr_req == buffer) { + paddr_index = reventry->paddr_index; + found =1 ; +break ; + } + } +if (!found) { +return ; + } +QTAILQ_REMOVE (&mapcache->locked_entries, reventry, next); +qemu_free (reventry); + + entry = &mapcache->entry[paddr_index % mapcache->nr_buckets]; +while (entry && entry->paddr_index != paddr_index) { + pentry = entry; + entry = entry->next; + } +if (!entry) { +return ; + } +if (entry->lock >0 ) { + entry->lock--; + } +} +ram_addr_t qemu_ram_addr_from_mapcache (void *ptr) {MapCacheRev *reventry;
Signature · 1 line
1.7.2.5
PATCH v14 12/17 configure: Always use 64bits target physical addresses with xen enabled.
In reply to [email protected]From: Anthony PERARD <[email protected]>
With MapCache, we can handle a 64b target, even with a 32b host/qemu. So, we need to have target_phys_addr_t to 64bits.
--- configure | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
configure +1 -0
@@ -3282,6 +3282,7 @@ echo "TARGET_ABI_DIR=$TARGET_ABI_DIR" >> $config_target_mak case "$target_arch2" in i386|x86_64) if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then + target_phys_bits=64 echo "CONFIG_XEN=y" >> $config_target_mak if test "$cpu" = "i386" -o "$cpu" = "x86_64"; then echo "CONFIG_XEN_MAPCACHE=y" >> $config_target_mak
Signature · 1 line
1.7.2.5
PATCH v14 13/17 pci: Use of qemu_put_ram_ptr in pci_add_option_rom.
In reply to [email protected]From: John Baboval <[email protected]>
Prevent a deadlock caused by leaving a map cache bucket locked by the preceding qemu_get_ram_ptr() call.
--- hw/pci.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
hw/pci.c +2 -0
@@ -1897,6 +1897,8 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)pci_patch_ids (pdev, ptr, size); } +qemu_put_ram_ptr (ptr); +pci_register_bar (pdev,PCI_ROM_SLOT , size,0 , pci_map_option_rom);
Signature · 1 line
1.7.2.5
PATCH v14 14/17 vl.c: Introduce getter for shutdown_requested and reset_requested.
In reply to [email protected]From: Anthony PERARD <[email protected]>
Introduce two functions qemu_shutdown_requested_get and qemu_reset_requested_get to get the value of shutdown/reset_requested without reset it.
--- sysemu.h | 2 ++ vl.c | 10 ++++++++++ 2 files changed, 12 insertions(+), 0 deletions(-)
sysemu.h +2 -0
@@ -63,6 +63,8 @@ void qemu_system_shutdown_request(void);void qemu_system_powerdown_request (void );void qemu_system_debug_request (void );void qemu_system_vmstop_request (int reason); +int qemu_shutdown_requested_get (void ); +int qemu_reset_requested_get (void );int qemu_shutdown_requested (void );int qemu_reset_requested (void );int qemu_powerdown_requested (void );
vl.c +10 -0
@@ -1161,6 +1161,16 @@ static int powerdown_requested;static int debug_requested;static int vmstop_requested; +int qemu_shutdown_requested_get (void ) +{ +return shutdown_requested; +} + +int qemu_reset_requested_get (void ) +{ +return reset_requested; +} +int qemu_shutdown_requested (void ) {int r = shutdown_requested;
Signature · 1 line
1.7.2.5
PATCH v14 15/17 xen: Initialize event channels and io rings
In reply to [email protected]From: Arun Sharma <[email protected]>
Open and bind event channels; map ioreq and buffered ioreq rings.
--- hw/xen_common.h | 2 + xen-all.c | 417 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 419 insertions(+), 0 deletions(-)
hw/xen_common.h +2 -0
@@ -107,4 +107,6 @@ static inline int xc_fd(xc_interface *xen_xc) }#endif +void destroy_hvm_domain (void ); +#endif /* QEMU_HW_XEN_COMMON_H */
xen-all.c +417 -0
446 lines not on this page · raw message
Signature · 1 line
1.7.2.5
PATCH v14 16/17 xen: Set running state in xenstore.
In reply to [email protected]From: Anthony PERARD <[email protected]>
This tells to the xen management tool that the machine can begin run.
--- xen-all.c | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-)
xen-all.c +23 -0
@@ -64,6 +64,8 @@ typedef struct XenIOState {/* which vcpu we are serving */ int send_vcpu; +struct xs_handle *xenstore; +Notifier exit; } XenIOState;
@@ -450,6 +452,17 @@ static void cpu_handle_ioreq(void *opaque) } } +static void xenstore_record_dm_state (XenIOState *s,const char *state) +{ +char path[50 ]; + +snprintf (path,sizeof (path),"/local/domain/0/device-model/%u/state" , xen_domid); +if (!xs_write (s->xenstore,XBT_NULL , path, state,strlen (state))) { +fprintf (stderr,"error recording dm state\n" ); +exit (1 ); + } +} +static void xen_main_loop_prepare (XenIOState *state) {int evtchn_fd =-1 ;
@@ -465,6 +478,9 @@ static void xen_main_loop_prepare(XenIOState *state)if (evtchn_fd !=-1 ) {qemu_set_fd_handler (evtchn_fd, cpu_handle_ioreq,NULL , state); } + +/* record state running */ +xenstore_record_dm_state (state,"running" ); }
@@ -483,6 +499,7 @@ static void xen_exit_notifier(Notifier *n)XenIOState *state =container_of (n, XenIOState, exit);xc_evtchn_close (state->xce_handle); +xs_daemon_close (state->xenstore); }int xen_init (void )
@@ -510,6 +527,12 @@ int xen_hvm_init(void)return -errno; } + state->xenstore =xs_daemon_open (); +if (state->xenstore ==NULL ) { +perror ("xen: xenstore open" ); +return -errno; + } + state->exit.notify = xen_exit_notifier;qemu_add_exit_notifier (&state->exit);
Signature · 1 line
1.7.2.5
PATCH v14 17/17 xen: Add Xen hypercall for sleep state in the cmos_s3 callback.
In reply to [email protected]From: Anthony PERARD <[email protected]>
--- hw/pc_piix.c | 6 +++++- hw/xen.h | 1 + xen-all.c | 9 +++++++++ xen-stub.c | 4 ++++ 4 files changed, 19 insertions(+), 1 deletions(-)
hw/pc_piix.c +5 -1
@@ -179,7 +179,11 @@ static void pc_init1(ram_addr_t ram_size,if (pci_enabled && acpi_enabled) {i2c_bus *smbus; - cmos_s3 =qemu_allocate_irqs (pc_cmos_set_s3_resume, rtc_state,1 ); +if (!xen_enabled ()) { + cmos_s3 =qemu_allocate_irqs (pc_cmos_set_s3_resume, rtc_state,1 ); + }else { + cmos_s3 =qemu_allocate_irqs (xen_cmos_set_s3_resume, rtc_state,1 ); + } smi_irq =qemu_allocate_irqs (pc_acpi_smi_interrupt, first_cpu,1 );/* TODO: Populate SPD eeprom data. */ smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
hw/xen.h +1 -0
@@ -43,6 +43,7 @@ static inline int xen_mapcache_enabled(void)int xen_pci_slot_get_pirq (PCIDevice *pci_dev,int irq_num);void xen_piix3_set_irq (void *opaque,int irq_num,int level);void xen_piix_pci_write_config_client (uint32_t address,uint32_t val,int len); +void xen_cmos_set_s3_resume (void *opaque,int irq,int level);qemu_irq *xen_interrupt_controller_init (void );
xen-all.c +9 -0
@@ -9,6 +9,7 @@#include <sys/mman.h> #include "hw/pci.h" +#include "hw/pc.h" #include "hw/xen_common.h" #include "hw/xen_backend.h"
@@ -99,6 +100,14 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len) } } +void xen_cmos_set_s3_resume (void *opaque,int irq,int level) +{ +pc_cmos_set_s3_resume (opaque, irq, level); +if (level) { +xc_set_hvm_param (xen_xc, xen_domid,HVM_PARAM_ACPI_S_STATE ,3 ); + } +} +/* Xen Interrupt Controller */ static void xen_set_irq (void *opaque,int irq,int level)
xen-stub.c +4 -0
@@ -22,6 +22,10 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len) { } +void xen_cmos_set_s3_resume (void *opaque,int irq,int level) +{ +} +void xen_ram_alloc (ram_addr_t ram_addr,ram_addr_t size) { }
Signature · 1 line
1.7.2.5