v2: RFC xen device model support
cover v2: RFC xen device model support
Hi all,
this is the second version of the patch series that adds xen device model support in qemu.
This is the list of changes we made on top of the last version:
- we modified the first patch to add support to the new libxc interface without removing support for the old one;
- we converted the new xen platform device to VMState and qdev;
- we addressed the code style change requests;
- we removed the register functions in piix_pci and we are now calling directly xen functions from there; we added a --enable-xen command line option to enable these code paths.
As you can see we tried to address all the comments apart from removing target-xen that is the next item on the todo list.
Anthony Perard (15):
xen: Support new libxc calls from xen unstable.
xen: Add xen_machine_fv
xen: Add a new target to qemu: target-xen
xen: xen_machine_fv, initialize xenctrl
xen: add a 8259 Interrupt Controller
xen: Add the Xen platform pci device
xen: handle xenstore events
xen: Read and write the state of the VM in xenstore
xen: Initialize event channels and io rings
xen: Introduce the Xen mapcache
xen: Introduce --enable-xen command options.
piix_pci: Introduces Xen specific call for irq.
vl.c: Introduce getter for shutdown_requested and reset_requested.
xen: destroy the VM when shutdown is requested
xen: Add a Xen specific ACPI Implementation to target-xen
Makefile.target | 34 ++ arch_init.c | 2 + arch_init.h | 1 + configure | 16 +- default-configs/xen-dm-softmmu.mak | 24 ++ hw/hw.h | 3 + hw/pci_ids.h | 2 + hw/piix_pci.c | 19 +- hw/xen.h | 11 + hw/xen_acpi_piix4.c | 424 +++++++++++++++++++ hw/xen_backend.c | 10 +- hw/xen_backend.h | 2 +- hw/xen_common.h | 29 ++- hw/xen_disk.c | 12 +- hw/xen_domainbuild.c | 2 +- hw/xen_machine_fv.c | 199 +++++++++ hw/xen_nic.c | 16 +- hw/xen_platform.c | 449 ++++++++++++++++++++ hw/xen_platform.h | 8 + qemu-options.hx | 9 + sysemu.h | 2 + target-xen/cpu.h | 122 ++++++ target-xen/exec-dm.c | 791 ++++++++++++++++++++++++++++++++++++ target-xen/helper.c | 424 +++++++++++++++++++ target-xen/i8259-xen-stub.c | 63 +++ target-xen/qemu-xen.h | 50 +++ target-xen/stub-functions.c | 42 ++ target-xen/xen_mapcache.c | 261 ++++++++++++ target-xen/xenstore.c | 168 ++++++++ target-xen/xenstore.h | 12 + vl.c | 21 + xen-all.c | 25 ++ xen-stub.c | 9 + 33 files changed, 3235 insertions(+), 27 deletions(-)
A git tree is available here:
git://xenbits.xen.org/people/sstabellini/qemu-dm.git qemu-dm-v2.
Cheers,
Stefano
P.S.
Anthony is currently on vacation so the work will be on hold for a bit and it might take some time for him to reply to your emails.
PATCH 1/15 xen: Support new libxc calls from xen unstable.
From: Anthony PERARD <[email protected]>
Update the libxenctrl calls in Qemu to use the new interface, otherwise Qemu wouldn't be able to build against new versions of the library.
--- configure | 5 +++++ hw/xen_backend.c | 10 +++++----- hw/xen_backend.h | 2 +- hw/xen_common.h | 23 ++++++++++++++++++++++- hw/xen_disk.c | 12 ++++++------ hw/xen_domainbuild.c | 2 +- hw/xen_nic.c | 16 ++++++++-------- 7 files changed, 48 insertions(+), 22 deletions(-)
configure +5 -0
@@ -1102,7 +1102,12 @@ if test "$xen" != "no" ; then cat > $TMPC <<EOF #include <xenctrl.h> #include <xs.h> +#include <xen/xen-compat.h> +#if __XEN_LATEST_INTERFACE_VERSION__ < 0x0003020a int main(void) { xs_daemon_open(); xc_interface_open(); return 0; } +#else +int main(void) { xs_daemon_open(); xc_interface_open(0, 0, 0); return 0; } +#endif EOF if compile_prog "" "$xen_libs" ; then xen=yes
hw/xen_backend.c +5 -5
@@ -43,7 +43,7 @@/* ------------------------------------------------------------- */ /* public */ -int xen_xc; +qemu_xc_interface xen_xc =XC_HANDLER_INITIAL_VALUE ;struct xs_handle *xenstore =NULL ;const char *xen_protocol;
@@ -216,7 +216,7 @@ 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 (); + xendev->gnttabdev =xc_gnttab_open (xen_xc);if (xendev->gnttabdev <0 ) {xen_be_printf (NULL ,0 ,"can't open gnttab device\n" );xc_evtchn_close (xendev->evtchndev);
@@ -269,7 +269,7 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev)if (xendev->evtchndev >=0 )xc_evtchn_close (xendev->evtchndev);if (xendev->gnttabdev >=0 ) -xc_gnttab_close (xendev->gnttabdev); +xc_gnttab_close (xen_xc, xendev->gnttabdev);QTAILQ_REMOVE (&xendevs, xendev, next);qemu_free (xendev);
@@ -627,8 +627,8 @@ int xen_be_init(void)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_xc =xc_interface_open (NULL ,NULL ,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 +1 -1
@@ -57,7 +57,7 @@ struct XenDevice {/* ------------------------------------------------------------- */ /* variables */ -extern int xen_xc; +extern qemu_xc_interface xen_xc;extern struct xs_handle *xenstore;extern const char *xen_protocol;
hw/xen_common.h +22 -1
@@ -16,7 +16,8 @@* tweaks needed to build with different xen versions * 0x00030205 -> 3.1.0 * 0x00030207 -> 3.2.0 -* 0x00030208 -> unstable +* 0x00030209 -> 3.3.0 +* 0x0003020a -> unstable */ #include <xen/xen-compat.h> #if __XEN_LATEST_INTERFACE_VERSION__ <0x00030205
@@ -31,4 +32,24 @@# define xen_wmb () wmb()#endif +#if __XEN_LATEST_INTERFACE_VERSION__ <0x0003020a +typedef int qemu_xc_interface ; +# define XC_HANDLER_INITIAL_VALUE -1 +# define xc_fd (xen_xc) xen_xc +# define xc_interface_open (l, dl, f) xc_interface_open() +# define xc_gnttab_open (xc) xc_gnttab_open() +# define xc_gnttab_map_grant_ref (xc, gnt, domid, ref, flags) \ + xc_gnttab_map_grant_ref(gnt, domid, ref, flags) +# define xc_gnttab_map_grant_refs (xc, gnt, count, domids, refs, flags) \ + xc_gnttab_map_grant_refs(gnt, count, domids, refs, flags) +# define xc_gnttab_munmap (xc, gnt, pages, niov) xc_gnttab_munmap(gnt, pages, niov) +# define xc_gnttab_close (xc, dev) xc_gnttab_close(dev) +#else +typedef xc_interface *qemu_xc_interface ; +# define XC_HANDLER_INITIAL_VALUE NULL +/* FIXME The fd of xen_xc is now xen_xc->fd */ +/* fd is the first field, so this works */ +# define xc_fd (xen_xc) (*(int*)xen_xc) +#endif +#endif /* QEMU_HW_XEN_COMMON_H */
hw/xen_disk.c +6 -6
@@ -242,7 +242,7 @@ static void ioreq_unmap(struct ioreq *ioreq)if (batch_maps) {if (!ioreq->pages)return ; -if (xc_gnttab_munmap (gnt, ioreq->pages, ioreq->v.niov) !=0 ) +if (xc_gnttab_munmap (xen_xc, gnt, ioreq->pages, ioreq->v.niov) !=0 )xen_be_printf (&ioreq->blkdev->xendev,0 ,"xc_gnttab_munmap failed: %s\n" ,strerror (errno)); ioreq->blkdev->cnt_map -= ioreq->v.niov;
@@ -251,7 +251,7 @@ static void ioreq_unmap(struct ioreq *ioreq)for (i =0 ; i < ioreq->v.niov; i++) {if (!ioreq->page[i])continue ; -if (xc_gnttab_munmap (gnt, ioreq->page[i],1 ) !=0 ) +if (xc_gnttab_munmap (xen_xc, gnt, ioreq->page[i],1 ) !=0 )xen_be_printf (&ioreq->blkdev->xendev,0 ,"xc_gnttab_munmap failed: %s\n" ,strerror (errno)); ioreq->blkdev->cnt_map--;
@@ -269,7 +269,7 @@ static int ioreq_map(struct ioreq *ioreq)return 0 ;if (batch_maps) { ioreq->pages =xc_gnttab_map_grant_refs - (gnt, ioreq->v.niov, ioreq->domids, ioreq->refs, ioreq->prot); + (xen_xc, gnt, ioreq->v.niov, ioreq->domids, ioreq->refs, ioreq->prot);if (ioreq->pages ==NULL ) { xen_be_printf(&ioreq->blkdev->xendev, 0, "can't map %d grant refs (%s, %d maps)\n",
@@ -283,7 +283,7 @@ static int ioreq_map(struct ioreq *ioreq) }else {for (i =0 ; i < ioreq->v.niov; i++) { ioreq->page[i] =xc_gnttab_map_grant_ref - (gnt, ioreq->domids[i], ioreq->refs[i], ioreq->prot); + (xen_xc, gnt, ioreq->domids[i], ioreq->refs[i], ioreq->prot);if (ioreq->page[i] ==NULL ) { xen_be_printf(&ioreq->blkdev->xendev, 0, "can't map grant ref %d (%s, %d maps)\n",
@@ -683,7 +683,7 @@ static int blk_connect(struct XenDevice *xendev) blkdev->protocol =BLKIF_PROTOCOL_X86_64 ; } - blkdev->sring =xc_gnttab_map_grant_ref (blkdev->xendev.gnttabdev, + blkdev->sring =xc_gnttab_map_grant_ref (xen_xc, blkdev->xendev.gnttabdev, blkdev->xendev.dom, blkdev->ring_ref,PROT_READ |PROT_WRITE );
@@ -738,7 +738,7 @@ static void blk_disconnect(struct XenDevice *xendev)xen_be_unbind_evtchn (&blkdev->xendev);if (blkdev->sring) { -xc_gnttab_munmap (blkdev->xendev.gnttabdev, blkdev->sring,1 ); +xc_gnttab_munmap (xen_xc, blkdev->xendev.gnttabdev, blkdev->sring,1 ); blkdev->cnt_map--; blkdev->sring =NULL ; }
hw/xen_domainbuild.c +1 -1
@@ -176,7 +176,7 @@ 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); }
hw/xen_nic.c +8 -8
@@ -166,7 +166,7 @@ static void net_tx_packets(struct XenNetDev *netdev) (txreq.flags & NETTXF_more_data) ?" more_data" :"" , (txreq.flags & NETTXF_extra_info) ? " extra_info" : ""); - page =xc_gnttab_map_grant_ref (netdev->xendev.gnttabdev, + page =xc_gnttab_map_grant_ref (xen_xc, netdev->xendev.gnttabdev, netdev->xendev.dom, txreq.gref,PROT_READ );if (page ==NULL ) {
@@ -185,7 +185,7 @@ static void net_tx_packets(struct XenNetDev *netdev) }else {qemu_send_packet (&netdev->nic->nc, page + txreq.offset, txreq.size); } -xc_gnttab_munmap (netdev->xendev.gnttabdev, page,1 ); +xc_gnttab_munmap (xen_xc, netdev->xendev.gnttabdev, page,1 );net_tx_response (netdev, &txreq,NETIF_RSP_OKAY ); }if (!netdev->tx_work)
@@ -272,7 +272,7 @@ static ssize_t net_rx_packet(VLANClientState *nc, const uint8_t *buf, size_t sizmemcpy (&rxreq,RING_GET_REQUEST (&netdev->rx_ring, rc),sizeof (rxreq)); netdev->rx_ring.req_cons = ++rc; - page =xc_gnttab_map_grant_ref (netdev->xendev.gnttabdev, + page =xc_gnttab_map_grant_ref (xen_xc, netdev->xendev.gnttabdev, netdev->xendev.dom, rxreq.gref,PROT_WRITE );if (page ==NULL ) {
@@ -282,7 +282,7 @@ static ssize_t net_rx_packet(VLANClientState *nc, const uint8_t *buf, size_t sizreturn -1 ; }memcpy (page +NET_IP_ALIGN , buf, size); -xc_gnttab_munmap (netdev->xendev.gnttabdev, page,1 ); +xc_gnttab_munmap (xen_xc, netdev->xendev.gnttabdev, page,1 );net_rx_response (netdev, &rxreq,NETIF_RSP_OKAY ,NET_IP_ALIGN , size,0 );return size;
@@ -350,11 +350,11 @@ static int net_connect(struct XenDevice *xendev)return -1 ; } - netdev->txs =xc_gnttab_map_grant_ref (netdev->xendev.gnttabdev, + netdev->txs =xc_gnttab_map_grant_ref (xen_xc, netdev->xendev.gnttabdev, netdev->xendev.dom, netdev->tx_ring_ref,PROT_READ |PROT_WRITE ); - netdev->rxs =xc_gnttab_map_grant_ref (netdev->xendev.gnttabdev, + netdev->rxs =xc_gnttab_map_grant_ref (xen_xc, netdev->xendev.gnttabdev, netdev->xendev.dom, netdev->rx_ring_ref,PROT_READ |PROT_WRITE );
@@ -381,11 +381,11 @@ static void net_disconnect(struct XenDevice *xendev)xen_be_unbind_evtchn (&netdev->xendev);if (netdev->txs) { -xc_gnttab_munmap (netdev->xendev.gnttabdev, netdev->txs,1 ); +xc_gnttab_munmap (xen_xc, netdev->xendev.gnttabdev, netdev->txs,1 ); netdev->txs =NULL ; }if (netdev->rxs) { -xc_gnttab_munmap (netdev->xendev.gnttabdev, netdev->rxs,1 ); +xc_gnttab_munmap (xen_xc, netdev->xendev.gnttabdev, netdev->rxs,1 ); netdev->rxs =NULL ; }if (netdev->nic) {
Signature · 1 line
1.7.0.4
PATCH 2/15 xen: Add xen_machine_fv
In reply to Stefano StabelliniFrom: Anthony PERARD <[email protected]>
Add the Xen FV (Fully Virtualized) machine to Qemu; this is groundwork to add Xen device model support in Qemu.
--- Makefile.target | 3 + hw/xen_machine_fv.c | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+), 0 deletions(-) create mode 100644 hw/xen_machine_fv.c
Makefile.target +3 -0
@@ -183,6 +183,9 @@ QEMU_CFLAGS += $(VNC_PNG_CFLAGS) # xen backend driver support obj-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o +# xen full virtualized machine +obj-$(CONFIG_XEN) += xen_machine_fv.o + # USB layer obj-$(CONFIG_USB_OHCI) += usb-ohci.o
hw/xen_machine_fv.c new file +156 -0
156 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH 3/15 xen: Add a new target to qemu: target-xen
In reply to Stefano StabelliniFrom: Anthony PERARD <[email protected]>
This patch adds a new Xen device model target to Qemu, called target-xen.
The new target makes use of the previously introduced xen_machine_fv. In order to have a fully working Xen device model we still need functionalities introduced by the following patches.
--- Makefile.target | 31 ++- arch_init.c | 2 + arch_init.h | 1 + configure | 11 +- default-configs/xen-dm-softmmu.mak | 24 ++ target-xen/cpu.h | 116 ++++++ target-xen/exec-dm.c | 791 ++++++++++++++++++++++++++++++++++++ target-xen/helper.c | 63 +++ target-xen/qemu-xen.h | 30 ++ target-xen/stub-functions.c | 42 ++ target-xen/xen_mapcache.c | 14 + 11 files changed, 1120 insertions(+), 5 deletions(-) create mode 100644 default-configs/xen-dm-softmmu.mak create mode 100644 target-xen/cpu.h create mode 100644 target-xen/exec-dm.c create mode 100644 target-xen/helper.c create mode 100644 target-xen/machine.c create mode 100644 target-xen/qemu-xen.h create mode 100644 target-xen/stub-functions.c create mode 100644 target-xen/xen_mapcache.c
Makefile.target +28 -3
@@ -183,9 +183,6 @@ QEMU_CFLAGS += $(VNC_PNG_CFLAGS) # xen backend driver support obj-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o -# xen full virtualized machine -obj-$(CONFIG_XEN) += xen_machine_fv.o - # USB layer obj-$(CONFIG_USB_OHCI) += usb-ohci.o
@@ -310,6 +307,34 @@ obj-y += $(addprefix $(HWDIR)/, $(hw-obj-y)) endif # CONFIG_SOFTMMU +# Xen Device Model +# xen full virtualized machine + +# Remove some lib, because we don't want it for a xen target. +ifeq ($(TARGET_BASE_ARCH), xen) +bad-libobj-y = exec.o translate-all.o cpu-exec.o translate.o +bad-libobj-y += tcg%.o fpu/%.o +bad-libobj-y += disas.o op_helper.o +libobj-y := $(filter-out $(bad-libobj-y), $(libobj-y)) +endif + +obj-xen-y += xen_machine_fv.o +obj-xen-y += i8259.o +obj-xen-y += pc.o +obj-xen-y += piix_pci.o +obj-xen-y += mc146818rtc.o + +obj-xen-y += xen_mapcache.o +obj-xen-y += stub-functions.o + +obj-xen-y += vga.o +obj-xen-y += hpet.o +obj-xen-y += cirrus_vga.o +obj-xen-y += smbios.o +obj-xen-y += multiboot.o +obj-xen-y += exec-dm.o +obj-xen-y += lsi53c895a.o usb-ohci.o + obj-$(CONFIG_GDBSTUB_XML) += gdbstub-xml.o $(QEMU_PROG): $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y)
arch_init.c +2 -0
@@ -75,6 +75,8 @@ const char arch_config_name[] = CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".con#define QEMU_ARCH QEMU_ARCH_SH4#elif defined(TARGET_SPARC )#define QEMU_ARCH QEMU_ARCH_SPARC +#elif defined(TARGET_XEN ) +#define QEMU_ARCH QEMU_ARCH_XEN#endif const uint32_t arch_type =QEMU_ARCH ;
arch_init.h +1 -0
@@ -16,6 +16,7 @@ enum {QEMU_ARCH_S390X =256 ,QEMU_ARCH_SH4 =512 ,QEMU_ARCH_SPARC =1024 , + QEMU_ARCH_XEN = 2048, };extern const uint32_t arch_type;
configure +9 -2
@@ -2522,6 +2522,9 @@ case "$target" in ${target_arch2}-softmmu) target_softmmu="yes" ;; + ${target_arch2}-dm-softmmu) + target_softmmu="yes" + ;; ${target_arch2}-linux-user) if test "$linux" != "yes" ; then echo "ERROR: Target '$target' is only available on a Linux host"
@@ -2587,6 +2590,10 @@ case "$target_arch2" in TARGET_BASE_ARCH=i386 target_phys_bits=64 ;; + xen) + # This is use for xen mapcache + target_phys_bits=64 + ;; alpha) target_phys_bits=64 target_nptl="yes"
@@ -2698,7 +2705,7 @@ if [ "$TARGET_ABI_DIR" = "" ]; then fi echo "TARGET_ABI_DIR=$TARGET_ABI_DIR" >> $config_target_mak case "$target_arch2" in - i386|x86_64) + i386|x86_64|xen) if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then echo "CONFIG_XEN=y" >> $config_target_mak fi
@@ -2864,7 +2871,7 @@ if test "$target_softmmu" = "yes" ; then arm) cflags="-DHAS_AUDIO $cflags" ;; - i386|mips|ppc) + i386|mips|ppc|xen) cflags="-DHAS_AUDIO -DHAS_AUDIO_CHOICE $cflags" ;; esac
default-configs/xen-dm-softmmu.mak new file +24 -0
@@ -0,0 +1,24 @@ +# Default configuration for xen-dm-softmmu + +CONFIG_VGA_PCI=y +CONFIG_VGA_ISA=y +CONFIG_VMWARE_VGA=y +CONFIG_SERIAL=y +CONFIG_PARALLEL=y +CONFIG_I8254=y +CONFIG_PCSPK=y +CONFIG_PCKBD=y +CONFIG_USB_UHCI=y +CONFIG_FDC=y +CONFIG_ACPI=y +CONFIG_APM=y +CONFIG_DMA=y +CONFIG_IDE_CORE=y +CONFIG_IDE_QDEV=y +CONFIG_IDE_PCI=y +CONFIG_IDE_ISA=y +CONFIG_IDE_PIIX=y +CONFIG_NE2000_ISA=y +CONFIG_PIIX_PCI=y +CONFIG_SOUND=y +CONFIG_XEN=y
target-xen/cpu.h new file +116 -0
116 lines not on this page · raw message
target-xen/exec-dm.c new file +791 -0
791 lines not on this page · raw message
target-xen/helper.c new file +63 -0
63 lines not on this page · raw message
target-xen/machine.c new file +0 -0
target-xen/qemu-xen.h new file +30 -0
@@ -0,0 +1,30 @@ +#ifndef QEMU_XEN_H +#define QEMU_XEN_H + +#include "hw/xen_common.h" + +/* vl.c */ + +#if defined(__i386__) || defined(__x86_64__) +#define phys_ram_addr (x) (qemu_map_cache(x, 0)) +#elif defined(__ia64__) +#define phys_ram_addr (x) (((x) < ram_size) ? (phys_ram_base + (x)) : NULL) +#endif + +/* xen_mapcache.c */ + +uint8_t *qemu_map_cache (target_phys_addr_t phys_addr,uint8_t lock); +void qemu_invalidate_entry (uint8_t *buffer); +void qemu_invalidate_map_cache (void ); + +#define mapcache_lock () ((void)0) +#define mapcache_unlock () ((void)0) + +/* target-xen/exec-dm.c */ + +int cpu_register_io_memory_fixed (int io_index, +CPUReadMemoryFunc *const *mem_read, +CPUWriteMemoryFunc *const *mem_write, +void *opaque); + +#endif /*QEMU_XEN_H*/
target-xen/stub-functions.c new file +42 -0
42 lines not on this page · raw message
target-xen/xen_mapcache.c new file +14 -0
@@ -0,0 +1,14 @@ +#include "qemu-xen.h" + +uint8_t *qemu_map_cache (target_phys_addr_t phys_addr,uint8_t lock) +{ +return phys_ram_addr (phys_addr); +} + +void qemu_invalidate_map_cache (void ) +{ +} + +void qemu_invalidate_entry (uint8_t *buffer) +{ +}
Signature · 1 line
1.7.0.4
[Qemu-devel] Re: [PATCH 03/15] xen: Add a new target to qemu: target-xen
Quoted 10 lines · [email protected] wrote:
From: Anthony PERARD <[email protected]>
This patch adds a new Xen device model target to Qemu, called target-xen.
The new target makes use of the previously introducedxen_machine_fv. In order to have a fully working Xen device model we still need functionalities introduced by the following patches.Signed-off-by Anthony PERARD <[email protected]>Signed-off-by Stefano Stabellini <[email protected]>
....
Quoted 6 lines
Makefile.target +0
-0@@ -183,9 +183,6 @@ QEMU_CFLAGS += $(VNC_PNG_CFLAGS) # xen backend driver support
....
Makefile.target obj-y += $(addprefix $(HWDIR)/, $(hw-obj-y)) · line 319
Quoted 10 lines
Makefile.target +10
-0+# Xen Device Model +# xen full virtualized machine + +# Remove some lib, because we don't want it for a xen target. +ifeq ($(TARGET_BASE_ARCH), xen) +bad-libobj-y = exec.o translate-all.o cpu-exec.o translate.o +bad-libobj-y += tcg%.o fpu/%.o +bad-libobj-y += disas.o op_helper.o +libobj-y := $(filter-out $(bad-libobj-y), $(libobj-y)) +endif
This is a hack (to call it something). Can we have a proper fix for this? Just putting that files under tcg-libobj-y (or something like that), and add it only to some targets. There is (another similar bad hack) on qemu-kvm.git to disable them for ia64. Can we get something saner here?
Later, Juan.
PD. No, this is not xen specific, disabling compilation of tcg on qemu
is basically imposible.
[Qemu-devel] Re: [PATCH 03/15] xen: Add a new target to qemu: target-xen
Quoted 8 lines · Juan Quintela
Quoted 8 lines
Makefile.target +8
-0+# Xen Device Model +# xen full virtualized machine + +# Remove some lib, because we don't want it for a xen target. +ifeq ($(TARGET_BASE_ARCH), xen) +bad-libobj-y = exec.o translate-all.o cpu-exec.o translate.o +bad-libobj-y += tcg%.o fpu/%.o +bad-libobj-y += disas.o op_helper.o
Quoted 9 lines
Makefile.target obj-y += $(addprefix $(HWDIR)/, $(hw-obj-y)) · line 319
Quoted 2 lines
Makefile.target +2
-0+libobj-y := $(filter-out $(bad-libobj-y), $(libobj-y)) +endifThis is a hack (to call it something). Can we have a proper fix for this? Just putting that files under tcg-libobj-y (or something like that), and add it only to some targets. There is (another similar bad hack) on qemu-kvm.git to disable them for ia64. Can we get something saner here?
As I mentioned in the introduction email to the series, we haven't tried to remove target-xen yet, but it is the next item on our todo list. Removing the new target will remove this hack too.
PATCH 4/15 xen: xen_machine_fv, initialize xenctrl
In reply to Stefano StabelliniFrom: Anthony PERARD <[email protected]>
Introduce a xen_dm_init function that opens the xenctrl interface; call xen_dm_init from xen_machine_fv.
--- Makefile.target | 1 + hw/xen_machine_fv.c | 8 ++++++++ target-xen/xenstore.c | 13 +++++++++++++ target-xen/xenstore.h | 6 ++++++ 4 files changed, 28 insertions(+), 0 deletions(-) create mode 100644 target-xen/xenstore.c create mode 100644 target-xen/xenstore.h
Makefile.target +1 -0
@@ -323,6 +323,7 @@ obj-xen-y += i8259.o obj-xen-y += pc.o obj-xen-y += piix_pci.o obj-xen-y += mc146818rtc.o +obj-xen-y += xenstore.o obj-xen-y += xen_mapcache.o obj-xen-y += stub-functions.o
hw/xen_machine_fv.c +8 -0
@@ -32,6 +32,8 @@#include "ide.h" #include "sysemu.h" +#include "xen_backend.h" +#include "xenstore.h" #include "xen/hvm/hvm_info_table.h" #define MAX_IDE_BUS 2
@@ -61,6 +63,12 @@ static void xen_init_fv(ram_addr_t ram_size,CPUState *env; +/* Initialize backend core & drivers */ +if (xen_dm_init () !=0 ) { +fprintf (stderr,"%s: xen backend core setup failed\n" , __FUNCTION__); +exit (1 ); + } +/* Initialize a dummy CPU */ if (cpu_model ==NULL ) {#ifdef TARGET_X86_64
target-xen/xenstore.c new file +13 -0
@@ -0,0 +1,13 @@ +#include "hw/xen_backend.h" +#include "xenstore.h" + +int xen_dm_init (void ) +{ + xen_xc =xc_interface_open (NULL ,NULL ,0 ); +if (xen_xc ==NULL ) { +xen_be_printf (NULL ,0 ,"can't open xen interface\n" ); +return -1 ; + } + +return 0 ; +}
target-xen/xenstore.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef XENSTORE_H_ +#define XENSTORE_H_ + +int xen_dm_init (void ); + +#endif /* !XENSTORE_H_ */
Signature · 1 line
1.7.0.4
PATCH 5/15 xen: add a 8259 Interrupt Controller
In reply to Stefano StabelliniFrom: Anthony PERARD <[email protected]>
Introduce a 8259 Interrupt Controller for target-xen; every set_irq call makes a Xen hypercall.
--- Makefile.target | 2 +- hw/xen_common.h | 3 ++ hw/xen_machine_fv.c | 5 +-- target-xen/i8259-xen-stub.c | 63 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 target-xen/i8259-xen-stub.c
Makefile.target +1 -1
@@ -319,7 +319,7 @@ libobj-y := $(filter-out $(bad-libobj-y), $(libobj-y)) endif obj-xen-y += xen_machine_fv.o -obj-xen-y += i8259.o +obj-xen-y += i8259-xen-stub.o obj-xen-y += pc.o obj-xen-y += piix_pci.o obj-xen-y += mc146818rtc.o
hw/xen_common.h +3 -0
@@ -52,4 +52,7 @@ typedef xc_interface *qemu_xc_interface;# define xc_fd (xen_xc) (*(int*)xen_xc)#endif +/* hw/i8259-xen-stub.c */ +qemu_irq *i8259_xen_init (void ); +#endif /* QEMU_HW_XEN_COMMON_H */
hw/xen_machine_fv.c +2 -3
@@ -32,6 +32,7 @@#include "ide.h" #include "sysemu.h" +#include "xen_common.h" #include "xen_backend.h" #include "xenstore.h" #include "xen/hvm/hvm_info_table.h"
@@ -50,7 +51,6 @@ static void xen_init_fv(ram_addr_t ram_size,PCIBus *pci_bus;PCII440FXState *i440fx_state;int piix3_devfn =-1 ; -qemu_irq *cpu_irq;qemu_irq *isa_irq;qemu_irq *i8259;qemu_irq *cmos_s3;
@@ -80,8 +80,7 @@ static void xen_init_fv(ram_addr_t ram_size, env =cpu_init (cpu_model); env->halted =1 ; - cpu_irq =pc_allocate_cpu_irq (); - i8259 =i8259_init (cpu_irq[0 ]); + i8259 =i8259_xen_init (); isa_irq_state =qemu_mallocz (sizeof (*isa_irq_state)); isa_irq_state->i8259 = i8259;
target-xen/i8259-xen-stub.c new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH 6/15 xen: Add the Xen platform pci device
In reply to Stefano StabelliniFrom: Anthony PERARD <[email protected]>
Introduce a new emulated PCI device, specific to fully virtualized Xen guests. The device is necessary for PV on HVM drivers to work.
--- Makefile.target | 1 + hw/hw.h | 3 + hw/pci_ids.h | 2 + hw/xen_machine_fv.c | 3 + hw/xen_platform.c | 449 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/xen_platform.h | 8 + 6 files changed, 466 insertions(+), 0 deletions(-) create mode 100644 hw/xen_platform.c create mode 100644 hw/xen_platform.h
Makefile.target +1 -0
@@ -324,6 +324,7 @@ obj-xen-y += pc.o obj-xen-y += piix_pci.o obj-xen-y += mc146818rtc.o obj-xen-y += xenstore.o +obj-xen-y += xen_platform.o obj-xen-y += xen_mapcache.o obj-xen-y += stub-functions.o
hw/hw.h +3 -0
@@ -651,6 +651,9 @@ extern const VMStateDescription vmstate_i2c_slave;#define VMSTATE_INT32_LE (_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t) +#define VMSTATE_UINT8_TEST (_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t) +#define VMSTATE_UINT16_TEST (_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
hw/pci_ids.h +2 -0
@@ -105,3 +105,5 @@#define PCI_DEVICE_ID_INTEL_82371AB 0x7111#define PCI_DEVICE_ID_INTEL_82371AB_2 0x7112#define PCI_DEVICE_ID_INTEL_82371AB_3 0x7113 + +#define PCI_VENDOR_ID_XENSOURCE 0x5853
hw/xen_machine_fv.c +3 -0
@@ -35,6 +35,7 @@#include "xen_common.h" #include "xen_backend.h" #include "xenstore.h" +#include "xen_platform.h" #include "xen/hvm/hvm_info_table.h" #define MAX_IDE_BUS 2
@@ -93,6 +94,8 @@ static void xen_init_fv(ram_addr_t ram_size,pc_vga_init (pci_bus); +pci_xen_platform_init (pci_bus); +/* init basic PC hardware */ pc_basic_device_init (isa_irq, &floppy_controller, &rtc_state);
hw/xen_platform.c new file +449 -0
449 lines not on this page · raw message
hw/xen_platform.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef XEN_PLATFORM_H +#define XEN_PLATFORM_H + +#include "hw/pci.h" + +void pci_xen_platform_init (PCIBus *bus); + +#endif
Signature · 1 line
1.7.0.4
PATCH 7/15 xen: handle xenstore events
In reply to Stefano StabelliniFrom: Anthony PERARD <[email protected]>
Add an handler to process xenstore events.
--- target-xen/xenstore.c | 30 +++++++++++++++++++++++++++++- 1 files changed, 29 insertions(+), 1 deletions(-)
target-xen/xenstore.c +29 -1
@@ -1,13 +1,41 @@#include "hw/xen_backend.h" #include "xenstore.h" +static void xenstore_process_event (void *opaque) +{ +char **vec; +unsigned int num; + + vec =xs_read_watch (xenstore, &num); +if (!vec) +return ; + +free (vec); +} +int xen_dm_init (void ) { + xenstore =xs_daemon_open (); +if (!xenstore) { +xen_be_printf (NULL ,0 ,"can't connect to xenstored\n" ); +return -1 ; + } + +if (qemu_set_fd_handler (xs_fileno (xenstore), xenstore_process_event,NULL ,NULL ) <0 ) + goto err; + xen_xc =xc_interface_open (NULL ,NULL ,0 );if (xen_xc ==NULL ) {xen_be_printf (NULL ,0 ,"can't open xen interface\n" ); -return -1 ; + goto err; }return 0 ; + +err: +qemu_set_fd_handler (xs_fileno (xenstore),NULL ,NULL ,NULL ); +xs_daemon_close (xenstore); + xenstore =NULL ; + +return -1 ; }
Signature · 1 line
1.7.0.4
PATCH 8/15 xen: Read and write the state of the VM in xenstore
In reply to Stefano StabelliniFrom: Anthony PERARD <[email protected]>
Introduce functions to read and write the state of the VM in xenstore.
--- hw/xen_machine_fv.c | 9 ++++ target-xen/helper.c | 7 +++ target-xen/qemu-xen.h | 3 + target-xen/xenstore.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++ target-xen/xenstore.h | 6 ++ 5 files changed, 152 insertions(+), 0 deletions(-)
hw/xen_machine_fv.c +9 -0
@@ -36,10 +36,17 @@#include "xen_backend.h" #include "xenstore.h" #include "xen_platform.h" +#include "qemu-xen.h" #include "xen/hvm/hvm_info_table.h" #define MAX_IDE_BUS 2 +static void xen_vm_change_state_handler (void *opaque,int running,int reason) +{ +if (running) +xen_main_loop_prepare (); +} + static void xen_init_fv(ram_addr_t ram_size, const char *boot_device, const char *kernel_filename,
@@ -149,6 +156,8 @@ static void xen_init_fv(ram_addr_t ram_size, }pc_pci_device_init (pci_bus); + +qemu_add_vm_change_state_handler (xen_vm_change_state_handler,NULL ); }static QEMUMachine xenfv_machine = {
target-xen/helper.c +7 -0
@@ -19,6 +19,8 @@*/ #include "cpu.h" +#include "qemu-xen.h" +#include "xenstore.h" CPUXenState *cpu_xen_init (const char *cpu_model) {
@@ -61,3 +63,8 @@ target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr) {return addr; } + +void xen_main_loop_prepare (void ) +{ +xenstore_record_dm_state ("running" ); +}
target-xen/qemu-xen.h +3 -0
@@ -27,4 +27,7 @@ int cpu_register_io_memory_fixed(int io_index, CPUWriteMemoryFunc * const *mem_write, void *opaque); +/* target-xen/helper.c */ +void xen_main_loop_prepare (void ); +#endif /*QEMU_XEN_H*/
target-xen/xenstore.c +127 -0
136 lines not on this page · raw message
target-xen/xenstore.h +6 -0
@@ -3,4 +3,10 @@int xen_dm_init (void ); +char *xenstore_vm_read (int domid,const char *key,unsigned int *len); +int xenstore_vm_write (int domid,const char *key,const char *value); + +void xenstore_record_dm (const char *subpath,const char *state); +void xenstore_record_dm_state (const char *state); +#endif /* !XENSTORE_H_ */
Signature · 1 line
1.7.0.4
PATCH 9/15 xen: Initialize event channels and io rings
In reply to Stefano StabelliniFrom: Anthony PERARD <[email protected]>
Open and bind event channels; map ioreq and buffered ioreq rings.
--- hw/xen_machine_fv.c | 21 +++ target-xen/cpu.h | 6 + target-xen/helper.c | 339 +++++++++++++++++++++++++++++++++++++++++++++++++ target-xen/qemu-xen.h | 2 + 4 files changed, 368 insertions(+), 0 deletions(-)
hw/xen_machine_fv.c +21 -0
@@ -22,6 +22,9 @@* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "config.h" + +#include <sys/mman.h> #include "hw.h" #include "pc.h"
@@ -71,12 +74,30 @@ static void xen_init_fv(ram_addr_t ram_size,CPUState *env; +unsigned long ioreq_pfn; +/* Initialize backend core & drivers */ if (xen_dm_init () !=0 ) {fprintf (stderr,"%s: xen backend core setup failed\n" , __FUNCTION__);exit (1 ); } +xc_get_hvm_param (xen_xc, xen_domid,HVM_PARAM_IOREQ_PFN , &ioreq_pfn); +fprintf (stderr,"shared page at pfn %lx\n" , ioreq_pfn); + shared_page =xc_map_foreign_range (xen_xc, xen_domid,XC_PAGE_SIZE , +PROT_READ |PROT_WRITE , ioreq_pfn); +if (shared_page ==NULL ) { +hw_error ("map shared IO page returned error %d handle=%p" , errno, xen_xc); + } + +xc_get_hvm_param (xen_xc, xen_domid,HVM_PARAM_BUFIOREQ_PFN , &ioreq_pfn); +fprintf (stderr,"buffered io page at pfn %lx\n" , ioreq_pfn); + buffered_io_page =xc_map_foreign_range (xen_xc, xen_domid,XC_PAGE_SIZE , +PROT_READ |PROT_WRITE , ioreq_pfn); +if (buffered_io_page ==NULL ) { +hw_error ("map buffered IO page returned error %d" , errno); + } +/* Initialize a dummy CPU */ if (cpu_model ==NULL ) {#ifdef TARGET_X86_64
target-xen/cpu.h +6 -0
@@ -68,6 +68,7 @@ typedef struct CPUXenState {CPUXenState *cpu_xen_init (const char *cpu_model);int cpu_xen_exec (CPUXenState *s); +void cpu_xen_close (CPUXenState *s);int cpu_get_pic_interrupt (CPUXenState *s);void cpu_set_ferr (CPUX86State *s);
@@ -113,4 +114,9 @@ static inline void cpu_get_tb_cpu_state(CPUState *env, target_ulong *pc, { } +#include <xen/hvm/ioreq.h> + +extern shared_iopage_t *shared_page; +extern buffered_iopage_t *buffered_io_page; +#endif /* CPU_XEN_H */
target-xen/helper.c +339 -0
369 lines not on this page · raw message
target-xen/qemu-xen.h +2 -0
@@ -22,12 +22,14 @@ void qemu_invalidate_map_cache(void);/* target-xen/exec-dm.c */ +void destroy_hvm_domain (void );int cpu_register_io_memory_fixed (int io_index,CPUReadMemoryFunc *const *mem_read,CPUWriteMemoryFunc *const *mem_write,void *opaque);/* target-xen/helper.c */ +extern int xce_handle;void xen_main_loop_prepare (void );#endif /*QEMU_XEN_H*/
Signature · 1 line
1.7.0.4
PATCH 10/15 xen: Introduce the Xen mapcache
In reply to Stefano StabelliniFrom: Anthony PERARD <[email protected]>
Introduce a mapcache to handle the 64bit address space of the guest from a 32bit userland process (Qemu).
The mapcache maps chucks of guest memory on demand, unmaps them when they are not needed anymore.
--- hw/xen_machine_fv.c | 7 ++ target-xen/qemu-xen.h | 15 +++ target-xen/xen_mapcache.c | 247 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 269 insertions(+), 0 deletions(-)
hw/xen_machine_fv.c +7 -0
@@ -82,6 +82,13 @@ static void xen_init_fv(ram_addr_t ram_size,exit (1 ); } +#if defined(__i386__) || defined(__x86_64__) +if (qemu_map_cache_init ()) { +fprintf (stderr,"qemu_map_cache_init returned: error %d\n" , errno); +exit (-1 ); + } +#endif +xc_get_hvm_param (xen_xc, xen_domid,HVM_PARAM_IOREQ_PFN , &ioreq_pfn);fprintf (stderr,"shared page at pfn %lx\n" , ioreq_pfn); shared_page = xc_map_foreign_range(xen_xc, xen_domid, XC_PAGE_SIZE,
target-xen/qemu-xen.h +15 -0
@@ -13,6 +13,21 @@/* xen_mapcache.c */ +#if (defined(__i386__) || defined(__x86_64__)) && !defined(QEMU_TOOL ) +#define MAPCACHE + +#if defined(__i386__) +#define MAX_MCACHE_SIZE 0x40000000/* 1GB max for x86 */ +#define MCACHE_BUCKET_SHIFT 16 +#elif defined(__x86_64__) +#define MAX_MCACHE_SIZE 0x1000000000/* 64GB max for x86_64 */ +#define MCACHE_BUCKET_SHIFT 20 +#endif + +#define MCACHE_BUCKET_SIZE (1UL << MCACHE_BUCKET_SHIFT) +#endif + +int qemu_map_cache_init (void );uint8_t *qemu_map_cache (target_phys_addr_t phys_addr,uint8_t lock);void qemu_invalidate_entry (uint8_t *buffer);void qemu_invalidate_map_cache (void );
target-xen/xen_mapcache.c +247 -0
255 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH 11/15 xen: Introduce --enable-xen command options.
In reply to Stefano StabelliniFrom: Anthony PERARD <[email protected]>
This options will check if the target is build with Xen support.
--- Makefile.target | 3 +++ hw/xen.h | 8 ++++++++ qemu-options.hx | 9 +++++++++ vl.c | 11 +++++++++++ 4 files changed, 31 insertions(+), 0 deletions(-) create mode 100644 xen-all.c create mode 100644 xen-stub.c
Makefile.target +3 -0
@@ -2,6 +2,7 @@ GENERATED_HEADERS = config-target.h CONFIG_NO_KVM = $(if $(subst n,,$(CONFIG_KVM)),n,y) +CONFIG_NO_XEN = $(if $(subst n,,$(CONFIG_XEN)),n,y) include ../config-host.mak include config-devices.mak
@@ -182,6 +183,8 @@ QEMU_CFLAGS += $(VNC_PNG_CFLAGS) # xen backend driver support obj-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o +obj-$(CONFIG_XEN) += xen-all.o +obj-$(CONFIG_NO_XEN) += xen-stub.o # USB layer obj-$(CONFIG_USB_OHCI) += usb-ohci.o
hw/xen.h +8 -0
@@ -18,4 +18,12 @@ enum xen_mode {extern uint32_t xen_domid;extern enum xen_mode xen_mode; +extern int xen_allowed; + +#if definedCONFIG_XEN +#define xen_enabled () (xen_allowed) +#else +#define xen_enabled () (0) +#endif +#endif /* QEMU_HW_XEN_H */
qemu-options.hx +9 -0
@@ -1908,6 +1908,15 @@ Enable KVM full virtualization support. This option is only available if KVM support is enabled when compiling. ETEXI +DEF("enable-xen", 0, QEMU_OPTION_enable_xen, \ + "-enable-xen enable Xen full virtualization support\n", QEMU_ARCH_ALL) +STEXI +@item -enable-xen +@findex -enable-xen +Enable Xen full virtualization support. This option is only available +if Xen support is enabled when compiling. +ETEXI + DEF("xen-domid", HAS_ARG, QEMU_OPTION_xen_domid, "-xen-domid id specify xen guest domain id\n", QEMU_ARCH_ALL) DEF("xen-create", 0, QEMU_OPTION_xen_create,
vl.c +11 -0
@@ -239,6 +239,7 @@ static NotifierList exit_notifiers =NOTIFIER_LIST_INITIALIZER (exit_notifiers);int kvm_allowed =0 ; +int xen_allowed =0 ;uint32_t xen_domid;enum xen_mode xen_mode =XEN_EMULATE ;
@@ -2436,6 +2437,9 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_enable_kvm: kvm_allowed =1 ;break ; +case QEMU_OPTION_enable_xen: + xen_allowed =1 ; +break ;case QEMU_OPTION_usb: usb_enabled =1 ;break ;
@@ -2730,6 +2734,13 @@ int main(int argc, char **argv, char **envp) } } +if (xen_allowed) { +if (!xen_available ()) { +printf ("Xen not supported for this target\n" ); +exit (1 ); + } + } +if (qemu_init_main_loop ()) {fprintf (stderr,"qemu_init_main_loop failed\n" );exit (1 );
xen-all.c new file +0 -0
xen-stub.c new file +0 -0
Signature · 1 line
1.7.0.4
PATCH 12/15 piix_pci: Introduces Xen specific call for irq.
In reply to Stefano StabelliniFrom: 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/piix_pci.c | 19 ++++++++++++++++--- hw/xen.h | 3 +++ xen-all.c | 25 +++++++++++++++++++++++++ xen-stub.c | 9 +++++++++ 4 files changed, 53 insertions(+), 3 deletions(-)
hw/piix_pci.c +16 -3
@@ -28,6 +28,7 @@#include "pci_host.h" #include "isa.h" #include "sysbus.h" +#include "xen.h" /* * I440FX chipset data sheet.
@@ -61,9 +62,13 @@ static void piix3_set_irq(void *opaque, int irq_num, int level);mapping. */ static int pci_slot_get_pirq (PCIDevice *pci_dev,int irq_num) { -int slot_addend; - slot_addend = (pci_dev->devfn >>3 ) -1 ; -return (irq_num + slot_addend) &3 ; +if (!xen_enabled ()) { +int slot_addend; + slot_addend = (pci_dev->devfn >>3 ) -1 ; +return (irq_num + slot_addend) &3 ; + }else { +return irq_num + ((pci_dev->devfn >>3 ) <<2 ); + } }static void update_pam (PCII440FXState *d,uint32_t start,uint32_t end,int r)
@@ -142,6 +147,9 @@ static void i440fx_write_config(PCIDevice *dev, {PCII440FXState *d =DO_UPCAST (PCII440FXState, dev, dev); +if (xen_enabled ()) +xen_piix_pci_write_config_client (address, val, len); +/* XXX: implement SMRAM.D_LOCK */ pci_default_write_config (dev, address, val, len); if (ranges_overlap(address, len, I440FX_PAM, I440FX_PAM_SIZE) ||
@@ -255,6 +263,11 @@ static void piix3_set_irq(void *opaque, int irq_num, int level)int i, pic_irq, pic_level;PIIX3State *piix3 = opaque; +if (xen_enabled ()) { +xen_piix3_set_irq (irq_num, level); +return ; + } + piix3->pci_irq_levels[irq_num] = level;/* now we change the pic irq level according to the piix irq mappings */
hw/xen.h +3 -0
@@ -26,4 +26,7 @@ extern int xen_allowed;#define xen_enabled () (0)#endif +void xen_piix3_set_irq (int irq_num,int level); +void xen_piix_pci_write_config_client (uint32_t address,uint32_t val,int len); +#endif /* QEMU_HW_XEN_H */
xen-all.c +25 -0
@@ -0,0 +1,25 @@ +#include "config.h" + +#include "hw/xen.h" +#include "hw/xen_backend.h" + +void xen_piix3_set_irq (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); + } +}
xen-stub.c +9 -0
@@ -0,0 +1,9 @@ +#include "hw/xen.h" + +void xen_piix3_set_irq (int irq_num,int level) +{ +} + +void xen_piix_pci_write_config_client (uint32_t address,uint32_t val,int len) +{ +}
Signature · 1 line
1.7.0.4
Re: [Qemu-devel] [PATCH 12/15] piix_pci: Introduces Xen specific call for irq.
Quoted 34 lines · On Mon, Aug 23, 2010 at 10:50:49AM +0100, [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_irqandget_pirq.Signed-off-by Anthony PERARD <[email protected]>Signed-off-by Stefano Stabellini <[email protected]>--- hw/piix_pci.c | 19 ++++++++++++++++--- hw/xen.h | 3 +++ xen-all.c | 25 +++++++++++++++++++++++++ xen-stub.c | 9 +++++++++ 4 files changed, 53 insertions(+), 3 deletions(-)hw/piix_pci.c +1
-3@@ -28,6 +28,7 @@#include "pci_host.h" #include "isa.h" #include "sysbus.h" +#include "xen.h" /* * I440FX chipset data sheet. @@ -61,9 +62,13 @@ static void piix3_set_irq(void *opaque, int irq_num, int level);mapping. */ static int pci_slot_get_pirq (PCIDevice *pci_dev,int irq_num) { -int slot_addend; - slot_addend = (pci_dev->devfn >>3 ) -1 ; -return (irq_num + slot_addend) &3 ;
hw/piix_pci.c static void piix3_set_irq(void *opaque, int irq_num, int level); · line 74
Quoted 10 lines
hw/piix_pci.c +7
-0+if (!xen_enabled ()) { +int slot_addend; + slot_addend = (pci_dev->devfn >>3 ) -1 ; +return (irq_num + slot_addend) &3 ; + }else { +return irq_num + ((pci_dev->devfn >>3 ) <<2 ); + } }static void update_pam (PCII440FXState *d,uint32_t start,uint32_t end,int r)
pci_slot_get_pirq() is passed to pci_bus_irqs() in i440fx_init(). It would be better to pass xen specific function to pci_bus_irqs() instead of dynamic check.
hw/piix_pci.c static void i440fx_write_config(PCIDevice *dev, · line 155
Quoted 10 lines
hw/piix_pci.c +3
-0@@ -142,6 +147,9 @@ static void i440fx_write_config(PCIDevice *dev, {PCII440FXState *d =DO_UPCAST (PCII440FXState, dev, dev); +if (xen_enabled ()) +xen_piix_pci_write_config_client (address, val, len); +/* XXX: implement SMRAM.D_LOCK */ pci_default_write_config (dev, address, val, len); if (ranges_overlap(address, len, I440FX_PAM, I440FX_PAM_SIZE) ||
Maybe do we want another PCIDeviceInfo whose difference is .write_config? I'm not sure which is better, though.
hw/piix_pci.c static void piix3_set_irq(void *opaque, int irq_num, int level) · line 271
Quoted 10 lines
hw/piix_pci.c +5
-0@@ -255,6 +263,11 @@ static void piix3_set_irq(void *opaque, int irq_num, int level)int i, pic_irq, pic_level;PIIX3State *piix3 = opaque; +if (xen_enabled ()) { +xen_piix3_set_irq (irq_num, level); +return ; + } + piix3->pci_irq_levels[irq_num] = level;
Ditto. Pass xen_piix3_set_irq() to pci_bus_irqs()?
thanks,
Quoted 62 lines
hw/piix_pci.c +0
-0/* now we change the pic irq level according to the piix irq mappings */ hw/xen.h +3
-0@@ -26,4 +26,7 @@ extern int xen_allowed;#define xen_enabled () (0)#endif +void xen_piix3_set_irq (int irq_num,int level); +void xen_piix_pci_write_config_client (uint32_t address,uint32_t val,int len); +#endif /* QEMU_HW_XEN_H */ xen-all.c +25
-0@@ -0,0 +1,25 @@ +#include "config.h" + +#include "hw/xen.h" +#include "hw/xen_backend.h" + +void xen_piix3_set_irq (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); + } +}xen-stub.c +9
-0@@ -0,0 +1,9 @@ +#include "hw/xen.h" + +void xen_piix3_set_irq (int irq_num,int level) +{ +} + +void xen_piix_pci_write_config_client (uint32_t address,uint32_t val,int len) +{ +}Signature · 1 line
1.7.0.4
Signature · 1 line
yamahata
PATCH 13/15 vl.c: Introduce getter for shutdown_requested and reset_requested.
In reply to Stefano StabelliniFrom: 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
@@ -51,6 +51,8 @@ void cpu_disable_ticks(void);void qemu_system_reset_request (void );void qemu_system_shutdown_request (void );void qemu_system_powerdown_request (void ); +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
@@ -1130,6 +1130,16 @@ static int powerdown_requested;int debug_requested;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.0.4
PATCH 14/15 xen: destroy the VM when shutdown is requested
In reply to Stefano StabelliniFrom: Anthony PERARD <[email protected]>
Handle shutdown and reset requests in helper.c.
--- target-xen/helper.c | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-)
target-xen/helper.c +15 -0
@@ -368,6 +368,21 @@ static void cpu_handle_ioreq(void *opaque)xen_wmb ();/* Update ioreq contents /then/ update state. */ +/* +* We do this before we send the response so that the tools +* have the opportunity to pick up on the reset before the +* guest resumes and does a hlt with interrupts disabled which +* causes Xen to powerdown the domain. +*/ +if (vm_running) { +if (qemu_shutdown_requested_get ()) { +destroy_hvm_domain (); + } +if (qemu_reset_requested_get ()) { +qemu_system_reset (); + } + } + req->state =STATE_IORESP_READY ;xc_evtchn_notify (xce_handle, ioreq_local_port[send_vcpu]); }
Signature · 1 line
1.7.0.4
PATCH 15/15 xen: Add a Xen specific ACPI Implementation to target-xen
In reply to Stefano StabelliniFrom: Anthony PERARD <[email protected]>
Xen currently uses a different BIOS (hvmloader + rombios) therefore the Qemu acpi_piix4 implementation wouldn't work correctly with Xen. We plan on fixing this properly but at the moment we are just adding a new Xen specific acpi_piix4 implementation.
This patch is optional; without it the VM boots but it cannot shutdown properly or go to S3.
--- Makefile.target | 1 + hw/xen_acpi_piix4.c | 424 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/xen_common.h | 3 + hw/xen_machine_fv.c | 6 +- 4 files changed, 429 insertions(+), 5 deletions(-) create mode 100644 hw/xen_acpi_piix4.c
Makefile.target +1 -0
@@ -328,6 +328,7 @@ obj-xen-y += piix_pci.o obj-xen-y += mc146818rtc.o obj-xen-y += xenstore.o obj-xen-y += xen_platform.o +obj-xen-y += xen_acpi_piix4.o obj-xen-y += xen_mapcache.o obj-xen-y += stub-functions.o
hw/xen_acpi_piix4.c new file +424 -0
424 lines not on this page · raw message
hw/xen_common.h +3 -0
@@ -55,4 +55,7 @@ typedef xc_interface *qemu_xc_interface;/* hw/i8259-xen-stub.c */ qemu_irq *i8259_xen_init (void ); +/* hw/xen_acpi_piix4.c */ +void piix4_pm_xen_init (PCIBus *bus,int devfn,qemu_irq sci_irq_spec,qemu_irq cmos_s3); +#endif /* QEMU_HW_XEN_COMMON_H */
hw/xen_machine_fv.c +1 -5
@@ -65,7 +65,6 @@ static void xen_init_fv(ram_addr_t ram_size,qemu_irq *isa_irq;qemu_irq *i8259;qemu_irq *cmos_s3; -qemu_irq *smi_irq;IsaIrqState *isa_irq_state;DriveInfo *hd[MAX_IDE_BUS *MAX_IDE_DEVS ];FDCtrl *floppy_controller;
@@ -173,10 +172,7 @@ static void xen_init_fv(ram_addr_t ram_size,if (acpi_enabled) { cmos_s3 =qemu_allocate_irqs (pc_cmos_set_s3_resume, rtc_state,1 ); - smi_irq =qemu_allocate_irqs (pc_acpi_smi_interrupt, first_cpu,1 ); -piix4_pm_init (pci_bus, piix3_devfn +3 ,0xb100 , -isa_reserve_irq (9 ), *cmos_s3, *smi_irq, -0 ); +piix4_pm_xen_init (pci_bus, piix3_devfn +3 ,isa_reserve_irq (9 ), *cmos_s3); }if (i440fx_state) {
Signature · 1 line
1.7.0.4
[Qemu-devel] Re: [PATCH 15/15] xen: Add a Xen specific ACPI Implementation to target-xen
Quoted 43 lines · [email protected] wrote:
From: Anthony PERARD <[email protected]>
Xen currently uses a different BIOS (hvmloader + rombios) therefore the Qemu
acpi_piix4implementation wouldn't work correctly with Xen. We plan on fixing this properly but at the moment we are just adding a new Xen specificacpi_piix4implementation.
This patch is optional; without it the VM boots but it cannot shutdown properly or go to S3.Signed-off-by Anthony PERARD <[email protected]>Signed-off-by Stefano Stabellini <[email protected]>hw/xen_acpi_piix4.c new file +31
-0+static void gpe_save (QEMUFile * f,void * opaque) +{ +GPEState *s = (GPEState *)opaque; +int i; + +for ( i =0 ; i <ACPI_GPE0_BLK_LEN /2 ; i++ ) { +qemu_put_8s (f, &s->gpe0_sts[i]); +qemu_put_8s (f, &s->gpe0_en[i]); + } + +qemu_put_8s (f, &s->sci_asserted); +if ( s->sci_asserted ) { +PIIX4ACPI_LOG (PIIX4ACPI_LOG_INFO ,"gpe_save with sci asserted!\n" ); + } +} + +static int gpe_load (QEMUFile * f,void * opaque,int version_id) +{ +GPEState *s = (GPEState *)opaque; +int i; +if (version_id !=1 ) +return -EINVAL ; + +for ( i =0 ; i <ACPI_GPE0_BLK_LEN /2 ; i++ ) { +qemu_get_8s (f, &s->gpe0_sts[i]); +qemu_get_8s (f, &s->gpe0_en[i]); + } + +qemu_get_8s (f, &s->sci_asserted); +return 0 ; +}
....
Quoted 1 line
+
register_savevm(NULL, "gpe", 0, 1, gpe_save, gpe_load, s);
Please port this to VMSTATE.
If possible (i.e. not problems with backwards compatibility), something like:
hw/xen_acpi_piix4.c line 288
Quoted 6 lines
hw/xen_acpi_piix4.c new file +6
-0+for ( i =0 ; i <ACPI_GPE0_BLK_LEN /2 ; i++ ) { +qemu_get_8s (f, &s->gpe0_sts[i]); + } +for ( i =0 ; i <ACPI_GPE0_BLK_LEN /2 ; i++ ) { +qemu_get_8s (f, &s->gpe0_en[i]); + }
Would be easier to put in vmstate.
Later, Juan.
[Qemu-devel] Re: [PATCH 15/15] xen: Add a Xen specific ACPI Implementation to target-xen
Quoted 6 lines · Juan Quintela
Quoted 1 line
+
register_savevm(NULL, "gpe", 0, 1, gpe_save, gpe_load, s);Please port this to VMSTATE.
If possible (i.e. not problems with backwards compatibility), something like:
Quoted 9 lines
hw/xen_acpi_piix4.c line 288
Quoted 6 lines
hw/xen_acpi_piix4.c new file +6
-0+for ( i =0 ; i <ACPI_GPE0_BLK_LEN /2 ; i++ ) { +qemu_get_8s (f, &s->gpe0_sts[i]); + } +for ( i =0 ; i <ACPI_GPE0_BLK_LEN /2 ; i++ ) { +qemu_get_8s (f, &s->gpe0_en[i]); + }Would be easier to put in vmstate.
Ok, will do.