qemu/qdev: type safety in reset handler
Add type safety to qdev reset handlers, by declaring them as DeviceState * rather than void *. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
		
							parent
							
								
									ac0be99800
								
							
						
					
					
						commit
						7f23f812c4
					
				
							
								
								
									
										13
									
								
								hw/qdev.c
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								hw/qdev.c
									
									
									
									
									
								
							| @ -222,6 +222,13 @@ DeviceState *qdev_device_add(QemuOpts *opts) | ||||
|     return qdev; | ||||
| } | ||||
| 
 | ||||
| static void qdev_reset(void *opaque) | ||||
| { | ||||
|     DeviceState *dev = opaque; | ||||
|     if (dev->info->reset) | ||||
|         dev->info->reset(dev); | ||||
| } | ||||
| 
 | ||||
| /* Initialize a device.  Device properties should be set before calling
 | ||||
|    this function.  IRQs and MMIO regions should be connected/mapped after | ||||
|    calling this function.  */ | ||||
| @ -233,8 +240,7 @@ int qdev_init(DeviceState *dev) | ||||
|     rc = dev->info->init(dev, dev->info); | ||||
|     if (rc < 0) | ||||
|         return rc; | ||||
|     if (dev->info->reset) | ||||
|         qemu_register_reset(dev->info->reset, dev); | ||||
|     qemu_register_reset(qdev_reset, dev); | ||||
|     if (dev->info->vmsd) | ||||
|         vmstate_register(-1, dev->info->vmsd, dev); | ||||
|     dev->state = DEV_STATE_INITIALIZED; | ||||
| @ -273,13 +279,12 @@ void qdev_free(DeviceState *dev) | ||||
|         if (dev->info->vmsd) | ||||
|             vmstate_unregister(dev->info->vmsd, dev); | ||||
| #endif | ||||
|         if (dev->info->reset) | ||||
|             qemu_unregister_reset(dev->info->reset, dev); | ||||
|         if (dev->info->exit) | ||||
|             dev->info->exit(dev); | ||||
|         if (dev->opts) | ||||
|             qemu_opts_del(dev->opts); | ||||
|     } | ||||
|     qemu_unregister_reset(qdev_reset, dev); | ||||
|     QLIST_REMOVE(dev, sibling); | ||||
|     qemu_free(dev); | ||||
| } | ||||
|  | ||||
| @ -115,6 +115,7 @@ BusState *qdev_get_child_bus(DeviceState *dev, const char *name); | ||||
| 
 | ||||
| typedef int (*qdev_initfn)(DeviceState *dev, DeviceInfo *info); | ||||
| typedef int (*qdev_event)(DeviceState *dev); | ||||
| typedef void (*qdev_resetfn)(DeviceState *dev); | ||||
| 
 | ||||
| struct DeviceInfo { | ||||
|     const char *name; | ||||
| @ -125,7 +126,7 @@ struct DeviceInfo { | ||||
|     int no_user; | ||||
| 
 | ||||
|     /* callbacks */ | ||||
|     QEMUResetHandler *reset; | ||||
|     qdev_resetfn reset; | ||||
| 
 | ||||
|     /* device state */ | ||||
|     const VMStateDescription *vmsd; | ||||
|  | ||||
							
								
								
									
										10
									
								
								hw/rtl8139.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								hw/rtl8139.c
									
									
									
									
									
								
							| @ -1173,9 +1173,9 @@ static void rtl8139_reset_rxring(RTL8139State *s, uint32_t bufferSize) | ||||
|     s->RxBufAddr = 0; | ||||
| } | ||||
| 
 | ||||
| static void rtl8139_reset(void *opaque) | ||||
| static void rtl8139_reset(DeviceState *d) | ||||
| { | ||||
|     RTL8139State *s = opaque; | ||||
|     RTL8139State *s = container_of(d, RTL8139State, dev.qdev); | ||||
|     int i; | ||||
| 
 | ||||
|     /* restore MAC address */ | ||||
| @ -1371,7 +1371,7 @@ static void rtl8139_ChipCmd_write(RTL8139State *s, uint32_t val) | ||||
|     if (val & CmdReset) | ||||
|     { | ||||
|         DEBUG_PRINT(("RTL8139: ChipCmd reset\n")); | ||||
|         rtl8139_reset(s); | ||||
|         rtl8139_reset(&s->dev.qdev); | ||||
|     } | ||||
|     if (val & CmdRxEnb) | ||||
|     { | ||||
| @ -1544,7 +1544,7 @@ static void rtl8139_Cfg9346_write(RTL8139State *s, uint32_t val) | ||||
|     } else if (opmode == 0x40) { | ||||
|         /* Reset.  */ | ||||
|         val = 0; | ||||
|         rtl8139_reset(s); | ||||
|         rtl8139_reset(&s->dev.qdev); | ||||
|     } | ||||
| 
 | ||||
|     s->Cfg9346 = val; | ||||
| @ -3464,7 +3464,7 @@ static int pci_rtl8139_init(PCIDevice *dev) | ||||
|                            PCI_ADDRESS_SPACE_MEM, rtl8139_mmio_map); | ||||
| 
 | ||||
|     qdev_get_macaddr(&dev->qdev, s->macaddr); | ||||
|     rtl8139_reset(s); | ||||
|     rtl8139_reset(&s->dev.qdev); | ||||
|     s->vc = qdev_get_vlan_client(&dev->qdev, | ||||
|                                  rtl8139_can_receive, rtl8139_receive, NULL, | ||||
|                                  rtl8139_cleanup, s); | ||||
|  | ||||
							
								
								
									
										6
									
								
								hw/tcx.c
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								hw/tcx.c
									
									
									
									
									
								
							| @ -411,9 +411,9 @@ static const VMStateDescription vmstate_tcx = { | ||||
|     } | ||||
| }; | ||||
| 
 | ||||
| static void tcx_reset(void *opaque) | ||||
| static void tcx_reset(DeviceState *d) | ||||
| { | ||||
|     TCXState *s = opaque; | ||||
|     TCXState *s = container_of(d, TCXState, busdev.qdev); | ||||
| 
 | ||||
|     /* Initialize palette */ | ||||
|     memset(s->r, 0, 256); | ||||
| @ -560,7 +560,7 @@ static int tcx_init1(SysBusDevice *dev) | ||||
|                                      tcx_screen_dump, NULL, s); | ||||
|     } | ||||
| 
 | ||||
|     tcx_reset(s); | ||||
|     tcx_reset(&s->busdev.qdev); | ||||
|     qemu_console_resize(s->ds, s->width, s->height); | ||||
|     return 0; | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Michael S. Tsirkin
						Michael S. Tsirkin