WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] usb device haven't save&&restore in ioemu-remote

To: <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] usb device haven't save&&restore in ioemu-remote
From: "James Song" <jsong@xxxxxxxxxx>
Date: Fri, 20 Mar 2009 01:08:17 -0600
Delivery-date: Fri, 20 Mar 2009 00:08:54 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
usb device haven't save&&restore in ioemu-remote.
patch for that:
 
diff -r 21508368a9db tools/ioemu-remote/hw/usb-hid.c
--- a/tools/ioemu-remote/hw/usb-hid.c Fri Feb 20 21:14:55 2009 +0800
+++ b/tools/ioemu-remote/hw/usb-hid.c Wed Mar 04 11:55:39 2009 +0800
@@ -870,6 +870,60 @@
     qemu_free(s);
 }
 
+void usb_mouse_save(QEMUFile *f, void *opaque)
+{
+    USBHIDState *hs = (USBHIDState *)opaque;
+    USBPointerState *s = &hs->ptr;
+    USBPointerEvent *e;
+    if (s->head == s->tail)
+       /* use the last report */
+       s->head = (s->head - 1) & QUEUEINDEXMASK;
+    e = &s->queue[s->head];
+
+    /* save usb dev */
+    generic_usb_save(f, &hs->dev);
+
+    qemu_put_be32(f, e->xdx);
+    qemu_put_be32(f, e->ydy);
+    qemu_put_be32(f, e->dz);
+    qemu_put_be32(f, e->buttons_state);
+    qemu_put_be32(f, hs->kind);
+    qemu_put_be32(f, s->mouse_grabbed);
+    qemu_put_be32(f, s->xyrel);
+    qemu_put_be32(f, hs->protocol);
+
+}
+
+int usb_mouse_load(QEMUFile *f, void *opaque, int version_id)
+{
+    USBHIDState *hs = (USBHIDState *)opaque;
+    USBPointerState *s = &hs->ptr;
+    USBPointerEvent *e;
+
+    if (version_id != 1)
+        return -EINVAL;
+
+    if (s->head == s->tail)
+       /* use the last report */
+       s->head = (s->head - 1) & QUEUEINDEXMASK;
+    e = &s->queue[s->head];
+
+    /* load usb dev */
+    generic_usb_save(f, &hs->dev);
+
+    qemu_get_be32s(f,&e->xdx);
+    qemu_get_be32s(f,&e->ydy);
+    qemu_get_be32s(f, &e->dz);
+    qemu_get_be32s(f, &e->buttons_state);
+    qemu_get_be32s(f, &hs->kind);
+    qemu_get_be32s(f, &s->mouse_grabbed);
+    qemu_get_be32s(f,&s->xyrel);
+    qemu_get_be32s(f,&hs->protocol);
+
+    qemu_add_mouse_event_handler(usb_pointer_event, hs,!s->xyrel,  "QEMU USB Pointer");
+    return 0;
+}
+
 static USBDevice *usb_pointer_init(int kind, int xyrel, const char *devname)
 {
     USBHIDState *s;
@@ -894,6 +948,7 @@
     s->ptr.tail = 1;
 
     pstrcpy(s->dev.devname, sizeof(s->dev.devname), devname);
+    register_savevm("USB_mouse_dev", 0, 1, usb_mouse_save, usb_mouse_load, s);
     return (USBDevice *)s;
 }
 
diff -r 21508368a9db tools/ioemu-remote/hw/usb-ohci.c
--- a/tools/ioemu-remote/hw/usb-ohci.c Fri Feb 20 21:14:55 2009 +0800
+++ b/tools/ioemu-remote/hw/usb-ohci.c Wed Mar 04 11:55:39 2009 +0800
@@ -1634,6 +1634,20 @@
     OHCIState state;
 } OHCIPCIState;
 
+static void ohci_usb_save(QEMUFile *f, void *opaque)
+{
+    OHCIPCIState *ohci_pci = (OHCIPCIState *)opaque;
+
+    pci_device_save(&ohci_pci->pci_dev, f);
+}
+
+static int ohci_usb_load(QEMUFile *f, void *opaque, int version_id)
+{
+    OHCIPCIState *ohci_pci = (OHCIPCIState *)opaque;
+
+    return pci_device_load(&ohci_pci->pci_dev, f);
+}
+
 static void ohci_mapfunc(PCIDevice *pci_dev, int i,
             uint32_t addr, uint32_t size, int type)
 {
@@ -1669,6 +1683,7 @@
 
     pci_register_io_region((struct PCIDevice *)ohci, 0, 256,
                            PCI_ADDRESS_SPACE_MEM, ohci_mapfunc);
+    register_savevm("OHCI USB", 0, 1, ohci_usb_save, ohci_usb_load, ohci);
 }
 
 void usb_ohci_init_pxa(target_phys_addr_t base, int num_ports, int devfn,
diff -r 21508368a9db tools/ioemu-remote/hw/usb-uhci.c
--- a/tools/ioemu-remote/hw/usb-uhci.c Fri Feb 20 21:14:55 2009 +0800
+++ b/tools/ioemu-remote/hw/usb-uhci.c Wed Mar 04 11:55:39 2009 +0800
@@ -902,6 +902,57 @@
     register_ioport_read(addr, 32, 1, uhci_ioport_readb, s);
 }
 
