debuggers.hg

view tools/ioemu/patches/ioemu-save-restore-usb @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children
line source
1 Index: ioemu/hw/usb-hid.c
2 ===================================================================
3 --- ioemu.orig/hw/usb-hid.c 2007-05-09 14:10:50.000000000 +0100
4 +++ ioemu/hw/usb-hid.c 2007-05-09 14:11:27.000000000 +0100
5 @@ -510,6 +510,51 @@
6 qemu_free(s);
7 }
9 +void usb_mouse_save(QEMUFile *f, void *opaque)
10 +{
11 + USBMouseState *s = (USBMouseState*)opaque;
12 +
13 + qemu_put_be32s(f, &s->dx);
14 + qemu_put_be32s(f, &s->dy);
15 + qemu_put_be32s(f, &s->dz);
16 + qemu_put_be32s(f, &s->buttons_state);
17 + qemu_put_be32s(f, &s->x);
18 + qemu_put_be32s(f, &s->y);
19 + qemu_put_be32s(f, &s->kind);
20 + qemu_put_be32s(f, &s->mouse_grabbed);
21 + qemu_put_be32s(f, &s->status_changed);
22 +
23 +}
24 +
25 +int usb_mouse_load(QEMUFile *f, void *opaque, int version_id)
26 +{
27 + USBMouseState *s = (USBMouseState*)opaque;
28 +
29 + if (version_id != 1)
30 + return -EINVAL;
31 +
32 + qemu_get_be32s(f, &s->dx);
33 + qemu_get_be32s(f, &s->dy);
34 + qemu_get_be32s(f, &s->dz);
35 + qemu_get_be32s(f, &s->buttons_state);
36 + qemu_get_be32s(f, &s->x);
37 + qemu_get_be32s(f, &s->y);
38 + qemu_get_be32s(f, &s->kind);
39 + qemu_get_be32s(f, &s->mouse_grabbed);
40 + qemu_get_be32s(f, &s->status_changed);
41 +
42 + if ( s->kind == USB_TABLET) {
43 + fprintf(logfile, "usb_mouse_load:add usb_tablet_event.\n");
44 + qemu_add_mouse_event_handler(usb_tablet_event, s, 1, "QEMU USB Tablet");
45 + } else if ( s->kind == USB_MOUSE) {
46 + fprintf(logfile, "usb_mouse_load:add usb_mouse_event.\n");
47 + qemu_add_mouse_event_handler(usb_mouse_event, s, 0, "QEMU USB MOUSE");
48 + }
49 +
50 + return 0;
51 +}
52 +
53 +
54 USBDevice *usb_tablet_init(void)
55 {
56 USBMouseState *s;
57 @@ -528,6 +573,8 @@
59 pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Tablet");
61 + register_savevm("USB tablet dev", 0, 1, usb_mouse_save, usb_mouse_load, s);
62 +
63 return (USBDevice *)s;
64 }
66 @@ -549,5 +596,7 @@
68 pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Mouse");
70 + register_savevm("USB mouse dev", 0, 1, usb_mouse_save, usb_mouse_load, s);
71 +
72 return (USBDevice *)s;
73 }
74 Index: ioemu/vl.c
75 ===================================================================
76 --- ioemu.orig/vl.c 2007-05-09 14:10:50.000000000 +0100
77 +++ ioemu/vl.c 2007-05-09 14:11:19.000000000 +0100
78 @@ -4076,6 +4076,7 @@
79 const char *p;
80 USBDevice *dev;
81 USBPort *port;
82 + char usb_name[256] = "USB ";
84 if (!free_usb_ports)
85 return -1;
86 @@ -4112,6 +4113,12 @@
87 free_usb_ports = port->next;
88 port->next = used_usb_ports;
89 used_usb_ports = port;
90 +
91 + pstrcpy(usb_name + strlen(usb_name),
92 + sizeof(usb_name) - strlen(usb_name),
93 + devname);
94 + register_savevm(usb_name, 0, 1, generic_usb_save, generic_usb_load, dev);
95 +
96 usb_attach(port, dev);
97 return 0;
98 }
99 Index: ioemu/hw/usb.c
100 ===================================================================
101 --- ioemu.orig/hw/usb.c 2007-05-09 14:10:50.000000000 +0100
102 +++ ioemu/hw/usb.c 2007-05-09 14:11:01.000000000 +0100
103 @@ -201,3 +201,42 @@
104 dev->handle_packet(dev, &p);
105 }
107 +void generic_usb_save(QEMUFile* f, void *opaque)
108 +{
109 + USBDevice *s = (USBDevice*)opaque;
110 +
111 + qemu_put_be32s(f, &s->speed);
112 + qemu_put_8s(f, &s->addr);
113 + qemu_put_be32s(f, &s->state);
114 +
115 + qemu_put_buffer(f, s->setup_buf, 8);
116 + qemu_put_buffer(f, s->data_buf, 1024);
117 +
118 + qemu_put_be32s(f, &s->remote_wakeup);
119 + qemu_put_be32s(f, &s->setup_state);
120 + qemu_put_be32s(f, &s->setup_len);
121 + qemu_put_be32s(f, &s->setup_index);
122 +
123 +}
124 +
125 +int generic_usb_load(QEMUFile* f, void *opaque, int version_id)
126 +{
127 + USBDevice *s = (USBDevice*)opaque;
128 +
129 + if (version_id != 1)
130 + return -EINVAL;
131 +
132 + qemu_get_be32s(f, &s->speed);
133 + qemu_get_8s(f, &s->addr);
134 + qemu_get_be32s(f, &s->state);
135 +
136 + qemu_get_buffer(f, s->setup_buf, 8);
137 + qemu_get_buffer(f, s->data_buf, 1024);
138 +
139 + qemu_get_be32s(f, &s->remote_wakeup);
140 + qemu_get_be32s(f, &s->setup_state);
141 + qemu_get_be32s(f, &s->setup_len);
142 + qemu_get_be32s(f, &s->setup_index);
143 +
144 + return 0;
145 +}
146 Index: ioemu/hw/usb-ohci.c
147 ===================================================================
148 --- ioemu.orig/hw/usb-ohci.c 2007-05-09 14:10:50.000000000 +0100
149 +++ ioemu/hw/usb-ohci.c 2007-05-09 14:11:01.000000000 +0100
150 @@ -1215,6 +1215,20 @@
151 cpu_register_physical_memory(addr, size, ohci->mem);
152 }
154 +static void ohci_usb_save(QEMUFile *f, void *opaque)
155 +{
156 + OHCIState *ohci = opaque;
157 +
158 + pci_device_save(&ohci->pci_dev, f);
159 +}
160 +
161 +static int ohci_usb_load(QEMUFile *f, void *opaque, int version_id)
162 +{
163 + OHCIState *ohci = opaque;
164 +
165 + return pci_device_load(&ohci->pci_dev, f);
166 +}
167 +
168 void usb_ohci_init(struct PCIBus *bus, int num_ports, int devfn)
169 {
170 OHCIState *ohci;
171 @@ -1265,6 +1279,8 @@
172 qemu_register_usb_port(&ohci->rhport[i].port, ohci, i, ohci_attach);
173 }
175 + register_savevm("OHCI USB", 0, 1, ohci_usb_save, ohci_usb_load, ohci);
176 +
177 ohci->async_td = 0;
178 ohci_reset(ohci);
179 }
180 Index: ioemu/hw/usb.h
181 ===================================================================
182 --- ioemu.orig/hw/usb.h 2007-05-09 14:10:50.000000000 +0100
183 +++ ioemu/hw/usb.h 2007-05-09 14:11:01.000000000 +0100
184 @@ -218,3 +218,9 @@
186 /* usb-msd.c */
187 USBDevice *usb_msd_init(const char *filename);
188 +
189 +/* usb.c */
190 +void generic_usb_save(QEMUFile* f, void *opaque);
191 +int generic_usb_load(QEMUFile* f, void *opaque, int version_id);
192 +
193 +
194 Index: ioemu/hw/usb-uhci.c
195 ===================================================================
196 --- ioemu.orig/hw/usb-uhci.c 2007-05-09 14:10:50.000000000 +0100
197 +++ ioemu/hw/usb-uhci.c 2007-05-09 14:11:18.000000000 +0100
198 @@ -760,6 +760,57 @@
199 register_ioport_read(addr, 32, 1, uhci_ioport_readb, s);
200 }
202 +void uhci_usb_save(QEMUFile *f, void *opaque)
203 +{
204 + int i;
205 + UHCIState *s = (UHCIState*)opaque;
206 +
207 + pci_device_save(&s->dev, f);
208 +
209 + qemu_put_be16s(f, &s->cmd);
210 + qemu_put_be16s(f, &s->status);
211 + qemu_put_be16s(f, &s->intr);
212 + qemu_put_be16s(f, &s->frnum);
213 + qemu_put_be32s(f, &s->fl_base_addr);
214 + qemu_put_8s(f, &s->sof_timing);
215 + qemu_put_8s(f, &s->status2);
216 +
217 + for(i = 0; i < NB_PORTS; i++) {
218 + qemu_put_be16s(f, &s->ports[i].ctrl);
219 + }
220 +
221 + qemu_put_timer(f, s->frame_timer);
222 +}
223 +
224 +int uhci_usb_load(QEMUFile *f, void *opaque, int version_id)
225 +{
226 + int i;
227 + UHCIState *s = (UHCIState*)opaque;
228 +
229 + if (version_id != 1)
230 + return -EINVAL;
231 +
232 + i = pci_device_load(&s->dev, f);
233 + if (i < 0)
234 + return i;
235 +
236 + qemu_get_be16s(f, &s->cmd);
237 + qemu_get_be16s(f, &s->status);
238 + qemu_get_be16s(f, &s->intr);
239 + qemu_get_be16s(f, &s->frnum);
240 + qemu_get_be32s(f, &s->fl_base_addr);
241 + qemu_get_8s(f, &s->sof_timing);
242 + qemu_get_8s(f, &s->status2);
243 +
244 + for(i = 0; i < NB_PORTS; i++) {
245 + qemu_get_be16s(f, &s->ports[i].ctrl);
246 + }
247 +
248 + qemu_get_timer(f, s->frame_timer);
249 +
250 + return 0;
251 +}
252 +
253 void usb_uhci_init(PCIBus *bus, int devfn)
254 {
255 UHCIState *s;
256 @@ -793,4 +844,6 @@
257 to rely on this. */
258 pci_register_io_region(&s->dev, 4, 0x20,
259 PCI_ADDRESS_SPACE_IO, uhci_map);
260 +
261 + register_savevm("UHCI usb controller", 0, 1, uhci_usb_save, uhci_usb_load, s);
262 }