pci: Move VMState registration/unregistration to QOM realize/unrealize
Use the realize and unrealize hooks to register and unregister vmstate_pcibus respectively. Relocate some stuff to avoid forward declarations. Signed-off-by: Bandan Das <bsd@redhat.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> [AF: Keep using PCI_BUS() cast macro] Signed-off-by: Andreas Färber <afaerber@suse.de>
This commit is contained in:
		
							parent
							
								
									5c21ce77d7
								
							
						
					
					
						commit
						d2f69df746
					
				
							
								
								
									
										51
									
								
								hw/pci/pci.c
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								hw/pci/pci.c
									
									
									
									
									
								
							@ -48,7 +48,6 @@ static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent);
 | 
				
			|||||||
static char *pcibus_get_dev_path(DeviceState *dev);
 | 
					static char *pcibus_get_dev_path(DeviceState *dev);
 | 
				
			||||||
static char *pcibus_get_fw_dev_path(DeviceState *dev);
 | 
					static char *pcibus_get_fw_dev_path(DeviceState *dev);
 | 
				
			||||||
static void pcibus_reset(BusState *qbus);
 | 
					static void pcibus_reset(BusState *qbus);
 | 
				
			||||||
static void pci_bus_finalize(Object *obj);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
static Property pci_props[] = {
 | 
					static Property pci_props[] = {
 | 
				
			||||||
    DEFINE_PROP_PCI_DEVFN("addr", PCIDevice, devfn, -1),
 | 
					    DEFINE_PROP_PCI_DEVFN("addr", PCIDevice, devfn, -1),
 | 
				
			||||||
@ -61,6 +60,34 @@ static Property pci_props[] = {
 | 
				
			|||||||
    DEFINE_PROP_END_OF_LIST()
 | 
					    DEFINE_PROP_END_OF_LIST()
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const VMStateDescription vmstate_pcibus = {
 | 
				
			||||||
 | 
					    .name = "PCIBUS",
 | 
				
			||||||
 | 
					    .version_id = 1,
 | 
				
			||||||
 | 
					    .minimum_version_id = 1,
 | 
				
			||||||
 | 
					    .minimum_version_id_old = 1,
 | 
				
			||||||
 | 
					    .fields      = (VMStateField[]) {
 | 
				
			||||||
 | 
					        VMSTATE_INT32_EQUAL(nirq, PCIBus),
 | 
				
			||||||
 | 
					        VMSTATE_VARRAY_INT32(irq_count, PCIBus,
 | 
				
			||||||
 | 
					                             nirq, 0, vmstate_info_int32,
 | 
				
			||||||
 | 
					                             int32_t),
 | 
				
			||||||
 | 
					        VMSTATE_END_OF_LIST()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void pci_bus_realize(BusState *qbus, Error **errp)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    PCIBus *bus = PCI_BUS(qbus);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    vmstate_register(NULL, -1, &vmstate_pcibus, bus);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void pci_bus_unrealize(BusState *qbus, Error **errp)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    PCIBus *bus = PCI_BUS(qbus);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    vmstate_unregister(NULL, &vmstate_pcibus, bus);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void pci_bus_class_init(ObjectClass *klass, void *data)
 | 
					static void pci_bus_class_init(ObjectClass *klass, void *data)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    BusClass *k = BUS_CLASS(klass);
 | 
					    BusClass *k = BUS_CLASS(klass);
 | 
				
			||||||
@ -68,6 +95,8 @@ static void pci_bus_class_init(ObjectClass *klass, void *data)
 | 
				
			|||||||
    k->print_dev = pcibus_dev_print;
 | 
					    k->print_dev = pcibus_dev_print;
 | 
				
			||||||
    k->get_dev_path = pcibus_get_dev_path;
 | 
					    k->get_dev_path = pcibus_get_dev_path;
 | 
				
			||||||
    k->get_fw_dev_path = pcibus_get_fw_dev_path;
 | 
					    k->get_fw_dev_path = pcibus_get_fw_dev_path;
 | 
				
			||||||
 | 
					    k->realize = pci_bus_realize;
 | 
				
			||||||
 | 
					    k->unrealize = pci_bus_unrealize;
 | 
				
			||||||
    k->reset = pcibus_reset;
 | 
					    k->reset = pcibus_reset;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -75,7 +104,6 @@ static const TypeInfo pci_bus_info = {
 | 
				
			|||||||
    .name = TYPE_PCI_BUS,
 | 
					    .name = TYPE_PCI_BUS,
 | 
				
			||||||
    .parent = TYPE_BUS,
 | 
					    .parent = TYPE_BUS,
 | 
				
			||||||
    .instance_size = sizeof(PCIBus),
 | 
					    .instance_size = sizeof(PCIBus),
 | 
				
			||||||
    .instance_finalize = pci_bus_finalize,
 | 
					 | 
				
			||||||
    .class_init = pci_bus_class_init,
 | 
					    .class_init = pci_bus_class_init,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -95,17 +123,6 @@ static uint16_t pci_default_sub_device_id = PCI_SUBDEVICE_ID_QEMU;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static QLIST_HEAD(, PCIHostState) pci_host_bridges;
 | 
					static QLIST_HEAD(, PCIHostState) pci_host_bridges;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const VMStateDescription vmstate_pcibus = {
 | 
					 | 
				
			||||||
    .name = "PCIBUS",
 | 
					 | 
				
			||||||
    .version_id = 1,
 | 
					 | 
				
			||||||
    .minimum_version_id = 1,
 | 
					 | 
				
			||||||
    .minimum_version_id_old = 1,
 | 
					 | 
				
			||||||
    .fields      = (VMStateField []) {
 | 
					 | 
				
			||||||
        VMSTATE_INT32_EQUAL(nirq, PCIBus),
 | 
					 | 
				
			||||||
        VMSTATE_VARRAY_INT32(irq_count, PCIBus, nirq, 0, vmstate_info_int32, int32_t),
 | 
					 | 
				
			||||||
        VMSTATE_END_OF_LIST()
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
static int pci_bar(PCIDevice *d, int reg)
 | 
					static int pci_bar(PCIDevice *d, int reg)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    uint8_t type;
 | 
					    uint8_t type;
 | 
				
			||||||
@ -299,8 +316,6 @@ static void pci_bus_init(PCIBus *bus, DeviceState *parent,
 | 
				
			|||||||
    QLIST_INIT(&bus->child);
 | 
					    QLIST_INIT(&bus->child);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pci_host_bus_register(bus, parent);
 | 
					    pci_host_bus_register(bus, parent);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    vmstate_register(NULL, -1, &vmstate_pcibus, bus);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool pci_bus_is_express(PCIBus *bus)
 | 
					bool pci_bus_is_express(PCIBus *bus)
 | 
				
			||||||
@ -369,12 +384,6 @@ int pci_bus_num(PCIBus *s)
 | 
				
			|||||||
    return s->parent_dev->config[PCI_SECONDARY_BUS];
 | 
					    return s->parent_dev->config[PCI_SECONDARY_BUS];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void pci_bus_finalize(Object *obj)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    PCIBus *bus = PCI_BUS(obj);
 | 
					 | 
				
			||||||
    vmstate_unregister(NULL, &vmstate_pcibus, bus);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static int get_pci_config_device(QEMUFile *f, void *pv, size_t size)
 | 
					static int get_pci_config_device(QEMUFile *f, void *pv, size_t size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    PCIDevice *s = container_of(pv, PCIDevice, config);
 | 
					    PCIDevice *s = container_of(pv, PCIDevice, config);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user