+void uhci_usb_save(QEMUFile *f, void *opaque)
+{
+    int i;
+    UHCIState *s = (UHCIState*)opaque;
+
+    pci_device_save(&s->dev,f);
+
+    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);
+
+    for(i = 0; i < NB_PORTS; i++) {
+        qemu_put_be16s(f, &s->ports[i].ctrl);
+    }
+
+    qemu_put_timer(f, s->frame_timer);
+}
+
+int uhci_usb_load(QEMUFile *f, void *opaque, int version_id)
+{
+    int i,ret;
+    UHCIState *s = (UHCIState*)opaque;
+
+    if (version_id != 1)
+        return -EINVAL;
+
+    ret = pci_device_load(&s->dev, f);
+    if (ret < 0)
+        return ret;
+
+    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);
+
+    for(i = 0; i < NB_PORTS; i++) {
+        qemu_get_be16s(f, &s->ports[i].ctrl);
+    }
+
+    qemu_get_timer(f, s->frame_timer);
+    
+    return 0;
+}
+
 void usb_uhci_piix3_init(PCIBus *bus, int devfn)
 {
     UHCIState *s;
@@ -935,6 +986,7 @@
        to rely on this.  */
     pci_register_io_region(&s->dev, 4, 0x20,
                            PCI_ADDRESS_SPACE_IO, uhci_map);
+    register_savevm("UHCI_usb_controller", 0, 1, uhci_usb_save, uhci_usb_load, s);
 }
 
 void usb_uhci_piix4_init(PCIBus *bus, int devfn)
@@ -970,4 +1022,5 @@
        to rely on this.  */
     pci_register_io_region(&s->dev, 4, 0x20,
                            PCI_ADDRESS_SPACE_IO, uhci_map);
+    register_savevm("UHCI_usb_controller", 0, 1, uhci_usb_save, uhci_usb_load, s);
 }
diff -r 21508368a9db tools/ioemu-remote/hw/usb.c
--- a/tools/ioemu-remote/hw/usb.c Fri Feb 20 21:14:55 2009 +0800
+++ b/tools/ioemu-remote/hw/usb.c Wed Mar 04 11:55:39 2009 +0800
@@ -23,6 +23,7 @@
  */
 #include "qemu-common.h"
 #include "usb.h"
+#include "hw.h"
 
 void usb_attach(USBPort *port, USBDevice *dev)
 {
@@ -202,3 +203,43 @@
     dev->handle_packet(dev, &p);
 }
 
+void generic_usb_save(QEMUFile* f, void *opaque)
+{
+    USBDevice *s = (USBDevice*)opaque;
+
+    qemu_put_be32s(f, &s->speed);
+    qemu_put_8s(f, &s->addr);
+    qemu_put_be32s(f, &s->state);
+
+    qemu_put_buffer(f, s->setup_buf, 8);
+    qemu_put_buffer(f, s->data_buf, 1024);
+
+    qemu_put_be32s(f, &s->remote_wakeup);
+    qemu_put_be32s(f, &s->setup_state);
+    qemu_put_be32s(f, &s->setup_len);
+    qemu_put_be32s(f, &s->setup_index);
+
+}
+
+int generic_usb_load(QEMUFile* f, void *opaque, int version_id)
+{
+    USBDevice *s = (USBDevice*)opaque;
+
+    if (version_id != 1)
+        return -EINVAL;
+
+    qemu_get_be32s(f, &s->speed);
+    qemu_get_8s(f, &s->addr);
+    qemu_get_be32s(f, &s->state);
+
+    qemu_get_buffer(f, s->setup_buf, 8);
+    qemu_get_buffer(f, s->data_buf, 1024);
+
+    qemu_get_be32s(f, &s->remote_wakeup);
+    qemu_get_be32s(f, &s->setup_state);
+    qemu_get_be32s(f, &s->setup_len);
+    qemu_get_be32s(f, &s->setup_index);
+
+    return 0;
+}
+
diff -r 21508368a9db tools/ioemu-remote/hw/usb.h
--- a/tools/ioemu-remote/hw/usb.h Fri Feb 20 21:14:55 2009 +0800
+++ b/tools/ioemu-remote/hw/usb.h Wed Mar 04 11:55:39 2009 +0800
@@ -257,3 +257,6 @@
 uint32_t musb_core_intr_get(struct musb_s *s);
 void musb_core_intr_clear(struct musb_s *s, uint32_t mask);
 void musb_set_size(struct musb_s *s, int epnum, int size, int is_tx);
+
+void generic_usb_save(QEMUFile* f, void *opaque);
+int generic_usb_load(QEMUFile* f, void *opaque, int version_id);
diff -r 21508368a9db tools/ioemu-remote/vl.c
--- a/tools/ioemu-remote/vl.c Fri Feb 20 21:14:55 2009 +0800
+++ b/tools/ioemu-remote/vl.c Wed Mar 04 11:55:39 2009 +0800
@@ -5504,6 +5504,7 @@
     const char *p;
     USBDevice *dev;
     USBPort *port;
+    char usb_name[256] = "USB ";
 
     if (!free_usb_ports)
         return -1;
@@ -5549,6 +5550,11 @@
         port = free_usb_ports;
     }
 
+    pstrcpy(usb_name + strlen(usb_name),
+            sizeof(usb_name) - strlen(usb_name),
+            devname);
+    register_savevm(usb_name, 0, 1, generic_usb_save, generic_usb_load, dev);
+
     free_usb_ports = port->next;
     port->next = used_usb_ports;
     used_usb_ports = port;
 
 
thanks
James Song ( Song Wei )
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>