direct-io.hg

changeset 14366:2955b0677310

add usb device save/restore in qemu

Signed-off-by: Zhai Edwin <edwin.zhai@intel.com>
author Tim Deegan <Tim.Deegan@xensource.com>
date Wed Mar 14 10:44:56 2007 +0000 (2007-03-14)
parents 3c38150de7fd
children f233456b89d5
files tools/ioemu/hw/usb-hid.c tools/ioemu/hw/usb-ohci.c tools/ioemu/hw/usb-uhci.c tools/ioemu/hw/usb.c tools/ioemu/hw/usb.h tools/ioemu/vl.c
line diff
     1.1 --- a/tools/ioemu/hw/usb-hid.c	Tue Mar 13 15:55:37 2007 +0000
     1.2 +++ b/tools/ioemu/hw/usb-hid.c	Wed Mar 14 10:44:56 2007 +0000
     1.3 @@ -517,6 +517,49 @@ static void usb_mouse_handle_destroy(USB
     1.4      qemu_free(s);
     1.5  }
     1.6  
     1.7 +void usb_mouse_save(QEMUFile *f, void *opaque)
     1.8 +{
     1.9 +    USBMouseState *s = (USBMouseState*)opaque;
    1.10 +
    1.11 +    qemu_put_be32s(f, &s->dx);
    1.12 +    qemu_put_be32s(f, &s->dy);
    1.13 +    qemu_put_be32s(f, &s->dz);
    1.14 +    qemu_put_be32s(f, &s->buttons_state);
    1.15 +    qemu_put_be32s(f, &s->x);
    1.16 +    qemu_put_be32s(f, &s->y);
    1.17 +    qemu_put_be32s(f, &s->kind);
    1.18 +    qemu_put_be32s(f, &s->mouse_grabbed);
    1.19 +    qemu_put_be32s(f, &s->status_changed);
    1.20 +
    1.21 +}
    1.22 +
    1.23 +int usb_mouse_load(QEMUFile *f, void *opaque, int version_id)
    1.24 +{
    1.25 +    USBMouseState *s = (USBMouseState*)opaque;
    1.26 +
    1.27 +    if (version_id != 1)
    1.28 +        return -EINVAL;
    1.29 +
    1.30 +    qemu_get_be32s(f, &s->dx);
    1.31 +    qemu_get_be32s(f, &s->dy);
    1.32 +    qemu_get_be32s(f, &s->dz);
    1.33 +    qemu_get_be32s(f, &s->buttons_state);
    1.34 +    qemu_get_be32s(f, &s->x);
    1.35 +    qemu_get_be32s(f, &s->y);
    1.36 +    qemu_get_be32s(f, &s->kind);
    1.37 +    qemu_get_be32s(f, &s->mouse_grabbed);
    1.38 +    qemu_get_be32s(f, &s->status_changed);
    1.39 +
    1.40 +    if ( s->kind == USB_TABLET) {
    1.41 +        fprintf(logfile, "usb_mouse_load:add usb_tablet_event.\n");
    1.42 +        qemu_add_mouse_event_handler(usb_tablet_event, s, 1);
    1.43 +    } else if ( s->kind == USB_MOUSE) {
    1.44 +        fprintf(logfile, "usb_mouse_load:add usb_mouse_event.\n");
    1.45 +        qemu_add_mouse_event_handler(usb_mouse_event, s, 0);
    1.46 +    }
    1.47 +}
    1.48 +
    1.49 +
    1.50  USBDevice *usb_tablet_init(void)
    1.51  {
    1.52      USBMouseState *s;
    1.53 @@ -536,6 +579,8 @@ USBDevice *usb_tablet_init(void)
    1.54  
    1.55      pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Tablet");
    1.56  
    1.57 +    register_savevm("USB tablet dev", 0, 1, usb_mouse_save, usb_mouse_load, s);
    1.58 +
    1.59      return (USBDevice *)s;
    1.60  }
    1.61  
    1.62 @@ -558,5 +603,7 @@ USBDevice *usb_mouse_init(void)
    1.63  
    1.64      pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Mouse");
    1.65  
    1.66 +    register_savevm("USB mouse dev", 0, 1, usb_mouse_save, usb_mouse_load, s);
    1.67 +
    1.68      return (USBDevice *)s;
    1.69  }
     2.1 --- a/tools/ioemu/hw/usb-ohci.c	Tue Mar 13 15:55:37 2007 +0000
     2.2 +++ b/tools/ioemu/hw/usb-ohci.c	Wed Mar 14 10:44:56 2007 +0000
     2.3 @@ -1186,5 +1186,7 @@ void usb_ohci_init(struct PCIBus *bus, i
     2.4          qemu_register_usb_port(&ohci->rhport[i].port, ohci, i, ohci_attach);
     2.5      }
     2.6  
     2.7 +    register_savevm("OHCI USB", 0, 1, generic_pci_save, generic_pci_load, ohci);
     2.8 +
     2.9      ohci_reset(ohci);
    2.10  }
     3.1 --- a/tools/ioemu/hw/usb-uhci.c	Tue Mar 13 15:55:37 2007 +0000
     3.2 +++ b/tools/ioemu/hw/usb-uhci.c	Wed Mar 14 10:44:56 2007 +0000
     3.3 @@ -658,6 +658,50 @@ static void uhci_map(PCIDevice *pci_dev,
     3.4      register_ioport_read(addr, 32, 1, uhci_ioport_readb, s);
     3.5  }
     3.6  
     3.7 +void uhci_usb_save(QEMUFile *f, void *opaque)
     3.8 +{
     3.9 +    int i;
    3.10 +    UHCIState *s = (UHCIState*)opaque;
    3.11 +
    3.12 +    qemu_put_be16s(f, &s->cmd);
    3.13 +    qemu_put_be16s(f, &s->status);
    3.14 +    qemu_put_be16s(f, &s->intr);
    3.15 +    qemu_put_be16s(f, &s->frnum);
    3.16 +    qemu_put_be32s(f, &s->fl_base_addr);
    3.17 +    qemu_put_8s(f, &s->sof_timing);
    3.18 +    qemu_put_8s(f, &s->status2);
    3.19 +
    3.20 +    for(i = 0; i < NB_PORTS; i++) {
    3.21 +        qemu_put_be16s(f, &s->ports[i].ctrl);
    3.22 +    }
    3.23 +
    3.24 +    qemu_put_timer(f, s->frame_timer);
    3.25 +}
    3.26 +
    3.27 +int uhci_usb_load(QEMUFile *f, void *opaque, int version_id)
    3.28 +{
    3.29 +    int i;
    3.30 +    UHCIState *s = (UHCIState*)opaque;
    3.31 +
    3.32 +    if (version_id != 1)
    3.33 +        return -EINVAL;
    3.34 +
    3.35 +    qemu_get_be16s(f, &s->cmd);
    3.36 +    qemu_get_be16s(f, &s->status);
    3.37 +    qemu_get_be16s(f, &s->intr);
    3.38 +    qemu_get_be16s(f, &s->frnum);
    3.39 +    qemu_get_be32s(f, &s->fl_base_addr);
    3.40 +    qemu_get_8s(f, &s->sof_timing);
    3.41 +    qemu_get_8s(f, &s->status2);
    3.42 +
    3.43 +    for(i = 0; i < NB_PORTS; i++) {
    3.44 +        qemu_get_be16s(f, &s->ports[i].ctrl);
    3.45 +    }
    3.46 +
    3.47 +    qemu_get_timer(f, s->frame_timer);
    3.48 +
    3.49 +}
    3.50 +
    3.51  void usb_uhci_init(PCIBus *bus, int devfn)
    3.52  {
    3.53      UHCIState *s;
    3.54 @@ -693,4 +737,8 @@ void usb_uhci_init(PCIBus *bus, int devf
    3.55         to rely on this.  */
    3.56      pci_register_io_region(&s->dev, 4, 0x20, 
    3.57                             PCI_ADDRESS_SPACE_IO, uhci_map);
    3.58 +
    3.59 +    register_savevm("UHCI_usb_pci", 0, 1, generic_pci_save, generic_pci_load, s);
    3.60 +
    3.61 +    register_savevm("UHCI usb controller", 0, 1, uhci_usb_save, uhci_usb_load, s);
    3.62  }
     4.1 --- a/tools/ioemu/hw/usb.c	Tue Mar 13 15:55:37 2007 +0000
     4.2 +++ b/tools/ioemu/hw/usb.c	Wed Mar 14 10:44:56 2007 +0000
     4.3 @@ -191,3 +191,43 @@ int set_usb_string(uint8_t *buf, const c
     4.4      }
     4.5      return q - buf;
     4.6  }
     4.7 +
     4.8 +void generic_usb_save(QEMUFile* f, void *opaque)
     4.9 +{
    4.10 +    USBDevice *s = (USBDevice*)opaque;
    4.11 +
    4.12 +    qemu_put_be32s(f, &s->speed);
    4.13 +    qemu_put_8s(f, &s->addr);
    4.14 +    qemu_put_be32s(f, &s->state);
    4.15 +
    4.16 +    qemu_put_buffer(f, s->setup_buf, 8);
    4.17 +    qemu_put_buffer(f, s->data_buf, 1024);
    4.18 +
    4.19 +    qemu_put_be32s(f, &s->remote_wakeup);
    4.20 +    qemu_put_be32s(f, &s->setup_state);
    4.21 +    qemu_put_be32s(f, &s->setup_len);
    4.22 +    qemu_put_be32s(f, &s->setup_index);
    4.23 +
    4.24 +}
    4.25 +
    4.26 +int generic_usb_load(QEMUFile* f, void *opaque, int version_id)
    4.27 +{
    4.28 +    USBDevice *s = (USBDevice*)opaque;
    4.29 +
    4.30 +    if (version_id != 1)
    4.31 +        return -EINVAL;
    4.32 +
    4.33 +    qemu_get_be32s(f, &s->speed);
    4.34 +    qemu_get_8s(f, &s->addr);
    4.35 +    qemu_get_be32s(f, &s->state);
    4.36 +
    4.37 +    qemu_get_buffer(f, s->setup_buf, 8);
    4.38 +    qemu_get_buffer(f, s->data_buf, 1024);
    4.39 +
    4.40 +    qemu_get_be32s(f, &s->remote_wakeup);
    4.41 +    qemu_get_be32s(f, &s->setup_state);
    4.42 +    qemu_get_be32s(f, &s->setup_len);
    4.43 +    qemu_get_be32s(f, &s->setup_index);
    4.44 +
    4.45 +    return 0;
    4.46 +}
     5.1 --- a/tools/ioemu/hw/usb.h	Tue Mar 13 15:55:37 2007 +0000
     5.2 +++ b/tools/ioemu/hw/usb.h	Wed Mar 14 10:44:56 2007 +0000
     5.3 @@ -176,3 +176,9 @@ USBDevice *usb_tablet_init(void);
     5.4  
     5.5  /* usb-msd.c */
     5.6  USBDevice *usb_msd_init(const char *filename);
     5.7 +
     5.8 +/* usb.c */
     5.9 +void generic_usb_save(QEMUFile* f, void *opaque);
    5.10 +int generic_usb_load(QEMUFile* f, void *opaque, int version_id);
    5.11 +
    5.12 +
     6.1 --- a/tools/ioemu/vl.c	Tue Mar 13 15:55:37 2007 +0000
     6.2 +++ b/tools/ioemu/vl.c	Wed Mar 14 10:44:56 2007 +0000
     6.3 @@ -841,10 +841,22 @@ void qemu_get_timer(QEMUFile *f, QEMUTim
     6.4  #ifdef CONFIG_DM
     6.5  static void timer_save(QEMUFile *f, void *opaque)
     6.6  {
     6.7 +    /* need timer for save/restoe qemu_timer in usb_uhci */
     6.8 +    if (cpu_ticks_enabled) {
     6.9 +        hw_error("cannot save state if virtual timers are running");
    6.10 +    }
    6.11 +    qemu_put_be64s(f, &cpu_clock_offset);
    6.12  }
    6.13  
    6.14  static int timer_load(QEMUFile *f, void *opaque, int version_id)
    6.15  {
    6.16 +    if (version_id != 1)
    6.17 +        return -EINVAL;
    6.18 +    if (cpu_ticks_enabled) {
    6.19 +        return -EINVAL;
    6.20 +    }
    6.21 +
    6.22 +    qemu_get_be64s(f, &cpu_clock_offset);
    6.23      return 0;
    6.24  }
    6.25  #else  /* !CONFIG_DM */
    6.26 @@ -3900,6 +3912,7 @@ static int usb_device_add(const char *de
    6.27      const char *p;
    6.28      USBDevice *dev;
    6.29      USBPort *port;
    6.30 +    char usb_name[256] = "USB ";
    6.31  
    6.32      if (!free_usb_ports)
    6.33          return -1;
    6.34 @@ -3936,6 +3949,12 @@ static int usb_device_add(const char *de
    6.35      free_usb_ports = port->next;
    6.36      port->next = used_usb_ports;
    6.37      used_usb_ports = port;
    6.38 +
    6.39 +    pstrcpy(usb_name + strlen(usb_name), 
    6.40 +            sizeof(usb_name) - strlen(usb_name), 
    6.41 +            devname);
    6.42 +    register_savevm(usb_name, 0, 1, generic_usb_save, generic_usb_load, dev);
    6.43 +    
    6.44      usb_attach(port, dev);
    6.45      return 0;
    6.46  }