From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GnlPT-0007KJ-1L for qemu-devel@nongnu.org; Fri, 24 Nov 2006 19:28:47 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GnlPQ-0007IJ-Fg for qemu-devel@nongnu.org; Fri, 24 Nov 2006 19:28:45 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GnlPQ-0007IE-Br for qemu-devel@nongnu.org; Fri, 24 Nov 2006 19:28:44 -0500 Received: from [24.93.47.43] (helo=ms-smtp-04.texas.rr.com) by monty-python.gnu.org with esmtp (Exim 4.52) id 1GnlPQ-0003SU-1I for qemu-devel@nongnu.org; Fri, 24 Nov 2006 19:28:44 -0500 Received: from vaio (cpe-66-68-31-100.austin.res.rr.com [66.68.31.100]) by ms-smtp-04.texas.rr.com (8.13.6/8.13.6) with ESMTP id kAP0SdjD000445 for ; Fri, 24 Nov 2006 18:28:40 -0600 (CST) From: Lonnie Mendez Content-Type: multipart/mixed; boundary="=-s05eQnEg27zGSUTLLeaq" Date: Fri, 24 Nov 2006 18:28:38 -0600 Message-Id: <1164414518.10246.12.camel@vaio> Mime-Version: 1.0 Subject: [Qemu-devel] [PATCH] usb-uhci.c: save/load state implementation Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --=-s05eQnEg27zGSUTLLeaq Content-Type: text/plain Content-Transfer-Encoding: 7bit lo list. Attached is a patch that implements save/load state for the uhci controller. The code will only work well if you remove all usb devices attached to the guest prior to saving the vm state. There is no code yet that tries to reconstruct the ports list. I'm sure there will need to be additional code to the handle the case of previously attached devices - this is difficult because the device(s) could have been removed, the device state could have changed, etc. Test case with windows xp guest. (qemu) stop (qemu) savevm test1 (qemu) quit qemu -hda winxp.qcow2 -localtime -usb -no-acpi -kernel-kqemu -loadvm test1 Adding the usb tablet after resuming the guest results in a functional tablet input device. --=-s05eQnEg27zGSUTLLeaq Content-Disposition: attachment; filename=qemu-uhci-savestate.diff Content-Type: text/x-patch; name=qemu-uhci-savestate.diff; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit --- qemu/hw/usb-uhci.c 2006-08-11 20:04:27.000000000 -0500 +++ qemu/hw/usb-uhci.c 2006-11-24 17:46:18.000000000 -0600 @@ -144,6 +144,62 @@ } } +static void uhci_save(QEMUFile *f, void *opaque) +{ + UHCIState *s = opaque; + uint8_t num_ports = NB_PORTS; + int i; + + pci_device_save(&s->dev, f); + + qemu_put_8s(f, &num_ports); + for (i = 0; i < num_ports; ++i) + qemu_put_be16s(f, &s->ports[i].ctrl); + qemu_put_be16s(f, &s->cmd); + qemu_put_be16s(f, &s->status); + qemu_put_be16s(f, &s->intr); + qemu_put_be16s(f, &s->frnum); + qemu_put_be32s(f, &s->fl_base_addr); + qemu_put_8s(f, &s->sof_timing); + qemu_put_8s(f, &s->status2); + qemu_put_timer(f, s->frame_timer); + qemu_put_be32s(f, &s->pending_int_mask); + qemu_put_be32s(f, &s->async_qh); +} + +static int uhci_load(QEMUFile* f,void* opaque,int version_id) +{ + UHCIState *s = opaque; + uint8_t num_ports; + int i, ret; + + if (version_id > 1) + return -EINVAL; + + ret = pci_device_load(&s->dev, f); + if (ret < 0) + return ret; + + qemu_get_8s(f, &num_ports); + if (num_ports != NB_PORTS) + return -EINVAL; + + for (i = 0; i < num_ports; ++i) + qemu_get_be16s(f, &s->ports[i].ctrl); + qemu_get_be16s(f, &s->cmd); + qemu_get_be16s(f, &s->status); + qemu_get_be16s(f, &s->intr); + qemu_get_be16s(f, &s->frnum); + qemu_get_be32s(f, &s->fl_base_addr); + qemu_get_8s(f, &s->sof_timing); + qemu_get_8s(f, &s->status2); + qemu_get_timer(f, s->frame_timer); + qemu_get_be32s(f, &s->pending_int_mask); + qemu_get_be32s(f, &s->async_qh); + + return 0; +} + static void uhci_ioport_writeb(void *opaque, uint32_t addr, uint32_t val) { UHCIState *s = opaque; @@ -793,4 +849,6 @@ to rely on this. */ pci_register_io_region(&s->dev, 4, 0x20, PCI_ADDRESS_SPACE_IO, uhci_map); + + register_savevm("uhci", 0, 1, uhci_save, uhci_load, s); } --=-s05eQnEg27zGSUTLLeaq--